Skip to content

Commit 1c4e541

Browse files
committed
Finally mock the eth_call in tests
1 parent a7e0cb5 commit 1c4e541

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { toHex } from 'viem';
2+
import { mockRpcRequest } from '../../../test/mocks/mock-request';
3+
import {
4+
setupMockWalletClient,
5+
setupMockPublicClient,
6+
} from '../../../test/mocks/setup-mock-clients';
7+
import { Chain } from '../../chains/constants';
8+
import { PufferVaultHandler } from './puffer-vault-handler';
9+
10+
describe('PufferVaultHandler', () => {
11+
it('should check pufETH balance', async () => {
12+
const mockAddress = '0x8d37d81e29d11cd7557ceaca25e4e4a4255b1159';
13+
const mockBalance = BigInt(1);
14+
const mockCallHex = toHex(mockBalance, { size: 32 });
15+
16+
const walletClient = setupMockWalletClient();
17+
const publicRequest = mockRpcRequest({ eth_call: mockCallHex });
18+
const publicClient = setupMockPublicClient(publicRequest);
19+
20+
const handler = new PufferVaultHandler(
21+
Chain.Anvil,
22+
walletClient,
23+
publicClient,
24+
);
25+
const balance = await handler.balanceOf(mockAddress);
26+
27+
expect(balance).toBe(mockBalance);
28+
});
29+
30+
it('should be able to deposit ETH', async () => {
31+
const mockAddress = '0xEB77D02f8122B32273444a1b544C147Fb559CB41';
32+
const mockGas = BigInt(1);
33+
34+
const walletRequest = mockRpcRequest({
35+
eth_sendTransaction: mockAddress,
36+
});
37+
const walletClient = setupMockWalletClient(walletRequest);
38+
const publicRequest = mockRpcRequest({ eth_estimateGas: mockGas });
39+
const publicClient = setupMockPublicClient(publicRequest);
40+
41+
const handler = new PufferVaultHandler(
42+
Chain.Anvil,
43+
walletClient,
44+
publicClient,
45+
);
46+
const { transact, estimate } = handler.depositETH(mockAddress);
47+
48+
expect(await transact(BigInt(1))).toBe(mockAddress);
49+
expect(await estimate()).toBe(mockGas);
50+
});
51+
});

0 commit comments

Comments
 (0)