-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for the PufferDepositorHandler
- Loading branch information
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |