Skip to content

Commit

Permalink
more test info
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Nov 3, 2023
1 parent d707d4e commit b6c887f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 15 deletions.
23 changes: 17 additions & 6 deletions yarn-project/aztec.js/src/contract/sent_tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ export type WaitOpts = {
* If false, then any queries that depend on state set by this transaction may return stale data. Defaults to true.
**/
waitForNotesSync?: boolean;
/** Whether newly created notes should be included in the receipt. */
getNotes?: boolean;
/** Whether to include information useful for testing in the receipt. */
test?: boolean;
};

const DefaultWaitOpts: WaitOpts = {
timeout: 60,
interval: 1,
waitForNotesSync: true,
getNotes: false,
test: false,
};

/**
Expand Down Expand Up @@ -61,14 +61,25 @@ export class SentTx {
* @returns The transaction receipt.
*/
public async wait(opts?: WaitOpts): Promise<FieldsOf<TxReceipt>> {
if (opts?.getNotes && opts.waitForNotesSync === false) {
if (opts?.test && opts.waitForNotesSync === false) {
throw new Error('Cannot set getNotes to true if waitForNotesSync is false');
}
const receipt = await this.waitForReceipt(opts);
if (receipt.status !== TxStatus.MINED)
throw new Error(`Transaction ${await this.getTxHash()} was ${receipt.status}`);
if (opts?.getNotes) {
receipt.visibleNotes = await this.pxe.getNotes({ txHash: await this.getTxHash() });
if (opts?.test) {
const txHash = await this.getTxHash();
const tx = (await this.pxe.getTx(txHash))!;
const visibleNotes = await this.pxe.getNotes({ txHash });
receipt.testInfo = {
newCommitments: tx.newCommitments,
newNullifiers: tx.newNullifiers,
newPublicDataWrites: tx.newPublicDataWrites,
newL2ToL1Msgs: tx.newL2ToL1Msgs,
newContracts: tx.newContracts,
newContractData: tx.newContractData,
visibleNotes,
};
}
return receipt;
}
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/end-to-end/src/e2e_token_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ describe('e2e_token_contract', () => {
it('redeem as recipient', async () => {
await addPendingShieldNoteToPXE(0, amount, secretHash, txHash);
const txClaim = asset.methods.redeem_shield(accounts[0].address, amount, secret).send();
const receiptClaim = await txClaim.wait({ getNotes: true });
const receiptClaim = await txClaim.wait({ test: true });
expect(receiptClaim.status).toBe(TxStatus.MINED);
tokenSim.redeemShield(accounts[0].address, amount);
// 1 note should be created containing `amount` of tokens
const notes = receiptClaim.visibleNotes!;
expect(notes.length).toBe(1);
expect(notes[0].note.items[0].toBigInt()).toBe(amount);
const {visibleNotes} = receiptClaim.testInfo!;
expect(visibleNotes.length).toBe(1);
expect(visibleNotes[0].note.items[0].toBigInt()).toBe(amount);
});
});

Expand Down
45 changes: 40 additions & 5 deletions yarn-project/types/src/tx/tx_receipt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { ExtendedNote, TxHash } from '@aztec/types';
import { Fr } from '@aztec/foundation/fields';
import { ContractData, ExtendedNote, PublicDataWrite, TxHash } from '@aztec/types';

/**
* Possible status of a transaction.
Expand Down Expand Up @@ -41,11 +42,9 @@ export class TxReceipt {
*/
public contractAddress?: AztecAddress,
/**
* Notes created in this tx which belong to accounts which are registered in the PXE which was used to submit the
* tx. You will not receive notes of accounts which are not registered in the PXE here even though they were
* created in this tx.
* Information useful for testing, set when test flag is set to true in `waitOpts`.
*/
public visibleNotes?: ExtendedNote[],
public testInfo?: TestInfo,
) {}

/**
Expand Down Expand Up @@ -78,3 +77,39 @@ export class TxReceipt {
return new TxReceipt(txHash, status, error, blockHash, blockNumber, contractAddress);
}
}

/**
* Information useful for testing purposes included in the receipt when the test flag is set to true in `WaitOpts`.
*/
interface TestInfo {
/**
* New commitments created by the transaction.
*/
newCommitments: Fr[];
/**
* New nullifiers created by the transaction.
*/
newNullifiers: Fr[];
/**
* New public data writes created by the transaction.
*/
newPublicDataWrites: PublicDataWrite[];
/**
* New L2 to L1 messages created by the transaction.
*/
newL2ToL1Msgs: Fr[];
/**
* New contracts leafs created by the transaction to be inserted into the contract tree.
*/
newContracts: Fr[];
/**
* New contract data created by the transaction.
*/
newContractData: ContractData[];
/**
* Notes created in this tx which belong to accounts which are registered in the PXE which was used to submit the
* tx. You will not receive notes of accounts which are not registered in the PXE here even though they were
* created in this tx.
*/
visibleNotes: ExtendedNote[];
}

0 comments on commit b6c887f

Please sign in to comment.