From 3d2cf528c2844fe9ce4cc3c47c60518e9d2ba8ed Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 3 Nov 2023 13:44:28 +0000 Subject: [PATCH 1/4] more test info --- 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 | 45 ++++++++++++++++--- 3 files changed, 61 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 90849963a2fd..b65e94c5fab1 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 testing in the receipt. */ + test?: boolean; }; const DefaultWaitOpts: WaitOpts = { timeout: 60, interval: 1, waitForNotesSync: true, - getNotes: false, + test: 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?.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; } 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 327b781cdd5e..c7bf820c16d4 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({ 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); }); }); diff --git a/yarn-project/types/src/tx/tx_receipt.ts b/yarn-project/types/src/tx/tx_receipt.ts index bcde7d35d35f..bc4f02dbd5e3 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, set when test flag is set to true in `waitOpts`. */ - public visibleNotes?: ExtendedNote[], + public testInfo?: TestInfo, ) {} /** @@ -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[]; +} From 964585b47b6801c618fc7d80b23851b64335a008 Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 3 Nov 2023 14:02:19 +0000 Subject: [PATCH 2/4] formatting --- yarn-project/end-to-end/src/e2e_token_contract.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c7bf820c16d4..b4ff285522d0 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 @@ -176,7 +176,7 @@ describe('e2e_token_contract', () => { expect(receiptClaim.status).toBe(TxStatus.MINED); tokenSim.redeemShield(accounts[0].address, amount); // 1 note should be created containing `amount` of tokens - const {visibleNotes} = receiptClaim.testInfo!; + const { visibleNotes } = receiptClaim.testInfo!; expect(visibleNotes.length).toBe(1); expect(visibleNotes[0].note.items[0].toBigInt()).toBe(amount); }); From 0b51791a21a775fe7675220b1f2213bc4ef07e19 Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 3 Nov 2023 19:46:19 +0000 Subject: [PATCH 3/4] naming --- yarn-project/aztec.js/src/contract/sent_tx.ts | 12 ++++++------ .../end-to-end/src/e2e_token_contract.test.ts | 4 ++-- yarn-project/types/src/tx/tx_receipt.ts | 7 ++++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/yarn-project/aztec.js/src/contract/sent_tx.ts b/yarn-project/aztec.js/src/contract/sent_tx.ts index b65e94c5fab1..9c52a6418a75 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 to include information useful for testing in the receipt. */ - test?: boolean; + /** Whether to include information useful for debugging/testing in the receipt. */ + debug?: boolean; }; const DefaultWaitOpts: WaitOpts = { timeout: 60, interval: 1, waitForNotesSync: true, - test: false, + debug: false, }; /** @@ -61,17 +61,17 @@ export class SentTx { * @returns The transaction receipt. */ public async wait(opts?: WaitOpts): Promise> { - if (opts?.test && 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?.test) { + if (opts?.debug) { const txHash = await this.getTxHash(); const tx = (await this.pxe.getTx(txHash))!; const visibleNotes = await this.pxe.getNotes({ txHash }); - receipt.testInfo = { + receipt.debugInfo = { newCommitments: tx.newCommitments, newNullifiers: tx.newNullifiers, newPublicDataWrites: tx.newPublicDataWrites, 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 b4ff285522d0..009e276095d2 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,11 +172,11 @@ 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({ test: 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 { visibleNotes } = receiptClaim.testInfo!; + 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 bc4f02dbd5e3..0e6cd50a9ec3 100644 --- a/yarn-project/types/src/tx/tx_receipt.ts +++ b/yarn-project/types/src/tx/tx_receipt.ts @@ -44,7 +44,7 @@ export class TxReceipt { /** * Information useful for testing, set when test flag is set to true in `waitOpts`. */ - public testInfo?: TestInfo, + public debugInfo?: DebugInfo, ) {} /** @@ -79,9 +79,10 @@ export class TxReceipt { } /** - * Information useful for testing purposes included in the receipt when the test flag is set to true in `WaitOpts`. + * Information useful for debugging/testing purposes included in the receipt when the debug flag is set to true + * in `WaitOpts`. */ -interface TestInfo { +interface DebugInfo { /** * New commitments created by the transaction. */ From 930cff563923533d79f732c6d0c2c1b6395c1f08 Mon Sep 17 00:00:00 2001 From: benesjan Date: Mon, 6 Nov 2023 08:11:27 +0000 Subject: [PATCH 4/4] fix --- yarn-project/types/src/tx/tx_receipt.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/types/src/tx/tx_receipt.ts b/yarn-project/types/src/tx/tx_receipt.ts index 0e6cd50a9ec3..dbd71233aea3 100644 --- a/yarn-project/types/src/tx/tx_receipt.ts +++ b/yarn-project/types/src/tx/tx_receipt.ts @@ -42,7 +42,7 @@ export class TxReceipt { */ public contractAddress?: AztecAddress, /** - * Information useful for testing, set when test flag is set to true in `waitOpts`. + * Information useful for testing/debugging, set when test flag is set to true in `waitOpts`. */ public debugInfo?: DebugInfo, ) {}