This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 676
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b6761e6
commit a581d91
Showing
5 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
pragma solidity ^0.6.0; | ||
|
||
contract ChainId { | ||
function getChainId() pure external returns (uint256) { | ||
uint256 id; | ||
assembly { | ||
id := chainid() | ||
} | ||
return id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const assert = require("assert"); | ||
const initializeTestProvider = require("../helpers/web3/initializeTestProvider"); | ||
const { compile } = require("../helpers/contract/compileAndDeploy"); | ||
|
||
describe.only("Chain Id option", function() { | ||
const contract = {}; | ||
|
||
before("compile contract", async function() { | ||
this.timeout(10000); | ||
const contractSubdirectory = "chainId"; | ||
const contractFilename = "ChainId"; | ||
const subcontractFiles = []; | ||
const { abi, bytecode } = await compile(contractFilename, subcontractFiles, contractSubdirectory, "istanbul"); | ||
contract.abi = abi; | ||
contract.bytecode = bytecode; | ||
}); | ||
|
||
describe("Allow Unlimited Contract Size", function() { | ||
let context; | ||
|
||
before("Setup provider to allow unlimited contract size", async function() { | ||
const ganacheOptions = { | ||
_chainId: 1, | ||
_chainIdRpc: 1 | ||
}; | ||
|
||
context = await initializeTestProvider(ganacheOptions); | ||
}); | ||
|
||
before("deploy contract", async function() { | ||
const chainIdContract = new context.web3.eth.Contract(contract.abi); | ||
contract.deployed = await chainIdContract | ||
.deploy({ | ||
data: contract.bytecode | ||
}) | ||
.send({ | ||
from: context.accounts[0], | ||
gas: 3141592 | ||
}); | ||
}); | ||
|
||
it("chainid opcode should match options", async function() { | ||
const chainId = await contract.deployed.methods.getChainId().call(); | ||
assert.strictEqual(chainId, "1"); | ||
}); | ||
|
||
it("chain id rpc should match options", async function() { | ||
const chainId = await context.web3.eth.getChainId(); | ||
assert.strictEqual(chainId, 1); | ||
}); | ||
}); | ||
}); |