From 4f66d2f0c5fbdf712eb352e38d43204363effa57 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 4 Apr 2024 15:11:20 +0000 Subject: [PATCH 1/3] refactor: nuking accounts from e2e setup --- .../src/benchmarks/bench_tx_size_fees.test.ts | 30 +- .../end-to-end/src/e2e_2_pxes.test.ts | 72 ++- .../end-to-end/src/e2e_authwit.test.ts | 8 +- .../src/e2e_blacklist_token_contract.test.ts | 518 +++++++++--------- .../end-to-end/src/e2e_cheat_codes.test.ts | 5 +- .../src/e2e_counter_contract.test.ts | 8 +- .../src/e2e_dapp_subscription.test.ts | 35 +- .../src/e2e_deploy_contract.test.ts | 33 +- .../src/e2e_escrow_contract.test.ts | 20 +- yarn-project/end-to-end/src/e2e_fees.test.ts | 43 +- .../src/e2e_inclusion_proofs_contract.test.ts | 19 +- .../src/e2e_lending_contract.test.ts | 25 +- .../e2e_pending_note_hashes_contract.test.ts | 11 +- .../src/e2e_private_voting_contract.test.ts | 9 +- .../e2e_public_cross_chain_messaging.test.ts | 18 +- .../end-to-end/src/e2e_token_contract.test.ts | 423 +++++++------- yarn-project/end-to-end/src/fixtures/utils.ts | 47 +- .../end-to-end/src/shared/uniswap_l1_l2.ts | 2 +- .../pxe/src/contract_data_oracle/index.ts | 3 + .../pxe/src/database/kv_pxe_database.ts | 1 + .../pxe/src/pxe_service/pxe_service.ts | 1 + .../pxe/src/simulator_oracle/index.ts | 6 + .../src/client/client_execution_context.ts | 1 + 23 files changed, 664 insertions(+), 674 deletions(-) diff --git a/yarn-project/end-to-end/src/benchmarks/bench_tx_size_fees.test.ts b/yarn-project/end-to-end/src/benchmarks/bench_tx_size_fees.test.ts index a786e4d263a..20252e7496f 100644 --- a/yarn-project/end-to-end/src/benchmarks/bench_tx_size_fees.test.ts +++ b/yarn-project/end-to-end/src/benchmarks/bench_tx_size_fees.test.ts @@ -1,50 +1,56 @@ import { - type AccountWalletWithPrivateKey, - type AztecAddress, - type FeePaymentMethod, + type AztecNode, + type DeployL1Contracts, + type EthAddress, NativeFeePaymentMethod, PrivateFeePaymentMethod, PublicFeePaymentMethod, TxStatus, getContractClassFromArtifact, + type AccountWalletWithPrivateKey, + type AztecAddress, + type FeePaymentMethod, } from '@aztec/aztec.js'; import { FPCContract, GasTokenContract, TokenContract } from '@aztec/noir-contracts.js'; import { getCanonicalGasTokenAddress } from '@aztec/protocol-contracts/gas-token'; import { jest } from '@jest/globals'; -import { type EndToEndContext, publicDeployAccounts, setup } from '../fixtures/utils.js'; +import { publicDeployAccounts, setup } from '../fixtures/utils.js'; jest.setTimeout(50_000); describe('benchmarks/tx_size_fees', () => { - let ctx: EndToEndContext; let aliceWallet: AccountWalletWithPrivateKey; let bobAddress: AztecAddress; let sequencerAddress: AztecAddress; let gas: GasTokenContract; let fpc: FPCContract; let token: TokenContract; + let gasPortalAddress: EthAddress; // setup the environment beforeAll(async () => { - ctx = await setup(3); - aliceWallet = ctx.wallets[0]; - bobAddress = ctx.wallets[1].getAddress(); - sequencerAddress = ctx.wallets[2].getAddress(); + const { wallets, aztecNode, deployL1ContractsValues } = await setup(3); + + gasPortalAddress = deployL1ContractsValues.l1ContractAddresses.gasPortalAddress; + + aliceWallet = wallets[0]; + bobAddress = wallets[1].getAddress(); + sequencerAddress = wallets[2].getAddress(); - await ctx.aztecNode.setConfig({ + await aztecNode.setConfig({ feeRecipient: sequencerAddress, allowedFeePaymentContractClasses: [getContractClassFromArtifact(FPCContract.artifact).id], }); - await publicDeployAccounts(aliceWallet, ctx.accounts); + await publicDeployAccounts(aliceWallet, wallets); }); // deploy the contracts beforeAll(async () => { gas = await GasTokenContract.at( - getCanonicalGasTokenAddress(ctx.deployL1ContractsValues.l1ContractAddresses.gasPortalAddress), + getCanonicalGasTokenAddress(gasPortalAddress), aliceWallet, ); token = await TokenContract.deploy(aliceWallet, aliceWallet.getAddress(), 'test', 'test', 18).send().deployed(); diff --git a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts index 2091acb648a..050041098ae 100644 --- a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts +++ b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts @@ -2,7 +2,6 @@ import { getUnsafeSchnorrAccount } from '@aztec/accounts/single_key'; import { type AztecAddress, type AztecNode, - type CompleteAddress, type DebugLogger, ExtendedNote, Fr, @@ -29,29 +28,22 @@ describe('e2e_2_pxes', () => { let pxeB: PXE; let walletA: Wallet; let walletB: Wallet; - let userA: CompleteAddress; - let userB: CompleteAddress; let logger: DebugLogger; let teardownA: () => Promise; beforeEach(async () => { - let accounts: CompleteAddress[] = []; ({ aztecNode, pxe: pxeA, - accounts, wallets: [walletA], logger, teardown: teardownA, } = await setup(1)); - [userA] = accounts; ({ pxe: pxeB, - accounts: accounts, wallets: [walletB], } = await setupPXEService(1, aztecNode!, {}, undefined, true)); - [userB] = accounts; }, 100_000); afterEach(async () => { @@ -121,13 +113,13 @@ describe('e2e_2_pxes', () => { const transferAmount1 = 654n; const transferAmount2 = 323n; - const tokenInstance = await deployTokenContract(initialBalance, userA.address, pxeA); + const tokenInstance = await deployTokenContract(initialBalance, walletA.getAddress(), pxeA); const tokenAddress = tokenInstance.address; // Add account B to wallet A - await pxeA.registerRecipient(userB); + await pxeA.registerRecipient(walletB.getCompleteAddress()); // Add account A to wallet B - await pxeB.registerRecipient(userA); + await pxeB.registerRecipient(walletA.getCompleteAddress()); // Add token to PXE B (PXE A already has it because it was deployed through it) await pxeB.registerContract({ @@ -136,29 +128,29 @@ describe('e2e_2_pxes', () => { }); // Check initial balances and logs are as expected - await expectTokenBalance(walletA, tokenAddress, userA.address, initialBalance); - await expectTokenBalance(walletB, tokenAddress, userB.address, 0n); + await expectTokenBalance(walletA, tokenAddress, walletA.getAddress(), initialBalance); + await expectTokenBalance(walletB, tokenAddress, walletB.getAddress(), 0n); await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 1); // Transfer funds from A to B via PXE A const contractWithWalletA = await TokenContract.at(tokenAddress, walletA); - await contractWithWalletA.methods.transfer(userA.address, userB.address, transferAmount1, 0).send().wait(); + await contractWithWalletA.methods.transfer(walletA.getAddress(), walletB.getAddress(), transferAmount1, 0).send().wait(); // Check balances and logs are as expected - await expectTokenBalance(walletA, tokenAddress, userA.address, initialBalance - transferAmount1); - await expectTokenBalance(walletB, tokenAddress, userB.address, transferAmount1); + await expectTokenBalance(walletA, tokenAddress, walletA.getAddress(), initialBalance - transferAmount1); + await expectTokenBalance(walletB, tokenAddress, walletB.getAddress(), transferAmount1); await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 2); // Transfer funds from B to A via PXE B const contractWithWalletB = await TokenContract.at(tokenAddress, walletB); await contractWithWalletB.methods - .transfer(userB.address, userA.address, transferAmount2, 0) + .transfer(walletB.getAddress(), walletA.getAddress(), transferAmount2, 0) .send() .wait({ interval: 0.1 }); // Check balances and logs are as expected - await expectTokenBalance(walletA, tokenAddress, userA.address, initialBalance - transferAmount1 + transferAmount2); - await expectTokenBalance(walletB, tokenAddress, userB.address, transferAmount1 - transferAmount2); + await expectTokenBalance(walletA, tokenAddress, walletA.getAddress(), initialBalance - transferAmount1 + transferAmount2); + await expectTokenBalance(walletB, tokenAddress, walletB.getAddress(), transferAmount1 - transferAmount2); await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 2); }, 120_000); @@ -209,13 +201,13 @@ describe('e2e_2_pxes', () => { const userABalance = 100n; const userBBalance = 150n; - const tokenInstance = await deployTokenContract(userABalance, userA.address, pxeA); + const tokenInstance = await deployTokenContract(userABalance, walletA.getAddress(), pxeA); const contractWithWalletA = await TokenContract.at(tokenInstance.address, walletA); // Add account B to wallet A - await pxeA.registerRecipient(userB); + await pxeA.registerRecipient(walletB.getCompleteAddress()); // Add account A to wallet B - await pxeB.registerRecipient(userA); + await pxeB.registerRecipient(walletA.getCompleteAddress()); // Add token to PXE B (PXE A already has it because it was deployed through it) await pxeB.registerContract({ @@ -224,20 +216,20 @@ describe('e2e_2_pxes', () => { }); // Mint tokens to user B - await mintTokens(contractWithWalletA, userB.address, userBBalance, pxeA); + await mintTokens(contractWithWalletA, walletB.getAddress(), userBBalance, pxeA); // Check that user A balance is 100 on server A - await expectTokenBalance(walletA, tokenInstance.address, userA.address, userABalance); + await expectTokenBalance(walletA, tokenInstance.address, walletA.getAddress(), userABalance); // Check that user B balance is 150 on server B - await expectTokenBalance(walletB, tokenInstance.address, userB.address, userBBalance); + await expectTokenBalance(walletB, tokenInstance.address, walletB.getAddress(), userBBalance); // CHECK THAT PRIVATE BALANCES ARE 0 WHEN ACCOUNT'S PRIVATE KEYS ARE NOT REGISTERED // Note: Not checking if the account is synchronized because it is not registered as an account (it would throw). const checkIfSynchronized = false; // Check that user A balance is 0 on server B - await expectTokenBalance(walletB, tokenInstance.address, userA.address, 0n, checkIfSynchronized); + await expectTokenBalance(walletB, tokenInstance.address, walletA.getAddress(), 0n, checkIfSynchronized); // Check that user B balance is 0 on server A - await expectTokenBalance(walletA, tokenInstance.address, userB.address, 0n, checkIfSynchronized); + await expectTokenBalance(walletA, tokenInstance.address, walletB.getAddress(), 0n, checkIfSynchronized); }); it('permits migrating an account from one PXE to another', async () => { @@ -262,31 +254,31 @@ describe('e2e_2_pxes', () => { const initialBalance = 987n; const transferAmount1 = 654n; - const tokenInstance = await deployTokenContract(initialBalance, userA.address, pxeA); + const tokenInstance = await deployTokenContract(initialBalance, walletA.getAddress(), pxeA); const tokenAddress = tokenInstance.address; // Add account B to wallet A - await pxeA.registerRecipient(userB); + await pxeA.registerRecipient(walletB.getCompleteAddress()); // Add account A to wallet B - await pxeB.registerRecipient(userA); + await pxeB.registerRecipient(walletA.getCompleteAddress()); // Check initial balances and logs are as expected - await expectTokenBalance(walletA, tokenAddress, userA.address, initialBalance); + await expectTokenBalance(walletA, tokenAddress, walletA.getAddress(), initialBalance); // don't check userB yet await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 1); // Transfer funds from A to B via PXE A const contractWithWalletA = await TokenContract.at(tokenAddress, walletA); - await contractWithWalletA.methods.transfer(userA.address, userB.address, transferAmount1, 0).send().wait(); + await contractWithWalletA.methods.transfer(walletA.getAddress(), walletB.getAddress(), transferAmount1, 0).send().wait(); // now add the contract and check balances await pxeB.registerContract({ artifact: TokenContract.artifact, instance: tokenInstance, }); - await expectTokenBalance(walletA, tokenAddress, userA.address, initialBalance - transferAmount1); - await expectTokenBalance(walletB, tokenAddress, userB.address, transferAmount1); + await expectTokenBalance(walletA, tokenAddress, walletA.getAddress(), initialBalance - transferAmount1); + await expectTokenBalance(walletB, tokenAddress, walletB.getAddress(), transferAmount1); }); it('permits sending funds to a user, and spending them, before they have registered the contract', async () => { @@ -305,28 +297,28 @@ describe('e2e_2_pxes', () => { await sharedAccountOnB.register(); const sharedWalletOnB = await sharedAccountOnB.getWallet(); - await pxeA.registerRecipient(userB); + await pxeA.registerRecipient(walletB.getCompleteAddress()); // deploy the contract on PXE A - const tokenInstance = await deployTokenContract(initialBalance, userA.address, pxeA); + const tokenInstance = await deployTokenContract(initialBalance, walletA.getAddress(), pxeA); const tokenAddress = tokenInstance.address; // Transfer funds from A to Shared Wallet via PXE A const contractWithWalletA = await TokenContract.at(tokenAddress, walletA); await contractWithWalletA.methods - .transfer(userA.address, sharedAccountAddress.address, transferAmount1, 0) + .transfer(walletA.getAddress(), sharedAccountAddress.address, transferAmount1, 0) .send() .wait(); // Now send funds from Shared Wallet to B via PXE A const contractWithSharedWalletA = await TokenContract.at(tokenAddress, sharedWalletOnA); await contractWithSharedWalletA.methods - .transfer(sharedAccountAddress.address, userB.address, transferAmount2, 0) + .transfer(sharedAccountAddress.address, walletB.getAddress(), transferAmount2, 0) .send() .wait(); // check balances from PXE-A's perspective - await expectTokenBalance(walletA, tokenAddress, userA.address, initialBalance - transferAmount1); + await expectTokenBalance(walletA, tokenAddress, walletA.getAddress(), initialBalance - transferAmount1); await expectTokenBalance( sharedWalletOnA, tokenAddress, @@ -343,7 +335,7 @@ describe('e2e_2_pxes', () => { artifact: TokenContract.artifact, instance: tokenInstance, }); - await expectTokenBalance(walletB, tokenAddress, userB.address, transferAmount2); + await expectTokenBalance(walletB, tokenAddress, walletB.getAddress(), transferAmount2); await expect(sharedWalletOnB.isAccountStateSynchronized(sharedAccountAddress.address)).resolves.toBe(true); await expectTokenBalance( sharedWalletOnB, diff --git a/yarn-project/end-to-end/src/e2e_authwit.test.ts b/yarn-project/end-to-end/src/e2e_authwit.test.ts index 44fb5e83da2..e3c46af3e73 100644 --- a/yarn-project/end-to-end/src/e2e_authwit.test.ts +++ b/yarn-project/end-to-end/src/e2e_authwit.test.ts @@ -1,9 +1,8 @@ import { - type AccountWallet, - type CompleteAddress, Fr, computeInnerAuthWitHash, computeOuterAuthWitHash, + type AccountWallet } from '@aztec/aztec.js'; import { SchnorrAccountContract } from '@aztec/noir-contracts.js'; @@ -17,14 +16,13 @@ describe('e2e_authwit_tests', () => { jest.setTimeout(TIMEOUT); let wallets: AccountWallet[]; - let accounts: CompleteAddress[]; let chainId: Fr; let version: Fr; beforeAll(async () => { - ({ wallets, accounts } = await setup(2)); - await publicDeployAccounts(wallets[0], accounts.slice(0, 2)); + ({ wallets } = await setup(2)); + await publicDeployAccounts(wallets[0], wallets.slice(0, 2)); const nodeInfo = await wallets[0].getNodeInfo(); chainId = new Fr(nodeInfo.chainId); diff --git a/yarn-project/end-to-end/src/e2e_blacklist_token_contract.test.ts b/yarn-project/end-to-end/src/e2e_blacklist_token_contract.test.ts index 622fb312b72..580f3c02803 100644 --- a/yarn-project/end-to-end/src/e2e_blacklist_token_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_blacklist_token_contract.test.ts @@ -1,17 +1,16 @@ import { - type AccountWallet, AztecAddress, - type CheatCodes, - type CompleteAddress, - type DebugLogger, ExtendedNote, Fr, FunctionSelector, Note, - type TxHash, - type Wallet, computeAuthWitMessageHash, computeMessageSecretHash, + type AccountWallet, + type CheatCodes, + type DebugLogger, + type TxHash, + type Wallet } from '@aztec/aztec.js'; import { openTmpStore } from '@aztec/kv-store/utils'; import { Pedersen, SparseTree, newTree } from '@aztec/merkle-tree'; @@ -30,7 +29,6 @@ describe('e2e_blacklist_token_contract', () => { let teardown: () => Promise; let wallets: AccountWallet[]; - let accounts: CompleteAddress[]; let logger: DebugLogger; let asset: TokenBlacklistContract; @@ -92,7 +90,7 @@ describe('e2e_blacklist_token_contract', () => { const note = new Note([new Fr(amount), secretHash]); const extendedNote = new ExtendedNote( note, - accounts[accountIndex].address, + wallets[accountIndex].getAddress(), asset.address, storageSlot, noteTypeId, @@ -107,8 +105,8 @@ describe('e2e_blacklist_token_contract', () => { }; beforeAll(async () => { - ({ teardown, logger, wallets, accounts, cheatCodes } = await setup(4)); - await publicDeployAccounts(wallets[0], accounts.slice(0, 3)); + ({ teardown, logger, wallets, cheatCodes } = await setup(4)); + await publicDeployAccounts(wallets[0], wallets.slice(0, 3)); slowTree = await SlowTreeContract.deploy(wallets[0]).send().deployed(); @@ -116,20 +114,20 @@ describe('e2e_blacklist_token_contract', () => { slowUpdateTreeSimulator = await newTree(SparseTree, openTmpStore(), new Pedersen(), 'test', Fr, depth); // Add account[0] as admin - await updateSlowTree(slowUpdateTreeSimulator, wallets[0], accounts[0].address, 4n); + await updateSlowTree(slowUpdateTreeSimulator, wallets[0], wallets[0].getAddress(), 4n); - const deployTx = TokenBlacklistContract.deploy(wallets[0], accounts[0], slowTree.address).send({}); + const deployTx = TokenBlacklistContract.deploy(wallets[0], wallets[0].getAddress(), slowTree.address).send({}); const receipt = await deployTx.wait(); asset = receipt.contract; - await asset.methods.init_slow_tree(accounts[0].address).send().wait(); + await asset.methods.init_slow_tree(wallets[0].getAddress()).send().wait(); // Progress to next "epoch" const time = await cheatCodes.eth.timestamp(); await cheatCodes.aztec.warp(time + 200); await slowUpdateTreeSimulator.commit(); - const roleLeaf = await slowTree.methods.un_read_leaf_at(asset.address, accounts[0].address).simulate(); + const roleLeaf = await slowTree.methods.un_read_leaf_at(asset.address, wallets[0].getAddress()).simulate(); expect(roleLeaf['next_change']).toBeGreaterThan(0n); expect(roleLeaf['before']).toEqual(0n); expect(roleLeaf['after']).toEqual(4n); @@ -138,7 +136,7 @@ describe('e2e_blacklist_token_contract', () => { tokenSim = new TokenSimulator( asset as unknown as TokenContract, logger, - accounts.map(a => a.address), + wallets.map(a => a.getAddress()), ); asset.artifact.functions.forEach(fn => { @@ -159,7 +157,7 @@ describe('e2e_blacklist_token_contract', () => { describe('Access controlled functions', () => { it('Extend account[0] roles with minter as admin', async () => { - const newMinter = accounts[0].address; + const newMinter = wallets[0].getAddress(); const newRoles = 2n + 4n; const beforeLeaf = await slowTree.methods.un_read_leaf_at(asset.address, newMinter).simulate(); @@ -170,7 +168,7 @@ describe('e2e_blacklist_token_contract', () => { await updateSlowTree(slowUpdateTreeSimulator, wallets[0], newMinter, newRoles); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), false)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), false)), ); await asset.methods.update_roles(newMinter, newRoles).send().wait(); @@ -186,7 +184,7 @@ describe('e2e_blacklist_token_contract', () => { }); it('Make account[1] admin', async () => { - const newAdmin = accounts[1].address; + const newAdmin = wallets[1].getAddress(); const newRoles = 4n; let v = await slowTree.methods.un_read_leaf_at(asset.address, newAdmin).simulate(); @@ -195,7 +193,7 @@ describe('e2e_blacklist_token_contract', () => { await updateSlowTree(slowUpdateTreeSimulator, wallets[0], newAdmin, newRoles); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), false)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), false)), ); await asset.methods.update_roles(newAdmin, newRoles).send().wait(); @@ -212,7 +210,7 @@ describe('e2e_blacklist_token_contract', () => { }); it('Revoke admin as admin', async () => { - const actor = accounts[1].address; + const actor = wallets[1].getAddress(); const newRoles = 0n; const currentRoles = 4n; @@ -224,7 +222,7 @@ describe('e2e_blacklist_token_contract', () => { await updateSlowTree(slowUpdateTreeSimulator, wallets[0], actor, newRoles); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), false)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), false)), ); await asset.methods.update_roles(actor, newRoles).send().wait(); @@ -240,19 +238,19 @@ describe('e2e_blacklist_token_contract', () => { }); it('Add account[3] to blacklist', async () => { - let v = await slowTree.methods.un_read_leaf_at(asset.address, accounts[3].address).simulate(); + let v = await slowTree.methods.un_read_leaf_at(asset.address, wallets[3].getAddress()).simulate(); // eslint-disable-next-line camelcase expect(v).toEqual({ next_change: 0n, before: 0n, after: 0n }); - await updateSlowTree(slowUpdateTreeSimulator, wallets[0], accounts[3].address, 1n); + await updateSlowTree(slowUpdateTreeSimulator, wallets[0], wallets[3].getAddress(), 1n); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), false)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), false)), ); - await asset.methods.update_roles(accounts[3].address, 1n).send().wait(); + await asset.methods.update_roles(wallets[3].getAddress(), 1n).send().wait(); await slowUpdateTreeSimulator.commit(); - v = await slowTree.methods.un_read_leaf_at(asset.address, accounts[3].address).simulate(); + v = await slowTree.methods.un_read_leaf_at(asset.address, wallets[3].getAddress()).simulate(); expect(v['next_change']).toBeGreaterThan(0n); expect(v['before']).toEqual(0n); expect(v['after']).toEqual(1n); @@ -270,7 +268,7 @@ describe('e2e_blacklist_token_contract', () => { expect(v).toEqual({ next_change: 0n, before: 0n, after: 0n }); await wallets[3].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[3].address.toBigInt(), false)), + getMembershipCapsule(await getMembershipProof(wallets[3].getAddress().toBigInt(), false)), ); await expect(asset.withWallet(wallets[3]).methods.update_roles(account, newRoles).prove()).rejects.toThrow( "Assertion failed: caller is not admin 'caller_roles.is_admin'", @@ -278,7 +276,7 @@ describe('e2e_blacklist_token_contract', () => { }); it('Revoke minter not as admin', async () => { - const adminAccount = accounts[0].address; + const adminAccount = wallets[0].getAddress(); const v = await slowTree.methods.un_read_leaf_at(asset.address, adminAccount).simulate(); const newRoles = 0n; // eslint-disable-next-line camelcase @@ -287,7 +285,7 @@ describe('e2e_blacklist_token_contract', () => { expect(v['after']).toEqual(6n); await wallets[3].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[3].address.toBigInt(), false)), + getMembershipCapsule(await getMembershipProof(wallets[3].getAddress().toBigInt(), false)), ); await expect(asset.withWallet(wallets[3]).methods.update_roles(adminAccount, newRoles).prove()).rejects.toThrow( "Assertion failed: caller is not admin 'caller_roles.is_admin'", @@ -300,11 +298,11 @@ describe('e2e_blacklist_token_contract', () => { describe('Public', () => { it('as minter', async () => { const amount = 10000n; - await asset.methods.mint_public(accounts[0].address, amount).send().wait(); + await asset.methods.mint_public(wallets[0].getAddress(), amount).send().wait(); - tokenSim.mintPublic(accounts[0].address, amount); - expect(await asset.methods.balance_of_public(accounts[0].address).simulate()).toEqual( - tokenSim.balanceOfPublic(accounts[0].address), + tokenSim.mintPublic(wallets[0].getAddress(), amount); + expect(await asset.methods.balance_of_public(wallets[0].getAddress()).simulate()).toEqual( + tokenSim.balanceOfPublic(wallets[0].getAddress()), ); expect(await asset.methods.total_supply().simulate()).toEqual(tokenSim.totalSupply); }); @@ -313,34 +311,34 @@ describe('e2e_blacklist_token_contract', () => { it('as non-minter', async () => { const amount = 10000n; await expect( - asset.withWallet(wallets[1]).methods.mint_public(accounts[0].address, amount).prove(), + asset.withWallet(wallets[1]).methods.mint_public(wallets[0].getAddress(), amount).prove(), ).rejects.toThrow('Assertion failed: caller is not minter'); }); it('mint >u128 tokens to overflow', async () => { const amount = 2n ** 128n; // U128::max() + 1; - await expect(asset.methods.mint_public(accounts[0].address, amount).prove()).rejects.toThrow( + await expect(asset.methods.mint_public(wallets[0].getAddress(), amount).prove()).rejects.toThrow( BITSIZE_TOO_BIG_ERROR, ); }); it('mint u128', async () => { - const amount = 2n ** 128n - tokenSim.balanceOfPublic(accounts[0].address); - await expect(asset.methods.mint_public(accounts[0].address, amount).prove()).rejects.toThrow( + const amount = 2n ** 128n - tokenSim.balanceOfPublic(wallets[0].getAddress()); + await expect(asset.methods.mint_public(wallets[0].getAddress(), amount).prove()).rejects.toThrow( U128_OVERFLOW_ERROR, ); }); it('mint u128', async () => { - const amount = 2n ** 128n - tokenSim.balanceOfPublic(accounts[0].address); - await expect(asset.methods.mint_public(accounts[1].address, amount).prove()).rejects.toThrow( + const amount = 2n ** 128n - tokenSim.balanceOfPublic(wallets[0].getAddress()); + await expect(asset.methods.mint_public(wallets[1].getAddress(), amount).prove()).rejects.toThrow( U128_OVERFLOW_ERROR, ); }); it('mint to blacklisted entity', async () => { await expect( - asset.withWallet(wallets[1]).methods.mint_public(accounts[3].address, 1n).prove(), + asset.withWallet(wallets[1]).methods.mint_public(wallets[3].getAddress(), 1n).prove(), ).rejects.toThrow("Assertion failed: Blacklisted: Recipient '!to_roles.is_blacklisted'"); }); }); @@ -366,13 +364,13 @@ describe('e2e_blacklist_token_contract', () => { it('redeem as recipient', async () => { await addPendingShieldNoteToPXE(0, amount, secretHash, txHash); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); const receiptClaim = await asset.methods - .redeem_shield(accounts[0].address, amount, secret) + .redeem_shield(wallets[0].getAddress(), amount, secret) .send() .wait({ debug: true }); - tokenSim.redeemShield(accounts[0].address, amount); + tokenSim.redeemShield(wallets[0].getAddress(), amount); // 1 note should be created containing `amount` of tokens const { visibleNotes } = receiptClaim.debugInfo!; expect(visibleNotes.length).toBe(1); @@ -386,9 +384,9 @@ describe('e2e_blacklist_token_contract', () => { 'The note has been destroyed.', ); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); - await expect(asset.methods.redeem_shield(accounts[0].address, amount, secret).prove()).rejects.toThrow( + await expect(asset.methods.redeem_shield(wallets[0].getAddress(), amount, secret).prove()).rejects.toThrow( `Assertion failed: Cannot return zero notes`, ); }); @@ -406,7 +404,7 @@ describe('e2e_blacklist_token_contract', () => { it('mint u128', async () => { // @todo @LHerskind this one don't make sense. It fails because of total supply overflowing. - const amount = 2n ** 128n - tokenSim.balanceOfPrivate(accounts[0].address); + const amount = 2n ** 128n - tokenSim.balanceOfPrivate(wallets[0].getAddress()); expect(amount).toBeLessThan(2n ** 128n); await expect(asset.methods.mint_private(amount, secretHash).prove()).rejects.toThrow(U128_OVERFLOW_ERROR); }); @@ -418,9 +416,9 @@ describe('e2e_blacklist_token_contract', () => { it('mint and try to redeem at blacklist', async () => { await wallets[3].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[3].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[3].getAddress().toBigInt(), true)), ); - await expect(asset.methods.redeem_shield(accounts[3].address, amount, secret).prove()).rejects.toThrow( + await expect(asset.methods.redeem_shield(wallets[3].getAddress(), amount, secret).prove()).rejects.toThrow( "Assertion failed: Blacklisted: Recipient '!to_roles.is_blacklisted'", ); }); @@ -431,25 +429,25 @@ describe('e2e_blacklist_token_contract', () => { describe('Transfer', () => { describe('public', () => { it('transfer less than balance', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; expect(amount).toBeGreaterThan(0n); - await asset.methods.transfer_public(accounts[0].address, accounts[1].address, amount, 0).send().wait(); + await asset.methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, 0).send().wait(); - tokenSim.transferPublic(accounts[0].address, accounts[1].address, amount); + tokenSim.transferPublic(wallets[0].getAddress(), wallets[1].getAddress(), amount); }); it('transfer to self', async () => { - const balance = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance / 2n; expect(amount).toBeGreaterThan(0n); - await asset.methods.transfer_public(accounts[0].address, accounts[0].address, amount, 0).send().wait(); + await asset.methods.transfer_public(wallets[0].getAddress(), wallets[0].getAddress(), amount, 0).send().wait(); - tokenSim.transferPublic(accounts[0].address, accounts[0].address, amount); + tokenSim.transferPublic(wallets[0].getAddress(), wallets[0].getAddress(), amount); }); it('transfer on behalf of other', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; expect(amount).toBeGreaterThan(0n); const nonce = Fr.random(); @@ -457,79 +455,79 @@ describe('e2e_blacklist_token_contract', () => { // docs:start:authwit_public_transfer_example const action = asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); - await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, true).send().wait(); + await wallets[0].setPublicAuthWit({ caller: wallets[1].getAddress(), action }, true).send().wait(); // docs:end:authwit_public_transfer_example // Perform the transfer await action.send().wait(); - tokenSim.transferPublic(accounts[0].address, accounts[1].address, amount); + tokenSim.transferPublic(wallets[0].getAddress(), wallets[1].getAddress(), amount); // Check that the message hash is no longer valid. Need to try to send since nullifiers are handled by sequencer. const txReplay = asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce) + .methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce) .send(); await expect(txReplay.wait()).rejects.toThrow('Transaction '); }); describe('failure cases', () => { it('transfer more than balance', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 + 1n; const nonce = 0; await expect( - asset.methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce).prove(), + asset.methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce).prove(), ).rejects.toThrow(U128_UNDERFLOW_ERROR); }); it('transfer on behalf of self with non-zero nonce', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 - 1n; const nonce = 1; await expect( - asset.methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce).prove(), + asset.methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce).prove(), ).rejects.toThrow('Assertion failed: invalid nonce'); }); it('transfer on behalf of other without "approval"', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 + 1n; const nonce = Fr.random(); await expect( asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce) + .methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce) .prove(), ).rejects.toThrow('Assertion failed: Message not authorized by account'); }); it('transfer more than balance on behalf of other', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); - const balance1 = await asset.methods.balance_of_public(accounts[1].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); + const balance1 = await asset.methods.balance_of_public(wallets[1].getAddress()).simulate(); const amount = balance0 + 1n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); const action = asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); // We need to compute the message we want to sign and add it to the wallet as approved - await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, true).send().wait(); + await wallets[0].setPublicAuthWit({ caller: wallets[1].getAddress(), action }, true).send().wait(); // Perform the transfer await expect(action.prove()).rejects.toThrow(U128_UNDERFLOW_ERROR); - expect(await asset.methods.balance_of_public(accounts[0].address).simulate()).toEqual(balance0); - expect(await asset.methods.balance_of_public(accounts[1].address).simulate()).toEqual(balance1); + expect(await asset.methods.balance_of_public(wallets[0].getAddress()).simulate()).toEqual(balance0); + expect(await asset.methods.balance_of_public(wallets[1].getAddress()).simulate()).toEqual(balance1); }); it('transfer on behalf of other, wrong designated caller', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); - const balance1 = await asset.methods.balance_of_public(accounts[1].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); + const balance1 = await asset.methods.balance_of_public(wallets[1].getAddress()).simulate(); const amount = balance0 + 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); @@ -537,20 +535,20 @@ describe('e2e_blacklist_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); - await wallets[0].setPublicAuthWit({ caller: accounts[0].address, action }, true).send().wait(); + await wallets[0].setPublicAuthWit({ caller: wallets[0].getAddress(), action }, true).send().wait(); // Perform the transfer await expect(action.prove()).rejects.toThrow('Assertion failed: Message not authorized by account'); - expect(await asset.methods.balance_of_public(accounts[0].address).simulate()).toEqual(balance0); - expect(await asset.methods.balance_of_public(accounts[1].address).simulate()).toEqual(balance1); + expect(await asset.methods.balance_of_public(wallets[0].getAddress()).simulate()).toEqual(balance0); + expect(await asset.methods.balance_of_public(wallets[1].getAddress()).simulate()).toEqual(balance1); }); it('transfer on behalf of other, wrong designated caller', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); - const balance1 = await asset.methods.balance_of_public(accounts[1].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); + const balance1 = await asset.methods.balance_of_public(wallets[1].getAddress()).simulate(); const amount = balance0 + 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); @@ -558,14 +556,14 @@ describe('e2e_blacklist_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); - await wallets[0].setPublicAuthWit({ caller: accounts[0].address, action }, true).send().wait(); + .methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); + await wallets[0].setPublicAuthWit({ caller: wallets[0].getAddress(), action }, true).send().wait(); // Perform the transfer await expect(action.prove()).rejects.toThrow('Assertion failed: Message not authorized by account'); - expect(await asset.methods.balance_of_public(accounts[0].address).simulate()).toEqual(balance0); - expect(await asset.methods.balance_of_public(accounts[1].address).simulate()).toEqual(balance1); + expect(await asset.methods.balance_of_public(wallets[0].getAddress()).simulate()).toEqual(balance0); + expect(await asset.methods.balance_of_public(wallets[1].getAddress()).simulate()).toEqual(balance1); }); it.skip('transfer into account to overflow', () => { @@ -577,13 +575,13 @@ describe('e2e_blacklist_token_contract', () => { it('transfer from a blacklisted account', async () => { await expect( - asset.methods.transfer_public(accounts[3].address, accounts[0].address, 1n, 0n).prove(), + asset.methods.transfer_public(wallets[3].getAddress(), wallets[0].getAddress(), 1n, 0n).prove(), ).rejects.toThrow("Assertion failed: Blacklisted: Sender '!from_roles.is_blacklisted'"); }); it('transfer to a blacklisted account', async () => { await expect( - asset.methods.transfer_public(accounts[0].address, accounts[3].address, 1n, 0n).prove(), + asset.methods.transfer_public(wallets[0].getAddress(), wallets[3].getAddress(), 1n, 0n).prove(), ).rejects.toThrow("Assertion failed: Blacklisted: Recipient '!to_roles.is_blacklisted'"); }); }); @@ -591,35 +589,35 @@ describe('e2e_blacklist_token_contract', () => { describe('private', () => { it('transfer less than balance', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; expect(amount).toBeGreaterThan(0n); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[1].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[1].getAddress().toBigInt(), true)), ); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); - await asset.methods.transfer(accounts[0].address, accounts[1].address, amount, 0).send().wait(); - tokenSim.transferPrivate(accounts[0].address, accounts[1].address, amount); + await asset.methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, 0).send().wait(); + tokenSim.transferPrivate(wallets[0].getAddress(), wallets[1].getAddress(), amount); }); it('transfer to self', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; expect(amount).toBeGreaterThan(0n); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); - await asset.methods.transfer(accounts[0].address, accounts[0].address, amount, 0).send().wait(); - tokenSim.transferPrivate(accounts[0].address, accounts[0].address, amount); + await asset.methods.transfer(wallets[0].getAddress(), wallets[0].getAddress(), amount, 0).send().wait(); + tokenSim.transferPrivate(wallets[0].getAddress(), wallets[0].getAddress(), amount); }); it('transfer on behalf of other', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); @@ -629,72 +627,72 @@ describe('e2e_blacklist_token_contract', () => { // docs:start:authwit_computeAuthWitMessageHash const action = asset .withWallet(wallets[1]) - .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); // docs:end:authwit_computeAuthWitMessageHash - const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); + const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); await wallets[1].addAuthWitness(witness); // docs:end:authwit_transfer_example await wallets[1].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[1].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[1].getAddress().toBigInt(), true)), ); await wallets[1].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); // Perform the transfer await action.send().wait(); - tokenSim.transferPrivate(accounts[0].address, accounts[1].address, amount); + tokenSim.transferPrivate(wallets[0].getAddress(), wallets[1].getAddress(), amount); await wallets[1].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[1].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[1].getAddress().toBigInt(), true)), ); await wallets[1].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); // Perform the transfer again, should fail const txReplay = asset .withWallet(wallets[1]) - .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce) + .methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce) .send(); await expect(txReplay.wait()).rejects.toThrow('Transaction '); }); describe('failure cases', () => { it('transfer more than balance', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 + 1n; expect(amount).toBeGreaterThan(0n); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[1].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[1].getAddress().toBigInt(), true)), ); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); await expect( - asset.methods.transfer(accounts[0].address, accounts[1].address, amount, 0).prove(), + asset.methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, 0).prove(), ).rejects.toThrow('Assertion failed: Balance too low'); }); it('transfer on behalf of self with non-zero nonce', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 - 1n; expect(amount).toBeGreaterThan(0n); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[1].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[1].getAddress().toBigInt(), true)), ); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); await expect( - asset.methods.transfer(accounts[0].address, accounts[1].address, amount, 1).prove(), + asset.methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, 1).prove(), ).rejects.toThrow('Assertion failed: invalid nonce'); }); it('transfer more than balance on behalf of other', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); - const balance1 = await asset.methods.balance_of_private(accounts[1].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); + const balance1 = await asset.methods.balance_of_private(wallets[1].getAddress()).simulate(); const amount = balance0 + 1n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); @@ -702,23 +700,23 @@ describe('e2e_blacklist_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[1]) - .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. - const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); + const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); await wallets[1].addAuthWitness(witness); await wallets[1].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[1].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[1].getAddress().toBigInt(), true)), ); await wallets[1].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); // Perform the transfer await expect(action.prove()).rejects.toThrow('Assertion failed: Balance too low'); - expect(await asset.methods.balance_of_private(accounts[0].address).simulate()).toEqual(balance0); - expect(await asset.methods.balance_of_private(accounts[1].address).simulate()).toEqual(balance1); + expect(await asset.methods.balance_of_private(wallets[0].getAddress()).simulate()).toEqual(balance0); + expect(await asset.methods.balance_of_private(wallets[1].getAddress()).simulate()).toEqual(balance1); }); it.skip('transfer into account to overflow', () => { @@ -729,7 +727,7 @@ describe('e2e_blacklist_token_contract', () => { }); it('transfer on behalf of other without approval', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); @@ -737,18 +735,18 @@ describe('e2e_blacklist_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[1]) - .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); const messageHash = computeAuthWitMessageHash( - accounts[1].address, + wallets[1].getAddress(), wallets[0].getChainId(), wallets[0].getVersion(), action.request(), ); await wallets[1].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[1].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[1].getAddress().toBigInt(), true)), ); await wallets[1].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); await expect(action.prove()).rejects.toThrow( @@ -757,7 +755,7 @@ describe('e2e_blacklist_token_contract', () => { }); it('transfer on behalf of other, wrong designated caller', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); @@ -765,49 +763,49 @@ describe('e2e_blacklist_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[2]) - .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); const expectedMessageHash = computeAuthWitMessageHash( - accounts[2].address, + wallets[2].getAddress(), wallets[0].getChainId(), wallets[0].getVersion(), action.request(), ); - const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); + const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); await wallets[2].addAuthWitness(witness); await wallets[2].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[1].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[1].getAddress().toBigInt(), true)), ); await wallets[2].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); await expect(action.prove()).rejects.toThrow( `Unknown auth witness for message hash ${expectedMessageHash.toString()}`, ); - expect(await asset.methods.balance_of_private(accounts[0].address).simulate()).toEqual(balance0); + expect(await asset.methods.balance_of_private(wallets[0].getAddress()).simulate()).toEqual(balance0); }); it('transfer from a blacklisted account', async () => { await wallets[3].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); await wallets[3].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[3].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[3].getAddress().toBigInt(), true)), ); - await expect(asset.methods.transfer(accounts[3].address, accounts[0].address, 1n, 0).prove()).rejects.toThrow( + await expect(asset.methods.transfer(wallets[3].getAddress(), wallets[0].getAddress(), 1n, 0).prove()).rejects.toThrow( "Assertion failed: Blacklisted: Sender '!from_roles.is_blacklisted'", ); }); it('transfer to a blacklisted account', async () => { await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[3].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[3].getAddress().toBigInt(), true)), ); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); - await expect(asset.methods.transfer(accounts[0].address, accounts[3].address, 1n, 0).prove()).rejects.toThrow( + await expect(asset.methods.transfer(wallets[0].getAddress(), wallets[3].getAddress(), 1n, 0).prove()).rejects.toThrow( "Assertion failed: Blacklisted: Recipient '!to_roles.is_blacklisted'", ); }); @@ -824,117 +822,117 @@ describe('e2e_blacklist_token_contract', () => { }); it('on behalf of self', async () => { - const balancePub = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balancePub = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balancePub / 2n; expect(amount).toBeGreaterThan(0n); - const receipt = await asset.methods.shield(accounts[0].address, amount, secretHash, 0).send().wait(); + const receipt = await asset.methods.shield(wallets[0].getAddress(), amount, secretHash, 0).send().wait(); - tokenSim.shield(accounts[0].address, amount); + tokenSim.shield(wallets[0].getAddress(), amount); await tokenSim.check(); // Redeem it await addPendingShieldNoteToPXE(0, amount, secretHash, receipt.txHash); - await wallets[0].addCapsule(getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true))); - await asset.methods.redeem_shield(accounts[0].address, amount, secret).send().wait(); + await wallets[0].addCapsule(getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true))); + await asset.methods.redeem_shield(wallets[0].getAddress(), amount, secret).send().wait(); - tokenSim.redeemShield(accounts[0].address, amount); + tokenSim.redeemShield(wallets[0].getAddress(), amount); }); it('on behalf of other', async () => { - const balancePub = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balancePub = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balancePub / 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset.withWallet(wallets[1]).methods.shield(accounts[0].address, amount, secretHash, nonce); - await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, true).send().wait(); + const action = asset.withWallet(wallets[1]).methods.shield(wallets[0].getAddress(), amount, secretHash, nonce); + await wallets[0].setPublicAuthWit({ caller: wallets[1].getAddress(), action }, true).send().wait(); const receipt = await action.send().wait(); - tokenSim.shield(accounts[0].address, amount); + tokenSim.shield(wallets[0].getAddress(), amount); await tokenSim.check(); // Check that replaying the shield should fail! const txReplay = asset .withWallet(wallets[1]) - .methods.shield(accounts[0].address, amount, secretHash, nonce) + .methods.shield(wallets[0].getAddress(), amount, secretHash, nonce) .send(); await expect(txReplay.wait()).rejects.toThrow('Transaction '); // Redeem it await addPendingShieldNoteToPXE(0, amount, secretHash, receipt.txHash); - await wallets[0].addCapsule(getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true))); - await asset.methods.redeem_shield(accounts[0].address, amount, secret).send().wait(); + await wallets[0].addCapsule(getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true))); + await asset.methods.redeem_shield(wallets[0].getAddress(), amount, secret).send().wait(); - tokenSim.redeemShield(accounts[0].address, amount); + tokenSim.redeemShield(wallets[0].getAddress(), amount); }); describe('failure cases', () => { it('on behalf of self (more than balance)', async () => { - const balancePub = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balancePub = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balancePub + 1n; expect(amount).toBeGreaterThan(0n); - await expect(asset.methods.shield(accounts[0].address, amount, secretHash, 0).prove()).rejects.toThrow( + await expect(asset.methods.shield(wallets[0].getAddress(), amount, secretHash, 0).prove()).rejects.toThrow( U128_UNDERFLOW_ERROR, ); }); it('on behalf of self (invalid nonce)', async () => { - const balancePub = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balancePub = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balancePub + 1n; expect(amount).toBeGreaterThan(0n); - await expect(asset.methods.shield(accounts[0].address, amount, secretHash, 1).prove()).rejects.toThrow( + await expect(asset.methods.shield(wallets[0].getAddress(), amount, secretHash, 1).prove()).rejects.toThrow( 'Assertion failed: invalid nonce', ); }); it('on behalf of other (more than balance)', async () => { - const balancePub = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balancePub = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balancePub + 1n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset.withWallet(wallets[1]).methods.shield(accounts[0].address, amount, secretHash, nonce); - await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, true).send().wait(); + const action = asset.withWallet(wallets[1]).methods.shield(wallets[0].getAddress(), amount, secretHash, nonce); + await wallets[0].setPublicAuthWit({ caller: wallets[1].getAddress(), action }, true).send().wait(); await expect(action.prove()).rejects.toThrow(U128_UNDERFLOW_ERROR); }); it('on behalf of other (wrong designated caller)', async () => { - const balancePub = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balancePub = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balancePub + 1n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset.withWallet(wallets[2]).methods.shield(accounts[0].address, amount, secretHash, nonce); - await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, true).send().wait(); + const action = asset.withWallet(wallets[2]).methods.shield(wallets[0].getAddress(), amount, secretHash, nonce); + await wallets[0].setPublicAuthWit({ caller: wallets[1].getAddress(), action }, true).send().wait(); await expect(action.prove()).rejects.toThrow('Assertion failed: Message not authorized by account'); }); it('on behalf of other (without approval)', async () => { - const balance = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance / 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); await expect( - asset.withWallet(wallets[1]).methods.shield(accounts[0].address, amount, secretHash, nonce).prove(), + asset.withWallet(wallets[1]).methods.shield(wallets[0].getAddress(), amount, secretHash, nonce).prove(), ).rejects.toThrow(`Assertion failed: Message not authorized by account`); }); it('shielding from blacklisted account', async () => { await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[3].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[3].getAddress().toBigInt(), true)), ); await expect( - asset.withWallet(wallets[3]).methods.shield(accounts[3].address, 1n, secretHash, 0).prove(), + asset.withWallet(wallets[3]).methods.shield(wallets[3].getAddress(), 1n, secretHash, 0).prove(), ).rejects.toThrow("Assertion failed: Blacklisted: Sender '!from_roles.is_blacklisted'"); }); }); @@ -942,44 +940,44 @@ describe('e2e_blacklist_token_contract', () => { describe('Unshielding', () => { it('on behalf of self', async () => { - const balancePriv = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balancePriv = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balancePriv / 2n; expect(amount).toBeGreaterThan(0n); - await wallets[1].addCapsule(getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true))); - await wallets[1].addCapsule(getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true))); - await asset.methods.unshield(accounts[0].address, accounts[0].address, amount, 0).send().wait(); + await wallets[1].addCapsule(getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true))); + await wallets[1].addCapsule(getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true))); + await asset.methods.unshield(wallets[0].getAddress(), wallets[0].getAddress(), amount, 0).send().wait(); - tokenSim.unshield(accounts[0].address, accounts[0].address, amount); + tokenSim.unshield(wallets[0].getAddress(), wallets[0].getAddress(), amount); }); it('on behalf of other', async () => { - const balancePriv0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balancePriv0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balancePriv0 / 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved - await wallets[1].addCapsule(getMembershipCapsule(await getMembershipProof(accounts[1].address.toBigInt(), true))); - await wallets[1].addCapsule(getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true))); + await wallets[1].addCapsule(getMembershipCapsule(await getMembershipProof(wallets[1].getAddress().toBigInt(), true))); + await wallets[1].addCapsule(getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true))); const action = asset .withWallet(wallets[1]) - .methods.unshield(accounts[0].address, accounts[1].address, amount, nonce); + .methods.unshield(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. - const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); + const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); await wallets[1].addAuthWitness(witness); await action.send().wait(); - tokenSim.unshield(accounts[0].address, accounts[1].address, amount); + tokenSim.unshield(wallets[0].getAddress(), wallets[1].getAddress(), amount); // Perform the transfer again, should fail - await wallets[1].addCapsule(getMembershipCapsule(await getMembershipProof(accounts[1].address.toBigInt(), true))); - await wallets[1].addCapsule(getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true))); + await wallets[1].addCapsule(getMembershipCapsule(await getMembershipProof(wallets[1].getAddress().toBigInt(), true))); + await wallets[1].addCapsule(getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true))); const txReplay = asset .withWallet(wallets[1]) - .methods.unshield(accounts[0].address, accounts[1].address, amount, nonce) + .methods.unshield(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce) .send(); await expect(txReplay.wait()).rejects.toThrow('Transaction '); // @todo @LHerskind This error is weird? @@ -987,41 +985,41 @@ describe('e2e_blacklist_token_contract', () => { describe('failure cases', () => { it('on behalf of self (more than balance)', async () => { - const balancePriv = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balancePriv = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balancePriv + 1n; expect(amount).toBeGreaterThan(0n); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); await expect( - asset.methods.unshield(accounts[0].address, accounts[0].address, amount, 0).prove(), + asset.methods.unshield(wallets[0].getAddress(), wallets[0].getAddress(), amount, 0).prove(), ).rejects.toThrow('Assertion failed: Balance too low'); }); it('on behalf of self (invalid nonce)', async () => { - const balancePriv = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balancePriv = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balancePriv + 1n; expect(amount).toBeGreaterThan(0n); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); await expect( - asset.methods.unshield(accounts[0].address, accounts[0].address, amount, 1).prove(), + asset.methods.unshield(wallets[0].getAddress(), wallets[0].getAddress(), amount, 1).prove(), ).rejects.toThrow('Assertion failed: invalid nonce'); }); it('on behalf of other (more than balance)', async () => { - const balancePriv0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balancePriv0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balancePriv0 + 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); @@ -1029,24 +1027,24 @@ describe('e2e_blacklist_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[1]) - .methods.unshield(accounts[0].address, accounts[1].address, amount, nonce); + .methods.unshield(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. - const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); + const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); await wallets[1].addAuthWitness(witness); await wallets[1].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[1].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[1].getAddress().toBigInt(), true)), ); await wallets[1].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); await expect(action.prove()).rejects.toThrow('Assertion failed: Balance too low'); }); it('on behalf of other (invalid designated caller)', async () => { - const balancePriv0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balancePriv0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balancePriv0 + 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); @@ -1054,9 +1052,9 @@ describe('e2e_blacklist_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[2]) - .methods.unshield(accounts[0].address, accounts[1].address, amount, nonce); + .methods.unshield(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); const expectedMessageHash = computeAuthWitMessageHash( - accounts[2].address, + wallets[2].getAddress(), wallets[0].getChainId(), wallets[0].getVersion(), action.request(), @@ -1064,13 +1062,13 @@ describe('e2e_blacklist_token_contract', () => { // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. - const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); + const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); await wallets[2].addAuthWitness(witness); await wallets[2].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[1].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[1].getAddress().toBigInt(), true)), ); await wallets[2].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); await expect(action.prove()).rejects.toThrow( @@ -1080,24 +1078,24 @@ describe('e2e_blacklist_token_contract', () => { it('unshield from blacklisted account', async () => { await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[3].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[3].getAddress().toBigInt(), true)), ); - await expect(asset.methods.unshield(accounts[3].address, accounts[0].address, 1n, 0).prove()).rejects.toThrow( + await expect(asset.methods.unshield(wallets[3].getAddress(), wallets[0].getAddress(), 1n, 0).prove()).rejects.toThrow( "Assertion failed: Blacklisted: Sender '!from_roles.is_blacklisted'", ); }); it('unshield to blacklisted account', async () => { await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[3].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[3].getAddress().toBigInt(), true)), ); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); - await expect(asset.methods.unshield(accounts[0].address, accounts[3].address, 1n, 0).prove()).rejects.toThrow( + await expect(asset.methods.unshield(wallets[0].getAddress(), wallets[3].getAddress(), 1n, 0).prove()).rejects.toThrow( "Assertion failed: Blacklisted: Recipient '!to_roles.is_blacklisted'", ); }); @@ -1107,92 +1105,92 @@ describe('e2e_blacklist_token_contract', () => { describe('Burn', () => { describe('public', () => { it('burn less than balance', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; expect(amount).toBeGreaterThan(0n); - await asset.methods.burn_public(accounts[0].address, amount, 0).send().wait(); + await asset.methods.burn_public(wallets[0].getAddress(), amount, 0).send().wait(); - tokenSim.burnPublic(accounts[0].address, amount); + tokenSim.burnPublic(wallets[0].getAddress(), amount); }); it('burn on behalf of other', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; expect(amount).toBeGreaterThan(0n); const nonce = Fr.random(); // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce); - await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, true).send().wait(); + const action = asset.withWallet(wallets[1]).methods.burn_public(wallets[0].getAddress(), amount, nonce); + await wallets[0].setPublicAuthWit({ caller: wallets[1].getAddress(), action }, true).send().wait(); await action.send().wait(); - tokenSim.burnPublic(accounts[0].address, amount); + tokenSim.burnPublic(wallets[0].getAddress(), amount); // Check that the message hash is no longer valid. Need to try to send since nullifiers are handled by sequencer. - const txReplay = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce).send(); + const txReplay = asset.withWallet(wallets[1]).methods.burn_public(wallets[0].getAddress(), amount, nonce).send(); await expect(txReplay.wait()).rejects.toThrow('Transaction '); }); describe('failure cases', () => { it('burn more than balance', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 + 1n; const nonce = 0; - await expect(asset.methods.burn_public(accounts[0].address, amount, nonce).prove()).rejects.toThrow( + await expect(asset.methods.burn_public(wallets[0].getAddress(), amount, nonce).prove()).rejects.toThrow( U128_UNDERFLOW_ERROR, ); }); it('burn on behalf of self with non-zero nonce', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 - 1n; expect(amount).toBeGreaterThan(0n); const nonce = 1; - await expect(asset.methods.burn_public(accounts[0].address, amount, nonce).prove()).rejects.toThrow( + await expect(asset.methods.burn_public(wallets[0].getAddress(), amount, nonce).prove()).rejects.toThrow( 'Assertion failed: invalid nonce', ); }); it('burn on behalf of other without "approval"', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 + 1n; const nonce = Fr.random(); await expect( - asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce).prove(), + asset.withWallet(wallets[1]).methods.burn_public(wallets[0].getAddress(), amount, nonce).prove(), ).rejects.toThrow('Assertion failed: Message not authorized by account'); }); it('burn more than balance on behalf of other', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 + 1n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce); - await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, true).send().wait(); + const action = asset.withWallet(wallets[1]).methods.burn_public(wallets[0].getAddress(), amount, nonce); + await wallets[0].setPublicAuthWit({ caller: wallets[1].getAddress(), action }, true).send().wait(); await expect(action.prove()).rejects.toThrow(U128_UNDERFLOW_ERROR); }); it('burn on behalf of other, wrong designated caller', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 + 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce); - await wallets[0].setPublicAuthWit({ caller: accounts[0].address, action }, true).send().wait(); + const action = asset.withWallet(wallets[1]).methods.burn_public(wallets[0].getAddress(), amount, nonce); + await wallets[0].setPublicAuthWit({ caller: wallets[0].getAddress(), action }, true).send().wait(); await expect( - asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce).prove(), + asset.withWallet(wallets[1]).methods.burn_public(wallets[0].getAddress(), amount, nonce).prove(), ).rejects.toThrow('Assertion failed: Message not authorized by account'); }); it('burn from blacklisted account', async () => { - await expect(asset.methods.burn_public(accounts[3].address, 1n, 0).prove()).rejects.toThrow( + await expect(asset.methods.burn_public(wallets[3].getAddress(), 1n, 0).prove()).rejects.toThrow( "Assertion failed: Blacklisted: Sender '!from_roles.is_blacklisted'", ); }); @@ -1201,102 +1199,102 @@ describe('e2e_blacklist_token_contract', () => { describe('private', () => { it('burn less than balance', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; expect(amount).toBeGreaterThan(0n); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); - await asset.methods.burn(accounts[0].address, amount, 0).send().wait(); - tokenSim.burnPrivate(accounts[0].address, amount); + await asset.methods.burn(wallets[0].getAddress(), amount, 0).send().wait(); + tokenSim.burnPrivate(wallets[0].getAddress(), amount); }); it('burn on behalf of other', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce); + const action = asset.withWallet(wallets[1]).methods.burn(wallets[0].getAddress(), amount, nonce); // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. - const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); + const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); await wallets[1].addAuthWitness(witness); await wallets[1].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); - await asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce).send().wait(); - tokenSim.burnPrivate(accounts[0].address, amount); + await asset.withWallet(wallets[1]).methods.burn(wallets[0].getAddress(), amount, nonce).send().wait(); + tokenSim.burnPrivate(wallets[0].getAddress(), amount); // Perform the transfer again, should fail await wallets[1].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); - const txReplay = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce).send(); + const txReplay = asset.withWallet(wallets[1]).methods.burn(wallets[0].getAddress(), amount, nonce).send(); await expect(txReplay.wait()).rejects.toThrow('Transaction '); }); describe('failure cases', () => { it('burn more than balance', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 + 1n; expect(amount).toBeGreaterThan(0n); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); - await expect(asset.methods.burn(accounts[0].address, amount, 0).prove()).rejects.toThrow( + await expect(asset.methods.burn(wallets[0].getAddress(), amount, 0).prove()).rejects.toThrow( 'Assertion failed: Balance too low', ); }); it('burn on behalf of self with non-zero nonce', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 - 1n; expect(amount).toBeGreaterThan(0n); await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); - await expect(asset.methods.burn(accounts[0].address, amount, 1).prove()).rejects.toThrow( + await expect(asset.methods.burn(wallets[0].getAddress(), amount, 1).prove()).rejects.toThrow( 'Assertion failed: invalid nonce', ); }); it('burn more than balance on behalf of other', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 + 1n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce); + const action = asset.withWallet(wallets[1]).methods.burn(wallets[0].getAddress(), amount, nonce); // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. - const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); + const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); await wallets[1].addAuthWitness(witness); await wallets[1].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); await expect(action.prove()).rejects.toThrow('Assertion failed: Balance too low'); }); it('burn on behalf of other without approval', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved await wallets[1].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); - const action = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce); + const action = asset.withWallet(wallets[1]).methods.burn(wallets[0].getAddress(), amount, nonce); const messageHash = computeAuthWitMessageHash( - accounts[1].address, + wallets[1].getAddress(), wallets[0].getChainId(), wallets[0].getVersion(), action.request(), @@ -1308,24 +1306,24 @@ describe('e2e_blacklist_token_contract', () => { }); it('on behalf of other (invalid designated caller)', async () => { - const balancePriv0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balancePriv0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balancePriv0 + 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved await wallets[2].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[0].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); - const action = asset.withWallet(wallets[2]).methods.burn(accounts[0].address, amount, nonce); + const action = asset.withWallet(wallets[2]).methods.burn(wallets[0].getAddress(), amount, nonce); const expectedMessageHash = computeAuthWitMessageHash( - accounts[2].address, + wallets[2].getAddress(), wallets[0].getChainId(), wallets[0].getVersion(), action.request(), ); - const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); + const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); await wallets[2].addAuthWitness(witness); await expect(action.prove()).rejects.toThrow( @@ -1335,9 +1333,9 @@ describe('e2e_blacklist_token_contract', () => { it('burn from blacklisted account', async () => { await wallets[0].addCapsule( - getMembershipCapsule(await getMembershipProof(accounts[3].address.toBigInt(), true)), + getMembershipCapsule(await getMembershipProof(wallets[3].getAddress().toBigInt(), true)), ); - await expect(asset.methods.burn(accounts[3].address, 1n, 0).prove()).rejects.toThrow( + await expect(asset.methods.burn(wallets[3].getAddress(), 1n, 0).prove()).rejects.toThrow( "Assertion failed: Blacklisted: Sender '!from_roles.is_blacklisted'", ); }); 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 f6f5568ec1c..20905605d68 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 @@ -39,13 +39,12 @@ describe('e2e_cheat_codes', () => { beforeAll(async () => { let deployL1ContractsValues; - let accounts; - ({ teardown, wallet, accounts, cheatCodes: cc, deployL1ContractsValues, pxe } = await setup()); + ({ teardown, wallet, cheatCodes: cc, deployL1ContractsValues, pxe } = await setup()); walletClient = deployL1ContractsValues.walletClient; publicClient = deployL1ContractsValues.publicClient; rollupAddress = deployL1ContractsValues.l1ContractAddresses.rollupAddress; - admin = accounts[0]; + admin = wallet.getCompleteAddress(); token = await TokenContract.deploy(wallet, admin, 'TokenName', 'TokenSymbol', 18).send().deployed(); }, 100_000); diff --git a/yarn-project/end-to-end/src/e2e_counter_contract.test.ts b/yarn-project/end-to-end/src/e2e_counter_contract.test.ts index 7677db89e44..2e7daaaf5a7 100644 --- a/yarn-project/end-to-end/src/e2e_counter_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_counter_contract.test.ts @@ -1,11 +1,10 @@ -import { type AccountWallet, type AztecAddress, type CompleteAddress, type DebugLogger } from '@aztec/aztec.js'; +import { type AccountWallet, type AztecAddress, type DebugLogger } from '@aztec/aztec.js'; import { CounterContract } from '@aztec/noir-contracts.js/Counter'; import { setup } from './fixtures/utils.js'; describe('e2e_counter_contract', () => { let wallet: AccountWallet; - let accounts: CompleteAddress[]; let logger: DebugLogger; let teardown: () => Promise; @@ -16,11 +15,10 @@ describe('e2e_counter_contract', () => { // Setup environment ({ teardown, - accounts, - wallets: [wallet], + wallet, logger, } = await setup(1)); - owner = accounts[0].address; + owner = wallet.getAddress(); counterContract = await CounterContract.deploy(wallet, 0, owner).send().deployed(); diff --git a/yarn-project/end-to-end/src/e2e_dapp_subscription.test.ts b/yarn-project/end-to-end/src/e2e_dapp_subscription.test.ts index f499b49d88d..1df66c7eadc 100644 --- a/yarn-project/end-to-end/src/e2e_dapp_subscription.test.ts +++ b/yarn-project/end-to-end/src/e2e_dapp_subscription.test.ts @@ -7,6 +7,10 @@ import { PublicFeePaymentMethod, SentTx, getContractClassFromArtifact, + type AztecNode, + type DeployL1Contracts, + type PXE, + type DebugLogger, } from '@aztec/aztec.js'; import { DefaultDappEntrypoint } from '@aztec/entrypoints/dapp'; import { @@ -22,7 +26,6 @@ import { jest } from '@jest/globals'; import { type BalancesFn, - type EndToEndContext, expectMapping, getBalancesFn, publicDeployAccounts, @@ -36,6 +39,9 @@ const TOKEN_SYMBOL = 'BC'; const TOKEN_DECIMALS = 18n; describe('e2e_dapp_subscription', () => { + let pxe: PXE; + let logger: DebugLogger; + let aliceWallet: AccountWalletWithPrivateKey; let bobWallet: AccountWalletWithPrivateKey; let aliceAddress: AztecAddress; // Dapp subscriber. @@ -47,7 +53,6 @@ describe('e2e_dapp_subscription', () => { let subscriptionContract: AppSubscriptionContract; let gasTokenContract: GasTokenContract; let bananaFPC: FPCContract; - let e2eContext: EndToEndContext; let gasBalances: BalancesFn; let bananasPublicBalances: BalancesFn; let bananasPrivateBalances: BalancesFn; @@ -63,10 +68,14 @@ describe('e2e_dapp_subscription', () => { beforeAll(async () => { process.env.PXE_URL = ''; - e2eContext = await setup(3); - await publicDeployAccounts(e2eContext.wallet, e2eContext.accounts); - const { wallets, accounts, aztecNode, deployL1ContractsValues } = e2eContext; + let wallets: AccountWalletWithPrivateKey[]; + let aztecNode: AztecNode; + let deployL1ContractsValues: DeployL1Contracts; + ({ wallets, aztecNode, deployL1ContractsValues, logger, pxe } = await setup(3)); + + await publicDeployAccounts(wallets[0], wallets); + await aztecNode.setConfig({ allowedFeePaymentContractClasses: [getContractClassFromArtifact(FPCContract.artifact).id], @@ -78,9 +87,9 @@ describe('e2e_dapp_subscription', () => { wallets[0], ); - aliceAddress = accounts.at(0)!.address; - bobAddress = accounts.at(1)!.address; - sequencerAddress = accounts.at(2)!.address; + aliceAddress = wallets[0].getAddress(); + bobAddress = wallets[1].getAddress(); + sequencerAddress = wallets[2].getAddress(); await aztecNode.setConfig({ feeRecipient: sequencerAddress, @@ -114,9 +123,9 @@ describe('e2e_dapp_subscription', () => { await gasTokenContract.methods.mint_public(subscriptionContract.address, INITIAL_GAS_BALANCE).send().wait(); await gasTokenContract.methods.mint_public(bananaFPC.address, INITIAL_GAS_BALANCE).send().wait(); - gasBalances = getBalancesFn('⛽', gasTokenContract.methods.balance_of_public, e2eContext.logger); - bananasPublicBalances = getBalancesFn('Public 🍌', bananaCoin.methods.balance_of_public, e2eContext.logger); - bananasPrivateBalances = getBalancesFn('Private 🍌', bananaCoin.methods.balance_of_private, e2eContext.logger); + gasBalances = getBalancesFn('⛽', gasTokenContract.methods.balance_of_public, logger); + bananasPublicBalances = getBalancesFn('Public 🍌', bananaCoin.methods.balance_of_public, logger); + bananasPrivateBalances = getBalancesFn('Private 🍌', bananaCoin.methods.balance_of_private, logger); await expectMapping( gasBalances, @@ -205,7 +214,6 @@ describe('e2e_dapp_subscription', () => { }); it('should call dapp subscription entrypoint', async () => { - const { pxe } = e2eContext; const dappPayload = new DefaultDappEntrypoint(aliceAddress, aliceWallet, subscriptionContract.address); const action = counterContract.methods.increment(bobAddress).request(); const txExReq = await dappPayload.createTxExecutionRequest([action]); @@ -249,7 +257,7 @@ describe('e2e_dapp_subscription', () => { return subscriptionContract .withWallet(aliceWallet) - .methods.subscribe(aliceAddress, nonce, (await e2eContext.pxe.getBlockNumber()) + blockDelta, txCount) + .methods.subscribe(aliceAddress, nonce, (await pxe.getBlockNumber()) + blockDelta, txCount) .send({ fee: { maxFee, @@ -260,7 +268,6 @@ describe('e2e_dapp_subscription', () => { } async function dappIncrement() { - const { pxe } = e2eContext; const dappEntrypoint = new DefaultDappEntrypoint(aliceAddress, aliceWallet, subscriptionContract.address); const action = counterContract.methods.increment(bobAddress).request(); const txExReq = await dappEntrypoint.createTxExecutionRequest([action]); diff --git a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts index efccbdd034c..6e22ae60296 100644 --- a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts @@ -37,7 +37,6 @@ import { setup } from './fixtures/utils.js'; describe('e2e_deploy_contract', () => { let pxe: PXE; - let accounts: CompleteAddress[]; let logger: DebugLogger; let wallet: Wallet; let sequencer: SequencerClient | undefined; @@ -46,7 +45,7 @@ describe('e2e_deploy_contract', () => { describe('legacy tests', () => { beforeAll(async () => { - ({ teardown, pxe, accounts, logger, wallet, sequencer, aztecNode } = await setup()); + ({ teardown, pxe, logger, wallet, sequencer, aztecNode } = await setup()); }, 100_000); afterAll(() => teardown()); @@ -57,7 +56,7 @@ describe('e2e_deploy_contract', () => { */ it('should deploy a test contract', async () => { const salt = Fr.random(); - const publicKey = accounts[0].publicKey; + const publicKey = wallet.getCompleteAddress().publicKey; const deploymentData = getContractInstanceFromDeployParams(TestContractArtifact, { salt, publicKey, @@ -92,7 +91,7 @@ describe('e2e_deploy_contract', () => { logger(`Deploying contract ${index + 1}...`); const receipt = await deployer.deploy().send({ contractAddressSalt: Fr.random() }).wait({ wallet }); logger(`Sending TX to contract ${index + 1}...`); - await receipt.contract.methods.get_public_key(accounts[0].address).send().wait(); + await receipt.contract.methods.get_public_key(wallet.getAddress()).send().wait(); } }, 90_000); @@ -126,7 +125,7 @@ describe('e2e_deploy_contract', () => { // This test requires at least another good transaction to go through in the same block as the bad one. const artifact = TokenContractArtifact; const initArgs = ['TokenName', 'TKN', 18] as const; - const goodDeploy = StatefulTestContract.deploy(wallet, accounts[0], 42); + const goodDeploy = StatefulTestContract.deploy(wallet, wallet.getAddress(), 42); const badDeploy = new ContractDeployer(artifact, wallet).deploy(AztecAddress.ZERO, ...initArgs); const firstOpts = { skipPublicSimulation: true, skipClassRegistration: true, skipInstanceDeploy: true }; @@ -160,7 +159,7 @@ describe('e2e_deploy_contract', () => { describe('private initialization', () => { beforeAll(async () => { - ({ teardown, pxe, accounts, logger, wallet, sequencer, aztecNode } = await setup()); + ({ teardown, pxe, logger, wallet, sequencer, aztecNode } = await setup()); }, 100_000); afterAll(() => teardown()); @@ -272,7 +271,7 @@ describe('e2e_deploy_contract', () => { describe('registering a contract class', () => { beforeAll(async () => { - ({ teardown, pxe, accounts, logger, wallet, sequencer, aztecNode } = await setup()); + ({ teardown, pxe, logger, wallet, sequencer, aztecNode } = await setup()); }, 100_000); afterAll(() => teardown()); @@ -329,7 +328,7 @@ describe('e2e_deploy_contract', () => { let contract: StatefulTestContract; const deployInstance = async (opts: { constructorName?: string; deployer?: AztecAddress } = {}) => { - const initArgs = [accounts[0].address, 42] as StatefulContractCtorArgs; + const initArgs = [wallet.getAddress(), 42] as StatefulContractCtorArgs; const salt = Fr.random(); const portalAddress = EthAddress.random(); const publicKey = Point.random(); @@ -485,7 +484,7 @@ describe('e2e_deploy_contract', () => { describe('error scenarios in deployment', () => { it('refuses to call a public function on an undeployed contract', async () => { - const whom = accounts[0].address; + const whom = wallet.getAddress(); const instance = await registerContract(wallet, StatefulTestContract, { initArgs: [whom, 42] }); await expect( instance.methods.increment_public_value_no_init_check(whom, 10).send({ skipPublicSimulation: true }).wait(), @@ -508,12 +507,12 @@ describe('e2e_deploy_contract', () => { // TODO(@spalladino): The above is only true for locally run e2e tests, on the CI this runs // on a single sandbox instance, so tests are not truly independent. beforeEach(async () => { - ({ teardown, pxe, accounts, logger, wallet, sequencer, aztecNode } = await setup()); + ({ teardown, pxe, logger, wallet, sequencer, aztecNode } = await setup()); }, 100_000); afterEach(() => teardown()); it('publicly deploys and initializes a contract', async () => { - const owner = accounts[0]; + const owner = wallet.getAddress(); logger.debug(`Deploying stateful test contract`); const contract = await StatefulTestContract.deploy(wallet, owner, 42).send().deployed(); expect(await contract.methods.summed_values(owner).simulate()).toEqual(42n); @@ -523,7 +522,7 @@ describe('e2e_deploy_contract', () => { }, 60_000); it('publicly universally deploys and initializes a contract', async () => { - const owner = accounts[0]; + const owner = wallet.getAddress(); const opts = { universalDeploy: true }; const contract = await StatefulTestContract.deploy(wallet, owner, 42).send(opts).deployed(); expect(await contract.methods.summed_values(owner).simulate()).toEqual(42n); @@ -532,13 +531,13 @@ describe('e2e_deploy_contract', () => { }, 60_000); it('publicly deploys and calls a public function from the constructor', async () => { - const owner = accounts[0]; + const owner = wallet.getAddress(); const token = await TokenContract.deploy(wallet, owner, 'TOKEN', 'TKN', 18).send().deployed(); expect(await token.methods.is_minter(owner).simulate()).toEqual(true); }, 60_000); it('publicly deploys and initializes via a public function', async () => { - const owner = accounts[0]; + const owner = wallet.getAddress(); logger.debug(`Deploying contract via a public constructor`); const contract = await StatefulTestContract.deployWithOpts({ wallet, method: 'public_constructor' }, owner, 42) .send() @@ -552,10 +551,10 @@ describe('e2e_deploy_contract', () => { it('deploys a contract with a default initializer not named constructor', async () => { logger.debug(`Deploying contract with a default initializer named initialize`); const opts = { skipClassRegistration: true, skipPublicDeployment: true }; - const contract = await CounterContract.deploy(wallet, 10, accounts[0]).send(opts).deployed(); + const contract = await CounterContract.deploy(wallet, 10, wallet.getAddress()).send(opts).deployed(); logger.debug(`Calling a function to ensure the contract was properly initialized`); - await contract.methods.increment(accounts[0]).send().wait(); - expect(await contract.methods.get_counter(accounts[0]).simulate()).toEqual(11n); + await contract.methods.increment(wallet.getAddress()).send().wait(); + expect(await contract.methods.get_counter(wallet.getAddress()).simulate()).toEqual(11n); }); it('publicly deploys a contract with no constructor', async () => { 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 90a6e59a747..edbcd538623 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,18 +1,17 @@ import { - type AccountWallet, - type AztecAddress, BatchCall, - type CompleteAddress, - type DebugLogger, ExtendedNote, Fr, - type GrumpkinPrivateKey, GrumpkinScalar, Note, - type PXE, - type PublicKey, computeMessageSecretHash, generatePublicKey, + type AccountWallet, + type AztecAddress, + type DebugLogger, + type GrumpkinPrivateKey, + type PXE, + type PublicKey } from '@aztec/aztec.js'; import { computePartialAddress } from '@aztec/circuits.js'; import { EscrowContract } from '@aztec/noir-contracts.js/Escrow'; @@ -27,7 +26,7 @@ describe('e2e_escrow_contract', () => { let pxe: PXE; let wallet: AccountWallet; let recipientWallet: AccountWallet; - let accounts: CompleteAddress[]; + let logger: DebugLogger; let teardown: () => Promise; @@ -44,12 +43,11 @@ describe('e2e_escrow_contract', () => { ({ teardown, pxe, - accounts, wallets: [wallet, recipientWallet], logger, } = await setup(2)); - owner = accounts[0].address; - recipient = accounts[1].address; + owner = wallet.getAddress(); + recipient = recipientWallet.getAddress(); // Generate private key for escrow contract, register key in pxe service, and deploy // Note that we need to register it first if we want to emit an encrypted note for it in the constructor diff --git a/yarn-project/end-to-end/src/e2e_fees.test.ts b/yarn-project/end-to-end/src/e2e_fees.test.ts index 3b11f865776..c4e5547f231 100644 --- a/yarn-project/end-to-end/src/e2e_fees.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees.test.ts @@ -1,22 +1,26 @@ import { - type AztecAddress, BatchCall, - type DebugLogger, ExtendedNote, Fr, - type FunctionCall, FunctionSelector, Note, PrivateFeePaymentMethod, PublicFeePaymentMethod, - type TxHash, TxStatus, - type Wallet, computeAuthWitMessageHash, computeMessageSecretHash, + type AccountWalletWithPrivateKey, + type AztecAddress, + type AztecNode, + type DebugLogger, + type DeployL1Contracts, + type FunctionCall, + type PXE, + type TxHash, + type Wallet, } from '@aztec/aztec.js'; import { FunctionData, getContractClassFromArtifact } from '@aztec/circuits.js'; -import { type ContractArtifact, decodeFunctionSignature } from '@aztec/foundation/abi'; +import { decodeFunctionSignature, type ContractArtifact } from '@aztec/foundation/abi'; import { TokenContract as BananaCoin, FPCContract, @@ -27,12 +31,11 @@ import { import { jest } from '@jest/globals'; import { - type BalancesFn, - type EndToEndContext, expectMapping, getBalancesFn, publicDeployAccounts, setup, + type BalancesFn } from './fixtures/utils.js'; import { GasPortalTestingHarnessFactory, type IGasBridgingTestHarness } from './shared/gas_portal_test_harness.js'; @@ -53,16 +56,15 @@ describe('e2e_fees', () => { let bananaFPC: FPCContract; let gasBridgeTestHarness: IGasBridgingTestHarness; - let e2eContext: EndToEndContext; let gasBalances: BalancesFn; let bananaPublicBalances: BalancesFn; let bananaPrivateBalances: BalancesFn; beforeAll(async () => { - e2eContext = await setup(3); - const { accounts, logger, aztecNode, pxe, deployL1ContractsValues, wallets } = e2eContext; + const { wallets, aztecNode, deployL1ContractsValues, logger, pxe } = await setup(3); + await aztecNode.setConfig({ allowedFeePaymentContractClasses: [getContractClassFromArtifact(FPCContract.artifact).id], }); @@ -73,13 +75,13 @@ describe('e2e_fees', () => { logFunctionSignatures(SchnorrAccountContract.artifact, logger); await aztecNode.setConfig({ - feeRecipient: accounts.at(-1)!.address, + feeRecipient: wallets.at(-1)!.getAddress(), }); aliceWallet = wallets[0]; - aliceAddress = accounts[0].address; - bobAddress = accounts[1].address; - sequencerAddress = accounts[2].address; + aliceAddress = wallets[0].getAddress(); + bobAddress = wallets[1].getAddress(); + sequencerAddress = wallets[2].getAddress(); gasBridgeTestHarness = await GasPortalTestingHarnessFactory.create({ pxeService: pxe, @@ -92,7 +94,7 @@ describe('e2e_fees', () => { gasTokenContract = gasBridgeTestHarness.l2Token; - bananaCoin = await BananaCoin.deploy(wallets[0], accounts[0], TOKEN_NAME, TOKEN_SYMBOL, TOKEN_DECIMALS) + bananaCoin = await BananaCoin.deploy(wallets[0], wallets[0].getAddress(), TOKEN_NAME, TOKEN_SYMBOL, TOKEN_DECIMALS) .send() .deployed(); @@ -100,7 +102,7 @@ describe('e2e_fees', () => { bananaFPC = await FPCContract.deploy(wallets[0], bananaCoin.address, gasTokenContract.address).send().deployed(); logger(`bananaPay deployed at ${bananaFPC.address}`); - await publicDeployAccounts(wallets[0], accounts); + await publicDeployAccounts(wallets[0], wallets); await gasBridgeTestHarness.bridgeFromL1ToL2(BRIDGED_FPC_GAS, BRIDGED_FPC_GAS, bananaFPC.address); @@ -118,7 +120,6 @@ describe('e2e_fees', () => { const FeeAmount = 1n; const RefundAmount = 2n; const MaxFee = FeeAmount + RefundAmount; - const { wallets } = e2eContext; const [initialAlicePrivateBananas, initialFPCPrivateBananas] = await bananaPrivateBalances( aliceAddress, @@ -547,7 +548,6 @@ describe('e2e_fees', () => { const FeeAmount = 1n; const RefundAmount = 2n; const MaxFee = FeeAmount + RefundAmount; - const { wallets } = e2eContext; // simulation throws an error when setup fails await expect( @@ -587,7 +587,6 @@ describe('e2e_fees', () => { const FeeAmount = 1n; const RefundAmount = 2n; const MaxFee = FeeAmount + RefundAmount; - const { wallets } = e2eContext; const [initialAlicePrivateBananas, initialFPCPrivateBananas] = await bananaPrivateBalances( aliceAddress, @@ -677,13 +676,13 @@ describe('e2e_fees', () => { const note = new Note([new Fr(amount), secretHash]); const extendedNote = new ExtendedNote( note, - e2eContext.accounts[accountIndex].address, + wallets[accountIndex].getAddress(), bananaCoin.address, storageSlot, noteTypeId, txHash, ); - await e2eContext.wallets[accountIndex].addNote(extendedNote); + await wallets[accountIndex].addNote(extendedNote); }; }); diff --git a/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts b/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts index 21498916e4f..8c14bb9e9af 100644 --- a/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts @@ -1,11 +1,10 @@ import { - type AccountWallet, AztecAddress, - type CompleteAddress, Fr, INITIAL_L2_BLOCK_NUM, - type PXE, getContractInstanceFromDeployParams, + type AccountWallet, + type PXE } from '@aztec/aztec.js'; import { deployInstance, registerContractClass } from '@aztec/aztec.js/deployment'; import { randomInt } from '@aztec/foundation/crypto'; @@ -13,7 +12,7 @@ import { StatefulTestContract, StatefulTestContractArtifact } from '@aztec/noir- import { InclusionProofsContract } from '@aztec/noir-contracts.js/InclusionProofs'; import { jest } from '@jest/globals'; -import { type MemDown, default as memdown } from 'memdown'; +import { default as memdown, type MemDown } from 'memdown'; import { setup } from './fixtures/utils.js'; @@ -27,7 +26,7 @@ describe('e2e_inclusion_proofs_contract', () => { let pxe: PXE; let teardown: () => Promise; let wallets: AccountWallet[]; - let accounts: CompleteAddress[]; + let contract: InclusionProofsContract; let deploymentBlockNumber: number; @@ -35,7 +34,7 @@ describe('e2e_inclusion_proofs_contract', () => { const contractAddressSalt = Fr.random(); beforeAll(async () => { - ({ pxe, teardown, wallets, accounts } = await setup(1)); + ({ pxe, teardown, wallets } = await setup(1)); const receipt = await InclusionProofsContract.deploy(wallets[0], publicValue).send({ contractAddressSalt }).wait(); contract = receipt.contract; @@ -48,7 +47,7 @@ describe('e2e_inclusion_proofs_contract', () => { let owner: AztecAddress; beforeAll(() => { - owner = accounts[0].address; + owner = wallets[0].getAddress(); }); describe('proves note existence and its nullifier non-existence and nullifier non-existence failure case', () => { @@ -148,7 +147,7 @@ describe('e2e_inclusion_proofs_contract', () => { it('proves note validity (note commitment inclusion and nullifier non-inclusion)', async () => { // Owner of a note - const owner = accounts[0].address; + const owner = wallets[0].getAddress(); let noteCreationBlockNumber: number; { // Create a note @@ -267,7 +266,7 @@ describe('e2e_inclusion_proofs_contract', () => { it('proves public deployment of a contract', async () => { // Publicly deploy another contract (so we don't test on the same contract) - const initArgs = [accounts[0], 42n]; + const initArgs = [wallets[0].getAddress(), 42n]; const instance = getContractInstanceFromDeployParams(StatefulTestContractArtifact, { constructorArgs: initArgs }); await (await registerContractClass(wallets[0], StatefulTestContractArtifact)).send().wait(); const receipt = await deployInstance(wallets[0], instance).send().wait(); @@ -277,7 +276,7 @@ describe('e2e_inclusion_proofs_contract', () => { it('proves initialization of a contract', async () => { // Initialize (but not deploy) a test contract - const receipt = await StatefulTestContract.deploy(wallets[0], accounts[0], 42n) + const receipt = await StatefulTestContract.deploy(wallets[0], wallets[0].getAddress(), 42n) .send({ skipClassRegistration: true, skipPublicDeployment: true }) .wait(); 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 8a5ce3cd3fd..4368a22d822 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 @@ -1,13 +1,12 @@ import { - type AccountWallet, - type CheatCodes, - type CompleteAddress, - type DebugLogger, ExtendedNote, Fr, Note, computeAuthWitMessageHash, computeMessageSecretHash, + type AccountWallet, + type CheatCodes, + type DebugLogger } from '@aztec/aztec.js'; import { LendingContract, PriceFeedContract, TokenContract } from '@aztec/noir-contracts.js'; @@ -19,7 +18,7 @@ import { LendingAccount, LendingSimulator, TokenSimulator } from './simulators/i describe('e2e_lending_contract', () => { jest.setTimeout(100_000); let wallet: AccountWallet; - let accounts: CompleteAddress[]; + let logger: DebugLogger; let teardown: () => Promise; @@ -40,13 +39,13 @@ describe('e2e_lending_contract', () => { logger(`Price feed deployed to ${priceFeedContract.address}`); logger(`Deploying collateral asset feed contract...`); - const collateralAsset = await TokenContract.deploy(wallet, accounts[0], 'TokenName', 'TokenSymbol', 18) + const collateralAsset = await TokenContract.deploy(wallet, wallet.getAddress(), 'TokenName', 'TokenSymbol', 18) .send() .deployed(); logger(`Collateral asset deployed to ${collateralAsset.address}`); logger(`Deploying stable coin contract...`); - const stableCoin = await TokenContract.deploy(wallet, accounts[0], 'TokenName', 'TokenSymbol', 18) + const stableCoin = await TokenContract.deploy(wallet, wallet.getAddress(), 'TokenName', 'TokenSymbol', 18) .send() .deployed(); logger(`Stable coin asset deployed to ${stableCoin.address}`); @@ -62,11 +61,11 @@ describe('e2e_lending_contract', () => { }; beforeAll(async () => { - ({ teardown, logger, cheatCodes: cc, wallet, accounts } = await setup(1)); + ({ teardown, logger, cheatCodes: cc, wallet } = await setup(1)); ({ lendingContract, priceFeedContract, collateralAsset, stableCoin } = await deployContracts()); - await publicDeployAccounts(wallet, accounts); + await publicDeployAccounts(wallet, [wallet]); - lendingAccount = new LendingAccount(accounts[0].address, new Fr(42)); + lendingAccount = new LendingAccount(wallet.getAddress(), new Fr(42)); // Also specified in `noir-contracts/contracts/lending_contract/src/main.nr` const rate = 1268391679n; @@ -75,8 +74,8 @@ describe('e2e_lending_contract', () => { lendingAccount, rate, lendingContract, - new TokenSimulator(collateralAsset, logger, [lendingContract.address, ...accounts.map(a => a.address)]), - new TokenSimulator(stableCoin, logger, [lendingContract.address, ...accounts.map(a => a.address)]), + new TokenSimulator(collateralAsset, logger, [lendingContract.address, wallet.getAddress()]), + new TokenSimulator(stableCoin, logger, [lendingContract.address, wallet.getAddress()]), ); }, 200_000); @@ -110,7 +109,7 @@ describe('e2e_lending_contract', () => { const txHash = await b.getTxHash(); const extendedNote = new ExtendedNote( note, - accounts[0].address, + wallet.getAddress(), asset.address, storageSlot, noteTypeId, diff --git a/yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts b/yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts index 5cf47cd3f53..743a5e0db8b 100644 --- a/yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts @@ -1,10 +1,9 @@ import { + Fr, type AztecAddress, type AztecNode, - type CompleteAddress, type DebugLogger, - Fr, - type Wallet, + type Wallet } from '@aztec/aztec.js'; import { PendingNoteHashesContract } from '@aztec/noir-contracts.js/PendingNoteHashes'; @@ -19,9 +18,9 @@ describe('e2e_pending_note_hashes_contract', () => { let contract: PendingNoteHashesContract; beforeEach(async () => { - let accounts: CompleteAddress[]; - ({ teardown, aztecNode, accounts, wallet, logger } = await setup(2)); - owner = accounts[0].address; + + ({ teardown, aztecNode, wallet, logger } = await setup(2)); + owner = wallet.getAddress(); }, 100_000); afterEach(() => teardown()); diff --git a/yarn-project/end-to-end/src/e2e_private_voting_contract.test.ts b/yarn-project/end-to-end/src/e2e_private_voting_contract.test.ts index 4602383f09a..85c3f3a6bbc 100644 --- a/yarn-project/end-to-end/src/e2e_private_voting_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_private_voting_contract.test.ts @@ -1,11 +1,11 @@ -import { type AccountWallet, type AztecAddress, type CompleteAddress, type DebugLogger, Fr } from '@aztec/aztec.js'; +import { Fr, type AccountWallet, type AztecAddress, type DebugLogger } from '@aztec/aztec.js'; import { EasyPrivateVotingContract } from '@aztec/noir-contracts.js/EasyPrivateVoting'; import { setup } from './fixtures/utils.js'; describe('e2e_voting_contract', () => { let wallet: AccountWallet; - let accounts: CompleteAddress[]; + let logger: DebugLogger; let teardown: () => Promise; @@ -16,11 +16,10 @@ describe('e2e_voting_contract', () => { // Setup environment ({ teardown, - accounts, - wallets: [wallet], + wallet, logger, } = await setup(1)); - owner = accounts[0].address; + owner = wallet.getAddress(); votingContract = await EasyPrivateVotingContract.deploy(wallet, owner).send().deployed(); 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 58a8872db78..02574d0af63 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 @@ -1,18 +1,17 @@ import { - type AccountWallet, - type AztecAddress, - type AztecNode, - type CompleteAddress, - type DebugLogger, - type DeployL1Contracts, EthAddress, Fr, L1Actor, L1ToL2Message, L2Actor, - type PXE, computeAuthWitMessageHash, computeMessageSecretHash, + type AccountWallet, + type AztecAddress, + type AztecNode, + type DebugLogger, + type DeployL1Contracts, + type PXE } from '@aztec/aztec.js'; import { sha256ToField } from '@aztec/foundation/crypto'; import { InboxAbi, OutboxAbi } from '@aztec/l1-artifacts'; @@ -33,7 +32,6 @@ describe('e2e_public_cross_chain_messaging', () => { let logger: DebugLogger; let teardown: () => Promise; let wallets: AccountWallet[]; - let accounts: CompleteAddress[]; let user1Wallet: AccountWallet; let user2Wallet: AccountWallet; @@ -47,10 +45,10 @@ describe('e2e_public_cross_chain_messaging', () => { let outbox: GetContractReturnType>; beforeAll(async () => { - ({ aztecNode, pxe, deployL1ContractsValues, wallets, accounts, logger, teardown } = await setup(2)); + ({ aztecNode, pxe, deployL1ContractsValues, wallets, logger, teardown } = await setup(2)); user1Wallet = wallets[0]; user2Wallet = wallets[1]; - await publicDeployAccounts(wallets[0], accounts.slice(0, 2)); + await publicDeployAccounts(wallets[0], wallets.slice(0, 2)); }, 30_000); beforeEach(async () => { diff --git a/yarn-project/end-to-end/src/e2e_token_contract.test.ts b/yarn-project/end-to-end/src/e2e_token_contract.test.ts index 2c985d5e1f5..e17cfc12179 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract.test.ts @@ -1,14 +1,13 @@ import { - type AccountWallet, - type CompleteAddress, - type DebugLogger, ExtendedNote, Fr, FunctionSelector, Note, - type TxHash, computeAuthWitMessageHash, computeMessageSecretHash, + type AccountWallet, + type DebugLogger, + type TxHash } from '@aztec/aztec.js'; import { decodeFunctionSignature } from '@aztec/foundation/abi'; import { DocsExampleContract, ReaderContract, TokenContract } from '@aztec/noir-contracts.js'; @@ -29,7 +28,7 @@ describe('e2e_token_contract', () => { const TOKEN_DECIMALS = 18n; let teardown: () => Promise; let wallets: AccountWallet[]; - let accounts: CompleteAddress[]; + let logger: DebugLogger; let asset: TokenContract; @@ -44,7 +43,7 @@ describe('e2e_token_contract', () => { const note = new Note([new Fr(amount), secretHash]); const extendedNote = new ExtendedNote( note, - accounts[accountIndex].address, + wallets[accountIndex].getAddress(), asset.address, storageSlot, noteTypeId, @@ -64,25 +63,25 @@ describe('e2e_token_contract', () => { }; beforeAll(async () => { - ({ teardown, logger, wallets, accounts } = await setup(3)); - await publicDeployAccounts(wallets[0], accounts.slice(0, 2)); + ({ teardown, logger, wallets } = await setup(3)); + await publicDeployAccounts(wallets[0], wallets.slice(0, 2)); TokenContract.artifact.functions.forEach(fn => { const sig = decodeFunctionSignature(fn.name, fn.parameters); logger(`Function ${sig} and the selector: ${FunctionSelector.fromNameAndParameters(fn.name, fn.parameters)}`); }); - asset = await TokenContract.deploy(wallets[0], accounts[0], TOKEN_NAME, TOKEN_SYMBOL, TOKEN_DECIMALS) + asset = await TokenContract.deploy(wallets[0], wallets[0].getAddress(), TOKEN_NAME, TOKEN_SYMBOL, TOKEN_DECIMALS) .send() .deployed(); logger(`Token deployed to ${asset.address}`); tokenSim = new TokenSimulator( asset, logger, - accounts.map(a => a.address), + wallets.map(w => w.getAddress()), ); - expect(await asset.methods.admin().simulate()).toBe(accounts[0].address.toBigInt()); + expect(await asset.methods.admin().simulate()).toBe(wallets[0].getAddress().toBigInt()); badAccount = await DocsExampleContract.deploy(wallets[0]).send().deployed(); }, 100_000); @@ -166,28 +165,28 @@ describe('e2e_token_contract', () => { describe('Access controlled functions', () => { it('Set admin', async () => { - await asset.methods.set_admin(accounts[1].address).send().wait(); - expect(await asset.methods.admin().simulate()).toBe(accounts[1].address.toBigInt()); + await asset.methods.set_admin(wallets[1].getAddress()).send().wait(); + expect(await asset.methods.admin().simulate()).toBe(wallets[1].getAddress().toBigInt()); }); it('Add minter as admin', async () => { - await asset.withWallet(wallets[1]).methods.set_minter(accounts[1].address, true).send().wait(); - expect(await asset.methods.is_minter(accounts[1].address).simulate()).toBe(true); + await asset.withWallet(wallets[1]).methods.set_minter(wallets[1].getAddress(), true).send().wait(); + expect(await asset.methods.is_minter(wallets[1].getAddress()).simulate()).toBe(true); }); it('Revoke minter as admin', async () => { - await asset.withWallet(wallets[1]).methods.set_minter(accounts[1].address, false).send().wait(); - expect(await asset.methods.is_minter(accounts[1].address).simulate()).toBe(false); + await asset.withWallet(wallets[1]).methods.set_minter(wallets[1].getAddress(), false).send().wait(); + expect(await asset.methods.is_minter(wallets[1].getAddress()).simulate()).toBe(false); }); describe('failure cases', () => { it('Set admin (not admin)', async () => { - await expect(asset.methods.set_admin(accounts[0].address).prove()).rejects.toThrow( + await expect(asset.methods.set_admin(wallets[0].getAddress()).prove()).rejects.toThrow( 'Assertion failed: caller is not admin', ); }); it('Revoke minter not as admin', async () => { - await expect(asset.methods.set_minter(accounts[0].address, false).prove()).rejects.toThrow( + await expect(asset.methods.set_minter(wallets[0].getAddress(), false).prove()).rejects.toThrow( 'Assertion failed: caller is not admin', ); }); @@ -198,11 +197,11 @@ describe('e2e_token_contract', () => { describe('Public', () => { it('as minter', async () => { const amount = 10000n; - await asset.methods.mint_public(accounts[0].address, amount).send().wait(); + await asset.methods.mint_public(wallets[0].getAddress(), amount).send().wait(); - tokenSim.mintPublic(accounts[0].address, amount); - expect(await asset.methods.balance_of_public(accounts[0].address).simulate()).toEqual( - tokenSim.balanceOfPublic(accounts[0].address), + tokenSim.mintPublic(wallets[0].getAddress(), amount); + expect(await asset.methods.balance_of_public(wallets[0].getAddress()).simulate()).toEqual( + tokenSim.balanceOfPublic(wallets[0].getAddress()), ); expect(await asset.methods.total_supply().simulate()).toEqual(tokenSim.totalSupply); }); @@ -211,27 +210,27 @@ describe('e2e_token_contract', () => { it('as non-minter', async () => { const amount = 10000n; await expect( - asset.withWallet(wallets[1]).methods.mint_public(accounts[0].address, amount).prove(), + asset.withWallet(wallets[1]).methods.mint_public(wallets[0].getAddress(), amount).prove(), ).rejects.toThrow('Assertion failed: caller is not minter'); }); it('mint >u128 tokens to overflow', async () => { const amount = 2n ** 128n; // U128::max() + 1; - await expect(asset.methods.mint_public(accounts[0].address, amount).prove()).rejects.toThrow( + await expect(asset.methods.mint_public(wallets[0].getAddress(), amount).prove()).rejects.toThrow( BITSIZE_TOO_BIG_ERROR, ); }); it('mint u128', async () => { - const amount = 2n ** 128n - tokenSim.balanceOfPublic(accounts[0].address); - await expect(asset.methods.mint_public(accounts[0].address, amount).prove()).rejects.toThrow( + const amount = 2n ** 128n - tokenSim.balanceOfPublic(wallets[0].getAddress()); + await expect(asset.methods.mint_public(wallets[0].getAddress(), amount).prove()).rejects.toThrow( U128_OVERFLOW_ERROR, ); }); it('mint u128', async () => { - const amount = 2n ** 128n - tokenSim.balanceOfPublic(accounts[0].address); - await expect(asset.methods.mint_public(accounts[1].address, amount).prove()).rejects.toThrow( + const amount = 2n ** 128n - tokenSim.balanceOfPublic(wallets[0].getAddress()); + await expect(asset.methods.mint_public(wallets[1].getAddress(), amount).prove()).rejects.toThrow( U128_OVERFLOW_ERROR, ); }); @@ -257,11 +256,11 @@ describe('e2e_token_contract', () => { it('redeem as recipient', async () => { await addPendingShieldNoteToPXE(0, amount, secretHash, txHash); - const txClaim = asset.methods.redeem_shield(accounts[0].address, amount, secret).send(); + const txClaim = asset.methods.redeem_shield(wallets[0].getAddress(), amount, secret).send(); // docs:start:debug const receiptClaim = await txClaim.wait({ debug: true }); // docs:end:debug - tokenSim.redeemShield(accounts[0].address, amount); + tokenSim.redeemShield(wallets[0].getAddress(), amount); // 1 note should be created containing `amount` of tokens const { visibleNotes } = receiptClaim.debugInfo!; expect(visibleNotes.length).toBe(1); @@ -274,7 +273,7 @@ describe('e2e_token_contract', () => { await expect(addPendingShieldNoteToPXE(0, amount, secretHash, txHash)).rejects.toThrow( 'The note has been destroyed.', ); - await expect(asset.methods.redeem_shield(accounts[0].address, amount, secret).prove()).rejects.toThrow( + await expect(asset.methods.redeem_shield(wallets[0].getAddress(), amount, secret).prove()).rejects.toThrow( `Assertion failed: Cannot return zero notes`, ); }); @@ -291,7 +290,7 @@ describe('e2e_token_contract', () => { }); it('mint u128', async () => { - const amount = 2n ** 128n - tokenSim.balanceOfPrivate(accounts[0].address); + const amount = 2n ** 128n - tokenSim.balanceOfPrivate(wallets[0].getAddress()); expect(amount).toBeLessThan(2n ** 128n); await expect(asset.methods.mint_private(amount, secretHash).prove()).rejects.toThrow(U128_OVERFLOW_ERROR); }); @@ -307,25 +306,25 @@ describe('e2e_token_contract', () => { describe('Transfer', () => { describe('public', () => { it('transfer less than balance', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; expect(amount).toBeGreaterThan(0n); - await asset.methods.transfer_public(accounts[0].address, accounts[1].address, amount, 0).send().wait(); + await asset.methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, 0).send().wait(); - tokenSim.transferPublic(accounts[0].address, accounts[1].address, amount); + tokenSim.transferPublic(wallets[0].getAddress(), wallets[1].getAddress(), amount); }); it('transfer to self', async () => { - const balance = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance / 2n; expect(amount).toBeGreaterThan(0n); - await asset.methods.transfer_public(accounts[0].address, accounts[0].address, amount, 0).send().wait(); + await asset.methods.transfer_public(wallets[0].getAddress(), wallets[0].getAddress(), amount, 0).send().wait(); - tokenSim.transferPublic(accounts[0].address, accounts[0].address, amount); + tokenSim.transferPublic(wallets[0].getAddress(), wallets[0].getAddress(), amount); }); it('transfer on behalf of other', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; expect(amount).toBeGreaterThan(0n); const nonce = Fr.random(); @@ -333,78 +332,78 @@ describe('e2e_token_contract', () => { // docs:start:authwit_public_transfer_example const action = asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); - await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, true).send().wait(); + await wallets[0].setPublicAuthWit({ caller: wallets[1].getAddress(), action }, true).send().wait(); // docs:end:authwit_public_transfer_example // Perform the transfer await action.send().wait(); - tokenSim.transferPublic(accounts[0].address, accounts[1].address, amount); + tokenSim.transferPublic(wallets[0].getAddress(), wallets[1].getAddress(), amount); // Check that the message hash is no longer valid. Need to try to send since nullifiers are handled by sequencer. const txReplay = asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce) + .methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce) .send(); await expect(txReplay.wait()).rejects.toThrow('Transaction '); }); describe('failure cases', () => { it('transfer more than balance', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 + 1n; const nonce = 0; await expect( - asset.methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce).prove(), + asset.methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce).prove(), ).rejects.toThrow(U128_UNDERFLOW_ERROR); }); it('transfer on behalf of self with non-zero nonce', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 - 1n; const nonce = 1; await expect( - asset.methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce).prove(), + asset.methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce).prove(), ).rejects.toThrow('Assertion failed: invalid nonce'); }); it('transfer on behalf of other without "approval"', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 + 1n; const nonce = Fr.random(); await expect( asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce) + .methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce) .prove(), ).rejects.toThrow('Assertion failed: Message not authorized by account'); }); it('transfer more than balance on behalf of other', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); - const balance1 = await asset.methods.balance_of_public(accounts[1].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); + const balance1 = await asset.methods.balance_of_public(wallets[1].getAddress()).simulate(); const amount = balance0 + 1n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); const action = asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); expect( - await wallets[0].lookupValidity(wallets[0].getAddress(), { caller: accounts[1].address, action }), + await wallets[0].lookupValidity(wallets[0].getAddress(), { caller: wallets[1].getAddress(), action }), ).toEqual({ isValidInPrivate: false, isValidInPublic: false, }); // We need to compute the message we want to sign and add it to the wallet as approved - await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, true).send().wait(); + await wallets[0].setPublicAuthWit({ caller: wallets[1].getAddress(), action }, true).send().wait(); expect( - await wallets[0].lookupValidity(wallets[0].getAddress(), { caller: accounts[1].address, action }), + await wallets[0].lookupValidity(wallets[0].getAddress(), { caller: wallets[1].getAddress(), action }), ).toEqual({ isValidInPrivate: false, isValidInPublic: true, @@ -413,13 +412,13 @@ describe('e2e_token_contract', () => { // Perform the transfer await expect(action.prove()).rejects.toThrow(U128_UNDERFLOW_ERROR); - expect(await asset.methods.balance_of_public(accounts[0].address).simulate()).toEqual(balance0); - expect(await asset.methods.balance_of_public(accounts[1].address).simulate()).toEqual(balance1); + expect(await asset.methods.balance_of_public(wallets[0].getAddress()).simulate()).toEqual(balance0); + expect(await asset.methods.balance_of_public(wallets[1].getAddress()).simulate()).toEqual(balance1); }); it('transfer on behalf of other, wrong designated caller', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); - const balance1 = await asset.methods.balance_of_public(accounts[1].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); + const balance1 = await asset.methods.balance_of_public(wallets[1].getAddress()).simulate(); const amount = balance0 + 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); @@ -427,20 +426,20 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); - await wallets[0].setPublicAuthWit({ caller: accounts[0].address, action }, true).send().wait(); + await wallets[0].setPublicAuthWit({ caller: wallets[0].getAddress(), action }, true).send().wait(); // Perform the transfer await expect(action.prove()).rejects.toThrow('Assertion failed: Message not authorized by account'); - expect(await asset.methods.balance_of_public(accounts[0].address).simulate()).toEqual(balance0); - expect(await asset.methods.balance_of_public(accounts[1].address).simulate()).toEqual(balance1); + expect(await asset.methods.balance_of_public(wallets[0].getAddress()).simulate()).toEqual(balance0); + expect(await asset.methods.balance_of_public(wallets[1].getAddress()).simulate()).toEqual(balance1); }); it('transfer on behalf of other, wrong designated caller', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); - const balance1 = await asset.methods.balance_of_public(accounts[1].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); + const balance1 = await asset.methods.balance_of_public(wallets[1].getAddress()).simulate(); const amount = balance0 + 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); @@ -448,71 +447,71 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); - await wallets[0].setPublicAuthWit({ caller: accounts[0].address, action }, true).send().wait(); + .methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); + await wallets[0].setPublicAuthWit({ caller: wallets[0].getAddress(), action }, true).send().wait(); // Perform the transfer await expect(action.prove()).rejects.toThrow('Assertion failed: Message not authorized by account'); - expect(await asset.methods.balance_of_public(accounts[0].address).simulate()).toEqual(balance0); - expect(await asset.methods.balance_of_public(accounts[1].address).simulate()).toEqual(balance1); + expect(await asset.methods.balance_of_public(wallets[0].getAddress()).simulate()).toEqual(balance0); + expect(await asset.methods.balance_of_public(wallets[1].getAddress()).simulate()).toEqual(balance1); }); it('transfer on behalf of other, cancelled authwit', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; expect(amount).toBeGreaterThan(0n); const nonce = Fr.random(); const action = asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); - await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, true).send().wait(); + await wallets[0].setPublicAuthWit({ caller: wallets[1].getAddress(), action }, true).send().wait(); - await wallets[0].cancelAuthWit({ caller: accounts[1].address, action }).send().wait(); + await wallets[0].cancelAuthWit({ caller: wallets[1].getAddress(), action }).send().wait(); // Check that the authwit is no longer valid. Need to try to send since nullifiers are handled by sequencer. const txCancelledAuthwit = asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce) + .methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce) .send(); await expect(txCancelledAuthwit.wait()).rejects.toThrowError('Transaction '); }); it('transfer on behalf of other, cancelled authwit, flow 2', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; expect(amount).toBeGreaterThan(0n); const nonce = Fr.random(); const action = asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); - await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, true).send().wait(); + await wallets[0].setPublicAuthWit({ caller: wallets[1].getAddress(), action }, true).send().wait(); - await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, false).send().wait(); + await wallets[0].setPublicAuthWit({ caller: wallets[1].getAddress(), action }, false).send().wait(); // Check that the authwit is no longer valid. Need to try to send since nullifiers are handled by sequencer. const txCancelledAuthwit = asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce) + .methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce) .send(); await expect(txCancelledAuthwit.wait()).rejects.toThrowError('Transaction '); }); it('transfer on behalf of other, cancelled authwit, flow 3', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; expect(amount).toBeGreaterThan(0n); const nonce = Fr.random(); const action = asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); const messageHash = computeAuthWitMessageHash( - accounts[1].address, + wallets[1].getAddress(), wallets[0].getChainId(), wallets[0].getVersion(), action.request(), @@ -525,7 +524,7 @@ describe('e2e_token_contract', () => { // Check that the message hash is no longer valid. Need to try to send since nullifiers are handled by sequencer. const txCancelledAuthwit = asset .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce) + .methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce) .send(); await expect(txCancelledAuthwit.wait()).rejects.toThrow('Transaction '); }); @@ -536,7 +535,7 @@ describe('e2e_token_contract', () => { // Should fail as the returned value from the badAccount is malformed const txCancelledAuthwit = asset .withWallet(wallets[1]) - .methods.transfer_public(badAccount.address, accounts[1].address, 0, nonce) + .methods.transfer_public(badAccount.address, wallets[1].getAddress(), 0, nonce) .send(); await expect(txCancelledAuthwit.wait()).rejects.toThrow( "Assertion failed: Message not authorized by account 'result == IS_VALID_SELECTOR'", @@ -554,23 +553,23 @@ describe('e2e_token_contract', () => { describe('private', () => { it('transfer less than balance', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; expect(amount).toBeGreaterThan(0n); - await asset.methods.transfer(accounts[0].address, accounts[1].address, amount, 0).send().wait(); - tokenSim.transferPrivate(accounts[0].address, accounts[1].address, amount); + await asset.methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, 0).send().wait(); + tokenSim.transferPrivate(wallets[0].getAddress(), wallets[1].getAddress(), amount); }); it('transfer to self', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; expect(amount).toBeGreaterThan(0n); - await asset.methods.transfer(accounts[0].address, accounts[0].address, amount, 0).send().wait(); - tokenSim.transferPrivate(accounts[0].address, accounts[0].address, amount); + await asset.methods.transfer(wallets[0].getAddress(), wallets[0].getAddress(), amount, 0).send().wait(); + tokenSim.transferPrivate(wallets[0].getAddress(), wallets[0].getAddress(), amount); }); it('transfer on behalf of other', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); @@ -579,12 +578,12 @@ describe('e2e_token_contract', () => { // docs:start:authwit_transfer_example const action = asset .withWallet(wallets[1]) - .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); - const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); + const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); await wallets[1].addAuthWitness(witness); expect( - await wallets[0].lookupValidity(wallets[0].getAddress(), { caller: accounts[1].address, action }), + await wallets[0].lookupValidity(wallets[0].getAddress(), { caller: wallets[1].getAddress(), action }), ).toEqual({ isValidInPrivate: true, isValidInPublic: false, @@ -593,38 +592,38 @@ describe('e2e_token_contract', () => { // Perform the transfer await action.send().wait(); - tokenSim.transferPrivate(accounts[0].address, accounts[1].address, amount); + tokenSim.transferPrivate(wallets[0].getAddress(), wallets[1].getAddress(), amount); // Perform the transfer again, should fail const txReplay = asset .withWallet(wallets[1]) - .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce) + .methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce) .send(); await expect(txReplay.wait()).rejects.toThrow('Transaction '); }); describe('failure cases', () => { it('transfer more than balance', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 + 1n; expect(amount).toBeGreaterThan(0n); await expect( - asset.methods.transfer(accounts[0].address, accounts[1].address, amount, 0).prove(), + asset.methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, 0).prove(), ).rejects.toThrow('Assertion failed: Balance too low'); }); it('transfer on behalf of self with non-zero nonce', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 - 1n; expect(amount).toBeGreaterThan(0n); await expect( - asset.methods.transfer(accounts[0].address, accounts[1].address, amount, 1).prove(), + asset.methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, 1).prove(), ).rejects.toThrow('Assertion failed: invalid nonce'); }); it('transfer more than balance on behalf of other', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); - const balance1 = await asset.methods.balance_of_private(accounts[1].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); + const balance1 = await asset.methods.balance_of_private(wallets[1].getAddress()).simulate(); const amount = balance0 + 1n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); @@ -632,18 +631,18 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[1]) - .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); // Both wallets are connected to same node and PXE so we could just insert directly using // await wallet.signAndAddAuthWitness(messageHash, ); // But doing it in two actions to show the flow. - const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); + const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); await wallets[1].addAuthWitness(witness); // Perform the transfer await expect(action.prove()).rejects.toThrow('Assertion failed: Balance too low'); - expect(await asset.methods.balance_of_private(accounts[0].address).simulate()).toEqual(balance0); - expect(await asset.methods.balance_of_private(accounts[1].address).simulate()).toEqual(balance1); + expect(await asset.methods.balance_of_private(wallets[0].getAddress()).simulate()).toEqual(balance0); + expect(await asset.methods.balance_of_private(wallets[1].getAddress()).simulate()).toEqual(balance1); }); it.skip('transfer into account to overflow', () => { @@ -654,7 +653,7 @@ describe('e2e_token_contract', () => { }); it('transfer on behalf of other without approval', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); @@ -662,9 +661,9 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[1]) - .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); const messageHash = computeAuthWitMessageHash( - accounts[1].address, + wallets[1].getAddress(), wallets[0].getChainId(), wallets[0].getVersion(), action.request(), @@ -676,7 +675,7 @@ describe('e2e_token_contract', () => { }); it('transfer on behalf of other, wrong designated caller', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); @@ -684,25 +683,25 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[2]) - .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); const expectedMessageHash = computeAuthWitMessageHash( - accounts[2].address, + wallets[2].getAddress(), wallets[0].getChainId(), wallets[0].getVersion(), action.request(), ); - const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); + const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); await wallets[2].addAuthWitness(witness); await expect(action.prove()).rejects.toThrow( `Unknown auth witness for message hash ${expectedMessageHash.toString()}`, ); - expect(await asset.methods.balance_of_private(accounts[0].address).simulate()).toEqual(balance0); + expect(await asset.methods.balance_of_private(wallets[0].getAddress()).simulate()).toEqual(balance0); }); it('transfer on behalf of other, cancelled authwit', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); @@ -710,9 +709,9 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[1]) - .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); - const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); + const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); await wallets[1].addAuthWitness(witness); await wallets[0].cancelAuthWit(witness.requestHash).send().wait(); @@ -720,13 +719,13 @@ describe('e2e_token_contract', () => { // Perform the transfer, should fail because nullifier already emitted const txCancelledAuthwit = asset .withWallet(wallets[1]) - .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce) + .methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce) .send(); await expect(txCancelledAuthwit.wait()).rejects.toThrowError('Transaction '); }); it('transfer on behalf of other, cancelled authwit, flow 2', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); @@ -734,17 +733,17 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[1]) - .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce); + .methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); - const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); + const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); await wallets[1].addAuthWitness(witness); - await wallets[0].cancelAuthWit({ caller: accounts[1].address, action }).send().wait(); + await wallets[0].cancelAuthWit({ caller: wallets[1].getAddress(), action }).send().wait(); // Perform the transfer, should fail because nullifier already emitted const txCancelledAuthwit = asset .withWallet(wallets[1]) - .methods.transfer(accounts[0].address, accounts[1].address, amount, nonce) + .methods.transfer(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce) .send(); await expect(txCancelledAuthwit.wait()).rejects.toThrow('Transaction '); }); @@ -755,7 +754,7 @@ describe('e2e_token_contract', () => { // Should fail as the returned value from the badAccount is malformed const txCancelledAuthwit = asset .withWallet(wallets[1]) - .methods.transfer(badAccount.address, accounts[1].address, 0, nonce) + .methods.transfer(badAccount.address, wallets[1].getAddress(), 0, nonce) .send(); await expect(txCancelledAuthwit.wait()).rejects.toThrow( "Assertion failed: Message not authorized by account 'result == IS_VALID_SELECTOR'", @@ -774,106 +773,106 @@ describe('e2e_token_contract', () => { }); it('on behalf of self', async () => { - const balancePub = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balancePub = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balancePub / 2n; expect(amount).toBeGreaterThan(0n); - const receipt = await asset.methods.shield(accounts[0].address, amount, secretHash, 0).send().wait(); + const receipt = await asset.methods.shield(wallets[0].getAddress(), amount, secretHash, 0).send().wait(); - tokenSim.shield(accounts[0].address, amount); + tokenSim.shield(wallets[0].getAddress(), amount); await tokenSim.check(); // Redeem it await addPendingShieldNoteToPXE(0, amount, secretHash, receipt.txHash); - await asset.methods.redeem_shield(accounts[0].address, amount, secret).send().wait(); + await asset.methods.redeem_shield(wallets[0].getAddress(), amount, secret).send().wait(); - tokenSim.redeemShield(accounts[0].address, amount); + tokenSim.redeemShield(wallets[0].getAddress(), amount); }); it('on behalf of other', async () => { - const balancePub = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balancePub = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balancePub / 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset.withWallet(wallets[1]).methods.shield(accounts[0].address, amount, secretHash, nonce); - await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, true).send().wait(); + const action = asset.withWallet(wallets[1]).methods.shield(wallets[0].getAddress(), amount, secretHash, nonce); + await wallets[0].setPublicAuthWit({ caller: wallets[1].getAddress(), action }, true).send().wait(); const receipt = await action.send().wait(); - tokenSim.shield(accounts[0].address, amount); + tokenSim.shield(wallets[0].getAddress(), amount); await tokenSim.check(); // Check that replaying the shield should fail! const txReplay = asset .withWallet(wallets[1]) - .methods.shield(accounts[0].address, amount, secretHash, nonce) + .methods.shield(wallets[0].getAddress(), amount, secretHash, nonce) .send(); await expect(txReplay.wait()).rejects.toThrow('Transaction '); // Redeem it await addPendingShieldNoteToPXE(0, amount, secretHash, receipt.txHash); - await asset.methods.redeem_shield(accounts[0].address, amount, secret).send().wait(); + await asset.methods.redeem_shield(wallets[0].getAddress(), amount, secret).send().wait(); - tokenSim.redeemShield(accounts[0].address, amount); + tokenSim.redeemShield(wallets[0].getAddress(), amount); }); describe('failure cases', () => { it('on behalf of self (more than balance)', async () => { - const balancePub = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balancePub = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balancePub + 1n; expect(amount).toBeGreaterThan(0n); - await expect(asset.methods.shield(accounts[0].address, amount, secretHash, 0).prove()).rejects.toThrow( + await expect(asset.methods.shield(wallets[0].getAddress(), amount, secretHash, 0).prove()).rejects.toThrow( U128_UNDERFLOW_ERROR, ); }); it('on behalf of self (invalid nonce)', async () => { - const balancePub = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balancePub = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balancePub + 1n; expect(amount).toBeGreaterThan(0n); - await expect(asset.methods.shield(accounts[0].address, amount, secretHash, 1).prove()).rejects.toThrow( + await expect(asset.methods.shield(wallets[0].getAddress(), amount, secretHash, 1).prove()).rejects.toThrow( 'Assertion failed: invalid nonce', ); }); it('on behalf of other (more than balance)', async () => { - const balancePub = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balancePub = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balancePub + 1n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset.withWallet(wallets[1]).methods.shield(accounts[0].address, amount, secretHash, nonce); - await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, true).send().wait(); + const action = asset.withWallet(wallets[1]).methods.shield(wallets[0].getAddress(), amount, secretHash, nonce); + await wallets[0].setPublicAuthWit({ caller: wallets[1].getAddress(), action }, true).send().wait(); await expect(action.prove()).rejects.toThrow(U128_UNDERFLOW_ERROR); }); it('on behalf of other (wrong designated caller)', async () => { - const balancePub = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balancePub = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balancePub + 1n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset.withWallet(wallets[2]).methods.shield(accounts[0].address, amount, secretHash, nonce); - await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, true).send().wait(); + const action = asset.withWallet(wallets[2]).methods.shield(wallets[0].getAddress(), amount, secretHash, nonce); + await wallets[0].setPublicAuthWit({ caller: wallets[1].getAddress(), action }, true).send().wait(); await expect(action.prove()).rejects.toThrow('Assertion failed: Message not authorized by account'); }); it('on behalf of other (without approval)', async () => { - const balance = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance / 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); await expect( - asset.withWallet(wallets[1]).methods.shield(accounts[0].address, amount, secretHash, nonce).prove(), + asset.withWallet(wallets[1]).methods.shield(wallets[0].getAddress(), amount, secretHash, nonce).prove(), ).rejects.toThrow(`Assertion failed: Message not authorized by account`); }); }); @@ -881,17 +880,17 @@ describe('e2e_token_contract', () => { describe('Unshielding', () => { it('on behalf of self', async () => { - const balancePriv = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balancePriv = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balancePriv / 2n; expect(amount).toBeGreaterThan(0n); - await asset.methods.unshield(accounts[0].address, accounts[0].address, amount, 0).send().wait(); + await asset.methods.unshield(wallets[0].getAddress(), wallets[0].getAddress(), amount, 0).send().wait(); - tokenSim.unshield(accounts[0].address, accounts[0].address, amount); + tokenSim.unshield(wallets[0].getAddress(), wallets[0].getAddress(), amount); }); it('on behalf of other', async () => { - const balancePriv0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balancePriv0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balancePriv0 / 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); @@ -899,47 +898,47 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[1]) - .methods.unshield(accounts[0].address, accounts[1].address, amount, nonce); + .methods.unshield(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. - const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); + const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); await wallets[1].addAuthWitness(witness); await action.send().wait(); - tokenSim.unshield(accounts[0].address, accounts[1].address, amount); + tokenSim.unshield(wallets[0].getAddress(), wallets[1].getAddress(), amount); // Perform the transfer again, should fail const txReplay = asset .withWallet(wallets[1]) - .methods.unshield(accounts[0].address, accounts[1].address, amount, nonce) + .methods.unshield(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce) .send(); await expect(txReplay.wait()).rejects.toThrow('Transaction '); }); describe('failure cases', () => { it('on behalf of self (more than balance)', async () => { - const balancePriv = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balancePriv = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balancePriv + 1n; expect(amount).toBeGreaterThan(0n); await expect( - asset.methods.unshield(accounts[0].address, accounts[0].address, amount, 0).prove(), + asset.methods.unshield(wallets[0].getAddress(), wallets[0].getAddress(), amount, 0).prove(), ).rejects.toThrow('Assertion failed: Balance too low'); }); it('on behalf of self (invalid nonce)', async () => { - const balancePriv = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balancePriv = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balancePriv + 1n; expect(amount).toBeGreaterThan(0n); await expect( - asset.methods.unshield(accounts[0].address, accounts[0].address, amount, 1).prove(), + asset.methods.unshield(wallets[0].getAddress(), wallets[0].getAddress(), amount, 1).prove(), ).rejects.toThrow('Assertion failed: invalid nonce'); }); it('on behalf of other (more than balance)', async () => { - const balancePriv0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balancePriv0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balancePriv0 + 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); @@ -947,18 +946,18 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[1]) - .methods.unshield(accounts[0].address, accounts[1].address, amount, nonce); + .methods.unshield(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. - const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); + const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); await wallets[1].addAuthWitness(witness); await expect(action.prove()).rejects.toThrow('Assertion failed: Balance too low'); }); it('on behalf of other (invalid designated caller)', async () => { - const balancePriv0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balancePriv0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balancePriv0 + 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); @@ -966,9 +965,9 @@ describe('e2e_token_contract', () => { // We need to compute the message we want to sign and add it to the wallet as approved const action = asset .withWallet(wallets[2]) - .methods.unshield(accounts[0].address, accounts[1].address, amount, nonce); + .methods.unshield(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); const expectedMessageHash = computeAuthWitMessageHash( - accounts[2].address, + wallets[2].getAddress(), wallets[0].getChainId(), wallets[0].getVersion(), action.request(), @@ -976,7 +975,7 @@ describe('e2e_token_contract', () => { // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. - const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); + const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); await wallets[2].addAuthWitness(witness); await expect(action.prove()).rejects.toThrow( @@ -989,87 +988,87 @@ describe('e2e_token_contract', () => { describe('Burn', () => { describe('public', () => { it('burn less than balance', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; expect(amount).toBeGreaterThan(0n); - await asset.methods.burn_public(accounts[0].address, amount, 0).send().wait(); + await asset.methods.burn_public(wallets[0].getAddress(), amount, 0).send().wait(); - tokenSim.burnPublic(accounts[0].address, amount); + tokenSim.burnPublic(wallets[0].getAddress(), amount); }); it('burn on behalf of other', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; expect(amount).toBeGreaterThan(0n); const nonce = Fr.random(); // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce); - await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, true).send().wait(); + const action = asset.withWallet(wallets[1]).methods.burn_public(wallets[0].getAddress(), amount, nonce); + await wallets[0].setPublicAuthWit({ caller: wallets[1].getAddress(), action }, true).send().wait(); await action.send().wait(); - tokenSim.burnPublic(accounts[0].address, amount); + tokenSim.burnPublic(wallets[0].getAddress(), amount); // Check that the message hash is no longer valid. Need to try to send since nullifiers are handled by sequencer. - const txReplay = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce).send(); + const txReplay = asset.withWallet(wallets[1]).methods.burn_public(wallets[0].getAddress(), amount, nonce).send(); await expect(txReplay.wait()).rejects.toThrow('Transaction '); }); describe('failure cases', () => { it('burn more than balance', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 + 1n; const nonce = 0; - await expect(asset.methods.burn_public(accounts[0].address, amount, nonce).prove()).rejects.toThrow( + await expect(asset.methods.burn_public(wallets[0].getAddress(), amount, nonce).prove()).rejects.toThrow( U128_UNDERFLOW_ERROR, ); }); it('burn on behalf of self with non-zero nonce', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 - 1n; expect(amount).toBeGreaterThan(0n); const nonce = 1; - await expect(asset.methods.burn_public(accounts[0].address, amount, nonce).prove()).rejects.toThrow( + await expect(asset.methods.burn_public(wallets[0].getAddress(), amount, nonce).prove()).rejects.toThrow( 'Assertion failed: invalid nonce', ); }); it('burn on behalf of other without "approval"', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 + 1n; const nonce = Fr.random(); await expect( - asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce).prove(), + asset.withWallet(wallets[1]).methods.burn_public(wallets[0].getAddress(), amount, nonce).prove(), ).rejects.toThrow('Assertion failed: Message not authorized by account'); }); it('burn more than balance on behalf of other', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 + 1n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce); - await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, true).send().wait(); + const action = asset.withWallet(wallets[1]).methods.burn_public(wallets[0].getAddress(), amount, nonce); + await wallets[0].setPublicAuthWit({ caller: wallets[1].getAddress(), action }, true).send().wait(); await expect(action.prove()).rejects.toThrow(U128_UNDERFLOW_ERROR); }); it('burn on behalf of other, wrong designated caller', async () => { - const balance0 = await asset.methods.balance_of_public(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); const amount = balance0 + 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce); - await wallets[0].setPublicAuthWit({ caller: accounts[0].address, action }, true).send().wait(); + const action = asset.withWallet(wallets[1]).methods.burn_public(wallets[0].getAddress(), amount, nonce); + await wallets[0].setPublicAuthWit({ caller: wallets[0].getAddress(), action }, true).send().wait(); await expect( - asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce).prove(), + asset.withWallet(wallets[1]).methods.burn_public(wallets[0].getAddress(), amount, nonce).prove(), ).rejects.toThrow('Assertion failed: Message not authorized by account'); }); }); @@ -1077,81 +1076,81 @@ describe('e2e_token_contract', () => { describe('private', () => { it('burn less than balance', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; expect(amount).toBeGreaterThan(0n); - await asset.methods.burn(accounts[0].address, amount, 0).send().wait(); - tokenSim.burnPrivate(accounts[0].address, amount); + await asset.methods.burn(wallets[0].getAddress(), amount, 0).send().wait(); + tokenSim.burnPrivate(wallets[0].getAddress(), amount); }); it('burn on behalf of other', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce); + const action = asset.withWallet(wallets[1]).methods.burn(wallets[0].getAddress(), amount, nonce); // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. - const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); + const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); await wallets[1].addAuthWitness(witness); - await asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce).send().wait(); - tokenSim.burnPrivate(accounts[0].address, amount); + await asset.withWallet(wallets[1]).methods.burn(wallets[0].getAddress(), amount, nonce).send().wait(); + tokenSim.burnPrivate(wallets[0].getAddress(), amount); // Perform the transfer again, should fail - const txReplay = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce).send(); + const txReplay = asset.withWallet(wallets[1]).methods.burn(wallets[0].getAddress(), amount, nonce).send(); await expect(txReplay.wait()).rejects.toThrow('Transaction '); }); describe('failure cases', () => { it('burn more than balance', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 + 1n; expect(amount).toBeGreaterThan(0n); - await expect(asset.methods.burn(accounts[0].address, amount, 0).prove()).rejects.toThrow( + await expect(asset.methods.burn(wallets[0].getAddress(), amount, 0).prove()).rejects.toThrow( 'Assertion failed: Balance too low', ); }); it('burn on behalf of self with non-zero nonce', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 - 1n; expect(amount).toBeGreaterThan(0n); - await expect(asset.methods.burn(accounts[0].address, amount, 1).prove()).rejects.toThrow( + await expect(asset.methods.burn(wallets[0].getAddress(), amount, 1).prove()).rejects.toThrow( 'Assertion failed: invalid nonce', ); }); it('burn more than balance on behalf of other', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 + 1n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce); + const action = asset.withWallet(wallets[1]).methods.burn(wallets[0].getAddress(), amount, nonce); // Both wallets are connected to same node and PXE so we could just insert directly // But doing it in two actions to show the flow. - const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); + const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); await wallets[1].addAuthWitness(witness); await expect(action.prove()).rejects.toThrow('Assertion failed: Balance too low'); }); it('burn on behalf of other without approval', async () => { - const balance0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balance0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balance0 / 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset.withWallet(wallets[1]).methods.burn(accounts[0].address, amount, nonce); + const action = asset.withWallet(wallets[1]).methods.burn(wallets[0].getAddress(), amount, nonce); const messageHash = computeAuthWitMessageHash( - accounts[1].address, + wallets[1].getAddress(), wallets[0].getChainId(), wallets[0].getVersion(), action.request(), @@ -1163,21 +1162,21 @@ describe('e2e_token_contract', () => { }); it('on behalf of other (invalid designated caller)', async () => { - const balancePriv0 = await asset.methods.balance_of_private(accounts[0].address).simulate(); + const balancePriv0 = await asset.methods.balance_of_private(wallets[0].getAddress()).simulate(); const amount = balancePriv0 + 2n; const nonce = Fr.random(); expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset.withWallet(wallets[2]).methods.burn(accounts[0].address, amount, nonce); + const action = asset.withWallet(wallets[2]).methods.burn(wallets[0].getAddress(), amount, nonce); const expectedMessageHash = computeAuthWitMessageHash( - accounts[2].address, + wallets[2].getAddress(), wallets[0].getChainId(), wallets[0].getVersion(), action.request(), ); - const witness = await wallets[0].createAuthWit({ caller: accounts[1].address, action }); + const witness = await wallets[0].createAuthWit({ caller: wallets[1].getAddress(), action }); await wallets[2].addAuthWitness(witness); await expect(action.prove()).rejects.toThrow( diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index fe6a4b23bc7..f33b7d00d36 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -1,24 +1,13 @@ import { SchnorrAccountContractArtifact } from '@aztec/accounts/schnorr'; import { createAccounts, getDeployedTestAccountsWallets } from '@aztec/accounts/testing'; -import { type AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node'; +import { AztecNodeService, getConfigEnvVars, type AztecNodeConfig } from '@aztec/aztec-node'; import { - type AccountWalletWithPrivateKey, - type AztecAddress, - type AztecNode, BatchCall, CheatCodes, - type CompleteAddress, - type ContractMethod, - type DebugLogger, - type DeployL1Contracts, EncryptedL2BlockL2Logs, EthCheatCodes, - type L1ContractArtifactsForDeployment, LogType, - type PXE, - type SentTx, SignerlessWallet, - type Wallet, createAztecNodeClient, createDebugLogger, createPXEClient, @@ -26,6 +15,16 @@ import { fileURLToPath, makeFetch, waitForPXE, + type AccountWalletWithPrivateKey, + type AztecAddress, + type AztecNode, + type ContractMethod, + type DebugLogger, + type DeployL1Contracts, + type L1ContractArtifactsForDeployment, + type PXE, + type SentTx, + type Wallet } from '@aztec/aztec.js'; import { deployInstance, registerContractClass } from '@aztec/aztec.js/deployment'; import { DefaultMultiCallEntrypoint } from '@aztec/entrypoints/multi-call'; @@ -47,21 +46,21 @@ import { RollupBytecode, } from '@aztec/l1-artifacts'; import { getCanonicalGasToken, getCanonicalGasTokenAddress } from '@aztec/protocol-contracts/gas-token'; -import { PXEService, type PXEServiceConfig, createPXEService, getPXEServiceConfig } from '@aztec/pxe'; +import { PXEService, createPXEService, getPXEServiceConfig, type PXEServiceConfig } from '@aztec/pxe'; import { type SequencerClient } from '@aztec/sequencer-client'; import * as fs from 'fs/promises'; import * as path from 'path'; import { + createPublicClient, + createWalletClient, + getContract, + http, type Account, type Chain, type HDAccount, type HttpTransport, type PrivateKeyAccount, - createPublicClient, - createWalletClient, - getContract, - http, } from 'viem'; import { mnemonicToAccount } from 'viem/accounts'; import { foundry } from 'viem/chains'; @@ -186,10 +185,6 @@ export async function setupPXEService( * The PXE instance. */ pxe: PXE; - /** - * The accounts created by the PXE. - */ - accounts: CompleteAddress[]; /** * The wallets to be used. */ @@ -206,7 +201,6 @@ export async function setupPXEService( return { pxe, - accounts: await pxe.getRegisteredAccounts(), wallets, logger, }; @@ -302,8 +296,6 @@ export type EndToEndContext = { pxe: PXE; /** Return values from deployL1Contracts function. */ deployL1ContractsValues: DeployL1Contracts; - /** The accounts created by the PXE. */ - accounts: CompleteAddress[]; /** The Aztec Node configuration. */ config: AztecNodeConfig; /** The first wallet to be used. */ @@ -369,7 +361,7 @@ export async function setup( const aztecNode = await AztecNodeService.createAndSync(config); const sequencer = aztecNode.getSequencer(); - const { pxe, accounts, wallets } = await setupPXEService(numberOfAccounts, aztecNode!, pxeOpts, logger); + const { pxe, wallets } = await setupPXEService(numberOfAccounts, aztecNode!, pxeOpts, logger); if (['1', 'true'].includes(ENABLE_GAS)) { await deployCanonicalGasToken(new SignerlessWallet(pxe, new DefaultMultiCallEntrypoint())); @@ -396,7 +388,6 @@ export async function setup( aztecNode, pxe, deployL1ContractsValues, - accounts, config, wallet: wallets[0], wallets, @@ -413,8 +404,8 @@ export async function setup( * @param sender - Wallet to send the deployment tx. * @param accountsToDeploy - Which accounts to publicly deploy. */ -export async function publicDeployAccounts(sender: Wallet, accountsToDeploy: (CompleteAddress | AztecAddress)[]) { - const accountAddressesToDeploy = accountsToDeploy.map(a => ('address' in a ? a.address : a)); +export async function publicDeployAccounts(sender: Wallet, accountsToDeploy: Wallet[]) { + const accountAddressesToDeploy = accountsToDeploy.map(a => a.getAddress()); const instances = await Promise.all(accountAddressesToDeploy.map(account => sender.getContractInstance(account))); const batch = new BatchCall(sender, [ (await registerContractClass(sender, SchnorrAccountContractArtifact)).request(), diff --git a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts index 3b01120511e..ef6d453af21 100644 --- a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts +++ b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts @@ -107,7 +107,7 @@ export const uniswapL1L2TestSuite = ( sponsorAddress = sponsorWallet.getAddress(); ownerEthAddress = EthAddress.fromString((await walletClient.getAddresses())[0]); - await publicDeployAccounts(ownerWallet, [ownerAddress, sponsorAddress]); + await publicDeployAccounts(ownerWallet, [ownerWallet, sponsorWallet]); logger('Deploying DAI Portal, initializing and deploying l2 contract...'); daiCrossChainHarness = await CrossChainTestHarness.new( diff --git a/yarn-project/pxe/src/contract_data_oracle/index.ts b/yarn-project/pxe/src/contract_data_oracle/index.ts index eaf53cb9be6..6fa2d1c86f4 100644 --- a/yarn-project/pxe/src/contract_data_oracle/index.ts +++ b/yarn-project/pxe/src/contract_data_oracle/index.ts @@ -34,6 +34,7 @@ export class ContractDataOracle { if (!this.contractInstances.has(contractAddress.toString())) { const instance = await this.db.getContractInstance(contractAddress); if (!instance) { + // tady 4 throw new ContractNotFoundError(contractAddress.toString()); } this.contractInstances.set(contractAddress.toString(), instance); @@ -76,6 +77,7 @@ export class ContractDataOracle { * @returns The corresponding function's artifact as an object. */ public async getFunctionArtifact(contractAddress: AztecAddress, selector: FunctionSelector) { + // tady 2 const tree = await this.getTreeForAddress(contractAddress); return tree.getFunctionArtifact(selector); } @@ -192,6 +194,7 @@ export class ContractDataOracle { * @throws An Error if the contract is not found in the ContractDatabase. */ private async getTreeForAddress(contractAddress: AztecAddress): Promise { + // tady 3 const instance = await this.getContractInstance(contractAddress); return this.getTreeForClassId(instance.contractClassId); } diff --git a/yarn-project/pxe/src/database/kv_pxe_database.ts b/yarn-project/pxe/src/database/kv_pxe_database.ts index aadab576f8d..cb491efb430 100644 --- a/yarn-project/pxe/src/database/kv_pxe_database.ts +++ b/yarn-project/pxe/src/database/kv_pxe_database.ts @@ -106,6 +106,7 @@ export class KVPxeDatabase implements PxeDatabase { } getContractInstance(address: AztecAddress): Promise { + // tady se to pta na data const contract = this.#contractInstances.get(address.toString()); return Promise.resolve(contract && SerializableContractInstance.fromBuffer(contract).withAddress(address)); } diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 92079b73330..ac07f460c15 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -247,6 +247,7 @@ export class PXEService implements PXE { } } + // here I don't see the contract being added this.log.info(`Added contract ${artifact.name} at ${instance.address.toString()}`); await this.db.addContractInstance(instance); await this.synchronizer.reprocessDeferredNotesForContract(instance.address); diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index 56e65ee0e81..def175e2a46 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -101,6 +101,12 @@ export class SimulatorOracle implements DBOracle { contractAddress: AztecAddress, selector: FunctionSelector, ): Promise { + // tady 1 + { + // TODO(#5555): this log out is here to verify a hypothesis that the e2e_account test flakiness is caused by slow sync + const nodeSyncedUpToBlock = await this.aztecNode.getBlockNumber(); + this.log(`Node synced up to block ${nodeSyncedUpToBlock}`); + } const artifact = await this.contractDataOracle.getFunctionArtifact(contractAddress, selector); const debug = await this.contractDataOracle.getFunctionDebugMetadata(contractAddress, selector); return { diff --git a/yarn-project/simulator/src/client/client_execution_context.ts b/yarn-project/simulator/src/client/client_execution_context.ts index 3f626293121..f95f6bdabd9 100644 --- a/yarn-project/simulator/src/client/client_execution_context.ts +++ b/yarn-project/simulator/src/client/client_execution_context.ts @@ -355,6 +355,7 @@ export class ClientExecutionContext extends ViewDataOracle { isStaticCall = isStaticCall || this.callContext.isStaticCall; + // tady 0 const targetArtifact = await this.db.getFunctionArtifact(targetContractAddress, functionSelector); const targetFunctionData = FunctionData.fromAbi(targetArtifact); From 0f4ff2379374a97c9fc4c011aa64deac0bb0d952 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 4 Apr 2024 15:16:03 +0000 Subject: [PATCH 2/3] fix --- yarn-project/end-to-end/src/e2e_fees.test.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/yarn-project/end-to-end/src/e2e_fees.test.ts b/yarn-project/end-to-end/src/e2e_fees.test.ts index c4e5547f231..1307bb1e0da 100644 --- a/yarn-project/end-to-end/src/e2e_fees.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees.test.ts @@ -9,15 +9,12 @@ import { TxStatus, computeAuthWitMessageHash, computeMessageSecretHash, - type AccountWalletWithPrivateKey, type AztecAddress, - type AztecNode, type DebugLogger, - type DeployL1Contracts, type FunctionCall, - type PXE, type TxHash, type Wallet, + type AccountWallet } from '@aztec/aztec.js'; import { FunctionData, getContractClassFromArtifact } from '@aztec/circuits.js'; import { decodeFunctionSignature, type ContractArtifact } from '@aztec/foundation/abi'; @@ -47,6 +44,7 @@ const BRIDGED_FPC_GAS = 500n; jest.setTimeout(1_000_000_000); describe('e2e_fees', () => { + let wallets: AccountWallet[]; let aliceWallet: Wallet; let aliceAddress: AztecAddress; let bobAddress: AztecAddress; @@ -63,7 +61,8 @@ describe('e2e_fees', () => { beforeAll(async () => { - const { wallets, aztecNode, deployL1ContractsValues, logger, pxe } = await setup(3); + const { wallets: _wallets, aztecNode, deployL1ContractsValues, logger, pxe } = await setup(3); + wallets = _wallets; await aztecNode.setConfig({ allowedFeePaymentContractClasses: [getContractClassFromArtifact(FPCContract.artifact).id], From 69a76ad082a282a8ac7adce2d80cdcb42306aeb4 Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 4 Apr 2024 15:20:55 +0000 Subject: [PATCH 3/3] cleanup --- .../src/benchmarks/bench_tx_size_fees.test.ts | 13 ++-- .../end-to-end/src/e2e_2_pxes.test.ts | 17 ++++- .../end-to-end/src/e2e_authwit.test.ts | 7 +- .../src/e2e_blacklist_token_contract.test.ts | 71 ++++++++++++------- .../src/e2e_counter_contract.test.ts | 6 +- .../src/e2e_dapp_subscription.test.ts | 19 ++--- .../src/e2e_escrow_contract.test.ts | 14 ++-- yarn-project/end-to-end/src/e2e_fees.test.ts | 25 +++---- .../src/e2e_inclusion_proofs_contract.test.ts | 7 +- .../src/e2e_lending_contract.test.ts | 8 +-- .../e2e_pending_note_hashes_contract.test.ts | 9 +-- .../src/e2e_private_voting_contract.test.ts | 10 +-- .../e2e_public_cross_chain_messaging.test.ts | 12 ++-- .../end-to-end/src/e2e_token_contract.test.ts | 13 ++-- yarn-project/end-to-end/src/fixtures/utils.ts | 32 ++++----- .../pxe/src/contract_data_oracle/index.ts | 3 - .../pxe/src/database/kv_pxe_database.ts | 1 - .../pxe/src/pxe_service/pxe_service.ts | 1 - .../pxe/src/simulator_oracle/index.ts | 6 -- .../src/client/client_execution_context.ts | 1 - 20 files changed, 128 insertions(+), 147 deletions(-) diff --git a/yarn-project/end-to-end/src/benchmarks/bench_tx_size_fees.test.ts b/yarn-project/end-to-end/src/benchmarks/bench_tx_size_fees.test.ts index 20252e7496f..def00fbbb70 100644 --- a/yarn-project/end-to-end/src/benchmarks/bench_tx_size_fees.test.ts +++ b/yarn-project/end-to-end/src/benchmarks/bench_tx_size_fees.test.ts @@ -1,15 +1,13 @@ import { - type AztecNode, - type DeployL1Contracts, + type AccountWalletWithPrivateKey, + type AztecAddress, type EthAddress, + type FeePaymentMethod, NativeFeePaymentMethod, PrivateFeePaymentMethod, PublicFeePaymentMethod, TxStatus, getContractClassFromArtifact, - type AccountWalletWithPrivateKey, - type AztecAddress, - type FeePaymentMethod, } from '@aztec/aztec.js'; import { FPCContract, GasTokenContract, TokenContract } from '@aztec/noir-contracts.js'; import { getCanonicalGasTokenAddress } from '@aztec/protocol-contracts/gas-token'; @@ -49,10 +47,7 @@ describe('benchmarks/tx_size_fees', () => { // deploy the contracts beforeAll(async () => { - gas = await GasTokenContract.at( - getCanonicalGasTokenAddress(gasPortalAddress), - aliceWallet, - ); + gas = await GasTokenContract.at(getCanonicalGasTokenAddress(gasPortalAddress), aliceWallet); token = await TokenContract.deploy(aliceWallet, aliceWallet.getAddress(), 'test', 'test', 18).send().deployed(); fpc = await FPCContract.deploy(aliceWallet, token.address, gas.address).send().deployed(); }); diff --git a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts index 050041098ae..170eb6c4d86 100644 --- a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts +++ b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts @@ -134,7 +134,10 @@ describe('e2e_2_pxes', () => { // Transfer funds from A to B via PXE A const contractWithWalletA = await TokenContract.at(tokenAddress, walletA); - await contractWithWalletA.methods.transfer(walletA.getAddress(), walletB.getAddress(), transferAmount1, 0).send().wait(); + await contractWithWalletA.methods + .transfer(walletA.getAddress(), walletB.getAddress(), transferAmount1, 0) + .send() + .wait(); // Check balances and logs are as expected await expectTokenBalance(walletA, tokenAddress, walletA.getAddress(), initialBalance - transferAmount1); @@ -149,7 +152,12 @@ describe('e2e_2_pxes', () => { .wait({ interval: 0.1 }); // Check balances and logs are as expected - await expectTokenBalance(walletA, tokenAddress, walletA.getAddress(), initialBalance - transferAmount1 + transferAmount2); + await expectTokenBalance( + walletA, + tokenAddress, + walletA.getAddress(), + initialBalance - transferAmount1 + transferAmount2, + ); await expectTokenBalance(walletB, tokenAddress, walletB.getAddress(), transferAmount1 - transferAmount2); await expectsNumOfEncryptedLogsInTheLastBlockToBe(aztecNode, 2); }, 120_000); @@ -270,7 +278,10 @@ describe('e2e_2_pxes', () => { // Transfer funds from A to B via PXE A const contractWithWalletA = await TokenContract.at(tokenAddress, walletA); - await contractWithWalletA.methods.transfer(walletA.getAddress(), walletB.getAddress(), transferAmount1, 0).send().wait(); + await contractWithWalletA.methods + .transfer(walletA.getAddress(), walletB.getAddress(), transferAmount1, 0) + .send() + .wait(); // now add the contract and check balances await pxeB.registerContract({ diff --git a/yarn-project/end-to-end/src/e2e_authwit.test.ts b/yarn-project/end-to-end/src/e2e_authwit.test.ts index e3c46af3e73..b882374745c 100644 --- a/yarn-project/end-to-end/src/e2e_authwit.test.ts +++ b/yarn-project/end-to-end/src/e2e_authwit.test.ts @@ -1,9 +1,4 @@ -import { - Fr, - computeInnerAuthWitHash, - computeOuterAuthWitHash, - type AccountWallet -} from '@aztec/aztec.js'; +import { type AccountWallet, Fr, computeInnerAuthWitHash, computeOuterAuthWitHash } from '@aztec/aztec.js'; import { SchnorrAccountContract } from '@aztec/noir-contracts.js'; import { jest } from '@jest/globals'; diff --git a/yarn-project/end-to-end/src/e2e_blacklist_token_contract.test.ts b/yarn-project/end-to-end/src/e2e_blacklist_token_contract.test.ts index 580f3c02803..1f44365bfcd 100644 --- a/yarn-project/end-to-end/src/e2e_blacklist_token_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_blacklist_token_contract.test.ts @@ -1,16 +1,16 @@ import { + type AccountWallet, AztecAddress, + type CheatCodes, + type DebugLogger, ExtendedNote, Fr, FunctionSelector, Note, + type TxHash, + type Wallet, computeAuthWitMessageHash, computeMessageSecretHash, - type AccountWallet, - type CheatCodes, - type DebugLogger, - type TxHash, - type Wallet } from '@aztec/aztec.js'; import { openTmpStore } from '@aztec/kv-store/utils'; import { Pedersen, SparseTree, newTree } from '@aztec/merkle-tree'; @@ -793,9 +793,9 @@ describe('e2e_blacklist_token_contract', () => { await wallets[3].addCapsule( getMembershipCapsule(await getMembershipProof(wallets[3].getAddress().toBigInt(), true)), ); - await expect(asset.methods.transfer(wallets[3].getAddress(), wallets[0].getAddress(), 1n, 0).prove()).rejects.toThrow( - "Assertion failed: Blacklisted: Sender '!from_roles.is_blacklisted'", - ); + await expect( + asset.methods.transfer(wallets[3].getAddress(), wallets[0].getAddress(), 1n, 0).prove(), + ).rejects.toThrow("Assertion failed: Blacklisted: Sender '!from_roles.is_blacklisted'"); }); it('transfer to a blacklisted account', async () => { @@ -805,9 +805,9 @@ describe('e2e_blacklist_token_contract', () => { await wallets[0].addCapsule( getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); - await expect(asset.methods.transfer(wallets[0].getAddress(), wallets[3].getAddress(), 1n, 0).prove()).rejects.toThrow( - "Assertion failed: Blacklisted: Recipient '!to_roles.is_blacklisted'", - ); + await expect( + asset.methods.transfer(wallets[0].getAddress(), wallets[3].getAddress(), 1n, 0).prove(), + ).rejects.toThrow("Assertion failed: Blacklisted: Recipient '!to_roles.is_blacklisted'"); }); }); }); @@ -833,7 +833,9 @@ describe('e2e_blacklist_token_contract', () => { // Redeem it await addPendingShieldNoteToPXE(0, amount, secretHash, receipt.txHash); - await wallets[0].addCapsule(getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true))); + await wallets[0].addCapsule( + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), + ); await asset.methods.redeem_shield(wallets[0].getAddress(), amount, secret).send().wait(); tokenSim.redeemShield(wallets[0].getAddress(), amount); @@ -863,7 +865,9 @@ describe('e2e_blacklist_token_contract', () => { // Redeem it await addPendingShieldNoteToPXE(0, amount, secretHash, receipt.txHash); - await wallets[0].addCapsule(getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true))); + await wallets[0].addCapsule( + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), + ); await asset.methods.redeem_shield(wallets[0].getAddress(), amount, secret).send().wait(); tokenSim.redeemShield(wallets[0].getAddress(), amount); @@ -944,8 +948,12 @@ describe('e2e_blacklist_token_contract', () => { const amount = balancePriv / 2n; expect(amount).toBeGreaterThan(0n); - await wallets[1].addCapsule(getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true))); - await wallets[1].addCapsule(getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true))); + await wallets[1].addCapsule( + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), + ); + await wallets[1].addCapsule( + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), + ); await asset.methods.unshield(wallets[0].getAddress(), wallets[0].getAddress(), amount, 0).send().wait(); tokenSim.unshield(wallets[0].getAddress(), wallets[0].getAddress(), amount); @@ -958,8 +966,12 @@ describe('e2e_blacklist_token_contract', () => { expect(amount).toBeGreaterThan(0n); // We need to compute the message we want to sign and add it to the wallet as approved - await wallets[1].addCapsule(getMembershipCapsule(await getMembershipProof(wallets[1].getAddress().toBigInt(), true))); - await wallets[1].addCapsule(getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true))); + await wallets[1].addCapsule( + getMembershipCapsule(await getMembershipProof(wallets[1].getAddress().toBigInt(), true)), + ); + await wallets[1].addCapsule( + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), + ); const action = asset .withWallet(wallets[1]) .methods.unshield(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); @@ -973,8 +985,12 @@ describe('e2e_blacklist_token_contract', () => { tokenSim.unshield(wallets[0].getAddress(), wallets[1].getAddress(), amount); // Perform the transfer again, should fail - await wallets[1].addCapsule(getMembershipCapsule(await getMembershipProof(wallets[1].getAddress().toBigInt(), true))); - await wallets[1].addCapsule(getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true))); + await wallets[1].addCapsule( + getMembershipCapsule(await getMembershipProof(wallets[1].getAddress().toBigInt(), true)), + ); + await wallets[1].addCapsule( + getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), + ); const txReplay = asset .withWallet(wallets[1]) .methods.unshield(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce) @@ -1083,9 +1099,9 @@ describe('e2e_blacklist_token_contract', () => { await wallets[0].addCapsule( getMembershipCapsule(await getMembershipProof(wallets[3].getAddress().toBigInt(), true)), ); - await expect(asset.methods.unshield(wallets[3].getAddress(), wallets[0].getAddress(), 1n, 0).prove()).rejects.toThrow( - "Assertion failed: Blacklisted: Sender '!from_roles.is_blacklisted'", - ); + await expect( + asset.methods.unshield(wallets[3].getAddress(), wallets[0].getAddress(), 1n, 0).prove(), + ).rejects.toThrow("Assertion failed: Blacklisted: Sender '!from_roles.is_blacklisted'"); }); it('unshield to blacklisted account', async () => { @@ -1095,9 +1111,9 @@ describe('e2e_blacklist_token_contract', () => { await wallets[0].addCapsule( getMembershipCapsule(await getMembershipProof(wallets[0].getAddress().toBigInt(), true)), ); - await expect(asset.methods.unshield(wallets[0].getAddress(), wallets[3].getAddress(), 1n, 0).prove()).rejects.toThrow( - "Assertion failed: Blacklisted: Recipient '!to_roles.is_blacklisted'", - ); + await expect( + asset.methods.unshield(wallets[0].getAddress(), wallets[3].getAddress(), 1n, 0).prove(), + ).rejects.toThrow("Assertion failed: Blacklisted: Recipient '!to_roles.is_blacklisted'"); }); }); }); @@ -1128,7 +1144,10 @@ describe('e2e_blacklist_token_contract', () => { tokenSim.burnPublic(wallets[0].getAddress(), amount); // Check that the message hash is no longer valid. Need to try to send since nullifiers are handled by sequencer. - const txReplay = asset.withWallet(wallets[1]).methods.burn_public(wallets[0].getAddress(), amount, nonce).send(); + const txReplay = asset + .withWallet(wallets[1]) + .methods.burn_public(wallets[0].getAddress(), amount, nonce) + .send(); await expect(txReplay.wait()).rejects.toThrow('Transaction '); }); diff --git a/yarn-project/end-to-end/src/e2e_counter_contract.test.ts b/yarn-project/end-to-end/src/e2e_counter_contract.test.ts index 2e7daaaf5a7..98f4dd931b3 100644 --- a/yarn-project/end-to-end/src/e2e_counter_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_counter_contract.test.ts @@ -13,11 +13,7 @@ describe('e2e_counter_contract', () => { beforeAll(async () => { // Setup environment - ({ - teardown, - wallet, - logger, - } = await setup(1)); + ({ teardown, wallet, logger } = await setup(1)); owner = wallet.getAddress(); counterContract = await CounterContract.deploy(wallet, 0, owner).send().deployed(); diff --git a/yarn-project/end-to-end/src/e2e_dapp_subscription.test.ts b/yarn-project/end-to-end/src/e2e_dapp_subscription.test.ts index 1df66c7eadc..90348fa8d28 100644 --- a/yarn-project/end-to-end/src/e2e_dapp_subscription.test.ts +++ b/yarn-project/end-to-end/src/e2e_dapp_subscription.test.ts @@ -1,16 +1,16 @@ import { type AccountWalletWithPrivateKey, type AztecAddress, + type AztecNode, + type DebugLogger, + type DeployL1Contracts, type FeePaymentMethod, Fr, + type PXE, PrivateFeePaymentMethod, PublicFeePaymentMethod, SentTx, getContractClassFromArtifact, - type AztecNode, - type DeployL1Contracts, - type PXE, - type DebugLogger, } from '@aztec/aztec.js'; import { DefaultDappEntrypoint } from '@aztec/entrypoints/dapp'; import { @@ -24,13 +24,7 @@ import { getCanonicalGasTokenAddress } from '@aztec/protocol-contracts/gas-token import { jest } from '@jest/globals'; -import { - type BalancesFn, - expectMapping, - getBalancesFn, - publicDeployAccounts, - setup, -} from './fixtures/utils.js'; +import { type BalancesFn, expectMapping, getBalancesFn, publicDeployAccounts, setup } from './fixtures/utils.js'; jest.setTimeout(100_000); @@ -71,12 +65,11 @@ describe('e2e_dapp_subscription', () => { let wallets: AccountWalletWithPrivateKey[]; let aztecNode: AztecNode; - let deployL1ContractsValues: DeployL1Contracts; + let deployL1ContractsValues: DeployL1Contracts; ({ wallets, aztecNode, deployL1ContractsValues, logger, pxe } = await setup(3)); await publicDeployAccounts(wallets[0], wallets); - await aztecNode.setConfig({ allowedFeePaymentContractClasses: [getContractClassFromArtifact(FPCContract.artifact).id], }); 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 edbcd538623..c8f5b922e9a 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,17 +1,17 @@ import { + type AccountWallet, + type AztecAddress, BatchCall, + type DebugLogger, ExtendedNote, Fr, + type GrumpkinPrivateKey, GrumpkinScalar, Note, + type PXE, + type PublicKey, computeMessageSecretHash, generatePublicKey, - type AccountWallet, - type AztecAddress, - type DebugLogger, - type GrumpkinPrivateKey, - type PXE, - type PublicKey } from '@aztec/aztec.js'; import { computePartialAddress } from '@aztec/circuits.js'; import { EscrowContract } from '@aztec/noir-contracts.js/Escrow'; @@ -26,7 +26,7 @@ describe('e2e_escrow_contract', () => { let pxe: PXE; let wallet: AccountWallet; let recipientWallet: AccountWallet; - + let logger: DebugLogger; let teardown: () => Promise; diff --git a/yarn-project/end-to-end/src/e2e_fees.test.ts b/yarn-project/end-to-end/src/e2e_fees.test.ts index 1307bb1e0da..99e63546a55 100644 --- a/yarn-project/end-to-end/src/e2e_fees.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees.test.ts @@ -1,23 +1,23 @@ import { + type AccountWallet, + type AztecAddress, BatchCall, + type DebugLogger, ExtendedNote, Fr, + type FunctionCall, FunctionSelector, Note, PrivateFeePaymentMethod, PublicFeePaymentMethod, + type TxHash, TxStatus, + type Wallet, computeAuthWitMessageHash, computeMessageSecretHash, - type AztecAddress, - type DebugLogger, - type FunctionCall, - type TxHash, - type Wallet, - type AccountWallet } from '@aztec/aztec.js'; import { FunctionData, getContractClassFromArtifact } from '@aztec/circuits.js'; -import { decodeFunctionSignature, type ContractArtifact } from '@aztec/foundation/abi'; +import { type ContractArtifact, decodeFunctionSignature } from '@aztec/foundation/abi'; import { TokenContract as BananaCoin, FPCContract, @@ -27,13 +27,7 @@ import { import { jest } from '@jest/globals'; -import { - expectMapping, - getBalancesFn, - publicDeployAccounts, - setup, - type BalancesFn -} from './fixtures/utils.js'; +import { type BalancesFn, expectMapping, getBalancesFn, publicDeployAccounts, setup } from './fixtures/utils.js'; import { GasPortalTestingHarnessFactory, type IGasBridgingTestHarness } from './shared/gas_portal_test_harness.js'; const TOKEN_NAME = 'BananaCoin'; @@ -60,10 +54,9 @@ describe('e2e_fees', () => { let bananaPrivateBalances: BalancesFn; beforeAll(async () => { - const { wallets: _wallets, aztecNode, deployL1ContractsValues, logger, pxe } = await setup(3); wallets = _wallets; - + await aztecNode.setConfig({ allowedFeePaymentContractClasses: [getContractClassFromArtifact(FPCContract.artifact).id], }); diff --git a/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts b/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts index 8c14bb9e9af..00da02fb2d9 100644 --- a/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_inclusion_proofs_contract.test.ts @@ -1,10 +1,10 @@ import { + type AccountWallet, AztecAddress, Fr, INITIAL_L2_BLOCK_NUM, + type PXE, getContractInstanceFromDeployParams, - type AccountWallet, - type PXE } from '@aztec/aztec.js'; import { deployInstance, registerContractClass } from '@aztec/aztec.js/deployment'; import { randomInt } from '@aztec/foundation/crypto'; @@ -12,7 +12,7 @@ import { StatefulTestContract, StatefulTestContractArtifact } from '@aztec/noir- import { InclusionProofsContract } from '@aztec/noir-contracts.js/InclusionProofs'; import { jest } from '@jest/globals'; -import { default as memdown, type MemDown } from 'memdown'; +import { type MemDown, default as memdown } from 'memdown'; import { setup } from './fixtures/utils.js'; @@ -26,7 +26,6 @@ describe('e2e_inclusion_proofs_contract', () => { let pxe: PXE; let teardown: () => Promise; let wallets: AccountWallet[]; - let contract: InclusionProofsContract; let deploymentBlockNumber: number; 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 4368a22d822..9f7f58c0525 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 @@ -1,12 +1,12 @@ import { + type AccountWallet, + type CheatCodes, + type DebugLogger, ExtendedNote, Fr, Note, computeAuthWitMessageHash, computeMessageSecretHash, - type AccountWallet, - type CheatCodes, - type DebugLogger } from '@aztec/aztec.js'; import { LendingContract, PriceFeedContract, TokenContract } from '@aztec/noir-contracts.js'; @@ -18,7 +18,7 @@ import { LendingAccount, LendingSimulator, TokenSimulator } from './simulators/i describe('e2e_lending_contract', () => { jest.setTimeout(100_000); let wallet: AccountWallet; - + let logger: DebugLogger; let teardown: () => Promise; diff --git a/yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts b/yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts index 743a5e0db8b..61ef05c0df2 100644 --- a/yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_pending_note_hashes_contract.test.ts @@ -1,10 +1,4 @@ -import { - Fr, - type AztecAddress, - type AztecNode, - type DebugLogger, - type Wallet -} from '@aztec/aztec.js'; +import { type AztecAddress, type AztecNode, type DebugLogger, Fr, type Wallet } from '@aztec/aztec.js'; import { PendingNoteHashesContract } from '@aztec/noir-contracts.js/PendingNoteHashes'; import { setup } from './fixtures/utils.js'; @@ -18,7 +12,6 @@ describe('e2e_pending_note_hashes_contract', () => { let contract: PendingNoteHashesContract; beforeEach(async () => { - ({ teardown, aztecNode, wallet, logger } = await setup(2)); owner = wallet.getAddress(); }, 100_000); diff --git a/yarn-project/end-to-end/src/e2e_private_voting_contract.test.ts b/yarn-project/end-to-end/src/e2e_private_voting_contract.test.ts index 85c3f3a6bbc..1a0a9710fac 100644 --- a/yarn-project/end-to-end/src/e2e_private_voting_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_private_voting_contract.test.ts @@ -1,11 +1,11 @@ -import { Fr, type AccountWallet, type AztecAddress, type DebugLogger } from '@aztec/aztec.js'; +import { type AccountWallet, type AztecAddress, type DebugLogger, Fr } from '@aztec/aztec.js'; import { EasyPrivateVotingContract } from '@aztec/noir-contracts.js/EasyPrivateVoting'; import { setup } from './fixtures/utils.js'; describe('e2e_voting_contract', () => { let wallet: AccountWallet; - + let logger: DebugLogger; let teardown: () => Promise; @@ -14,11 +14,7 @@ describe('e2e_voting_contract', () => { beforeAll(async () => { // Setup environment - ({ - teardown, - wallet, - logger, - } = await setup(1)); + ({ teardown, wallet, logger } = await setup(1)); owner = wallet.getAddress(); votingContract = await EasyPrivateVotingContract.deploy(wallet, owner).send().deployed(); 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 02574d0af63..1031824eaff 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 @@ -1,17 +1,17 @@ import { + type AccountWallet, + type AztecAddress, + type AztecNode, + type DebugLogger, + type DeployL1Contracts, EthAddress, Fr, L1Actor, L1ToL2Message, L2Actor, + type PXE, computeAuthWitMessageHash, computeMessageSecretHash, - type AccountWallet, - type AztecAddress, - type AztecNode, - type DebugLogger, - type DeployL1Contracts, - type PXE } from '@aztec/aztec.js'; import { sha256ToField } from '@aztec/foundation/crypto'; import { InboxAbi, OutboxAbi } from '@aztec/l1-artifacts'; diff --git a/yarn-project/end-to-end/src/e2e_token_contract.test.ts b/yarn-project/end-to-end/src/e2e_token_contract.test.ts index e17cfc12179..a79c47703fb 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract.test.ts @@ -1,13 +1,13 @@ import { + type AccountWallet, + type DebugLogger, ExtendedNote, Fr, FunctionSelector, Note, + type TxHash, computeAuthWitMessageHash, computeMessageSecretHash, - type AccountWallet, - type DebugLogger, - type TxHash } from '@aztec/aztec.js'; import { decodeFunctionSignature } from '@aztec/foundation/abi'; import { DocsExampleContract, ReaderContract, TokenContract } from '@aztec/noir-contracts.js'; @@ -28,7 +28,7 @@ describe('e2e_token_contract', () => { const TOKEN_DECIMALS = 18n; let teardown: () => Promise; let wallets: AccountWallet[]; - + let logger: DebugLogger; let asset: TokenContract; @@ -1011,7 +1011,10 @@ describe('e2e_token_contract', () => { tokenSim.burnPublic(wallets[0].getAddress(), amount); // Check that the message hash is no longer valid. Need to try to send since nullifiers are handled by sequencer. - const txReplay = asset.withWallet(wallets[1]).methods.burn_public(wallets[0].getAddress(), amount, nonce).send(); + const txReplay = asset + .withWallet(wallets[1]) + .methods.burn_public(wallets[0].getAddress(), amount, nonce) + .send(); await expect(txReplay.wait()).rejects.toThrow('Transaction '); }); diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index f33b7d00d36..c9db9da05b2 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -1,13 +1,23 @@ import { SchnorrAccountContractArtifact } from '@aztec/accounts/schnorr'; import { createAccounts, getDeployedTestAccountsWallets } from '@aztec/accounts/testing'; -import { AztecNodeService, getConfigEnvVars, type AztecNodeConfig } from '@aztec/aztec-node'; +import { type AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node'; import { + type AccountWalletWithPrivateKey, + type AztecAddress, + type AztecNode, BatchCall, CheatCodes, + type ContractMethod, + type DebugLogger, + type DeployL1Contracts, EncryptedL2BlockL2Logs, EthCheatCodes, + type L1ContractArtifactsForDeployment, LogType, + type PXE, + type SentTx, SignerlessWallet, + type Wallet, createAztecNodeClient, createDebugLogger, createPXEClient, @@ -15,16 +25,6 @@ import { fileURLToPath, makeFetch, waitForPXE, - type AccountWalletWithPrivateKey, - type AztecAddress, - type AztecNode, - type ContractMethod, - type DebugLogger, - type DeployL1Contracts, - type L1ContractArtifactsForDeployment, - type PXE, - type SentTx, - type Wallet } from '@aztec/aztec.js'; import { deployInstance, registerContractClass } from '@aztec/aztec.js/deployment'; import { DefaultMultiCallEntrypoint } from '@aztec/entrypoints/multi-call'; @@ -46,21 +46,21 @@ import { RollupBytecode, } from '@aztec/l1-artifacts'; import { getCanonicalGasToken, getCanonicalGasTokenAddress } from '@aztec/protocol-contracts/gas-token'; -import { PXEService, createPXEService, getPXEServiceConfig, type PXEServiceConfig } from '@aztec/pxe'; +import { PXEService, type PXEServiceConfig, createPXEService, getPXEServiceConfig } from '@aztec/pxe'; import { type SequencerClient } from '@aztec/sequencer-client'; import * as fs from 'fs/promises'; import * as path from 'path'; import { - createPublicClient, - createWalletClient, - getContract, - http, type Account, type Chain, type HDAccount, type HttpTransport, type PrivateKeyAccount, + createPublicClient, + createWalletClient, + getContract, + http, } from 'viem'; import { mnemonicToAccount } from 'viem/accounts'; import { foundry } from 'viem/chains'; diff --git a/yarn-project/pxe/src/contract_data_oracle/index.ts b/yarn-project/pxe/src/contract_data_oracle/index.ts index 6fa2d1c86f4..eaf53cb9be6 100644 --- a/yarn-project/pxe/src/contract_data_oracle/index.ts +++ b/yarn-project/pxe/src/contract_data_oracle/index.ts @@ -34,7 +34,6 @@ export class ContractDataOracle { if (!this.contractInstances.has(contractAddress.toString())) { const instance = await this.db.getContractInstance(contractAddress); if (!instance) { - // tady 4 throw new ContractNotFoundError(contractAddress.toString()); } this.contractInstances.set(contractAddress.toString(), instance); @@ -77,7 +76,6 @@ export class ContractDataOracle { * @returns The corresponding function's artifact as an object. */ public async getFunctionArtifact(contractAddress: AztecAddress, selector: FunctionSelector) { - // tady 2 const tree = await this.getTreeForAddress(contractAddress); return tree.getFunctionArtifact(selector); } @@ -194,7 +192,6 @@ export class ContractDataOracle { * @throws An Error if the contract is not found in the ContractDatabase. */ private async getTreeForAddress(contractAddress: AztecAddress): Promise { - // tady 3 const instance = await this.getContractInstance(contractAddress); return this.getTreeForClassId(instance.contractClassId); } diff --git a/yarn-project/pxe/src/database/kv_pxe_database.ts b/yarn-project/pxe/src/database/kv_pxe_database.ts index cb491efb430..aadab576f8d 100644 --- a/yarn-project/pxe/src/database/kv_pxe_database.ts +++ b/yarn-project/pxe/src/database/kv_pxe_database.ts @@ -106,7 +106,6 @@ export class KVPxeDatabase implements PxeDatabase { } getContractInstance(address: AztecAddress): Promise { - // tady se to pta na data const contract = this.#contractInstances.get(address.toString()); return Promise.resolve(contract && SerializableContractInstance.fromBuffer(contract).withAddress(address)); } diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index ac07f460c15..92079b73330 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -247,7 +247,6 @@ export class PXEService implements PXE { } } - // here I don't see the contract being added this.log.info(`Added contract ${artifact.name} at ${instance.address.toString()}`); await this.db.addContractInstance(instance); await this.synchronizer.reprocessDeferredNotesForContract(instance.address); diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index def175e2a46..56e65ee0e81 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -101,12 +101,6 @@ export class SimulatorOracle implements DBOracle { contractAddress: AztecAddress, selector: FunctionSelector, ): Promise { - // tady 1 - { - // TODO(#5555): this log out is here to verify a hypothesis that the e2e_account test flakiness is caused by slow sync - const nodeSyncedUpToBlock = await this.aztecNode.getBlockNumber(); - this.log(`Node synced up to block ${nodeSyncedUpToBlock}`); - } const artifact = await this.contractDataOracle.getFunctionArtifact(contractAddress, selector); const debug = await this.contractDataOracle.getFunctionDebugMetadata(contractAddress, selector); return { diff --git a/yarn-project/simulator/src/client/client_execution_context.ts b/yarn-project/simulator/src/client/client_execution_context.ts index f95f6bdabd9..3f626293121 100644 --- a/yarn-project/simulator/src/client/client_execution_context.ts +++ b/yarn-project/simulator/src/client/client_execution_context.ts @@ -355,7 +355,6 @@ export class ClientExecutionContext extends ViewDataOracle { isStaticCall = isStaticCall || this.callContext.isStaticCall; - // tady 0 const targetArtifact = await this.db.getFunctionArtifact(targetContractAddress, functionSelector); const targetFunctionData = FunctionData.fromAbi(targetArtifact);