2023-02-09 15:47:13 -08:00
|
|
|
import { expect } from "chai";
|
|
|
|
import { ethers } from "ethers";
|
|
|
|
import { ChainId, tryNativeToHexString } from "@certusone/wormhole-sdk";
|
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";
|
2022-09-30 09:18:49 -07:00
|
|
|
|
2023-02-09 15:47:13 -08:00
|
|
|
const ETHEREUM_ROOT = `${__dirname}/..`;
|
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);
|
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);
|
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
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|