Skip to content

Commit

Permalink
Add tests for the PufferDepositorHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
9inpachi committed Jun 14, 2024
1 parent b08741a commit 2d784ea
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions lib/contracts/handlers/puffer-depositor-handler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { Address, toHex } from 'viem';
import {
setupTestPublicClient,
setupTestWalletClient,
} from '../../../test/setup-test-clients';
import { mockAccount, testingUtils } from '../../../test/setup-tests';
import { Chain } from '../../chains/constants';
import { PufferDepositorHandler } from './puffer-depositor-handler';

describe('PufferDepositorHandler', () => {
it('should deposit stETH in exchange for pufETH', async () => {
const mockGas = BigInt(1);
const mockTxHash = '0x123';

testingUtils.lowLevel.mockRequest('eth_sendTransaction', mockTxHash);
testingUtils.lowLevel.mockRequest('eth_estimateGas', toHex(mockGas));

const walletClient = setupTestWalletClient();
const publicClient = setupTestPublicClient();

const handler = new PufferDepositorHandler(
Chain.Holesky,
walletClient,
publicClient,
);

const mockPermitSignature = {
r: `0x${new Array(64).fill(0).join('')}` as Address,
s: `0x${new Array(64).fill(0).join('')}` as Address,
v: BigInt(0),
yParity: 1,
deadline: BigInt(0),
};
jest
.spyOn(handler.tokensHandler, 'getPermitSignature')
.mockReturnValue(Promise.resolve(mockPermitSignature));

const { transact, estimate } = await handler.depositStETH(
mockAccount,
BigInt(1),
);

expect(await transact()).toBe(mockTxHash);
expect(await estimate()).toBe(mockGas);
});

it('should deposit wstETH in exchange for pufETH', async () => {
const mockGas = BigInt(1);
const mockTxHash = '0x123';

testingUtils.lowLevel.mockRequest('eth_sendTransaction', mockTxHash);
testingUtils.lowLevel.mockRequest('eth_estimateGas', toHex(mockGas));

const walletClient = setupTestWalletClient();
const publicClient = setupTestPublicClient();

const handler = new PufferDepositorHandler(
Chain.Holesky,
walletClient,
publicClient,
);

const mockPermitSignature = {
r: `0x${new Array(64).fill(0).join('')}` as Address,
s: `0x${new Array(64).fill(0).join('')}` as Address,
v: BigInt(0),
yParity: 1,
deadline: BigInt(0),
};
jest
.spyOn(handler.tokensHandler, 'getPermitSignature')
.mockReturnValue(Promise.resolve(mockPermitSignature));

const { transact, estimate } = await handler.depositWstETH(
mockAccount,
BigInt(1),
);

expect(await transact()).toBe(mockTxHash);
expect(await estimate()).toBe(mockGas);
});
});

0 comments on commit 2d784ea

Please sign in to comment.