Skip to content

Commit 659254f

Browse files
committed
test: update fill tests
Signed-off-by: Pablo Maldonado <[email protected]>
1 parent 6bad227 commit 659254f

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

Diff for: test/svm/SvmSpoke.Fill.AcrossPlus.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@ import {
3434
import { MulticallHandler } from "../../target/types/multicall_handler";
3535
import { common } from "./SvmSpoke.common";
3636
import { FillDataParams, FillDataValues } from "../../src/types/svm";
37-
const { provider, connection, program, owner, chainId, seedBalance } = common;
38-
const { initializeState, assertSE } = common;
37+
const { provider, connection, program, owner, chainId, seedBalance, initializeState, assertSE } = common;
3938

4039
describe("svm_spoke.fill.across_plus", () => {
4140
anchor.setProvider(provider);
42-
const payer = (anchor.AnchorProvider.env().wallet as anchor.Wallet).payer;
41+
const { payer } = anchor.AnchorProvider.env().wallet as anchor.Wallet;
4342
const relayer = Keypair.generate();
4443

4544
const handlerProgram = anchor.workspace.MulticallHandler as Program<MulticallHandler>;
@@ -58,7 +57,7 @@ describe("svm_spoke.fill.across_plus", () => {
5857
let relayData: any; // reused relay data for all tests.
5958
let accounts: any; // Store accounts to simplify contract interactions.
6059

61-
function updateRelayData(newRelayData: any) {
60+
const updateRelayData = (newRelayData: any) => {
6261
relayData = newRelayData;
6362
const relayHashUint8Array = calculateRelayHashUint8Array(relayData, chainId);
6463
const [fillStatusPDA] = PublicKey.findProgramAddressSync(
@@ -68,7 +67,7 @@ describe("svm_spoke.fill.across_plus", () => {
6867

6968
accounts = {
7069
state,
71-
delegate: getFillRelayDelegatePda(relayHashUint8Array, seed, program.programId),
70+
delegate: getFillRelayDelegatePda(relayHashUint8Array, new BN(1), relayer.publicKey, program.programId).pda,
7271
signer: relayer.publicKey,
7372
instructionParams: program.programId,
7473
mint: mint,
@@ -79,17 +78,17 @@ describe("svm_spoke.fill.across_plus", () => {
7978
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
8079
systemProgram: anchor.web3.SystemProgram.programId,
8180
};
82-
}
81+
};
8382

84-
async function createApproveAndFillIx(multicallHandlerCoder: MulticallHandlerCoder, bufferParams = false) {
83+
const createApproveAndFillIx = async (multicallHandlerCoder: MulticallHandlerCoder, bufferParams = false) => {
8584
const relayHashUint8Array = calculateRelayHashUint8Array(relayData, chainId);
8685
const relayHash = Array.from(relayHashUint8Array);
8786

8887
// Delegate state PDA to pull relayer tokens.
8988
const approveIx = await createApproveCheckedInstruction(
9089
accounts.relayerTokenAccount,
9190
accounts.mint,
92-
getFillRelayDelegatePda(relayHashUint8Array, seed, program.programId),
91+
getFillRelayDelegatePda(relayHashUint8Array, new BN(1), relayer.publicKey, program.programId).pda,
9392
accounts.signer,
9493
BigInt(relayAmount),
9594
mintDecimals
@@ -119,7 +118,7 @@ describe("svm_spoke.fill.across_plus", () => {
119118
.instruction();
120119

121120
return { approveIx, fillIx };
122-
}
121+
};
123122

124123
before("Creates token mint and associated token accounts", async () => {
125124
mint = await createMint(connection, payer, owner, owner, mintDecimals);

Diff for: test/svm/SvmSpoke.SlowFill.ts

+25-9
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,23 @@ import {
2323
} from "../../src/svm/web3-v1";
2424
import { testAcrossPlusMessage } from "./utils";
2525

26-
const { provider, connection, program, owner, chainId, seedBalance, initializeState } = common;
27-
const { recipient, setCurrentTime, assertSE, assert } = common;
26+
const {
27+
provider,
28+
connection,
29+
program,
30+
owner,
31+
chainId,
32+
seedBalance,
33+
initializeState,
34+
recipient,
35+
setCurrentTime,
36+
assertSE,
37+
assert,
38+
} = common;
2839

2940
describe("svm_spoke.slow_fill", () => {
3041
anchor.setProvider(provider);
31-
const payer = (anchor.AnchorProvider.env().wallet as anchor.Wallet).payer;
42+
const { payer } = anchor.AnchorProvider.env().wallet as anchor.Wallet;
3243
const relayer = Keypair.generate();
3344
const otherRelayer = Keypair.generate();
3445
const { encodedMessage, fillRemainingAccounts } = testAcrossPlusMessage();
@@ -50,7 +61,7 @@ describe("svm_spoke.slow_fill", () => {
5061

5162
const initialMintAmount = 10_000_000_000;
5263

53-
async function updateRelayData(newRelayData: SlowFillLeaf["relayData"]) {
64+
const updateRelayData = async (newRelayData: SlowFillLeaf["relayData"]) => {
5465
relayData = newRelayData;
5566
const relayHashUint8Array = calculateRelayHashUint8Array(relayData, chainId);
5667
[fillStatus] = PublicKey.findProgramAddressSync([Buffer.from("fills"), relayHashUint8Array], program.programId);
@@ -69,6 +80,7 @@ describe("svm_spoke.slow_fill", () => {
6980
};
7081
fillAccounts = {
7182
state,
83+
delegate: getFillRelayDelegatePda(relayHashUint8Array, new BN(1), relayer.publicKey, program.programId).pda,
7284
signer: relayer.publicKey,
7385
instructionParams: program.programId,
7486
mint: mint,
@@ -79,7 +91,7 @@ describe("svm_spoke.slow_fill", () => {
7991
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
8092
systemProgram: anchor.web3.SystemProgram.programId,
8193
};
82-
}
94+
};
8395

8496
const relaySlowFillRootBundle = async (
8597
slowRelayLeafRecipient = recipient,
@@ -118,7 +130,7 @@ describe("svm_spoke.slow_fill", () => {
118130
const leaf = slowRelayLeafs[0];
119131

120132
let stateAccountData = await program.account.state.fetch(state);
121-
const rootBundleId = stateAccountData.rootBundleId;
133+
const { rootBundleId } = stateAccountData;
122134

123135
const rootBundleIdBuffer = Buffer.alloc(4);
124136
rootBundleIdBuffer.writeUInt32LE(rootBundleId);
@@ -213,7 +225,9 @@ describe("svm_spoke.slow_fill", () => {
213225
Object.entries(relayData).forEach(([key, value]) => {
214226
if (key === "message") {
215227
assertSE(event.messageHash, hashNonEmptyMessage(value as Buffer), `MessageHash should match`);
216-
} else assertSE(event[key], value, `${key.charAt(0).toUpperCase() + key.slice(1)} should match`);
228+
} else {
229+
assertSE(event[key], value, `${key.charAt(0).toUpperCase() + key.slice(1)} should match`);
230+
}
217231
});
218232
});
219233

@@ -225,7 +239,7 @@ describe("svm_spoke.slow_fill", () => {
225239
const approveIx = await createApproveCheckedInstruction(
226240
fillAccounts.relayerTokenAccount,
227241
fillAccounts.mint,
228-
getFillRelayDelegatePda(relayHashUint8Array, seed, program.programId),
242+
getFillRelayDelegatePda(relayHashUint8Array, new BN(1), relayer.publicKey, program.programId).pda,
229243
fillAccounts.signer,
230244
BigInt(relayData.outputAmount.toString()),
231245
tokenDecimals
@@ -386,7 +400,9 @@ describe("svm_spoke.slow_fill", () => {
386400
Object.entries(relayData).forEach(([key, value]) => {
387401
if (key === "message") {
388402
assertSE(event.messageHash, hashNonEmptyMessage(value as Buffer), `MessageHash should match`);
389-
} else assertSE(event[key], value, `${key.charAt(0).toUpperCase() + key.slice(1)} should match`);
403+
} else {
404+
assertSE(event[key], value, `${key.charAt(0).toUpperCase() + key.slice(1)} should match`);
405+
}
390406
});
391407
// RelayExecutionInfo should match.
392408
assertSE(event.relayExecutionInfo.updatedRecipient, relayData.recipient, "UpdatedRecipient should match");

0 commit comments

Comments
 (0)