From 5a8e0373c1403920ff3f4f8c79f5dda215553ed5 Mon Sep 17 00:00:00 2001 From: salman01zp Date: Tue, 16 May 2023 12:56:54 +0530 Subject: [PATCH 1/9] dkg test on CI --- tests/test/substrate/governorUpdate.test.ts | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/test/substrate/governorUpdate.test.ts b/tests/test/substrate/governorUpdate.test.ts index 0c9658a1c..d15d6ea86 100644 --- a/tests/test/substrate/governorUpdate.test.ts +++ b/tests/test/substrate/governorUpdate.test.ts @@ -28,9 +28,8 @@ import { LocalTangle } from '../../lib/localTangle.js'; import { u8aToHex } from '@polkadot/util'; import { UsageMode } from '@webb-tools/test-utils'; import { defaultEventsWatcherValue } from '../../lib/utils.js'; -import { timeout } from '../../lib/timeout.js'; -describe.skip('Substrate SignatureBridge Governor Update', function () { +describe.only('Substrate SignatureBridge Governor Update', function () { const tmpDirPath = temp.mkdirSync(); // Tangle nodes let aliceNode: LocalTangle; @@ -81,7 +80,7 @@ describe.skip('Substrate SignatureBridge Governor Update', function () { // Wait until we are ready and connected const api = await aliceNode.api(); await api.isReady; - console.log('substrate node ready'); + console.log('tangle node ready waiting for dkg public key to be set onchain'); const chainId = await aliceNode.getChainId(); // Step 2. We need to wait until the public key is on chain. @@ -122,17 +121,18 @@ describe.skip('Substrate SignatureBridge Governor Update', function () { await webbRelayer.waitUntilReady(); }); - it('ownership should be transfered when the DKG rotates', async () => { + it('ownership should be transferred when the DKG rotates', async () => { // Now we just need to force the DKG to rotate/refresh. const api = await aliceNode.api(); - const forceChangeAuthorities = api.tx.dkg.forceChangeAuthorities(); - - await timeout( - aliceNode.sudoExecuteTransaction(forceChangeAuthorities), - 30_000 - ); - // Now we just need for the relayer to pick up the new DKG events. const chainId = await aliceNode.getChainId(); + await webbRelayer.waitForEvent({ + kind: 'signature_bridge', + event: { + call: 'transfer_ownership_with_signature_pub_key', + chain_id: chainId.toString(), + }, + }); + // Now we just need for the relayer to pick up the new DKG events. await webbRelayer.waitForEvent({ kind: 'tx_queue', event: { @@ -156,4 +156,4 @@ describe.skip('Substrate SignatureBridge Governor Update', function () { await charlieNode?.stop(); await webbRelayer?.stop(); }); -}); +}); \ No newline at end of file From a503da41867ec426681c7adb9e475c355e1b1351 Mon Sep 17 00:00:00 2001 From: salman01zp Date: Tue, 16 May 2023 13:17:32 +0530 Subject: [PATCH 2/9] Update CI: build relayer before executing test --- .github/workflows/check.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 7cb8fa15c..4f23c9e57 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -183,6 +183,9 @@ jobs: - name: Install Node Packages. run: cd tests && dvc pull && yarn + - name: Build relayer + run: cargo build --features integration-tests,cli,native-tls/vendored + - name: Pull Docker Images used for testing. run: docker pull ghcr.io/webb-tools/tangle/tangle-standalone-integration-tests:main From 614c1838dfd7138e74a25fdfbe49e9d43d0ef308 Mon Sep 17 00:00:00 2001 From: salman01zp Date: Tue, 16 May 2023 18:42:55 +0530 Subject: [PATCH 3/9] update and fix dkg tests --- tests/test/evm/governorUpdates.test.ts | 31 +- tests/test/{ => evm}/proposals.test.ts | 118 ++-- tests/test/signatureBridge.test.ts | 595 -------------------- tests/test/substrate/governorUpdate.test.ts | 2 +- 4 files changed, 93 insertions(+), 653 deletions(-) rename tests/test/{ => evm}/proposals.test.ts (83%) delete mode 100644 tests/test/signatureBridge.test.ts diff --git a/tests/test/evm/governorUpdates.test.ts b/tests/test/evm/governorUpdates.test.ts index f17f04270..6b0aaa830 100644 --- a/tests/test/evm/governorUpdates.test.ts +++ b/tests/test/evm/governorUpdates.test.ts @@ -25,7 +25,6 @@ import temp from 'temp'; import retry from 'async-retry'; import { LocalChain } from '../../lib/localTestnet.js'; import { sleep } from '../../lib/sleep.js'; -import { timeout } from '../../lib/timeout.js'; import { Pallet, WebbRelayer, @@ -45,7 +44,7 @@ import { MintableToken } from '@webb-tools/tokens'; Chai.use(ChaiAsPromised); // FIXME: this test is skipped since there is an issue with manual DKG Refresh. -describe.skip('SignatureBridge Governor Updates', function () { +describe('SignatureBridge Governor Updates', function () { const tmpDirPath = temp.mkdirSync(); let localChain1: LocalChain; let localChain2: LocalChain; @@ -94,8 +93,12 @@ describe.skip('SignatureBridge Governor Updates', function () { ports: 'auto', enableLogging: false, }); - + // Wait until we are ready and connected + const api = await charlieNode.api(); + await api.isReady; + console.log('tangle node ready waiting for dkg public key to be set onchain'); const chainId = await charlieNode.getChainId(); + await charlieNode.writeConfig(`${tmpDirPath}/${charlieNode.name}.json`, { suri: '//Charlie', chainId: chainId, @@ -105,7 +108,7 @@ describe.skip('SignatureBridge Governor Updates', function () { // we need to wait until the public key is on chain. await charlieNode.waitForEvent({ section: 'dkg', - method: 'PublicKeySubmitted', + method: 'PublicKeySignatureChanged', }); // next we need to start local evm node. @@ -189,8 +192,8 @@ describe.skip('SignatureBridge Governor Updates', function () { }); // fetch the dkg public key. const dkgPublicKey = await charlieNode.fetchDkgPublicKey(); - expect(dkgPublicKey).to.not.be.null; - const governorAddress = ethAddressFromUncompressedPublicKey(dkgPublicKey!); + expect(dkgPublicKey).to.not.equal('0x'); + const governorAddress = ethAddressFromUncompressedPublicKey(dkgPublicKey); // verify the governor address is a valid ethereum address. expect(ethers.utils.isAddress(governorAddress)).to.be.true; // transfer ownership to the DKG. @@ -250,7 +253,6 @@ describe.skip('SignatureBridge Governor Updates', function () { await tx.wait(); await token2.mintTokens(wallet2.address, ethers.utils.parseEther('1000')); - const api = await charlieNode.api(); const resourceId1 = await anchor.createResourceId(); const resourceId2 = await anchor2.createResourceId(); @@ -268,22 +270,13 @@ describe.skip('SignatureBridge Governor Updates', function () { }, tmp: true, configDir: tmpDirPath, - showLogs: false, + showLogs: true, verbosity: 3, }); await webbRelayer.waitUntilReady(); }); it('ownership should be transfered when the DKG rotates', async () => { - // now we just need to force the DKG to rotate/refresh. - const api = await charlieNode.api(); - const forceIncrementNonce = api.tx.dkg.manualIncrementNonce!(); - const forceRefresh = api.tx.dkg.manualRefresh!(); - await timeout( - charlieNode.sudoExecuteTransaction(forceIncrementNonce), - 30_000 - ); - await timeout(charlieNode.sudoExecuteTransaction(forceRefresh), 60_000); // now we just need for the relayer to pick up the new DKG events. // and update both chains' signature bridge governor. await Promise.all([ @@ -308,8 +301,8 @@ describe.skip('SignatureBridge Governor Updates', function () { await sleep(1000); // now we need to check that the ownership was transfered. const dkgPublicKey = await charlieNode.fetchDkgPublicKey(); - expect(dkgPublicKey).to.not.be.null; - const governorAddress = ethAddressFromUncompressedPublicKey(dkgPublicKey!); + expect(dkgPublicKey).to.not.equal('0x'); + const governorAddress = ethAddressFromUncompressedPublicKey(dkgPublicKey); const sides = signatureBridge.vBridgeSides.values(); for (const signatureSide of sides) { const contract = signatureSide.contract; diff --git a/tests/test/proposals.test.ts b/tests/test/evm/proposals.test.ts similarity index 83% rename from tests/test/proposals.test.ts rename to tests/test/evm/proposals.test.ts index bfe699abc..cdd409c5b 100644 --- a/tests/test/proposals.test.ts +++ b/tests/test/evm/proposals.test.ts @@ -16,7 +16,7 @@ */ // Testing different kind of proposals between DKG <=> Relayer <=> Signature Bridge. - +import '@webb-tools/tangle-substrate-types'; import Chai, { expect } from 'chai'; import ChaiAsPromised from 'chai-as-promised'; import { Tokens, VBridge } from '@webb-tools/protocol-solidity'; @@ -24,14 +24,14 @@ import { u8aToHex } from '@polkadot/util'; import { ethers } from 'ethers'; import temp from 'temp'; import retry from 'async-retry'; -import { LocalChain } from '../lib/localTestnet.js'; -import { Pallet, WebbRelayer, EnabledContracts } from '../lib/webbRelayer.js'; +import { LocalChain } from '../../lib/localTestnet.js'; +import { Pallet, WebbRelayer, EnabledContracts } from '../../lib/webbRelayer.js'; import getPort, { portNumbers } from 'get-port'; -import { LocalTangle } from '../lib/localTangle.js'; +import { LocalTangle } from '../../lib/localTangle.js'; import isCi from 'is-ci'; import path from 'path'; -import { ethAddressFromUncompressedPublicKey } from '../lib/ethHelperFunctions.js'; -import { sleep } from '../lib/sleep.js'; +import { ethAddressFromUncompressedPublicKey } from '../../lib/ethHelperFunctions.js'; +import { sleep } from '../../lib/sleep.js'; import { ProposalHeader, ResourceId, @@ -42,21 +42,20 @@ import { import { hexToU8a } from '@polkadot/util'; import { ChainType } from '@webb-tools/sdk-core'; import { UsageMode } from '@webb-tools/test-utils'; -import { defaultEventsWatcherValue } from '../lib/utils.js'; +import { defaultEventsWatcherValue } from '../../lib/utils.js'; import { MintableToken } from '@webb-tools/tokens'; // to support chai-as-promised Chai.use(ChaiAsPromised); -describe.skip('Proposals (DKG <=> Relayer <=> SigBridge)', function () { - // 8 minutes - this.timeout(8 * 60 * 1000); +describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { const tmpDirPath = temp.mkdirSync(); let localChain1: LocalChain; let localChain2: LocalChain; let signatureBridge: VBridge.VBridge; let wallet1: ethers.Wallet; let wallet2: ethers.Wallet; + let relayerWallet1: ethers.Wallet; // dkg nodes let aliceNode: LocalTangle; @@ -65,10 +64,9 @@ describe.skip('Proposals (DKG <=> Relayer <=> SigBridge)', function () { let webbRelayer: WebbRelayer; before(async function () { - // Only run these tests in CI - if (!isCi) this.skip(); const PK1 = u8aToHex(ethers.utils.randomBytes(32)); const PK2 = u8aToHex(ethers.utils.randomBytes(32)); + const relayerPk = u8aToHex(ethers.utils.randomBytes(32)); const usageMode: UsageMode = isCi ? { mode: 'host', nodePath: 'dkg-standalone-node' } : { @@ -82,12 +80,18 @@ describe.skip('Proposals (DKG <=> Relayer <=> SigBridge)', function () { pallet: 'DKGProposalHandler', eventsWatcher: defaultEventsWatcherValue, }, + { + pallet: 'DKG', + eventsWatcher: defaultEventsWatcherValue, + }, ]; aliceNode = await LocalTangle.start({ name: 'substrate-alice', authority: 'alice', usageMode, ports: 'auto', + enableLogging: false, + }); charlieNode = await LocalTangle.start({ @@ -98,8 +102,11 @@ describe.skip('Proposals (DKG <=> Relayer <=> SigBridge)', function () { enableLogging: false, }); - // get chainId + const api = await charlieNode.api(); + await api.isReady; + console.log('tangle node ready waiting for dkg public key to be set onchain'); const chainId = await charlieNode.getChainId(); + await charlieNode.writeConfig(`${tmpDirPath}/${charlieNode.name}.json`, { suri: '//Charlie', chainId: chainId, @@ -109,7 +116,7 @@ describe.skip('Proposals (DKG <=> Relayer <=> SigBridge)', function () { // we need to wait until the public key is on chain. await charlieNode.waitForEvent({ section: 'dkg', - method: 'PublicKeySubmitted', + method: 'PublicKeySignatureChanged', }); // next we need to start local evm node. @@ -119,7 +126,7 @@ describe.skip('Proposals (DKG <=> Relayer <=> SigBridge)', function () { const enabledContracts: EnabledContracts[] = [ { - contract: 'Anchor', + contract: 'VAnchor', }, ]; localChain1 = await LocalChain.init({ @@ -131,6 +138,10 @@ describe.skip('Proposals (DKG <=> Relayer <=> SigBridge)', function () { secretKey: PK1, balance: ethers.utils.parseEther('1000').toHexString(), }, + { + secretKey: relayerPk, + balance: ethers.utils.parseEther('1000').toHexString(), + }, ], enabledContracts: enabledContracts, }); @@ -148,12 +159,17 @@ describe.skip('Proposals (DKG <=> Relayer <=> SigBridge)', function () { secretKey: PK2, balance: ethers.utils.parseEther('1000').toHexString(), }, + { + secretKey: relayerPk, + balance: ethers.utils.parseEther('1000').toHexString(), + }, ], enabledContracts: enabledContracts, }); wallet1 = new ethers.Wallet(PK1, localChain1.provider()); wallet2 = new ethers.Wallet(PK2, localChain2.provider()); + relayerWallet1 = new ethers.Wallet(relayerPk, localChain1.provider()); // Deploy the token. const wrappedToken1 = await localChain1.deployToken( 'Wrapped Ethereum', @@ -187,15 +203,17 @@ describe.skip('Proposals (DKG <=> Relayer <=> SigBridge)', function () { await localChain1.writeConfig(`${tmpDirPath}/${localChain1.name}.json`, { signatureVBridge: signatureBridge, proposalSigningBackend: { type: 'DKGNode', chainId }, + relayerWallet: relayerWallet1 }); await localChain2.writeConfig(`${tmpDirPath}/${localChain2.name}.json`, { signatureVBridge: signatureBridge, proposalSigningBackend: { type: 'DKGNode', chainId }, + relayerWallet: relayerWallet1 }); // fetch the dkg public key. const dkgPublicKey = await charlieNode.fetchDkgPublicKey(); - expect(dkgPublicKey).to.not.be.null; - const governorAddress = ethAddressFromUncompressedPublicKey(dkgPublicKey!); + expect(dkgPublicKey).to.not.equal('0x'); + const governorAddress = ethAddressFromUncompressedPublicKey(dkgPublicKey); // verify the governor address is a valid ethereum address. expect(ethers.utils.isAddress(governorAddress)).to.be.true; // transfer ownership to the DKG. @@ -255,7 +273,6 @@ describe.skip('Proposals (DKG <=> Relayer <=> SigBridge)', function () { await tx.wait(); await token2.mintTokens(wallet2.address, ethers.utils.parseEther('1000')); - const api = await charlieNode.api(); const resourceId1 = await anchor.createResourceId(); const resourceId2 = await anchor2.createResourceId(); const governedTokenAddress = anchor.token!; @@ -276,10 +293,11 @@ describe.skip('Proposals (DKG <=> Relayer <=> SigBridge)', function () { webbRelayer = new WebbRelayer({ tmp: true, commonConfig: { + features: { privateTxRelay: false }, port: relayerPort, }, configDir: tmpDirPath, - showLogs: false, + showLogs: true, verbosity: 3, }); await webbRelayer.waitUntilReady(); @@ -302,18 +320,19 @@ describe.skip('Proposals (DKG <=> Relayer <=> SigBridge)', function () { const resourceId = ResourceId.newFromContractAddress( governedTokenAddress, ChainType.EVM, - await governedToken.signer.getChainId() + localChain1.underlyingChainId ); const functionSignature = hexToU8a( governedToken.contract.interface.getSighash( - governedToken.contract.interface.functions['add(address,uint256)'] + governedToken.contract.interface.functions['add(address,uint32)'] ) ); const nonce = await governedToken.contract.proposalNonce(); + console.log("Proposal nonce: ", nonce.toString()); const proposalHeader = new ProposalHeader( resourceId, functionSignature, - nonce.toNumber() + nonce.add(1).toNumber() ); const tokenAddProposal = new TokenAddProposal( proposalHeader, @@ -331,7 +350,10 @@ describe.skip('Proposals (DKG <=> Relayer <=> SigBridge)', function () { // now we wait for the proposal to be executed by the relayer then by the Signature Bridge. await webbRelayer.waitForEvent({ kind: 'signature_bridge', - event: { chain_id: localChain1.underlyingChainId.toString() }, + event: { + chain_id: localChain1.underlyingChainId.toString(), + call: 'execute_proposal_with_signature', + }, }); // now we wait for the tx queue on that chain to execute the transaction. await webbRelayer.waitForEvent({ @@ -342,14 +364,19 @@ describe.skip('Proposals (DKG <=> Relayer <=> SigBridge)', function () { finalized: true, }, }); - await sleep(1000); + await sleep(5000); // now we check that the token was added. const tokens = await governedToken.contract.getTokens(); expect(tokens.includes(testToken.contract.address)).to.eq(true); }); it('should handle TokenRemoveProposal', async () => { - // get the anhor on localchain1 + // we need to wait until the public key is on chain. + await charlieNode.waitForEvent({ + section: 'dkg', + method: 'PublicKeySignatureChanged', + }); + // get the anchor on localchain1 const anchor = signatureBridge.getVAnchor(localChain1.chainId); const governedTokenAddress = anchor.token!; const governedToken = Tokens.FungibleTokenWrapper.connect( @@ -364,26 +391,29 @@ describe.skip('Proposals (DKG <=> Relayer <=> SigBridge)', function () { const resourceId = ResourceId.newFromContractAddress( governedTokenAddress, ChainType.EVM, - await governedToken.signer.getChainId() + localChain1.underlyingChainId ); const functionSignature = hexToU8a( governedToken.contract.interface.getSighash( - governedToken.contract.interface.functions['remove(address,uint256)'] + governedToken.contract.interface.functions['remove(address,uint32)'] ) ); const nonce = await governedToken.contract.proposalNonce(); + console.log("Proposal nonce: ", nonce.toString()); const proposalHeader = new ProposalHeader( resourceId, functionSignature, - nonce.toNumber() + nonce.add(1).toNumber() ); - const tokenAddProposal = new TokenRemoveProposal( + const tokenRemoveProposal = new TokenRemoveProposal( proposalHeader, tokenToRemove! ); + + await forceSubmitUnsignedProposal(charlieNode, { kind: 'TokenRemove', - data: u8aToHex(tokenAddProposal.toU8a()), + data: u8aToHex(tokenRemoveProposal.toU8a()), }); // now we wait for the proposal to be signed. charlieNode.waitForEvent({ @@ -393,7 +423,10 @@ describe.skip('Proposals (DKG <=> Relayer <=> SigBridge)', function () { // now we wait for the proposal to be executed by the relayer then by the Signature Bridge. await webbRelayer.waitForEvent({ kind: 'signature_bridge', - event: { chain_id: localChain1.underlyingChainId.toString() }, + event: { + chain_id: localChain1.underlyingChainId.toString(), + call: 'execute_proposal_with_signature', + }, }); // now we wait for the tx queue on that chain to execute the transaction. await webbRelayer.waitForEvent({ @@ -404,13 +437,18 @@ describe.skip('Proposals (DKG <=> Relayer <=> SigBridge)', function () { finalized: true, }, }); - await sleep(1000); + await sleep(10000); // now we check that the token was removed. const tokens = await governedToken.contract.getTokens(); expect(tokens.includes(tokenToRemove!)).to.eq(false); }); it('should handle WrappingFeeUpdateProposal', async () => { + // we need to wait until the public key is on chain. + await charlieNode.waitForEvent({ + section: 'dkg', + method: 'PublicKeySignatureChanged', + }); // get the anhor on localchain1 const anchor = signatureBridge.getVAnchor(localChain1.chainId); const governedTokenAddress = anchor.token!; @@ -424,15 +462,16 @@ describe.skip('Proposals (DKG <=> Relayer <=> SigBridge)', function () { localChain1.underlyingChainId ); const nonce = await governedToken.contract.proposalNonce(); + console.log("Proposal nonce: ", nonce.toString()); const functionSignature = hexToU8a( governedToken.contract.interface.getSighash( - governedToken.contract.interface.functions['setFee(uint8,uint256)'] + governedToken.contract.interface.functions['setFee(uint16,uint32)'] ) ); const proposalHeader = new ProposalHeader( resourceId, functionSignature, - nonce.toNumber() + nonce.add(1).toNumber() ); webbRelayer.clearLogs(); const newFee = ethers.utils.hexValue(50); @@ -452,7 +491,10 @@ describe.skip('Proposals (DKG <=> Relayer <=> SigBridge)', function () { // now we wait for the proposal to be executed by the relayer then by the Signature Bridge. await webbRelayer.waitForEvent({ kind: 'signature_bridge', - event: { chain_id: localChain1.underlyingChainId.toString() }, + event: { + chain_id: localChain1.underlyingChainId.toString(), + call: 'execute_proposal_with_signature', + }, }); // now we wait for the tx queue on that chain to execute the transaction. await webbRelayer.waitForEvent({ @@ -463,7 +505,7 @@ describe.skip('Proposals (DKG <=> Relayer <=> SigBridge)', function () { finalized: true, }, }); - await sleep(1000); + await sleep(10000); const fee = await governedToken.contract.getFee(); expect(newFee).to.eq(ethers.utils.hexValue(fee)); }); @@ -488,11 +530,11 @@ async function forceSubmitUnsignedProposal( ) { const api = await node.api(); const kind = api.createType( - 'DkgRuntimePrimitivesProposalProposalKind', + 'WebbProposalsProposalProposalKind', opts.kind ); const proposal = api - .createType('DkgRuntimePrimitivesProposal', { + .createType('WebbProposalsProposal', { Unsigned: { kind, data: opts.data, diff --git a/tests/test/signatureBridge.test.ts b/tests/test/signatureBridge.test.ts deleted file mode 100644 index 8c9991af6..000000000 --- a/tests/test/signatureBridge.test.ts +++ /dev/null @@ -1,595 +0,0 @@ -/* - * Copyright 2022 Webb Technologies Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -// A simple test for the Signature Bridge with the Relayer and the DKG. - -import Chai, { expect } from 'chai'; -import ChaiAsPromised from 'chai-as-promised'; -import { Tokens, VBridge } from '@webb-tools/protocol-solidity'; -import { hexToU8a, u8aToHex } from '@polkadot/util'; -import { BigNumber, ethers } from 'ethers'; -import temp from 'temp'; -import retry from 'async-retry'; -import { LocalChain } from '../lib/localTestnet.js'; -import { Pallet, WebbRelayer, EnabledContracts } from '../lib/webbRelayer.js'; -import getPort, { portNumbers } from 'get-port'; -import { LocalTangle } from '../lib/localTangle.js'; -import isCi from 'is-ci'; -import path from 'path'; -import { ethAddressFromUncompressedPublicKey } from '../lib/ethHelperFunctions.js'; -import { CircomUtxo, Keypair } from '@webb-tools/sdk-core'; -import { UsageMode } from '@webb-tools/test-utils'; -import { defaultEventsWatcherValue } from '../lib/utils.js'; -import { MintableToken } from '@webb-tools/tokens'; - -// to support chai-as-promised -Chai.use(ChaiAsPromised); - -describe.skip('Signature Bridge <> DKG Proposal Signing Backend', function () { - this.timeout(5 * 60 * 1000); - const tmpDirPath = temp.mkdirSync(); - let localChain1: LocalChain; - let localChain2: LocalChain; - let signatureBridge: VBridge.VBridge; - let wallet1: ethers.Wallet; - let wallet2: ethers.Wallet; - - // dkg nodes - let aliceNode: LocalTangle; - let charlieNode: LocalTangle; - - let webbRelayer: WebbRelayer; - - before(async function () { - // skip this test if we are locally running, only run on the CI - if (!isCi) this.skip(); - const PK1 = u8aToHex(ethers.utils.randomBytes(32)); - const PK2 = u8aToHex(ethers.utils.randomBytes(32)); - const usageMode: UsageMode = isCi - ? { mode: 'host', nodePath: 'dkg-standalone-node' } - : { - mode: 'host', - nodePath: path.resolve( - '../../tangle/target/release/tangle-standalone' - ), - }; - const enabledPallets: Pallet[] = [ - { - pallet: 'DKGProposalHandler', - eventsWatcher: defaultEventsWatcherValue, - }, - ]; - aliceNode = await LocalTangle.start({ - name: 'substrate-alice', - authority: 'alice', - usageMode, - ports: 'auto', - }); - - charlieNode = await LocalTangle.start({ - name: 'substrate-charlie', - authority: 'charlie', - usageMode, - ports: 'auto', - enableLogging: false, - }); - // get chainId - const chainId = await charlieNode.getChainId(); - await charlieNode.writeConfig(`${tmpDirPath}/${charlieNode.name}.json`, { - suri: '//Charlie', - chainId: chainId, - enabledPallets, - }); - - // we need to wait until the public key is on chain. - await charlieNode.waitForEvent({ - section: 'dkg', - method: 'PublicKeySubmitted', - }); - - // next we need to start local evm node. - const localChain1Port = await getPort({ - port: portNumbers(3333, 4444), - }); - - const enabledContracts: EnabledContracts[] = [ - { - contract: 'Anchor', - }, - ]; - - localChain1 = await LocalChain.init({ - port: localChain1Port, - chainId: localChain1Port, - name: 'Hermes', - populatedAccounts: [ - { - secretKey: PK1, - balance: ethers.utils.parseEther('1000').toHexString(), - }, - ], - enabledContracts: enabledContracts, - }); - - const localChain2Port = await getPort({ - port: portNumbers(3333, 4444), - }); - - localChain2 = await LocalChain.init({ - port: localChain2Port, - chainId: localChain2Port, - name: 'Athena', - populatedAccounts: [ - { - secretKey: PK2, - balance: ethers.utils.parseEther('1000').toHexString(), - }, - ], - enabledContracts: enabledContracts, - }); - - wallet1 = new ethers.Wallet(PK1, localChain1.provider()); - wallet2 = new ethers.Wallet(PK2, localChain2.provider()); - // Deploy the token. - const wrappedToken1 = await localChain1.deployToken( - 'Wrapped Ethereum', - 'WETH' - ); - const wrappedToken2 = await localChain2.deployToken( - 'Wrapped Ethereum', - 'WETH' - ); - const unwrappedToken1 = await MintableToken.createToken( - 'Webb Token', - 'WEBB', - wallet1 - ); - const unwrappedToken2 = await MintableToken.createToken( - 'Webb Token', - 'WEBB', - wallet2 - ); - - signatureBridge = await localChain1.deploySignatureVBridge( - localChain2, - wrappedToken1, - wrappedToken2, - wallet1, - wallet2, - unwrappedToken1, - unwrappedToken2 - ); - // save the chain configs. - await localChain1.writeConfig(`${tmpDirPath}/${localChain1.name}.json`, { - signatureVBridge: signatureBridge, - proposalSigningBackend: { type: 'DKGNode', chainId }, - }); - await localChain2.writeConfig(`${tmpDirPath}/${localChain2.name}.json`, { - signatureVBridge: signatureBridge, - proposalSigningBackend: { type: 'DKGNode', chainId }, - }); - // fetch the dkg public key. - const dkgPublicKey = await charlieNode.fetchDkgPublicKey(); - expect(dkgPublicKey).to.not.be.null; - const governorAddress = ethAddressFromUncompressedPublicKey(dkgPublicKey!); - // verify the governor address is a valid ethereum address. - expect(ethers.utils.isAddress(governorAddress)).to.be.true; - // transfer ownership to the DKG. - const sides = signatureBridge.vBridgeSides.values(); - for (const signatureSide of sides) { - // now we transferOwnership, forcefully. - const tx = await signatureSide.transferOwnership(governorAddress, 1); - await retry( - async () => { - await tx.wait(); - }, - { - retries: 5, - minTimeout: 1000, - onRetry: (error) => { - console.error('transferOwnership retry', error.name, error.message); - }, - } - ); - // check that the new governor is the same as the one we just set. - const currentGovernor = await signatureSide.contract.governor(); - expect(currentGovernor).to.eq(governorAddress); - } - // get the anhor on localchain1 - const anchor = signatureBridge.getVAnchor(localChain1.chainId); - await anchor.setSigner(wallet1); - // approve token spending - const tokenAddress = signatureBridge.getWebbTokenAddress( - localChain1.chainId - )!; - const token = await Tokens.MintableToken.tokenFromAddress( - tokenAddress, - wallet1 - ); - let tx = await token.approveSpending( - anchor.contract.address, - ethers.utils.parseEther('1000') - ); - await tx.wait(); - await token.mintTokens(wallet1.address, ethers.utils.parseEther('1000')); - - // do the same but on localchain2 - const anchor2 = signatureBridge.getVAnchor(localChain2.chainId); - await anchor2.setSigner(wallet2); - const tokenAddress2 = signatureBridge.getWebbTokenAddress( - localChain2.chainId - )!; - const token2 = await Tokens.MintableToken.tokenFromAddress( - tokenAddress2, - wallet2 - ); - - tx = await token2.approveSpending( - anchor2.contract.address, - ethers.utils.parseEther('1000') - ); - await tx.wait(); - await token2.mintTokens(wallet2.address, ethers.utils.parseEther('1000')); - - const api = await charlieNode.api(); - const resourceId1 = await anchor.createResourceId(); - const resourceId2 = await anchor2.createResourceId(); - - const call = (resourceId: string) => - api.tx.dkgProposals.setResource(resourceId, '0x00'); - // register the resource on DKG node. - for (const rid of [resourceId1, resourceId2]) { - await charlieNode.sudoExecuteTransaction(call(rid)); - } - // now start the relayer - const relayerPort = await getPort({ port: portNumbers(9955, 9999) }); - webbRelayer = new WebbRelayer({ - commonConfig: { - port: relayerPort, - }, - tmp: true, - configDir: tmpDirPath, - showLogs: false, - verbosity: 3, - }); - await webbRelayer.waitUntilReady(); - }); - - it('should handle AnchorUpdateProposal when a deposit happens using DKG proposal backend', async () => { - // we will use chain1 as an example here. - const anchor1 = signatureBridge.getVAnchor(localChain1.chainId); - const anchor2 = signatureBridge.getVAnchor(localChain2.chainId); - await anchor1.setSigner(wallet1); - const tokenAddress = signatureBridge.getWebbTokenAddress( - localChain1.chainId - )!; - const token = await Tokens.MintableToken.tokenFromAddress( - tokenAddress, - wallet1 - ); - - await token.mintTokens(wallet1.address, ethers.utils.parseEther('1000')); - const webbBalance = await token.getBalance(wallet1.address); - expect(webbBalance.toBigInt() > ethers.utils.parseEther('1').toBigInt()).to - .be.true; - - // Create a deposit utxo - const randomKeypair = new Keypair(); - const depositUtxo = await CircomUtxo.generateUtxo({ - curve: 'Bn254', - backend: 'Circom', - amount: (1e2).toString(), - originChainId: localChain1.chainId.toString(), - chainId: localChain2.chainId.toString(), - keypair: randomKeypair, - }); - - // Make the deposit transaction - await signatureBridge.transact( - [], - [depositUtxo], - 0, - 0, - '0', - '0', - tokenAddress, - wallet1 - ); - - // wait until the signature bridge recives the execute call. - await webbRelayer.waitForEvent({ - kind: 'signature_bridge', - event: { chain_id: localChain2.underlyingChainId.toString() }, - }); - // now we wait for the tx queue on that chain to execute the transaction. - await webbRelayer.waitForEvent({ - kind: 'tx_queue', - event: { - ty: 'EVM', - chain_id: localChain2.underlyingChainId.toString(), - finalized: true, - }, - }); - // all is good, last thing is to check for the roots. - const srcChainRoot = await anchor1.contract.getLastRoot(); - const neigborRoots = await anchor2.contract.getLatestNeighborRoots(); - const edges = await anchor2.contract.getLatestNeighborEdges(); - const isKnownNeighborRoot = neigborRoots.some( - (root: BigNumber) => root.toHexString() === srcChainRoot.toHexString() - ); - if (!isKnownNeighborRoot) { - console.log({ - srcChainRoot, - neigborRoots, - edges, - isKnownNeighborRoot, - }); - } - expect(isKnownNeighborRoot).to.be.true; - }); - - after(async () => { - await aliceNode?.stop(); - await charlieNode?.stop(); - await localChain1?.stop(); - await localChain2?.stop(); - await webbRelayer?.stop(); - }); -}); - -describe('Signature Bridge <> Mocked Proposal Signing Backend', function () { - const tmpDirPath = temp.mkdirSync(); - let localChain1: LocalChain; - let localChain2: LocalChain; - let signatureBridge: VBridge.VBridge; - let wallet1: ethers.Wallet; - let wallet2: ethers.Wallet; - let govWallet: ethers.Wallet; - - let webbRelayer: WebbRelayer; - - before(async () => { - const PK1 = u8aToHex(ethers.utils.randomBytes(32)); - const PK2 = u8aToHex(ethers.utils.randomBytes(32)); - const GOV = u8aToHex(ethers.utils.randomBytes(32)); - const localChain1Port = await getPort({ - port: portNumbers(3333, 4444), - }); - - const enabledContracts: EnabledContracts[] = [ - { - contract: 'VAnchor', - }, - { - contract: 'SignatureBridge', - }, - ]; - - localChain1 = await LocalChain.init({ - port: localChain1Port, - chainId: localChain1Port, - name: 'Hermes', - populatedAccounts: [ - { - secretKey: PK1, - balance: ethers.utils.parseEther('1000').toHexString(), - }, - { - secretKey: GOV, - balance: ethers.utils.parseEther('1000').toHexString(), - }, - ], - enabledContracts: enabledContracts, - }); - - const localChain2Port = await getPort({ - port: portNumbers(3333, 4444), - }); - - localChain2 = await LocalChain.init({ - port: localChain2Port, - chainId: localChain2Port, - name: 'Athena', - populatedAccounts: [ - { - secretKey: PK2, - balance: ethers.utils.parseEther('1000').toHexString(), - }, - { - secretKey: GOV, - balance: ethers.utils.parseEther('1000').toHexString(), - }, - ], - enabledContracts: enabledContracts, - }); - - wallet1 = new ethers.Wallet(PK1, localChain1.provider()); - wallet2 = new ethers.Wallet(PK2, localChain2.provider()); - govWallet = new ethers.Wallet(GOV, localChain1.provider()); - // Deploy the token. - const wrappedToken1 = await localChain1.deployToken( - 'Wrapped Ethereum', - 'WETH' - ); - const wrappedToken2 = await localChain2.deployToken( - 'Wrapped Ethereum', - 'WETH' - ); - const unwrappedToken1 = await MintableToken.createToken( - 'Webb Token', - 'WEBB', - wallet1 - ); - const unwrappedToken2 = await MintableToken.createToken( - 'Webb Token', - 'WEBB', - wallet2 - ); - - signatureBridge = await localChain1.deploySignatureVBridge( - localChain2, - wrappedToken1, - wrappedToken2, - wallet1, - wallet2, - unwrappedToken1, - unwrappedToken2, - { - [localChain1.chainId]: govWallet.address, - [localChain2.chainId]: govWallet.address, - } - ); - - // get the anhor on localchain1 - const anchor = signatureBridge.getVAnchor(localChain1.chainId); - await anchor.setSigner(wallet1); - // approve token spending - const tokenAddress = signatureBridge.getWebbTokenAddress( - localChain1.chainId - )!; - const token = await Tokens.MintableToken.tokenFromAddress( - tokenAddress, - wallet1 - ); - let tx = await token.approveSpending( - anchor.contract.address, - ethers.utils.parseEther('1000') - ); - await tx.wait(); - await token.mintTokens(wallet1.address, ethers.utils.parseEther('1000')); - - // do the same but on localchain2 - const anchor2 = signatureBridge.getVAnchor(localChain2.chainId); - await anchor2.setSigner(wallet2); - const tokenAddress2 = signatureBridge.getWebbTokenAddress( - localChain2.chainId - )!; - const token2 = await Tokens.MintableToken.tokenFromAddress( - tokenAddress2, - wallet2 - ); - - tx = await token2.approveSpending( - anchor2.contract.address, - ethers.utils.parseEther('1000') - ); - await tx.wait(); - await token2.mintTokens(wallet2.address, ethers.utils.parseEther('1000')); - - const resourceId1 = await anchor.createResourceId(); - const resourceId2 = await anchor2.createResourceId(); - // save the chain configs. - await localChain1.writeConfig(`${tmpDirPath}/${localChain1.name}.json`, { - signatureVBridge: signatureBridge, - proposalSigningBackend: { type: 'Mocked', privateKey: GOV }, - linkedAnchors: [{ type: 'Raw', resourceId: resourceId2 }], - }); - await localChain2.writeConfig(`${tmpDirPath}/${localChain2.name}.json`, { - signatureVBridge: signatureBridge, - proposalSigningBackend: { type: 'Mocked', privateKey: GOV }, - linkedAnchors: [{ type: 'Raw', resourceId: resourceId1 }], - }); - - // now start the relayer - const relayerPort = await getPort({ port: portNumbers(9955, 9999) }); - webbRelayer = new WebbRelayer({ - commonConfig: { - port: relayerPort, - }, - tmp: true, - configDir: tmpDirPath, - showLogs: false, - verbosity: 3, - }); - await webbRelayer.waitUntilReady(); - }); - - it('should handle AnchorUpdateProposal when a deposit happens using mocked proposal backend', async () => { - // we will use chain1 as an example here. - const anchor1 = signatureBridge.getVAnchor(localChain1.chainId); - const anchor2 = signatureBridge.getVAnchor(localChain2.chainId); - await anchor1.setSigner(wallet1); - const tokenAddress = signatureBridge.getWebbTokenAddress( - localChain1.chainId - )!; - const token = await Tokens.MintableToken.tokenFromAddress( - tokenAddress, - wallet1 - ); - await token.mintTokens(wallet1.address, ethers.utils.parseEther('1000')); - const webbBalance = await token.getBalance(wallet1.address); - expect(webbBalance.toBigInt() > ethers.utils.parseEther('1').toBigInt()).to - .be.true; - - // Create a deposit utxo - const randomKeypair = new Keypair(); - const depositUtxo = await CircomUtxo.generateUtxo({ - curve: 'Bn254', - backend: 'Circom', - amount: (1e2).toString(), - originChainId: localChain1.chainId.toString(), - chainId: localChain2.chainId.toString(), - keypair: randomKeypair, - }); - - // Make the deposit transaction - - const leaves = anchor1.tree - .elements() - .map((el) => hexToU8a(el.toHexString())); - - await anchor1.transact([], [depositUtxo], 0, 0, '0', '0', tokenAddress, { - [localChain1.chainId]: leaves, - }); - - // wait until the signature bridge recives the execute call. - await webbRelayer.waitForEvent({ - kind: 'signature_bridge', - event: { chain_id: localChain2.underlyingChainId.toString() }, - }); - // now we wait for the tx queue on that chain to execute the transaction. - await webbRelayer.waitForEvent({ - kind: 'tx_queue', - event: { - ty: 'EVM', - chain_id: localChain2.underlyingChainId.toString(), - finalized: true, - }, - }); - // all is good, last thing is to check for the roots. - const srcChainRoot = await anchor1.contract.getLastRoot(); - const neigborRoots = await anchor2.contract.getLatestNeighborRoots(); - const edges = await anchor2.contract.getLatestNeighborEdges(); - const isKnownNeighborRoot = neigborRoots.some( - (root: BigNumber) => root.toHexString() === srcChainRoot.toHexString() - ); - if (!isKnownNeighborRoot) { - console.log({ - srcChainRoot, - neigborRoots, - edges, - isKnownNeighborRoot, - }); - } - expect(isKnownNeighborRoot).to.be.true; - }); - - after(async () => { - await localChain1?.stop(); - await localChain2?.stop(); - await webbRelayer?.stop(); - }); -}); diff --git a/tests/test/substrate/governorUpdate.test.ts b/tests/test/substrate/governorUpdate.test.ts index d15d6ea86..2e0b6a663 100644 --- a/tests/test/substrate/governorUpdate.test.ts +++ b/tests/test/substrate/governorUpdate.test.ts @@ -29,7 +29,7 @@ import { u8aToHex } from '@polkadot/util'; import { UsageMode } from '@webb-tools/test-utils'; import { defaultEventsWatcherValue } from '../../lib/utils.js'; -describe.only('Substrate SignatureBridge Governor Update', function () { +describe('Substrate SignatureBridge Governor Update', function () { const tmpDirPath = temp.mkdirSync(); // Tangle nodes let aliceNode: LocalTangle; From f44899056d8dacd313ae5f63604c715cca85f424 Mon Sep 17 00:00:00 2001 From: salman01zp Date: Tue, 16 May 2023 19:03:08 +0530 Subject: [PATCH 4/9] use docker host --- tests/test/evm/governorUpdates.test.ts | 2 +- tests/test/evm/proposals.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test/evm/governorUpdates.test.ts b/tests/test/evm/governorUpdates.test.ts index 6b0aaa830..03f0c7b62 100644 --- a/tests/test/evm/governorUpdates.test.ts +++ b/tests/test/evm/governorUpdates.test.ts @@ -62,7 +62,7 @@ describe('SignatureBridge Governor Updates', function () { const PK1 = u8aToHex(ethers.utils.randomBytes(32)); const PK2 = u8aToHex(ethers.utils.randomBytes(32)); const usageMode: UsageMode = isCi - ? { mode: 'host', nodePath: 'dkg-standalone-node' } + ? { mode: 'docker', forcePullImage: false } : { mode: 'host', nodePath: path.resolve( diff --git a/tests/test/evm/proposals.test.ts b/tests/test/evm/proposals.test.ts index cdd409c5b..165144994 100644 --- a/tests/test/evm/proposals.test.ts +++ b/tests/test/evm/proposals.test.ts @@ -68,7 +68,7 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { const PK2 = u8aToHex(ethers.utils.randomBytes(32)); const relayerPk = u8aToHex(ethers.utils.randomBytes(32)); const usageMode: UsageMode = isCi - ? { mode: 'host', nodePath: 'dkg-standalone-node' } + ? { mode: 'docker', forcePullImage: false } : { mode: 'host', nodePath: path.resolve( From 269130fb281fc276c4474c5020db58496929d1a0 Mon Sep 17 00:00:00 2001 From: salman01zp Date: Tue, 16 May 2023 22:24:10 +0530 Subject: [PATCH 5/9] add signature bridge test --- tests/test/evm/proposals.test.ts | 4 +- tests/test/evm/signatureBridge.test.ts | 672 +++++++++++++++++++++++++ 2 files changed, 674 insertions(+), 2 deletions(-) create mode 100644 tests/test/evm/signatureBridge.test.ts diff --git a/tests/test/evm/proposals.test.ts b/tests/test/evm/proposals.test.ts index 165144994..08e58a7bf 100644 --- a/tests/test/evm/proposals.test.ts +++ b/tests/test/evm/proposals.test.ts @@ -437,7 +437,7 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { finalized: true, }, }); - await sleep(10000); + await sleep(5000); // now we check that the token was removed. const tokens = await governedToken.contract.getTokens(); expect(tokens.includes(tokenToRemove!)).to.eq(false); @@ -505,7 +505,7 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { finalized: true, }, }); - await sleep(10000); + await sleep(5000); const fee = await governedToken.contract.getFee(); expect(newFee).to.eq(ethers.utils.hexValue(fee)); }); diff --git a/tests/test/evm/signatureBridge.test.ts b/tests/test/evm/signatureBridge.test.ts new file mode 100644 index 000000000..0d904a1fa --- /dev/null +++ b/tests/test/evm/signatureBridge.test.ts @@ -0,0 +1,672 @@ +/* + * Copyright 2022 Webb Technologies Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +// A simple test for the Signature Bridge with the Relayer and the DKG. + +import Chai, { expect } from 'chai'; +import ChaiAsPromised from 'chai-as-promised'; +import { Tokens, VBridge } from '@webb-tools/protocol-solidity'; +import { hexToU8a, u8aToHex } from '@polkadot/util'; +import { BigNumber, ethers } from 'ethers'; +import temp from 'temp'; +import retry from 'async-retry'; +import { LocalChain } from '../../lib/localTestnet.js'; +import { Pallet, WebbRelayer, EnabledContracts } from '../../lib/webbRelayer.js'; +import getPort, { portNumbers } from 'get-port'; +import { LocalTangle } from '../../lib/localTangle.js'; +import isCi from 'is-ci'; +import path from 'path'; +import { ethAddressFromUncompressedPublicKey } from '../../lib/ethHelperFunctions.js'; +import { AnchorUpdateProposal, CircomUtxo, Keypair, ProposalHeader, ResourceId } from '@webb-tools/sdk-core'; +import { UsageMode } from '@webb-tools/test-utils'; +import { defaultEventsWatcherValue } from '../../lib/utils.js'; +import { MintableToken } from '@webb-tools/tokens'; +import { ApiPromise } from '@polkadot/api'; + +// to support chai-as-promised +Chai.use(ChaiAsPromised); + +describe('Signature Bridge <> DKG Proposal Signing Backend', function () { + this.timeout(5 * 60 * 1000); + const tmpDirPath = temp.mkdirSync(); + let localChain1: LocalChain; + let localChain2: LocalChain; + let signatureBridge: VBridge.VBridge; + let wallet1: ethers.Wallet; + let wallet2: ethers.Wallet; + let relayerWallet: ethers.Wallet; + + // dkg nodes + let aliceNode: LocalTangle; + let charlieNode: LocalTangle; + + let webbRelayer: WebbRelayer; + + before(async function () { + const PK1 = u8aToHex(ethers.utils.randomBytes(32)); + const PK2 = u8aToHex(ethers.utils.randomBytes(32)); + const relayerPk = u8aToHex(ethers.utils.randomBytes(32)); + + const usageMode: UsageMode = isCi + ? { mode: 'host', nodePath: 'dkg-standalone-node' } + : { + mode: 'host', + nodePath: path.resolve( + '../../tangle/target/release/tangle-standalone' + ), + }; + const enabledPallets: Pallet[] = [ + { + pallet: 'DKGProposalHandler', + eventsWatcher: defaultEventsWatcherValue, + }, + { + pallet: 'DKG', + eventsWatcher: defaultEventsWatcherValue, + }, + ]; + aliceNode = await LocalTangle.start({ + name: 'substrate-alice', + authority: 'alice', + usageMode, + // ports: 'auto', + ports: {ws: 9944, http: 9933, p2p: 30333}, + enableLogging: false, + }); + + charlieNode = await LocalTangle.start({ + name: 'substrate-charlie', + authority: 'charlie', + usageMode, + // ports: 'auto', + ports: {ws: 9945, http: 9934, p2p: 30334}, + enableLogging: false, + }); + const api = await charlieNode.api(); + await api.isReady; + console.log('tangle node ready waiting for dkg public key to be set onchain'); + const chainId = await charlieNode.getChainId(); + await charlieNode.writeConfig(`${tmpDirPath}/${charlieNode.name}.json`, { + suri: '//Charlie', + chainId: chainId, + enabledPallets, + }); + + // we need to wait until the public key is on chain. + await charlieNode.waitForEvent({ + section: 'dkg', + method: 'PublicKeySignatureChanged', + }); + + // next we need to start local evm node. + const localChain1Port = await getPort({ + port: portNumbers(3333, 4444), + }); + + const enabledContracts: EnabledContracts[] = [ + { + contract: 'VAnchor', + }, + ]; + + localChain1 = await LocalChain.init({ + port: localChain1Port, + chainId: localChain1Port, + name: 'Hermes', + populatedAccounts: [ + { + secretKey: PK1, + balance: ethers.utils.parseEther('1000').toHexString(), + }, + { + secretKey: relayerPk, + balance: ethers.utils.parseEther('1000').toHexString(), + }, + ], + enabledContracts: enabledContracts, + }); + + const localChain2Port = await getPort({ + port: portNumbers(3333, 4444), + }); + + localChain2 = await LocalChain.init({ + port: localChain2Port, + chainId: localChain2Port, + name: 'Athena', + populatedAccounts: [ + { + secretKey: PK2, + balance: ethers.utils.parseEther('1000').toHexString(), + }, + { + secretKey: relayerPk, + balance: ethers.utils.parseEther('1000').toHexString(), + }, + ], + enabledContracts: enabledContracts, + }); + + wallet1 = new ethers.Wallet(PK1, localChain1.provider()); + wallet2 = new ethers.Wallet(PK2, localChain2.provider()); + relayerWallet = new ethers.Wallet(relayerPk, localChain1.provider()); + + // Deploy the token. + const wrappedToken1 = await localChain1.deployToken( + 'Wrapped Ethereum', + 'WETH' + ); + const wrappedToken2 = await localChain2.deployToken( + 'Wrapped Ethereum', + 'WETH' + ); + const unwrappedToken1 = await MintableToken.createToken( + 'Webb Token', + 'WEBB', + wallet1 + ); + const unwrappedToken2 = await MintableToken.createToken( + 'Webb Token', + 'WEBB', + wallet2 + ); + + signatureBridge = await localChain1.deploySignatureVBridge( + localChain2, + wrappedToken1, + wrappedToken2, + wallet1, + wallet2, + unwrappedToken1, + unwrappedToken2 + ); + // save the chain configs. + await localChain1.writeConfig(`${tmpDirPath}/${localChain1.name}.json`, { + signatureVBridge: signatureBridge, + proposalSigningBackend: { type: 'DKGNode', chainId }, + relayerWallet + }); + await localChain2.writeConfig(`${tmpDirPath}/${localChain2.name}.json`, { + signatureVBridge: signatureBridge, + proposalSigningBackend: { type: 'DKGNode', chainId }, + relayerWallet + }); + // fetch the dkg public key. + const dkgPublicKey = await charlieNode.fetchDkgPublicKey(); + expect(dkgPublicKey).to.not.equal('0x'); + const governorAddress = ethAddressFromUncompressedPublicKey(dkgPublicKey); + // verify the governor address is a valid ethereum address. + expect(ethers.utils.isAddress(governorAddress)).to.be.true; + // transfer ownership to the DKG. + const sides = signatureBridge.vBridgeSides.values(); + for (const signatureSide of sides) { + // now we transferOwnership, forcefully. + const tx = await signatureSide.transferOwnership(governorAddress, 1); + await retry( + async () => { + await tx.wait(); + }, + { + retries: 5, + minTimeout: 1000, + onRetry: (error) => { + console.error('transferOwnership retry', error.name, error.message); + }, + } + ); + // check that the new governor is the same as the one we just set. + const currentGovernor = await signatureSide.contract.governor(); + expect(currentGovernor).to.eq(governorAddress); + } + + // get the anhor on localchain1 + const anchor = signatureBridge.getVAnchor(localChain1.chainId); + await anchor.setSigner(wallet1); + // approve token spending + const tokenAddress = signatureBridge.getWebbTokenAddress( + localChain1.chainId + )!; + const token = await Tokens.MintableToken.tokenFromAddress( + tokenAddress, + wallet1 + ); + let tx = await token.approveSpending( + anchor.contract.address, + ethers.utils.parseEther('1000') + ); + await tx.wait(); + await token.mintTokens(wallet1.address, ethers.utils.parseEther('1000')); + + // do the same but on localchain2 + const anchor2 = signatureBridge.getVAnchor(localChain2.chainId); + await anchor2.setSigner(wallet2); + const tokenAddress2 = signatureBridge.getWebbTokenAddress( + localChain2.chainId + )!; + const token2 = await Tokens.MintableToken.tokenFromAddress( + tokenAddress2, + wallet2 + ); + + tx = await token2.approveSpending( + anchor2.contract.address, + ethers.utils.parseEther('1000') + ); + await tx.wait(); + await token2.mintTokens(wallet2.address, ethers.utils.parseEther('1000')); + + const resourceId1 = await anchor.createResourceId(); + const resourceId2 = await anchor2.createResourceId(); + + const setResourceIdCall = (resourceId: string) => + api.tx.dkgProposals.setResource(resourceId, '0x00'); + // register the resource on tangle node. + for (const rid of [resourceId1, resourceId2]) { + await charlieNode.sudoExecuteTransaction(setResourceIdCall(rid)); + } + // Whitelist chainId on tangle node + const whitelistChainIdCall = (chain_id: number) => + api.tx.dkgProposals.whitelistChain({Evm: chain_id}); + for (const chain_id of [localChain1.underlyingChainId,localChain2.underlyingChainId]) { + await charlieNode.sudoExecuteTransaction(whitelistChainIdCall(chain_id)); + } + + // We will send anchor update proposal to register bride and its resources on tangle node. + await sendAnchorUpdateProposal( + charlieNode, + api, + resourceId1, + resourceId2 + ); + + + // now start the relayer + const relayerPort = await getPort({ port: portNumbers(9955, 9999) }); + webbRelayer = new WebbRelayer({ + commonConfig: { + + port: relayerPort, + }, + tmp: true, + configDir: tmpDirPath, + showLogs: true, + verbosity: 3, + }); + await webbRelayer.waitUntilReady(); + }); + + it('should handle AnchorUpdateProposal when a deposit happens using DKG proposal backend', async () => { + // we will use chain1 as an example here. + const anchor1 = signatureBridge.getVAnchor(localChain1.chainId); + const anchor2 = signatureBridge.getVAnchor(localChain2.chainId); + await anchor1.setSigner(wallet1); + const tokenAddress = signatureBridge.getWebbTokenAddress( + localChain1.chainId + )!; + const token = await Tokens.MintableToken.tokenFromAddress( + tokenAddress, + wallet1 + ); + + await token.mintTokens(wallet1.address, ethers.utils.parseEther('1000')); + const webbBalance = await token.getBalance(wallet1.address); + expect(webbBalance.toBigInt() > ethers.utils.parseEther('1').toBigInt()).to + .be.true; + + // Create a deposit utxo + const randomKeypair = new Keypair(); + const depositUtxo = await CircomUtxo.generateUtxo({ + curve: 'Bn254', + backend: 'Circom', + amount: (1e2).toString(), + originChainId: localChain1.chainId.toString(), + chainId: localChain2.chainId.toString(), + keypair: randomKeypair, + }); + + // Make the deposit transaction + const leaves = anchor1.tree + .elements() + .map((el) => hexToU8a(el.toHexString())); + + + await anchor1.transact([], [depositUtxo], 0, 0, '0', '0', tokenAddress, { + [localChain1.chainId]: leaves, + }); + + // wait until the signature bridge receives the execute call. + await webbRelayer.waitForEvent({ + kind: 'signature_bridge', + event: { + chain_id: localChain2.underlyingChainId.toString(), + call: 'execute_proposal_with_signature', + }, + }); + // now we wait for the tx queue on that chain to execute the transaction. + await webbRelayer.waitForEvent({ + kind: 'tx_queue', + event: { + ty: 'EVM', + chain_id: localChain2.underlyingChainId.toString(), + finalized: true, + }, + }); + // all is good, last thing is to check for the roots. + const srcChainRoot = await anchor1.contract.getLastRoot(); + const neigborRoots = await anchor2.contract.getLatestNeighborRoots(); + const edges = await anchor2.contract.getLatestNeighborEdges(); + const isKnownNeighborRoot = neigborRoots.some( + (root: BigNumber) => root.toHexString() === srcChainRoot.toHexString() + ); + if (!isKnownNeighborRoot) { + console.log({ + srcChainRoot, + neigborRoots, + edges, + isKnownNeighborRoot, + }); + } + expect(isKnownNeighborRoot).to.be.true; + }); + + after(async () => { + await aliceNode?.stop(); + await charlieNode?.stop(); + await localChain1?.stop(); + await localChain2?.stop(); + await webbRelayer?.stop(); + }); +}); + +describe('Signature Bridge <> Mocked Proposal Signing Backend', function () { + const tmpDirPath = temp.mkdirSync(); + let localChain1: LocalChain; + let localChain2: LocalChain; + let signatureBridge: VBridge.VBridge; + let wallet1: ethers.Wallet; + let wallet2: ethers.Wallet; + let govWallet: ethers.Wallet; + + let webbRelayer: WebbRelayer; + + before(async () => { + const PK1 = u8aToHex(ethers.utils.randomBytes(32)); + const PK2 = u8aToHex(ethers.utils.randomBytes(32)); + const GOV = u8aToHex(ethers.utils.randomBytes(32)); + const localChain1Port = await getPort({ + port: portNumbers(3333, 4444), + }); + + const enabledContracts: EnabledContracts[] = [ + { + contract: 'VAnchor', + }, + { + contract: 'SignatureBridge', + }, + ]; + + localChain1 = await LocalChain.init({ + port: localChain1Port, + chainId: localChain1Port, + name: 'Hermes', + populatedAccounts: [ + { + secretKey: PK1, + balance: ethers.utils.parseEther('1000').toHexString(), + }, + { + secretKey: GOV, + balance: ethers.utils.parseEther('1000').toHexString(), + }, + ], + enabledContracts: enabledContracts, + }); + + const localChain2Port = await getPort({ + port: portNumbers(3333, 4444), + }); + + localChain2 = await LocalChain.init({ + port: localChain2Port, + chainId: localChain2Port, + name: 'Athena', + populatedAccounts: [ + { + secretKey: PK2, + balance: ethers.utils.parseEther('1000').toHexString(), + }, + { + secretKey: GOV, + balance: ethers.utils.parseEther('1000').toHexString(), + }, + ], + enabledContracts: enabledContracts, + }); + + wallet1 = new ethers.Wallet(PK1, localChain1.provider()); + wallet2 = new ethers.Wallet(PK2, localChain2.provider()); + govWallet = new ethers.Wallet(GOV, localChain1.provider()); + // Deploy the token. + const wrappedToken1 = await localChain1.deployToken( + 'Wrapped Ethereum', + 'WETH' + ); + const wrappedToken2 = await localChain2.deployToken( + 'Wrapped Ethereum', + 'WETH' + ); + const unwrappedToken1 = await MintableToken.createToken( + 'Webb Token', + 'WEBB', + wallet1 + ); + const unwrappedToken2 = await MintableToken.createToken( + 'Webb Token', + 'WEBB', + wallet2 + ); + + signatureBridge = await localChain1.deploySignatureVBridge( + localChain2, + wrappedToken1, + wrappedToken2, + wallet1, + wallet2, + unwrappedToken1, + unwrappedToken2, + { + [localChain1.chainId]: govWallet.address, + [localChain2.chainId]: govWallet.address, + } + ); + + // get the anhor on localchain1 + const anchor = signatureBridge.getVAnchor(localChain1.chainId); + await anchor.setSigner(wallet1); + // approve token spending + const tokenAddress = signatureBridge.getWebbTokenAddress( + localChain1.chainId + )!; + const token = await Tokens.MintableToken.tokenFromAddress( + tokenAddress, + wallet1 + ); + let tx = await token.approveSpending( + anchor.contract.address, + ethers.utils.parseEther('1000') + ); + await tx.wait(); + await token.mintTokens(wallet1.address, ethers.utils.parseEther('1000')); + + // do the same but on localchain2 + const anchor2 = signatureBridge.getVAnchor(localChain2.chainId); + await anchor2.setSigner(wallet2); + const tokenAddress2 = signatureBridge.getWebbTokenAddress( + localChain2.chainId + )!; + const token2 = await Tokens.MintableToken.tokenFromAddress( + tokenAddress2, + wallet2 + ); + + tx = await token2.approveSpending( + anchor2.contract.address, + ethers.utils.parseEther('1000') + ); + await tx.wait(); + await token2.mintTokens(wallet2.address, ethers.utils.parseEther('1000')); + + const resourceId1 = await anchor.createResourceId(); + const resourceId2 = await anchor2.createResourceId(); + // save the chain configs. + await localChain1.writeConfig(`${tmpDirPath}/${localChain1.name}.json`, { + signatureVBridge: signatureBridge, + proposalSigningBackend: { type: 'Mocked', privateKey: GOV }, + linkedAnchors: [{ type: 'Raw', resourceId: resourceId2 }], + }); + await localChain2.writeConfig(`${tmpDirPath}/${localChain2.name}.json`, { + signatureVBridge: signatureBridge, + proposalSigningBackend: { type: 'Mocked', privateKey: GOV }, + linkedAnchors: [{ type: 'Raw', resourceId: resourceId1 }], + }); + + // now start the relayer + const relayerPort = await getPort({ port: portNumbers(9955, 9999) }); + webbRelayer = new WebbRelayer({ + commonConfig: { + port: relayerPort, + }, + tmp: true, + configDir: tmpDirPath, + showLogs: false, + verbosity: 3, + }); + await webbRelayer.waitUntilReady(); + }); + + it('should handle AnchorUpdateProposal when a deposit happens using mocked proposal backend', async () => { + const anchor1 = signatureBridge.getVAnchor(localChain1.chainId); + const anchor2 = signatureBridge.getVAnchor(localChain2.chainId); + await anchor1.setSigner(wallet1); + const tokenAddress = signatureBridge.getWebbTokenAddress( + localChain1.chainId + )!; + const token = await Tokens.MintableToken.tokenFromAddress( + tokenAddress, + wallet1 + ); + await token.mintTokens(wallet1.address, ethers.utils.parseEther('1000')); + const webbBalance = await token.getBalance(wallet1.address); + expect(webbBalance.toBigInt() > ethers.utils.parseEther('1').toBigInt()).to + .be.true; + + // Create a deposit utxo + const randomKeypair = new Keypair(); + const depositUtxo = await CircomUtxo.generateUtxo({ + curve: 'Bn254', + backend: 'Circom', + amount: (1e2).toString(), + originChainId: localChain1.chainId.toString(), + chainId: localChain2.chainId.toString(), + keypair: randomKeypair, + }); + + // Make the deposit transaction + + const leaves = anchor1.tree + .elements() + .map((el) => hexToU8a(el.toHexString())); + + await anchor1.transact([], [depositUtxo], 0, 0, '0', '0', tokenAddress, { + [localChain1.chainId]: leaves, + }); + + // wait until the signature bridge recives the execute call. + await webbRelayer.waitForEvent({ + kind: 'signature_bridge', + event: { + chain_id: localChain2.underlyingChainId.toString(), + call: 'execute_proposal_with_signature', + }, + }); + // now we wait for the tx queue on that chain to execute the transaction. + await webbRelayer.waitForEvent({ + kind: 'tx_queue', + event: { + ty: 'EVM', + chain_id: localChain2.underlyingChainId.toString(), + finalized: true, + }, + }); + // all is good, last thing is to check for the roots. + const srcChainRoot = await anchor1.contract.getLastRoot(); + const neigborRoots = await anchor2.contract.getLatestNeighborRoots(); + const edges = await anchor2.contract.getLatestNeighborEdges(); + const isKnownNeighborRoot = neigborRoots.some( + (root: BigNumber) => root.toHexString() === srcChainRoot.toHexString() + ); + if (!isKnownNeighborRoot) { + console.log({ + srcChainRoot, + neigborRoots, + edges, + isKnownNeighborRoot, + }); + } + expect(isKnownNeighborRoot).to.be.true; + }); + + after(async () => { + await localChain1?.stop(); + await localChain2?.stop(); + await webbRelayer?.stop(); + }); +}); + +async function sendAnchorUpdateProposal( + dkgNode: LocalTangle, + api: ApiPromise, + resourceId1: string, + resourceId2: string +) { + // send dummy proposal to register bridge + const sourceResourceId = ResourceId.fromBytes(hexToU8a(resourceId1)); + const targetResourceId = ResourceId.fromBytes(hexToU8a(resourceId2)); + const functionSignature = hexToU8a('0x00000002', 32); + const merkleRoot = u8aToHex(ethers.utils.randomBytes(32)); + const header = new ProposalHeader(targetResourceId, functionSignature, 0); + const anchorUpdateProposal = new AnchorUpdateProposal( + header, + merkleRoot, + sourceResourceId + ); + const kind = api.createType( + 'WebbProposalsProposalProposalKind', + 'AnchorUpdate' + ); + const prop = api.createType('WebbProposalsProposal', { + Unsigned: { + kind, + data: u8aToHex(anchorUpdateProposal.toU8a()), + }, + }); + + const submitUnsignedProposalCall = + api.tx.dkgProposalHandler.forceSubmitUnsignedProposal(prop.toU8a()); + await dkgNode.sudoExecuteTransaction(submitUnsignedProposalCall); + console.log('Dummy proposal sent'); +} From 855b7a60f0e39bb822df936f7a2c171c5bda7db3 Mon Sep 17 00:00:00 2001 From: salman01zp Date: Tue, 16 May 2023 22:53:45 +0530 Subject: [PATCH 6/9] use docker host --- tests/test/evm/proposals.test.ts | 4 ++-- tests/test/evm/signatureBridge.test.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test/evm/proposals.test.ts b/tests/test/evm/proposals.test.ts index 08e58a7bf..165144994 100644 --- a/tests/test/evm/proposals.test.ts +++ b/tests/test/evm/proposals.test.ts @@ -437,7 +437,7 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { finalized: true, }, }); - await sleep(5000); + await sleep(10000); // now we check that the token was removed. const tokens = await governedToken.contract.getTokens(); expect(tokens.includes(tokenToRemove!)).to.eq(false); @@ -505,7 +505,7 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { finalized: true, }, }); - await sleep(5000); + await sleep(10000); const fee = await governedToken.contract.getFee(); expect(newFee).to.eq(ethers.utils.hexValue(fee)); }); diff --git a/tests/test/evm/signatureBridge.test.ts b/tests/test/evm/signatureBridge.test.ts index 0d904a1fa..6406a8b25 100644 --- a/tests/test/evm/signatureBridge.test.ts +++ b/tests/test/evm/signatureBridge.test.ts @@ -61,8 +61,8 @@ describe('Signature Bridge <> DKG Proposal Signing Backend', function () { const relayerPk = u8aToHex(ethers.utils.randomBytes(32)); const usageMode: UsageMode = isCi - ? { mode: 'host', nodePath: 'dkg-standalone-node' } - : { + ? { mode: 'docker', forcePullImage: false } + : { mode: 'host', nodePath: path.resolve( '../../tangle/target/release/tangle-standalone' From 18ebf7dfa3fb62dd34ec7ec98c48b936b4e21052 Mon Sep 17 00:00:00 2001 From: salman01zp Date: Wed, 17 May 2023 11:56:25 +0530 Subject: [PATCH 7/9] update signature bridge test --- .../evm/evmToSubstrateTransaction.test.ts | 12 +- tests/test/evm/governorUpdates.test.ts | 4 +- tests/test/evm/proposals.test.ts | 45 +++---- tests/test/evm/signatureBridge.test.ts | 112 +++++++----------- tests/test/substrate/governorUpdate.test.ts | 6 +- 5 files changed, 79 insertions(+), 100 deletions(-) diff --git a/tests/test/evm/evmToSubstrateTransaction.test.ts b/tests/test/evm/evmToSubstrateTransaction.test.ts index 2b2f7a0c2..ccf895fae 100644 --- a/tests/test/evm/evmToSubstrateTransaction.test.ts +++ b/tests/test/evm/evmToSubstrateTransaction.test.ts @@ -68,7 +68,7 @@ import { VAnchor } from '@webb-tools/anchors'; import { MintableToken } from '@webb-tools/tokens'; const { ecdsaSign } = pkg; -describe('Cross chain transaction <<>> Mocked Backend', function() { +describe('Cross chain transaction <<>> Mocked Backend', function () { const tmpDirPath = temp.mkdirSync(); let localChain1: LocalChain; let aliceNode: LocalTangle; @@ -94,11 +94,11 @@ describe('Cross chain transaction <<>> Mocked Backend', function() { const usageMode: UsageMode = isCi ? { mode: 'docker', forcePullImage: false } : { - mode: 'host', - nodePath: path.resolve( - '../../tangle/target/release/tangle-standalone' - ), - }; + mode: 'host', + nodePath: path.resolve( + '../../tangle/target/release/tangle-standalone' + ), + }; const enabledPallets: Pallet[] = [ { pallet: 'VAnchorBn254', diff --git a/tests/test/evm/governorUpdates.test.ts b/tests/test/evm/governorUpdates.test.ts index 03f0c7b62..e2e298e67 100644 --- a/tests/test/evm/governorUpdates.test.ts +++ b/tests/test/evm/governorUpdates.test.ts @@ -96,7 +96,9 @@ describe('SignatureBridge Governor Updates', function () { // Wait until we are ready and connected const api = await charlieNode.api(); await api.isReady; - console.log('tangle node ready waiting for dkg public key to be set onchain'); + console.log( + 'tangle node ready waiting for dkg public key to be set onchain' + ); const chainId = await charlieNode.getChainId(); await charlieNode.writeConfig(`${tmpDirPath}/${charlieNode.name}.json`, { diff --git a/tests/test/evm/proposals.test.ts b/tests/test/evm/proposals.test.ts index 165144994..21273cab0 100644 --- a/tests/test/evm/proposals.test.ts +++ b/tests/test/evm/proposals.test.ts @@ -25,7 +25,11 @@ import { ethers } from 'ethers'; import temp from 'temp'; import retry from 'async-retry'; import { LocalChain } from '../../lib/localTestnet.js'; -import { Pallet, WebbRelayer, EnabledContracts } from '../../lib/webbRelayer.js'; +import { + Pallet, + WebbRelayer, + EnabledContracts, +} from '../../lib/webbRelayer.js'; import getPort, { portNumbers } from 'get-port'; import { LocalTangle } from '../../lib/localTangle.js'; import isCi from 'is-ci'; @@ -91,7 +95,6 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { usageMode, ports: 'auto', enableLogging: false, - }); charlieNode = await LocalTangle.start({ @@ -104,7 +107,9 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { const api = await charlieNode.api(); await api.isReady; - console.log('tangle node ready waiting for dkg public key to be set onchain'); + console.log( + 'tangle node ready waiting for dkg public key to be set onchain' + ); const chainId = await charlieNode.getChainId(); await charlieNode.writeConfig(`${tmpDirPath}/${charlieNode.name}.json`, { @@ -203,12 +208,12 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { await localChain1.writeConfig(`${tmpDirPath}/${localChain1.name}.json`, { signatureVBridge: signatureBridge, proposalSigningBackend: { type: 'DKGNode', chainId }, - relayerWallet: relayerWallet1 + relayerWallet: relayerWallet1, }); await localChain2.writeConfig(`${tmpDirPath}/${localChain2.name}.json`, { signatureVBridge: signatureBridge, proposalSigningBackend: { type: 'DKGNode', chainId }, - relayerWallet: relayerWallet1 + relayerWallet: relayerWallet1, }); // fetch the dkg public key. const dkgPublicKey = await charlieNode.fetchDkgPublicKey(); @@ -328,7 +333,7 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { ) ); const nonce = await governedToken.contract.proposalNonce(); - console.log("Proposal nonce: ", nonce.toString()); + console.log('Proposal nonce: ', nonce.toString()); const proposalHeader = new ProposalHeader( resourceId, functionSignature, @@ -350,10 +355,10 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { // now we wait for the proposal to be executed by the relayer then by the Signature Bridge. await webbRelayer.waitForEvent({ kind: 'signature_bridge', - event: { + event: { chain_id: localChain1.underlyingChainId.toString(), call: 'execute_proposal_with_signature', - }, + }, }); // now we wait for the tx queue on that chain to execute the transaction. await webbRelayer.waitForEvent({ @@ -371,8 +376,8 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { }); it('should handle TokenRemoveProposal', async () => { - // we need to wait until the public key is on chain. - await charlieNode.waitForEvent({ + // we need to wait until the public key is on chain. + await charlieNode.waitForEvent({ section: 'dkg', method: 'PublicKeySignatureChanged', }); @@ -399,7 +404,7 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { ) ); const nonce = await governedToken.contract.proposalNonce(); - console.log("Proposal nonce: ", nonce.toString()); + console.log('Proposal nonce: ', nonce.toString()); const proposalHeader = new ProposalHeader( resourceId, functionSignature, @@ -409,7 +414,6 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { proposalHeader, tokenToRemove! ); - await forceSubmitUnsignedProposal(charlieNode, { kind: 'TokenRemove', @@ -423,10 +427,10 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { // now we wait for the proposal to be executed by the relayer then by the Signature Bridge. await webbRelayer.waitForEvent({ kind: 'signature_bridge', - event: { + event: { chain_id: localChain1.underlyingChainId.toString(), call: 'execute_proposal_with_signature', - }, + }, }); // now we wait for the tx queue on that chain to execute the transaction. await webbRelayer.waitForEvent({ @@ -444,8 +448,8 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { }); it('should handle WrappingFeeUpdateProposal', async () => { - // we need to wait until the public key is on chain. - await charlieNode.waitForEvent({ + // we need to wait until the public key is on chain. + await charlieNode.waitForEvent({ section: 'dkg', method: 'PublicKeySignatureChanged', }); @@ -462,7 +466,7 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { localChain1.underlyingChainId ); const nonce = await governedToken.contract.proposalNonce(); - console.log("Proposal nonce: ", nonce.toString()); + console.log('Proposal nonce: ', nonce.toString()); const functionSignature = hexToU8a( governedToken.contract.interface.getSighash( governedToken.contract.interface.functions['setFee(uint16,uint32)'] @@ -491,7 +495,7 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { // now we wait for the proposal to be executed by the relayer then by the Signature Bridge. await webbRelayer.waitForEvent({ kind: 'signature_bridge', - event: { + event: { chain_id: localChain1.underlyingChainId.toString(), call: 'execute_proposal_with_signature', }, @@ -529,10 +533,7 @@ async function forceSubmitUnsignedProposal( } ) { const api = await node.api(); - const kind = api.createType( - 'WebbProposalsProposalProposalKind', - opts.kind - ); + const kind = api.createType('WebbProposalsProposalProposalKind', opts.kind); const proposal = api .createType('WebbProposalsProposal', { Unsigned: { diff --git a/tests/test/evm/signatureBridge.test.ts b/tests/test/evm/signatureBridge.test.ts index 6406a8b25..8d6dfde11 100644 --- a/tests/test/evm/signatureBridge.test.ts +++ b/tests/test/evm/signatureBridge.test.ts @@ -24,17 +24,20 @@ import { BigNumber, ethers } from 'ethers'; import temp from 'temp'; import retry from 'async-retry'; import { LocalChain } from '../../lib/localTestnet.js'; -import { Pallet, WebbRelayer, EnabledContracts } from '../../lib/webbRelayer.js'; +import { + Pallet, + WebbRelayer, + EnabledContracts, +} from '../../lib/webbRelayer.js'; import getPort, { portNumbers } from 'get-port'; import { LocalTangle } from '../../lib/localTangle.js'; import isCi from 'is-ci'; import path from 'path'; import { ethAddressFromUncompressedPublicKey } from '../../lib/ethHelperFunctions.js'; -import { AnchorUpdateProposal, CircomUtxo, Keypair, ProposalHeader, ResourceId } from '@webb-tools/sdk-core'; +import { CircomUtxo, Keypair } from '@webb-tools/sdk-core'; import { UsageMode } from '@webb-tools/test-utils'; import { defaultEventsWatcherValue } from '../../lib/utils.js'; import { MintableToken } from '@webb-tools/tokens'; -import { ApiPromise } from '@polkadot/api'; // to support chai-as-promised Chai.use(ChaiAsPromised); @@ -61,8 +64,8 @@ describe('Signature Bridge <> DKG Proposal Signing Backend', function () { const relayerPk = u8aToHex(ethers.utils.randomBytes(32)); const usageMode: UsageMode = isCi - ? { mode: 'docker', forcePullImage: false } - : { + ? { mode: 'docker', forcePullImage: false } + : { mode: 'host', nodePath: path.resolve( '../../tangle/target/release/tangle-standalone' @@ -83,7 +86,7 @@ describe('Signature Bridge <> DKG Proposal Signing Backend', function () { authority: 'alice', usageMode, // ports: 'auto', - ports: {ws: 9944, http: 9933, p2p: 30333}, + ports: { ws: 9944, http: 9933, p2p: 30333 }, enableLogging: false, }); @@ -92,12 +95,14 @@ describe('Signature Bridge <> DKG Proposal Signing Backend', function () { authority: 'charlie', usageMode, // ports: 'auto', - ports: {ws: 9945, http: 9934, p2p: 30334}, + ports: { ws: 9945, http: 9934, p2p: 30334 }, enableLogging: false, }); const api = await charlieNode.api(); await api.isReady; - console.log('tangle node ready waiting for dkg public key to be set onchain'); + console.log( + 'tangle node ready waiting for dkg public key to be set onchain' + ); const chainId = await charlieNode.getChainId(); await charlieNode.writeConfig(`${tmpDirPath}/${charlieNode.name}.json`, { suri: '//Charlie', @@ -193,17 +198,7 @@ describe('Signature Bridge <> DKG Proposal Signing Backend', function () { unwrappedToken1, unwrappedToken2 ); - // save the chain configs. - await localChain1.writeConfig(`${tmpDirPath}/${localChain1.name}.json`, { - signatureVBridge: signatureBridge, - proposalSigningBackend: { type: 'DKGNode', chainId }, - relayerWallet - }); - await localChain2.writeConfig(`${tmpDirPath}/${localChain2.name}.json`, { - signatureVBridge: signatureBridge, - proposalSigningBackend: { type: 'DKGNode', chainId }, - relayerWallet - }); + // fetch the dkg public key. const dkgPublicKey = await charlieNode.fetchDkgPublicKey(); expect(dkgPublicKey).to.not.equal('0x'); @@ -231,7 +226,7 @@ describe('Signature Bridge <> DKG Proposal Signing Backend', function () { const currentGovernor = await signatureSide.contract.governor(); expect(currentGovernor).to.eq(governorAddress); } - + // get the anhor on localchain1 const anchor = signatureBridge.getVAnchor(localChain1.chainId); await anchor.setSigner(wallet1); @@ -279,25 +274,33 @@ describe('Signature Bridge <> DKG Proposal Signing Backend', function () { } // Whitelist chainId on tangle node const whitelistChainIdCall = (chain_id: number) => - api.tx.dkgProposals.whitelistChain({Evm: chain_id}); - for (const chain_id of [localChain1.underlyingChainId,localChain2.underlyingChainId]) { + api.tx.dkgProposals.whitelistChain({ Evm: chain_id }); + for (const chain_id of [ + localChain1.underlyingChainId, + localChain2.underlyingChainId, + ]) { await charlieNode.sudoExecuteTransaction(whitelistChainIdCall(chain_id)); } - - // We will send anchor update proposal to register bride and its resources on tangle node. - await sendAnchorUpdateProposal( - charlieNode, - api, - resourceId1, - resourceId2 - ); + // save the chain configs. + await localChain1.writeConfig(`${tmpDirPath}/${localChain1.name}.json`, { + signatureVBridge: signatureBridge, + proposalSigningBackend: { type: 'DKGNode', chainId }, + linkedAnchors: [{ type: 'Raw', resourceId: resourceId2 }], + relayerWallet, + }); + await localChain2.writeConfig(`${tmpDirPath}/${localChain2.name}.json`, { + signatureVBridge: signatureBridge, + proposalSigningBackend: { type: 'DKGNode', chainId }, + linkedAnchors: [{ type: 'Raw', resourceId: resourceId1 }], + relayerWallet, + }); // now start the relayer const relayerPort = await getPort({ port: portNumbers(9955, 9999) }); webbRelayer = new WebbRelayer({ commonConfig: { - + features: { governanceRelay: true }, port: relayerPort, }, tmp: true, @@ -309,6 +312,12 @@ describe('Signature Bridge <> DKG Proposal Signing Backend', function () { }); it('should handle AnchorUpdateProposal when a deposit happens using DKG proposal backend', async () => { + // we need to wait until the public key is changed. + await charlieNode.waitForEvent({ + section: 'dkg', + method: 'PublicKeySignatureChanged', + }); + // we will use chain1 as an example here. const anchor1 = signatureBridge.getVAnchor(localChain1.chainId); const anchor2 = signatureBridge.getVAnchor(localChain2.chainId); @@ -341,16 +350,15 @@ describe('Signature Bridge <> DKG Proposal Signing Backend', function () { const leaves = anchor1.tree .elements() .map((el) => hexToU8a(el.toHexString())); - - await anchor1.transact([], [depositUtxo], 0, 0, '0', '0', tokenAddress, { + await anchor1.transact([], [depositUtxo], 0, 0, '0', '0', tokenAddress, { [localChain1.chainId]: leaves, }); // wait until the signature bridge receives the execute call. await webbRelayer.waitForEvent({ kind: 'signature_bridge', - event: { + event: { chain_id: localChain2.underlyingChainId.toString(), call: 'execute_proposal_with_signature', }, @@ -598,7 +606,7 @@ describe('Signature Bridge <> Mocked Proposal Signing Backend', function () { // wait until the signature bridge recives the execute call. await webbRelayer.waitForEvent({ kind: 'signature_bridge', - event: { + event: { chain_id: localChain2.underlyingChainId.toString(), call: 'execute_proposal_with_signature', }, @@ -636,37 +644,3 @@ describe('Signature Bridge <> Mocked Proposal Signing Backend', function () { await webbRelayer?.stop(); }); }); - -async function sendAnchorUpdateProposal( - dkgNode: LocalTangle, - api: ApiPromise, - resourceId1: string, - resourceId2: string -) { - // send dummy proposal to register bridge - const sourceResourceId = ResourceId.fromBytes(hexToU8a(resourceId1)); - const targetResourceId = ResourceId.fromBytes(hexToU8a(resourceId2)); - const functionSignature = hexToU8a('0x00000002', 32); - const merkleRoot = u8aToHex(ethers.utils.randomBytes(32)); - const header = new ProposalHeader(targetResourceId, functionSignature, 0); - const anchorUpdateProposal = new AnchorUpdateProposal( - header, - merkleRoot, - sourceResourceId - ); - const kind = api.createType( - 'WebbProposalsProposalProposalKind', - 'AnchorUpdate' - ); - const prop = api.createType('WebbProposalsProposal', { - Unsigned: { - kind, - data: u8aToHex(anchorUpdateProposal.toU8a()), - }, - }); - - const submitUnsignedProposalCall = - api.tx.dkgProposalHandler.forceSubmitUnsignedProposal(prop.toU8a()); - await dkgNode.sudoExecuteTransaction(submitUnsignedProposalCall); - console.log('Dummy proposal sent'); -} diff --git a/tests/test/substrate/governorUpdate.test.ts b/tests/test/substrate/governorUpdate.test.ts index 2e0b6a663..7fa1b57f7 100644 --- a/tests/test/substrate/governorUpdate.test.ts +++ b/tests/test/substrate/governorUpdate.test.ts @@ -80,7 +80,9 @@ describe('Substrate SignatureBridge Governor Update', function () { // Wait until we are ready and connected const api = await aliceNode.api(); await api.isReady; - console.log('tangle node ready waiting for dkg public key to be set onchain'); + console.log( + 'tangle node ready waiting for dkg public key to be set onchain' + ); const chainId = await aliceNode.getChainId(); // Step 2. We need to wait until the public key is on chain. @@ -156,4 +158,4 @@ describe('Substrate SignatureBridge Governor Update', function () { await charlieNode?.stop(); await webbRelayer?.stop(); }); -}); \ No newline at end of file +}); From 333958808a7223ad532aa45925f7a9d908f53482 Mon Sep 17 00:00:00 2001 From: salman01zp Date: Thu, 18 May 2023 14:40:36 +0530 Subject: [PATCH 8/9] update metadata and fix test --- Cargo.lock | 482 ++++++++++-------- Cargo.toml | 2 +- crates/bridge-registry-backends/src/mocked.rs | 2 +- .../tests/submit_anchor_update_proposal.rs | 11 +- crates/proposal-signing-backends/src/dkg.rs | 25 +- .../substrate/src/signature_bridge_watcher.rs | 2 +- tests/test/evm/proposals.test.ts | 69 ++- tests/test/evm/signatureBridge.test.ts | 261 +--------- 8 files changed, 364 insertions(+), 490 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1234697f8..d190c404a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -78,9 +78,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.20" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +checksum = "67fc08ce920c31afb70f013dcce1bfc3a3195de6a228474e45e1f145b36f8d04" dependencies = [ "memchr", ] @@ -153,7 +153,7 @@ dependencies = [ "cfg-if 1.0.0", "color-eyre 0.5.11", "criterion", - "ethers-core 2.0.2 (git+https://github.com/gakonst/ethers-rs)", + "ethers-core 2.0.4", "fnv", "hex", "num", @@ -580,7 +580,7 @@ dependencies = [ "serde_urlencoded 0.7.1", "sha1", "sync_wrapper", - "tokio 1.27.0", + "tokio 1.28.1", "tokio-tungstenite 0.18.0", "tower", "tower-layer", @@ -638,7 +638,7 @@ dependencies = [ "instant", "pin-project-lite 0.2.9", "rand 0.8.5", - "tokio 1.27.0", + "tokio 1.28.1", ] [[package]] @@ -1182,7 +1182,7 @@ dependencies = [ "digest 0.10.6", "getrandom 0.2.8", "hmac 0.12.1", - "k256 0.13.0", + "k256 0.13.1", "lazy_static", "serde", "sha2 0.10.6", @@ -1191,21 +1191,19 @@ dependencies = [ [[package]] name = "coins-bip39" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad2a68a46b9d8cc90484f0689adc0e4c890eb215bf698ae52e5235bb88f40be7" +checksum = "84f4d04ee18e58356accd644896aeb2094ddeafb6a713e056cef0c0a8e468c15" dependencies = [ "bitvec 0.17.4", "coins-bip32", "getrandom 0.2.8", - "hex", "hmac 0.12.1", "once_cell", "pbkdf2 0.12.1", "rand 0.8.5", "sha2 0.10.6", "thiserror", - "tracing", ] [[package]] @@ -2020,7 +2018,7 @@ checksum = "a64d2e9c561b39b2de83c0387baffecfbc62ad116c4fc8f4e5b040b8e0737d7c" dependencies = [ "der 0.7.2", "digest 0.10.6", - "elliptic-curve 0.13.3", + "elliptic-curve 0.13.4", "rfc6979 0.4.0", "signature 2.1.0", ] @@ -2089,9 +2087,9 @@ dependencies = [ [[package]] name = "elliptic-curve" -version = "0.13.3" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22cdacd4d6ed3f9b98680b679c0e52a823b8a2c7a97358d508fe247f2180c282" +checksum = "75c71eaa367f2e5d556414a8eea812bc62985c879748d6403edabd9cb03f16e7" dependencies = [ "base16ct 0.2.0", "crypto-bigint 0.5.1", @@ -2126,14 +2124,14 @@ dependencies = [ [[package]] name = "enr" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb4d5fbf6f56acecd38f5988eb2e4ae412008a2a30268c748c701ec6322f39d4" +checksum = "cf56acd72bb22d2824e66ae8e9e5ada4d0de17a69c7fd35569dde2ada8ec9116" dependencies = [ "base64 0.13.1", "bytes 1.4.0", "hex", - "k256 0.13.0", + "k256 0.13.1", "log", "rand 0.8.5", "rlp", @@ -2286,7 +2284,7 @@ dependencies = [ "sp-keyring", "sp-runtime", "subxt", - "tokio 1.27.0", + "tokio 1.28.1", "toml 0.5.11", "tree_hash 0.4.1 (git+https://github.com/webb-tools/pallet-eth2-light-client)", "webb 0.5.21", @@ -2431,7 +2429,7 @@ dependencies = [ "sp-core", "sp-keyring", "thread", - "tokio 1.27.0", + "tokio 1.28.1", "toml 0.5.11", "tree_hash 0.4.1 (git+https://github.com/webb-tools/pallet-eth2-light-client)", "types", @@ -2469,7 +2467,7 @@ dependencies = [ "serde", "serde_json", "thread", - "tokio 1.27.0", + "tokio 1.28.1", "toml 0.5.11", "tree_hash 0.4.1 (git+https://github.com/webb-tools/lighthouse.git?branch=develop)", "types", @@ -2557,29 +2555,28 @@ version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "697aba1bec98cb86e7bebd69f9bb365218871464137af9e93e7a72bd6dc421d0" dependencies = [ - "ethers-addressbook 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ethers-contract 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ethers-core 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ethers-etherscan 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ethers-middleware 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ethers-providers 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ethers-signers 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ethers-solc 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethers-addressbook 2.0.2", + "ethers-contract 2.0.2", + "ethers-core 2.0.2", + "ethers-etherscan 2.0.2", + "ethers-middleware 2.0.2", + "ethers-providers 2.0.2", + "ethers-signers 2.0.2", + "ethers-solc", ] [[package]] name = "ethers" -version = "2.0.2" -source = "git+https://github.com/gakonst/ethers-rs#1dd35458695e2b967d4c2ff278cc8d0eaadcc9fb" +version = "2.0.4" +source = "git+https://github.com/gakonst/ethers-rs#3031efb2380483dd6bc5a6599519e58e95a8467f" dependencies = [ - "ethers-addressbook 2.0.2 (git+https://github.com/gakonst/ethers-rs)", - "ethers-contract 2.0.2 (git+https://github.com/gakonst/ethers-rs)", - "ethers-core 2.0.2 (git+https://github.com/gakonst/ethers-rs)", - "ethers-etherscan 2.0.2 (git+https://github.com/gakonst/ethers-rs)", - "ethers-middleware 2.0.2 (git+https://github.com/gakonst/ethers-rs)", - "ethers-providers 2.0.2 (git+https://github.com/gakonst/ethers-rs)", - "ethers-signers 2.0.2 (git+https://github.com/gakonst/ethers-rs)", - "ethers-solc 2.0.2 (git+https://github.com/gakonst/ethers-rs)", + "ethers-addressbook 2.0.4", + "ethers-contract 2.0.4", + "ethers-core 2.0.4", + "ethers-etherscan 2.0.4", + "ethers-middleware 2.0.4", + "ethers-providers 2.0.4", + "ethers-signers 2.0.4", ] [[package]] @@ -2588,7 +2585,7 @@ version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0b603812e5e4d63521c691cbc1f34743879e96a1ee96c6594639d7fa0cf6fbc" dependencies = [ - "ethers-core 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethers-core 2.0.2", "once_cell", "serde", "serde_json", @@ -2596,10 +2593,10 @@ dependencies = [ [[package]] name = "ethers-addressbook" -version = "2.0.2" -source = "git+https://github.com/gakonst/ethers-rs#1dd35458695e2b967d4c2ff278cc8d0eaadcc9fb" +version = "2.0.4" +source = "git+https://github.com/gakonst/ethers-rs#3031efb2380483dd6bc5a6599519e58e95a8467f" dependencies = [ - "ethers-core 2.0.2 (git+https://github.com/gakonst/ethers-rs)", + "ethers-core 2.0.4", "once_cell", "serde", "serde_json", @@ -2611,10 +2608,10 @@ version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4e8ed7c2b2a22e07b65ae0eb426c948a7448f1be15c66e4813e02c423751fc9" dependencies = [ - "ethers-contract-abigen 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ethers-contract-derive 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ethers-core 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ethers-providers 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethers-contract-abigen 2.0.2", + "ethers-contract-derive 2.0.2", + "ethers-core 2.0.2", + "ethers-providers 2.0.2", "futures-util", "hex", "once_cell", @@ -2626,13 +2623,13 @@ dependencies = [ [[package]] name = "ethers-contract" -version = "2.0.2" -source = "git+https://github.com/gakonst/ethers-rs#1dd35458695e2b967d4c2ff278cc8d0eaadcc9fb" +version = "2.0.4" +source = "git+https://github.com/gakonst/ethers-rs#3031efb2380483dd6bc5a6599519e58e95a8467f" dependencies = [ - "ethers-contract-abigen 2.0.2 (git+https://github.com/gakonst/ethers-rs)", - "ethers-contract-derive 2.0.2 (git+https://github.com/gakonst/ethers-rs)", - "ethers-core 2.0.2 (git+https://github.com/gakonst/ethers-rs)", - "ethers-providers 2.0.2 (git+https://github.com/gakonst/ethers-rs)", + "ethers-contract-abigen 2.0.4", + "ethers-contract-derive 2.0.4", + "ethers-core 2.0.4", + "ethers-providers 2.0.4", "futures-util", "hex", "once_cell", @@ -2650,8 +2647,8 @@ checksum = "bf0984f4ec4e267fd27b7c9fa2f73e72c5c98491a73f777290654154d104f723" dependencies = [ "Inflector", "dunce", - "ethers-core 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ethers-etherscan 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethers-core 2.0.2", + "ethers-etherscan 2.0.2", "eyre", "getrandom 0.2.8", "hex", @@ -2663,7 +2660,7 @@ dependencies = [ "serde", "serde_json", "syn 1.0.109", - "tokio 1.27.0", + "tokio 1.28.1", "toml 0.7.3", "url", "walkdir", @@ -2671,27 +2668,23 @@ dependencies = [ [[package]] name = "ethers-contract-abigen" -version = "2.0.2" -source = "git+https://github.com/gakonst/ethers-rs#1dd35458695e2b967d4c2ff278cc8d0eaadcc9fb" +version = "2.0.4" +source = "git+https://github.com/gakonst/ethers-rs#3031efb2380483dd6bc5a6599519e58e95a8467f" dependencies = [ "Inflector", "dunce", - "ethers-core 2.0.2 (git+https://github.com/gakonst/ethers-rs)", - "ethers-etherscan 2.0.2 (git+https://github.com/gakonst/ethers-rs)", + "ethers-core 2.0.4", "eyre", "getrandom 0.2.8", "hex", - "prettyplease 0.1.25", + "prettyplease 0.2.4", "proc-macro2", "quote", "regex", - "reqwest", "serde", "serde_json", - "syn 1.0.109", - "tokio 1.27.0", + "syn 2.0.13", "toml 0.7.3", - "url", "walkdir", ] @@ -2701,8 +2694,8 @@ version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "914e9211077a1b590af1ee6b8dfbd54515c808119546c95da69479908dc3d4de" dependencies = [ - "ethers-contract-abigen 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ethers-core 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethers-contract-abigen 2.0.2", + "ethers-core 2.0.2", "hex", "proc-macro2", "quote", @@ -2711,15 +2704,17 @@ dependencies = [ [[package]] name = "ethers-contract-derive" -version = "2.0.2" -source = "git+https://github.com/gakonst/ethers-rs#1dd35458695e2b967d4c2ff278cc8d0eaadcc9fb" +version = "2.0.4" +source = "git+https://github.com/gakonst/ethers-rs#3031efb2380483dd6bc5a6599519e58e95a8467f" dependencies = [ - "ethers-contract-abigen 2.0.2 (git+https://github.com/gakonst/ethers-rs)", - "ethers-core 2.0.2 (git+https://github.com/gakonst/ethers-rs)", + "Inflector", + "ethers-contract-abigen 2.0.4", + "ethers-core 2.0.4", "hex", "proc-macro2", "quote", - "syn 1.0.109", + "serde_json", + "syn 2.0.13", ] [[package]] @@ -2733,13 +2728,13 @@ dependencies = [ "cargo_metadata", "chrono", "convert_case 0.6.0", - "elliptic-curve 0.13.3", + "elliptic-curve 0.13.4", "ethabi", "generic-array 0.14.7", "getrandom 0.2.8", "hex", - "k256 0.13.0", - "num_enum", + "k256 0.13.1", + "num_enum 0.5.11", "once_cell", "open-fastrlp", "proc-macro2", @@ -2757,30 +2752,28 @@ dependencies = [ [[package]] name = "ethers-core" -version = "2.0.2" -source = "git+https://github.com/gakonst/ethers-rs#1dd35458695e2b967d4c2ff278cc8d0eaadcc9fb" +version = "2.0.4" +source = "git+https://github.com/gakonst/ethers-rs#3031efb2380483dd6bc5a6599519e58e95a8467f" dependencies = [ "arrayvec 0.7.2", "bytes 1.4.0", "cargo_metadata", "chrono", - "convert_case 0.6.0", - "elliptic-curve 0.13.3", + "elliptic-curve 0.13.4", "ethabi", "generic-array 0.14.7", "getrandom 0.2.8", "hex", - "k256 0.13.0", - "num_enum", + "k256 0.13.1", + "num_enum 0.6.1", "once_cell", "open-fastrlp", - "proc-macro2", "rand 0.8.5", "rlp", "serde", "serde_json", "strum", - "syn 1.0.109", + "syn 2.0.13", "tempfile", "thiserror", "tiny-keccak", @@ -2793,8 +2786,8 @@ version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8920b59cf81e357df2c8102d6a9dc81c2d68f7409543ff3b6868851ecf007807" dependencies = [ - "ethers-core 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ethers-solc 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethers-core 2.0.2", + "ethers-solc", "getrandom 0.2.8", "reqwest", "semver 1.0.17", @@ -2806,11 +2799,10 @@ dependencies = [ [[package]] name = "ethers-etherscan" -version = "2.0.2" -source = "git+https://github.com/gakonst/ethers-rs#1dd35458695e2b967d4c2ff278cc8d0eaadcc9fb" +version = "2.0.4" +source = "git+https://github.com/gakonst/ethers-rs#3031efb2380483dd6bc5a6599519e58e95a8467f" dependencies = [ - "ethers-core 2.0.2 (git+https://github.com/gakonst/ethers-rs)", - "ethers-solc 2.0.2 (git+https://github.com/gakonst/ethers-rs)", + "ethers-core 2.0.4", "getrandom 0.2.8", "reqwest", "semver 1.0.17", @@ -2828,11 +2820,11 @@ checksum = "c54b30f67c1883ed68bd38aedbdd321831382c12e1b95089c8261c79bb85e4da" dependencies = [ "async-trait", "auto_impl", - "ethers-contract 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ethers-core 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ethers-etherscan 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ethers-providers 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ethers-signers 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethers-contract 2.0.2", + "ethers-core 2.0.2", + "ethers-etherscan 2.0.2", + "ethers-providers 2.0.2", + "ethers-signers 2.0.2", "futures-channel", "futures-locks", "futures-util", @@ -2841,7 +2833,7 @@ dependencies = [ "serde", "serde_json", "thiserror", - "tokio 1.27.0", + "tokio 1.28.1", "tracing", "tracing-futures", "url", @@ -2849,16 +2841,16 @@ dependencies = [ [[package]] name = "ethers-middleware" -version = "2.0.2" -source = "git+https://github.com/gakonst/ethers-rs#1dd35458695e2b967d4c2ff278cc8d0eaadcc9fb" +version = "2.0.4" +source = "git+https://github.com/gakonst/ethers-rs#3031efb2380483dd6bc5a6599519e58e95a8467f" dependencies = [ "async-trait", "auto_impl", - "ethers-contract 2.0.2 (git+https://github.com/gakonst/ethers-rs)", - "ethers-core 2.0.2 (git+https://github.com/gakonst/ethers-rs)", - "ethers-etherscan 2.0.2 (git+https://github.com/gakonst/ethers-rs)", - "ethers-providers 2.0.2 (git+https://github.com/gakonst/ethers-rs)", - "ethers-signers 2.0.2 (git+https://github.com/gakonst/ethers-rs)", + "ethers-contract 2.0.4", + "ethers-core 2.0.4", + "ethers-etherscan 2.0.4", + "ethers-providers 2.0.4", + "ethers-signers 2.0.4", "futures-channel", "futures-locks", "futures-util", @@ -2867,7 +2859,7 @@ dependencies = [ "serde", "serde_json", "thiserror", - "tokio 1.27.0", + "tokio 1.28.1", "tracing", "tracing-futures", "url", @@ -2884,7 +2876,7 @@ dependencies = [ "base64 0.21.0", "bytes 1.4.0", "enr", - "ethers-core 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethers-core 2.0.2", "futures-core", "futures-timer", "futures-util", @@ -2899,7 +2891,7 @@ dependencies = [ "serde", "serde_json", "thiserror", - "tokio 1.27.0", + "tokio 1.28.1", "tracing", "tracing-futures", "url", @@ -2911,15 +2903,15 @@ dependencies = [ [[package]] name = "ethers-providers" -version = "2.0.2" -source = "git+https://github.com/gakonst/ethers-rs#1dd35458695e2b967d4c2ff278cc8d0eaadcc9fb" +version = "2.0.4" +source = "git+https://github.com/gakonst/ethers-rs#3031efb2380483dd6bc5a6599519e58e95a8467f" dependencies = [ "async-trait", "auto_impl", "base64 0.21.0", "bytes 1.4.0", "enr", - "ethers-core 2.0.2 (git+https://github.com/gakonst/ethers-rs)", + "ethers-core 2.0.4", "futures-core", "futures-timer", "futures-util", @@ -2934,7 +2926,7 @@ dependencies = [ "serde", "serde_json", "thiserror", - "tokio 1.27.0", + "tokio 1.28.1", "tracing", "tracing-futures", "url", @@ -2953,9 +2945,9 @@ dependencies = [ "async-trait", "coins-bip32", "coins-bip39", - "elliptic-curve 0.13.3", + "elliptic-curve 0.13.4", "eth-keystore", - "ethers-core 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethers-core 2.0.2", "hex", "rand 0.8.5", "sha2 0.10.6", @@ -2965,15 +2957,15 @@ dependencies = [ [[package]] name = "ethers-signers" -version = "2.0.2" -source = "git+https://github.com/gakonst/ethers-rs#1dd35458695e2b967d4c2ff278cc8d0eaadcc9fb" +version = "2.0.4" +source = "git+https://github.com/gakonst/ethers-rs#3031efb2380483dd6bc5a6599519e58e95a8467f" dependencies = [ "async-trait", "coins-bip32", "coins-bip39", - "elliptic-curve 0.13.3", + "elliptic-curve 0.13.4", "eth-keystore", - "ethers-core 2.0.2 (git+https://github.com/gakonst/ethers-rs)", + "ethers-core 2.0.4", "hex", "rand 0.8.5", "sha2 0.10.6", @@ -2989,37 +2981,7 @@ checksum = "139542f51f4c405d0dd7e97c34232140a14e8744d1cf121777355567187259e4" dependencies = [ "cfg-if 1.0.0", "dunce", - "ethers-core 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "getrandom 0.2.8", - "glob", - "hex", - "home", - "md-5", - "num_cpus", - "once_cell", - "path-slash", - "rayon", - "regex", - "semver 1.0.17", - "serde", - "serde_json", - "solang-parser", - "thiserror", - "tiny-keccak", - "tokio 1.27.0", - "tracing", - "walkdir", - "yansi", -] - -[[package]] -name = "ethers-solc" -version = "2.0.2" -source = "git+https://github.com/gakonst/ethers-rs#1dd35458695e2b967d4c2ff278cc8d0eaadcc9fb" -dependencies = [ - "cfg-if 1.0.0", - "dunce", - "ethers-core 2.0.2 (git+https://github.com/gakonst/ethers-rs)", + "ethers-core 2.0.2", "getrandom 0.2.8", "glob", "hex", @@ -3036,7 +2998,7 @@ dependencies = [ "solang-parser", "thiserror", "tiny-keccak", - "tokio 1.27.0", + "tokio 1.28.1", "tracing", "walkdir", "yansi", @@ -3492,7 +3454,7 @@ dependencies = [ "http", "indexmap", "slab", - "tokio 1.27.0", + "tokio 1.28.1", "tokio-util 0.7.7", "tracing", ] @@ -3789,7 +3751,7 @@ dependencies = [ "itoa 1.0.6", "pin-project-lite 0.2.9", "socket2 0.4.9", - "tokio 1.27.0", + "tokio 1.28.1", "tower-service", "tracing", "want", @@ -3804,13 +3766,26 @@ dependencies = [ "http", "hyper 0.14.25", "log", - "rustls", + "rustls 0.20.8", "rustls-native-certs", - "tokio 1.27.0", - "tokio-rustls", + "tokio 1.28.1", + "tokio-rustls 0.23.4", "webpki-roots", ] +[[package]] +name = "hyper-rustls" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0646026eb1b3eea4cd9ba47912ea5ce9cc07713d105b1a14698f4e6433d348b7" +dependencies = [ + "http", + "hyper 0.14.25", + "rustls 0.21.1", + "tokio 1.28.1", + "tokio-rustls 0.24.0", +] + [[package]] name = "hyper-tls" version = "0.5.0" @@ -3820,7 +3795,7 @@ dependencies = [ "bytes 1.4.0", "hyper 0.14.25", "native-tls", - "tokio 1.27.0", + "tokio 1.28.1", "tokio-native-tls", ] @@ -4066,8 +4041,8 @@ dependencies = [ "rustls-native-certs", "soketto", "thiserror", - "tokio 1.27.0", - "tokio-rustls", + "tokio 1.28.1", + "tokio-rustls 0.23.4", "tokio-util 0.7.7", "tracing", "webpki-roots", @@ -4092,7 +4067,7 @@ dependencies = [ "serde", "serde_json", "thiserror", - "tokio 1.27.0", + "tokio 1.28.1", "tracing", ] @@ -4104,14 +4079,14 @@ checksum = "cc345b0a43c6bc49b947ebeb936e886a419ee3d894421790c969cc56040542ad" dependencies = [ "async-trait", "hyper 0.14.25", - "hyper-rustls", + "hyper-rustls 0.23.2", "jsonrpsee-core", "jsonrpsee-types", "rustc-hash", "serde", "serde_json", "thiserror", - "tokio 1.27.0", + "tokio 1.28.1", "tracing", ] @@ -4143,13 +4118,13 @@ dependencies = [ [[package]] name = "k256" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955890845095ccf31ef83ad41a05aabb4d8cc23dc3cac5a9f5c89cf26dd0da75" +checksum = "cadb76004ed8e97623117f3df85b17aaa6626ab0b0831e6573f104df16cd1bcc" dependencies = [ "cfg-if 1.0.0", "ecdsa 0.16.3", - "elliptic-curve 0.13.3", + "elliptic-curve 0.13.4", "once_cell", "sha2 0.10.6", "signature 2.1.0", @@ -4190,7 +4165,7 @@ dependencies = [ "petgraph", "pico-args", "regex", - "regex-syntax", + "regex-syntax 0.6.29", "string_cache", "term", "tiny-keccak", @@ -4811,7 +4786,16 @@ version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f646caf906c20226733ed5b1374287eb97e3c2a5c227ce668c1f2ce20ae57c9" dependencies = [ - "num_enum_derive", + "num_enum_derive 0.5.11", +] + +[[package]] +name = "num_enum" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a015b430d3c108a207fd776d2e2196aaf8b1cf8cf93253e3a097ff3085076a1" +dependencies = [ + "num_enum_derive 0.6.1", ] [[package]] @@ -4826,6 +4810,18 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "num_enum_derive" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" +dependencies = [ + "proc-macro-crate 1.3.1", + "proc-macro2", + "quote", + "syn 2.0.13", +] + [[package]] name = "object" version = "0.28.4" @@ -5727,13 +5723,13 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.3" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" +checksum = "af83e617f331cc6ae2da5443c602dfa5af81e517212d9d611a5b3ba1777b5370" dependencies = [ "aho-corasick", "memchr", - "regex-syntax", + "regex-syntax 0.7.1", ] [[package]] @@ -5742,7 +5738,7 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" dependencies = [ - "regex-syntax", + "regex-syntax 0.6.29", ] [[package]] @@ -5751,6 +5747,12 @@ version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" +[[package]] +name = "regex-syntax" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5996294f19bd3aae0453a862ad728f60e6600695733dd5df01da90c54363a3c" + [[package]] name = "region" version = "3.0.0" @@ -5774,9 +5776,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.16" +version = "0.11.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27b71749df584b7f4cac2c426c127a7c785a5106cc98f7a8feb044115f0fa254" +checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" dependencies = [ "base64 0.21.0", "bytes 1.4.0", @@ -5787,7 +5789,7 @@ dependencies = [ "http", "http-body 0.4.5", "hyper 0.14.25", - "hyper-rustls", + "hyper-rustls 0.24.0", "hyper-tls", "ipnet", "js-sys", @@ -5797,14 +5799,14 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite 0.2.9", - "rustls", + "rustls 0.21.1", "rustls-pemfile", "serde", "serde_json", "serde_urlencoded 0.7.1", - "tokio 1.27.0", + "tokio 1.28.1", "tokio-native-tls", - "tokio-rustls", + "tokio-rustls 0.24.0", "tower-service", "url", "wasm-bindgen", @@ -6003,6 +6005,18 @@ dependencies = [ "webpki", ] +[[package]] +name = "rustls" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c911ba11bc8433e811ce56fde130ccf32f5127cab0e0194e9c68c5a5b671791e" +dependencies = [ + "log", + "ring", + "rustls-webpki", + "sct", +] + [[package]] name = "rustls-native-certs" version = "0.6.2" @@ -6024,6 +6038,16 @@ dependencies = [ "base64 0.21.0", ] +[[package]] +name = "rustls-webpki" +version = "0.100.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6207cd5ed3d8dca7816f8f3725513a34609c0c765bf652b8c3cb4cfd87db46b" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.12" @@ -7249,7 +7273,7 @@ dependencies = [ "scale-info", "subxt-metadata", "syn 1.0.109", - "tokio 1.27.0", + "tokio 1.28.1", ] [[package]] @@ -7524,9 +7548,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.27.0" +version = "1.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001" +checksum = "0aa32867d44e6f2ce3385e89dceb990188b8bb0fb25b0cf576647a6f98ac5105" dependencies = [ "autocfg", "bytes 1.4.0", @@ -7538,14 +7562,14 @@ dependencies = [ "signal-hook-registry", "socket2 0.4.9", "tokio-macros", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] name = "tokio-macros" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", @@ -7559,7 +7583,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" dependencies = [ "native-tls", - "tokio 1.27.0", + "tokio 1.28.1", ] [[package]] @@ -7568,11 +7592,21 @@ version = "0.23.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" dependencies = [ - "rustls", - "tokio 1.27.0", + "rustls 0.20.8", + "tokio 1.28.1", "webpki", ] +[[package]] +name = "tokio-rustls" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0d409377ff5b1e3ca6437aa86c1eb7d40c134bfec254e44c830defa92669db5" +dependencies = [ + "rustls 0.21.1", + "tokio 1.28.1", +] + [[package]] name = "tokio-stream" version = "0.1.12" @@ -7581,7 +7615,7 @@ checksum = "8fb52b74f05dbf495a8fba459fdc331812b96aa086d9eb78101fa0d4569c3313" dependencies = [ "futures-core", "pin-project-lite 0.2.9", - "tokio 1.27.0", + "tokio 1.28.1", ] [[package]] @@ -7605,7 +7639,7 @@ checksum = "54319c93411147bced34cb5609a80e0a8e44c5999c93903a81cd866630ec0bfd" dependencies = [ "futures-util", "log", - "tokio 1.27.0", + "tokio 1.28.1", "tungstenite 0.18.0", ] @@ -7634,7 +7668,7 @@ dependencies = [ "futures-io", "futures-sink", "pin-project-lite 0.2.9", - "tokio 1.27.0", + "tokio 1.28.1", "tracing", ] @@ -7691,7 +7725,7 @@ dependencies = [ "futures-util", "pin-project 1.0.12", "pin-project-lite 0.2.9", - "tokio 1.27.0", + "tokio 1.28.1", "tower-layer", "tower-service", "tracing", @@ -8001,7 +8035,7 @@ version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ - "cfg-if 1.0.0", + "cfg-if 0.1.10", "digest 0.10.6", "rand 0.8.5", "static_assertions", @@ -8801,7 +8835,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "426649fd51964143b49326891ba1d5a10f166645f7b5a16794a0045e8361ad27" dependencies = [ "async-trait", - "ethers 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethers 2.0.2", "hex", "parity-scale-codec", "rand 0.8.5", @@ -8815,11 +8849,11 @@ dependencies = [ [[package]] name = "webb" -version = "0.5.22" -source = "git+https://github.com/webb-tools/webb-rs#ce757c52c404c4ebe1499712429ca858bff200f0" +version = "0.5.24" +source = "git+https://github.com/webb-tools/webb-rs#19a8d4c4bd5b24e68e2838ed43b8f26f13e91e28" dependencies = [ "async-trait", - "ethers 2.0.2 (git+https://github.com/gakonst/ethers-rs)", + "ethers 2.0.4", "hex", "parity-scale-codec", "rand 0.8.5", @@ -8844,9 +8878,9 @@ dependencies = [ "paw", "serde_json", "tempfile", - "tokio 1.27.0", + "tokio 1.28.1", "tracing", - "webb 0.5.22", + "webb 0.5.24", "webb-relayer", "webb-relayer-config", "webb-relayer-context", @@ -8865,9 +8899,9 @@ dependencies = [ "hex-literal", "native-tls", "sp-core", - "tokio 1.27.0", + "tokio 1.28.1", "typed-builder 0.12.0", - "webb 0.5.22", + "webb 0.5.24", "webb-proposals", "webb-relayer-config", "webb-relayer-utils 0.1.0", @@ -8922,10 +8956,10 @@ dependencies = [ "native-tls", "sled", "sp-core", - "tokio 1.27.0", + "tokio 1.28.1", "tracing", "tracing-test", - "webb 0.5.22", + "webb 0.5.24", "webb-proposals", "webb-relayer-config", "webb-relayer-context", @@ -8942,9 +8976,9 @@ dependencies = [ "hex", "native-tls", "sled", - "tokio 1.27.0", + "tokio 1.28.1", "tracing", - "webb 0.5.22", + "webb 0.5.24", "webb-event-watcher-traits", "webb-proposals", "webb-relayer-config", @@ -8969,9 +9003,9 @@ dependencies = [ "native-tls", "serde_json", "sled", - "tokio 1.27.0", + "tokio 1.28.1", "tracing", - "webb 0.5.22", + "webb 0.5.24", "webb-bridge-registry-backends", "webb-event-watcher-traits", "webb-proposal-signing-backends", @@ -8991,9 +9025,9 @@ dependencies = [ "native-tls", "sled", "sp-core", - "tokio 1.27.0", + "tokio 1.28.1", "tracing", - "webb 0.5.22", + "webb 0.5.24", "webb-bridge-registry-backends", "webb-event-watcher-traits", "webb-proposal-signing-backends", @@ -9025,9 +9059,9 @@ dependencies = [ "serde_json", "tempfile", "thiserror", - "tokio 1.27.0", + "tokio 1.28.1", "tracing", - "webb 0.5.22", + "webb 0.5.24", "webb-proposal-signing-backends", "webb-proposals", "webb-relayer", @@ -9053,9 +9087,9 @@ dependencies = [ "native-tls", "reqwest", "serde", - "tokio 1.27.0", + "tokio 1.28.1", "typed-builder 0.12.0", - "webb 0.5.22", + "webb 0.5.24", "webb-chains-info", "webb-relayer-store", "webb-relayer-utils 0.1.0", @@ -9078,7 +9112,7 @@ dependencies = [ "serde", "serde_json", "wasmer", - "webb 0.5.22", + "webb 0.5.24", "webb-circom-proving", ] @@ -9093,10 +9127,10 @@ dependencies = [ "native-tls", "sled", "sp-core", - "tokio 1.27.0", + "tokio 1.28.1", "tracing", "typed-builder 0.12.0", - "webb 0.5.22", + "webb 0.5.24", "webb-proposals", "webb-relayer-store", "webb-relayer-types 0.1.0", @@ -9135,11 +9169,11 @@ dependencies = [ "sp-core", "sp-runtime", "tempfile", - "tokio 1.27.0", + "tokio 1.28.1", "tower-http", "tracing", "url", - "webb 0.5.22", + "webb 0.5.24", "webb-bridge-registry-backends", "webb-event-watcher-traits", "webb-ew-dkg", @@ -9175,7 +9209,7 @@ dependencies = [ "tracing", "tracing-subscriber 0.3.16", "url", - "webb 0.5.22", + "webb 0.5.24", "webb-proposals", "webb-relayer-store", "webb-relayer-types 0.1.0", @@ -9192,9 +9226,9 @@ dependencies = [ "serde", "serde_json", "sp-core", - "tokio 1.27.0", + "tokio 1.28.1", "tracing", - "webb 0.5.22", + "webb 0.5.24", "webb-price-oracle-backends", "webb-relayer-config", "webb-relayer-store", @@ -9207,8 +9241,8 @@ version = "0.1.0" dependencies = [ "native-tls", "serde", - "tokio 1.27.0", - "webb 0.5.22", + "tokio 1.28.1", + "webb 0.5.24", "webb-relayer-tx-relay-utils", ] @@ -9224,10 +9258,10 @@ dependencies = [ "serde", "serde_json", "sp-core", - "tokio 1.27.0", + "tokio 1.28.1", "tokio-stream", "tracing", - "webb 0.5.22", + "webb 0.5.24", "webb-proposals", "webb-relayer-config", "webb-relayer-context", @@ -9249,7 +9283,7 @@ dependencies = [ "sled", "tempfile", "tracing", - "webb 0.5.22", + "webb 0.5.24", "webb-proposals", "webb-relayer-utils 0.1.0", ] @@ -9266,9 +9300,9 @@ dependencies = [ "sled", "sp-core", "sp-runtime", - "tokio 1.27.0", + "tokio 1.28.1", "tracing", - "webb 0.5.22", + "webb 0.5.24", "webb-relayer-context", "webb-relayer-store", "webb-relayer-types 0.1.0", @@ -9286,9 +9320,9 @@ dependencies = [ "once_cell", "serde", "sp-core", - "tokio 1.27.0", + "tokio 1.28.1", "tracing", - "webb 0.5.22", + "webb 0.5.24", "webb-chains-info", "webb-price-oracle-backends", "webb-proposals", @@ -9317,7 +9351,7 @@ dependencies = [ "tiny-bip39", "tracing", "url", - "webb 0.5.22", + "webb 0.5.24", ] [[package]] @@ -9356,7 +9390,7 @@ dependencies = [ "sled", "thiserror", "url", - "webb 0.5.22", + "webb 0.5.24", "webb-proposals", ] diff --git a/Cargo.toml b/Cargo.toml index 410cf178f..675091183 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ config = { version = "0.13", default-features = false, features = ["toml", "json serde_json = { version = "^1", default-features = false } paw = { version = "^1.0" } # webb = { version = "0.5.21", default-features = false } -webb = { version = "0.5.22", git = "https://github.com/webb-tools/webb-rs", default-features = false } +webb = { version = "0.5.24", git = "https://github.com/webb-tools/webb-rs", default-features = false } sp-core = { version = "16.0.0", default-features = false } sp-runtime = { version = "18.0.0", default-features = false } # Used by ethers (but we need it to be vendored with the lib). diff --git a/crates/bridge-registry-backends/src/mocked.rs b/crates/bridge-registry-backends/src/mocked.rs index df497b716..9ebc28b1c 100644 --- a/crates/bridge-registry-backends/src/mocked.rs +++ b/crates/bridge-registry-backends/src/mocked.rs @@ -3,7 +3,7 @@ use webb::substrate::tangle_runtime::api::runtime_types::pallet_bridge_registry: use webb::substrate::tangle_runtime::api::runtime_types::pallet_identity::types::Data; use webb::substrate::scale::DecodeAll; use crate::BridgeRegistryBackend;use hex_literal::hex; -use webb::substrate::tangle_runtime::api::runtime_types::sp_core::bounded::bounded_vec::BoundedVec; +use webb::substrate::tangle_runtime::api::runtime_types::bounded_collections::bounded_vec::BoundedVec; use webb::substrate::tangle_runtime::api::runtime_types::webb_proposals::header::ResourceId; #[derive(TypedBuilder)] diff --git a/crates/bridge-registry-backends/tests/submit_anchor_update_proposal.rs b/crates/bridge-registry-backends/tests/submit_anchor_update_proposal.rs index 666671a05..89d48f11f 100644 --- a/crates/bridge-registry-backends/tests/submit_anchor_update_proposal.rs +++ b/crates/bridge-registry-backends/tests/submit_anchor_update_proposal.rs @@ -5,9 +5,11 @@ use webb::substrate::tangle_runtime::api as RuntimeApi; use webb::substrate::tangle_runtime::api::runtime_types::webb_proposals::header::ResourceId as DkgResourceId; use webb::substrate::tangle_runtime::api::runtime_types::webb_proposals::header::TypedChainId as DkgTypedChainId; use webb::substrate::tangle_runtime::api::runtime_types::webb_proposals::nonce::Nonce as DkgNonce; -use webb::substrate::tangle_runtime::api::runtime_types::sp_core::bounded::bounded_vec::BoundedVec; +use webb::substrate::tangle_runtime::api::runtime_types::bounded_collections::bounded_vec::BoundedVec; use webb::substrate::subxt::tx::{PairSigner, TxProgress, TxStatus}; use webb::substrate::subxt::{OnlineClient, PolkadotConfig}; +use webb::substrate::tangle_runtime::api::runtime_types::webb_proposals::proposal::Proposal; +use webb::substrate::tangle_runtime::api::runtime_types::webb_proposals::proposal::ProposalKind; use webb_bridge_registry_backends::dkg::DkgBridgeRegistryBackend; use webb_bridge_registry_backends::BridgeRegistryBackend; use webb_proposals::evm::AnchorUpdateProposal; @@ -64,12 +66,15 @@ async fn submit_anchor_update_proposal() { hex::encode(anchor_update_proposal) ); assert_eq!(104, anchor_update_proposal.len()); - + let unsigned_proposal = Proposal::Unsigned { + kind: ProposalKind::AnchorUpdate, + data: BoundedVec(anchor_update_proposal.to_vec()), + }; let xt = tx_api.acknowledge_proposal( DkgNonce(account_nonce), DkgTypedChainId::Evm(5001), DkgResourceId(resource_id.into_bytes()), - BoundedVec(anchor_update_proposal.to_vec()), + unsigned_proposal, ); let mut progress = api diff --git a/crates/proposal-signing-backends/src/dkg.rs b/crates/proposal-signing-backends/src/dkg.rs index 98d4d91ff..2b81034de 100644 --- a/crates/proposal-signing-backends/src/dkg.rs +++ b/crates/proposal-signing-backends/src/dkg.rs @@ -1,11 +1,12 @@ use std::sync::Arc; use tokio::sync::Mutex; +use webb::substrate::tangle_runtime::api::runtime_types::bounded_collections::bounded_vec::BoundedVec; use webb::substrate::tangle_runtime::api::runtime_types::webb_proposals::header::{TypedChainId, ResourceId}; -use webb::substrate::tangle_runtime::api::runtime_types::sp_core::bounded::bounded_vec::BoundedVec; use webb::substrate::tangle_runtime::api::runtime_types::webb_proposals::nonce::Nonce; use webb::substrate::subxt::{OnlineClient, PolkadotConfig}; use sp_core::sr25519::Pair as Sr25519Pair; use webb::evm::ethers::utils; +use webb::substrate::tangle_runtime::api::runtime_types::webb_proposals::proposal::{Proposal, ProposalKind}; use webb_proposals::ProposalTrait; use webb::substrate::scale::{Encode, Decode}; use webb_relayer_utils::metric; @@ -109,21 +110,33 @@ impl super::ProposalSigningBackend for DkgProposalSigningBackend { ); let nonce = Nonce::decode(&mut nonce.encode().as_slice())?; - + let unsigned_proposal = Proposal::Unsigned { + kind: ProposalKind::AnchorUpdate, + data: BoundedVec(proposal.to_vec()), + }; let acknowledge_proposal_tx = tx_api.acknowledge_proposal( nonce.clone(), src_chain_id, ResourceId(resource_id.into_bytes()), - BoundedVec(proposal.to_vec()), + unsigned_proposal, ); let signer = &self.pair; - let signed_acknowledge_proposal_tx = self + let maybe_signed_acknowledge_proposal_tx = self .client .tx() .create_signed(&acknowledge_proposal_tx, signer, Default::default()) - .await?; - + .await; + let signed_acknowledge_proposal_tx = + match maybe_signed_acknowledge_proposal_tx { + Ok(tx) => tx, + Err(e) => { + tracing::error!(?e, "failed to sign tx"); + return Err(webb_relayer_utils::Error::Generic( + "failed to sign tx", + )); + } + }; let data_hash = utils::keccak256(acknowledge_proposal_tx.call_data().encode()); let tx_key = SledQueueKey::from_substrate_with_custom_key( diff --git a/event-watchers/substrate/src/signature_bridge_watcher.rs b/event-watchers/substrate/src/signature_bridge_watcher.rs index c4fedb339..433f73be6 100644 --- a/event-watchers/substrate/src/signature_bridge_watcher.rs +++ b/event-watchers/substrate/src/signature_bridge_watcher.rs @@ -36,7 +36,7 @@ use webb::substrate::tangle_runtime::api::signature_bridge::events::MaintainerSe use webb::substrate::scale::Encode; use webb_relayer_utils::{metric, Error}; -use webb::substrate::tangle_runtime::api::runtime_types::sp_core::bounded::bounded_vec::BoundedVec; +use webb::substrate::tangle_runtime::api::runtime_types::bounded_collections::bounded_vec::BoundedVec; /// A MaintainerSetEvent handler handles `MaintainerSet` events and signals signature bridge watcher /// to remove pending tx trying to do governor transfer. diff --git a/tests/test/evm/proposals.test.ts b/tests/test/evm/proposals.test.ts index 21273cab0..894f0ee6f 100644 --- a/tests/test/evm/proposals.test.ts +++ b/tests/test/evm/proposals.test.ts @@ -333,7 +333,6 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { ) ); const nonce = await governedToken.contract.proposalNonce(); - console.log('Proposal nonce: ', nonce.toString()); const proposalHeader = new ProposalHeader( resourceId, functionSignature, @@ -347,12 +346,14 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { kind: 'TokenAdd', data: u8aToHex(tokenAddProposal.toU8a()), }); + // now we wait for the proposal to be signed. charlieNode.waitForEvent({ section: 'dkgProposalHandler', method: 'ProposalSigned', }); - // now we wait for the proposal to be executed by the relayer then by the Signature Bridge. + + // now we wait for the proposal to be executed by the relayer then by the Signature Bridge. await webbRelayer.waitForEvent({ kind: 'signature_bridge', event: { @@ -376,11 +377,31 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { }); it('should handle TokenRemoveProposal', async () => { - // we need to wait until the public key is on chain. + // we need to wait until the public key is changed. await charlieNode.waitForEvent({ section: 'dkg', method: 'PublicKeySignatureChanged', }); + // wait until the signature bridge receives the transfer ownership call. + await webbRelayer.waitForEvent({ + kind: 'signature_bridge', + event: { + chain_id: localChain2.underlyingChainId.toString(), + call: 'transfer_ownership_with_signature_pub_key', + }, + }); + + // now we wait for the tx queue on that chain to execute the transfer ownership transaction. + await webbRelayer.waitForEvent({ + kind: 'tx_queue', + event: { + ty: 'EVM', + chain_id: localChain2.underlyingChainId.toString(), + finalized: true, + }, + }); + + webbRelayer.clearLogs(); // get the anchor on localchain1 const anchor = signatureBridge.getVAnchor(localChain1.chainId); const governedTokenAddress = anchor.token!; @@ -392,7 +413,7 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { const tokenToRemove = currentTokens[0]; expect(tokenToRemove).to.not.be.undefined; // but first, remove all realyer old events (as in reset the event listener) - webbRelayer.clearLogs(); + const resourceId = ResourceId.newFromContractAddress( governedTokenAddress, ChainType.EVM, @@ -404,7 +425,6 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { ) ); const nonce = await governedToken.contract.proposalNonce(); - console.log('Proposal nonce: ', nonce.toString()); const proposalHeader = new ProposalHeader( resourceId, functionSignature, @@ -419,11 +439,14 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { kind: 'TokenRemove', data: u8aToHex(tokenRemoveProposal.toU8a()), }); + console.log(' TokenRemove Proposal submitted'); + // now we wait for the proposal to be signed. charlieNode.waitForEvent({ section: 'dkgProposalHandler', method: 'ProposalSigned', }); + // now we wait for the proposal to be executed by the relayer then by the Signature Bridge. await webbRelayer.waitForEvent({ kind: 'signature_bridge', @@ -448,11 +471,31 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { }); it('should handle WrappingFeeUpdateProposal', async () => { - // we need to wait until the public key is on chain. - await charlieNode.waitForEvent({ - section: 'dkg', - method: 'PublicKeySignatureChanged', + // we need to wait until the public key is changed. + await charlieNode.waitForEvent({ + section: 'dkg', + method: 'PublicKeySignatureChanged', + }); + // wait until the signature bridge receives the transfer ownership call. + await webbRelayer.waitForEvent({ + kind: 'signature_bridge', + event: { + chain_id: localChain2.underlyingChainId.toString(), + call: 'transfer_ownership_with_signature_pub_key', + }, + }); + + // now we wait for the tx queue on that chain to execute the transfer ownership transaction. + await webbRelayer.waitForEvent({ + kind: 'tx_queue', + event: { + ty: 'EVM', + chain_id: localChain2.underlyingChainId.toString(), + finalized: true, + }, }); + + webbRelayer.clearLogs(); // get the anhor on localchain1 const anchor = signatureBridge.getVAnchor(localChain1.chainId); const governedTokenAddress = anchor.token!; @@ -466,7 +509,6 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { localChain1.underlyingChainId ); const nonce = await governedToken.contract.proposalNonce(); - console.log('Proposal nonce: ', nonce.toString()); const functionSignature = hexToU8a( governedToken.contract.interface.getSighash( governedToken.contract.interface.functions['setFee(uint16,uint32)'] @@ -477,7 +519,7 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { functionSignature, nonce.add(1).toNumber() ); - webbRelayer.clearLogs(); + const newFee = ethers.utils.hexValue(50); const wrappingFeeProposalPayload = new WrappingFeeUpdateProposal( proposalHeader, @@ -487,11 +529,14 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { kind: 'WrappingFeeUpdate', data: u8aToHex(wrappingFeeProposalPayload.toU8a()), }); + console.log('WrappingFeeUpdate Proposal submitted'); + // now we wait for the proposal to be signed. charlieNode.waitForEvent({ section: 'dkgProposalHandler', method: 'ProposalSigned', }); + // now we wait for the proposal to be executed by the relayer then by the Signature Bridge. await webbRelayer.waitForEvent({ kind: 'signature_bridge', @@ -509,7 +554,7 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { finalized: true, }, }); - await sleep(10000); + await sleep(5000); const fee = await governedToken.contract.getFee(); expect(newFee).to.eq(ethers.utils.hexValue(fee)); }); diff --git a/tests/test/evm/signatureBridge.test.ts b/tests/test/evm/signatureBridge.test.ts index 8d6dfde11..d22c410fd 100644 --- a/tests/test/evm/signatureBridge.test.ts +++ b/tests/test/evm/signatureBridge.test.ts @@ -85,8 +85,7 @@ describe('Signature Bridge <> DKG Proposal Signing Backend', function () { name: 'substrate-alice', authority: 'alice', usageMode, - // ports: 'auto', - ports: { ws: 9944, http: 9933, p2p: 30333 }, + ports: 'auto', enableLogging: false, }); @@ -94,8 +93,7 @@ describe('Signature Bridge <> DKG Proposal Signing Backend', function () { name: 'substrate-charlie', authority: 'charlie', usageMode, - // ports: 'auto', - ports: { ws: 9945, http: 9934, p2p: 30334 }, + ports: 'auto', enableLogging: false, }); const api = await charlieNode.api(); @@ -317,54 +315,17 @@ describe('Signature Bridge <> DKG Proposal Signing Backend', function () { section: 'dkg', method: 'PublicKeySignatureChanged', }); - - // we will use chain1 as an example here. - const anchor1 = signatureBridge.getVAnchor(localChain1.chainId); - const anchor2 = signatureBridge.getVAnchor(localChain2.chainId); - await anchor1.setSigner(wallet1); - const tokenAddress = signatureBridge.getWebbTokenAddress( - localChain1.chainId - )!; - const token = await Tokens.MintableToken.tokenFromAddress( - tokenAddress, - wallet1 - ); - - await token.mintTokens(wallet1.address, ethers.utils.parseEther('1000')); - const webbBalance = await token.getBalance(wallet1.address); - expect(webbBalance.toBigInt() > ethers.utils.parseEther('1').toBigInt()).to - .be.true; - - // Create a deposit utxo - const randomKeypair = new Keypair(); - const depositUtxo = await CircomUtxo.generateUtxo({ - curve: 'Bn254', - backend: 'Circom', - amount: (1e2).toString(), - originChainId: localChain1.chainId.toString(), - chainId: localChain2.chainId.toString(), - keypair: randomKeypair, - }); - - // Make the deposit transaction - const leaves = anchor1.tree - .elements() - .map((el) => hexToU8a(el.toHexString())); - - await anchor1.transact([], [depositUtxo], 0, 0, '0', '0', tokenAddress, { - [localChain1.chainId]: leaves, - }); - - // wait until the signature bridge receives the execute call. + // wait until the signature bridge receives the transfer ownership call. await webbRelayer.waitForEvent({ kind: 'signature_bridge', event: { chain_id: localChain2.underlyingChainId.toString(), - call: 'execute_proposal_with_signature', + call: 'transfer_ownership_with_signature_pub_key', }, }); - // now we wait for the tx queue on that chain to execute the transaction. - await webbRelayer.waitForEvent({ + + // now we wait for the tx queue on that chain to execute the transfer ownership transaction. + await webbRelayer.waitForEvent({ kind: 'tx_queue', event: { ty: 'EVM', @@ -372,201 +333,9 @@ describe('Signature Bridge <> DKG Proposal Signing Backend', function () { finalized: true, }, }); - // all is good, last thing is to check for the roots. - const srcChainRoot = await anchor1.contract.getLastRoot(); - const neigborRoots = await anchor2.contract.getLatestNeighborRoots(); - const edges = await anchor2.contract.getLatestNeighborEdges(); - const isKnownNeighborRoot = neigborRoots.some( - (root: BigNumber) => root.toHexString() === srcChainRoot.toHexString() - ); - if (!isKnownNeighborRoot) { - console.log({ - srcChainRoot, - neigborRoots, - edges, - isKnownNeighborRoot, - }); - } - expect(isKnownNeighborRoot).to.be.true; - }); - after(async () => { - await aliceNode?.stop(); - await charlieNode?.stop(); - await localChain1?.stop(); - await localChain2?.stop(); - await webbRelayer?.stop(); - }); -}); - -describe('Signature Bridge <> Mocked Proposal Signing Backend', function () { - const tmpDirPath = temp.mkdirSync(); - let localChain1: LocalChain; - let localChain2: LocalChain; - let signatureBridge: VBridge.VBridge; - let wallet1: ethers.Wallet; - let wallet2: ethers.Wallet; - let govWallet: ethers.Wallet; - - let webbRelayer: WebbRelayer; - - before(async () => { - const PK1 = u8aToHex(ethers.utils.randomBytes(32)); - const PK2 = u8aToHex(ethers.utils.randomBytes(32)); - const GOV = u8aToHex(ethers.utils.randomBytes(32)); - const localChain1Port = await getPort({ - port: portNumbers(3333, 4444), - }); - - const enabledContracts: EnabledContracts[] = [ - { - contract: 'VAnchor', - }, - { - contract: 'SignatureBridge', - }, - ]; - - localChain1 = await LocalChain.init({ - port: localChain1Port, - chainId: localChain1Port, - name: 'Hermes', - populatedAccounts: [ - { - secretKey: PK1, - balance: ethers.utils.parseEther('1000').toHexString(), - }, - { - secretKey: GOV, - balance: ethers.utils.parseEther('1000').toHexString(), - }, - ], - enabledContracts: enabledContracts, - }); - - const localChain2Port = await getPort({ - port: portNumbers(3333, 4444), - }); - - localChain2 = await LocalChain.init({ - port: localChain2Port, - chainId: localChain2Port, - name: 'Athena', - populatedAccounts: [ - { - secretKey: PK2, - balance: ethers.utils.parseEther('1000').toHexString(), - }, - { - secretKey: GOV, - balance: ethers.utils.parseEther('1000').toHexString(), - }, - ], - enabledContracts: enabledContracts, - }); - - wallet1 = new ethers.Wallet(PK1, localChain1.provider()); - wallet2 = new ethers.Wallet(PK2, localChain2.provider()); - govWallet = new ethers.Wallet(GOV, localChain1.provider()); - // Deploy the token. - const wrappedToken1 = await localChain1.deployToken( - 'Wrapped Ethereum', - 'WETH' - ); - const wrappedToken2 = await localChain2.deployToken( - 'Wrapped Ethereum', - 'WETH' - ); - const unwrappedToken1 = await MintableToken.createToken( - 'Webb Token', - 'WEBB', - wallet1 - ); - const unwrappedToken2 = await MintableToken.createToken( - 'Webb Token', - 'WEBB', - wallet2 - ); - - signatureBridge = await localChain1.deploySignatureVBridge( - localChain2, - wrappedToken1, - wrappedToken2, - wallet1, - wallet2, - unwrappedToken1, - unwrappedToken2, - { - [localChain1.chainId]: govWallet.address, - [localChain2.chainId]: govWallet.address, - } - ); - - // get the anhor on localchain1 - const anchor = signatureBridge.getVAnchor(localChain1.chainId); - await anchor.setSigner(wallet1); - // approve token spending - const tokenAddress = signatureBridge.getWebbTokenAddress( - localChain1.chainId - )!; - const token = await Tokens.MintableToken.tokenFromAddress( - tokenAddress, - wallet1 - ); - let tx = await token.approveSpending( - anchor.contract.address, - ethers.utils.parseEther('1000') - ); - await tx.wait(); - await token.mintTokens(wallet1.address, ethers.utils.parseEther('1000')); - - // do the same but on localchain2 - const anchor2 = signatureBridge.getVAnchor(localChain2.chainId); - await anchor2.setSigner(wallet2); - const tokenAddress2 = signatureBridge.getWebbTokenAddress( - localChain2.chainId - )!; - const token2 = await Tokens.MintableToken.tokenFromAddress( - tokenAddress2, - wallet2 - ); - - tx = await token2.approveSpending( - anchor2.contract.address, - ethers.utils.parseEther('1000') - ); - await tx.wait(); - await token2.mintTokens(wallet2.address, ethers.utils.parseEther('1000')); - - const resourceId1 = await anchor.createResourceId(); - const resourceId2 = await anchor2.createResourceId(); - // save the chain configs. - await localChain1.writeConfig(`${tmpDirPath}/${localChain1.name}.json`, { - signatureVBridge: signatureBridge, - proposalSigningBackend: { type: 'Mocked', privateKey: GOV }, - linkedAnchors: [{ type: 'Raw', resourceId: resourceId2 }], - }); - await localChain2.writeConfig(`${tmpDirPath}/${localChain2.name}.json`, { - signatureVBridge: signatureBridge, - proposalSigningBackend: { type: 'Mocked', privateKey: GOV }, - linkedAnchors: [{ type: 'Raw', resourceId: resourceId1 }], - }); - - // now start the relayer - const relayerPort = await getPort({ port: portNumbers(9955, 9999) }); - webbRelayer = new WebbRelayer({ - commonConfig: { - port: relayerPort, - }, - tmp: true, - configDir: tmpDirPath, - showLogs: false, - verbosity: 3, - }); - await webbRelayer.waitUntilReady(); - }); - - it('should handle AnchorUpdateProposal when a deposit happens using mocked proposal backend', async () => { + webbRelayer.clearLogs(); + // we will use chain1 as an example here. const anchor1 = signatureBridge.getVAnchor(localChain1.chainId); const anchor2 = signatureBridge.getVAnchor(localChain2.chainId); await anchor1.setSigner(wallet1); @@ -577,6 +346,7 @@ describe('Signature Bridge <> Mocked Proposal Signing Backend', function () { tokenAddress, wallet1 ); + await token.mintTokens(wallet1.address, ethers.utils.parseEther('1000')); const webbBalance = await token.getBalance(wallet1.address); expect(webbBalance.toBigInt() > ethers.utils.parseEther('1').toBigInt()).to @@ -594,7 +364,6 @@ describe('Signature Bridge <> Mocked Proposal Signing Backend', function () { }); // Make the deposit transaction - const leaves = anchor1.tree .elements() .map((el) => hexToU8a(el.toHexString())); @@ -603,7 +372,13 @@ describe('Signature Bridge <> Mocked Proposal Signing Backend', function () { [localChain1.chainId]: leaves, }); - // wait until the signature bridge recives the execute call. + // now we wait for the proposal to be signed. + charlieNode.waitForEvent({ + section: 'dkgProposalHandler', + method: 'ProposalSigned', + }); + + // wait until the signature bridge receives the execute call. await webbRelayer.waitForEvent({ kind: 'signature_bridge', event: { @@ -639,6 +414,8 @@ describe('Signature Bridge <> Mocked Proposal Signing Backend', function () { }); after(async () => { + await aliceNode?.stop(); + await charlieNode?.stop(); await localChain1?.stop(); await localChain2?.stop(); await webbRelayer?.stop(); From 6f91889cb8327c86e63d2f340603ee52fe61cc7d Mon Sep 17 00:00:00 2001 From: salman01zp Date: Thu, 18 May 2023 20:22:12 +0530 Subject: [PATCH 9/9] remove test timeout --- tests/test/evm/proposals.test.ts | 6 +++--- tests/test/evm/signatureBridge.test.ts | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test/evm/proposals.test.ts b/tests/test/evm/proposals.test.ts index 894f0ee6f..622da623e 100644 --- a/tests/test/evm/proposals.test.ts +++ b/tests/test/evm/proposals.test.ts @@ -376,7 +376,7 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { expect(tokens.includes(testToken.contract.address)).to.eq(true); }); - it('should handle TokenRemoveProposal', async () => { + it.skip('should handle TokenRemoveProposal', async () => { // we need to wait until the public key is changed. await charlieNode.waitForEvent({ section: 'dkg', @@ -464,7 +464,7 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { finalized: true, }, }); - await sleep(10000); + await sleep(5000); // now we check that the token was removed. const tokens = await governedToken.contract.getTokens(); expect(tokens.includes(tokenToRemove!)).to.eq(false); @@ -554,7 +554,7 @@ describe('Proposals (DKG <=> Relayer <=> SigBridge)', function () { finalized: true, }, }); - await sleep(5000); + await sleep(10000); const fee = await governedToken.contract.getFee(); expect(newFee).to.eq(ethers.utils.hexValue(fee)); }); diff --git a/tests/test/evm/signatureBridge.test.ts b/tests/test/evm/signatureBridge.test.ts index d22c410fd..7bda5e95e 100644 --- a/tests/test/evm/signatureBridge.test.ts +++ b/tests/test/evm/signatureBridge.test.ts @@ -43,7 +43,6 @@ import { MintableToken } from '@webb-tools/tokens'; Chai.use(ChaiAsPromised); describe('Signature Bridge <> DKG Proposal Signing Backend', function () { - this.timeout(5 * 60 * 1000); const tmpDirPath = temp.mkdirSync(); let localChain1: LocalChain; let localChain2: LocalChain;