From 27d5c76ac49e2d1c737ec81bee396ca4ffc27c45 Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Fri, 8 Sep 2023 14:16:50 -0300 Subject: [PATCH] feat: Remove entrypoint collection --- .../src/examples/private_token_contract.ts | 29 ++--- .../examples/uniswap_trade_on_l1_from_l2.ts | 22 ++-- .../auth_witness_account_entrypoint.ts | 13 +-- .../entrypoint/entrypoint_collection.ts | 51 --------- .../aztec.js/src/account/entrypoint/index.ts | 12 +- .../single_key_account_entrypoint.ts | 11 +- .../stored_key_account_entrypoint.ts | 11 +- .../aztec.js/src/aztec_rpc_client/wallet.ts | 18 +-- .../src/contract/base_contract_interaction.ts | 5 - .../aztec.js/src/contract/batch_call.ts | 7 +- .../aztec.js/src/contract/contract.test.ts | 6 +- .../aztec.js/src/contract/contract_base.ts | 16 ++- .../contract/contract_function_interaction.ts | 5 +- .../contract_deployer.test.ts | 4 +- yarn-project/aztec.js/src/sandbox/index.ts | 18 +-- yarn-project/aztec.js/src/utils/account.ts | 107 +++++------------- .../canary/src/aztec_js_browser.test.ts | 14 +-- .../src/uniswap_trade_on_l1_from_l2.test.ts | 12 +- yarn-project/cli/src/index.ts | 10 +- .../end-to-end/src/e2e_2_rpc_servers.test.ts | 27 ++--- .../src/e2e_aztec_js_browser.test.ts | 15 ++- .../end-to-end/src/e2e_cheat_codes.test.ts | 11 +- .../src/e2e_cross_chain_messaging.test.ts | 2 +- .../src/e2e_escrow_contract.test.ts | 18 ++- .../src/e2e_lending_contract.test.ts | 44 ++++--- .../end-to-end/src/e2e_multi_transfer.test.ts | 8 +- .../e2e_multiple_accounts_1_enc_key.test.ts | 2 +- .../src/e2e_nested_contract.test.ts | 21 ++-- .../src/e2e_non_contract_account.test.ts | 5 +- .../e2e_pending_commitments_contract.test.ts | 18 ++- .../src/e2e_private_token_contract.test.ts | 4 +- .../e2e_public_cross_chain_messaging.test.ts | 2 +- .../src/e2e_public_token_contract.test.ts | 4 +- .../src/e2e_sandbox_example.test.ts | 2 +- .../src/fixtures/cross_chain_test_harness.ts | 18 +-- yarn-project/end-to-end/src/fixtures/utils.ts | 97 ++++------------ .../writing_an_account_contract.test.ts | 8 +- .../src/integration_archiver_l1_to_l2.test.ts | 2 +- .../src/uniswap_trade_on_l1_from_l2.test.ts | 2 +- 39 files changed, 221 insertions(+), 460 deletions(-) delete mode 100644 yarn-project/aztec.js/src/account/entrypoint/entrypoint_collection.ts diff --git a/yarn-project/aztec-sandbox/src/examples/private_token_contract.ts b/yarn-project/aztec-sandbox/src/examples/private_token_contract.ts index 6a5dd3e0fce..d637d02d710 100644 --- a/yarn-project/aztec-sandbox/src/examples/private_token_contract.ts +++ b/yarn-project/aztec-sandbox/src/examples/private_token_contract.ts @@ -1,14 +1,13 @@ import { + AccountWallet, AztecAddress, Contract, - Fr, GrumpkinScalar, - Wallet, - createAccounts, createAztecRpcClient, + createRecipient, + getUnsafeSchnorrAccount, } from '@aztec/aztec.js'; import { createDebugLogger } from '@aztec/foundation/log'; -import { SchnorrSingleKeyAccountContractAbi } from '@aztec/noir-contracts/artifacts'; import { PrivateTokenContract } from '@aztec/noir-contracts/types'; const logger = createDebugLogger('aztec:http-rpc-client'); @@ -18,7 +17,7 @@ export const privateKey = GrumpkinScalar.fromString('ac0974bec39a17e36ba4a6b4d23 const url = 'http://localhost:8080'; const aztecRpcClient = createAztecRpcClient(url); -let wallet: Wallet; +let wallet: AccountWallet; const INITIAL_BALANCE = 333n; const SECONDARY_AMOUNT = 33n; @@ -30,10 +29,7 @@ const SECONDARY_AMOUNT = 33n; */ async function deployZKContract(owner: AztecAddress) { logger('Deploying L2 contract...'); - const tx = PrivateTokenContract.deploy(aztecRpcClient, INITIAL_BALANCE, owner).send(); - const receipt = await tx.getReceipt(); - const contract = await PrivateTokenContract.at(receipt.contractAddress!, wallet); - await tx.isMined(); + const contract = await PrivateTokenContract.deploy(aztecRpcClient, INITIAL_BALANCE, owner).send().deployed(); logger('L2 contract deployed'); return contract; } @@ -54,10 +50,9 @@ async function getBalance(contract: Contract, ownerAddress: AztecAddress) { async function main() { logger('Running ZK contract test on HTTP interface.'); - wallet = await createAccounts(aztecRpcClient, SchnorrSingleKeyAccountContractAbi, privateKey, Fr.random(), 2); - const accounts = await aztecRpcClient.getAccounts(); - const [owner, account2] = accounts; - logger(`Created ${accounts.length} accounts`); + wallet = await getUnsafeSchnorrAccount(aztecRpcClient, privateKey).waitDeploy(); + const owner = wallet.getCompleteAddress(); + const recipient = await createRecipient(aztecRpcClient); logger(`Created Owner account ${owner.toString()}`); @@ -67,17 +62,15 @@ async function main() { // Mint more tokens logger(`Minting ${SECONDARY_AMOUNT} more coins`); - const mintTx = zkContract.methods.mint(SECONDARY_AMOUNT, owner.address).send({ origin: owner.address }); - await mintTx.isMined({ interval: 0.5 }); + await zkContract.methods.mint(SECONDARY_AMOUNT, owner.address).send().wait({ interval: 0.5 }); const balanceAfterMint = await getBalance(zkContract, owner.address); logger(`Owner's balance is now: ${balanceAfterMint}`); // Perform a transfer logger(`Transferring ${SECONDARY_AMOUNT} tokens from owner to another account.`); - const transferTx = zkContract.methods.transfer(SECONDARY_AMOUNT, account2.address).send({ origin: owner.address }); - await transferTx.isMined({ interval: 0.5 }); + await zkContract.methods.transfer(SECONDARY_AMOUNT, recipient.address).send().wait({ interval: 0.5 }); const balanceAfterTransfer = await getBalance(zkContract, owner.address); - const receiverBalance = await getBalance(zkContract, account2.address); + const receiverBalance = await getBalance(zkContract, recipient.address); logger(`Owner's balance is now ${balanceAfterTransfer}`); logger(`The transfer receiver's balance is ${receiverBalance}`); } diff --git a/yarn-project/aztec-sandbox/src/examples/uniswap_trade_on_l1_from_l2.ts b/yarn-project/aztec-sandbox/src/examples/uniswap_trade_on_l1_from_l2.ts index ea2d7b73e18..72fd032da4a 100644 --- a/yarn-project/aztec-sandbox/src/examples/uniswap_trade_on_l1_from_l2.ts +++ b/yarn-project/aztec-sandbox/src/examples/uniswap_trade_on_l1_from_l2.ts @@ -1,17 +1,17 @@ import { + AccountWallet, AztecAddress, EthAddress, Fr, - Wallet, computeMessageSecretHash, - createAccounts, createAztecRpcClient, + createRecipient, getL1ContractAddresses, + getUnsafeSchnorrAccount, } from '@aztec/aztec.js'; import { GrumpkinScalar } from '@aztec/circuits.js'; import { createDebugLogger } from '@aztec/foundation/log'; import { UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts'; -import { SchnorrSingleKeyAccountContractAbi } from '@aztec/noir-contracts/artifacts'; import { NonNativeTokenContract, UniswapContract } from '@aztec/noir-contracts/types'; import { AztecRPC, TxStatus } from '@aztec/types'; @@ -56,7 +56,7 @@ if (Number(await publicClient.getBlockNumber()) < EXPECTED_FORKED_BLOCK) { const ethAccount = EthAddress.fromString((await walletClient.getAddresses())[0]); const aztecRpcClient = createAztecRpcClient(aztecRpcUrl); -let wallet: Wallet; +let wallet: AccountWallet; /** * Deploys all l1 / l2 contracts @@ -153,7 +153,7 @@ const transferWethOnL2 = async ( receiver: AztecAddress, transferAmount: bigint, ) => { - const transferTx = wethL2Contract.methods.transfer(transferAmount, receiver).send({ origin: ownerAddress }); + const transferTx = wethL2Contract.methods.transfer(transferAmount, receiver).send(); await transferTx.isMined({ interval: 0.5 }); const transferReceipt = await transferTx.getReceipt(); // expect(transferReceipt.status).toBe(TxStatus.MINED); @@ -166,9 +166,9 @@ const transferWethOnL2 = async ( async function main() { logger('Running L1/L2 messaging test on HTTP interface.'); - wallet = await createAccounts(aztecRpcClient, SchnorrSingleKeyAccountContractAbi, privateKey!, Fr.random(), 2); - const accounts = await wallet.getAccounts(); - const [owner, receiver] = accounts; + wallet = await getUnsafeSchnorrAccount(aztecRpcClient, privateKey).waitDeploy(); + const owner = wallet.getCompleteAddress(); + const receiver = await createRecipient(aztecRpcClient); const result = await deployAllContracts(owner.address); const { @@ -220,7 +220,7 @@ async function main() { // Call the mint tokens function on the noir contract const consumptionTx = wethL2Contract.methods .mint(wethAmountToBridge, owner.address, messageKey, secret, ethAccount.toField()) - .send({ origin: owner.address }); + .send(); await consumptionTx.isMined({ interval: 0.5 }); const consumptionReceipt = await consumptionTx.getReceipt(); // expect(consumptionReceipt.status).toBe(TxStatus.MINED); @@ -250,7 +250,7 @@ async function main() { ethAccount.toField(), ethAccount.toField(), ) - .send({ origin: owner.address }); + .send(); await withdrawTx.isMined({ interval: 0.5 }); const withdrawReceipt = await withdrawTx.getReceipt(); // expect(withdrawReceipt.status).toBe(TxStatus.MINED); @@ -301,7 +301,7 @@ async function main() { // Call the mint tokens function on the noir contract const daiMintTx = daiL2Contract.methods .mint(daiAmountToBridge, owner.address, depositDaiMessageKey, secret, ethAccount.toField()) - .send({ origin: owner.address }); + .send(); await daiMintTx.isMined({ interval: 0.5 }); const daiMintTxReceipt = await daiMintTx.getReceipt(); // expect(daiMintTxReceipt.status).toBe(TxStatus.MINED); diff --git a/yarn-project/aztec.js/src/account/entrypoint/auth_witness_account_entrypoint.ts b/yarn-project/aztec.js/src/account/entrypoint/auth_witness_account_entrypoint.ts index a92b7194887..e8067d57585 100644 --- a/yarn-project/aztec.js/src/account/entrypoint/auth_witness_account_entrypoint.ts +++ b/yarn-project/aztec.js/src/account/entrypoint/auth_witness_account_entrypoint.ts @@ -7,7 +7,7 @@ import SchnorrAuthWitnessAccountContractAbi from '../../abis/schnorr_auth_witnes import { generatePublicKey } from '../../index.js'; import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from '../../utils/defaults.js'; import { buildPayload, hashPayload } from './entrypoint_payload.js'; -import { CreateTxRequestOpts, Entrypoint } from './index.js'; +import { Entrypoint } from './index.js'; /** * Account contract implementation that uses a single key for signing and encryption. This public key is not @@ -59,10 +59,7 @@ export class AuthWitnessAccountEntrypoint implements Entrypoint { * @param opts - The options * @returns The TxRequest, the auth witness to insert in db and the message signed */ - async createTxExecutionRequestWithWitness( - executions: FunctionCall[], - opts: CreateTxRequestOpts = {}, - ): Promise<{ + async createTxExecutionRequestWithWitness(executions: FunctionCall[]): Promise<{ /** The transaction request */ txRequest: TxExecutionRequest; /** The auth witness */ @@ -70,10 +67,6 @@ export class AuthWitnessAccountEntrypoint implements Entrypoint { /** The message signed */ message: Buffer; }> { - if (opts.origin && !opts.origin.equals(this.address)) { - throw new Error(`Sender ${opts.origin.toString()} does not match account address ${this.address.toString()}`); - } - const { payload, packedArguments: callsPackedArguments } = await buildPayload(executions); const message = await hashPayload(payload); const witness = await this.createAuthWitness(message); @@ -92,7 +85,7 @@ export class AuthWitnessAccountEntrypoint implements Entrypoint { return { txRequest, message, witness }; } - createTxExecutionRequest(executions: FunctionCall[], _opts: CreateTxRequestOpts = {}): Promise { + createTxExecutionRequest(_executions: FunctionCall[]): Promise { throw new Error(`Not implemented, use createTxExecutionRequestWithWitness instead`); } diff --git a/yarn-project/aztec.js/src/account/entrypoint/entrypoint_collection.ts b/yarn-project/aztec.js/src/account/entrypoint/entrypoint_collection.ts deleted file mode 100644 index 1da44c3c766..00000000000 --- a/yarn-project/aztec.js/src/account/entrypoint/entrypoint_collection.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { AztecAddress } from '@aztec/circuits.js'; -import { FunctionCall, TxExecutionRequest } from '@aztec/types'; - -import { Account } from '../account.js'; -import { CreateTxRequestOpts, Entrypoint } from './index.js'; - -/** - * An entrypoint that groups together multiple concrete entrypoints. - * Delegates to the registered entrypoints based on the requested origin. - */ -export class EntrypointCollection implements Entrypoint { - private entrypoints: Map = new Map(); - - constructor(entrypoints: [AztecAddress, Entrypoint][] = []) { - for (const [key, value] of entrypoints) { - this.registerAccount(key, value); - } - } - - /** - * Creates a new instance out of a set of Accounts. - * @param accounts - Accounts to register in this entrypoint. - * @returns A new instance. - */ - static async fromAccounts(accounts: Account[]) { - const collection = new EntrypointCollection(); - for (const account of accounts) { - collection.registerAccount((await account.getCompleteAddress()).address, await account.getEntrypoint()); - } - return collection; - } - - /** - * Registers an entrypoint against an aztec address - * @param addr - The aztec address against which to register the implementation. - * @param impl - The entrypoint to be registered. - */ - public registerAccount(addr: AztecAddress, impl: Entrypoint) { - this.entrypoints.set(addr.toString(), impl); - } - - public createTxExecutionRequest( - executions: FunctionCall[], - opts: CreateTxRequestOpts = {}, - ): Promise { - const defaultAccount = this.entrypoints.values().next().value as Entrypoint; - const impl = opts.origin ? this.entrypoints.get(opts.origin.toString()) : defaultAccount; - if (!impl) throw new Error(`No entrypoint registered for ${opts.origin}`); - return impl.createTxExecutionRequest(executions, opts); - } -} diff --git a/yarn-project/aztec.js/src/account/entrypoint/index.ts b/yarn-project/aztec.js/src/account/entrypoint/index.ts index bd38032d428..d35b79d72bf 100644 --- a/yarn-project/aztec.js/src/account/entrypoint/index.ts +++ b/yarn-project/aztec.js/src/account/entrypoint/index.ts @@ -1,18 +1,10 @@ -import { AztecAddress } from '@aztec/circuits.js'; import { FunctionCall, TxExecutionRequest } from '@aztec/types'; -export * from './entrypoint_collection.js'; +export * from './auth_witness_account_entrypoint.js'; export * from './entrypoint_payload.js'; export * from './entrypoint_utils.js'; export * from './single_key_account_entrypoint.js'; export * from './stored_key_account_entrypoint.js'; -export * from './auth_witness_account_entrypoint.js'; - -/** Options for creating a tx request out of a set of function calls. */ -export type CreateTxRequestOpts = { - /** Origin of the tx. Needs to be an address managed by this account. */ - origin?: AztecAddress; -}; // docs:start:entrypoint-interface /** @@ -26,6 +18,6 @@ export interface Entrypoint { * @param opts - Options. * @returns The authenticated transaction execution request. */ - createTxExecutionRequest(executions: FunctionCall[], opts?: CreateTxRequestOpts): Promise; + createTxExecutionRequest(executions: FunctionCall[]): Promise; } // docs:end:entrypoint-interface diff --git a/yarn-project/aztec.js/src/account/entrypoint/single_key_account_entrypoint.ts b/yarn-project/aztec.js/src/account/entrypoint/single_key_account_entrypoint.ts index edd6943b445..85bc88ba909 100644 --- a/yarn-project/aztec.js/src/account/entrypoint/single_key_account_entrypoint.ts +++ b/yarn-project/aztec.js/src/account/entrypoint/single_key_account_entrypoint.ts @@ -7,7 +7,7 @@ import SchnorrSingleKeyAccountContractAbi from '../../abis/schnorr_single_key_ac import { generatePublicKey } from '../../index.js'; import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from '../../utils/defaults.js'; import { buildPayload, hashPayload } from './entrypoint_payload.js'; -import { CreateTxRequestOpts, Entrypoint } from './index.js'; +import { Entrypoint } from './index.js'; /** * Account contract implementation that uses a single key for signing and encryption. This public key is not @@ -23,14 +23,7 @@ export class SingleKeyAccountEntrypoint implements Entrypoint { private version: number = DEFAULT_VERSION, ) {} - async createTxExecutionRequest( - executions: FunctionCall[], - opts: CreateTxRequestOpts = {}, - ): Promise { - if (opts.origin && !opts.origin.equals(this.address)) { - throw new Error(`Sender ${opts.origin.toString()} does not match account address ${this.address.toString()}`); - } - + async createTxExecutionRequest(executions: FunctionCall[]): Promise { const { payload, packedArguments: callsPackedArguments } = await buildPayload(executions); const message = await hashPayload(payload); diff --git a/yarn-project/aztec.js/src/account/entrypoint/stored_key_account_entrypoint.ts b/yarn-project/aztec.js/src/account/entrypoint/stored_key_account_entrypoint.ts index 0d6f195df47..0c391306c49 100644 --- a/yarn-project/aztec.js/src/account/entrypoint/stored_key_account_entrypoint.ts +++ b/yarn-project/aztec.js/src/account/entrypoint/stored_key_account_entrypoint.ts @@ -7,7 +7,7 @@ import { FunctionCall, PackedArguments, TxExecutionRequest } from '@aztec/types' import EcdsaAccountContractAbi from '../../abis/ecdsa_account_contract.json' assert { type: 'json' }; import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from '../../utils/defaults.js'; import { buildPayload, hashPayload } from './entrypoint_payload.js'; -import { CreateTxRequestOpts, Entrypoint } from './index.js'; +import { Entrypoint } from './index.js'; /** * Account contract implementation that keeps a signing public key in storage, and is retrieved on @@ -25,14 +25,7 @@ export class StoredKeyAccountEntrypoint implements Entrypoint { this.log = createDebugLogger('aztec:client:accounts:stored_key'); } - async createTxExecutionRequest( - executions: FunctionCall[], - opts: CreateTxRequestOpts = {}, - ): Promise { - if (opts.origin && !opts.origin.equals(this.address)) { - throw new Error(`Sender ${opts.origin.toString()} does not match account address ${this.address.toString()}`); - } - + async createTxExecutionRequest(executions: FunctionCall[]): Promise { const { payload, packedArguments: callsPackedArguments } = await buildPayload(executions); const message = await hashPayload(payload); const signature = this.sign(message).toBuffer(); diff --git a/yarn-project/aztec.js/src/aztec_rpc_client/wallet.ts b/yarn-project/aztec.js/src/aztec_rpc_client/wallet.ts index 7b7df529c0c..83f49162064 100644 --- a/yarn-project/aztec.js/src/aztec_rpc_client/wallet.ts +++ b/yarn-project/aztec.js/src/aztec_rpc_client/wallet.ts @@ -16,7 +16,7 @@ import { TxReceipt, } from '@aztec/types'; -import { AuthWitnessAccountEntrypoint, CreateTxRequestOpts, Entrypoint } from '../account/entrypoint/index.js'; +import { AuthWitnessAccountEntrypoint, Entrypoint } from '../account/entrypoint/index.js'; import { CompleteAddress } from '../index.js'; /** @@ -30,7 +30,7 @@ export type Wallet = Entrypoint & AztecRPC; export abstract class BaseWallet implements Wallet { constructor(protected readonly rpc: AztecRPC) {} - abstract createTxExecutionRequest(execs: FunctionCall[], opts?: CreateTxRequestOpts): Promise; + abstract createTxExecutionRequest(execs: FunctionCall[]): Promise; registerAccount(privKey: GrumpkinPrivateKey, partialAddress: PartialAddress): Promise { return this.rpc.registerAccount(privKey, partialAddress); @@ -110,8 +110,8 @@ export class EntrypointWallet extends BaseWallet { constructor(rpc: AztecRPC, protected accountImpl: Entrypoint) { super(rpc); } - createTxExecutionRequest(executions: FunctionCall[], opts: CreateTxRequestOpts = {}): Promise { - return this.accountImpl.createTxExecutionRequest(executions, opts); + createTxExecutionRequest(executions: FunctionCall[]): Promise { + return this.accountImpl.createTxExecutionRequest(executions); } } @@ -136,14 +136,8 @@ export class AuthWitnessEntrypointWallet extends BaseWallet { * @param opts - The options. * @returns - The TxRequest */ - async createTxExecutionRequest( - executions: FunctionCall[], - opts: CreateTxRequestOpts = {}, - ): Promise { - const { txRequest, message, witness } = await this.accountImpl.createTxExecutionRequestWithWitness( - executions, - opts, - ); + async createTxExecutionRequest(executions: FunctionCall[]): Promise { + const { txRequest, message, witness } = await this.accountImpl.createTxExecutionRequestWithWitness(executions); await this.rpc.addAuthWitness(Fr.fromBuffer(message), witness); return txRequest; } diff --git a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts index 2412401f5df..df444dff062 100644 --- a/yarn-project/aztec.js/src/contract/base_contract_interaction.ts +++ b/yarn-project/aztec.js/src/contract/base_contract_interaction.ts @@ -1,4 +1,3 @@ -import { AztecAddress } from '@aztec/circuits.js'; import { AztecRPC, Tx, TxExecutionRequest } from '@aztec/types'; import { SentTx } from './sent_tx.js'; @@ -8,10 +7,6 @@ import { SentTx } from './sent_tx.js'; * Allows the user to specify the sender address and nonce for a transaction. */ export interface SendMethodOptions { - /** - * Sender's address initiating the transaction. - */ - origin?: AztecAddress; /** * Wether to skip the simulation of the public part of the transaction. */ diff --git a/yarn-project/aztec.js/src/contract/batch_call.ts b/yarn-project/aztec.js/src/contract/batch_call.ts index ed45d7169c1..9b801ddec83 100644 --- a/yarn-project/aztec.js/src/contract/batch_call.ts +++ b/yarn-project/aztec.js/src/contract/batch_call.ts @@ -1,5 +1,5 @@ import { FunctionCall, TxExecutionRequest, Wallet } from '../index.js'; -import { BaseContractInteraction, SendMethodOptions } from './base_contract_interaction.js'; +import { BaseContractInteraction } from './base_contract_interaction.js'; /** A batch of function calls to be sent as a single transaction through a wallet. */ export class BatchCall extends BaseContractInteraction { @@ -10,12 +10,11 @@ export class BatchCall extends BaseContractInteraction { /** * Create a transaction execution request that represents this batch, encoded and authenticated by the * user's wallet, ready to be simulated. - * @param options - An optional object containing additional configuration for the transaction. * @returns A Promise that resolves to a transaction instance. */ - public async create(options?: SendMethodOptions | undefined): Promise { + public async create(): Promise { if (!this.txRequest) { - this.txRequest = await this.wallet.createTxExecutionRequest(this.calls, options); + this.txRequest = await this.wallet.createTxExecutionRequest(this.calls); } return this.txRequest; } diff --git a/yarn-project/aztec.js/src/contract/contract.test.ts b/yarn-project/aztec.js/src/contract/contract.test.ts index 8f821cf0ff8..f85912cd3e9 100644 --- a/yarn-project/aztec.js/src/contract/contract.test.ts +++ b/yarn-project/aztec.js/src/contract/contract.test.ts @@ -109,9 +109,7 @@ describe('Contract Class', () => { const fooContract = await Contract.at(contractAddress, defaultAbi, wallet); const param0 = 12; const param1 = 345n; - const sentTx = fooContract.methods.bar(param0, param1).send({ - origin: account.address, - }); + const sentTx = fooContract.methods.bar(param0, param1).send(); const txHash = await sentTx.getTxHash(); const receipt = await sentTx.getReceipt(); @@ -134,7 +132,7 @@ describe('Contract Class', () => { it('should not call create on an unconstrained function', async () => { const fooContract = await Contract.at(contractAddress, defaultAbi, wallet); - await expect(fooContract.methods.qux().create({ origin: account.address })).rejects.toThrow(); + await expect(fooContract.methods.qux().create()).rejects.toThrow(); }); it('should not call view on a secret or open function', async () => { diff --git a/yarn-project/aztec.js/src/contract/contract_base.ts b/yarn-project/aztec.js/src/contract/contract_base.ts index 2cd9ec0a15c..c3bce05c883 100644 --- a/yarn-project/aztec.js/src/contract/contract_base.ts +++ b/yarn-project/aztec.js/src/contract/contract_base.ts @@ -19,7 +19,7 @@ export type ContractMethod = ((...args: any[]) => ContractFunctionInteraction) & /** * Abstract implementation of a contract extended by the Contract class and generated contract types. */ -export abstract class ContractBase { +export class ContractBase { /** * An object containing contract methods mapped to their respective names. */ @@ -56,10 +56,22 @@ export abstract class ContractBase { }); } - get address() { + /** + * Address of the contract. + */ + public get address() { return this.completeAddress.address; } + /** + * Creates a new instance of the contract wrapper attached to a different wallet. + * @param wallet - Wallet to use for sending txs. + * @returns A new contract instance. + */ + public withWallet(wallet: Wallet): this { + return new ContractBase(this.completeAddress, this.abi, wallet) as this; + } + /** * Attach the current contract instance to a portal contract and optionally add its dependencies. * The function will return a promise that resolves when all contracts have been added to the AztecRPCClient. diff --git a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts index 772349e641d..e3bb4bdf6b7 100644 --- a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts +++ b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts @@ -38,15 +38,14 @@ export class ContractFunctionInteraction extends BaseContractInteraction { /** * Create a transaction execution request that represents this call, encoded and authenticated by the * user's wallet, ready to be simulated. - * @param options - An optional object containing additional configuration for the transaction. * @returns A Promise that resolves to a transaction instance. */ - public async create(options: SendMethodOptions = {}): Promise { + public async create(): Promise { if (this.functionDao.functionType === FunctionType.UNCONSTRAINED) { throw new Error("Can't call `create` on an unconstrained function."); } if (!this.txRequest) { - this.txRequest = await this.wallet.createTxExecutionRequest([this.request()], options); + this.txRequest = await this.wallet.createTxExecutionRequest([this.request()]); } return this.txRequest; } diff --git a/yarn-project/aztec.js/src/contract_deployer/contract_deployer.test.ts b/yarn-project/aztec.js/src/contract_deployer/contract_deployer.test.ts index df700e27f1d..36e2d8b5bac 100644 --- a/yarn-project/aztec.js/src/contract_deployer/contract_deployer.test.ts +++ b/yarn-project/aztec.js/src/contract_deployer/contract_deployer.test.ts @@ -1,4 +1,4 @@ -import { AztecAddress, EthAddress, Fr, Point } from '@aztec/circuits.js'; +import { EthAddress, Fr, Point } from '@aztec/circuits.js'; import { ContractAbi, FunctionType } from '@aztec/foundation/abi'; import { AztecRPC, PublicKey, Tx, TxHash, TxReceipt } from '@aztec/types'; @@ -26,7 +26,6 @@ describe.skip('Contract Deployer', () => { const publicKey: PublicKey = Point.random(); const portalContract = EthAddress.random(); const contractAddressSalt = Fr.random(); - const account = AztecAddress.random(); const args = [12, 345n]; const mockTx = { type: 'Tx' } as any as Tx; @@ -44,7 +43,6 @@ describe.skip('Contract Deployer', () => { const sentTx = deployer.deploy(args[0], args[1]).send({ portalContract, contractAddressSalt, - origin: account, }); const txHash = await sentTx.getTxHash(); const receipt = await sentTx.getReceipt(); diff --git a/yarn-project/aztec.js/src/sandbox/index.ts b/yarn-project/aztec.js/src/sandbox/index.ts index 814218c3a12..447e29beaaf 100644 --- a/yarn-project/aztec.js/src/sandbox/index.ts +++ b/yarn-project/aztec.js/src/sandbox/index.ts @@ -1,11 +1,10 @@ import { Fr, GrumpkinScalar } from '@aztec/circuits.js'; -import { ContractAbi } from '@aztec/foundation/abi'; import { sleep } from '@aztec/foundation/sleep'; import zip from 'lodash.zip'; import SchnorrAccountContractAbi from '../abis/schnorr_account_contract.json' assert { type: 'json' }; -import { AccountWallet, AztecRPC, EntrypointWallet, getAccountWallets, getSchnorrAccount } from '../index.js'; +import { AccountWallet, AztecRPC, getSchnorrAccount } from '../index.js'; export const INITIAL_SANDBOX_ENCRYPTION_KEYS = [ GrumpkinScalar.fromString('2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281'), @@ -19,21 +18,6 @@ export const INITIAL_SANDBOX_SALTS = [Fr.ZERO, Fr.ZERO, Fr.ZERO]; export const INITIAL_SANDBOX_ACCOUNT_CONTRACT_ABI = SchnorrAccountContractAbi; -/** - * Gets a single wallet that manages all the Aztec accounts that are initially stored in the sandbox. - * @param aztecRpc - An instance of the Aztec RPC interface. - * @returns An AccountWallet implementation that includes all the initial accounts. - */ -export async function getSandboxAccountsWallet(aztecRpc: AztecRPC): Promise { - return await getAccountWallets( - aztecRpc, - INITIAL_SANDBOX_ACCOUNT_CONTRACT_ABI as unknown as ContractAbi, - INITIAL_SANDBOX_ENCRYPTION_KEYS, - INITIAL_SANDBOX_SIGNING_KEYS, - INITIAL_SANDBOX_SALTS, - ); -} - /** * Gets a collection of wallets for the Aztec accounts that are initially stored in the sandbox. * @param aztecRpc - An instance of the Aztec RPC interface. diff --git a/yarn-project/aztec.js/src/utils/account.ts b/yarn-project/aztec.js/src/utils/account.ts index baa0b5110f1..f82b371d7da 100644 --- a/yarn-project/aztec.js/src/utils/account.ts +++ b/yarn-project/aztec.js/src/utils/account.ts @@ -1,91 +1,38 @@ -import { Fr, GrumpkinPrivateKey, GrumpkinScalar, getContractDeploymentInfo } from '@aztec/circuits.js'; -import { Schnorr } from '@aztec/circuits.js/barretenberg'; -import { ContractAbi } from '@aztec/foundation/abi'; -import { createDebugLogger } from '@aztec/foundation/log'; -import { AztecRPC, TxStatus } from '@aztec/types'; +import { CompleteAddress, GrumpkinScalar } from '@aztec/circuits.js'; +import { AztecRPC } from '@aztec/types'; -import { SingleKeyAccountEntrypoint } from '../account/entrypoint/single_key_account_entrypoint.js'; -import { EntrypointWallet, Wallet } from '../aztec_rpc_client/wallet.js'; -import { ContractDeployer, EntrypointCollection, StoredKeyAccountEntrypoint, generatePublicKey } from '../index.js'; +import { AccountWallet } from '../aztec_rpc_client/wallet.js'; +import { getSchnorrAccount } from '../index.js'; /** - * Creates an Aztec Account. - * @returns The account's address & public key. + * Creates a random address and registers it as a recipient on the RPC server. Useful for testing. + * @param rpc - RPC client. + * @returns Complete address of the registered recipient. */ -export async function createAccounts( - aztecRpcClient: AztecRPC, - accountContractAbi: ContractAbi, - privateKey?: GrumpkinPrivateKey, - salt = Fr.random(), - numberOfAccounts = 1, - logger = createDebugLogger('aztec:aztec.js:accounts'), -): Promise { - const accountImpls = new EntrypointCollection(); - - for (let i = 0; i < numberOfAccounts; ++i) { - // TODO(#662): Let the aztec rpc server generate the keypair rather than hardcoding the private key - const privKey = i == 0 && privateKey ? privateKey : GrumpkinScalar.random(); - const publicKey = await generatePublicKey(privKey); - const deploymentInfo = await getContractDeploymentInfo(accountContractAbi, [], salt, publicKey); - await aztecRpcClient.registerAccount(privKey, deploymentInfo.completeAddress.partialAddress); - const contractDeployer = new ContractDeployer(accountContractAbi, aztecRpcClient, publicKey); - const tx = contractDeployer.deploy().send({ contractAddressSalt: salt }); - await tx.isMined({ interval: 0.5 }); - const receipt = await tx.getReceipt(); - if (receipt.status !== TxStatus.MINED) { - throw new Error(`Deployment tx not mined (status is ${receipt.status})`); - } - const address = receipt.contractAddress!; - if (!address.equals(deploymentInfo.completeAddress.address)) { - throw new Error( - `Deployment address does not match for account contract (expected ${deploymentInfo.completeAddress.address.toString()} got ${address.toString()})`, - ); - } - logger(`Created account ${address.toString()} with public key ${publicKey.toString()}`); - accountImpls.registerAccount( - address, - new SingleKeyAccountEntrypoint(address, deploymentInfo.completeAddress.partialAddress, privKey), - ); - } - return new EntrypointWallet(aztecRpcClient, accountImpls); +export async function createRecipient(rpc: AztecRPC): Promise { + const completeAddress = await CompleteAddress.random(); + await rpc.registerRecipient(completeAddress); + return completeAddress; } /** - * Gets the Aztec accounts that are stored in an Aztec RPC instance. - * @param aztecRpcClient - An instance of the Aztec RPC interface. - * @param accountContractAbi - The abi of the account contract used when the accounts were deployed - * @param privateKeys - The encryption private keys used to create the accounts. - * @param signingKeys - The signing private keys used to create the accounts. - * @param salts - The salt values used to create the accounts. - * @returns An AccountWallet implementation that includes all the accounts found. + * Creates a given number of random accounts using the Schnorr account wallet. + * @param rpc - RPC interface. + * @param numberOfAccounts - How many accounts to create. + * @returns The created account wallets. */ -export async function getAccountWallets( - aztecRpcClient: AztecRPC, - accountContractAbi: ContractAbi, - privateKeys: GrumpkinPrivateKey[], - signingKeys: GrumpkinPrivateKey[], - salts: Fr[], -) { - if (privateKeys.length != salts.length || signingKeys.length != privateKeys.length) { - throw new Error('Keys and salts must be the same length'); - } - const accountCollection = new EntrypointCollection(); - const schnorr = await Schnorr.new(); +export async function createAccounts(rpc: AztecRPC, numberOfAccounts = 1): Promise { + const accounts = []; - for (let i = 0; i < privateKeys.length; i++) { - const publicKey = await generatePublicKey(privateKeys[i]); - const signingPublicKey = await generatePublicKey(signingKeys[i]); - const deploymentInfo = await getContractDeploymentInfo( - accountContractAbi, - [signingPublicKey.x, signingPublicKey.y], - salts[i], - publicKey, - ); - const address = deploymentInfo.completeAddress.address; - - const signClosure = (msg: Buffer) => schnorr.constructSignature(msg, signingKeys[i]); - - accountCollection.registerAccount(address, new StoredKeyAccountEntrypoint(address, signClosure)); + // Prepare deployments + for (let i = 0; i < numberOfAccounts; ++i) { + const account = getSchnorrAccount(rpc, GrumpkinScalar.random(), GrumpkinScalar.random()); + await account.getDeployMethod().then(d => d.simulate({ contractAddressSalt: account.salt })); + accounts.push(account); } - return new EntrypointWallet(aztecRpcClient, accountCollection); + + // Send them and await them to be mined + const txs = await Promise.all(accounts.map(account => account.deploy())); + await Promise.all(txs.map(tx => tx.wait({ interval: 0.1 }))); + return Promise.all(accounts.map(account => account.getWallet())); } diff --git a/yarn-project/canary/src/aztec_js_browser.test.ts b/yarn-project/canary/src/aztec_js_browser.test.ts index 4b3afb1e3c5..b2c70ade731 100644 --- a/yarn-project/canary/src/aztec_js_browser.test.ts +++ b/yarn-project/canary/src/aztec_js_browser.test.ts @@ -97,11 +97,11 @@ conditionalDescribe()('e2e_aztec.js_browser', () => { }); it('Loads Aztec.js in the browser', async () => { - const createAccountsExists = await page.evaluate(() => { - const { createAccounts } = window.AztecJs; - return typeof createAccounts === 'function'; + const generatePublicKeyExists = await page.evaluate(() => { + const { generatePublicKey } = window.AztecJs; + return typeof generatePublicKey === 'function'; }); - expect(createAccountsExists).toBe(true); + expect(generatePublicKeyExists).toBe(true); }); it('Creates an account', async () => { @@ -135,7 +135,7 @@ conditionalDescribe()('e2e_aztec.js_browser', () => { const { Contract, AztecAddress, createAztecRpcClient, makeFetch } = window.AztecJs; const client = createAztecRpcClient(rpcUrl!, makeFetch([1, 2, 3], true)); const owner = (await client.getAccounts())[0].address; - const wallet = await AztecJs.getSandboxAccountsWallet(client); + const [wallet] = await AztecJs.getSandboxAccountsWallets(client); const contract = await Contract.at(AztecAddress.fromString(contractAddress), PrivateTokenContractAbi, wallet); const balance = await contract.methods.getBalance(owner).view({ from: owner }); console.log(`Owner's balance: ${balance}`); @@ -158,9 +158,9 @@ conditionalDescribe()('e2e_aztec.js_browser', () => { const accounts = await client.getAccounts(); const owner = accounts[0].address; const receiver = accounts[1].address; - const wallet = await AztecJs.getSandboxAccountsWallet(client); + const [wallet] = await AztecJs.getSandboxAccountsWallets(client); const contract = await Contract.at(AztecAddress.fromString(contractAddress), PrivateTokenContractAbi, wallet); - await contract.methods.transfer(transferAmount, receiver).send({ origin: owner }).wait(); + await contract.methods.transfer(transferAmount, receiver).send().wait(); console.log(`Transferred ${transferAmount} tokens to new Account`); const receiverBalance = await contract.methods.getBalance(receiver).view({ from: receiver }); console.log(`Receiver's balance is now: ${receiverBalance}`); diff --git a/yarn-project/canary/src/uniswap_trade_on_l1_from_l2.test.ts b/yarn-project/canary/src/uniswap_trade_on_l1_from_l2.test.ts index 350f01656ca..f79632c5f83 100644 --- a/yarn-project/canary/src/uniswap_trade_on_l1_from_l2.test.ts +++ b/yarn-project/canary/src/uniswap_trade_on_l1_from_l2.test.ts @@ -8,7 +8,7 @@ import { createAztecRpcClient, createDebugLogger, getL1ContractAddresses, - getSandboxAccountsWallet, + getSandboxAccountsWallets, makeFetch, sleep, waitForSandbox, @@ -151,7 +151,7 @@ const transferWethOnL2 = async ( receiver: AztecAddress, transferAmount: bigint, ) => { - const transferTx = wethL2Contract.methods.transfer(transferAmount, receiver).send({ origin: ownerAddress }); + const transferTx = wethL2Contract.methods.transfer(transferAmount, receiver).send(); await transferTx.isMined(); const transferReceipt = await transferTx.getReceipt(); expect(transferReceipt.status).toBe(TxStatus.MINED); @@ -184,7 +184,7 @@ describe('uniswap_trade_on_l1_from_l2', () => { it('should uniswap trade on L1 from L2 funds privately (swaps WETH -> DAI)', async () => { logger('Running L1/L2 messaging test on HTTP interface.'); - wallet = await getSandboxAccountsWallet(aztecRpcClient); + [wallet] = await getSandboxAccountsWallets(aztecRpcClient); const accounts = await wallet.getAccounts(); const owner = accounts[0].address; const receiver = accounts[1].address; @@ -246,7 +246,7 @@ describe('uniswap_trade_on_l1_from_l2', () => { // Call the mint tokens function on the noir contract const consumptionTx = wethL2Contract.methods .mint(wethAmountToBridge, owner, messageKey, secret, ethAccount.toField()) - .send({ origin: owner }); + .send(); await consumptionTx.isMined(); const consumptionReceipt = await consumptionTx.getReceipt(); expect(consumptionReceipt.status).toBe(TxStatus.MINED); @@ -276,7 +276,7 @@ describe('uniswap_trade_on_l1_from_l2', () => { ethAccount.toField(), ethAccount.toField(), ) - .send({ origin: owner }); + .send(); await withdrawTx.isMined(); const withdrawReceipt = await withdrawTx.getReceipt(); expect(withdrawReceipt.status).toBe(TxStatus.MINED); @@ -327,7 +327,7 @@ describe('uniswap_trade_on_l1_from_l2', () => { // Call the mint tokens function on the noir contract const daiMintTx = daiL2Contract.methods .mint(daiAmountToBridge, owner, depositDaiMessageKey, secret, ethAccount.toField()) - .send({ origin: owner }); + .send(); await daiMintTx.isMined(); const daiMintTxReceipt = await daiMintTx.getReceipt(); expect(daiMintTxReceipt.status).toBe(TxStatus.MINED); diff --git a/yarn-project/cli/src/index.ts b/yarn-project/cli/src/index.ts index f4583419176..d06d4062aba 100644 --- a/yarn-project/cli/src/index.ts +++ b/yarn-project/cli/src/index.ts @@ -6,7 +6,6 @@ import { GrumpkinScalar, Point, generatePublicKey, - getAccountWallets, getSchnorrAccount, isContractDeployed, } from '@aztec/aztec.js'; @@ -15,7 +14,6 @@ import { JsonStringify } from '@aztec/foundation/json-rpc'; import { DebugLogger, LogFn } from '@aztec/foundation/log'; import { fileURLToPath } from '@aztec/foundation/url'; import { compileContract } from '@aztec/noir-compiler/cli'; -import { SchnorrAccountContractAbi } from '@aztec/noir-contracts/artifacts'; import { CompleteAddress, ContractData, L2BlockL2Logs, TxHash } from '@aztec/types'; import { Command } from 'commander'; @@ -387,13 +385,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command { const privateKey = GrumpkinScalar.fromString(stripLeadingHex(options.privateKey)); const client = await createCompatibleClient(options.rpcUrl, debugLogger); - const wallet = await getAccountWallets( - client, - SchnorrAccountContractAbi, - [privateKey], - [privateKey], - [accountCreationSalt], - ); + const wallet = await getSchnorrAccount(client, privateKey, privateKey, accountCreationSalt).getWallet(); const contract = await Contract.at(contractAddress, contractAbi, wallet); const tx = contract.methods[functionName](...functionArgs).send(); await tx.wait(); diff --git a/yarn-project/end-to-end/src/e2e_2_rpc_servers.test.ts b/yarn-project/end-to-end/src/e2e_2_rpc_servers.test.ts index 5bed24350ab..554ad930ff6 100644 --- a/yarn-project/end-to-end/src/e2e_2_rpc_servers.test.ts +++ b/yarn-project/end-to-end/src/e2e_2_rpc_servers.test.ts @@ -27,14 +27,20 @@ describe('e2e_2_rpc_servers', () => { throw new Error(`Test can't be run against the sandbox as 2 RPC servers are required`); } let accounts: CompleteAddress[] = []; - ({ aztecNode, aztecRpcServer: aztecRpcServerA, accounts, wallet: walletA, logger } = await setup(1)); + ({ + aztecNode, + aztecRpcServer: aztecRpcServerA, + accounts, + wallets: [walletA], + logger, + } = await setup(1)); [userA] = accounts; ({ aztecRpcServer: aztecRpcServerB, accounts: accounts, - wallet: walletB, - } = await setupAztecRPCServer(1, aztecNode!, null, undefined, true)); + wallets: [walletB], + } = await setupAztecRPCServer(1, aztecNode!, undefined, true)); [userB] = accounts; }, 100_000); @@ -108,7 +114,7 @@ describe('e2e_2_rpc_servers', () => { // Transfer funds from A to B via RPC server A const contractWithWalletA = await PrivateTokenContract.at(tokenAddress, walletA); - const txAToB = contractWithWalletA.methods.transfer(transferAmount1, userB.address).send({ origin: userA.address }); + const txAToB = contractWithWalletA.methods.transfer(transferAmount1, userB.address).send(); await txAToB.isMined({ interval: 0.1 }); const receiptAToB = await txAToB.getReceipt(); @@ -122,12 +128,7 @@ describe('e2e_2_rpc_servers', () => { // Transfer funds from B to A via RPC server B const contractWithWalletB = await PrivateTokenContract.at(tokenAddress, walletB); - const txBToA = contractWithWalletB.methods.transfer(transferAmount2, userA.address).send({ origin: userB.address }); - - await txBToA.isMined({ interval: 0.1 }); - const receiptBToA = await txBToA.getReceipt(); - - expect(receiptBToA.status).toBe(TxStatus.MINED); + await contractWithWalletB.methods.transfer(transferAmount2, userA.address).send().wait({ interval: 0.1 }); // Check balances and logs are as expected await expectTokenBalance(walletA, tokenAddress, userA.address, initialBalance - transferAmount1 + transferAmount2); @@ -170,11 +171,7 @@ describe('e2e_2_rpc_servers', () => { const newValueToSet = 256n; const childContractWithWalletB = await ChildContract.at(childCompleteAddress.address, walletB); - const tx = childContractWithWalletB.methods.pubIncValue(newValueToSet).send({ origin: userB.address }); - await tx.isMined({ interval: 0.1 }); - - const receipt = await tx.getReceipt(); - expect(receipt.status).toBe(TxStatus.MINED); + await childContractWithWalletB.methods.pubIncValue(newValueToSet).send().wait({ interval: 0.1 }); await awaitServerSynchronised(aztecRpcServerA); diff --git a/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts b/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts index b2100c2f2ac..906a1bb1cd0 100644 --- a/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts +++ b/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts @@ -100,11 +100,11 @@ conditionalDescribe()('e2e_aztec.js_browser', () => { }); it('Loads Aztec.js in the browser', async () => { - const createAccountsExists = await page.evaluate(() => { - const { createAccounts } = window.AztecJs; - return typeof createAccounts === 'function'; + const generatePublicKeyExists = await page.evaluate(() => { + const { generatePublicKey } = window.AztecJs; + return typeof generatePublicKey === 'function'; }); - expect(createAccountsExists).toBe(true); + expect(generatePublicKeyExists).toBe(true); }); it('Creates an account', async () => { @@ -138,7 +138,7 @@ conditionalDescribe()('e2e_aztec.js_browser', () => { const { Contract, AztecAddress, createAztecRpcClient, makeFetch } = window.AztecJs; const client = createAztecRpcClient(rpcUrl!, makeFetch([1, 2, 3], true)); const owner = (await client.getAccounts())[0].address; - const wallet = await AztecJs.getSandboxAccountsWallet(client); + const [wallet] = await AztecJs.getSandboxAccountsWallets(client); const contract = await Contract.at(AztecAddress.fromString(contractAddress), PrivateTokenContractAbi, wallet); const balance = await contract.methods.getBalance(owner).view({ from: owner }); return balance; @@ -158,11 +158,10 @@ conditionalDescribe()('e2e_aztec.js_browser', () => { const { AztecAddress, Contract, createAztecRpcClient, makeFetch } = window.AztecJs; const client = createAztecRpcClient(rpcUrl!, makeFetch([1, 2, 3], true)); const accounts = await client.getAccounts(); - const owner = accounts[0].address; const receiver = accounts[1].address; - const wallet = await AztecJs.getSandboxAccountsWallet(client); + const [wallet] = await AztecJs.getSandboxAccountsWallets(client); const contract = await Contract.at(AztecAddress.fromString(contractAddress), PrivateTokenContractAbi, wallet); - await contract.methods.transfer(transferAmount, receiver).send({ origin: owner }).wait(); + await contract.methods.transfer(transferAmount, receiver).send().wait(); console.log(`Transferred ${transferAmount} tokens to new Account`); return await contract.methods.getBalance(receiver).view({ from: receiver }); }, diff --git a/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts b/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts index d7ec7962ee4..f0968945e54 100644 --- a/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts +++ b/yarn-project/end-to-end/src/e2e_cheat_codes.test.ts @@ -1,5 +1,5 @@ import { AztecNodeService } from '@aztec/aztec-node'; -import { AztecAddress, AztecRPCServer, EthAddress } from '@aztec/aztec-rpc'; +import { AztecRPCServer, EthAddress } from '@aztec/aztec-rpc'; import { CheatCodes, Wallet } from '@aztec/aztec.js'; import { RollupAbi } from '@aztec/l1-artifacts'; import { TestContract } from '@aztec/noir-contracts/types'; @@ -18,17 +18,14 @@ describe('e2e_cheat_codes', () => { let walletClient: WalletClient; let publicClient: PublicClient; let rollupAddress: EthAddress; - let recipient: AztecAddress; beforeAll(async () => { let deployL1ContractsValues; - let accounts; - ({ aztecNode, aztecRpcServer, wallet, accounts, cheatCodes: cc, deployL1ContractsValues } = await setup()); + ({ aztecNode, aztecRpcServer, wallet, cheatCodes: cc, deployL1ContractsValues } = await setup()); walletClient = deployL1ContractsValues.walletClient; publicClient = deployL1ContractsValues.publicClient; rollupAddress = deployL1ContractsValues.rollupAddress; - recipient = accounts[0].address; }, 100_000); afterAll(async () => { @@ -158,13 +155,13 @@ describe('e2e_cheat_codes', () => { expect(Number(await rollup.read.lastBlockTs())).toEqual(newTimestamp); expect(Number(await rollup.read.lastWarpedBlockTs())).toEqual(newTimestamp); - const txIsTimeEqual = contract.methods.isTimeEqual(newTimestamp).send({ origin: recipient }); + const txIsTimeEqual = contract.methods.isTimeEqual(newTimestamp).send(); const isTimeEqualReceipt = await txIsTimeEqual.wait({ interval: 0.1 }); expect(isTimeEqualReceipt.status).toBe(TxStatus.MINED); // Since last rollup block was warped, txs for this rollup will have time incremented by 1 // See https://github.com/AztecProtocol/aztec-packages/issues/1614 for details - const txTimeNotEqual = contract.methods.isTimeEqual(newTimestamp + 1).send({ origin: recipient }); + const txTimeNotEqual = contract.methods.isTimeEqual(newTimestamp + 1).send(); const isTimeNotEqualReceipt = await txTimeNotEqual.wait({ interval: 0.1 }); expect(isTimeNotEqualReceipt.status).toBe(TxStatus.MINED); // block is published at t >= newTimestamp + 1. diff --git a/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts b/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts index 16b0ce5a61c..8861c6477dd 100644 --- a/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts @@ -75,7 +75,7 @@ describe('e2e_cross_chain_messaging', () => { logger('Send L2 tx to withdraw funds'); const withdrawTx = l2Contract.methods .withdraw(withdrawAmount, ownerAddress, ethAccount, EthAddress.ZERO.toField()) - .send({ origin: ownerAddress }); + .send(); await withdrawTx.isMined({ interval: 0.1 }); const withdrawReceipt = await withdrawTx.getReceipt(); diff --git a/yarn-project/end-to-end/src/e2e_escrow_contract.test.ts b/yarn-project/end-to-end/src/e2e_escrow_contract.test.ts index 465b720f348..5121aaafdc7 100644 --- a/yarn-project/end-to-end/src/e2e_escrow_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_escrow_contract.test.ts @@ -1,6 +1,6 @@ import { AztecNodeService } from '@aztec/aztec-node'; import { AztecRPCServer } from '@aztec/aztec-rpc'; -import { AztecAddress, BatchCall, Wallet, generatePublicKey } from '@aztec/aztec.js'; +import { AccountWallet, AztecAddress, BatchCall, generatePublicKey } from '@aztec/aztec.js'; import { CompleteAddress, Fr, GrumpkinPrivateKey, GrumpkinScalar, getContractDeploymentInfo } from '@aztec/circuits.js'; import { DebugLogger } from '@aztec/foundation/log'; import { EscrowContractAbi } from '@aztec/noir-contracts/artifacts'; @@ -12,7 +12,8 @@ import { setup } from './fixtures/utils.js'; describe('e2e_escrow_contract', () => { let aztecNode: AztecNodeService | undefined; let aztecRpcServer: AztecRPC; - let wallet: Wallet; + let wallet: AccountWallet; + let recipientWallet: AccountWallet; let accounts: CompleteAddress[]; let logger: DebugLogger; @@ -26,7 +27,13 @@ describe('e2e_escrow_contract', () => { beforeEach(async () => { // Setup environment - ({ aztecNode, aztecRpcServer, accounts, wallet, logger } = await setup(2)); + ({ + aztecNode, + aztecRpcServer, + accounts, + wallets: [wallet, recipientWallet], + logger, + } = await setup(2)); owner = accounts[0].address; recipient = accounts[1].address; @@ -74,7 +81,10 @@ describe('e2e_escrow_contract', () => { it('refuses to withdraw funds as a non-owner', async () => { await expect( - escrowContract.methods.withdraw(privateTokenContract.address, 30, recipient).simulate({ origin: recipient }), + escrowContract + .withWallet(recipientWallet) + .methods.withdraw(privateTokenContract.address, 30, recipient) + .simulate(), ).rejects.toThrowError(); }, 60_000); diff --git a/yarn-project/end-to-end/src/e2e_lending_contract.test.ts b/yarn-project/end-to-end/src/e2e_lending_contract.test.ts index 0be2de648ac..0f6d538290b 100644 --- a/yarn-project/end-to-end/src/e2e_lending_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_lending_contract.test.ts @@ -296,7 +296,7 @@ describe('e2e_lending_contract', () => { const storageSnapshots: { [key: string]: { [key: string]: Fr } } = {}; const setPrice = async (newPrice: bigint) => { - const tx = priceFeedContract.methods.set_price(0n, newPrice).send({ origin: recipient }); + const tx = priceFeedContract.methods.set_price(0n, newPrice).send(); const receipt = await tx.wait(); expect(receipt.status).toBe(TxStatus.MINED); }; @@ -305,11 +305,11 @@ describe('e2e_lending_contract', () => { { // Minting some collateral in public so we got it at hand. - const tx = collateralAsset.methods.owner_mint_pub(lendingAccount.address, 10000n).send({ origin: recipient }); + const tx = collateralAsset.methods.owner_mint_pub(lendingAccount.address, 10000n).send(); const receipt = await tx.wait(); expect(receipt.status).toBe(TxStatus.MINED); - const tx2 = collateralAsset.methods.approve(lendingContract.address, 10000n).send({ origin: recipient }); + const tx2 = collateralAsset.methods.approve(lendingContract.address, 10000n).send(); const receipt2 = await tx2.wait(); expect(receipt2.status).toBe(TxStatus.MINED); @@ -317,15 +317,15 @@ describe('e2e_lending_contract', () => { const secret = Fr.random(); const secretHash = await computeMessageSecretHash(secret); const shieldAmount = 10000n; - const tx3 = stableCoin.methods.owner_mint_priv(shieldAmount, secretHash).send({ origin: recipient }); + const tx3 = stableCoin.methods.owner_mint_priv(shieldAmount, secretHash).send(); const receipt3 = await tx3.wait(); expect(receipt3.status).toBe(TxStatus.MINED); - const tx4 = stableCoin.methods.redeemShield(shieldAmount, secret, recipient).send({ origin: recipient }); + const tx4 = stableCoin.methods.redeemShield(shieldAmount, secret, recipient).send(); const receipt4 = await tx4.wait(); expect(receipt4.status).toBe(TxStatus.MINED); - const tx5 = stableCoin.methods.approve(lendingContract.address, 10000n).send({ origin: recipient }); + const tx5 = stableCoin.methods.approve(lendingContract.address, 10000n).send(); const receipt5 = await tx5.wait(); expect(receipt5.status).toBe(TxStatus.MINED); } @@ -342,7 +342,7 @@ describe('e2e_lending_contract', () => { logger('Initializing contract'); const tx = lendingContract.methods .init(priceFeedContract.address, 8000, collateralAsset.address, stableCoin.address) - .send({ origin: recipient }); + .send(); const receipt = await tx.wait(); expect(receipt.status).toBe(TxStatus.MINED); storageSnapshots['initial'] = await getStorageSnapshot( @@ -376,7 +376,7 @@ describe('e2e_lending_contract', () => { logger('Depositing 🥸 : 💰 -> 🏦'); const tx = lendingContract.methods .deposit_private(lendingAccount.secret, lendingAccount.address, 0n, depositAmount, collateralAsset.address) - .send({ origin: recipient }); + .send(); const receipt = await tx.wait(); expect(receipt.status).toBe(TxStatus.MINED); storageSnapshots['private_deposit'] = await getStorageSnapshot( @@ -409,7 +409,7 @@ describe('e2e_lending_contract', () => { logger('Depositing 🥸 on behalf of recipient: 💰 -> 🏦'); const tx = lendingContract.methods .deposit_private(0n, lendingAccount.address, recipient.toField(), depositAmount, collateralAsset.address) - .send({ origin: recipient }); + .send(); const receipt = await tx.wait(); expect(receipt.status).toBe(TxStatus.MINED); storageSnapshots['private_deposit_on_behalf'] = await getStorageSnapshot( @@ -436,7 +436,7 @@ describe('e2e_lending_contract', () => { logger('Depositing: 💰 -> 🏦'); const tx = lendingContract.methods .deposit_public(lendingAccount.address, depositAmount, collateralAsset.address) - .send({ origin: recipient }); + .send(); const receipt = await tx.wait(); expect(receipt.status).toBe(TxStatus.MINED); storageSnapshots['public_deposit'] = await getStorageSnapshot( @@ -462,7 +462,7 @@ describe('e2e_lending_contract', () => { logger('Borrow 🥸 : 🏦 -> 🍌'); const tx = lendingContract.methods .borrow_private(lendingAccount.secret, lendingAccount.address, borrowAmount) - .send({ origin: recipient }); + .send(); const receipt = await tx.wait(); expect(receipt.status).toBe(TxStatus.MINED); storageSnapshots['private_borrow'] = await getStorageSnapshot( @@ -487,9 +487,7 @@ describe('e2e_lending_contract', () => { // - increase the public debt. logger('Borrow: 🏦 -> 🍌'); - const tx = lendingContract.methods - .borrow_public(lendingAccount.address, borrowAmount) - .send({ origin: recipient }); + const tx = lendingContract.methods.borrow_public(lendingAccount.address, borrowAmount).send(); const receipt = await tx.wait(); expect(receipt.status).toBe(TxStatus.MINED); storageSnapshots['public_borrow'] = await getStorageSnapshot( @@ -524,7 +522,7 @@ describe('e2e_lending_contract', () => { logger('Repay 🥸 : 🍌 -> 🏦'); const tx = lendingContract.methods .repay_private(lendingAccount.secret, lendingAccount.address, 0n, repayAmount, stableCoin.address) - .send({ origin: recipient }); + .send(); const receipt = await tx.wait(); expect(receipt.status).toBe(TxStatus.MINED); storageSnapshots['private_repay'] = await getStorageSnapshot( @@ -559,7 +557,7 @@ describe('e2e_lending_contract', () => { logger('Repay 🥸 on behalf of public: 🍌 -> 🏦'); const tx = lendingContract.methods .repay_private(0n, lendingAccount.address, recipient.toField(), repayAmount, stableCoin.address) - .send({ origin: recipient }); + .send(); const receipt = await tx.wait(); expect(receipt.status).toBe(TxStatus.MINED); storageSnapshots['private_repay_on_behalf'] = await getStorageSnapshot( @@ -584,9 +582,7 @@ describe('e2e_lending_contract', () => { // - decrease the public debt. logger('Repay: 🍌 -> 🏦'); - const tx = lendingContract.methods - .repay_public(recipient.toField(), 20n, stableCoin.address) - .send({ origin: recipient }); + const tx = lendingContract.methods.repay_public(recipient.toField(), 20n, stableCoin.address).send(); const receipt = await tx.wait(); expect(receipt.status).toBe(TxStatus.MINED); storageSnapshots['public_repay'] = await getStorageSnapshot( @@ -602,9 +598,7 @@ describe('e2e_lending_contract', () => { { // Withdraw more than possible to test the revert. logger('Withdraw: trying to withdraw more than possible'); - const tx = lendingContract.methods - .withdraw_public(recipient, 10n ** 9n) - .send({ origin: recipient, skipPublicSimulation: true }); + const tx = lendingContract.methods.withdraw_public(recipient, 10n ** 9n).send({ skipPublicSimulation: true }); await tx.isMined({ interval: 0.1 }); const receipt = await tx.getReceipt(); expect(receipt.status).toBe(TxStatus.DROPPED); @@ -622,7 +616,7 @@ describe('e2e_lending_contract', () => { // - decrease the public collateral. logger('Withdraw: 🏦 -> 💰'); - const tx = lendingContract.methods.withdraw_public(recipient, withdrawAmount).send({ origin: recipient }); + const tx = lendingContract.methods.withdraw_public(recipient, withdrawAmount).send(); const receipt = await tx.wait(); expect(receipt.status).toBe(TxStatus.MINED); storageSnapshots['public_withdraw'] = await getStorageSnapshot( @@ -649,7 +643,7 @@ describe('e2e_lending_contract', () => { logger('Withdraw 🥸 : 🏦 -> 💰'); const tx = lendingContract.methods .withdraw_private(lendingAccount.secret, lendingAccount.address, withdrawAmount) - .send({ origin: recipient }); + .send(); const receipt = await tx.wait(); expect(receipt.status).toBe(TxStatus.MINED); storageSnapshots['private_withdraw'] = await getStorageSnapshot( @@ -670,7 +664,7 @@ describe('e2e_lending_contract', () => { const tx = lendingContract.methods ._deposit(recipient.toField(), 42n, collateralAsset.address) - .send({ origin: recipient, skipPublicSimulation: true }); + .send({ skipPublicSimulation: true }); await tx.isMined({ interval: 0.1 }); const receipt = await tx.getReceipt(); expect(receipt.status).toBe(TxStatus.DROPPED); diff --git a/yarn-project/end-to-end/src/e2e_multi_transfer.test.ts b/yarn-project/end-to-end/src/e2e_multi_transfer.test.ts index ca5422e2058..0dcfdb807db 100644 --- a/yarn-project/end-to-end/src/e2e_multi_transfer.test.ts +++ b/yarn-project/end-to-end/src/e2e_multi_transfer.test.ts @@ -102,7 +102,7 @@ describe('multi-transfer payments', () => { logger(`self batchTransfer()`); await zkTokenContract.methods .batchTransfer(ownerAddress, [200n, 300n, 400n], [ownerAddress, ownerAddress, ownerAddress], 0) - .send({ origin: ownerAddress }) + .send() .wait(); await expectBalance(zkTokenContract, ownerAddress, initialBalance); @@ -116,7 +116,7 @@ describe('multi-transfer payments', () => { logger(`multiTransfer()...`); await multiTransferContract.methods .multiTransfer(zkTokenContract.address.toField(), recipients, amounts, ownerAddress, noteOffsets) - .send({ origin: ownerAddress }) + .send() .wait({ timeout: 1000 }); // mining timeout ≥ time needed for the test to finish. await expectBalance(zkTokenContract, ownerAddress, initialBalance - amountSum); @@ -170,7 +170,7 @@ describe('multi-transfer payments', () => { await multiTransferContract.methods .multiTransfer(zkTokenContract.address.toField(), repeatedSelfAdddress, amounts, ownerAddress, noteOffsets) - .send({ origin: ownerAddress }) + .send() .wait({ timeout: 100 }); // mining timeout ≥ time needed for the test to finish. await expectBalance(zkTokenContract, ownerAddress, initialBalance); @@ -184,7 +184,7 @@ describe('multi-transfer payments', () => { const recipient = recipients[0]; await expectBalance(zkTokenContract, recipient, 0n); - await zkTokenContract.methods.transfer(transferAmount, recipient).send({ origin: ownerAddress }).wait(); + await zkTokenContract.methods.transfer(transferAmount, recipient).send().wait(); await expectBalance(zkTokenContract, ownerAddress, initialBalance - transferAmount); await expectBalance(zkTokenContract, recipient, transferAmount); diff --git a/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts b/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts index 602c29bdffb..2c86c7007dd 100644 --- a/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts +++ b/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts @@ -81,7 +81,7 @@ describe('e2e_multiple_accounts_1_enc_key', () => { const contractWithWallet = await PrivateTokenContract.at(privateTokenAddress, wallets[senderIndex]); - const tx = contractWithWallet.methods.transfer(transferAmount, receiver).send({ origin: sender }); + const tx = contractWithWallet.methods.transfer(transferAmount, receiver).send(); await tx.isMined({ interval: 0.1 }); const receipt = await tx.getReceipt(); diff --git a/yarn-project/end-to-end/src/e2e_nested_contract.test.ts b/yarn-project/end-to-end/src/e2e_nested_contract.test.ts index 0caa4840668..096daee1add 100644 --- a/yarn-project/end-to-end/src/e2e_nested_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_nested_contract.test.ts @@ -4,7 +4,7 @@ import { AztecAddress, Fr, Wallet } from '@aztec/aztec.js'; import { DebugLogger } from '@aztec/foundation/log'; import { toBigInt } from '@aztec/foundation/serialize'; import { ChildContract, ImportTestContract, ParentContract, TestContract } from '@aztec/noir-contracts/types'; -import { AztecRPC, CompleteAddress } from '@aztec/types'; +import { AztecRPC } from '@aztec/types'; import { setup } from './fixtures/utils.js'; @@ -12,13 +12,10 @@ describe('e2e_nested_contract', () => { let aztecNode: AztecNodeService | undefined; let aztecRpcServer: AztecRPC; let wallet: Wallet; - let sender: AztecAddress; let logger: DebugLogger; beforeEach(async () => { - let accounts: CompleteAddress[]; - ({ aztecNode, aztecRpcServer, accounts, wallet, logger } = await setup()); - sender = accounts[0].address; + ({ aztecNode, aztecRpcServer, wallet, logger } = await setup()); }, 100_000); afterEach(async () => { @@ -43,7 +40,7 @@ describe('e2e_nested_contract', () => { it('performs nested calls', async () => { await parentContract.methods .entryPoint(childContract.address, childContract.methods.value.selector.toField()) - .send({ origin: sender }) + .send() .wait(); }, 100_000); @@ -58,14 +55,14 @@ describe('e2e_nested_contract', () => { it('performs public nested calls', async () => { await parentContract.methods .pubEntryPoint(childContract.address, childContract.methods.pubGetValue.selector.toField(), 42n) - .send({ origin: sender }) + .send() .wait(); }, 100_000); it('enqueues a single public call', async () => { await parentContract.methods .enqueueCallToChild(childContract.address, childContract.methods.pubIncValue.selector.toField(), 42n) - .send({ origin: sender }) + .send() .wait(); expect(await getChildStoredValue(childContract)).toEqual(42n); }, 100_000); @@ -81,7 +78,7 @@ describe('e2e_nested_contract', () => { it('enqueues multiple public calls', async () => { await parentContract.methods .enqueueCallToChildTwice(childContract.address, childContract.methods.pubIncValue.selector.value, 42n) - .send({ origin: sender }) + .send() .wait(); expect(await getChildStoredValue(childContract)).toEqual(85n); }, 100_000); @@ -89,7 +86,7 @@ describe('e2e_nested_contract', () => { it('enqueues a public call with nested public calls', async () => { await parentContract.methods .enqueueCallToPubEntryPoint(childContract.address, childContract.methods.pubIncValue.selector.toField(), 42n) - .send({ origin: sender }) + .send() .wait(); expect(await getChildStoredValue(childContract)).toEqual(42n); }, 100_000); @@ -97,7 +94,7 @@ describe('e2e_nested_contract', () => { it('enqueues multiple public calls with nested public calls', async () => { await parentContract.methods .enqueueCallsToPubEntryPoint(childContract.address, childContract.methods.pubIncValue.selector.toField(), 42n) - .send({ origin: sender }) + .send() .wait(); expect(await getChildStoredValue(childContract)).toEqual(85n); }, 100_000); @@ -106,7 +103,7 @@ describe('e2e_nested_contract', () => { it('reads fresh value after write within the same tx', async () => { await parentContract.methods .pubEntryPointTwice(childContract.address, childContract.methods.pubIncValue.selector.value, 42n) - .send({ origin: sender }) + .send() .wait(); expect(await getChildStoredValue(childContract)).toEqual(84n); }, 100_000); diff --git a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts index a22288e68b7..12d085faa1d 100644 --- a/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts +++ b/yarn-project/end-to-end/src/e2e_non_contract_account.test.ts @@ -58,10 +58,7 @@ describe('e2e_non_contract_account', () => { const contractWithNoContractWallet = await PokeableTokenContract.at(contract.address, pokerWallet); // Send transaction as poker (arbitrary non-contract account) - await contractWithNoContractWallet.methods - .poke(sender, recipient) - .send({ origin: contract.address }) - .wait({ interval: 0.1 }); + await contractWithNoContractWallet.methods.poke(sender, recipient).send().wait({ interval: 0.1 }); // Initial balance should be fully transferred to the recipient await expectBalance(sender, 0n); diff --git a/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts b/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts index 9c3e15a0454..24edd48610b 100644 --- a/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_pending_commitments_contract.test.ts @@ -69,9 +69,7 @@ describe('e2e_pending_commitments_contract', () => { const deployedContract = await deployContract(); - const tx = deployedContract.methods - .test_insert_then_get_then_nullify_flat(mintAmount, owner) - .send({ origin: owner }); + const tx = deployedContract.methods.test_insert_then_get_then_nullify_flat(mintAmount, owner).send(); await tx.isMined({ interval: 0.1 }); const receipt = await tx.getReceipt(); @@ -93,7 +91,7 @@ describe('e2e_pending_commitments_contract', () => { deployedContract.methods.get_then_nullify_note.selector.toField(), deployedContract.methods.get_note_zero_balance.selector.toField(), ) - .send({ origin: owner }); + .send(); await tx.isMined({ interval: 0.1 }); const receipt = await tx.getReceipt(); @@ -117,7 +115,7 @@ describe('e2e_pending_commitments_contract', () => { deployedContract.methods.insert_note.selector.toField(), deployedContract.methods.get_then_nullify_note.selector.toField(), ) - .send({ origin: owner }); + .send(); await tx.isMined({ interval: 0.1 }); const receipt = await tx.getReceipt(); @@ -142,7 +140,7 @@ describe('e2e_pending_commitments_contract', () => { deployedContract.methods.insert_note.selector.toField(), deployedContract.methods.get_then_nullify_note.selector.toField(), ) - .send({ origin: owner }); + .send(); await tx.isMined({ interval: 0.1 }); const receipt = await tx.getReceipt(); @@ -163,7 +161,7 @@ describe('e2e_pending_commitments_contract', () => { const deployedContract = await deployContract(); // create persistent note - const tx0 = deployedContract.methods.insert_note(mintAmount, owner).send({ origin: owner }); + const tx0 = deployedContract.methods.insert_note(mintAmount, owner).send(); await tx0.isMined({ interval: 0.1 }); const receipt0 = await tx0.getReceipt(); @@ -181,7 +179,7 @@ describe('e2e_pending_commitments_contract', () => { deployedContract.methods.get_then_nullify_note.selector.toField(), deployedContract.methods.get_note_zero_balance.selector.toField(), ) - .send({ origin: owner }); + .send(); await tx1.isMined({ interval: 0.1 }); const receipt1 = await tx1.getReceipt(); @@ -203,7 +201,7 @@ describe('e2e_pending_commitments_contract', () => { const mintAmount = 65n; const deployedContract = await deployContract(); - const tx0 = deployedContract.methods.insert_note(mintAmount, owner).send({ origin: owner }); + const tx0 = deployedContract.methods.insert_note(mintAmount, owner).send(); await tx0.isMined({ interval: 0.1 }); const receipt = await tx0.getReceipt(); @@ -220,7 +218,7 @@ describe('e2e_pending_commitments_contract', () => { deployedContract.methods.get_then_nullify_note.selector.toField(), deployedContract.methods.get_note_zero_balance.selector.toField(), ) - .send({ origin: owner }); + .send(); await tx1.isMined({ interval: 0.1 }); const receipt2 = await tx1.getReceipt(); diff --git a/yarn-project/end-to-end/src/e2e_private_token_contract.test.ts b/yarn-project/end-to-end/src/e2e_private_token_contract.test.ts index 84d839908e0..9c1a066f760 100644 --- a/yarn-project/end-to-end/src/e2e_private_token_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_private_token_contract.test.ts @@ -67,7 +67,7 @@ describe('e2e_private_token_contract', () => { await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 0); - const tx = contract.methods.mint(mintAmount, owner).send({ origin: owner }); + const tx = contract.methods.mint(mintAmount, owner).send(); await tx.isMined({ interval: 0.1 }); const receipt = await tx.getReceipt(); @@ -92,7 +92,7 @@ describe('e2e_private_token_contract', () => { await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 1); - const tx = contract.methods.transfer(transferAmount, receiver).send({ origin: owner }); + const tx = contract.methods.transfer(transferAmount, receiver).send(); await tx.isMined({ interval: 0.1 }); const receipt = await tx.getReceipt(); diff --git a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts index 677b2c72599..795101a72e6 100644 --- a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts @@ -70,7 +70,7 @@ describe('e2e_public_cross_chain_messaging', () => { logger('Send L2 tx to withdraw funds'); const withdrawTx = l2Contract.methods .withdrawPublic(withdrawAmount, ethAccount.toField(), EthAddress.ZERO.toField()) - .send({ origin: ownerAddress }); + .send(); await withdrawTx.isMined({ interval: 0.1 }); const withdrawReceipt = await withdrawTx.getReceipt(); diff --git a/yarn-project/end-to-end/src/e2e_public_token_contract.test.ts b/yarn-project/end-to-end/src/e2e_public_token_contract.test.ts index ab554767011..279ed669a5c 100644 --- a/yarn-project/end-to-end/src/e2e_public_token_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_public_token_contract.test.ts @@ -49,7 +49,7 @@ describe('e2e_public_token_contract', () => { await deployContract(); - const tx = contract.methods.mint(mintAmount, recipient).send({ origin: recipient }); + const tx = contract.methods.mint(mintAmount, recipient).send(); await tx.isMined({ interval: 0.1 }); const receipt = await tx.getReceipt(); @@ -70,7 +70,7 @@ describe('e2e_public_token_contract', () => { // Assemble two mint txs sequentially (no parallel calls to circuits!) and send them simultaneously const methods = times(3, () => contract.methods.mint(mintAmount, recipient)); - for (const method of methods) await method.simulate({ origin: recipient }); + for (const method of methods) await method.simulate(); const txs = await Promise.all(methods.map(method => method.send())); // Check that all txs got mined in the same block diff --git a/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts b/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts index 3ab7245f3c6..d71c366c869 100644 --- a/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts +++ b/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts @@ -145,7 +145,7 @@ describe('e2e_sandbox_example', () => { // We will now transfer tokens from ALice to Bob const transferQuantity = 543n; logger(`Transferring ${transferQuantity} tokens from Alice to Bob...`); - await tokenContractAlice.methods.transfer(transferQuantity, bob).send({ origin: alice }).wait(); + await tokenContractAlice.methods.transfer(transferQuantity, bob).send().wait(); // Check the new balances aliceBalance = await tokenContractAlice.methods.getBalance(alice).view(); diff --git a/yarn-project/end-to-end/src/fixtures/cross_chain_test_harness.ts b/yarn-project/end-to-end/src/fixtures/cross_chain_test_harness.ts index 6e6e41ee0b8..ad71a3f1733 100644 --- a/yarn-project/end-to-end/src/fixtures/cross_chain_test_harness.ts +++ b/yarn-project/end-to-end/src/fixtures/cross_chain_test_harness.ts @@ -156,9 +156,7 @@ export class CrossChainTestHarness { async performL2Transfer(transferAmount: bigint) { // send a transfer tx to force through rollup with the message included - const transferTx = this.l2Contract.methods - .transfer(transferAmount, this.receiver) - .send({ origin: this.ownerAddress }); + const transferTx = this.l2Contract.methods.transfer(transferAmount, this.receiver).send(); await transferTx.isMined({ interval: 0.1 }); const transferReceipt = await transferTx.getReceipt(); @@ -171,7 +169,7 @@ export class CrossChainTestHarness { // Call the mint tokens function on the noir contract const consumptionTx = this.l2Contract.methods .mint(bridgeAmount, this.ownerAddress, messageKey, secret, this.ethAccount.toField()) - .send({ origin: this.ownerAddress }); + .send(); await consumptionTx.isMined({ interval: 0.1 }); const consumptionReceipt = await consumptionTx.getReceipt(); @@ -183,7 +181,7 @@ export class CrossChainTestHarness { // Call the mint tokens function on the noir contract const consumptionTx = this.l2Contract.methods .mintPublic(bridgeAmount, this.ownerAddress, messageKey, secret, this.ethAccount.toField()) - .send({ origin: this.ownerAddress }); + .send(); await consumptionTx.isMined({ interval: 0.1 }); const consumptionReceipt = await consumptionTx.getReceipt(); @@ -249,7 +247,7 @@ export class CrossChainTestHarness { async shieldFundsOnL2(shieldAmount: bigint, secretHash: Fr) { this.logger('Shielding funds on L2'); - const shieldTx = this.l2Contract.methods.shield(shieldAmount, secretHash).send({ origin: this.ownerAddress }); + const shieldTx = this.l2Contract.methods.shield(shieldAmount, secretHash).send(); await shieldTx.isMined({ interval: 0.1 }); const shieldReceipt = await shieldTx.getReceipt(); expect(shieldReceipt.status).toBe(TxStatus.MINED); @@ -257,9 +255,7 @@ export class CrossChainTestHarness { async redeemShieldPrivatelyOnL2(shieldAmount: bigint, secret: Fr) { this.logger('Spending commitment in private call'); - const privateTx = this.l2Contract.methods - .redeemShield(shieldAmount, secret, this.ownerAddress) - .send({ origin: this.ownerAddress }); + const privateTx = this.l2Contract.methods.redeemShield(shieldAmount, secret, this.ownerAddress).send(); await privateTx.isMined(); const privateReceipt = await privateTx.getReceipt(); @@ -269,9 +265,7 @@ export class CrossChainTestHarness { async unshieldTokensOnL2(unshieldAmount: bigint) { this.logger('Unshielding tokens'); - const unshieldTx = this.l2Contract.methods - .unshieldTokens(unshieldAmount, this.ownerAddress) - .send({ origin: this.ownerAddress }); + const unshieldTx = this.l2Contract.methods.unshieldTokens(unshieldAmount, this.ownerAddress).send(); await unshieldTx.isMined(); const unshieldReceipt = await unshieldTx.getReceipt(); diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index e9d322e7025..e5333ff9b0d 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -1,34 +1,27 @@ import { AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node'; import { RpcServerConfig, createAztecRPCServer, getConfigEnvVars as getRpcConfigEnvVars } from '@aztec/aztec-rpc'; import { - Account as AztecAccount, + AccountWallet, AztecAddress, CheatCodes, - Contract, - ContractDeployer, - EntrypointCollection, - EntrypointWallet, EthAddress, EthCheatCodes, Wallet, + createAccounts, createAztecRpcClient as createJsonRpcClient, getL1ContractAddresses, - getSandboxAccountsWallet, - getUnsafeSchnorrAccount, + getSandboxAccountsWallets, makeFetch, } from '@aztec/aztec.js'; -import { CompleteAddress, GrumpkinPrivateKey } from '@aztec/circuits.js'; +import { CompleteAddress } from '@aztec/circuits.js'; import { DeployL1Contracts, deployL1Contract, deployL1Contracts } from '@aztec/ethereum'; -import { ContractAbi } from '@aztec/foundation/abi'; -import { Fr, GrumpkinScalar } from '@aztec/foundation/fields'; +import { Fr } from '@aztec/foundation/fields'; import { DebugLogger, createDebugLogger } from '@aztec/foundation/log'; import { retryUntil } from '@aztec/foundation/retry'; import { PortalERC20Abi, PortalERC20Bytecode, TokenPortalAbi, TokenPortalBytecode } from '@aztec/l1-artifacts'; import { NonNativeTokenContract } from '@aztec/noir-contracts/types'; import { AztecRPC, L2BlockL2Logs, LogType, TxStatus } from '@aztec/types'; -import every from 'lodash.every'; -import zipWith from 'lodash.zipwith'; import { Account, Chain, @@ -130,7 +123,6 @@ const setupL1Contracts = async (l1RpcUrl: string, account: HDAccount, logger: De export async function setupAztecRPCServer( numberOfAccounts: number, aztecNode: AztecNodeService | undefined, - firstPrivKey: GrumpkinPrivateKey | null = null, logger = getLogger(), useLogSuffix = false, ): Promise<{ @@ -143,47 +135,33 @@ export async function setupAztecRPCServer( */ accounts: CompleteAddress[]; /** - * The wallet to be used. + * The wallets to be used. */ - wallet: Wallet; + wallets: AccountWallet[]; /** * Logger instance named as the current test. */ logger: DebugLogger; }> { const rpcConfig = getRpcConfigEnvVars(); - const aztecRpcServer = await createRpcServer(rpcConfig, aztecNode, logger, useLogSuffix); + const rpc = await createRpcServer(rpcConfig, aztecNode, logger, useLogSuffix); - const accounts: AztecAccount[] = []; - - const createWalletWithAccounts = async () => { + const createWallets = () => { if (!SANDBOX_URL) { logger('RPC server created, deploying new accounts...'); - - // Prepare deployments - for (let i = 0; i < numberOfAccounts; ++i) { - const privateKey = i === 0 && firstPrivKey !== null ? firstPrivKey! : GrumpkinScalar.random(); - const account = getUnsafeSchnorrAccount(aztecRpcServer, privateKey); - await account.getDeployMethod().then(d => d.simulate({ contractAddressSalt: account.salt })); - accounts.push(account); - } - - // Send them and await them to be mined - const txs = await Promise.all(accounts.map(account => account.deploy())); - await Promise.all(txs.map(tx => tx.wait({ interval: 0.1 }))); - return new EntrypointWallet(aztecRpcServer, await EntrypointCollection.fromAccounts(accounts)); + return createAccounts(rpc, numberOfAccounts); } else { - logger('RPC server created, constructing wallet from initial sandbox accounts...'); - return await getSandboxAccountsWallet(aztecRpcServer); + logger('RPC server created, constructing wallets from initial sandbox accounts...'); + return getSandboxAccountsWallets(rpc); } }; - const wallet = await createWalletWithAccounts(); + const wallets = await createWallets(); return { - aztecRpcServer: aztecRpcServer!, - accounts: await aztecRpcServer!.getAccounts(), - wallet, + aztecRpcServer: rpc!, + accounts: await rpc!.getAccounts(), + wallets, logger, }; } @@ -217,9 +195,13 @@ export async function setup( */ config: AztecNodeConfig; /** - * The wallet to be used. + * The first wallet to be used. */ - wallet: Wallet; + wallet: AccountWallet; + /** + * The wallets to be used. + */ + wallets: AccountWallet[]; /** * Logger instance named as the current test. */ @@ -242,9 +224,6 @@ export async function setup( const deployL1ContractsValues = await setupL1Contracts(config.rpcUrl, hdAccount, logger); const privKeyRaw = hdAccount.getHdKey().privateKey; const publisherPrivKey = privKeyRaw === null ? null : Buffer.from(privKeyRaw); - // TODO(#2052): This reduction is not secure enough. TACKLE THIS ISSUE BEFORE MAINNET. - const firstRpcAccountPrivKey = - publisherPrivKey === null ? null : GrumpkinScalar.fromBufferWithReduction(publisherPrivKey); config.publisherPrivateKey = `0x${publisherPrivKey!.toString('hex')}`; config.rollupContract = deployL1ContractsValues.rollupAddress; @@ -253,12 +232,7 @@ export async function setup( const aztecNode = await createAztecNode(config, logger); - const { aztecRpcServer, accounts, wallet } = await setupAztecRPCServer( - numberOfAccounts, - aztecNode, - firstRpcAccountPrivKey, - logger, - ); + const { aztecRpcServer, accounts, wallets } = await setupAztecRPCServer(numberOfAccounts, aztecNode, logger); const cheatCodes = await CheatCodes.create(config.rpcUrl, aztecRpcServer!); @@ -268,7 +242,8 @@ export async function setup( deployL1ContractsValues, accounts, config, - wallet, + wallet: wallets[0], + wallets, logger, cheatCodes, }; @@ -288,28 +263,6 @@ export async function setNextBlockTimestamp(rpcUrl: string, timestamp: number) { }); } -/** - * Deploys a set of contracts to the network. - * @param wallet - the wallet to make the request. - * @param abi - contracts to be deployed. - * @returns The deployed contract instances. - */ -export async function deployL2Contracts(wallet: Wallet, abis: ContractAbi[]) { - const logger = getLogger(); - const calls = await Promise.all(abis.map(abi => new ContractDeployer(abi, wallet).deploy())); - for (const call of calls) await call.create(); - const txs = await Promise.all(calls.map(c => c.send())); - expect(every(await Promise.all(txs.map(tx => tx.isMined({ interval: 0.1 }))))).toBeTruthy(); - const receipts = await Promise.all(txs.map(tx => tx.getReceipt())); - const contracts = zipWith( - abis, - receipts, - async (abi, receipt) => await Contract.at(receipt!.contractAddress!, abi!, wallet), - ); - contracts.forEach(async c => logger(`L2 contract ${(await c).abi.name} deployed at ${(await c).address}`)); - return contracts; -} - /** * Returns a logger instance for the current test. * @returns a logger instance for the current test. diff --git a/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts b/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts index cc068221806..68f762c7e70 100644 --- a/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts +++ b/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts @@ -3,7 +3,6 @@ import { Account, AccountContract, CompleteAddress, - CreateTxRequestOpts, Entrypoint, FunctionCall, NodeInfo, @@ -42,12 +41,7 @@ class SchnorrHardcodedKeyAccountContract implements AccountContract { // Create a new Entrypoint object, whose responsibility is to turn function calls from the user // into a tx execution request ready to be simulated and sent. return Promise.resolve({ - async createTxExecutionRequest(calls: FunctionCall[], opts: CreateTxRequestOpts = {}) { - // Validate that the requested origin matches (if set) - if (opts.origin && !opts.origin.equals(address)) { - throw new Error(`Sender ${opts.origin.toString()} does not match ${address.toString()}`); - } - + async createTxExecutionRequest(calls: FunctionCall[]) { // Assemble the EntrypointPayload out of the requested calls const { payload, packedArguments: callsPackedArguments } = await buildPayload(calls); diff --git a/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts b/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts index 07a30489ead..d1ee8dbd3fc 100644 --- a/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts +++ b/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts @@ -123,7 +123,7 @@ describe('archiver integration with l1 to l2 messages', () => { it('archiver handles l1 to l2 message correctly even when l2block has no such messages', async () => { // send a transfer tx to force through rollup with the message included const transferAmount = 1n; - l2Contract.methods.transfer(transferAmount, receiver).send({ origin: owner }); + l2Contract.methods.transfer(transferAmount, receiver).send(); expect((await archiver.getPendingL1ToL2Messages(10)).length).toEqual(0); expect(() => archiver.getConfirmedL1ToL2Message(Fr.ZERO)).toThrow(); diff --git a/yarn-project/end-to-end/src/uniswap_trade_on_l1_from_l2.test.ts b/yarn-project/end-to-end/src/uniswap_trade_on_l1_from_l2.test.ts index b92a05134f6..118df9e14b7 100644 --- a/yarn-project/end-to-end/src/uniswap_trade_on_l1_from_l2.test.ts +++ b/yarn-project/end-to-end/src/uniswap_trade_on_l1_from_l2.test.ts @@ -205,7 +205,7 @@ describe('uniswap_trade_on_l1_from_l2', () => { ethAccount.toField(), ethAccount.toField(), ) - .send({ origin: owner }); + .send(); await withdrawTx.isMined({ interval: 0.1 }); const withdrawReceipt = await withdrawTx.getReceipt(); expect(withdrawReceipt.status).toBe(TxStatus.MINED);