Skip to content

Commit

Permalink
Add test for using salt in ERC20PermitHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
9inpachi committed Sep 23, 2024
1 parent 2409014 commit 65da98b
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion lib/contracts/handlers/erc20-permit-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
setupTestPublicClient,
} from '../../../test/setup-test-clients';
import { mockAccount, testingUtils } from '../../../test/setup-tests';
import { Token } from '../tokens';
import { Token, TOKENS_SALT } from '../tokens';
import { ERC20PERMIT_ABI } from '../abis/tokens-abis';
import { ERC20PermitHandler } from './erc20-permit-handler';
import {
Expand Down Expand Up @@ -66,4 +66,33 @@ describe('ERC20PermitHandler', () => {
const txHash = await handler.approve(mockAccount, mockSpender, 1n);
expect(isHash(txHash)).toBeTruthy();
});

it('should use permit salt for tokens that have it', async () => {
// Using mainnet for this test since it has salt for pufETHwstE.
handler = new ERC20PermitHandler(Chain.Mainnet, walletClient, publicClient);

contractTestingUtils.mockCall('nonces', [10n]);
contractTestingUtils.mockCall('name', ['Ethereum Staking Mock']);

const mockSpender = padHex('0x', { size: 20 });
// Mocking the wallet client since couldn't find a way to mock
// through eth-testing.
const mockSignature = serializeSignature({
r: '0x1',
s: '0x1',
v: 0n,
yParity: 1,
});
const signTypedDataSpy = jest
.spyOn(walletClient, 'signTypedData')
.mockReturnValue(Promise.resolve(mockSignature));

await handler
.withToken(Token.pufETHwstE)
.getPermitSignature(mockAccount, mockSpender, 1n);

const salt = TOKENS_SALT[Token.pufETHwstE]?.[Chain.Mainnet];
expect(salt).toBeDefined();
expect(signTypedDataSpy.mock.lastCall?.[0].domain?.salt).toBe(salt);
});
});

0 comments on commit 65da98b

Please sign in to comment.