From 89e7c2172ee0db4929a9d2d64a570dae250f85da Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Fri, 27 Oct 2023 14:38:30 -0300 Subject: [PATCH] chore: Fix dapp_testing e2e race condition (#3094) 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. --- .../src/guides/dapp_testing.test.ts | 80 +++++++++---------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/yarn-project/end-to-end/src/guides/dapp_testing.test.ts b/yarn-project/end-to-end/src/guides/dapp_testing.test.ts index 92d3ed69e26..b4a5c583b85 100644 --- a/yarn-project/end-to-end/src/guides/dapp_testing.test.ts +++ b/yarn-project/end-to-end/src/guides/dapp_testing.test.ts @@ -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; - 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); @@ -257,4 +217,44 @@ describe('guides/dapp/testing', () => { }); }); }); + + describe('on in-proc sandbox', () => { + describe('token contract', () => { + let pxe: PXE; + let stop: () => Promise; + 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); + }); + }); });