Skip to content

Commit 2056253

Browse files
committed
added more a test coverage updates based on storage flows
1 parent 2eb1f86 commit 2056253

4 files changed

Lines changed: 57 additions & 36 deletions

File tree

src/core/token/token.test.ts

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -466,51 +466,60 @@ describe('ERC20Token — check', () => {
466466
describe('ERC20Token — write', () => {
467467
const usdc = createERC20Token(publicClient, USDC_ADDRESS);
468468

469-
it('write(transfer) returns a ComposableCall object', () => {
470-
const call = usdc.write({ functionName: 'transfer', args: [UNISWAP_V3_ROUTER, 1_000_000n] });
469+
it('write(transfer) returns a ComposableCall object', async () => {
470+
const call = await usdc.write({
471+
functionName: 'transfer',
472+
args: [UNISWAP_V3_ROUTER, 1_000_000n],
473+
});
471474
expect(typeof call).toBe('object');
472475
});
473476

474-
it('write(transfer) has a functionSig', () => {
475-
const call = usdc.write({ functionName: 'transfer', args: [UNISWAP_V3_ROUTER, 1_000_000n] });
477+
it('write(transfer) has a functionSig', async () => {
478+
const call = await usdc.write({
479+
functionName: 'transfer',
480+
args: [UNISWAP_V3_ROUTER, 1_000_000n],
481+
});
476482
expect(typeof call.functionSig).toBe('string');
477483
expect(call.functionSig.length).toBeGreaterThan(0);
478484
});
479485

480-
it('write(approve) has a functionSig', () => {
481-
const call = usdc.write({ functionName: 'approve', args: [UNISWAP_V3_ROUTER, 1_000_000n] });
486+
it('write(approve) has a functionSig', async () => {
487+
const call = await usdc.write({
488+
functionName: 'approve',
489+
args: [UNISWAP_V3_ROUTER, 1_000_000n],
490+
});
482491
expect(typeof call.functionSig).toBe('string');
483492
expect(call.functionSig.length).toBeGreaterThan(0);
484493
});
485494

486-
it('write(transfer) and write(approve) produce different functionSigs', () => {
487-
const transfer = usdc.write({
488-
functionName: 'transfer',
489-
args: [UNISWAP_V3_ROUTER, 1_000_000n],
490-
});
491-
const approve = usdc.write({
492-
functionName: 'approve',
493-
args: [UNISWAP_V3_ROUTER, 1_000_000n],
494-
});
495+
it('write(transfer) and write(approve) produce different functionSigs', async () => {
496+
const [transfer, approve] = await Promise.all([
497+
usdc.write({ functionName: 'transfer', args: [UNISWAP_V3_ROUTER, 1_000_000n] }),
498+
usdc.write({ functionName: 'approve', args: [UNISWAP_V3_ROUTER, 1_000_000n] }),
499+
]);
495500
expect(transfer.functionSig).not.toBe(approve.functionSig);
496501
});
497502

498-
it('write(transfer) accepts a runtimeBalance() as the amount arg', () => {
503+
it('write(transfer) accepts a runtimeBalance() as the amount arg', async () => {
499504
const rv = usdc.runtimeBalance({ owner: UNISWAP_V3_ROUTER });
500-
const call = usdc.write({ functionName: 'transfer', args: [WETH_ADDRESS, rv] });
505+
const call = await usdc.write({ functionName: 'transfer', args: [WETH_ADDRESS, rv] });
501506
expect(typeof call).toBe('object');
502507
expect(call.functionSig).toBeDefined();
503508
});
504509

505-
it('write(transfer) produces different inputParams for different amounts', () => {
506-
const a = usdc.write({ functionName: 'transfer', args: [UNISWAP_V3_ROUTER, 1n] });
507-
const b = usdc.write({ functionName: 'transfer', args: [UNISWAP_V3_ROUTER, 2n] });
510+
it('write(transfer) produces different inputParams for different amounts', async () => {
511+
const [a, b] = await Promise.all([
512+
usdc.write({ functionName: 'transfer', args: [UNISWAP_V3_ROUTER, 1n] }),
513+
usdc.write({ functionName: 'transfer', args: [UNISWAP_V3_ROUTER, 2n] }),
514+
]);
508515
expect(JSON.stringify(a.inputParams)).not.toBe(JSON.stringify(b.inputParams));
509516
});
510517

511-
it('write(transfer) produces different inputParams for different recipients', () => {
512-
const a = usdc.write({ functionName: 'transfer', args: [UNISWAP_V3_ROUTER, 1n] });
513-
const b = usdc.write({ functionName: 'transfer', args: [WETH_ADDRESS, 1n] });
518+
it('write(transfer) produces different inputParams for different recipients', async () => {
519+
const [a, b] = await Promise.all([
520+
usdc.write({ functionName: 'transfer', args: [UNISWAP_V3_ROUTER, 1n] }),
521+
usdc.write({ functionName: 'transfer', args: [WETH_ADDRESS, 1n] }),
522+
]);
514523
expect(JSON.stringify(a.inputParams)).not.toBe(JSON.stringify(b.inputParams));
515524
});
516525
});

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ describe('Integration — Biconomy abstractjs composable execution', () => {
3636
constraints: [{ gte: FUND_AMOUNT }],
3737
}),
3838
// Sweep: transfer the SCA's full runtime balance to the EOA
39-
usdc.write({ functionName: 'transfer', args: [_account.address, usdc.runtimeBalance()] }),
39+
await usdc.write({
40+
functionName: 'transfer',
41+
args: [_account.address, usdc.runtimeBalance()],
42+
}),
4043
// Post-condition: assert SCA balance is zero (or near zero) after sweep
4144
usdc.check({ functionName: 'balanceOf', args: [scaAddress], constraints: [{ gte: 0n }] }),
4245
]);
@@ -79,7 +82,10 @@ describe('Integration — Biconomy abstractjs composable execution', () => {
7982
constraints: [{ gte: 2n * FUND_AMOUNT }],
8083
}),
8184
// Sweep: would transfer runtime balance to EOA (never reached due to revert)
82-
usdc.write({ functionName: 'transfer', args: [_account.address, usdc.runtimeBalance()] }),
85+
await usdc.write({
86+
functionName: 'transfer',
87+
args: [_account.address, usdc.runtimeBalance()],
88+
}),
8389
]);
8490

8591
expect(batch.length).toBe(2);
@@ -106,7 +112,10 @@ describe('Integration — Biconomy abstractjs composable execution', () => {
106112

107113
batch.add([
108114
// Sweep: transfer runtime balance from SCA to EOA
109-
usdc.write({ functionName: 'transfer', args: [_account.address, usdc.runtimeBalance()] }),
115+
await usdc.write({
116+
functionName: 'transfer',
117+
args: [_account.address, usdc.runtimeBalance()],
118+
}),
110119
// Post-condition: require FUND_AMOUNT remaining after full sweep — will revert because balance is zero
111120
usdc.check({
112121
functionName: 'balanceOf',
@@ -151,12 +160,15 @@ describe('Integration — Biconomy abstractjs composable execution', () => {
151160
// Step B: assert the stored value equals what was just written before proceeding
152161
await storage.check({ storageKey, constraints: [{ eq: storageValue }] }),
153162
// Step C: transfer the runtime-resolved storage value (FUND_AMOUNT/2) from SCA to EOA
154-
usdc.write({
163+
await usdc.write({
155164
functionName: 'transfer',
156165
args: [_account.address, await storage.runtimeValue({ storageKey })],
157166
}),
158167
// Step D: sweep any remaining SCA balance (the other half) to the EOA
159-
usdc.write({ functionName: 'transfer', args: [_account.address, usdc.runtimeBalance()] }),
168+
await usdc.write({
169+
functionName: 'transfer',
170+
args: [_account.address, usdc.runtimeBalance()],
171+
}),
160172
]);
161173

162174
expect(batch.length).toBe(4);

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { fundWithUsdc, USDC, usdcBalanceOf } from './helpers';
1010
if (!account) throw new Error('PRIVATE_KEY is not set in environment');
1111

1212
const RUNTIME_TRANSFER_CONTRACT = getAddress('0x7c3b315E1d72CFdB8999A68a12e87fc3cc490fec');
13-
const DUMMY_CONTRACT = getAddress('0xEfDE41e2f93F2F0b231a010ddC35c9B8125f17bA');
13+
const _DUMMY_CONTRACT = getAddress('0xEfDE41e2f93F2F0b231a010ddC35c9B8125f17bA');
1414

1515
const TRANSFER_AMOUNT = parseUnits('1', 6); // 1 mock USDC funded into the runtime transfer contract per test
1616
const SCA_MIN_BALANCE = parseUnits('0.5', 6); // top up SCA if it drops below this
@@ -83,7 +83,7 @@ describe('Integration — composable execution via runtime transfer contract (Ba
8383
constraints: [{ gte: TRANSFER_AMOUNT }],
8484
}),
8585
// Transfer: move the runtime transfer contract's full balance to the SCA
86-
runtimeTransfer.write({
86+
await runtimeTransfer.write({
8787
functionName: 'transferFunds',
8888
args: [
8989
USDC,
@@ -136,7 +136,7 @@ describe('Integration — composable execution via runtime transfer contract (Ba
136136
args: [RUNTIME_TRANSFER_CONTRACT],
137137
constraints: [{ gte: TRANSFER_AMOUNT }],
138138
}),
139-
runtimeTransfer.write({
139+
await runtimeTransfer.write({
140140
functionName: 'transferFundsWithStruct',
141141
args: [
142142
USDC,
@@ -188,7 +188,7 @@ describe('Integration — composable execution via runtime transfer contract (Ba
188188
args: [RUNTIME_TRANSFER_CONTRACT],
189189
constraints: [{ gte: TRANSFER_AMOUNT }],
190190
}),
191-
runtimeTransfer.write({
191+
await runtimeTransfer.write({
192192
functionName: 'transferFundsWithDynamicArray',
193193
args: [
194194
USDC,
@@ -238,7 +238,7 @@ describe('Integration — composable execution via runtime transfer contract (Ba
238238
args: [RUNTIME_TRANSFER_CONTRACT],
239239
constraints: [{ gte: TRANSFER_AMOUNT }],
240240
}),
241-
runtimeTransfer.write({
241+
await runtimeTransfer.write({
242242
functionName: 'transferFundsWithString',
243243
args: [
244244
USDC,
@@ -288,7 +288,7 @@ describe('Integration — composable execution via runtime transfer contract (Ba
288288
args: [RUNTIME_TRANSFER_CONTRACT],
289289
constraints: [{ gte: TRANSFER_AMOUNT }],
290290
}),
291-
runtimeTransfer.write({
291+
await runtimeTransfer.write({
292292
functionName: 'transferFundsWithBytes',
293293
args: [
294294
USDC,
@@ -338,7 +338,7 @@ describe('Integration — composable execution via runtime transfer contract (Ba
338338
args: [RUNTIME_TRANSFER_CONTRACT],
339339
constraints: [{ gte: TRANSFER_AMOUNT }],
340340
}),
341-
runtimeTransfer.write({
341+
await runtimeTransfer.write({
342342
functionName: 'transferFundsWithRuntimeParamInsideArray',
343343
args: [
344344
USDC,

src/test/integration/zerodev-composable.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ describe.skip('Integration — ZeroDev Kernel + Biconomy composability module (B
191191
constraints: [{ gte: FUND_AMOUNT }],
192192
}),
193193
// Sweep: transfer the SCA's full runtime USDC balance to the EOA
194-
usdc.write({
194+
await usdc.write({
195195
functionName: 'transfer',
196196
args: [_account.address, usdc.runtimeBalance()],
197197
}),

0 commit comments

Comments
 (0)