Skip to content

Commit 7033ffd

Browse files
committed
chore: update test assertions
1 parent db0fe9b commit 7033ffd

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

packages/apps/abilities-e2e/test-e2e/swap.spec.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,24 @@ import {
4646
const ALCHEMY_GAS_SPONSOR_API_KEY = getEnv('ALCHEMY_GAS_SPONSOR_API_KEY');
4747
const ALCHEMY_GAS_SPONSOR_POLICY_ID = getEnv('ALCHEMY_GAS_SPONSOR_POLICY_ID');
4848

49-
const SWAP_AMOUNT = 80;
50-
const SWAP_TOKEN_IN_ADDRESS = '0x4ed4E862860beD51a9570b96d89aF5E1B0Efefed'; // DEGEN
51-
const SWAP_TOKEN_IN_DECIMALS = 18;
49+
// const SWAP_AMOUNT = 80;
50+
// const SWAP_TOKEN_IN_ADDRESS = '0x4ed4E862860beD51a9570b96d89aF5E1B0Efefed'; // DEGEN
51+
// const SWAP_TOKEN_IN_DECIMALS = 18;
5252

5353
// const SWAP_AMOUNT = 0.0003;
5454
// const SWAP_TOKEN_IN_ADDRESS = '0x4200000000000000000000000000000000000006'; // WETH
5555
// const SWAP_TOKEN_IN_DECIMALS = 18;
5656

57-
// const SWAP_AMOUNT = 0.1;
58-
// const SWAP_TOKEN_IN_ADDRESS = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'; // USDC
59-
// const SWAP_TOKEN_IN_DECIMALS = 6;
57+
const SWAP_AMOUNT = 0.1;
58+
const SWAP_TOKEN_IN_ADDRESS = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'; // USDC
59+
const SWAP_TOKEN_IN_DECIMALS = 6;
6060

61-
const SWAP_TOKEN_OUT_ADDRESS = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'; // USDC
62-
const SWAP_TOKEN_OUT_DECIMALS = 6;
61+
// const SWAP_TOKEN_OUT_ADDRESS = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'; // USDC
62+
// const SWAP_TOKEN_OUT_DECIMALS = 6;
6363
// const SWAP_TOKEN_OUT_ADDRESS = '0x4200000000000000000000000000000000000006'; // WETH
6464
// const SWAP_TOKEN_OUT_DECIMALS = 18;
65-
// const SWAP_TOKEN_OUT_ADDRESS = '0x4ed4E862860beD51a9570b96d89aF5E1B0Efefed'; // DEGEN
66-
// const SWAP_TOKEN_OUT_DECIMALS = 18;
65+
const SWAP_TOKEN_OUT_ADDRESS = '0x4ed4E862860beD51a9570b96d89aF5E1B0Efefed'; // DEGEN
66+
const SWAP_TOKEN_OUT_DECIMALS = 18;
6767

6868
const RPC_URL = BASE_RPC_URL;
6969
const CHAIN_ID = 8453;
@@ -478,6 +478,7 @@ describe('Uniswap Swap Ability E2E Tests', () => {
478478

479479
const precheckResult = await uniswapSwapAbilityClient.precheck(
480480
{
481+
action: AbilityAction.Swap,
481482
rpcUrlForUniswap: RPC_URL,
482483
signedUniswapQuote: {
483484
quote: signedUniswapQuote.quote,
@@ -514,9 +515,11 @@ describe('Uniswap Swap Ability E2E Tests', () => {
514515

515516
// Verify the result is properly populated
516517
expect(precheckResult.result).toBeDefined();
517-
expect(BigInt(precheckResult.result!.nativeTokenBalance)).toBeGreaterThan(0n);
518+
expect(precheckResult.result!.nativeTokenBalance).toBeDefined();
519+
expect(BigInt(precheckResult.result!.nativeTokenBalance as string)).toBeGreaterThan(0n);
518520
expect(precheckResult.result!.tokenInAddress).toBe(SWAP_TOKEN_IN_ADDRESS);
519-
expect(BigInt(precheckResult.result!.tokenInBalance)).toBeGreaterThan(0n);
521+
expect(precheckResult.result!.tokenInBalance).toBeDefined();
522+
expect(BigInt(precheckResult.result!.tokenInBalance as string)).toBeGreaterThan(0n);
520523
expect(BigInt(precheckResult.result!.currentTokenInAllowanceForSpender)).toBeGreaterThan(0n);
521524
expect(precheckResult.result!.spenderAddress).toBe(signedUniswapQuote.quote.to);
522525
});
@@ -713,6 +716,7 @@ describe('Uniswap Swap Ability E2E Tests', () => {
713716

714717
const precheckResult = await uniswapSwapAbilityClient.precheck(
715718
{
719+
action: AbilityAction.Swap,
716720
rpcUrlForUniswap: RPC_URL,
717721
signedUniswapQuote: {
718722
quote: signedUniswapQuote.quote,
@@ -751,9 +755,10 @@ describe('Uniswap Swap Ability E2E Tests', () => {
751755

752756
// Verify the result is properly populated
753757
expect(precheckResult.result).toBeDefined();
754-
expect(BigInt(precheckResult.result!.nativeTokenBalance)).toBeGreaterThan(0n);
758+
expect(precheckResult.result!.nativeTokenBalance).not.toBeDefined();
755759
expect(precheckResult.result!.tokenInAddress).toBe(SWAP_TOKEN_IN_ADDRESS);
756-
expect(BigInt(precheckResult.result!.tokenInBalance)).toBeGreaterThan(0n);
760+
expect(precheckResult.result!.tokenInBalance).toBeDefined();
761+
expect(BigInt(precheckResult.result!.tokenInBalance as string)).toBeGreaterThan(0n);
757762
expect(BigInt(precheckResult.result!.currentTokenInAllowanceForSpender)).toBeGreaterThan(0n);
758763
expect(precheckResult.result!.spenderAddress).toBe(signedUniswapQuote.quote.to);
759764
});

packages/apps/ability-uniswap-swap/src/lib/vincent-ability.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export const vincentAbility = createVincentAbility({
102102
// the current allowance is sufficient without having to call execute.
103103
if (action === AbilityAction.Approve) {
104104
return succeed({
105+
nativeTokenBalance: checkNativeTokenBalanceResultSuccess?.ethBalance.toString(),
105106
currentTokenInAllowanceForSpender: checkErc20AllowanceResult.currentAllowance.toString(),
106107
spenderAddress: checkErc20AllowanceResult.spenderAddress,
107108
});
@@ -119,8 +120,9 @@ export const vincentAbility = createVincentAbility({
119120
});
120121
}
121122

122-
// 5. At this point, the ability action is either swap and the current allowance is sufficient, or
123-
// approveAndSwap and the gas for the approval transaction can be paid for if the current allowance is insufficient.
123+
// 5. At this point, the ability action is either:
124+
// - Swap and the current allowance is sufficient
125+
// - ApproveAndSwap and the gas for the approval transaction can be paid for if the current allowance is insufficient.
124126
// We now need to check if the current delegator balance of tokenIn is sufficient to perform the swap.
125127
const checkErc20BalanceResult = await checkErc20Balance({
126128
provider,
@@ -188,9 +190,10 @@ export const vincentAbility = createVincentAbility({
188190
}
189191

190192
// 1. If the ability action is approve or approveAndSwap, we need to check if the current allowance is sufficient.
191-
// If the ability action is approve, we return success if sufficient, otherwise we send a new approval transaction.
192-
// If the ability action is approveAndSwap, and the current allowance is sufficient, we continue to create the swap transaction.
193-
// Otherwise, we send a new approval transaction and then continue to create the swap transaction.
193+
// If the ability action is:
194+
// - Approve, we return success if allowance is sufficient, otherwise we send a new approval transaction
195+
// - ApproveAndSwap, and the current allowance is sufficient, we continue to create the swap transaction. Otherwise,
196+
// we send a new approval transaction and then continue to create the swap transaction
194197
let approvalTxHash: string | undefined;
195198
let approvalTxUserOperationHash: string | undefined;
196199
if (action === AbilityAction.Approve || action === AbilityAction.ApproveAndSwap) {

0 commit comments

Comments
 (0)