Skip to content

Commit

Permalink
chore: Fix dapp_testing e2e race condition (#3094)
Browse files Browse the repository at this point in the history
Attempts to fix [this
error](https://app.circleci.com/pipelines/github/AztecProtocol/aztec-packages/15389/workflows/04aaf21e-e881-433c-b00c-d4acbc44221b/jobs/659626)
in the `guides/dapp_testing` e2e test. The error looks like both the
sandbox in the docker compose and the one in-proc in the tests are
trying to use the same anvil account for their L1 deployment. If it's
that, then reordering both suites so the in-proc one runs _after_ the
external sandbox one (which ensures that the external one has been
initialized) should do the trick easily.
  • Loading branch information
spalladino authored Oct 27, 2023
1 parent 906429f commit 89e7c21
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions yarn-project/end-to-end/src/guides/dapp_testing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,6 @@ import { TestContract, TokenContract } from '@aztec/noir-contracts/types';
const { PXE_URL = 'http://localhost:8080', ETHEREUM_HOST = 'http://localhost:8545' } = process.env;

describe('guides/dapp/testing', () => {
describe('on in-proc sandbox', () => {
describe('token contract', () => {
let pxe: PXE;
let stop: () => Promise<void>;
let owner: AccountWallet;
let recipient: AccountWallet;
let token: TokenContract;

beforeAll(async () => {
// docs:start:in-proc-sandbox
({ pxe, stop } = await createSandbox());
// docs:end:in-proc-sandbox
owner = await createAccount(pxe);
recipient = await createAccount(pxe);
token = await TokenContract.deploy(owner, owner.getCompleteAddress()).send().deployed();
}, 60_000);

// docs:start:stop-in-proc-sandbox
afterAll(() => stop());
// docs:end:stop-in-proc-sandbox

it('increases recipient funds on mint', async () => {
const recipientAddress = recipient.getAddress();
expect(await token.methods.balance_of_private(recipientAddress).view()).toEqual(0n);

const mintAmount = 20n;
const secret = Fr.random();
const secretHash = await computeMessageSecretHash(secret);
const receipt = await token.methods.mint_private(mintAmount, secretHash).send().wait();

const storageSlot = new Fr(5);
const preimage = new NotePreimage([new Fr(mintAmount), secretHash]);
await pxe.addNote(recipientAddress, token.address, storageSlot, preimage, receipt.txHash);

await token.methods.redeem_shield(recipientAddress, mintAmount, secret).send().wait();
expect(await token.methods.balance_of_private(recipientAddress).view()).toEqual(20n);
}, 30_000);
});
});

describe('on local sandbox', () => {
beforeAll(async () => {
const pxe = createPXEClient(PXE_URL);
Expand Down Expand Up @@ -257,4 +217,44 @@ describe('guides/dapp/testing', () => {
});
});
});

describe('on in-proc sandbox', () => {
describe('token contract', () => {
let pxe: PXE;
let stop: () => Promise<void>;
let owner: AccountWallet;
let recipient: AccountWallet;
let token: TokenContract;

beforeAll(async () => {
// docs:start:in-proc-sandbox
({ pxe, stop } = await createSandbox());
// docs:end:in-proc-sandbox
owner = await createAccount(pxe);
recipient = await createAccount(pxe);
token = await TokenContract.deploy(owner, owner.getCompleteAddress()).send().deployed();
}, 60_000);

// docs:start:stop-in-proc-sandbox
afterAll(() => stop());
// docs:end:stop-in-proc-sandbox

it('increases recipient funds on mint', async () => {
const recipientAddress = recipient.getAddress();
expect(await token.methods.balance_of_private(recipientAddress).view()).toEqual(0n);

const mintAmount = 20n;
const secret = Fr.random();
const secretHash = await computeMessageSecretHash(secret);
const receipt = await token.methods.mint_private(mintAmount, secretHash).send().wait();

const storageSlot = new Fr(5);
const preimage = new NotePreimage([new Fr(mintAmount), secretHash]);
await pxe.addNote(recipientAddress, token.address, storageSlot, preimage, receipt.txHash);

await token.methods.redeem_shield(recipientAddress, mintAmount, secret).send().wait();
expect(await token.methods.balance_of_private(recipientAddress).view()).toEqual(20n);
}, 30_000);
});
});
});

0 comments on commit 89e7c21

Please sign in to comment.