Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jan 17, 2025
1 parent 0e9f266 commit a9a170e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions yarn-project/end-to-end/src/e2e_token_contract/minting.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BITSIZE_TOO_BIG_ERROR, U128_OVERFLOW_ERROR } from '../fixtures/fixtures.js';
import { U128_OVERFLOW_ERROR } from '../fixtures/fixtures.js';
import { TokenContractTest } from './token_contract_test.js';

describe('e2e_token_contract minting', () => {
Expand Down Expand Up @@ -40,9 +40,16 @@ describe('e2e_token_contract minting', () => {
});

it('mint >u128 tokens to overflow', async () => {
const amount = 2n ** 128n; // U128::max() + 1;
await expect(asset.methods.mint_to_public(accounts[0].address, amount).simulate()).rejects.toThrow(
BITSIZE_TOO_BIG_ERROR,
const maxAmountWithoutOverflow = 2n ** 128n - 1n - tokenSim.balanceOfPublic(accounts[0].address);

// First we send a valid tx because if we minted with "amount > U128::max()" we would get an error in U128
// in encoder.ts
await asset.methods.mint_to_public(accounts[0].address, maxAmountWithoutOverflow).send().wait();
tokenSim.mintPublic(accounts[0].address, maxAmountWithoutOverflow);

// Then we try to mint 1 to cause the U128 overflow inside the contract
await expect(asset.methods.mint_to_public(accounts[0].address, 1n).simulate()).rejects.toThrow(
U128_OVERFLOW_ERROR,
);
});

Expand Down

0 comments on commit a9a170e

Please sign in to comment.