Skip to content

Commit

Permalink
chore: move e2e-avm-initializer test to e2e-avm-simulator (#5570)
Browse files Browse the repository at this point in the history
This avoids setting up a new unnecessary e2e test in the CI. We need 2 separate contracts to prevent the initializer modifying all the other functions in AvmTestContract, but we don't need 2 e2e tests.
  • Loading branch information
fcarreiro committed Apr 4, 2024
1 parent 11699c8 commit d827705
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 64 deletions.
32 changes: 0 additions & 32 deletions yarn-project/end-to-end/src/e2e_avm_initializer.test.ts

This file was deleted.

81 changes: 49 additions & 32 deletions yarn-project/end-to-end/src/e2e_avm_simulator.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AztecAddress, Fr, TxStatus, type Wallet } from '@aztec/aztec.js';
import { AvmTestContract } from '@aztec/noir-contracts.js';
import { AvmInitializerTestContract, AvmTestContract } from '@aztec/noir-contracts.js';

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

Expand All @@ -11,7 +11,6 @@ describe('e2e_avm_simulator', () => {
jest.setTimeout(TIMEOUT);

let wallet: Wallet;
let avmContact: AvmTestContract;
let teardown: () => Promise<void>;

beforeAll(async () => {
Expand All @@ -20,46 +19,64 @@ describe('e2e_avm_simulator', () => {

afterAll(() => teardown());

beforeEach(async () => {
avmContact = await AvmTestContract.deploy(wallet).send().deployed();
}, 50_000);
describe('AvmTestContract', () => {
let avmContract: AvmTestContract;

describe('Storage', () => {
it('Modifies storage (Field)', async () => {
await avmContact.methods.set_storage_single(20n).send().wait();
expect(await avmContact.methods.view_storage_single().simulate()).toEqual(20n);
beforeEach(async () => {
avmContract = await AvmTestContract.deploy(wallet).send().deployed();
}, 50_000);

describe('Storage', () => {
it('Modifies storage (Field)', async () => {
await avmContract.methods.set_storage_single(20n).send().wait();
expect(await avmContract.methods.view_storage_single().simulate()).toEqual(20n);
});

it('Modifies storage (Map)', async () => {
const address = AztecAddress.fromBigInt(9090n);
await avmContract.methods.set_storage_map(address, 100).send().wait();
await avmContract.methods.add_storage_map(address, 100).send().wait();
expect(await avmContract.methods.view_storage_map(address).simulate()).toEqual(200n);
});
});

it('Modifies storage (Map)', async () => {
const address = AztecAddress.fromBigInt(9090n);
await avmContact.methods.set_storage_map(address, 100).send().wait();
await avmContact.methods.add_storage_map(address, 100).send().wait();
expect(await avmContact.methods.view_storage_map(address).simulate()).toEqual(200n);
describe('Contract instance', () => {
it('Works', async () => {
const tx = await avmContract.methods.test_get_contract_instance().send().wait();
expect(tx.status).toEqual(TxStatus.MINED);
});
});
});

describe('Contract instance', () => {
it('Works', async () => {
const tx = await avmContact.methods.test_get_contract_instance().send().wait();
expect(tx.status).toEqual(TxStatus.MINED);
describe('Nullifiers', () => {
// Nullifier will not yet be siloed by the kernel.
it('Emit and check in the same tx', async () => {
const tx = await avmContract.methods.emit_nullifier_and_check(123456).send().wait();
expect(tx.status).toEqual(TxStatus.MINED);
});

// Nullifier will have been siloed by the kernel, but we check against the unsiloed one.
it('Emit and check in separate tx', async () => {
const nullifier = new Fr(123456);
let tx = await avmContract.methods.new_nullifier(nullifier).send().wait();
expect(tx.status).toEqual(TxStatus.MINED);

tx = await avmContract.methods.assert_nullifier_exists(nullifier).send().wait();
expect(tx.status).toEqual(TxStatus.MINED);
});
});
});

describe('Nullifiers', () => {
// Nullifier will not yet be siloed by the kernel.
it('Emit and check in the same tx', async () => {
const tx = await avmContact.methods.emit_nullifier_and_check(123456).send().wait();
expect(tx.status).toEqual(TxStatus.MINED);
});
describe('AvmInitializerTestContract', () => {
let avmContract: AvmInitializerTestContract;

// Nullifier will have been siloed by the kernel, but we check against the unsiloed one.
it('Emit and check in separate tx', async () => {
const nullifier = new Fr(123456);
let tx = await avmContact.methods.new_nullifier(nullifier).send().wait();
expect(tx.status).toEqual(TxStatus.MINED);
beforeEach(async () => {
avmContract = await AvmInitializerTestContract.deploy(wallet).send().deployed();
}, 50_000);

tx = await avmContact.methods.assert_nullifier_exists(nullifier).send().wait();
expect(tx.status).toEqual(TxStatus.MINED);
describe('Storage', () => {
it('Read immutable (initialized) storage (Field)', async () => {
expect(await avmContract.methods.view_storage_immutable().simulate()).toEqual(42n);
});
});
});
});

0 comments on commit d827705

Please sign in to comment.