Conversation
137ee51 to
a3d6037
Compare
07f434a to
66b5383
Compare
hswopeams
left a comment
There was a problem hiding this comment.
Looks mostly OK. There are a few changes that need to be made in the test file.
| const { hexlify } = require('ethers'); | ||
| const { switchChain, getChainIds } = chainweb; | ||
|
|
||
| const CREATE2_DEPLOYER = '0x4e59b44847b379578588920cA78FbF26c0B4956C'; |
There was a problem hiding this comment.
This should be called CREATE2_FACTORY. That is the standard name for this type of factory.
| const initCode = ethers.concat([SimpleToken.bytecode, encodedConstructorArgs]); | ||
|
|
||
| // Expected address | ||
| const address = ethers.getCreate2Address( |
There was a problem hiding this comment.
This should be called predictedAddress. It gets set in the contract object, and it looks as if this is an actual deployed address. I had to keep going back to look at the before code to see what that address actually is.
| const contract = contracts.find(d => d.chain === chain); | ||
| const signers = await getSigners(chain); | ||
| const deployer = signers.deployer; | ||
| const address = await deployer.call({ |
There was a problem hiding this comment.
It's odd and not standard to use deployer.call in this situation. sendTransaction should be used. Something like this:
// Use the predicted address computed in the `before` hook
const predicted = contract.address;
console.log(`Deploying SimpleToken on chain ${chain} via CREATE2 factory (normal sendTransaction)... predicted: ${predicted}`);
const tx = await deployer.sendTransaction({
to: CREATE2_DEPLOYER,
data: ethers.concat([contract.salt, contract.initCode]),
});
const receipt = await tx.wait();
expect(receipt.status).to.equal(1);
// Verify deployed code exists at the predicted address
const deployedCode = await deployer.provider.getCode(predicted);
expect(deployedCode).to.not.equal('0x');
| it('Should have deployed code at the address', async function () { | ||
| await chainweb.runOverChains(async (chain) => { | ||
| const contract = contracts.find(d => d.chain === chain); | ||
| const deployedCode = await ethers.provider.getCode(contract.address); |
There was a problem hiding this comment.
There shouldn't be any deployedCode at this address. The before hook doesn't actually deploy. This test case appears to rely on state from previous test cases. That violates unit testing principles. Each unit test must be isolated from other test cases. The before hook should be a beforeEach hook to ensure a clean slate for each test case.
This PR upgrades the sandbox to the latest version of the
evm/mainbranch of chainweb-node:eve-development. In previous versions it collided with the version code of theevm-testnet, which could cause issues in some scenarios.evm-developmentnetworks, which include the sandbox network.CREATE2 Factory System Contract
The provided CREATE2 factory is well known and widely used across the Ethereum ecosystem. It is deterministically deployed at address
0x4e59b44847b379578588920cA78FbF26c0B4956C.The factory contract is very minimalistic, which suites its use as a preinstalled system contract. It does not use ABI encoding. The contract is called with the 32 bytes of the salt followed by the contract initialization code as the only parameter. It returns the deployment address of the contract.
The availability in the sandbox network can be tested via:
./network devnet pull ./network devnet start ./network solidity test --chainweb sandbox ./test/Create2.test.jsThere is a PR that adds support to the hardhat-kadena-plugin. By using this branch one can run the tests directly on the hardhat network via
./network solidity test.Foundry provides this CREATE2 factory out of the box. The contract is also available on all EVM chains in the Kadena EVM testnet.