Skip to content

Commit

Permalink
chore: address api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Sep 12, 2023
1 parent e368494 commit 3a70678
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
41 changes: 23 additions & 18 deletions yarn-project/end-to-end/src/e2e_token_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { DebugLogger } from '@aztec/foundation/log';
import { SchnorrAuthWitnessAccountContract, TokenContract } from '@aztec/noir-contracts/types';
import { AztecRPC, TxStatus } from '@aztec/types';

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

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

const hashPayload = async (payload: Fr[]) => {
Expand All @@ -31,6 +33,8 @@ const hashPayload = async (payload: Fr[]) => {
);
};

const TIMEOUT = 60_000;

class TokenSimulator {
private balancesPrivate: Map<AztecAddress, bigint> = new Map();
private balancePublic: Map<AztecAddress, bigint> = new Map();
Expand Down Expand Up @@ -121,6 +125,8 @@ class TokenSimulator {
}

describe('e2e_token_contract', () => {
jest.setTimeout(TIMEOUT);

let aztecNode: AztecNodeService | undefined;
let aztecRpcServer: AztecRPC;
let wallets: AuthWitnessEntrypointWallet[];
Expand Down Expand Up @@ -195,9 +201,9 @@ describe('e2e_token_contract', () => {

afterEach(async () => {
await tokenSim.check();
}, 30_000);
}, TIMEOUT);

describe.only('Access controlled functions', () => {
describe('Access controlled functions', () => {
it('Set admin', async () => {
const tx = asset.methods.set_admin({ address: accounts[1].address }).send();
const receipt = await tx.wait();
Expand Down Expand Up @@ -233,7 +239,7 @@ describe('e2e_token_contract', () => {
});
});

describe.only('Minting', () => {
describe('Minting', () => {
describe('Public', () => {
it('as minter', async () => {
const amount = 10000n;
Expand Down Expand Up @@ -297,7 +303,6 @@ describe('e2e_token_contract', () => {
});

it('redeem as recipient', async () => {
// How is this shitter failing?
const txClaim = asset.methods.redeem_shield({ address: accounts[0].address }, amount, secret).send();
const receiptClaim = await txClaim.wait();
expect(receiptClaim.status).toBe(TxStatus.MINED);
Expand Down Expand Up @@ -388,7 +393,7 @@ describe('e2e_token_contract', () => {
expect(receipt.status).toBe(TxStatus.MINED);

tokenSim.transferPublic(accounts[0].address, accounts[0].address, amount);
}, 30_000);
});

it('transfer on behalf of other', async () => {
const balance0 = await asset.methods.balance_of_public({ address: accounts[0].address }).view();
Expand Down Expand Up @@ -423,7 +428,7 @@ describe('e2e_token_contract', () => {
await txReplay.isMined();
const receiptReplay = await txReplay.getReceipt();
expect(receiptReplay.status).toBe(TxStatus.DROPPED);
}, 45_000);
});

describe('failure cases', () => {
it('transfer more than balance', async () => {
Expand Down Expand Up @@ -496,7 +501,7 @@ describe('e2e_token_contract', () => {

expect(await asset.methods.balance_of_public({ address: accounts[0].address }).view()).toEqual(balance0);
expect(await asset.methods.balance_of_public({ address: accounts[1].address }).view()).toEqual(balance1);
}, 30_000);
});

it('transfer on behalf of other, wrong designated caller', async () => {
const balance0 = await asset.methods.balance_of_public({ address: accounts[0].address }).view();
Expand Down Expand Up @@ -529,7 +534,7 @@ describe('e2e_token_contract', () => {

expect(await asset.methods.balance_of_public({ address: accounts[0].address }).view()).toEqual(balance0);
expect(await asset.methods.balance_of_public({ address: accounts[1].address }).view()).toEqual(balance1);
}, 45_000);
});

it('transfer on behalf of other, wrong designated caller', async () => {
const balance0 = await asset.methods.balance_of_public({ address: accounts[0].address }).view();
Expand Down Expand Up @@ -600,7 +605,7 @@ describe('e2e_token_contract', () => {
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
tokenSim.transferPrivate(accounts[0].address, accounts[1].address, amount);
}, 30_000);
});

it('transfer to self', async () => {
const balance0 = await asset.methods.balance_of_private({ address: accounts[0].address }).view();
Expand All @@ -612,7 +617,7 @@ describe('e2e_token_contract', () => {
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
tokenSim.transferPrivate(accounts[0].address, accounts[0].address, amount);
}, 30_000);
});

it('transfer on behalf of other', async () => {
const balance0 = await asset.methods.balance_of_private({ address: accounts[0].address }).view();
Expand Down Expand Up @@ -792,7 +797,7 @@ describe('e2e_token_contract', () => {
await txClaimDoubleSpend.isMined();
const receiptDoubleSpend = await txClaimDoubleSpend.getReceipt();
expect(receiptDoubleSpend.status).toBe(TxStatus.DROPPED);
}, 30_000);
});

it('on behalf of other', async () => {
const balancePub = await asset.methods.balance_of_public({ address: accounts[0].address }).view();
Expand Down Expand Up @@ -840,7 +845,7 @@ describe('e2e_token_contract', () => {
await txClaimDoubleSpend.isMined();
const receiptDoubleSpend = await txClaimDoubleSpend.getReceipt();
expect(receiptDoubleSpend.status).toBe(TxStatus.DROPPED);
}, 60_000);
});

describe('failure cases', () => {
it('on behalf of self (more than balance)', async () => {
Expand Down Expand Up @@ -884,7 +889,7 @@ describe('e2e_token_contract', () => {
.methods.shield({ address: accounts[0].address }, amount, secretHash, nonce)
.simulate(),
).rejects.toThrowError('Assertion failed: Underflow');
}, 30_000);
});

it('on behalf of other (wrong designated caller)', async () => {
const balancePub = await asset.methods.balance_of_public({ address: accounts[0].address }).view();
Expand All @@ -907,7 +912,7 @@ describe('e2e_token_contract', () => {
.methods.shield({ address: accounts[0].address }, amount, secretHash, nonce)
.simulate(),
).rejects.toThrowError('Assertion failed: invalid call');
}, 30_000);
});

it('on behalf of other (wrong designated caller)', async () => {
const balancePub = await asset.methods.balance_of_public({ address: accounts[0].address }).view();
Expand Down Expand Up @@ -983,7 +988,7 @@ describe('e2e_token_contract', () => {
expect(receipt.status).toBe(TxStatus.MINED);

tokenSim.unshield(accounts[0].address, accounts[0].address, amount);
}, 45_000);
});

it('on behalf of other', async () => {
const balancePriv0 = await asset.methods.balance_of_private({ address: accounts[0].address }).view();
Expand Down Expand Up @@ -1016,7 +1021,7 @@ describe('e2e_token_contract', () => {
await txReplay.isMined();
const receiptReplay = await txReplay.getReceipt();
expect(receiptReplay.status).toBe(TxStatus.DROPPED);
}, 30_000);
});

describe('failure cases', () => {
it('on behalf of self (more than balance)', async () => {
Expand Down Expand Up @@ -1114,7 +1119,7 @@ describe('e2e_token_contract', () => {
expect(receipt.status).toBe(TxStatus.MINED);

tokenSim.burnPublic(accounts[0].address, amount);
}, 30_000);
});

it('burn on behalf of other', async () => {
const balance0 = await asset.methods.balance_of_public({ address: accounts[0].address }).view();
Expand Down Expand Up @@ -1148,7 +1153,7 @@ describe('e2e_token_contract', () => {
await txReplay.isMined();
const receiptReplay = await txReplay.getReceipt();
expect(receiptReplay.status).toBe(TxStatus.DROPPED);
}, 30_000);
});

describe('failure cases', () => {
it('burn more than balance', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ contract Token {
let balance = storage.balances.at(to.address);
let public_note = TransparentNote::new_from_secret(amount, secret);

pending_shields.assert_contains_and_remove(public_note);
pending_shields.assert_contains_and_remove_publicly_created(public_note);
increment(balance, amount, to.address);

1
Expand Down

0 comments on commit 3a70678

Please sign in to comment.