Skip to content

Commit

Permalink
Finally mock the eth_call in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
9inpachi committed May 28, 2024
1 parent 847b86e commit 14c140c
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions lib/contracts/handlers/puffer-vault-handler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { toHex } from 'viem';
import { mockRpcRequest } from '../../../test/mocks/mock-request';
import {
setupMockWalletClient,
setupMockPublicClient,
} from '../../../test/mocks/setup-mock-clients';
import { Chain } from '../../chains/constants';
import { PufferVaultHandler } from './puffer-vault-handler';

describe('PufferVaultHandler', () => {
it('should check pufETH balance', async () => {
const mockAddress = '0x8d37d81e29d11cd7557ceaca25e4e4a4255b1159';
const mockBalance = BigInt(1);
const mockCallHex = toHex(mockBalance, { size: 32 });

const walletClient = setupMockWalletClient();
const publicRequest = mockRpcRequest({ eth_call: mockCallHex });
const publicClient = setupMockPublicClient(publicRequest);

const handler = new PufferVaultHandler(
Chain.Anvil,
walletClient,
publicClient,
);
const balance = await handler.balanceOf(mockAddress);

expect(balance).toBe(mockBalance);
});

it('should be able to deposit ETH', async () => {
const mockAddress = '0xEB77D02f8122B32273444a1b544C147Fb559CB41';
const mockGas = BigInt(1);

const walletRequest = mockRpcRequest({
eth_sendTransaction: mockAddress,
});
const walletClient = setupMockWalletClient(walletRequest);
const publicRequest = mockRpcRequest({ eth_estimateGas: mockGas });
const publicClient = setupMockPublicClient(publicRequest);

const handler = new PufferVaultHandler(
Chain.Anvil,
walletClient,
publicClient,
);
const { transact, estimate } = handler.depositETH(mockAddress);

expect(await transact(BigInt(1))).toBe(mockAddress);
expect(await estimate()).toBe(mockGas);
});
});

0 comments on commit 14c140c

Please sign in to comment.