Skip to content

Commit

Permalink
ci: batch accountant VAAs
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-gray committed Dec 4, 2024
1 parent edbb89e commit a80ba8a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
6 changes: 3 additions & 3 deletions sdk/__tests__/accountant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const url = process.env["CI"]
? "http://wormchain:26657"
: "http://localhost:26659";

export async function submitAccountantVAA(vaa: Uint8Array) {
export async function submitAccountantVAAs(vaas: Uint8Array[]) {
if (!signer) {
// NttAccountantTest = wormhole18s5lynnmx37hq4wlrw9gdn68sg2uxp5rwf5k3u
const wallet = await getWallet(privateKey);
Expand All @@ -34,15 +34,15 @@ export async function submitAccountantVAA(vaa: Uint8Array) {
msg: encoding.bytes.encode(
JSON.stringify({
submit_vaas: {
vaas: [encoding.b64.encode(vaa)],
vaas: vaas.map((vaa) => encoding.b64.encode(vaa)),
},
})
),
funds: [],
});
const result = await client.signAndBroadcast(signer, [msg], {
...ZERO_FEE,
gas: "10000000",
gas: (BigInt("10000000") * BigInt(vaas.length)).toString(),
});
if (result.code !== 0) {
throw new Error(`Bad result: ${result.rawLog}`);
Expand Down
33 changes: 15 additions & 18 deletions sdk/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Chain } from "@wormhole-foundation/sdk-base";
import { deploy, link, transferWithChecks, wh } from "./utils.js";
import { submitAccountantVAA } from "./accountant.js";
import { submitAccountantVAAs } from "./accountant.js";

// Note: Currently, in order for this to run, the evm bindings with extra contracts must be build
// To do that, at the root, run `npm run generate:test`
Expand All @@ -13,23 +13,20 @@ const cases = [

async function registerRelayers() {
try {
await submitAccountantVAA(
Buffer.from(
"01000000000100a4f34c530ff196c060ff349f2bf7bcb16865771a7165ca84fb5e263f148a01b03592b9af46a410a3760f39097d7380e4e72b6e1da4fa25c2d7b2d00f102d0cae0100000000000000000001000000000000000000000000000000000000000000000000000000000000000400000000001ce9cf010000000000000000000000000000000000576f726d686f6c6552656c617965720100000002000000000000000000000000cc680d088586c09c3e0e099a676fa4b6e42467b4",
"hex"
)
);
} catch (e) {
console.log(e);
}

try {
await submitAccountantVAA(
Buffer.from(
"010000000001000fd839cfdbea0f43a35dbb8cc0219b55cd5ec9f59b7e4a7183dbeebd522f7c673c866a218bfa108d8c7606acb5fc6b94a7a4c3be06f10836c242afecdb80da6e00000000000000000000010000000000000000000000000000000000000000000000000000000000000004000000000445fb0b010000000000000000000000000000000000576f726d686f6c6552656c617965720100000004000000000000000000000000cc680d088586c09c3e0e099a676fa4b6e42467b4",
"hex"
)
);
await submitAccountantVAAs([
new Uint8Array(
Buffer.from(
"01000000000100a4f34c530ff196c060ff349f2bf7bcb16865771a7165ca84fb5e263f148a01b03592b9af46a410a3760f39097d7380e4e72b6e1da4fa25c2d7b2d00f102d0cae0100000000000000000001000000000000000000000000000000000000000000000000000000000000000400000000001ce9cf010000000000000000000000000000000000576f726d686f6c6552656c617965720100000002000000000000000000000000cc680d088586c09c3e0e099a676fa4b6e42467b4",
"hex"
)
),
new Uint8Array(
Buffer.from(
"010000000001000fd839cfdbea0f43a35dbb8cc0219b55cd5ec9f59b7e4a7183dbeebd522f7c673c866a218bfa108d8c7606acb5fc6b94a7a4c3be06f10836c242afecdb80da6e00000000000000000000010000000000000000000000000000000000000000000000000000000000000004000000000445fb0b010000000000000000000000000000000000576f726d686f6c6552656c617965720100000004000000000000000000000000cc680d088586c09c3e0e099a676fa4b6e42467b4",
"hex"
)
),
]);
} catch (e) {
console.log(e);
}
Expand Down
27 changes: 15 additions & 12 deletions sdk/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ import { WormholeTransceiver__factory } from "../../evm/ts/ethers-ci-contracts/f

import solanaTiltKey from "./solana-tilt.json"; // from https://github.com/wormhole-foundation/wormhole/blob/main/solana/keys/solana-devnet.json

import { Ntt } from "../definitions/src/index.js";
import "../../evm/ts/src/index.js";
import "../../solana/ts/sdk/index.js";
import { NTT } from "../../solana/ts/lib/index.js";
import { SolanaNtt } from "../../solana/ts/sdk/index.js";
import { submitAccountantVAA } from "./accountant.js";
import { Ntt } from "../definitions/src/index.js";
import { submitAccountantVAAs } from "./accountant.js";

// Note: Currently, in order for this to run, the evm bindings with extra contracts must be build
// To do that, at the root, run `npm run generate:test`
Expand Down Expand Up @@ -134,7 +134,7 @@ export async function link(chainInfos: Ctx[]) {
};

const vaa = await wh.getVaa(msgId, "Ntt:TransceiverInfo");
await submitAccountantVAA(serialize(vaa!));
const vaas: Uint8Array[] = [serialize(vaa!)];

// [target, peer, vaa]
const registrations: [string, string, VAA<"Ntt:TransceiverRegistration">][] =
Expand Down Expand Up @@ -164,47 +164,50 @@ export async function link(chainInfos: Ctx[]) {
}
}

// Submit Hub to Spoke registrations
// Push Hub to Spoke registrations
const hubToSpokeRegistrations = registrations.filter(
([_, peer]) => peer === hubChain
);
for (const [, , vaa] of hubToSpokeRegistrations) {
console.log(
"Submitting hub to spoke registrations: ",
"Pushing hub to spoke registrations: ",
vaa.emitterChain,
vaa.payload.chain,
vaa.payload.transceiver.toString()
);
await submitAccountantVAA(serialize(vaa));
vaas.push(serialize(vaa));
}

// Submit Spoke to Hub registrations
// Push Spoke to Hub registrations
const spokeToHubRegistrations = registrations.filter(
([target, _]) => target === hubChain
);
for (const [, , vaa] of spokeToHubRegistrations) {
console.log(
"Submitting spoke to hub registrations: ",
"Pushing spoke to hub registrations: ",
vaa.emitterChain,
vaa.payload.chain,
vaa.payload.transceiver.toString()
);
await submitAccountantVAA(serialize(vaa));
vaas.push(serialize(vaa));
}

// Submit all other registrations
// Push all other registrations
const spokeToSpokeRegistrations = registrations.filter(
([target, peer]) => target !== hubChain && peer !== hubChain
);
for (const [, , vaa] of spokeToSpokeRegistrations) {
console.log(
"Submitting spoke to spoke registrations: ",
"Pushing spoke to spoke registrations: ",
vaa.emitterChain,
vaa.payload.chain,
vaa.payload.transceiver.toString()
);
await submitAccountantVAA(serialize(vaa));
vaas.push(serialize(vaa));
}

// Submit all registrations at once
await submitAccountantVAAs(vaas);
}

export async function transferWithChecks(sourceCtx: Ctx, destinationCtx: Ctx) {
Expand Down

0 comments on commit a80ba8a

Please sign in to comment.