Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
});