move EVM state setup into a seperate contract
Change-Id: Ie000dd042c4ebbd7084511d38d87a7555c5d8048
This commit is contained in:
parent
1175eb1315
commit
a055af1416
|
@ -30,23 +30,6 @@ contract Implementation is Governance {
|
|||
setNextSequence(emitter, sequence + 1);
|
||||
}
|
||||
|
||||
function initialize(address[] memory initialGuardians, uint16 chainId, uint16 governanceChainId, bytes32 governanceContract) initializer public {
|
||||
require(initialGuardians.length > 0, "no guardians specified");
|
||||
|
||||
Structs.GuardianSet memory initialGuardianSet = Structs.GuardianSet({
|
||||
keys : initialGuardians,
|
||||
expirationTime : 0
|
||||
});
|
||||
|
||||
storeGuardianSet(initialGuardianSet, 0);
|
||||
// initial guardian set index is 0, which is the default value of the storage slot anyways
|
||||
|
||||
setChainId(chainId);
|
||||
|
||||
setGovernanceChainId(governanceChainId);
|
||||
setGovernanceContract(governanceContract);
|
||||
}
|
||||
|
||||
modifier initializer() {
|
||||
address implementation = ERC1967Upgrade._getImplementation();
|
||||
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
// contracts/Implementation.sol
|
||||
// SPDX-License-Identifier: Apache 2
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "./Governance.sol";
|
||||
|
||||
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Upgrade.sol";
|
||||
|
||||
contract Setup is Setters, ERC1967Upgrade {
|
||||
function setup(
|
||||
address implementation,
|
||||
address[] memory initialGuardians,
|
||||
uint16 chainId,
|
||||
uint16 governanceChainId,
|
||||
bytes32 governanceContract
|
||||
) public {
|
||||
require(initialGuardians.length > 0, "no guardians specified");
|
||||
|
||||
Structs.GuardianSet memory initialGuardianSet = Structs.GuardianSet({
|
||||
keys : initialGuardians,
|
||||
expirationTime : 0
|
||||
});
|
||||
|
||||
storeGuardianSet(initialGuardianSet, 0);
|
||||
// initial guardian set index is 0, which is the default value of the storage slot anyways
|
||||
|
||||
setChainId(chainId);
|
||||
|
||||
setGovernanceChainId(governanceChainId);
|
||||
setGovernanceContract(governanceContract);
|
||||
|
||||
_upgradeTo(implementation);
|
||||
}
|
||||
}
|
|
@ -6,8 +6,8 @@ pragma solidity ^0.8.0;
|
|||
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
|
||||
|
||||
contract Wormhole is ERC1967Proxy {
|
||||
constructor (address implementation, bytes memory initData) ERC1967Proxy(
|
||||
implementation,
|
||||
constructor (address setup, bytes memory initData) ERC1967Proxy(
|
||||
setup,
|
||||
initData
|
||||
) { }
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
require('dotenv').config({ path: "../.env" });
|
||||
|
||||
const Setup = artifacts.require("Setup");
|
||||
const Implementation = artifacts.require("Implementation");
|
||||
const Wormhole = artifacts.require("Wormhole");
|
||||
|
||||
|
@ -10,20 +11,22 @@ const governanceChainId = process.env.INIT_GOV_CHAIN_ID;
|
|||
const governanceContract = process.env.INIT_GOV_CONTRACT; // bytes32
|
||||
|
||||
module.exports = async function (deployer) {
|
||||
// deploy setup
|
||||
await deployer.deploy(Setup);
|
||||
|
||||
// deploy implementation
|
||||
await deployer.deploy(Implementation);
|
||||
|
||||
// encode initialisation data
|
||||
const impl = new web3.eth.Contract(Implementation.abi, Implementation.address);
|
||||
const initData = impl.methods.initialize(
|
||||
const setup = new web3.eth.Contract(Setup.abi, Setup.address);
|
||||
const initData = setup.methods.setup(
|
||||
Implementation.address,
|
||||
initialSigners,
|
||||
chainId,
|
||||
governanceChainId,
|
||||
governanceContract
|
||||
).encodeABI();
|
||||
|
||||
// console.log(initData)
|
||||
|
||||
// deploy proxy
|
||||
await deployer.deploy(Wormhole, Implementation.address, initData);
|
||||
await deployer.deploy(Wormhole, Setup.address, initData);
|
||||
};
|
||||
|
|
|
@ -85,21 +85,6 @@ contract("Wormhole", function () {
|
|||
assert.equal(governanceContract, testGovernanceContract);
|
||||
})
|
||||
|
||||
it("initialize should be non-reentrant", async function () {
|
||||
const initialized = new web3.eth.Contract(ImplementationFullABI, Wormhole.address);
|
||||
|
||||
try {
|
||||
await initialized.methods.initialize([
|
||||
testSigner1.address
|
||||
], testChainId, testGovernanceChainId, testGovernanceContract).estimateGas();
|
||||
} catch (error) {
|
||||
assert.equal(error.message, "Returned error: VM Exception while processing transaction: revert already initialized")
|
||||
return
|
||||
}
|
||||
|
||||
assert.fail("did not fail")
|
||||
})
|
||||
|
||||
it("should log a published message correctly", async function () {
|
||||
const initialized = new web3.eth.Contract(ImplementationFullABI, Wormhole.address);
|
||||
const accounts = await web3.eth.getAccounts();
|
||||
|
|
Loading…
Reference in New Issue