Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
jscriptcoder committed Jul 19, 2023
1 parent 5354874 commit 0be1db3
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
} catch (err) {
console.error(err);
if (error instanceof UserRejectedRequestError) {
if (err instanceof UserRejectedRequestError) {
warningToast($t('messages.network.rejected'));
}
} finally {
Expand Down
15 changes: 1 addition & 14 deletions packages/bridge-ui-v2/src/libs/token/checkMintable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,6 @@ describe('checkMintable', () => {
vi.clearAllMocks();
});

it('should throw when wallet is not connected', async () => {
vi.mocked(getWalletClient).mockResolvedValueOnce(null);

try {
await checkMintable(BLLToken, mainnetChain.id);
expect.fail('should have thrown');
} catch (error) {
const { cause } = error as Error;
expect(cause).toBe(MintableError.NOT_CONNECTED);
expect(getWalletClient).toHaveBeenCalled();
}
});

it('should throw when user has already minted', async () => {
vi.mocked(mockTokenContract.read.minters).mockResolvedValueOnce(true);

Expand Down Expand Up @@ -100,7 +87,7 @@ describe('checkMintable', () => {
} catch (error) {
const { cause } = error as Error;
expect(cause).toBe(MintableError.INSUFFICIENT_BALANCE);
expect(getPublicClient).toHaveBeenCalledWith({ chainId: mainnetChain.id });
expect(getPublicClient).toHaveBeenCalled();
expect(mockTokenContract.estimateGas.mint).toHaveBeenCalledWith([mockWalletClient.account.address]);
expect(mockPublicClient.getBalance).toHaveBeenCalledWith({ address: mockWalletClient.account.address });
}
Expand Down
5 changes: 2 additions & 3 deletions packages/bridge-ui-v2/src/libs/token/checkMintable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { getConnectedWallet } from '$libs/util/getWallet';
import { MintableError, type Token } from './types';

// Throws an error if:
// 1. Wallet is not connected
// 2. User has already minted this token
// 3. User has insufficient balance to mint this token
// 1. User has already minted this token
// 2. User has insufficient balance to mint this token
export async function checkMintable(token: Token, chainId: number) {
const walletClient = await getConnectedWallet();

Expand Down
2 changes: 1 addition & 1 deletion packages/bridge-ui-v2/src/libs/token/mint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('mint', () => {
vi.mocked(getContract).mockReturnValue(mockTokenContract);
vi.mocked(mockTokenContract.write.mint).mockResolvedValue('0x123456');

await expect(mint(BLLToken, mockWalletClient)).resolves.toEqual('0x123456');
await expect(mint(BLLToken)).resolves.toEqual('0x123456');
expect(mockTokenContract.write.mint).toHaveBeenCalledWith([mockWalletClient.account.address]);
});
});
1 change: 0 additions & 1 deletion packages/bridge-ui-v2/src/libs/token/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export type TokenEnv = {
};

export enum MintableError {
NOT_CONNECTED = 'NOT_CONNECTED',
TOKEN_MINTED = 'TOKEN_MINTED',
INSUFFICIENT_BALANCE = 'INSUFFICIENT_BALANCE',
}

0 comments on commit 0be1db3

Please sign in to comment.