update ts-test

This commit is contained in:
Joe Howarth 2023-02-09 23:45:43 +00:00 committed by chase-45
parent 0e9a3ad98e
commit 9bfee08792
1 changed files with 70 additions and 39 deletions

View File

@ -1,65 +1,96 @@
import { expect } from "chai";
import { ethers } from "ethers";
import { ChainId, tryNativeToHexString } from "@certusone/wormhole-sdk";
import { expect } from "chai"
import { ethers } from "ethers"
import { ChainId, tryNativeToHexString } from "@certusone/wormhole-sdk"
import { ChainInfo, RELAYER_DEPLOYER_PRIVATE_KEY } from "./helpers/consts"
import {
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";
CoreRelayer__factory,
IWormhole__factory,
MockRelayerIntegration__factory,
} from "../../sdk/src"
import {
init,
loadChains,
loadCoreRelayers,
loadMockIntegrations,
} from "../ts-scripts/helpers/env"
const ETHEREUM_ROOT = `${__dirname}/..`;
const ETHEREUM_ROOT = `${__dirname}/..`
init()
const chains = loadChains();
const coreRelayers = loadCoreRelayers();
const mockIntegrations = loadMockIntegrations();
const chains = loadChains()
const coreRelayers = loadCoreRelayers()
const mockIntegrations = loadMockIntegrations()
describe("Core Relayer Integration Test - Two Chains", () => {
const provider = new ethers.providers.StaticJsonRpcProvider(chains[0].rpc);
const provider = new ethers.providers.StaticJsonRpcProvider(chains[0].rpc)
// signers
const wallet = new ethers.Wallet(RELAYER_DEPLOYER_PRIVATE_KEY, provider);
const wallet = new ethers.Wallet(RELAYER_DEPLOYER_PRIVATE_KEY, provider)
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
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
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);
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
)
it("Executes a delivery", async (done) => {
try {
const arbitraryPayload = ethers.utils.hexlify(ethers.utils.toUtf8Bytes((Math.random()*1e32).toString(36)))
const value = await sourceCoreRelayer.quoteGasDeliveryFee(targetChain.chainId, 1000000, await sourceCoreRelayer.getDefaultRelayProvider());
const arbitraryPayload = ethers.utils.hexlify(
ethers.utils.toUtf8Bytes((Math.random() * 1e32).toString(36))
)
const value = await sourceCoreRelayer.quoteGasDeliveryFee(
targetChain.chainId,
1000000,
await sourceCoreRelayer.getDefaultRelayProvider()
)
console.log(`Quoted gas delivery fee: ${value}`)
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!");
const preMessage = await targetMockIntegration.getMessage()
console.log(`Original message: ${arbitraryPayload}`)
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!")
setTimeout(async () => {
try {
console.log("Checking if message was relayed")
const message = await targetMockIntegration.getMessage();
console.log(`Original message: ${arbitraryPayload}`);
const message = await targetMockIntegration.getMessage()
console.log(`Sent message: ${arbitraryPayload}`)
console.log(`Received message: ${message}`)
expect(message).to.equal(arbitraryPayload);
expect(message).to.equal(arbitraryPayload)
done()
} catch (e) {
done(e)
}
}, 1000 * 30)
} catch (e) {
done(e);
done(e)
}
});
});
})
})