Skip to content

Commit 78519c7

Browse files
committed
test setup refactor
1 parent dd3a664 commit 78519c7

3 files changed

Lines changed: 26 additions & 15 deletions

File tree

src/test/integration/batch-execution.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('Integration — Biconomy abstractjs composable execution', () => {
6060

6161
// 6. Execute the signed quote and wait for the supertransaction to settle
6262
const { hash } = await meeClient.executeQuote({ quote });
63-
await meeClient.waitForSupertransactionReceipt({ hash, mode: 'fast-block' });
63+
await meeClient.waitForSupertransactionReceipt({ hash });
6464

6565
// 7. Assert SCA balance has been swept to zero (minus fees)
6666
const scaBalanceAfter = await usdc.read({ functionName: 'balanceOf', args: [scaAddress] });
@@ -190,7 +190,7 @@ describe('Integration — Biconomy abstractjs composable execution', () => {
190190

191191
// 5. Execute the signed quote and wait for the supertransaction to settle
192192
const { hash } = await meeClient.executeQuote({ quote });
193-
await meeClient.waitForSupertransactionReceipt({ hash, mode: 'fast-block' });
193+
await meeClient.waitForSupertransactionReceipt({ hash });
194194

195195
// 6. Assert the on-chain storage slot holds the value that was written in step A
196196
expect(await storage.read({ storageKey })).to.eq(toBytes32(storageValue));

src/test/integration/capture-output.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe('Integration — capture output params: execResult and staticCall (Base
8282
});
8383

8484
const { hash } = await meeClient.executeQuote({ quote });
85-
await meeClient.waitForSupertransactionReceipt({ hash, mode: 'fast-block' });
85+
await meeClient.waitForSupertransactionReceipt({ hash });
8686

8787
expect(await storage.read({ storageKey })).to.eq(toBytes32(expectedResult));
8888
});
@@ -131,7 +131,7 @@ describe('Integration — capture output params: execResult and staticCall (Base
131131
});
132132

133133
const { hash } = await meeClient.executeQuote({ quote });
134-
await meeClient.waitForSupertransactionReceipt({ hash, mode: 'fast-block' });
134+
await meeClient.waitForSupertransactionReceipt({ hash });
135135

136136
// Off-chain: verify all three captured slots
137137
expect(await storage.read({ storageKey })).to.eq(toBytes32(expectedSum));
@@ -184,7 +184,7 @@ describe('Integration — capture output params: execResult and staticCall (Base
184184
});
185185

186186
const { hash } = await meeClient.executeQuote({ quote });
187-
await meeClient.waitForSupertransactionReceipt({ hash, mode: 'fast-block' });
187+
await meeClient.waitForSupertransactionReceipt({ hash });
188188

189189
expect(await storage.read({ storageKey })).to.eq(toBytes32(expectedResult));
190190
});
@@ -240,7 +240,7 @@ describe('Integration — capture output params: execResult and staticCall (Base
240240
});
241241

242242
const { hash } = await meeClient.executeQuote({ quote });
243-
await meeClient.waitForSupertransactionReceipt({ hash, mode: 'fast-block' });
243+
await meeClient.waitForSupertransactionReceipt({ hash });
244244

245245
// Off-chain: verify all three captured slots
246246
expect(await storage.read({ storageKey })).to.eq(toBytes32(expectedTriple));

src/test/integration/composable-execution-base.test.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getAddress, parseUnits } from 'viem';
33
import { baseSepolia } from 'viem/chains';
44
import { beforeAll, beforeEach, describe, expect, it } from 'vitest';
55
import { createComposableBatch } from '../../core/batch';
6-
import { account, initNexus, publicClient } from '../utils';
6+
import { account, initNexus, publicClient, walletClient } from '../utils';
77
import { RUNTIME_TRANSFER_ABI } from './abi/runtime-transfer';
88
import { fundWithUsdc, USDC, usdcBalanceOf } from './helpers';
99

@@ -34,10 +34,21 @@ async function ensureScaBalance(): Promise<void> {
3434
}
3535
}
3636

37-
// Tops up the runtime transfer contract to TRANSFER_AMOUNT if it has less than that
37+
// Resets the runtime transfer contract balance to exactly TRANSFER_AMOUNT before each test.
38+
// Drains any excess (from a previously failed test that didn't sweep) back to the EOA,
39+
// then tops up if the balance is below TRANSFER_AMOUNT.
3840
async function ensureRuntimeTransferContractBalance(): Promise<void> {
41+
if (!walletClient) throw new Error('PRIVATE_KEY is not set in environment');
3942
const balance = await usdcBalanceOf(RUNTIME_TRANSFER_CONTRACT);
40-
if (balance < TRANSFER_AMOUNT) {
43+
if (balance > TRANSFER_AMOUNT) {
44+
const hash = await walletClient.writeContract({
45+
abi: RUNTIME_TRANSFER_ABI,
46+
address: RUNTIME_TRANSFER_CONTRACT,
47+
functionName: 'transferFunds',
48+
args: [USDC, walletClient.account.address, balance - TRANSFER_AMOUNT],
49+
});
50+
await publicClient.waitForTransactionReceipt({ hash, confirmations: 2 });
51+
} else if (balance < TRANSFER_AMOUNT) {
4152
await fundWithUsdc(RUNTIME_TRANSFER_CONTRACT, TRANSFER_AMOUNT - balance);
4253
}
4354
}
@@ -108,7 +119,7 @@ describe('Integration — composable execution via runtime transfer contract (Ba
108119
});
109120

110121
const { hash } = await meeClient.executeQuote({ quote });
111-
await meeClient.waitForSupertransactionReceipt({ hash, mode: 'fast-block' });
122+
await meeClient.waitForSupertransactionReceipt({ hash });
112123

113124
// Runtime transfer contract should be swept to zero after the transfer
114125
const contractBalanceAfter = await usdcBalanceOf(RUNTIME_TRANSFER_CONTRACT);
@@ -162,7 +173,7 @@ describe('Integration — composable execution via runtime transfer contract (Ba
162173
});
163174

164175
const { hash } = await meeClient.executeQuote({ quote });
165-
await meeClient.waitForSupertransactionReceipt({ hash, mode: 'fast-block' });
176+
await meeClient.waitForSupertransactionReceipt({ hash });
166177

167178
const contractBalanceAfter = await usdcBalanceOf(RUNTIME_TRANSFER_CONTRACT);
168179
expect(contractBalanceAfter).toEqual(0n);
@@ -212,7 +223,7 @@ describe('Integration — composable execution via runtime transfer contract (Ba
212223
});
213224

214225
const { hash } = await meeClient.executeQuote({ quote });
215-
await meeClient.waitForSupertransactionReceipt({ hash, mode: 'fast-block' });
226+
await meeClient.waitForSupertransactionReceipt({ hash });
216227

217228
const contractBalanceAfter = await usdcBalanceOf(RUNTIME_TRANSFER_CONTRACT);
218229
expect(contractBalanceAfter).toEqual(0n);
@@ -262,7 +273,7 @@ describe('Integration — composable execution via runtime transfer contract (Ba
262273
});
263274

264275
const { hash } = await meeClient.executeQuote({ quote });
265-
await meeClient.waitForSupertransactionReceipt({ hash, mode: 'fast-block' });
276+
await meeClient.waitForSupertransactionReceipt({ hash });
266277

267278
const contractBalanceAfter = await usdcBalanceOf(RUNTIME_TRANSFER_CONTRACT);
268279
expect(contractBalanceAfter).toEqual(0n);
@@ -312,7 +323,7 @@ describe('Integration — composable execution via runtime transfer contract (Ba
312323
});
313324

314325
const { hash } = await meeClient.executeQuote({ quote });
315-
await meeClient.waitForSupertransactionReceipt({ hash, mode: 'fast-block' });
326+
await meeClient.waitForSupertransactionReceipt({ hash });
316327

317328
const contractBalanceAfter = await usdcBalanceOf(RUNTIME_TRANSFER_CONTRACT);
318329
expect(contractBalanceAfter).toEqual(0n);
@@ -361,7 +372,7 @@ describe('Integration — composable execution via runtime transfer contract (Ba
361372
});
362373

363374
const { hash } = await meeClient.executeQuote({ quote });
364-
await meeClient.waitForSupertransactionReceipt({ hash, mode: 'fast-block' });
375+
await meeClient.waitForSupertransactionReceipt({ hash });
365376

366377
const contractBalanceAfter = await usdcBalanceOf(RUNTIME_TRANSFER_CONTRACT);
367378
expect(contractBalanceAfter).toEqual(0n);

0 commit comments

Comments
 (0)