Forwarding test passes!

This commit is contained in:
derpy-duck 2023-02-13 18:23:25 +00:00 committed by chase-45
parent 1401c88038
commit 249145af86
5 changed files with 179 additions and 65 deletions

View File

@ -89,6 +89,22 @@ contract MockRelayerIntegration is IWormholeReceiver {
executeSend(targetChainId, destination, refundAddress, receiverValue, nonce);
}
function sendMessagesWithFurtherInstructions(
bytes[] memory messages,
FurtherInstructions memory furtherInstructions,
uint16 targetChainId,
address destination,
address refundAddress,
uint256 applicationBudget,
uint32 nonce
) public payable {
for(uint16 i=0; i<messages.length; i++) {
wormhole.publishMessage{value: wormhole.messageFee()}(nonce, messages[i], 200);
}
wormhole.publishMessage{value: wormhole.messageFee()}(nonce, encodeFurtherInstructions(furtherInstructions), 200);
executeSend(targetChainId, destination, refundAddress, applicationBudget, nonce);
}
function executeSend(
uint16 targetChainId,
address destination,

View File

@ -4,31 +4,31 @@
"relayProviders": [
{
"chainId": 2,
"address": "0xb4fFe5983B0B748124577Af4d16953bd096b6897"
"address": "0x59a13b07fE44Aa7221Fd6C55A3E8df26d4E37a65"
},
{
"chainId": 4,
"address": "0xdFccc9C59c7361307d47c558ffA75840B32DbA29"
"address": "0x3e5399049a779489000583dD0d14576D0472Fe94"
}
],
"coreRelayers": [
{
"chainId": 2,
"address": "0x42D4BA5e542d9FeD87EA657f0295F1968A61c00A"
"address": "0x32e02F2934824ec085298E2B4e0e07935Ec6DaeC"
},
{
"chainId": 4,
"address": "0xFF5181e2210AB92a5c9db93729Bc47332555B9E9"
"address": "0xa69F4c9F17e4C90138c55279aAF1917352D435C7"
}
],
"mockIntegrations": [
{
"chainId": 2,
"address": "0x3F4E941ef5071a1D09C2eB4a24DA1Fc43F76fcfF"
"address": "0x3Cc7B9a386410858B412B00B13264654F68364Ed"
},
{
"chainId": 4,
"address": "0x0d3C71782055bD88A71b611972152d6e984EDF79"
"address": "0xba5b7E64bae1f953816B9f3a7de6B5b5378F9Fb8"
}
]
}

View File

@ -26,15 +26,13 @@ async function registerChainsCoreRelayer(chain: ChainInfo) {
console.log("registerChainsCoreRelayer " + chain.chainId)
const coreRelayer = getCoreRelayer(chain)
await coreRelayer
.setDefaultRelayProvider(createDefaultRelayProviderVAA(chain))
.then(wait)
for (let i = 0; i < chains.length; i++) {
await coreRelayer
.registerCoreRelayerContract(createRegisterChainVAA(chains[i]))
.then(wait)
.then(wait);
}
console.log("Did all contract registrations for the core relayer on " + chain.chainId)

View File

@ -1,5 +1,8 @@
import { init, loadChains, writeOutputFiles } from "../helpers/env"
import { init, loadChains, writeOutputFiles, getMockIntegration } from "../helpers/env"
import { deployMockIntegration } from "../helpers/deployments"
import { BigNumber } from "ethers"
import { tryNativeToHexString } from "@certusone/wormhole-sdk"
import { MockRelayerIntegration__factory } from "../../../sdk/src"
const processName = "deployMockIntegration"
init()
@ -18,6 +21,14 @@ async function run() {
}
writeOutputFiles(output, processName)
for (let i = 0; i < chains.length; i++) {
const mockIntegration = getMockIntegration(chains[i]);
for (let j = 0; j < chains.length; j++) {
const secondMockIntegration = output.mockIntegrations[j];
await mockIntegration.registerEmitter(secondMockIntegration.chainId, "0x"+tryNativeToHexString(secondMockIntegration.address, "ethereum"), {gasLimit: 500000}).then((tx) => tx.wait);
}
}
}
run().then(() => console.log("Done!"))

View File

@ -1,72 +1,161 @@
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 { generateRandomString } from "./helpers/utils"
import {
ChainInfo,
RELAYER_DEPLOYER_PRIVATE_KEY,
} from "./helpers/consts";
import { generateRandomString } from "./helpers/utils";
import { CoreRelayer__factory, IWormhole__factory, MockRelayerIntegration__factory } from "../../sdk/src";
import { init, loadChains, loadCoreRelayers, loadMockIntegrations } from "../ts-scripts/helpers/env";
const ETHEREUM_ROOT = `${__dirname}/..`;
CoreRelayer__factory,
IWormhole__factory,
MockRelayerIntegration__factory,
} from "../../sdk/src"
import {
init,
loadChains,
loadCoreRelayers,
loadMockIntegrations,
} from "../ts-scripts/helpers/env"
import { MockRelayerIntegration } from "../../sdk/src"
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", () => {
// signers
const sourceChain = chains.find((c)=>(c.chainId == 2)) as ChainInfo;
const targetChain = chains.find((c)=>(c.chainId == 4)) as ChainInfo;
const sourceChain = chains.find((c) => c.chainId == 2) as ChainInfo
const targetChain = chains.find((c) => c.chainId == 4) as ChainInfo
const providerSource = new ethers.providers.StaticJsonRpcProvider(sourceChain.rpc);
const providerTarget = new ethers.providers.StaticJsonRpcProvider(targetChain.rpc);
const providerSource = new ethers.providers.StaticJsonRpcProvider(sourceChain.rpc)
const providerTarget = new ethers.providers.StaticJsonRpcProvider(targetChain.rpc)
const walletSource = new ethers.Wallet(RELAYER_DEPLOYER_PRIVATE_KEY, providerSource);
const walletTarget = new ethers.Wallet(RELAYER_DEPLOYER_PRIVATE_KEY, providerTarget);
const walletSource = new ethers.Wallet(RELAYER_DEPLOYER_PRIVATE_KEY, providerSource)
const walletTarget = new ethers.Wallet(RELAYER_DEPLOYER_PRIVATE_KEY, providerTarget)
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 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, walletSource);
const sourceMockIntegration = MockRelayerIntegration__factory.connect(sourceMockIntegrationAddress, walletSource);
const targetCoreRelayer = CoreRelayer__factory.connect(targetCoreRelayerAddress, walletTarget);
const targetMockIntegration = MockRelayerIntegration__factory.connect(targetMockIntegrationAddress, walletTarget);
const sourceCoreRelayer = CoreRelayer__factory.connect(
sourceCoreRelayerAddress,
walletSource
)
const sourceMockIntegration = MockRelayerIntegration__factory.connect(
sourceMockIntegrationAddress,
walletSource
)
const targetCoreRelayer = CoreRelayer__factory.connect(
targetCoreRelayerAddress,
walletTarget
)
const targetMockIntegration = MockRelayerIntegration__factory.connect(
targetMockIntegrationAddress,
walletTarget
)
it("Executes a delivery", async () => {
const arbitraryPayload = ethers.utils.hexlify(
ethers.utils.toUtf8Bytes(generateRandomString(32))
)
console.log(`Sent message: ${arbitraryPayload}`)
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,
{ value, gasLimit: 500000 }
)
console.log("Sent delivery request!")
const rx = await tx.wait()
console.log("Message confirmed!")
const arbitraryPayload = ethers.utils.hexlify(ethers.utils.toUtf8Bytes(generateRandomString(32)))
console.log(`Sent message: ${arbitraryPayload}`);
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!");
await new Promise((resolve) => {
setTimeout(() => {
resolve(0)
}, 1000)
})
await new Promise((resolve) => {
setTimeout(() => {
resolve(0);
}, 5000)
})
console.log("Checking if message was relayed")
const message = await targetMockIntegration.getMessage()
console.log(`Sent message: ${arbitraryPayload}`)
console.log(`Received message: ${message}`)
expect(message).to.equal(arbitraryPayload)
})
console.log("Checking if message was relayed")
const message = await targetMockIntegration.getMessage();
console.log(`Sent message: ${arbitraryPayload}`);
console.log(`Received message: ${message}`)
expect(message).to.equal(arbitraryPayload);
});
});
it("Executes a forward", async () => {
const arbitraryPayload1 = ethers.utils.hexlify(
ethers.utils.toUtf8Bytes(generateRandomString(32))
)
const arbitraryPayload2 = ethers.utils.hexlify(
ethers.utils.toUtf8Bytes(generateRandomString(32))
)
console.log(`Sent message: ${arbitraryPayload1}`)
const value = await sourceCoreRelayer.quoteGasDeliveryFee(
targetChain.chainId,
500000,
await sourceCoreRelayer.getDefaultRelayProvider()
)
const extraForwardingValue = await targetCoreRelayer.quoteGasDeliveryFee(
sourceChain.chainId,
500000,
await targetCoreRelayer.getDefaultRelayProvider()
)
console.log(`Quoted gas delivery fee: ${value.add(extraForwardingValue)}`)
const furtherInstructions: MockRelayerIntegration.FurtherInstructionsStruct = {
keepSending: true,
newMessages: [arbitraryPayload2, "0x00"],
chains: [sourceChain.chainId],
gasLimits: [500000],
}
const tx = await sourceMockIntegration.sendMessagesWithFurtherInstructions(
[arbitraryPayload1],
furtherInstructions,
targetChain.chainId,
targetMockIntegrationAddress,
targetMockIntegrationAddress,
0,
1,
{ value: value.add(extraForwardingValue), gasLimit: 500000 }
)
console.log("Sent delivery request!")
const rx = await tx.wait()
console.log("Message confirmed!")
await new Promise((resolve) => {
setTimeout(() => {
resolve(0)
}, 2000)
})
console.log("Checking if message was relayed")
const message1 = await targetMockIntegration.getMessage()
console.log(
`Sent message: ${arbitraryPayload1} (expecting ${arbitraryPayload2} from forward)`
)
console.log(`Received message on target: ${message1}`)
expect(message1).to.equal(arbitraryPayload1)
console.log("Checking if forward message was relayed back")
const message2 = await sourceMockIntegration.getMessage()
console.log(`Sent message: ${arbitraryPayload2}`)
console.log(`Received message on source: ${message2}`)
expect(message2).to.equal(arbitraryPayload2)
})
})