From b2e3360d69c99d297a7c07eff9cbaa91ba65b156 Mon Sep 17 00:00:00 2001 From: benesjan Date: Mon, 11 Nov 2024 19:45:25 +0000 Subject: [PATCH] WIP --- .../end-to-end/src/e2e_fees/fees_test.ts | 20 ------ .../src/e2e_fees/private_payments.test.ts | 71 +++++++------------ .../src/e2e_prover/e2e_prover_test.ts | 16 ----- .../e2e_token_contract/token_contract_test.ts | 24 +------ 4 files changed, 28 insertions(+), 103 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_fees/fees_test.ts b/yarn-project/end-to-end/src/e2e_fees/fees_test.ts index aa930a1a56ec..fad11c793691 100644 --- a/yarn-project/end-to-end/src/e2e_fees/fees_test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/fees_test.ts @@ -4,12 +4,8 @@ import { type AztecAddress, type AztecNode, type DebugLogger, - ExtendedNote, - Fr, - Note, type PXE, SignerlessWallet, - type TxHash, createDebugLogger, sleep, } from '@aztec/aztec.js'; @@ -126,22 +122,6 @@ export class FeesTest { expect(balanceAfter).toEqual(balanceBefore + amount); } - /** Adds a pending shield transparent node for the banana coin token contract to the pxe. */ - // TODO(benesjan): nuke this - async addPendingShieldNoteToPXE(owner: AztecAddress | AccountWallet, amount: bigint, secretHash: Fr, txHash: TxHash) { - const note = new Note([new Fr(amount), secretHash]); - const ownerAddress = 'getAddress' in owner ? owner.getAddress() : owner; - const extendedNote = new ExtendedNote( - note, - ownerAddress, - this.bananaCoin.address, - BananaCoin.storage.pending_shields.slot, - BananaCoin.notes.TransparentNote.id, - txHash, - ); - await this.pxe.addNote(extendedNote, ownerAddress); - } - public async applyBaseSnapshots() { await this.applyInitialAccountsSnapshot(); await this.applyPublicDeployAccountsSnapshot(); diff --git a/yarn-project/end-to-end/src/e2e_fees/private_payments.test.ts b/yarn-project/end-to-end/src/e2e_fees/private_payments.test.ts index bf9fdb65ba80..870f40707c99 100644 --- a/yarn-project/end-to-end/src/e2e_fees/private_payments.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/private_payments.test.ts @@ -1,12 +1,4 @@ -import { - type AccountWallet, - type AztecAddress, - BatchCall, - Fr, - PrivateFeePaymentMethod, - computeSecretHash, - sleep, -} from '@aztec/aztec.js'; +import { type AccountWallet, type AztecAddress, BatchCall, PrivateFeePaymentMethod, sleep } from '@aztec/aztec.js'; import { type GasSettings } from '@aztec/circuits.js'; import { type TokenContract as BananaCoin, FPCContract } from '@aztec/noir-contracts.js'; @@ -179,8 +171,8 @@ describe('e2e_fees private_payment', () => { * BC increase total supply * * PUBLIC TEARDOWN - * increase sequencer/fee recipient/FPC admin private banana balance by feeAmount by finalizing partial note - * increase Alice's private banana balance by feeAmount by finalizing partial note + * increase sequencer/fee recipient/FPC admin private banana balance by feeAmount by finalizing partial note + * increase Alice's private banana balance by feeAmount by finalizing partial note */ const newlyMintedBananas = 10n; const from = aliceAddress; // we are setting from to Alice here because of TODO(#9887) @@ -221,23 +213,20 @@ describe('e2e_fees private_payment', () => { * setup fee and refund partial notes * setup public teardown call * - * * PRIVATE APP LOGIC - * N/A + * a partial note is prepared * * PUBLIC APP LOGIC * BC decrease Alice public balance by shieldedBananas - * BC create transparent note of shieldedBananas + * BC finalizes the partial note with an amount --> this is where the note is created in public * * PUBLIC TEARDOWN - * increase sequencer/fee recipient/FPC admin private banana balance by feeAmount by finalizing partial note - * increase Alice's private banana balance by feeAmount by finalizing partial note + * increase sequencer/fee recipient/FPC admin private banana balance by feeAmount by finalizing partial note + * increase Alice's private banana balance by feeAmount by finalizing partial note */ - const shieldedBananas = 1n; - const shieldSecret = Fr.random(); - const shieldSecretHash = computeSecretHash(shieldSecret); + const amountTransferredToPrivate = 1n; const tx = await bananaCoin.methods - .shield(aliceAddress, shieldedBananas, shieldSecretHash, 0n) + .transfer_to_private(aliceAddress, amountTransferredToPrivate) .send({ fee: { gasSettings, @@ -256,30 +245,27 @@ describe('e2e_fees private_payment', () => { await expectMapping( t.getBananaPrivateBalanceFn, [aliceAddress, bananaFPC.address, sequencerAddress], - [initialAlicePrivateBananas - feeAmount, 0n, initialSequencerPrivateBananas + feeAmount], + [ + initialAlicePrivateBananas - feeAmount + amountTransferredToPrivate, + 0n, + initialSequencerPrivateBananas + feeAmount, + ], ); await expectMapping( t.getBananaPublicBalanceFn, [aliceAddress, bananaFPC.address, sequencerAddress], - [initialAlicePublicBananas - shieldedBananas, initialFPCPublicBananas, 0n], + [initialAlicePublicBananas - amountTransferredToPrivate, initialFPCPublicBananas, 0n], ); await expectMapping( t.getGasBalanceFn, [aliceAddress, bananaFPC.address, sequencerAddress], [initialAliceGas, initialFPCGas - feeAmount, initialSequencerGas], ); - - await expect( - t.addPendingShieldNoteToPXE(t.aliceWallet, shieldedBananas, shieldSecretHash, tx.txHash), - ).resolves.toBeUndefined(); }); it('pays fees for tx that creates notes in both private and public', async () => { - const privateTransfer = 1n; - const shieldedBananas = 1n; - const shieldSecret = Fr.random(); - const shieldSecretHash = computeSecretHash(shieldSecret); - + const amountTransferredInPrivate = 1n; + const amountTransferredToPrivate = 2n; /** * PRIVATE SETUP * check authwit @@ -290,18 +276,19 @@ describe('e2e_fees private_payment', () => { * PRIVATE APP LOGIC * reduce Alice's private balance by privateTransfer * create note for Bob with privateTransfer amount of private BC + * prepare partial note (in the transfer to private) * * PUBLIC APP LOGIC - * BC decrease Alice public balance by shieldedBananas - * BC create transparent note of shieldedBananas + * BC decrease Alice public balance by amountTransferredToPrivate + * BC finalize partial note with amountTransferredToPrivate (this is where the note is created in public) * * PUBLIC TEARDOWN - * increase sequencer/fee recipient/FPC admin private banana balance by feeAmount by finalizing partial note - * increase Alice's private banana balance by feeAmount by finalizing partial note + * increase sequencer/fee recipient/FPC admin private banana balance by feeAmount by finalizing partial note + * increase Alice's private banana balance by feeAmount by finalizing partial note */ const tx = await new BatchCall(aliceWallet, [ - bananaCoin.methods.transfer(bobAddress, privateTransfer).request(), - bananaCoin.methods.shield(aliceAddress, shieldedBananas, shieldSecretHash, 0n).request(), + bananaCoin.methods.transfer(bobAddress, amountTransferredInPrivate).request(), + bananaCoin.methods.transfer_to_private(aliceAddress, amountTransferredToPrivate).request(), ]) .send({ fee: { @@ -322,8 +309,8 @@ describe('e2e_fees private_payment', () => { t.getBananaPrivateBalanceFn, [aliceAddress, bobAddress, bananaFPC.address, sequencerAddress], [ - initialAlicePrivateBananas - feeAmount - privateTransfer, - initialBobPrivateBananas + privateTransfer, + initialAlicePrivateBananas - feeAmount - amountTransferredInPrivate + amountTransferredToPrivate, + initialBobPrivateBananas + amountTransferredInPrivate, 0n, initialSequencerPrivateBananas + feeAmount, ], @@ -331,17 +318,13 @@ describe('e2e_fees private_payment', () => { await expectMapping( t.getBananaPublicBalanceFn, [aliceAddress, bananaFPC.address, sequencerAddress], - [initialAlicePublicBananas - shieldedBananas, initialFPCPublicBananas, 0n], + [initialAlicePublicBananas - amountTransferredToPrivate, initialFPCPublicBananas, 0n], ); await expectMapping( t.getGasBalanceFn, [aliceAddress, bananaFPC.address, sequencerAddress], [initialAliceGas, initialFPCGas - feeAmount, initialSequencerGas], ); - - await expect( - t.addPendingShieldNoteToPXE(t.aliceWallet, shieldedBananas, shieldSecretHash, tx.txHash), - ).resolves.toBeUndefined(); }); it('rejects txs that dont have enough balance to cover gas costs', async () => { diff --git a/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts b/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts index ec66244d93b9..2df25d15ab6d 100644 --- a/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts +++ b/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts @@ -8,12 +8,9 @@ import { type DebugLogger, type DeployL1Contracts, EthAddress, - ExtendedNote, type Fq, Fr, - Note, type PXE, - type TxHash, createDebugLogger, deployL1Contract, } from '@aztec/aztec.js'; @@ -327,19 +324,6 @@ export class FullProverTest { await this.acvmConfigCleanup?.(); } - async addPendingShieldNoteToPXE(accountIndex: number, amount: bigint, secretHash: Fr, txHash: TxHash) { - const note = new Note([new Fr(amount), secretHash]); - const extendedNote = new ExtendedNote( - note, - this.accounts[accountIndex].address, - this.fakeProofsAsset.address, - TokenContract.storage.pending_shields.slot, - TokenContract.notes.TransparentNote.id, - txHash, - ); - await this.wallets[accountIndex].addNote(extendedNote); - } - async applyMintSnapshot() { await this.snapshotManager.snapshot( 'mint', diff --git a/yarn-project/end-to-end/src/e2e_token_contract/token_contract_test.ts b/yarn-project/end-to-end/src/e2e_token_contract/token_contract_test.ts index 4765930993b7..9d1d76123bc8 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/token_contract_test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/token_contract_test.ts @@ -1,14 +1,5 @@ import { getSchnorrAccount } from '@aztec/accounts/schnorr'; -import { - type AccountWallet, - type CompleteAddress, - type DebugLogger, - ExtendedNote, - Fr, - Note, - type TxHash, - createDebugLogger, -} from '@aztec/aztec.js'; +import { type AccountWallet, type CompleteAddress, type DebugLogger, createDebugLogger } from '@aztec/aztec.js'; import { DocsExampleContract, TokenContract } from '@aztec/noir-contracts.js'; import { jest } from '@jest/globals'; @@ -123,19 +114,6 @@ export class TokenContractTest { await this.snapshotManager.teardown(); } - async addPendingShieldNoteToPXE(accountIndex: number, amount: bigint, secretHash: Fr, txHash: TxHash) { - const note = new Note([new Fr(amount), secretHash]); - const extendedNote = new ExtendedNote( - note, - this.accounts[accountIndex].address, - this.asset.address, - TokenContract.storage.pending_shields.slot, - TokenContract.notes.TransparentNote.id, - txHash, - ); - await this.wallets[accountIndex].addNote(extendedNote); - } - async applyMintSnapshot() { await this.snapshotManager.snapshot( 'mint',