trustless-generic-relayer/ethereum/ts-test/2_core_relayer.ts

68 lines
3.0 KiB
TypeScript
Raw Normal View History

2023-02-09 15:47:13 -08:00
import { expect } from "chai";
import { ethers } from "ethers";
import { ChainId, tryNativeToHexString } from "@certusone/wormhole-sdk";
Add tests for send and deliver functionality (#9) * Complete send and deliver functionality * Clean up * Add tests for relayer send method * ethereum: remove interfaces * ethereum: fix test * ethereum: rename directory * ethereum: clean up; add ts tests * Add tests and clean up * ethereum: fix test * ethereum: fix output * Add reentrancy protection and reduce gas overhead for relayers * Add tests for full batch delivery * Update relayer contracts to reflect changes to batch VAA implementation * add rewards payout * implement redeliveries, replay protection * Complete full batch test suite * sdk: add sdk * sdk: fix package.json * Add partial batch unit test and add to integration test * Fix comments in integration test * sdk: fix tsconfig.json * ethereum: fix build * Add relayer registration to integration test * Finish integration test suite * ethereum: fix readAbi * ethereum: fix merge conflict * Complete full batch test suite * Add partial batch unit test and add to integration test * Finish integration test suite * Fix local validator test * Fix merge conflict * Add Makefile * Add documentation to relayer contracts * Fix Makefile * ethereum: clean up * ethereum: fix interface * ethereum: fix method names and tests * Prepare integration test for off-chain relayer changes * Refactor contracts Co-authored-by: Drew <dsterioti@users.noreply.github.com> Co-authored-by: Karl Kempe <karlkempe@users.noreply.github.com> Co-authored-by: valentin <valentinvonalbrecht@yahoo.de> Co-authored-by: justinschuldt <justinschuldt@gmail.com>
2022-09-30 09:18:49 -07:00
import {
2023-02-09 15:47:13 -08:00
ChainInfo,
RELAYER_DEPLOYER_PRIVATE_KEY,
} from "./helpers/consts";
import { CoreRelayer__factory, IWormhole__factory, MockRelayerIntegration__factory } from "../../sdk/src";
import { init, loadChains, loadCoreRelayers, loadMockIntegrations } from "../ts-scripts/helpers/env";
Add tests for send and deliver functionality (#9) * Complete send and deliver functionality * Clean up * Add tests for relayer send method * ethereum: remove interfaces * ethereum: fix test * ethereum: rename directory * ethereum: clean up; add ts tests * Add tests and clean up * ethereum: fix test * ethereum: fix output * Add reentrancy protection and reduce gas overhead for relayers * Add tests for full batch delivery * Update relayer contracts to reflect changes to batch VAA implementation * add rewards payout * implement redeliveries, replay protection * Complete full batch test suite * sdk: add sdk * sdk: fix package.json * Add partial batch unit test and add to integration test * Fix comments in integration test * sdk: fix tsconfig.json * ethereum: fix build * Add relayer registration to integration test * Finish integration test suite * ethereum: fix readAbi * ethereum: fix merge conflict * Complete full batch test suite * Add partial batch unit test and add to integration test * Finish integration test suite * Fix local validator test * Fix merge conflict * Add Makefile * Add documentation to relayer contracts * Fix Makefile * ethereum: clean up * ethereum: fix interface * ethereum: fix method names and tests * Prepare integration test for off-chain relayer changes * Refactor contracts Co-authored-by: Drew <dsterioti@users.noreply.github.com> Co-authored-by: Karl Kempe <karlkempe@users.noreply.github.com> Co-authored-by: valentin <valentinvonalbrecht@yahoo.de> Co-authored-by: justinschuldt <justinschuldt@gmail.com>
2022-09-30 09:18:49 -07:00
2023-02-09 15:47:13 -08:00
const ETHEREUM_ROOT = `${__dirname}/..`;
Add tests for send and deliver functionality (#9) * Complete send and deliver functionality * Clean up * Add tests for relayer send method * ethereum: remove interfaces * ethereum: fix test * ethereum: rename directory * ethereum: clean up; add ts tests * Add tests and clean up * ethereum: fix test * ethereum: fix output * Add reentrancy protection and reduce gas overhead for relayers * Add tests for full batch delivery * Update relayer contracts to reflect changes to batch VAA implementation * add rewards payout * implement redeliveries, replay protection * Complete full batch test suite * sdk: add sdk * sdk: fix package.json * Add partial batch unit test and add to integration test * Fix comments in integration test * sdk: fix tsconfig.json * ethereum: fix build * Add relayer registration to integration test * Finish integration test suite * ethereum: fix readAbi * ethereum: fix merge conflict * Complete full batch test suite * Add partial batch unit test and add to integration test * Finish integration test suite * Fix local validator test * Fix merge conflict * Add Makefile * Add documentation to relayer contracts * Fix Makefile * ethereum: clean up * ethereum: fix interface * ethereum: fix method names and tests * Prepare integration test for off-chain relayer changes * Refactor contracts Co-authored-by: Drew <dsterioti@users.noreply.github.com> Co-authored-by: Karl Kempe <karlkempe@users.noreply.github.com> Co-authored-by: valentin <valentinvonalbrecht@yahoo.de> Co-authored-by: justinschuldt <justinschuldt@gmail.com>
2022-09-30 09:18:49 -07:00
2023-02-08 12:47:54 -08:00
init()
2023-02-09 15:47:13 -08:00
const chains = loadChains();
const coreRelayers = loadCoreRelayers();
const mockIntegrations = loadMockIntegrations();
2023-02-08 12:47:54 -08:00
2023-02-09 14:46:42 -08:00
describe("Core Relayer Integration Test - Two Chains", () => {
2023-02-09 15:47:13 -08:00
const provider = new ethers.providers.StaticJsonRpcProvider(chains[0].rpc);
Add tests for send and deliver functionality (#9) * Complete send and deliver functionality * Clean up * Add tests for relayer send method * ethereum: remove interfaces * ethereum: fix test * ethereum: rename directory * ethereum: clean up; add ts tests * Add tests and clean up * ethereum: fix test * ethereum: fix output * Add reentrancy protection and reduce gas overhead for relayers * Add tests for full batch delivery * Update relayer contracts to reflect changes to batch VAA implementation * add rewards payout * implement redeliveries, replay protection * Complete full batch test suite * sdk: add sdk * sdk: fix package.json * Add partial batch unit test and add to integration test * Fix comments in integration test * sdk: fix tsconfig.json * ethereum: fix build * Add relayer registration to integration test * Finish integration test suite * ethereum: fix readAbi * ethereum: fix merge conflict * Complete full batch test suite * Add partial batch unit test and add to integration test * Finish integration test suite * Fix local validator test * Fix merge conflict * Add Makefile * Add documentation to relayer contracts * Fix Makefile * ethereum: clean up * ethereum: fix interface * ethereum: fix method names and tests * Prepare integration test for off-chain relayer changes * Refactor contracts Co-authored-by: Drew <dsterioti@users.noreply.github.com> Co-authored-by: Karl Kempe <karlkempe@users.noreply.github.com> Co-authored-by: valentin <valentinvonalbrecht@yahoo.de> Co-authored-by: justinschuldt <justinschuldt@gmail.com>
2022-09-30 09:18:49 -07:00
// signers
2023-02-09 15:47:13 -08:00
const wallet = new ethers.Wallet(RELAYER_DEPLOYER_PRIVATE_KEY, provider);
Add tests for send and deliver functionality (#9) * Complete send and deliver functionality * Clean up * Add tests for relayer send method * ethereum: remove interfaces * ethereum: fix test * ethereum: rename directory * ethereum: clean up; add ts tests * Add tests and clean up * ethereum: fix test * ethereum: fix output * Add reentrancy protection and reduce gas overhead for relayers * Add tests for full batch delivery * Update relayer contracts to reflect changes to batch VAA implementation * add rewards payout * implement redeliveries, replay protection * Complete full batch test suite * sdk: add sdk * sdk: fix package.json * Add partial batch unit test and add to integration test * Fix comments in integration test * sdk: fix tsconfig.json * ethereum: fix build * Add relayer registration to integration test * Finish integration test suite * ethereum: fix readAbi * ethereum: fix merge conflict * Complete full batch test suite * Add partial batch unit test and add to integration test * Finish integration test suite * Fix local validator test * Fix merge conflict * Add Makefile * Add documentation to relayer contracts * Fix Makefile * ethereum: clean up * ethereum: fix interface * ethereum: fix method names and tests * Prepare integration test for off-chain relayer changes * Refactor contracts Co-authored-by: Drew <dsterioti@users.noreply.github.com> Co-authored-by: Karl Kempe <karlkempe@users.noreply.github.com> Co-authored-by: valentin <valentinvonalbrecht@yahoo.de> Co-authored-by: justinschuldt <justinschuldt@gmail.com>
2022-09-30 09:18:49 -07:00
2023-02-09 15:47:13 -08:00
const sourceChain = chains.find((c)=>(c.chainId == 2)) as ChainInfo;
const targetChain = chains.find((c)=>(c.chainId == 4)) as ChainInfo;
const sourceCoreRelayerAddress = coreRelayers.find((p)=>(p.chainId==sourceChain.chainId))?.address as string
const sourceMockIntegrationAddress = mockIntegrations.find((p)=>(p.chainId==sourceChain.chainId))?.address as string
const targetCoreRelayerAddress = coreRelayers.find((p)=>(p.chainId==targetChain.chainId))?.address as string
const targetMockIntegrationAddress = mockIntegrations.find((p)=>(p.chainId==targetChain.chainId))?.address as string
2023-02-09 14:46:42 -08:00
2023-02-09 15:47:13 -08:00
const sourceCoreRelayer = CoreRelayer__factory.connect(sourceCoreRelayerAddress, wallet);
const sourceMockIntegration = MockRelayerIntegration__factory.connect(sourceMockIntegrationAddress, wallet);
const targetCoreRelayer = CoreRelayer__factory.connect(targetCoreRelayerAddress, wallet);
const targetMockIntegration = MockRelayerIntegration__factory.connect(targetMockIntegrationAddress, wallet);
2023-02-09 14:46:42 -08:00
it("Executes a delivery", async (done) => {
2023-02-09 15:47:13 -08:00
2023-02-09 14:46:42 -08:00
try {
2023-02-09 15:47:13 -08:00
const originalMessage = await targetMockIntegration.getMessage();
console.log(`Sent message: ${originalMessage}`);
const arbitraryPayload = ethers.utils.hexlify(ethers.utils.toUtf8Bytes((Math.random()*1e32).toString(36)))
const value = await sourceCoreRelayer.quoteGasDeliveryFee(targetChain.chainId, 1000000, await sourceCoreRelayer.getDefaultRelayProvider());
2023-02-09 14:46:42 -08:00
console.log(`Quoted gas delivery fee: ${value}`)
2023-02-09 15:47:13 -08:00
const tx = await sourceMockIntegration.sendMessage(arbitraryPayload, targetChain.chainId, targetMockIntegrationAddress, targetMockIntegrationAddress, {value, gasLimit: 500000});
console.log("Sent delivery request!");
const rx = await tx.wait();
console.log("Message confirmed!");
2023-02-09 14:46:42 -08:00
setTimeout(async () => {
try {
console.log("Checking if message was relayed")
2023-02-09 15:47:13 -08:00
const message = await targetMockIntegration.getMessage();
console.log(`Sent message: ${arbitraryPayload}`);
2023-02-09 14:46:42 -08:00
console.log(`Received message: ${message}`)
2023-02-09 15:47:13 -08:00
expect(message).to.equal(arbitraryPayload);
2023-02-09 14:46:42 -08:00
done()
} catch (e) {
done(e)
}
}, 1000 * 30)
} catch (e) {
2023-02-09 15:47:13 -08:00
done(e);
2023-02-09 14:46:42 -08:00
}
2023-02-09 15:47:13 -08:00
});
});