Skip to content

Commit

Permalink
chore(test-contracts): prepare e2e_token_contract+ error msgs for AVM…
Browse files Browse the repository at this point in the history
… migration (#6307)
  • Loading branch information
fcarreiro authored May 9, 2024
1 parent 27534ac commit 0c20f44
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 27 deletions.
9 changes: 5 additions & 4 deletions yarn-project/end-to-end/src/e2e_authwit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SchnorrAccountContract } from '@aztec/noir-contracts.js';

import { jest } from '@jest/globals';

import { DUPLICATE_NULLIFIER_ERROR } from './fixtures/fixtures.js';
import { publicDeployAccounts, setup } from './fixtures/utils.js';

const TIMEOUT = 90_000;
Expand Down Expand Up @@ -86,7 +87,7 @@ describe('e2e_authwit_tests', () => {
});

// The transaction should be dropped because of a cancelled authwit (duplicate nullifier)
await expect(txCancelledAuthwit.wait()).rejects.toThrow('Transaction ');
await expect(txCancelledAuthwit.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

it('invalid chain id', async () => {
Expand Down Expand Up @@ -130,7 +131,7 @@ describe('e2e_authwit_tests', () => {
});

// The transaction should be dropped because of the invalid chain id
await expect(txCancelledAuthwit.wait()).rejects.toThrow('Transaction ');
await expect(txCancelledAuthwit.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

it('invalid version', async () => {
Expand Down Expand Up @@ -174,7 +175,7 @@ describe('e2e_authwit_tests', () => {
});

// The transaction should be dropped because of the invalid version
await expect(txCancelledAuthwit.wait()).rejects.toThrow('Transaction ');
await expect(txCancelledAuthwit.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});
});
});
Expand Down Expand Up @@ -234,7 +235,7 @@ describe('e2e_authwit_tests', () => {
const c = await SchnorrAccountContract.at(wallets[0].getAddress(), wallets[0]);
const txCancelledAuthwit = c.withWallet(wallets[1]).methods.spend_public_authwit(innerHash).send();
// The transaction should be dropped because of a cancelled authwit (duplicate nullifier)
await expect(txCancelledAuthwit.wait()).rejects.toThrow('Transaction ');
await expect(txCancelledAuthwit.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fr, computeAuthWitMessageHash } from '@aztec/aztec.js';

import { U128_UNDERFLOW_ERROR } from '../fixtures/index.js';
import { DUPLICATE_NULLIFIER_ERROR, U128_UNDERFLOW_ERROR } from '../fixtures/index.js';
import { BlacklistTokenContractTest } from './blacklist_token_contract_test.js';

describe('e2e_blacklist_token_contract burn', () => {
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('e2e_blacklist_token_contract burn', () => {

// Check that the message hash is no longer valid. Need to try to send since nullifiers are handled by sequencer.
const txReplay = asset.withWallet(wallets[1]).methods.burn_public(wallets[0].getAddress(), amount, nonce).send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

describe('failure cases', () => {
Expand Down Expand Up @@ -146,7 +146,7 @@ describe('e2e_blacklist_token_contract burn', () => {

// Perform the transfer again, should fail
const txReplay = asset.withWallet(wallets[1]).methods.burn(wallets[0].getAddress(), amount, nonce).send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

describe('failure cases', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fr, computeSecretHash } from '@aztec/aztec.js';

import { U128_UNDERFLOW_ERROR } from '../fixtures/index.js';
import { DUPLICATE_NULLIFIER_ERROR, U128_UNDERFLOW_ERROR } from '../fixtures/index.js';
import { BlacklistTokenContractTest } from './blacklist_token_contract_test.js';

describe('e2e_blacklist_token_contract shield + redeem_shield', () => {
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('e2e_blacklist_token_contract shield + redeem_shield', () => {
.withWallet(wallets[1])
.methods.shield(wallets[0].getAddress(), amount, secretHash, nonce)
.send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);

// Redeem it
await t.addPendingShieldNoteToPXE(0, amount, secretHash, receipt.txHash);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Fr, computeAuthWitMessageHash } from '@aztec/aztec.js';

import { DUPLICATE_NULLIFIER_ERROR } from '../fixtures/fixtures.js';
import { BlacklistTokenContractTest } from './blacklist_token_contract_test.js';

describe('e2e_blacklist_token_contract transfer private', () => {
Expand Down Expand Up @@ -67,7 +68,7 @@ describe('e2e_blacklist_token_contract transfer private', () => {
.withWallet(wallets[1])
.methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce)
.send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

describe('failure cases', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fr } from '@aztec/aztec.js';

import { U128_UNDERFLOW_ERROR } from '../fixtures/index.js';
import { DUPLICATE_NULLIFIER_ERROR, U128_UNDERFLOW_ERROR } from '../fixtures/index.js';
import { BlacklistTokenContractTest } from './blacklist_token_contract_test.js';

describe('e2e_blacklist_token_contract transfer public', () => {
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('e2e_blacklist_token_contract transfer public', () => {
.withWallet(wallets[1])
.methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce)
.send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

describe('failure cases', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Fr, computeAuthWitMessageHash } from '@aztec/aztec.js';

import { DUPLICATE_NULLIFIER_ERROR } from '../fixtures/fixtures.js';
import { BlacklistTokenContractTest } from './blacklist_token_contract_test.js';

describe('e2e_blacklist_token_contract unshielding', () => {
Expand Down Expand Up @@ -57,7 +58,7 @@ describe('e2e_blacklist_token_contract unshielding', () => {
.withWallet(wallets[1])
.methods.unshield(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce)
.send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
// @todo @LHerskind This error is weird?
});

Expand Down
6 changes: 3 additions & 3 deletions yarn-project/end-to-end/src/e2e_token_contract/burn.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fr, computeAuthWitMessageHash } from '@aztec/aztec.js';

import { U128_UNDERFLOW_ERROR } from '../fixtures/index.js';
import { DUPLICATE_NULLIFIER_ERROR, U128_UNDERFLOW_ERROR } from '../fixtures/index.js';
import { TokenContractTest } from './token_contract_test.js';

describe('e2e_token_contract burn', () => {
Expand Down Expand Up @@ -49,7 +49,7 @@ describe('e2e_token_contract burn', () => {

// Check that the message hash is no longer valid. Need to try to send since nullifiers are handled by sequencer.
const txReplay = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce).send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

describe('failure cases', () => {
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('e2e_token_contract burn', () => {

// Perform the transfer again, should fail
const txReplay = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce).send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

describe('failure cases', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fr, computeSecretHash } from '@aztec/aztec.js';

import { U128_UNDERFLOW_ERROR } from '../fixtures/fixtures.js';
import { DUPLICATE_NULLIFIER_ERROR, U128_UNDERFLOW_ERROR } from '../fixtures/fixtures.js';
import { TokenContractTest } from './token_contract_test.js';

describe('e2e_token_contract shield + redeem shield', () => {
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('e2e_token_contract shield + redeem shield', () => {

// Check that replaying the shield should fail!
const txReplay = asset.withWallet(wallets[1]).methods.shield(accounts[0].address, amount, secretHash, nonce).send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);

// Redeem it
await t.addPendingShieldNoteToPXE(0, amount, secretHash, receipt.txHash);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Fr, computeAuthWitMessageHash } from '@aztec/aztec.js';

import { DUPLICATE_NULLIFIER_ERROR } from '../fixtures/fixtures.js';
import { TokenContractTest } from './token_contract_test.js';

describe('e2e_token_contract transfer private', () => {
Expand Down Expand Up @@ -66,7 +67,7 @@ describe('e2e_token_contract transfer private', () => {
.withWallet(wallets[1])
.methods.transfer(accounts[0].address, accounts[1].address, amount, nonce)
.send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

describe('failure cases', () => {
Expand Down Expand Up @@ -188,7 +189,7 @@ describe('e2e_token_contract transfer private', () => {
.withWallet(wallets[1])
.methods.transfer(accounts[0].address, accounts[1].address, amount, nonce)
.send();
await expect(txCancelledAuthwit.wait()).rejects.toThrowError('Transaction ');
await expect(txCancelledAuthwit.wait()).rejects.toThrowError(DUPLICATE_NULLIFIER_ERROR);
});

it('transfer on behalf of other, cancelled authwit, flow 2', async () => {
Expand All @@ -212,7 +213,7 @@ describe('e2e_token_contract transfer private', () => {
.withWallet(wallets[1])
.methods.transfer(accounts[0].address, accounts[1].address, amount, nonce)
.send();
await expect(txCancelledAuthwit.wait()).rejects.toThrow('Transaction ');
await expect(txCancelledAuthwit.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

it('transfer on behalf of other, invalid spend_private_authwit on "from"', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Fr, computeAuthWitMessageHash } from '@aztec/aztec.js';

import { U128_UNDERFLOW_ERROR } from '../fixtures/fixtures.js';
import { DUPLICATE_NULLIFIER_ERROR, U128_UNDERFLOW_ERROR } from '../fixtures/fixtures.js';
import { TokenContractTest } from './token_contract_test.js';

describe('e2e_token_contract transfer public', () => {
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('e2e_token_contract transfer public', () => {
.withWallet(wallets[1])
.methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce)
.send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

describe('failure cases', () => {
Expand Down Expand Up @@ -194,7 +194,7 @@ describe('e2e_token_contract transfer public', () => {
.withWallet(wallets[1])
.methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce)
.send();
await expect(txCancelledAuthwit.wait()).rejects.toThrowError('Transaction ');
await expect(txCancelledAuthwit.wait()).rejects.toThrowError(DUPLICATE_NULLIFIER_ERROR);
});

it('transfer on behalf of other, cancelled authwit, flow 2', async () => {
Expand All @@ -216,7 +216,7 @@ describe('e2e_token_contract transfer public', () => {
.withWallet(wallets[1])
.methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce)
.send();
await expect(txCancelledAuthwit.wait()).rejects.toThrowError('Transaction ');
await expect(txCancelledAuthwit.wait()).rejects.toThrowError(DUPLICATE_NULLIFIER_ERROR);
});

it('transfer on behalf of other, cancelled authwit, flow 3', async () => {
Expand Down Expand Up @@ -244,7 +244,7 @@ describe('e2e_token_contract transfer public', () => {
.withWallet(wallets[1])
.methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce)
.send();
await expect(txCancelledAuthwit.wait()).rejects.toThrow('Transaction ');
await expect(txCancelledAuthwit.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

it('transfer on behalf of other, invalid spend_public_authwit on "from"', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Fr, computeAuthWitMessageHash } from '@aztec/aztec.js';

import { DUPLICATE_NULLIFIER_ERROR } from '../fixtures/fixtures.js';
import { TokenContractTest } from './token_contract_test.js';

describe('e2e_token_contract unshielding', () => {
Expand Down Expand Up @@ -56,7 +57,7 @@ describe('e2e_token_contract unshielding', () => {
.withWallet(wallets[1])
.methods.unshield(accounts[0].address, accounts[1].address, amount, nonce)
.send();
await expect(txReplay.wait()).rejects.toThrow('Transaction ');
await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR);
});

describe('failure cases', () => {
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/end-to-end/src/fixtures/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ export const U128_UNDERFLOW_ERROR = "Assertion failed: attempt to subtract with
export const U128_OVERFLOW_ERROR = "Assertion failed: attempt to add with overflow 'hi == high'";
export const BITSIZE_TOO_BIG_ERROR =
"Assertion failed: call to assert_max_bit_size 'self.__assert_max_bit_size(bit_size)'";
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/5818): Make this a fixed error after transition.
export const DUPLICATE_NULLIFIER_ERROR = /Transaction .*|.*duplicate nullifier.*/;

0 comments on commit 0c20f44

Please sign in to comment.