11import {
22 createClient ,
3- createNonceManager ,
4- createPublicClient ,
53 createWalletClient ,
64 EIP1193RequestFn ,
75 encodeFunctionData ,
86 http ,
97 keccak256 ,
108 NonceManager ,
11- nonceManager ,
9+ PublicClient ,
1210 parseEther ,
11+ publicActions ,
12+ Transport ,
1313 toBytes ,
1414 toHex ,
1515} from 'viem' ;
@@ -63,6 +63,12 @@ const baseClientRequestSpy = vi.fn(async ({ method, params }) => {
6363 }
6464 if ( method === 'eth_estimateGas' ) {
6565 return MOCK_ETH_ESTIMATE_GAS_LIMIT ;
66+ } else if ( method === 'zks_estimateFee' ) {
67+ throw new Error ( 'zks_estimateFee not supported' ) ;
68+ } else if ( method === 'eth_gasPrice' ) {
69+ return toHex ( MOCK_FEE_PER_GAS ) ;
70+ } else if ( method === 'eth_getBalance' ) {
71+ return toHex ( 1000000000000000000n ) ; // 1 ETH
6672 }
6773 return anvilAbstractTestnet . getClient ( ) . request ( { method, params } as any ) ;
6874} ) ;
@@ -82,23 +88,9 @@ signerClient.request = (async ({ method, params }) => {
8288 return anvilAbstractTestnet . getClient ( ) . request ( { method, params } as any ) ;
8389} ) as EIP1193RequestFn ;
8490
85- const publicClient = createPublicClient ( {
86- chain : anvilAbstractTestnet . chain as ChainEIP712 ,
87- transport : anvilAbstractTestnet . clientConfig . transport ,
88- } ) ;
89-
90- publicClient . request = ( async ( { method, params } ) => {
91- if ( method === 'zks_estimateFee' ) {
92- throw new Error ( 'zks_estimateFee not supported' ) ;
93- } else if ( method === 'eth_estimateGas' ) {
94- return toHex ( MOCK_ETH_ESTIMATE_GAS_LIMIT ) ;
95- } else if ( method === 'eth_gasPrice' ) {
96- return toHex ( MOCK_FEE_PER_GAS ) ;
97- } else if ( method === 'eth_getBalance' ) {
98- return toHex ( 1000000000000000000n ) ; // 1 ETH
99- }
100- return anvilAbstractTestnet . getClient ( ) . request ( { method, params } as any ) ;
101- } ) as EIP1193RequestFn ;
91+ const publicClient = baseClient . extend (
92+ publicActions ,
93+ ) as unknown as PublicClient < Transport , ChainEIP712 > ;
10294
10395publicClient . getTransactionCount = vi . fn ( async ( ) => {
10496 return MOCK_NONCE ;
@@ -354,13 +346,13 @@ test.each([
354346] ) ( '$name' , async ( { balance, value, isSponsored, errorType } ) => {
355347 vi . mocked ( isSmartAccountDeployed ) . mockResolvedValue ( true ) ;
356348
357- // Create a modified public client that returns a specified balance
358- const publicClientWithCustomBalance = createPublicClient ( {
349+ const customBaseClient = createClient ( {
350+ account : address . smartAccountAddress ,
359351 chain : anvilAbstractTestnet . chain as ChainEIP712 ,
360352 transport : anvilAbstractTestnet . clientConfig . transport ,
361353 } ) ;
362354
363- publicClientWithCustomBalance . request = ( async ( { method, params } ) => {
355+ customBaseClient . request = ( async ( { method, params } ) => {
364356 if ( method === 'zks_estimateFee' ) {
365357 throw new Error ( 'zks_estimateFee not supported' ) ;
366358 } else if ( method === 'eth_estimateGas' ) {
@@ -373,6 +365,11 @@ test.each([
373365 return anvilAbstractTestnet . getClient ( ) . request ( { method, params } as any ) ;
374366 } ) as EIP1193RequestFn ;
375367
368+ // Create a modified public client that returns a specified balance
369+ const publicClientWithCustomBalance = customBaseClient . extend (
370+ publicActions ,
371+ ) as unknown as PublicClient < Transport , ChainEIP712 > ;
372+
376373 const txWithoutPaymaster = {
377374 ...transaction ,
378375 ...( value !== undefined && { value } ) ,
0 commit comments