From a7354dc7e7642b4a4a9ea9ee015242a83ef00cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bene=C5=A1?= Date: Mon, 6 Nov 2023 11:53:18 +0100 Subject: [PATCH] feat: more test info in tx receipt (#3221) Fixes #3218 --- yarn-project/aztec.js/src/contract/sent_tx.ts | 23 +++++++--- .../end-to-end/src/e2e_token_contract.test.ts | 8 ++-- yarn-project/types/src/tx/tx_receipt.ts | 46 +++++++++++++++++-- 3 files changed, 62 insertions(+), 15 deletions(-) diff --git a/yarn-project/aztec.js/src/contract/sent_tx.ts b/yarn-project/aztec.js/src/contract/sent_tx.ts index 90849963a2f..9c52a6418a7 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.ts @@ -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 debugging/testing in the receipt. */ + debug?: boolean; }; const DefaultWaitOpts: WaitOpts = { timeout: 60, interval: 1, waitForNotesSync: true, - getNotes: false, + debug: false, }; /** @@ -61,14 +61,25 @@ export class SentTx { * @returns The transaction receipt. */ public async wait(opts?: WaitOpts): Promise> { - if (opts?.getNotes && opts.waitForNotesSync === false) { + if (opts?.debug && 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?.debug) { + const txHash = await this.getTxHash(); + const tx = (await this.pxe.getTx(txHash))!; + const visibleNotes = await this.pxe.getNotes({ txHash }); + receipt.debugInfo = { + newCommitments: tx.newCommitments, + newNullifiers: tx.newNullifiers, + newPublicDataWrites: tx.newPublicDataWrites, + newL2ToL1Msgs: tx.newL2ToL1Msgs, + newContracts: tx.newContracts, + newContractData: tx.newContractData, + visibleNotes, + }; } return receipt; } diff --git a/yarn-project/end-to-end/src/e2e_token_contract.test.ts b/yarn-project/end-to-end/src/e2e_token_contract.test.ts index 327b781cdd5..009e276095d 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract.test.ts @@ -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({ debug: 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.debugInfo!; + expect(visibleNotes.length).toBe(1); + expect(visibleNotes[0].note.items[0].toBigInt()).toBe(amount); }); }); diff --git a/yarn-project/types/src/tx/tx_receipt.ts b/yarn-project/types/src/tx/tx_receipt.ts index bcde7d35d35..dbd71233aea 100644 --- a/yarn-project/types/src/tx/tx_receipt.ts +++ b/yarn-project/types/src/tx/tx_receipt.ts @@ -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. @@ -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/debugging, set when test flag is set to true in `waitOpts`. */ - public visibleNotes?: ExtendedNote[], + public debugInfo?: DebugInfo, ) {} /** @@ -78,3 +77,40 @@ export class TxReceipt { return new TxReceipt(txHash, status, error, blockHash, blockNumber, contractAddress); } } + +/** + * Information useful for debugging/testing purposes included in the receipt when the debug flag is set to true + * in `WaitOpts`. + */ +interface DebugInfo { + /** + * 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[]; +}