|
@@ -1,6 +1,16 @@
|
|
|
|
|
+const jsonfile = require('jsonfile');
|
|
|
|
|
+const elliptic = require('elliptic');
|
|
|
|
|
+const path = require('path');
|
|
|
|
|
+
|
|
|
const Wormhole = artifacts.require("Wormhole");
|
|
const Wormhole = artifacts.require("Wormhole");
|
|
|
-const WrappedAsset = artifacts.require("WrappedAsset");
|
|
|
|
|
-const ERC20 = artifacts.require("ERC20PresetMinterPauser");
|
|
|
|
|
|
|
+const MockImplementation = artifacts.require("MockImplementation");
|
|
|
|
|
+const Implementation = artifacts.require("Implementation");
|
|
|
|
|
+
|
|
|
|
|
+const testSigner1PK = "13b422ac887f1912629e34928674cb4a81e59d96a4d74653e41c2a305ba754a5";
|
|
|
|
|
+const testSigner2PK = "892330666a850761e7370376430bb8c2aa1494072d3bfeaed0c4fa3d5a9135fe";
|
|
|
|
|
+const testSigner3PK = "87b45997ea577b93073568f06fc4838cffc1d01f90fc4d57f936957f3c4d99fb";
|
|
|
|
|
+
|
|
|
|
|
+const ImplementationFullABI = jsonfile.readFileSync("build/contracts/Implementation.json").abi
|
|
|
|
|
|
|
|
// Taken from https://medium.com/fluidity/standing-the-time-of-test-b906fcc374a9
|
|
// Taken from https://medium.com/fluidity/standing-the-time-of-test-b906fcc374a9
|
|
|
advanceTimeAndBlock = async (time) => {
|
|
advanceTimeAndBlock = async (time) => {
|
|
@@ -43,247 +53,602 @@ advanceBlock = () => {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/*
|
|
|
|
|
- The VAA test fixtures are generated by bridge/cmd/vaa-test.
|
|
|
|
|
- */
|
|
|
|
|
-
|
|
|
|
|
contract("Wormhole", function () {
|
|
contract("Wormhole", function () {
|
|
|
- it("should use master wrapped asset", async function () {
|
|
|
|
|
- let bridge = await Wormhole.deployed();
|
|
|
|
|
- let wa = await bridge.wrappedAssetMaster.call();
|
|
|
|
|
- assert.equal(wa, WrappedAsset.address)
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- it("should transfer tokens in on valid VAA", async function () {
|
|
|
|
|
- let bridge = await Wormhole.deployed();
|
|
|
|
|
-
|
|
|
|
|
- // User locked an asset on the foreign chain and the VAA proving this is transferred in.
|
|
|
|
|
- await bridge.submitVAA("0x01000000000100454e7de661cd4386b1ce598a505825f8ed66fbc6a608393bae6257fef7370da27a2068240a902470bed6c0b1fa23d38e5d5958e2a422d59a0217fbe155638ed600000007d010000000380102020104000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000000347ef34687bdc9f189e87a9200658d9c40e9988080000000000000000000000000000000000000000000000000de0b6b3a7640000")
|
|
|
|
|
- // Expect user to have a balance of a new wrapped asset
|
|
|
|
|
- // submitVAA has automatically created a new WrappedAsset for the foreign asset that has been transferred in.
|
|
|
|
|
- // We know the address because deterministic network. A user would see the address in the submitVAA tx log.
|
|
|
|
|
- let wa = new WrappedAsset("0xC3697aaf5B3D354214548248710414812099bc93");
|
|
|
|
|
- assert.equal(await wa.assetChain(), 1)
|
|
|
|
|
- // Remote asset's contract address.
|
|
|
|
|
- assert.equal(await wa.assetAddress(), "0x0000000000000000000000000347ef34687bdc9f189e87a9200658d9c40e9988")
|
|
|
|
|
- // Account that the user requests the transfer to.
|
|
|
|
|
- let balance = await wa.balanceOf("0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1");
|
|
|
|
|
- assert.equal(balance, "1000000000000000000");
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- it("should not accept the same VAA twice", async function () {
|
|
|
|
|
- let bridge = await Wormhole.deployed();
|
|
|
|
|
- try {
|
|
|
|
|
- await bridge.submitVAA("0x01000000000100454e7de661cd4386b1ce598a505825f8ed66fbc6a608393bae6257fef7370da27a2068240a902470bed6c0b1fa23d38e5d5958e2a422d59a0217fbe155638ed600000007d010000000380102020104000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000000347ef34687bdc9f189e87a9200658d9c40e9988080000000000000000000000000000000000000000000000000de0b6b3a7640000");
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- assert.equal(e.reason, "VAA was already executed")
|
|
|
|
|
|
|
+ const testSigner1 = web3.eth.accounts.privateKeyToAccount(testSigner1PK);
|
|
|
|
|
+ const testSigner2 = web3.eth.accounts.privateKeyToAccount(testSigner2PK);
|
|
|
|
|
+ const testSigner3 = web3.eth.accounts.privateKeyToAccount(testSigner3PK);
|
|
|
|
|
+ const testChainId = "2";
|
|
|
|
|
+ const testGovernanceChainId = "3";
|
|
|
|
|
+ const testGovernanceContract = "0x0000000000000000000000000000000000000000000000000000000000000004";
|
|
|
|
|
+
|
|
|
|
|
+ it("should be initialized with the correct signers and values", async function(){
|
|
|
|
|
+ const initialized = new web3.eth.Contract(ImplementationFullABI, Wormhole.address);
|
|
|
|
|
+
|
|
|
|
|
+ const index = await initialized.methods.getCurrentGuardianSetIndex().call();
|
|
|
|
|
+ const set = (await initialized.methods.getGuardianSet(index).call());
|
|
|
|
|
+
|
|
|
|
|
+ // check set
|
|
|
|
|
+ assert.lengthOf(set, 2);
|
|
|
|
|
+ assert.equal(set[0][0], testSigner1.address);
|
|
|
|
|
+ assert.equal(set[0][1], testSigner2.address);
|
|
|
|
|
+
|
|
|
|
|
+ // check expiration
|
|
|
|
|
+ assert.equal(set.expirationTime, "0");
|
|
|
|
|
+
|
|
|
|
|
+ // chain id
|
|
|
|
|
+ const chainId = await initialized.methods.chainId().call();
|
|
|
|
|
+ assert.equal(chainId, testChainId);
|
|
|
|
|
+
|
|
|
|
|
+ // governance
|
|
|
|
|
+ const governanceChainId = await initialized.methods.governanceChainId().call();
|
|
|
|
|
+ assert.equal(governanceChainId, testGovernanceChainId);
|
|
|
|
|
+ const governanceContract = await initialized.methods.governanceContract().call();
|
|
|
|
|
+ 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
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
assert.fail("did not fail")
|
|
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();
|
|
|
|
|
+
|
|
|
|
|
+ const log = await initialized.methods.publishMessage(
|
|
|
|
|
+ "0x123",
|
|
|
|
|
+ "0x123321",
|
|
|
|
|
+ false
|
|
|
|
|
+ ).send({
|
|
|
|
|
+ value : 0, // fees are set to 0 initially
|
|
|
|
|
+ from : accounts[0]
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ assert.equal(log.events.LogMessagePublished.returnValues.sender.toString(), accounts[0]);
|
|
|
|
|
+ assert.equal(log.events.LogMessagePublished.returnValues.nonce, 291);
|
|
|
|
|
+ assert.equal(log.events.LogMessagePublished.returnValues.payload.toString(), "0x123321");
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it("parses VMs correctly", async function(){
|
|
|
|
|
+ const initialized = new web3.eth.Contract(ImplementationFullABI, Wormhole.address);
|
|
|
|
|
+
|
|
|
|
|
+ const timestamp = 1000;
|
|
|
|
|
+ const nonce = 1001;
|
|
|
|
|
+ const emitterChainId = 11;
|
|
|
|
|
+ const emitterAddress = "0x0000000000000000000000000000000000000000000000000000000000000eee"
|
|
|
|
|
+ const data = "0xaaaaaa";
|
|
|
|
|
+
|
|
|
|
|
+ const vm = await signAndEncodeVM(
|
|
|
|
|
+ timestamp,
|
|
|
|
|
+ nonce,
|
|
|
|
|
+ emitterChainId,
|
|
|
|
|
+ emitterAddress,
|
|
|
|
|
+ data,
|
|
|
|
|
+ [
|
|
|
|
|
+ testSigner1PK,
|
|
|
|
|
+ testSigner2PK
|
|
|
|
|
+ ],
|
|
|
|
|
+ 0
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ let result
|
|
|
|
|
+ try {
|
|
|
|
|
+ result = await initialized.methods.parseAndVerifyVM("0x" + vm).call();
|
|
|
|
|
+ } catch(err) {
|
|
|
|
|
+ console.log(err)
|
|
|
|
|
+ assert.fail("parseAndVerifyVM failed")
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- it("should burn tokens on lock", async function () {
|
|
|
|
|
- let bridge = await Wormhole.deployed();
|
|
|
|
|
- // Expect user to have a balance
|
|
|
|
|
- let wa = new WrappedAsset("0xC3697aaf5B3D354214548248710414812099bc93")
|
|
|
|
|
|
|
+ assert.equal(result.vm.version, 1);
|
|
|
|
|
+ assert.equal(result.vm.timestamp, timestamp);
|
|
|
|
|
+ assert.equal(result.vm.nonce, nonce);
|
|
|
|
|
+ assert.equal(result.vm.emitterChainId, emitterChainId);
|
|
|
|
|
+ assert.equal(result.vm.emitterAddress, emitterAddress);
|
|
|
|
|
+ assert.equal(result.vm.payload, data);
|
|
|
|
|
+ assert.equal(result.vm.guardianSetIndex, 0);
|
|
|
|
|
+
|
|
|
|
|
+ assert.equal(result.valid, true);
|
|
|
|
|
+
|
|
|
|
|
+ assert.equal(result.reason, "");
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it("should set and enforce fees", async function(){
|
|
|
|
|
+ const initialized = new web3.eth.Contract(ImplementationFullABI, Wormhole.address);
|
|
|
|
|
+ const accounts = await web3.eth.getAccounts();
|
|
|
|
|
+
|
|
|
|
|
+ const timestamp = 1000;
|
|
|
|
|
+ const nonce = 1001;
|
|
|
|
|
+ const emitterChainId = testGovernanceChainId;
|
|
|
|
|
+ const emitterAddress = testGovernanceContract
|
|
|
|
|
+ let data = "0x00000000000000000000000000000000000000000000000000000000436f726503";
|
|
|
|
|
+
|
|
|
|
|
+ data += [
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint16", testChainId).substring(2 + (64 - 4)),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint256", 1111).substring(2),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint256", 2222).substring(2),
|
|
|
|
|
+ ].join('')
|
|
|
|
|
+
|
|
|
|
|
+ const vm = await signAndEncodeVM(
|
|
|
|
|
+ timestamp,
|
|
|
|
|
+ nonce,
|
|
|
|
|
+ emitterChainId,
|
|
|
|
|
+ emitterAddress,
|
|
|
|
|
+ data,
|
|
|
|
|
+ [
|
|
|
|
|
+ testSigner1PK,
|
|
|
|
|
+ testSigner2PK
|
|
|
|
|
+ ],
|
|
|
|
|
+ 0
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ let before = await initialized.methods.messageFee().call();
|
|
|
|
|
+
|
|
|
|
|
+ let set = await initialized.methods.submitSetMessageFee("0x" + vm).send({
|
|
|
|
|
+ value : 0,
|
|
|
|
|
+ from : accounts[0],
|
|
|
|
|
+ gasLimit : 1000000
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- await bridge.lockAssets(wa.address, "500000000000000000", "0x0", 4, 2, false);
|
|
|
|
|
- let balance = await wa.balanceOf("0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1");
|
|
|
|
|
|
|
+ let after = await initialized.methods.messageFee().call();
|
|
|
|
|
+
|
|
|
|
|
+ assert.notEqual(before, after);
|
|
|
|
|
+ assert.equal(after, 1111);
|
|
|
|
|
+
|
|
|
|
|
+ // test non-persisted message
|
|
|
|
|
+ await initialized.methods.publishMessage(
|
|
|
|
|
+ "0x123",
|
|
|
|
|
+ "0x123321",
|
|
|
|
|
+ false
|
|
|
|
|
+ ).send({
|
|
|
|
|
+ from : accounts[0],
|
|
|
|
|
+ value : 1111
|
|
|
|
|
+ })
|
|
|
|
|
+ // test persisted message
|
|
|
|
|
+ await initialized.methods.publishMessage(
|
|
|
|
|
+ "0x123",
|
|
|
|
|
+ "0x123321",
|
|
|
|
|
+ true
|
|
|
|
|
+ ).send({
|
|
|
|
|
+ from : accounts[0],
|
|
|
|
|
+ value : 2222
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ let failed = false;
|
|
|
|
|
+ try {
|
|
|
|
|
+ await initialized.methods.publishMessage(
|
|
|
|
|
+ "0x123",
|
|
|
|
|
+ "0x123321",
|
|
|
|
|
+ false
|
|
|
|
|
+ ).send({
|
|
|
|
|
+ value : 1110,
|
|
|
|
|
+ from : accounts[0]
|
|
|
|
|
+ })
|
|
|
|
|
+ } catch(e) {
|
|
|
|
|
+ failed = true
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // Expect user balance to decrease
|
|
|
|
|
- assert.equal(balance, "500000000000000000");
|
|
|
|
|
|
|
+ assert.equal(failed, true);
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it("should transfer out collected fees", async function(){
|
|
|
|
|
+ const initialized = new web3.eth.Contract(ImplementationFullABI, Wormhole.address);
|
|
|
|
|
+ const accounts = await web3.eth.getAccounts();
|
|
|
|
|
+
|
|
|
|
|
+ const receiver = "0x" + zeroPadBytes( Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16), 20);
|
|
|
|
|
+
|
|
|
|
|
+ const timestamp = 1000;
|
|
|
|
|
+ const nonce = 1001;
|
|
|
|
|
+ const emitterChainId = testGovernanceChainId;
|
|
|
|
|
+ const emitterAddress = testGovernanceContract
|
|
|
|
|
+ let data = "0x00000000000000000000000000000000000000000000000000000000436f726504";
|
|
|
|
|
+
|
|
|
|
|
+ data += [
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint16", testChainId).substring(2 + (64 - 4)),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint256", 11).substring(2),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("address", receiver).substring(2),
|
|
|
|
|
+ ].join('')
|
|
|
|
|
+
|
|
|
|
|
+ const vm = await signAndEncodeVM(
|
|
|
|
|
+ timestamp,
|
|
|
|
|
+ nonce,
|
|
|
|
|
+ emitterChainId,
|
|
|
|
|
+ emitterAddress,
|
|
|
|
|
+ data,
|
|
|
|
|
+ [
|
|
|
|
|
+ testSigner1PK,
|
|
|
|
|
+ testSigner2PK
|
|
|
|
|
+ ],
|
|
|
|
|
+ 0
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ let WHBefore = await web3.eth.getBalance(Wormhole.address);
|
|
|
|
|
+ let receiverBefore = await web3.eth.getBalance(receiver);
|
|
|
|
|
+
|
|
|
|
|
+ let set = await initialized.methods.submitTransferFees("0x" + vm).send({
|
|
|
|
|
+ value : 0,
|
|
|
|
|
+ from : accounts[0],
|
|
|
|
|
+ gasLimit : 1000000
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- // Expect contract balance to be 0 since tokens have been burned
|
|
|
|
|
- balance = await wa.balanceOf(bridge.address);
|
|
|
|
|
- assert.equal(balance, "0");
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ let WHAfter = await web3.eth.getBalance(Wormhole.address);
|
|
|
|
|
+ let receiverAfter = await web3.eth.getBalance(receiver);
|
|
|
|
|
+
|
|
|
|
|
+ assert.equal(WHBefore - WHAfter, 11);
|
|
|
|
|
+ assert.equal(receiverAfter - receiverBefore, 11);
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it("should accept a new guardian set", async function(){
|
|
|
|
|
+ const initialized = new web3.eth.Contract(ImplementationFullABI, Wormhole.address);
|
|
|
|
|
+ const accounts = await web3.eth.getAccounts();
|
|
|
|
|
+
|
|
|
|
|
+ const timestamp = 1000;
|
|
|
|
|
+ const nonce = 1001;
|
|
|
|
|
+ const emitterChainId = testGovernanceChainId;
|
|
|
|
|
+ const emitterAddress = testGovernanceContract
|
|
|
|
|
+ let data = "0x00000000000000000000000000000000000000000000000000000000436f726502";
|
|
|
|
|
+
|
|
|
|
|
+ let oldIndex = Number(await initialized.methods.getCurrentGuardianSetIndex().call());
|
|
|
|
|
+
|
|
|
|
|
+ data += [
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint16", testChainId).substring(2 + (64 - 4)),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint32", oldIndex + 1).substring(2 + (64 - 8)),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint8", 3).substring(2 + (64 - 2)),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("address", testSigner1.address).substring(2 + (64 - 40)),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("address", testSigner2.address).substring(2 + (64 - 40)),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("address", testSigner3.address).substring(2 + (64 - 40)),
|
|
|
|
|
+ ].join('')
|
|
|
|
|
+
|
|
|
|
|
+ const vm = await signAndEncodeVM(
|
|
|
|
|
+ timestamp,
|
|
|
|
|
+ nonce,
|
|
|
|
|
+ emitterChainId,
|
|
|
|
|
+ emitterAddress,
|
|
|
|
|
+ data,
|
|
|
|
|
+ [
|
|
|
|
|
+ testSigner1PK,
|
|
|
|
|
+ testSigner2PK
|
|
|
|
|
+ ],
|
|
|
|
|
+ 0
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ let set = await initialized.methods.submitNewGuardianSet("0x" + vm).send({
|
|
|
|
|
+ value : 0,
|
|
|
|
|
+ from : accounts[0],
|
|
|
|
|
+ gasLimit : 1000000
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- it("should transfer tokens in and out", async function () {
|
|
|
|
|
- let bridge = await Wormhole.deployed();
|
|
|
|
|
- let token = await ERC20.new("Test Token", "TKN");
|
|
|
|
|
|
|
+ let index = await initialized.methods.getCurrentGuardianSetIndex().call();
|
|
|
|
|
|
|
|
- await token.mint("0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1", "1000000000000000000000000000");
|
|
|
|
|
- // Expect user to have a balance
|
|
|
|
|
- assert.equal(await token.balanceOf("0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1"), "1000000000000000000000000000");
|
|
|
|
|
|
|
+ assert.equal(oldIndex + 1, index);
|
|
|
|
|
|
|
|
- // Approve bridge
|
|
|
|
|
- await token.approve(bridge.address, "1000000000000000000000000000");
|
|
|
|
|
|
|
+ assert.equal(index, 1);
|
|
|
|
|
|
|
|
- // Transfer of that token out of the contract should not work
|
|
|
|
|
- let threw = false;
|
|
|
|
|
- try {
|
|
|
|
|
- await bridge.submitVAA("0x01000000000100078f0fe9406808b1e5003867ab74aa2085153b7735b329640d275ea943dd115d00e356c6d343142d9190872c11d2de898d075cea7f4e85ff2188af299e26a14200000007d010000000380102020104000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c102000000000000000000000000d833215cbcc3f914bd1c9ece3ee7bf8b14f841bb080000000000000000000000000000000000000000000000000de0b6b3a7640000");
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- threw = true;
|
|
|
|
|
- }
|
|
|
|
|
- assert.isTrue(threw);
|
|
|
|
|
-
|
|
|
|
|
- // Lock assets
|
|
|
|
|
- let ev = await bridge.lockAssets(token.address, "1000000000000000000000000000", "0x1230000000000000000000000000000000000000000000000000000000000000", 3, 3, false);
|
|
|
|
|
-
|
|
|
|
|
- // Check that the lock event was emitted correctly
|
|
|
|
|
- assert.lengthOf(ev.logs, 1)
|
|
|
|
|
- assert.equal(ev.logs[0].event, "LogTokensLocked")
|
|
|
|
|
- assert.equal(ev.logs[0].args.target_chain, "3")
|
|
|
|
|
- assert.equal(ev.logs[0].args.token_chain, "2")
|
|
|
|
|
- assert.equal(ev.logs[0].args.token, "0x000000000000000000000000d833215cbcc3f914bd1c9ece3ee7bf8b14f841bb")
|
|
|
|
|
- assert.equal(ev.logs[0].args.sender, "0x00000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1")
|
|
|
|
|
- assert.equal(ev.logs[0].args.recipient, "0x1230000000000000000000000000000000000000000000000000000000000000")
|
|
|
|
|
- assert.equal(ev.logs[0].args.amount, "1000000000000000000")
|
|
|
|
|
-
|
|
|
|
|
- // Check that the tokens were transferred to the bridge
|
|
|
|
|
- assert.equal(await token.balanceOf("0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1"), "0");
|
|
|
|
|
- assert.equal(await token.balanceOf(bridge.address), "1000000000000000000000000000");
|
|
|
|
|
-
|
|
|
|
|
- // Transfer this token back - This also checks decimal realignment
|
|
|
|
|
- await bridge.submitVAA("0x01000000000100078f0fe9406808b1e5003867ab74aa2085153b7735b329640d275ea943dd115d00e356c6d343142d9190872c11d2de898d075cea7f4e85ff2188af299e26a14200000007d010000000380102020104000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c102000000000000000000000000d833215cbcc3f914bd1c9ece3ee7bf8b14f841bb080000000000000000000000000000000000000000000000000de0b6b3a7640000");
|
|
|
|
|
- assert.equal(await token.balanceOf("0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1"), "1000000000000000000000000000");
|
|
|
|
|
- assert.equal(await token.balanceOf(bridge.address), "0");
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ let guardians = await initialized.methods.getGuardianSet(index).call();
|
|
|
|
|
|
|
|
- it("should accept validator set change", async function () {
|
|
|
|
|
- let bridge = await Wormhole.deployed();
|
|
|
|
|
|
|
+ assert.equal(guardians.expirationTime, 0);
|
|
|
|
|
|
|
|
- // Push time by 1000
|
|
|
|
|
- await advanceTimeAndBlock(1000);
|
|
|
|
|
- let ev = await bridge.submitVAA("0x01000000000100a33c022217ccb87a5bc83b71e6377fff6639e7904d9e9995a42dc0867dc2b0bc5d1aacc3752ea71cf4d85278526b5dd40b0343667a2d4434a44cbf7844181a1000000007d0010000000101e06a9adfeb38a8ee4d00e89307c016d0749679bd")
|
|
|
|
|
- assert.lengthOf(ev.logs, 1)
|
|
|
|
|
- assert.equal(ev.logs[0].event, "LogGuardianSetChanged")
|
|
|
|
|
|
|
+ assert.lengthOf(guardians[0], 3);
|
|
|
|
|
+ assert.equal(guardians[0][0], testSigner1.address);
|
|
|
|
|
+ assert.equal(guardians[0][1], testSigner2.address);
|
|
|
|
|
+ assert.equal(guardians[0][2], testSigner3.address);
|
|
|
|
|
|
|
|
- // Expect guardian set to transition to 1
|
|
|
|
|
- assert.equal(await bridge.guardian_set_index(), 1);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ let oldGuardians = await initialized.methods.getGuardianSet(oldIndex).call();
|
|
|
|
|
|
|
|
- it("should not accept guardian set change from old guardians", async function () {
|
|
|
|
|
- let bridge = await Wormhole.deployed();
|
|
|
|
|
|
|
+ const time = (await web3.eth.getBlock("latest")).timestamp;
|
|
|
|
|
|
|
|
- // Test update guardian set VAA from guardian set 0; timestamp 2000
|
|
|
|
|
- let threw = false;
|
|
|
|
|
- try {
|
|
|
|
|
- await bridge.submitVAA("0x01000000000100d90d6f9cbc0458599cbe4d267bc9221b54955b94cb5cb338aeb845bdc9dd275f558871ea479de9cc0b44cfb2a07344431a3adbd2f98aa86f4e12ff4aba061b7f00000007d00100000001018575df9b3c97b4e267deb92d93137844a97a0132")
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- threw = true;
|
|
|
|
|
- assert.equal(e.reason, "only the current guardian set can change the guardian set")
|
|
|
|
|
- }
|
|
|
|
|
- assert.isTrue(threw, "old guardian set could make changes")
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // old guardian set expiry is set
|
|
|
|
|
+ assert.ok(
|
|
|
|
|
+ oldGuardians.expirationTime > Number(time) + 86000
|
|
|
|
|
+ && oldGuardians.expirationTime < Number(time) + 88000
|
|
|
|
|
+ );
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
- it("should time out guardians", async function () {
|
|
|
|
|
- let bridge = await Wormhole.deployed();
|
|
|
|
|
|
|
+ it("should accept smart contract upgrades", async function(){
|
|
|
|
|
+ const initialized = new web3.eth.Contract(ImplementationFullABI, Wormhole.address);
|
|
|
|
|
+ const accounts = await web3.eth.getAccounts();
|
|
|
|
|
|
|
|
- // Test VAA from guardian set 0; timestamp 1000
|
|
|
|
|
- await bridge.submitVAA("0x0100000000010034890d1c1aa2455d083602996d924ca9ba2fd9641dcdaa3b0811c9ed37e831a8433b40b0f0779fa16be2daaf53ede378530a135b68ac95814c9d25023a29580e01000003e810000000380102020104000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000000347ef34687bdc9f189e87a9200658d9c40e9988080000000000000000000000000000000000000000000000000de0b6b3a7640000")
|
|
|
|
|
|
|
+ const mock = await MockImplementation.new();
|
|
|
|
|
|
|
|
- await advanceTimeAndBlock(1000);
|
|
|
|
|
|
|
+ const timestamp = 1000;
|
|
|
|
|
+ const nonce = 1001;
|
|
|
|
|
+ const emitterChainId = testGovernanceChainId;
|
|
|
|
|
+ const emitterAddress = testGovernanceContract
|
|
|
|
|
+ let data = "0x00000000000000000000000000000000000000000000000000000000436f726501";
|
|
|
|
|
|
|
|
- // Test VAA from guardian set 0; timestamp 2000 - should not work anymore
|
|
|
|
|
- let threw = false;
|
|
|
|
|
- try {
|
|
|
|
|
- await bridge.submitVAA("0x010000000001005a55b73ff79bc3cc39bec075ae28ae8351eee1428a7701f0d47fec5736bcfd9e158b49e6282678c425aed8185233ea4ef033af33bd450a77a46ddbadf3ea09ba00000007d010000000380102020105000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000000347ef34687bdc9f189e87a9200658d9c40e9988080000000000000000000000000000000000000000000000000de0b6b3a7640000")
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- threw = true;
|
|
|
|
|
- assert.equal(e.reason, "guardian set has expired")
|
|
|
|
|
- }
|
|
|
|
|
- assert.isTrue(threw, "guardian set did not expire")
|
|
|
|
|
-
|
|
|
|
|
- // Test same transaction with guardian set 1; timestamp 2000
|
|
|
|
|
- await bridge.submitVAA("0x01000000010100958a39752b14ab62a3dcdb37a8642c4ca1085c6ac77205a462ee5bb3650c92407675729615f69255fc150835621e96c917e68929efb975db9647636543c710f200000007d010000000380102020105000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000000347ef34687bdc9f189e87a9200658d9c40e9988080000000000000000000000000000000000000000000000000de0b6b3a7640000")
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ data += [
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint16", testChainId).substring(2 + (64 - 4)),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("address", mock.address).substring(2),
|
|
|
|
|
+ ].join('')
|
|
|
|
|
|
|
|
- it("mismatching guardian set and signature should not work", async function () {
|
|
|
|
|
- let bridge = await Wormhole.deployed();
|
|
|
|
|
|
|
+ const vm = await signAndEncodeVM(
|
|
|
|
|
+ timestamp,
|
|
|
|
|
+ nonce,
|
|
|
|
|
+ emitterChainId,
|
|
|
|
|
+ emitterAddress,
|
|
|
|
|
+ data,
|
|
|
|
|
+ [
|
|
|
|
|
+ testSigner1PK,
|
|
|
|
|
+ testSigner2PK,
|
|
|
|
|
+ testSigner3PK
|
|
|
|
|
+ ],
|
|
|
|
|
+ 1
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
- // Test VAA signed by guardian set 0 but set guardian set index to 1
|
|
|
|
|
- let threw = false;
|
|
|
|
|
- try {
|
|
|
|
|
- await bridge.submitVAA("0x01000000010100724a1d2cda45da3cf38f9e0eaef01742210f4deabf9b9d4b20127f6a200a94805928e26ae5f5ab8c3e1cb6d5231d4c48aacae0841513fbd3d9d430be7145db8200000007d010000000390102020105000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000000347ef34687bdc9f189e87a9200658d9c40e9988080000000000000000000000000000000000000000000000000de0b6b3a7640000")
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- threw = true;
|
|
|
|
|
- assert.equal(e.reason, "VAA signature invalid")
|
|
|
|
|
- }
|
|
|
|
|
- assert.isTrue(threw, "invalid signature accepted")
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ let before = await web3.eth.getStorageAt(Wormhole.address, "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc");
|
|
|
|
|
|
|
|
- it("quorum should be honored", async function () {
|
|
|
|
|
- let bridge = await Wormhole.deployed();
|
|
|
|
|
|
|
+ assert.equal(before.toLowerCase(), Implementation.address.toLowerCase());
|
|
|
|
|
|
|
|
- // Update to validator set 2 with 6 signers
|
|
|
|
|
- await bridge.submitVAA("0x010000000101007a8681fbb4eb93fe71d2608bacdd6ac8d7f07987d531435fc4e0e9224fcf5d087991860eb61b73671db864e7b33894ec82f7ffb17ba5a888712fb6be11df4b030100000fa0010000000206befa429d57cd18b7f8a4d91a2da9ab4af05d0fbee06a9adfeb38a8ee4d00e89307c016d0749679bd8575df9b3c97b4e267deb92d93137844a97a01320427cda59902dc6eb0c1bd2b6d38f87c5552b348bfea822f75c42e1764c791b8fe04a7b10ddb38572f5fe0b158147e7260f14062556afc94eece55ff")
|
|
|
|
|
|
|
+ let set = await initialized.methods.submitContractUpgrade("0x" + vm).send({
|
|
|
|
|
+ value : 0,
|
|
|
|
|
+ from : accounts[0],
|
|
|
|
|
+ gasLimit: 1000000
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- // Test VAA signed by only 3 signers
|
|
|
|
|
- let threw = false;
|
|
|
|
|
- try {
|
|
|
|
|
- await bridge.submitVAA("0x01000000020300e94bec8a17bd313522cdfea30cec5406a41a4cc4b6ec416a633ebe3aca070ae448e370e0a2e7c67fed04a2b825f56cf226c76e6ecd2e71865642393bf729dad80101ccf89506bef58d8cb12baabd60e3304cfb90ef0ef0657caba9c37ffa0d34a54c3aacd1a475ef4c72f24e8d9ce1e2de51e580ce85b18356436b6cda9e2ae9abc0010285f0d3c0d1cd421ce0ae515db1ac3b623c17d4702564971932fb9925c0506fc76e43a7283c712ee680cf058c3c447653c352ca9827b1780e1fc88a61540092d90100000fa010000000390102020105000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000000347ef34687bdc9f189e87a9200658d9c40e9988080000000000000000000000000000000000000000000000000de0b6b3a7640000")
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- threw = true;
|
|
|
|
|
- assert.equal(e.reason, "no quorum")
|
|
|
|
|
- }
|
|
|
|
|
- assert.isTrue(threw, "accepted only 3 signatures")
|
|
|
|
|
|
|
+ let after = await web3.eth.getStorageAt(Wormhole.address, "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc");
|
|
|
|
|
|
|
|
- // Test VAA signed by 5 signers (all except i=3)
|
|
|
|
|
- await bridge.submitVAA("0x01000000020500e94bec8a17bd313522cdfea30cec5406a41a4cc4b6ec416a633ebe3aca070ae448e370e0a2e7c67fed04a2b825f56cf226c76e6ecd2e71865642393bf729dad80101ccf89506bef58d8cb12baabd60e3304cfb90ef0ef0657caba9c37ffa0d34a54c3aacd1a475ef4c72f24e8d9ce1e2de51e580ce85b18356436b6cda9e2ae9abc001033e9b4ff5fb545e964e907349e3dab0057c408c832bb31fb76fae7f81c3e488ea4897ce14db61c46d1169bd64b449498b1a18dee4de0ef2038b1c7e3a4a0239a0010432eac9532a4c0ce279d6a3018a5ea0d74402eb6969df5d444f20e0cca66d3b4c53e41cb18648f64af100c7410692e83fa16e5696b1f5f0d517653b003e22689800055859330bd1fee76d99728803fa26d739e494e1a232f5658150c2a2c97e1c9722793bdd83bd7cbb4a39b587b45093ee76187c72dfd68d64b7c0abc32bfef5d55c0000000fa010000000390102020105000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000000347ef34687bdc9f189e87a9200658d9c40e9988080000000000000000000000000000000000000000000000000de0b6b3a7640000")
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ assert.equal(after.toLowerCase(), mock.address.toLowerCase());
|
|
|
|
|
|
|
|
- it("should correctly adjust decimals", async function () {
|
|
|
|
|
- let bridge = await Wormhole.deployed();
|
|
|
|
|
- let token = await ERC20.new("Test Token", "TKN");
|
|
|
|
|
|
|
+ const mockImpl = new web3.eth.Contract(MockImplementation.abi, Wormhole.address);
|
|
|
|
|
|
|
|
- await token.mint("0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1", "25000000000000000000000000000000000000");
|
|
|
|
|
|
|
+ let isUpgraded = await mockImpl.methods.testNewImplementationActive().call();
|
|
|
|
|
|
|
|
- // Approve bridge
|
|
|
|
|
- await token.approve(bridge.address, "25000000000000000000000000000000000000");
|
|
|
|
|
|
|
+ assert.ok(isUpgraded);
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
- // Lock assets
|
|
|
|
|
- let ev = await bridge.lockAssets(token.address, "2000000000000000003", "0x1230000000000000000000000000000000000000000000000000000000000000", 3, 3, false);
|
|
|
|
|
|
|
+ it("should revert governance packets from old guardian set", async function(){
|
|
|
|
|
+ const initialized = new web3.eth.Contract(ImplementationFullABI, Wormhole.address);
|
|
|
|
|
+ const accounts = await web3.eth.getAccounts();
|
|
|
|
|
|
|
|
- // Check that the correct amount was logged
|
|
|
|
|
- assert.lengthOf(ev.logs, 1)
|
|
|
|
|
- assert.equal(ev.logs[0].event, "LogTokensLocked")
|
|
|
|
|
- assert.equal(ev.logs[0].args.amount, "2000000000")
|
|
|
|
|
- assert.equal(ev.logs[0].args.token_decimals, "9")
|
|
|
|
|
|
|
+ let data = "0x00000000000000000000000000000000000000000000000000000000436f726504";
|
|
|
|
|
+ data += [
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint16", testChainId).substring(2 + (64 - 4)),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint256", 1).substring(2),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("address", "0x0000000000000000000000000000000000000000").substring(2),
|
|
|
|
|
+ ].join('')
|
|
|
|
|
|
|
|
- ev = await bridge.lockAssets(token.address, "2000000000000000000", "0x1230000000000000000000000000000000000000000000000000000000000000", 3, 3, false);
|
|
|
|
|
- // Check that the correct amount was logged
|
|
|
|
|
- assert.lengthOf(ev.logs, 1)
|
|
|
|
|
- assert.equal(ev.logs[0].event, "LogTokensLocked")
|
|
|
|
|
- assert.equal(ev.logs[0].args.amount, "2000000000")
|
|
|
|
|
|
|
+ const vm = await signAndEncodeVM(
|
|
|
|
|
+ 0,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ testGovernanceChainId,
|
|
|
|
|
+ testGovernanceContract,
|
|
|
|
|
+ data,
|
|
|
|
|
+ [
|
|
|
|
|
+ testSigner1PK,
|
|
|
|
|
+ testSigner2PK
|
|
|
|
|
+ ],
|
|
|
|
|
+ 0
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
- await bridge.lockAssets(token.address, "18446744069709551615000000000", "0x1230000000000000000000000000000000000000000000000000000000000000", 3, 3, false);
|
|
|
|
|
- let threw = false;
|
|
|
|
|
|
|
+ let failed = false;
|
|
|
try {
|
|
try {
|
|
|
- await bridge.lockAssets(token.address, "1000000000", "0x1230000000000000000000000000000000000000000000000000000000000000", 3, 3, false);
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- threw = true;
|
|
|
|
|
- assert.equal(e.reason, "bridge balance would exceed maximum")
|
|
|
|
|
|
|
+ await initialized.methods.submitTransferFees("0x" + vm).send({
|
|
|
|
|
+ value : 0,
|
|
|
|
|
+ from : accounts[0],
|
|
|
|
|
+ gasLimit : 1000000
|
|
|
|
|
+ });
|
|
|
|
|
+ asset.fail("governance packet of old guardian set accepted")
|
|
|
|
|
+ } catch(e) {
|
|
|
|
|
+ assert.equal(e.data[Object.keys(e.data)[0]].reason, "not signed by current guardian set")
|
|
|
}
|
|
}
|
|
|
- assert.isTrue(threw, "accepted total bridge balance > MAX_U64")
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- it("should refund dust", async function () {
|
|
|
|
|
- let bridge = await Wormhole.deployed();
|
|
|
|
|
- let token = await ERC20.new("Test Token", "TKN");
|
|
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it("should time out old gardians", async function(){
|
|
|
|
|
+ const initialized = new web3.eth.Contract(ImplementationFullABI, Wormhole.address);
|
|
|
|
|
+
|
|
|
|
|
+ const timestamp = 1000;
|
|
|
|
|
+ const nonce = 1001;
|
|
|
|
|
+ const emitterChainId = 11;
|
|
|
|
|
+ const emitterAddress = "0x0000000000000000000000000000000000000000000000000000000000000eee"
|
|
|
|
|
+ const data = "0xaaaaaa";
|
|
|
|
|
+
|
|
|
|
|
+ const vm = await signAndEncodeVM(
|
|
|
|
|
+ timestamp,
|
|
|
|
|
+ nonce,
|
|
|
|
|
+ emitterChainId,
|
|
|
|
|
+ emitterAddress,
|
|
|
|
|
+ data,
|
|
|
|
|
+ [
|
|
|
|
|
+ testSigner1PK,
|
|
|
|
|
+ testSigner2PK
|
|
|
|
|
+ ],
|
|
|
|
|
+ 0
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ // this should pass
|
|
|
|
|
+ const current = await initialized.methods.parseAndVerifyVM("0x" + vm).call();
|
|
|
|
|
+
|
|
|
|
|
+ assert.equal(current.valid, true)
|
|
|
|
|
+
|
|
|
|
|
+ await advanceTimeAndBlock(100000);
|
|
|
|
|
+
|
|
|
|
|
+ const expired = await initialized.methods.parseAndVerifyVM("0x" + vm).call();
|
|
|
|
|
+
|
|
|
|
|
+ assert.equal(expired.valid, false)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it("should revert governance packets from wrong governance chain", async function(){
|
|
|
|
|
+ const initialized = new web3.eth.Contract(ImplementationFullABI, Wormhole.address);
|
|
|
|
|
+ const accounts = await web3.eth.getAccounts();
|
|
|
|
|
+
|
|
|
|
|
+ let data = "0x00000000000000000000000000000000000000000000000000000000436f726504";
|
|
|
|
|
+ data += [
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint16", testChainId).substring(2 + (64 - 4)),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint256", 1).substring(2),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("address", "0x0000000000000000000000000000000000000000").substring(2),
|
|
|
|
|
+ ].join('')
|
|
|
|
|
+
|
|
|
|
|
+ const vm = await signAndEncodeVM(
|
|
|
|
|
+ 0,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ 999,
|
|
|
|
|
+ testGovernanceContract,
|
|
|
|
|
+ data,
|
|
|
|
|
+ [
|
|
|
|
|
+ testSigner1PK,
|
|
|
|
|
+ testSigner2PK,
|
|
|
|
|
+ testSigner3PK,
|
|
|
|
|
+ ],
|
|
|
|
|
+ 1
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
- await token.mint("0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1", "5000000100");
|
|
|
|
|
-
|
|
|
|
|
- // Approve bridge
|
|
|
|
|
- await token.approve(bridge.address, "5000000100");
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ await initialized.methods.submitTransferFees("0x" + vm).send({
|
|
|
|
|
+ value : 0,
|
|
|
|
|
+ from : accounts[0],
|
|
|
|
|
+ gasLimit : 1000000
|
|
|
|
|
+ });
|
|
|
|
|
+ asset.fail("governance packet from wrong governance chain accepted")
|
|
|
|
|
+ } catch(e) {
|
|
|
|
|
+ assert.equal(e.data[Object.keys(e.data)[0]].reason, "wrong governance chain")
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it("should revert governance packets from wrong governance contract", async function(){
|
|
|
|
|
+ const initialized = new web3.eth.Contract(ImplementationFullABI, Wormhole.address);
|
|
|
|
|
+ const accounts = await web3.eth.getAccounts();
|
|
|
|
|
+
|
|
|
|
|
+ let data = "0x00000000000000000000000000000000000000000000000000000000436f726504";
|
|
|
|
|
+ data += [
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint16", testChainId).substring(2 + (64 - 4)),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint256", 1).substring(2),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("address", "0x0000000000000000000000000000000000000000").substring(2),
|
|
|
|
|
+ ].join('')
|
|
|
|
|
+
|
|
|
|
|
+ const vm = await signAndEncodeVM(
|
|
|
|
|
+ 0,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ testGovernanceChainId,
|
|
|
|
|
+ "0x00000000000000000000000000000000000000000000000000000000436f7265",
|
|
|
|
|
+ data,
|
|
|
|
|
+ [
|
|
|
|
|
+ testSigner1PK,
|
|
|
|
|
+ testSigner2PK,
|
|
|
|
|
+ testSigner3PK,
|
|
|
|
|
+ ],
|
|
|
|
|
+ 1
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
- // Lock assets
|
|
|
|
|
- let ev = await bridge.lockAssets(token.address, "1000000005", "0x1230000000000000000000000000000000000000000000000000000000000000", 3, 3, false);
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ await initialized.methods.submitTransferFees("0x" + vm).send({
|
|
|
|
|
+ value : 0,
|
|
|
|
|
+ from : accounts[0],
|
|
|
|
|
+ gasLimit : 1000000
|
|
|
|
|
+ });
|
|
|
|
|
+ asset.fail("governance packet from wrong governance contract accepted")
|
|
|
|
|
+ } catch(e) {
|
|
|
|
|
+ assert.equal(e.data[Object.keys(e.data)[0]].reason, "wrong governance contract")
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it("should revert on governance packets that already have been applied", async function(){
|
|
|
|
|
+ const initialized = new web3.eth.Contract(ImplementationFullABI, Wormhole.address);
|
|
|
|
|
+ const accounts = await web3.eth.getAccounts();
|
|
|
|
|
+
|
|
|
|
|
+ let data = "0x00000000000000000000000000000000000000000000000000000000436f726504";
|
|
|
|
|
+ data += [
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint16", testChainId).substring(2 + (64 - 4)),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint256", 1).substring(2),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("address", "0x0000000000000000000000000000000000000000").substring(2),
|
|
|
|
|
+ ].join('')
|
|
|
|
|
+
|
|
|
|
|
+ const vm = await signAndEncodeVM(
|
|
|
|
|
+ 0,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ testGovernanceChainId,
|
|
|
|
|
+ testGovernanceContract,
|
|
|
|
|
+ data,
|
|
|
|
|
+ [
|
|
|
|
|
+ testSigner1PK,
|
|
|
|
|
+ testSigner2PK,
|
|
|
|
|
+ testSigner3PK,
|
|
|
|
|
+ ],
|
|
|
|
|
+ 1
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ await initialized.methods.submitTransferFees("0x" + vm).send({
|
|
|
|
|
+ value : 0,
|
|
|
|
|
+ from : accounts[0],
|
|
|
|
|
+ gasLimit : 1000000
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- // Check that dust was not subtracted
|
|
|
|
|
- assert.lengthOf(ev.logs, 1)
|
|
|
|
|
- assert.equal(ev.logs[0].event, "LogTokensLocked")
|
|
|
|
|
- assert.equal(ev.logs[0].args.amount, "1")
|
|
|
|
|
- assert.equal(await token.balanceOf("0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1"), "4000000095");
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ await initialized.methods.submitTransferFees("0x" + vm).send({
|
|
|
|
|
+ value : 0,
|
|
|
|
|
+ from : accounts[0],
|
|
|
|
|
+ gasLimit : 1000000
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ asset.fail("governance packet accepted twice")
|
|
|
|
|
+ } catch(e) {
|
|
|
|
|
+ assert.equal(e.data[Object.keys(e.data)[0]].reason, "governance action already consumed")
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+});
|
|
|
|
|
|
|
|
- // Lock assets
|
|
|
|
|
- ev = await bridge.lockAssets(token.address, "1000000005", "0x1230000000000000000000000000000000000000000000000000000000000000", 3, 3, true);
|
|
|
|
|
|
|
+const signAndEncodeVM = async function(
|
|
|
|
|
+ timestamp,
|
|
|
|
|
+ nonce,
|
|
|
|
|
+ emitterChainId,
|
|
|
|
|
+ emitterAddress,
|
|
|
|
|
+ data,
|
|
|
|
|
+
|
|
|
|
|
+ signers,
|
|
|
|
|
+ guardianSetIndex
|
|
|
|
|
+){
|
|
|
|
|
+ const body = [
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint32", timestamp).substring(2 + (64 - 8)),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint32", nonce).substring(2 + (64 - 8)),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint16", emitterChainId).substring(2 + (64 - 4)),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("bytes32", emitterAddress).substring(2),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint8", data.length / 2 - 1).substring(2 + (64 - 2)),
|
|
|
|
|
+ data.substr(2)
|
|
|
|
|
+ ]
|
|
|
|
|
+
|
|
|
|
|
+ const hash = web3.utils.soliditySha3("0x"+body.join(""))
|
|
|
|
|
+
|
|
|
|
|
+ let signatures = "";
|
|
|
|
|
+
|
|
|
|
|
+ for(let i in signers){
|
|
|
|
|
+ const ec = new elliptic.ec("secp256k1");
|
|
|
|
|
+ const key = ec.keyFromPrivate(signers[i]);
|
|
|
|
|
+ const signature = key.sign(hash.substr(2), { canonical: true });
|
|
|
|
|
+
|
|
|
|
|
+ const packSig = [
|
|
|
|
|
+ zeroPadBytes(signature.r.toString(16), 32),
|
|
|
|
|
+ zeroPadBytes(signature.s.toString(16), 32),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint8", signature.recoveryParam).substr(2 + (64 - 2)),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint8", i).substring(2 + (64 - 2))
|
|
|
|
|
+ ]
|
|
|
|
|
+
|
|
|
|
|
+ signatures += packSig.join("")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const vm = [
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint8", 1).substring(2 + (64 - 2)),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint32", guardianSetIndex).substring(2 + (64 - 8)),
|
|
|
|
|
+ web3.eth.abi.encodeParameter("uint8", signers.length).substring(2 + (64 - 2)),
|
|
|
|
|
+
|
|
|
|
|
+ signatures,
|
|
|
|
|
+ body.join("")
|
|
|
|
|
+ ].join("");
|
|
|
|
|
+
|
|
|
|
|
+ return vm
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- // Check that dust was refunded
|
|
|
|
|
- assert.lengthOf(ev.logs, 1)
|
|
|
|
|
- assert.equal(ev.logs[0].event, "LogTokensLocked")
|
|
|
|
|
- assert.equal(ev.logs[0].args.amount, "1")
|
|
|
|
|
- assert.equal((await token.balanceOf("0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1")).toString(), "3000000095");
|
|
|
|
|
- });
|
|
|
|
|
-});
|
|
|
|
|
|
|
+function zeroPadBytes(value, length) {
|
|
|
|
|
+ while (value.length < 2 * length) {
|
|
|
|
|
+ value = "0" + value;
|
|
|
|
|
+ }
|
|
|
|
|
+ return value;
|
|
|
|
|
+}
|