// tests/approve-action.test.ts import { describe, it, expect, beforeEach, vi } from 'vitest'; import { ExecuteOperationAction } from '../actions/execute-operation'; import { PrexClient } from '../prex-client'; import { PrexSigner } from '../core/sign'; import { PrexApiService } from '../api'; import { PrexUser } from '../types'; import { Address, zeroHash } from 'viem'; const TOKEN_ADDRESS = '0x0000000000000000000000000000000000000001' as Address; const USER_ADDRESS = '0x0000000000000000000000000000000000000002' as Address; describe('ExecuteOperationAction', () => { let executeOperationAction: ExecuteOperationAction; let mockClient: PrexClient; let mockSigner: PrexSigner; let mockApiService: PrexApiService; let mockUser: PrexUser; beforeEach(() => { mockClient = { loadConfig: vi.fn().mockResolvedValue({ feeTiers: [], maxFeePerGas: '0.1', maxPriorityFeePerGas: '0.1', }), getNonce: vi.fn(() => 1n), getPermitNonce: vi.fn(), executeOperation: vi.fn(), fetchBalance: vi.fn(), evmChainClient: { estimateGas: vi.fn(() => 1000000n), getCode: vi.fn(), }, logger: { debug: vi.fn(), }, } as unknown as PrexClient; mockSigner = { signTypedData: vi.fn(), signHash: vi.fn(() => '0x00'), } as unknown as PrexSigner; mockApiService = { chainId: 1337, execute: vi.fn(), signPaymasterAndData: vi.fn(() => zeroHash), } as unknown as PrexApiService; mockUser = { id: 'user-id', name: 'Test User', address: USER_ADDRESS, walletId: 'wallet-id', passkeys: [ { publicKey: '0x00', }, ], } as unknown as PrexUser; executeOperationAction = new ExecuteOperationAction( mockClient, mockUser, mockSigner, mockApiService ); }); it('should use permit if user is not using a smart wallet', async () => { mockUser.walletId = ''; vi.mocked(mockSigner.signHash).mockResolvedValue('0x00'); vi.mocked(mockApiService.execute).mockResolvedValue({ gas_used: 1000000, hash: zeroHash, }); await executeOperationAction.executeOperation( TOKEN_ADDRESS as Address, '0x00', {} ); expect(mockSigner.signHash).toHaveBeenCalled(); expect(mockApiService.execute).toHaveBeenCalled(); }); });