diff --git a/.circleci/config.yml b/.circleci/config.yml index b049069c8c0..99bde18cac1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -769,7 +769,7 @@ jobs: name: "Test" command: cond_spot_run_compose end-to-end 4 ./scripts/docker-compose-no-sandbox.yml TEST=e2e_p2p_network.test.ts - e2e-browser-sandbox: + e2e-browser: docker: - image: aztecprotocol/alpine-build-image resource_class: small @@ -791,7 +791,7 @@ jobs: name: "Test" command: cond_spot_run_compose end-to-end 4 ./scripts/docker-compose.yml TEST=e2e_card_game.test.ts - pxe-sandbox: + pxe: docker: - image: aztecprotocol/alpine-build-image resource_class: small @@ -1206,9 +1206,9 @@ workflows: - integration-l1-publisher: *e2e_test - integration-archiver-l1-to-l2: *e2e_test - e2e-p2p: *e2e_test - - e2e-browser-sandbox: *e2e_test + - e2e-browser: *e2e_test - e2e-card-game: *e2e_test - - pxe-sandbox: *e2e_test + - pxe: *e2e_test - cli-docs-sandbox: *e2e_test - guides-writing-an-account-contract: *e2e_test - guides-dapp-testing: *e2e_test @@ -1242,9 +1242,9 @@ workflows: - integration-l1-publisher - integration-archiver-l1-to-l2 - e2e-p2p - - e2e-browser-sandbox + - e2e-browser - e2e-card-game - - pxe-sandbox + - pxe - cli-docs-sandbox - guides-writing-an-account-contract - guides-dapp-testing diff --git a/boxes/blank-react/src/environment/index.ts b/boxes/blank-react/src/environment/index.ts new file mode 100644 index 00000000000..c64d7f6a2a3 --- /dev/null +++ b/boxes/blank-react/src/environment/index.ts @@ -0,0 +1,11 @@ +import { createPXEClient, waitForPXE } from '@aztec/aztec.js'; + +const { PXE_URL = 'http://localhost:8080' } = process.env; + +// assumes environment is running locally, which this script does not trigger +// as well as anvil. anvil can be started with yarn test:integration +export const setupEnvironment = async () => { + const pxe = createPXEClient(PXE_URL); + await waitForPXE(pxe); + return pxe; + }; \ No newline at end of file diff --git a/boxes/blank-react/src/scripts/util.ts b/boxes/blank-react/src/scripts/util.ts index 6aea0121265..3f9d05bfdcb 100644 --- a/boxes/blank-react/src/scripts/util.ts +++ b/boxes/blank-react/src/scripts/util.ts @@ -1,6 +1,6 @@ import { AccountWallet, CompleteAddress, Fr, FunctionArtifact, PXE, encodeArguments } from '@aztec/aztec.js'; -import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; +import { getInitialTestAccountsWallets } from '@aztec/accounts/testing'; export function convertArgs(functionAbi: FunctionArtifact, args: any): Fr[] { const untypedArgs = functionAbi.parameters.map(param => { @@ -27,7 +27,7 @@ export function convertArgs(functionAbi: FunctionArtifact, args: any): Fr[] { * @returns */ export async function getWallet(account: CompleteAddress, pxe: PXE): Promise { - const accountWallets: AccountWallet[] = await getSandboxAccountsWallets(pxe); + const accountWallets: AccountWallet[] = await getInitialTestAccountsWallets(pxe); const selectedWallet: AccountWallet = accountWallets.find(w => w.getAddress().equals(account.address))!; if (!selectedWallet) { throw new Error(`Wallet for account ${account.address.toShortString()} not found in the PXE.`); diff --git a/boxes/blank-react/src/tests/blank.contract.test.ts b/boxes/blank-react/src/tests/blank.contract.test.ts index 62fc7b7d1da..8adba3984e5 100644 --- a/boxes/blank-react/src/tests/blank.contract.test.ts +++ b/boxes/blank-react/src/tests/blank.contract.test.ts @@ -10,21 +10,11 @@ import { TxStatus, Wallet, createDebugLogger, - createPXEClient, - waitForSandbox, } from '@aztec/aztec.js'; +import { setupEnvironment } from '../environment/index.js'; const logger = createDebugLogger('aztec:http-pxe-client'); -// assumes sandbox is running locally, which this script does not trigger -// as well as anvil. anvil can be started with yarn test:integration -const setupSandbox = async () => { - const { PXE_URL = 'http://localhost:8080' } = process.env; - const pxe = createPXEClient(PXE_URL); - await waitForSandbox(pxe); - - return pxe; -}; async function deployZKContract(owner: CompleteAddress, wallet: Wallet, pxe: PXE) { logger('Deploying Blank contract...'); @@ -44,7 +34,7 @@ describe('ZK Contract Tests', () => { let pxe: PXE; beforeAll(async () => { - pxe = await setupSandbox(); + pxe = await setupEnvironment(); const accounts = await pxe.getRegisteredAccounts(); [owner, _account2, _account3] = accounts; diff --git a/boxes/blank/src/environment/index.ts b/boxes/blank/src/environment/index.ts new file mode 100644 index 00000000000..c64d7f6a2a3 --- /dev/null +++ b/boxes/blank/src/environment/index.ts @@ -0,0 +1,11 @@ +import { createPXEClient, waitForPXE } from '@aztec/aztec.js'; + +const { PXE_URL = 'http://localhost:8080' } = process.env; + +// assumes environment is running locally, which this script does not trigger +// as well as anvil. anvil can be started with yarn test:integration +export const setupEnvironment = async () => { + const pxe = createPXEClient(PXE_URL); + await waitForPXE(pxe); + return pxe; + }; \ No newline at end of file diff --git a/boxes/blank/src/index.ts b/boxes/blank/src/index.ts index e511f2d301b..6b7cafeac9f 100644 --- a/boxes/blank/src/index.ts +++ b/boxes/blank/src/index.ts @@ -16,7 +16,7 @@ import { encodeArguments, } from '@aztec/aztec.js'; -import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; +import { getInitialTestAccountsWallets } from '@aztec/accounts/testing'; // docs:end:imports @@ -45,7 +45,7 @@ if (typeof document !== 'undefined') { export async function handleDeployClick(): Promise { // eslint-disable-next-line no-console console.log('Deploying Contract'); - const [wallet, ..._rest] = await getSandboxAccountsWallets(pxe); + const [wallet, ..._rest] = await getInitialTestAccountsWallets(pxe); const contractAztecAddress = await deployContract( wallet.getCompleteAddress(), @@ -60,7 +60,7 @@ export async function handleDeployClick(): Promise { // docs:end:deploy // docs:start:interact export async function handleInteractClick(contractAddress: string) { - const [wallet, ..._rest] = await getSandboxAccountsWallets(pxe); + const [wallet, ..._rest] = await getInitialTestAccountsWallets(pxe); const callArgs = { address: wallet.getCompleteAddress().address }; const getPkAbi = getFunctionAbi(BlankContractArtifact, 'getPublicKey'); const typedArgs = convertArgs(getPkAbi, callArgs); @@ -115,7 +115,7 @@ export async function callContractFunction( * @returns */ export async function getWallet(account: CompleteAddress, pxe: PXE): Promise { - const accountWallets: AccountWallet[] = await getSandboxAccountsWallets(pxe); + const accountWallets: AccountWallet[] = await getInitialTestAccountsWallets(pxe); const selectedWallet: AccountWallet = accountWallets.find(w => w.getAddress().equals(account.address))!; if (!selectedWallet) { throw new Error(`Wallet for account ${account.address.toShortString()} not found in the PXE.`); diff --git a/boxes/blank/src/tests/blank.contract.test.ts b/boxes/blank/src/tests/blank.contract.test.ts index 6fb153315f0..c4e2cb5cdba 100644 --- a/boxes/blank/src/tests/blank.contract.test.ts +++ b/boxes/blank/src/tests/blank.contract.test.ts @@ -10,21 +10,11 @@ import { TxStatus, Wallet, createDebugLogger, - createPXEClient, - waitForSandbox, } from '@aztec/aztec.js'; +import { setupEnvironment } from '../environment/index.js'; const logger = createDebugLogger('aztec:blank-box-test'); -// assumes sandbox is running locally, which this script does not trigger -// as well as anvil. anvil can be started with yarn test:integration -const setupSandbox = async () => { - const { PXE_URL = 'http://localhost:8080' } = process.env; - const pxe = createPXEClient(PXE_URL); - await waitForSandbox(pxe); - return pxe; -}; - async function deployZKContract(owner: CompleteAddress, wallet: Wallet, pxe: PXE) { logger('Deploying Blank contract...'); const contractAddress = await deployContract(owner, BlankContract.artifact, [], Fr.random(), pxe); @@ -43,7 +33,7 @@ describe('ZK Contract Tests', () => { let pxe: PXE; beforeAll(async () => { - pxe = await setupSandbox(); + pxe = await setupEnvironment(); const accounts = await pxe.getRegisteredAccounts(); [owner, _account2, _account3] = accounts; diff --git a/boxes/token/src/environment/index.ts b/boxes/token/src/environment/index.ts new file mode 100644 index 00000000000..c64d7f6a2a3 --- /dev/null +++ b/boxes/token/src/environment/index.ts @@ -0,0 +1,11 @@ +import { createPXEClient, waitForPXE } from '@aztec/aztec.js'; + +const { PXE_URL = 'http://localhost:8080' } = process.env; + +// assumes environment is running locally, which this script does not trigger +// as well as anvil. anvil can be started with yarn test:integration +export const setupEnvironment = async () => { + const pxe = createPXEClient(PXE_URL); + await waitForPXE(pxe); + return pxe; + }; \ No newline at end of file diff --git a/boxes/token/src/scripts/util.ts b/boxes/token/src/scripts/util.ts index 46f82d79ca6..b35cdcdc227 100644 --- a/boxes/token/src/scripts/util.ts +++ b/boxes/token/src/scripts/util.ts @@ -1,6 +1,6 @@ import { AccountWallet, CompleteAddress, Fr, FunctionArtifact, PXE, encodeArguments } from '@aztec/aztec.js'; -import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; +import { getInitialTestAccountsWallets } from '@aztec/accounts/testing'; function convertBasicArg(paramType: string, value: any) { switch (paramType) { @@ -42,7 +42,7 @@ export function convertArgs(functionAbi: FunctionArtifact, args: any): Fr[] { * @returns */ export async function getWallet(account: CompleteAddress, pxe: PXE): Promise { - const accountWallets: AccountWallet[] = await getSandboxAccountsWallets(pxe); + const accountWallets: AccountWallet[] = await getInitialTestAccountsWallets(pxe); const selectedWallet: AccountWallet = accountWallets.find(w => w.getAddress().equals(account.address))!; if (!selectedWallet) { throw new Error(`Wallet for account ${account.address.toShortString()} not found in the PXE.`); diff --git a/boxes/token/src/tests/token.contract.test.ts b/boxes/token/src/tests/token.contract.test.ts index f8a86b508aa..5fbcfcd4179 100644 --- a/boxes/token/src/tests/token.contract.test.ts +++ b/boxes/token/src/tests/token.contract.test.ts @@ -13,22 +13,12 @@ import { computeAuthWitMessageHash, computeMessageSecretHash, createDebugLogger, - createPXEClient, - waitForSandbox, } from '@aztec/aztec.js'; -import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; +import { getInitialTestAccountsWallets } from '@aztec/accounts/testing'; import { afterEach, beforeAll, expect, jest } from '@jest/globals'; - -// assumes sandbox is running locally, which this script does not trigger -// as well as anvil. anvil can be started with yarn test:integration -const setupSandbox = async () => { - const { PXE_URL = 'http://localhost:8080' } = process.env; - const pxe = createPXEClient(PXE_URL); - await waitForSandbox(pxe); - return pxe; -}; +import { setupEnvironment } from '../environment/index.js'; const TIMEOUT = 60_000; @@ -53,10 +43,10 @@ describe('e2e_token_contract', () => { beforeAll(async () => { logger = createDebugLogger('box:token_contract_test'); - pxe = await setupSandbox(); + pxe = await setupEnvironment(); // wallets = await createAccounts(pxe, 3); accounts = await pxe.getRegisteredAccounts(); - wallets = await getSandboxAccountsWallets(pxe); + wallets = await getInitialTestAccountsWallets(pxe); logger(`Accounts: ${accounts.map(a => a.toReadableString())}`); logger(`Wallets: ${wallets.map(w => w.getAddress().toString())}`); diff --git a/docs/docs/dev_docs/cli/blank_box.md b/docs/docs/dev_docs/cli/blank_box.md index 2f1b586d832..94ceb1d7eca 100644 --- a/docs/docs/dev_docs/cli/blank_box.md +++ b/docs/docs/dev_docs/cli/blank_box.md @@ -104,7 +104,7 @@ The Sandbox runs on `localhost:8080` by default. With the `SANDBOX_URL`, we set #include_code deploy boxes/blank/src/index.ts typescript -To deploy, it gets one of the pre-initialized wallets that comes with the Sandbox with `getSandboxAccountsWallets`. Using that wallet, the contract ABI, optional salt (used to deterministically calculate the contract address, like [CREATE2 in Ethereum](https://docs.openzeppelin.com/cli/2.8/deploying-with-create2)), and the PXE, we can create a contract deployment transaction and send it to the sandbox network. The constructor defined in the Blank contract doesn't take any arguments, so we pass an empty array. +To deploy, it gets one of the pre-initialized wallets that comes with the Sandbox with `getInitialTestAccountsWallets`. Using that wallet, the contract ABI, optional salt (used to deterministically calculate the contract address, like [CREATE2 in Ethereum](https://docs.openzeppelin.com/cli/2.8/deploying-with-create2)), and the PXE, we can create a contract deployment transaction and send it to the sandbox network. The constructor defined in the Blank contract doesn't take any arguments, so we pass an empty array. With the web interface running, open your browser dev tools console, click the "Deploy" button and see the successfully deployed contract address. In the terminal or Docker logs where your sandbox is running, you will see transaction and block production info printed. diff --git a/docs/docs/dev_docs/tutorials/token_portal/typescript_glue_code.md b/docs/docs/dev_docs/tutorials/token_portal/typescript_glue_code.md index c3ed984126a..003f680acc9 100644 --- a/docs/docs/dev_docs/tutorials/token_portal/typescript_glue_code.md +++ b/docs/docs/dev_docs/tutorials/token_portal/typescript_glue_code.md @@ -87,8 +87,8 @@ Open `cross_chain_messaging.test.ts` and paste the initial description of the te ```typescript import { expect, jest} from '@jest/globals' -import { AccountWallet, AztecAddress, DebugLogger, EthAddress, Fr, computeAuthWitMessageHash, createDebugLogger, createPXEClient, waitForSandbox } from '@aztec/aztec.js'; -import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; +import { AccountWallet, AztecAddress, DebugLogger, EthAddress, Fr, computeAuthWitMessageHash, createDebugLogger, createPXEClient, waitForPXE } from '@aztec/aztec.js'; +import { getInitialTestAccountsWallets } from '@aztec/accounts/testing'; import { TokenContract } from '@aztec/noir-contracts/Token'; import { TokenBridgeContract } from '@aztec/noir-contracts/TokenBridge'; @@ -120,8 +120,8 @@ describe('e2e_cross_chain_messaging', () => { beforeEach(async () => { logger = createDebugLogger('aztec:e2e_uniswap'); const pxe = createPXEClient(PXE_URL); - await waitForSandbox(pxe); - const wallets = await getSandboxAccountsWallets(pxe); + await waitForPXE(pxe); + const wallets = await getInitialTestAccountsWallets(pxe); const walletClient = createWalletClient({ account: hdAccount, diff --git a/docs/docs/dev_docs/tutorials/uniswap/typescript_glue_code.md b/docs/docs/dev_docs/tutorials/uniswap/typescript_glue_code.md index 67b46b1b952..e4004c9b02d 100644 --- a/docs/docs/dev_docs/tutorials/uniswap/typescript_glue_code.md +++ b/docs/docs/dev_docs/tutorials/uniswap/typescript_glue_code.md @@ -86,9 +86,9 @@ import { computeAuthWitMessageHash, createDebugLogger, createPXEClient, - waitForSandbox, + waitForPXE, } from "@aztec/aztec.js"; -import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; +import { getInitialTestAccountsWallets } from '@aztec/accounts/testing'; import { Chain, HttpTransport, diff --git a/docs/docs/dev_docs/tutorials/writing_dapp/contract_deployment.md b/docs/docs/dev_docs/tutorials/writing_dapp/contract_deployment.md index 94ebf5ad032..18345d70135 100644 --- a/docs/docs/dev_docs/tutorials/writing_dapp/contract_deployment.md +++ b/docs/docs/dev_docs/tutorials/writing_dapp/contract_deployment.md @@ -60,9 +60,9 @@ Create a new file `src/deploy.mjs`: ```js // src/deploy.mjs import { writeFileSync } from 'fs'; -import { Contract, ContractDeployer, createPXEClient, getSandboxAccountsWallets } from '@aztec/aztec.js'; -import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; -import TokenContractArtifact from "../contracts/token/src/artifacts/Token.json" assert { type: "json" }; +import { Contract, ContractDeployer, createPXEClient } from '@aztec/aztec.js'; +import { getInitialTestAccountsWallets } from '@aztec/accounts/testing'; +import TokenContractArtifact from "../contracts/token/target/Token.json" assert { type: "json" }; #include_code dapp-deploy yarn-project/end-to-end/src/sample-dapp/deploy.mjs raw diff --git a/docs/docs/dev_docs/tutorials/writing_dapp/contract_interaction.md b/docs/docs/dev_docs/tutorials/writing_dapp/contract_interaction.md index 05510f43778..0e520cbf687 100644 --- a/docs/docs/dev_docs/tutorials/writing_dapp/contract_interaction.md +++ b/docs/docs/dev_docs/tutorials/writing_dapp/contract_interaction.md @@ -56,10 +56,10 @@ const wallet = await getSchnorrAccount( ).getWallet(); ``` -For ease of use, `accounts` also ships with a helper `getSandboxAccountsWallets` method that returns a wallet for each of the pre-initialized accounts in the Sandbox, so you can send transactions as any of them. +For ease of use, `accounts` also ships with a helper `getInitialTestAccountsWallets` method that returns a wallet for each of the pre-initialized accounts in the Sandbox, so you can send transactions as any of them. ```js -import { getSandboxAccountsWallets } from "@aztec/accounts/testing"; +import { getInitialTestAccountsWallets } from '@aztec/accounts/testing'; ``` We'll use one of these wallets to initialize the `Contract` instance that represents our private token contract, so every transaction sent through it will be sent through that wallet. diff --git a/docs/docs/dev_docs/tutorials/writing_dapp/testing.md b/docs/docs/dev_docs/tutorials/writing_dapp/testing.md index 4fce0d11b1d..17f144dd6ac 100644 --- a/docs/docs/dev_docs/tutorials/writing_dapp/testing.md +++ b/docs/docs/dev_docs/tutorials/writing_dapp/testing.md @@ -29,7 +29,7 @@ import { computeMessageSecretHash, createAccount, createPXEClient, - waitForSandbox, + waitForPXE, } from "@aztec/aztec.js"; import { TokenContractArtifact } from "@aztec/noir-contracts/Token"; diff --git a/yarn-project/accounts/src/testing/sandbox.ts b/yarn-project/accounts/src/testing/configuration.ts similarity index 50% rename from yarn-project/accounts/src/testing/sandbox.ts rename to yarn-project/accounts/src/testing/configuration.ts index 9c85f383b0d..7688913d1d9 100644 --- a/yarn-project/accounts/src/testing/sandbox.ts +++ b/yarn-project/accounts/src/testing/configuration.ts @@ -1,40 +1,58 @@ +import { generatePublicKey } from '@aztec/aztec.js'; import { AccountWalletWithPrivateKey } from '@aztec/aztec.js/wallet'; import { Fr, GrumpkinScalar } from '@aztec/foundation/fields'; import { PXE } from '@aztec/types'; import { getSchnorrAccount } from '../schnorr/index.js'; -export const INITIAL_SANDBOX_ENCRYPTION_KEYS = [ +export const INITIAL_TEST_ENCRYPTION_KEYS = [ GrumpkinScalar.fromString('2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281'), GrumpkinScalar.fromString('aebd1b4be76efa44f5ee655c20bf9ea60f7ae44b9a7fd1fd9f189c7a0b0cdae'), GrumpkinScalar.fromString('0f6addf0da06c33293df974a565b03d1ab096090d907d98055a8b7f4954e120c'), ]; -export const INITIAL_SANDBOX_SIGNING_KEYS = INITIAL_SANDBOX_ENCRYPTION_KEYS; +export const INITIAL_TEST_SIGNING_KEYS = INITIAL_TEST_ENCRYPTION_KEYS; -export const INITIAL_SANDBOX_SALTS = [Fr.ZERO, Fr.ZERO, Fr.ZERO]; +export const INITIAL_TEST_ACCOUNT_SALTS = [Fr.ZERO, Fr.ZERO, Fr.ZERO]; /** - * Gets a collection of wallets for the Aztec accounts that are initially stored in the sandbox. + * Gets a collection of wallets for the Aztec accounts that are initially stored in the test environment. * @param pxe - PXE instance. * @returns A set of AccountWallet implementations for each of the initial accounts. */ -export function getSandboxAccountsWallets(pxe: PXE): Promise { +export function getInitialTestAccountsWallets(pxe: PXE): Promise { return Promise.all( - INITIAL_SANDBOX_ENCRYPTION_KEYS.map((encryptionKey, i) => - getSchnorrAccount(pxe, encryptionKey!, INITIAL_SANDBOX_SIGNING_KEYS[i]!, INITIAL_SANDBOX_SALTS[i]).getWallet(), + INITIAL_TEST_ENCRYPTION_KEYS.map((encryptionKey, i) => + getSchnorrAccount(pxe, encryptionKey!, INITIAL_TEST_SIGNING_KEYS[i]!, INITIAL_TEST_ACCOUNT_SALTS[i]).getWallet(), ), ); } /** - * Deploys the initial set of schnorr signature accounts to the sandbox + * Queries a PXE for it's registered accounts and returns wallets for those accounts using keys in the initial test accounts. + * @param pxe - PXE instance. + * @returns A set of AccountWallet implementations for each of the initial accounts. + */ +export async function getDeployedTestAccountsWallets(pxe: PXE): Promise { + const registeredAccounts = await pxe.getRegisteredAccounts(); + return Promise.all( + INITIAL_TEST_ENCRYPTION_KEYS.filter(initialKey => { + const publicKey = generatePublicKey(initialKey); + return registeredAccounts.find(registered => registered.publicKey.equals(publicKey)) != undefined; + }).map((encryptionKey, i) => + getSchnorrAccount(pxe, encryptionKey!, INITIAL_TEST_SIGNING_KEYS[i]!, INITIAL_TEST_ACCOUNT_SALTS[i]).getWallet(), + ), + ); +} + +/** + * Deploys the initial set of schnorr signature accounts to the test environment * @param pxe - PXE instance. * @returns The set of deployed Account objects and associated private encryption keys */ -export async function deployInitialSandboxAccounts(pxe: PXE) { - const accounts = INITIAL_SANDBOX_ENCRYPTION_KEYS.map((privateKey, i) => { - const account = getSchnorrAccount(pxe, privateKey, INITIAL_SANDBOX_SIGNING_KEYS[i], INITIAL_SANDBOX_SALTS[i]); +export async function deployInitialTestAccounts(pxe: PXE) { + const accounts = INITIAL_TEST_ENCRYPTION_KEYS.map((privateKey, i) => { + const account = getSchnorrAccount(pxe, privateKey, INITIAL_TEST_SIGNING_KEYS[i], INITIAL_TEST_ACCOUNT_SALTS[i]); return { account, privateKey, diff --git a/yarn-project/accounts/src/testing/index.ts b/yarn-project/accounts/src/testing/index.ts index ba2cc4ae94d..b4084c48c25 100644 --- a/yarn-project/accounts/src/testing/index.ts +++ b/yarn-project/accounts/src/testing/index.ts @@ -2,10 +2,10 @@ * The `@aztec/accounts/testing` export provides utility methods for testing, in particular in a Sandbox environment. * * Use the {@link createAccount} and {@link createAccounts} methods to create new sample accounts for testing, - * or use {@link getSandboxAccountsWallets} to obtain a list of wallets for the sandbox pre-seeded accounts. + * or use {@link getInitialTestAccountsWallets} to obtain a list of wallets for the Sandbox pre-seeded accounts. * * @packageDocumentation */ export * from './create_account.js'; -export * from './sandbox.js'; +export * from './configuration.js'; diff --git a/yarn-project/aztec-sandbox/src/bin/index.ts b/yarn-project/aztec-sandbox/src/bin/index.ts index cc9ad7c9387..75b8d311347 100644 --- a/yarn-project/aztec-sandbox/src/bin/index.ts +++ b/yarn-project/aztec-sandbox/src/bin/index.ts @@ -1,10 +1,10 @@ #!/usr/bin/env -S node --no-warnings -import { deployInitialSandboxAccounts } from '@aztec/accounts/testing'; +import { deployInitialTestAccounts } from '@aztec/accounts/testing'; import { createAztecNodeRpcServer, getConfigEnvVars as getNodeConfigEnvVars } from '@aztec/aztec-node'; import { AccountManager, createAztecNodeClient } from '@aztec/aztec.js'; import { NULL_KEY } from '@aztec/ethereum'; import { init } from '@aztec/foundation/crypto'; -import { createStatusRouter } from '@aztec/foundation/json-rpc/server'; +import { createStatusRouter, startHttpRpcServer } from '@aztec/foundation/json-rpc/server'; import { createDebugLogger } from '@aztec/foundation/log'; import { fileURLToPath } from '@aztec/foundation/url'; import { NoirCommit, NoirTag } from '@aztec/noir-compiler/versions'; @@ -19,7 +19,6 @@ import { mnemonicToAccount } from 'viem/accounts'; import { setupFileDebugLog } from '../logging.js'; import { MNEMONIC, createAztecNode, createAztecPXE, createSandbox, deployContractsToL1 } from '../sandbox.js'; -import { startHttpRpcServer } from '../server.js'; import { github, splash } from '../splash.js'; /** @@ -72,7 +71,7 @@ async function createAndInitialiseSandbox(deployTestAccounts: boolean) { let accounts; if (deployTestAccounts) { logger.info('Setting up test accounts...'); - accounts = await deployInitialSandboxAccounts(pxe); + accounts = await deployInitialTestAccounts(pxe); } return { aztecNodeConfig, @@ -186,7 +185,7 @@ async function main() { if (deployTestAccounts) { logger.info('Setting up test accounts...'); - const accounts = await deployInitialSandboxAccounts(pxe); + const accounts = await deployInitialTestAccounts(pxe); const accountLogStrings = await createAccountLogs(accounts, pxe); logStrings.push(...accountLogStrings); } diff --git a/yarn-project/aztec-sandbox/src/index.ts b/yarn-project/aztec-sandbox/src/index.ts index a9a6669f682..84b8ae51dc5 100644 --- a/yarn-project/aztec-sandbox/src/index.ts +++ b/yarn-project/aztec-sandbox/src/index.ts @@ -1,2 +1 @@ export { createSandbox } from './sandbox.js'; -export { startHttpRpcServer } from './server.js'; diff --git a/yarn-project/aztec-sandbox/src/server.ts b/yarn-project/aztec-sandbox/src/server.ts deleted file mode 100644 index f8cc66f2198..00000000000 --- a/yarn-project/aztec-sandbox/src/server.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { JsonRpcServer } from '@aztec/foundation/json-rpc/server'; - -import http from 'http'; - -/** - * Creates an http server that forwards calls to the underlying instance and starts it on the given port. - * @param instance - Instance to wrap in a JSON-RPC server. - * @param jsonRpcFactoryFunc - Function that wraps the instance in a JSON-RPC server. - * @param port - Port to listen in. - * @returns A running http server. - */ -export function startHttpRpcServer( - instance: T, - jsonRpcFactoryFunc: (instance: T) => JsonRpcServer, - port: string | number, -): http.Server { - const rpcServer = jsonRpcFactoryFunc(instance); - - const app = rpcServer.getApp(); - - const httpServer = http.createServer(app.callback()); - httpServer.listen(port); - - return httpServer; -} diff --git a/yarn-project/aztec.js/src/contract/contract.test.ts b/yarn-project/aztec.js/src/contract/contract.test.ts index 41e3cc5b9b1..55b0242145a 100644 --- a/yarn-project/aztec.js/src/contract/contract.test.ts +++ b/yarn-project/aztec.js/src/contract/contract.test.ts @@ -28,7 +28,7 @@ describe('Contract Class', () => { decoderHelperAddress: EthAddress.random(), }; const mockNodeInfo: NodeInfo = { - sandboxVersion: 'vx.x.x', + nodeVersion: 'vx.x.x', compatibleNargoVersion: 'vx.x.x-aztec.x', chainId: 1, protocolVersion: 2, diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index 1f0c9dcac73..b851c8821a3 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -44,6 +44,7 @@ export { isContractDeployed, EthCheatCodes, computeAuthWitMessageHash, + waitForPXE, } from './utils/index.js'; export { createPXEClient } from './pxe_client.js'; @@ -53,8 +54,6 @@ export { AuthWitnessProvider } from './account/index.js'; export { AccountContract } from './account/index.js'; export { AccountManager } from './account_manager/index.js'; -export { waitForSandbox } from './sandbox/index.js'; - export { AccountWalletWithPrivateKey, AccountWallet, Wallet, SignerlessWallet } from './wallet/index.js'; // // TODO https://github.com/AztecProtocol/aztec-packages/issues/2632 --> FunctionSelector might not need to be exposed diff --git a/yarn-project/aztec.js/src/sandbox/index.ts b/yarn-project/aztec.js/src/sandbox/index.ts deleted file mode 100644 index bf60e94a5d7..00000000000 --- a/yarn-project/aztec.js/src/sandbox/index.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { sleep } from '@aztec/foundation/sleep'; -import { PXE } from '@aztec/types'; - -import { createPXEClient } from '../pxe_client.js'; - -export const { PXE_URL = 'http://localhost:8080' } = process.env; - -/** - * Function to wait until the sandbox becomes ready for use. - * @param pxe - The pxe client connected to the sandbox. - */ -export async function waitForSandbox(pxe?: PXE) { - pxe = pxe ?? createPXEClient(PXE_URL); - while (true) { - try { - await pxe.getNodeInfo(); - break; - } catch (err) { - await sleep(1000); - } - } -} diff --git a/yarn-project/aztec.js/src/utils/index.ts b/yarn-project/aztec.js/src/utils/index.ts index 08d014635ff..593a8ae4e6e 100644 --- a/yarn-project/aztec.js/src/utils/index.ts +++ b/yarn-project/aztec.js/src/utils/index.ts @@ -5,3 +5,4 @@ export * from './l2_contracts.js'; export * from './abi_types.js'; export * from './cheat_codes.js'; export * from './authwit.js'; +export * from './pxe.js'; diff --git a/yarn-project/aztec.js/src/utils/l1_contracts.ts b/yarn-project/aztec.js/src/utils/l1_contracts.ts index 7275756a579..9fd0e5d2b63 100644 --- a/yarn-project/aztec.js/src/utils/l1_contracts.ts +++ b/yarn-project/aztec.js/src/utils/l1_contracts.ts @@ -13,7 +13,7 @@ export const getL1ContractAddresses = async (url: string): Promise { + await retryUntil(async () => { + try { + logger?.('Attempting to contact PXE...'); + await pxe.getNodeInfo(); + return true; + } catch (error) { + logger?.('Failed to contact PXE!'); + } + return undefined; + }, 'RPC Get Node Info'); +}; diff --git a/yarn-project/cli/src/client.test.ts b/yarn-project/cli/src/client.test.ts index acb23c96e0a..607e1660886 100644 --- a/yarn-project/cli/src/client.test.ts +++ b/yarn-project/cli/src/client.test.ts @@ -13,19 +13,19 @@ describe('client', () => { }); it('checks versions match', async () => { - pxe.getNodeInfo.mockResolvedValue({ sandboxVersion: '0.1.0-alpha47' } as NodeInfo); + pxe.getNodeInfo.mockResolvedValue({ nodeVersion: '0.1.0-alpha47' } as NodeInfo); await checkServerVersion(pxe, '0.1.0-alpha47'); }); it('reports mismatch on older pxe version', async () => { - pxe.getNodeInfo.mockResolvedValue({ sandboxVersion: '0.1.0-alpha47' } as NodeInfo); + pxe.getNodeInfo.mockResolvedValue({ nodeVersion: '0.1.0-alpha47' } as NodeInfo); await expect(checkServerVersion(pxe, '0.1.0-alpha48')).rejects.toThrowError( /is older than the expected by this CLI/, ); }); it('reports mismatch on newer pxe version', async () => { - pxe.getNodeInfo.mockResolvedValue({ sandboxVersion: '0.1.0-alpha48' } as NodeInfo); + pxe.getNodeInfo.mockResolvedValue({ nodeVersion: '0.1.0-alpha48' } as NodeInfo); await expect(checkServerVersion(pxe, '0.1.0-alpha47')).rejects.toThrowError( /is newer than the expected by this CLI/, ); diff --git a/yarn-project/cli/src/client.ts b/yarn-project/cli/src/client.ts index acae1cfb9ce..18ea8bd2d5e 100644 --- a/yarn-project/cli/src/client.ts +++ b/yarn-project/cli/src/client.ts @@ -17,7 +17,7 @@ export async function createCompatibleClient(rpcUrl: string, logger: DebugLogger const pxe = createPXEClient(rpcUrl); const packageJsonPath = resolve(dirname(fileURLToPath(import.meta.url)), '../package.json'); const packageJsonContents = JSON.parse(readFileSync(packageJsonPath).toString()); - const expectedVersionRange = packageJsonContents.version; // During sandbox, we'll expect exact matches + const expectedVersionRange = packageJsonContents.version; try { await checkServerVersion(pxe, expectedVersionRange); @@ -41,27 +41,27 @@ class VersionMismatchError extends Error {} * @param expectedVersionRange - Expected version by CLI. */ export async function checkServerVersion(pxe: PXE, expectedVersionRange: string) { - const serverName = 'Aztec Sandbox'; - const { sandboxVersion } = await pxe.getNodeInfo(); - if (!sandboxVersion) { + const serverName = 'Aztec Node'; + const { nodeVersion } = await pxe.getNodeInfo(); + if (!nodeVersion) { throw new VersionMismatchError(`Couldn't determine ${serverName} version. You may run into issues.`); } - if (!sandboxVersion || !valid(sandboxVersion)) { + if (!nodeVersion || !valid(nodeVersion)) { throw new VersionMismatchError( - `Missing or invalid version identifier for ${serverName} (${sandboxVersion ?? 'empty'}).`, + `Missing or invalid version identifier for ${serverName} (${nodeVersion ?? 'empty'}).`, ); - } else if (!satisfies(sandboxVersion, expectedVersionRange)) { - if (gtr(sandboxVersion, expectedVersionRange)) { + } else if (!satisfies(nodeVersion, expectedVersionRange)) { + if (gtr(nodeVersion, expectedVersionRange)) { throw new VersionMismatchError( - `${serverName} is running version ${sandboxVersion} which is newer than the expected by this CLI (${expectedVersionRange}). Consider upgrading your CLI to a newer version.`, + `${serverName} is running version ${nodeVersion} which is newer than the expected by this CLI (${expectedVersionRange}). Consider upgrading your CLI to a newer version.`, ); - } else if (ltr(sandboxVersion, expectedVersionRange)) { + } else if (ltr(nodeVersion, expectedVersionRange)) { throw new VersionMismatchError( - `${serverName} is running version ${sandboxVersion} which is older than the expected by this CLI (${expectedVersionRange}). Consider upgrading your ${serverName} to a newer version.`, + `${serverName} is running version ${nodeVersion} which is older than the expected by this CLI (${expectedVersionRange}). Consider upgrading your ${serverName} to a newer version.`, ); } else { throw new VersionMismatchError( - `${serverName} is running version ${sandboxVersion} which does not match the expected by this CLI (${expectedVersionRange}).`, + `${serverName} is running version ${nodeVersion} which does not match the expected by this CLI (${expectedVersionRange}).`, ); } } diff --git a/yarn-project/cli/src/cmds/deploy.ts b/yarn-project/cli/src/cmds/deploy.ts index 459f5498c12..a8c7e7ffd96 100644 --- a/yarn-project/cli/src/cmds/deploy.ts +++ b/yarn-project/cli/src/cmds/deploy.ts @@ -27,7 +27,7 @@ export async function deploy( const client = await createCompatibleClient(rpcUrl, debugLogger); const nodeInfo = await client.getNodeInfo(); - const expectedAztecNrVersion = `${GITHUB_TAG_PREFIX}-v${nodeInfo.sandboxVersion}`; + const expectedAztecNrVersion = `${GITHUB_TAG_PREFIX}-v${nodeInfo.nodeVersion}`; if (contractArtifact.aztecNrVersion && contractArtifact.aztecNrVersion !== expectedAztecNrVersion) { log( `\nWarning: Contract was compiled with a different version of Aztec.nr: ${contractArtifact.aztecNrVersion}. Consider updating Aztec.nr to ${expectedAztecNrVersion}\n`, diff --git a/yarn-project/cli/src/cmds/get_node_info.ts b/yarn-project/cli/src/cmds/get_node_info.ts index bc71a7bc8cc..4d98da411cd 100644 --- a/yarn-project/cli/src/cmds/get_node_info.ts +++ b/yarn-project/cli/src/cmds/get_node_info.ts @@ -9,7 +9,7 @@ export async function getNodeInfo(rpcUrl: string, debugLogger: DebugLogger, log: const client = await createCompatibleClient(rpcUrl, debugLogger); const info = await client.getNodeInfo(); log(`\nNode Info:\n`); - log(`Sandbox Version: ${info.sandboxVersion}\n`); + log(`Node Version: ${info.nodeVersion}\n`); log(`Compatible Nargo Version: ${info.compatibleNargoVersion}\n`); log(`Chain Id: ${info.chainId}\n`); log(`Protocol Version: ${info.protocolVersion}\n`); diff --git a/yarn-project/end-to-end/package.json b/yarn-project/end-to-end/package.json index 0758812b741..7fc87ba4554 100644 --- a/yarn-project/end-to-end/package.json +++ b/yarn-project/end-to-end/package.json @@ -26,7 +26,6 @@ "@aztec/accounts": "workspace:^", "@aztec/archiver": "workspace:^", "@aztec/aztec-node": "workspace:^", - "@aztec/aztec-sandbox": "workspace:^", "@aztec/aztec.js": "workspace:^", "@aztec/circuits.js": "workspace:^", "@aztec/cli": "workspace:^", diff --git a/yarn-project/end-to-end/src/benchmarks/utils.ts b/yarn-project/end-to-end/src/benchmarks/utils.ts index 616cf6b90d9..780d2561d6c 100644 --- a/yarn-project/end-to-end/src/benchmarks/utils.ts +++ b/yarn-project/end-to-end/src/benchmarks/utils.ts @@ -21,7 +21,7 @@ import { join } from 'path'; import { EndToEndContext, setup } from '../fixtures/utils.js'; /** - * Setup for benchmarks. Initializes a sandbox node with a single account and deploys a benchmark contract. + * Setup for benchmarks. Initializes a remote node with a single account and deploys a benchmark contract. */ export async function benchmarkSetup(opts: Partial) { const context = await setup(1, { ...opts }); diff --git a/yarn-project/end-to-end/src/cli_docs_sandbox.test.ts b/yarn-project/end-to-end/src/cli_docs_sandbox.test.ts index 946f972e67b..a122f12ca61 100644 --- a/yarn-project/end-to-end/src/cli_docs_sandbox.test.ts +++ b/yarn-project/end-to-end/src/cli_docs_sandbox.test.ts @@ -29,7 +29,7 @@ describe('CLI docs sandbox', () => { % aztec-cli get-node-info Node Info: -Sandbox Version: #include_aztec_short_version +Node Version: #include_aztec_short_version Compatible Nargo Version: #include_noir_version Chain Id: 31337 Protocol Version: 1 diff --git a/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts b/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts index 3049ef611d8..fe12f518236 100644 --- a/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts +++ b/yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts @@ -1,39 +1,52 @@ import { createDebugLogger, fileURLToPath } from '@aztec/aztec.js'; +import { startPXEHttpServer } from '@aztec/pxe'; import Koa from 'koa'; import serve from 'koa-static'; import path, { dirname } from 'path'; +import { setup } from './fixtures/utils.js'; import { browserTestSuite } from './shared/browser.js'; +const { PXE_URL = '' } = process.env; + const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); -const PORT = 3000; +const PORT = 4000; +const PXE_PORT = 4001; + +const logger = createDebugLogger('aztec:e2e_aztec_browser.js:web'); +const pageLogger = createDebugLogger('aztec:e2e_aztec_browser.js:web:page'); -const logger = createDebugLogger('aztec:canary_aztec.js:web'); -const pageLogger = createDebugLogger('aztec:canary_aztec.js:web:page'); /** - * This test is a bit of a special case as it's relying on sandbox and web browser and not only on anvil and node.js. + * This test is a bit of a special case as it's on a web browser and not only on anvil and node.js. * To run the test, do the following: * 1) Build the whole repository, * 2) go to `yarn-project/end-to-end` and build the web packed package with `yarn build:web`, * 3) start anvil: `anvil`, - * 4) open new terminal and optionally set the more verbose debug level: `DEBUG=aztec:*`, - * 5) go to the sandbox dir `yarn-project/aztec-sandbox` and run `yarn start`, - * 6) open new terminal and export the URL of PXE from Sandbox: `export PXE_URL='http://localhost:8080'`, + * 4) if you intend to use a remotely running environment then export the URL of your PXE e.g. `export PXE_URL='http://localhost:8080'` * 7) go to `yarn-project/end-to-end` and run the test: `yarn test aztec_js_browser` * - * NOTE: If you see aztec-sandbox logs spammed with unexpected logs there is probably a chrome process with a webpage + * NOTE: If you see the logs spammed with unexpected logs there is probably a chrome process with a webpage * unexpectedly running in the background. Kill it with `killall chrome` */ -const setupApp = () => { + +const setupApp = async () => { + const { pxe: pxeService } = await setup(0); + let pxeURL = PXE_URL; + let pxeServer = undefined; + if (!PXE_URL) { + pxeServer = startPXEHttpServer(pxeService, PXE_PORT); + pxeURL = `http://localhost:${PXE_PORT}`; + } + const app = new Koa(); app.use(serve(path.resolve(__dirname, './web'))); const server = app.listen(PORT, () => { - logger(`Server started at http://localhost:${PORT}`); + logger(`Web Server started at http://localhost:${PORT}`); }); - return server; + return { server, webServerURL: `http://localhost:${PORT}`, pxeServer, pxeURL }; }; browserTestSuite(setupApp, pageLogger); diff --git a/yarn-project/end-to-end/src/e2e_card_game.test.ts b/yarn-project/end-to-end/src/e2e_card_game.test.ts index 737d5c1273d..e78a3a9ae84 100644 --- a/yarn-project/end-to-end/src/e2e_card_game.test.ts +++ b/yarn-project/end-to-end/src/e2e_card_game.test.ts @@ -1,13 +1,20 @@ -import { deployInitialSandboxAccounts, getSandboxAccountsWallets } from '@aztec/accounts/testing'; -import { AccountWallet, AztecAddress, DebugLogger, PXE, Wallet } from '@aztec/aztec.js'; +import { getSchnorrAccount } from '@aztec/accounts/schnorr'; +import { INITIAL_TEST_ENCRYPTION_KEYS } from '@aztec/accounts/testing'; +import { + AccountWallet, + AztecAddress, + DebugLogger, + GrumpkinScalar, + PXE, + Wallet, + generatePublicKey, +} from '@aztec/aztec.js'; import { CardGameContract } from '@aztec/noir-contracts/CardGame'; import { setup } from './fixtures/utils.js'; /* eslint-disable camelcase */ -const { PXE_URL } = process.env; - interface Card { points: bigint; strength: bigint; @@ -46,6 +53,8 @@ function unwrapOptions(options: NoirOption[]): T[] { const GAME_ID = 42; +const PLAYER_ENCRYPTION_KEYS = INITIAL_TEST_ENCRYPTION_KEYS; + describe('e2e_card_game', () => { let pxe: PXE; let logger: DebugLogger; @@ -64,24 +73,38 @@ describe('e2e_card_game', () => { let contractAsSecondPlayer: CardGameContract; let contractAsThirdPlayer: CardGameContract; - beforeEach(async () => { - // Card stats are derived from the users' private keys, so to get consistent values, we set up the - // initial sandbox accounts that always use the same private keys, instead of random ones. - ({ pxe, logger, teardown } = await setup(0)); - - // Get pre-deployed account wallets if we're running against sandbox. - if (PXE_URL) { - wallets = await getSandboxAccountsWallets(pxe); - } else { - // Deploy initial wallets if we're NOT running against sandbox. - wallets = await Promise.all((await deployInitialSandboxAccounts(pxe)).map(a => a.account.getWallet())); + beforeAll(async () => { + ({ pxe, logger, teardown, wallets } = await setup(0)); + + const preRegisteredAccounts = await pxe.getRegisteredAccounts(); + + const toRegister = PLAYER_ENCRYPTION_KEYS.filter(key => { + const publicKey = generatePublicKey(key); + return ( + preRegisteredAccounts.find(preRegisteredAccount => { + return preRegisteredAccount.publicKey.equals(publicKey); + }) == undefined + ); + }); + + for (let i = 0; i < toRegister.length; i++) { + logger(`Deploying account contract ${i}/${toRegister.length}...`); + const encryptionPrivateKey = toRegister[i]; + const account = getSchnorrAccount(pxe, encryptionPrivateKey, GrumpkinScalar.random()); + const wallet = await account.waitDeploy({ interval: 0.1 }); + wallets.push(wallet); } + logger('Account contracts deployed'); + [firstPlayerWallet, secondPlayerWallet, thirdPlayerWallet] = wallets; [firstPlayer, secondPlayer, thirdPlayer] = wallets.map(a => a.getAddress()); - await deployContract(); }, 100_000); - afterEach(() => teardown()); + beforeEach(async () => { + await deployContract(); + }); + + afterAll(() => teardown()); const deployContract = async () => { logger(`Deploying L2 contract...`); diff --git a/yarn-project/end-to-end/src/e2e_cli.test.ts b/yarn-project/end-to-end/src/e2e_cli.test.ts index bb3d0a11d71..221902983f9 100644 --- a/yarn-project/end-to-end/src/e2e_cli.test.ts +++ b/yarn-project/end-to-end/src/e2e_cli.test.ts @@ -1,33 +1,30 @@ -import { startHttpRpcServer } from '@aztec/aztec-sandbox'; import { PXE, createDebugLogger } from '@aztec/aztec.js'; +import { startHttpRpcServer } from '@aztec/foundation/json-rpc/server'; import { createPXERpcServer } from '@aztec/pxe'; import { setup as e2eSetup } from './fixtures/utils.js'; import { cliTestSuite } from './shared/cli.js'; const HTTP_PORT = 9009; -let RPC_URL = `http://localhost:${HTTP_PORT}`; const debug = createDebugLogger('aztec:e2e_cli'); +const { PXE_URL = '' } = process.env; +let RPC_URL = PXE_URL; + let http: ReturnType; let pxe: PXE; let teardown: () => Promise; -// Use Sandbox PXE URL if we're running against sandbox -const { PXE_URL } = process.env; -if (PXE_URL) { - RPC_URL = PXE_URL; -} - const testSetup = async () => { const context = await e2eSetup(2); debug(`Environment set up`); ({ pxe, teardown } = context); - if (!PXE_URL) { + if (!RPC_URL) { http = startHttpRpcServer(pxe, createPXERpcServer, HTTP_PORT); - debug(`HTTP RPC server started in port ${HTTP_PORT}`); + debug(`HTTP RPC server started on port ${HTTP_PORT}`); + RPC_URL = `http://localhost:${HTTP_PORT}`; } - return pxe; + return { pxe, rpcURL: RPC_URL }; }; const testCleanup = async () => { @@ -35,4 +32,4 @@ const testCleanup = async () => { await teardown(); }; -cliTestSuite('E2E CLI Test', testSetup, testCleanup, createDebugLogger('aztec:e2e_cli'), RPC_URL); +cliTestSuite('E2E CLI Test', testSetup, testCleanup, createDebugLogger('aztec:e2e_cli')); diff --git a/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts b/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts index 0f23b5387d3..4614d16de93 100644 --- a/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts +++ b/yarn-project/end-to-end/src/e2e_multiple_accounts_1_enc_key.test.ts @@ -1,5 +1,4 @@ import { getSchnorrAccount } from '@aztec/accounts/schnorr'; -import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; import { AztecAddress, AztecNode, @@ -19,13 +18,11 @@ import { TokenContract } from '@aztec/noir-contracts/Token'; import { expectsNumOfEncryptedLogsInTheLastBlockToBe, setup } from './fixtures/utils.js'; -const { PXE_URL } = process.env; - describe('e2e_multiple_accounts_1_enc_key', () => { let aztecNode: AztecNode | undefined; let pxe: PXE; const wallets: Wallet[] = []; - const accounts: AztecAddress[] = []; + const accounts: CompleteAddress[] = []; let logger: DebugLogger; let teardown: () => Promise; @@ -44,27 +41,16 @@ describe('e2e_multiple_accounts_1_enc_key', () => { const signingPrivateKey = GrumpkinScalar.random(); const account = getSchnorrAccount(pxe, encryptionPrivateKey, signingPrivateKey); const wallet = await account.waitDeploy({ interval: 0.1 }); - const { address } = account.getCompleteAddress(); + const completeAddress = account.getCompleteAddress(); wallets.push(wallet); - accounts.push(address); + accounts.push(completeAddress); } logger('Account contracts deployed'); // Verify that all accounts use the same encryption key const encryptionPublicKey = generatePublicKey(encryptionPrivateKey); - // Disregard sandbox accounts - let keyAccounts: CompleteAddress[]; - if (PXE_URL) { - const sandBoxWallets = await getSandboxAccountsWallets(pxe); - const allAccounts = await pxe.getRegisteredAccounts(); - keyAccounts = allAccounts.filter( - acc => !sandBoxWallets.map(wlt => wlt.getAddress().toString()).includes(acc.address.toString()), - ); - } else { - keyAccounts = await pxe.getRegisteredAccounts(); - } - for (const account of keyAccounts) { + for (const account of accounts) { expect(account.publicKey).toEqual(encryptionPublicKey); } @@ -81,7 +67,7 @@ describe('e2e_multiple_accounts_1_enc_key', () => { const storageSlot = new Fr(5); const note = new Note([new Fr(initialBalance), secretHash]); - const extendedNote = new ExtendedNote(note, accounts[0], token.address, storageSlot, receipt.txHash); + const extendedNote = new ExtendedNote(note, accounts[0].address, token.address, storageSlot, receipt.txHash); await pxe.addNote(extendedNote); expect((await token.methods.redeem_shield(accounts[0], initialBalance, secret).send().wait()).status).toEqual( @@ -97,7 +83,7 @@ describe('e2e_multiple_accounts_1_enc_key', () => { // Then check the balance const contractWithWallet = await TokenContract.at(tokenAddress, wallet); - const balance = await contractWithWallet.methods.balance_of_private(owner).view({ from: owner }); + const balance = await contractWithWallet.methods.balance_of_private(owner).view({ from: owner.address }); logger(`Account ${owner} balance: ${balance}`); expect(balance).toBe(expectedBalance); }; diff --git a/yarn-project/end-to-end/src/e2e_p2p_network.test.ts b/yarn-project/end-to-end/src/e2e_p2p_network.test.ts index a5888f24dcb..5522ad9c880 100644 --- a/yarn-project/end-to-end/src/e2e_p2p_network.test.ts +++ b/yarn-project/end-to-end/src/e2e_p2p_network.test.ts @@ -23,7 +23,6 @@ import { MNEMONIC } from './fixtures/fixtures.js'; import { setup } from './fixtures/utils.js'; // Don't set this to a higher value than 9 because each node will use a different L1 publisher account and anvil seeds -// only 10 accounts with ETH (9 and not 10 because first account is used by sandbox). const NUM_NODES = 4; const NUM_TXS_PER_BLOCK = 4; const NUM_TXS_PER_NODE = 2; @@ -114,7 +113,7 @@ describe('e2e_p2p_network', () => { // creates a P2P enabled instance of Aztec Node Service const createNode = async (tcpListenPort: number, bootstrapNode: string, publisherAddressIndex: number) => { // We use different L1 publisher accounts in order to avoid duplicate tx nonces. We start from - // publisherAddressIndex + 1 because index 0 was already used during sandbox setup. + // publisherAddressIndex + 1 because index 0 was already used during test environment setup. const hdAccount = mnemonicToAccount(MNEMONIC, { addressIndex: publisherAddressIndex + 1 }); const publisherPrivKey = Buffer.from(hdAccount.getHdKey().privateKey!); config.publisherPrivateKey = `0x${publisherPrivKey!.toString('hex')}`; diff --git a/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts b/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts index dd56c756b41..ed309ad1361 100644 --- a/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts +++ b/yarn-project/end-to-end/src/e2e_sandbox_example.test.ts @@ -1,6 +1,6 @@ // docs:start:imports import { getSchnorrAccount } from '@aztec/accounts/schnorr'; -import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; +import { getDeployedTestAccountsWallets } from '@aztec/accounts/testing'; import { ExtendedNote, Fr, @@ -10,7 +10,7 @@ import { computeMessageSecretHash, createDebugLogger, createPXEClient, - waitForSandbox, + waitForPXE, } from '@aztec/aztec.js'; import { TokenContract } from '@aztec/noir-contracts/Token'; @@ -28,7 +28,7 @@ describe('e2e_sandbox_example', () => { // We create PXE client connected to the sandbox URL const pxe = createPXEClient(PXE_URL); // Wait for sandbox to be ready - await waitForSandbox(pxe); + await waitForPXE(pxe, logger); const nodeInfo = await pxe.getNodeInfo(); @@ -45,7 +45,7 @@ describe('e2e_sandbox_example', () => { // docs:start:load_accounts ////////////// LOAD SOME ACCOUNTS FROM THE SANDBOX ////////////// // The sandbox comes with a set of created accounts. Load them - const accounts = await getSandboxAccountsWallets(pxe); + const accounts = await getDeployedTestAccountsWallets(pxe); const aliceWallet = accounts[0]; const bobWallet = accounts[1]; const alice = aliceWallet.getAddress(); @@ -167,7 +167,7 @@ describe('e2e_sandbox_example', () => { // We create PXE client connected to the sandbox URL const pxe = createPXEClient(PXE_URL); // Wait for sandbox to be ready - await waitForSandbox(pxe); + await waitForPXE(pxe, logger); // docs:start:create_accounts ////////////// CREATE SOME ACCOUNTS WITH SCHNORR SIGNERS ////////////// diff --git a/yarn-project/end-to-end/src/fixtures/index.ts b/yarn-project/end-to-end/src/fixtures/index.ts new file mode 100644 index 00000000000..146faa68d45 --- /dev/null +++ b/yarn-project/end-to-end/src/fixtures/index.ts @@ -0,0 +1,3 @@ +export * from './fixtures.js'; +export * from './logging.js'; +export * from './utils.js'; diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index 9809052c3a2..ae5755f56ea 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -1,4 +1,4 @@ -import { createAccounts, getSandboxAccountsWallets } from '@aztec/accounts/testing'; +import { createAccounts, getDeployedTestAccountsWallets } from '@aztec/accounts/testing'; import { AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node'; import { AccountWalletWithPrivateKey, @@ -17,7 +17,7 @@ import { createDebugLogger, createPXEClient, deployL1Contracts, - retryUntil, + waitForPXE, } from '@aztec/aztec.js'; import { ContractDeploymentEmitterAbi, @@ -67,19 +67,6 @@ const getAztecNodeUrl = () => { return url.toString(); }; -export const waitForPXE = async (pxe: PXE, logger: DebugLogger) => { - await retryUntil(async () => { - try { - logger('Attempting to contact PXE...'); - await pxe.getNodeInfo(); - return true; - } catch (error) { - logger('Failed to contact PXE!'); - } - return undefined; - }, 'RPC Get Node Info'); -}; - export const setupL1Contracts = async ( l1RpcUrl: string, account: HDAccount | PrivateKeyAccount, @@ -163,21 +150,21 @@ export async function setupPXEService( } /** - * Function to setup the test against a running sandbox. + * Function to setup the test against a remote deployment. It is assumed that L1 contract are already deployed * @param account - The account for use in create viem wallets. * @param config - The aztec Node Configuration * @param logger - The logger to be used * @param numberOfAccounts - The number of new accounts to be created once the PXE is initiated. - * (will create extra accounts if the sandbox don't already have enough accounts) + * (will create extra accounts if the environment doesn't already have enough accounts) * @returns Private eXecution Environment (PXE) client, viem wallets, contract addresses etc. */ -async function setupWithSandbox( +async function setupWithRemoteEnvironment( account: Account, config: AztecNodeConfig, logger: DebugLogger, numberOfAccounts: number, ) { - // we are setting up against the sandbox, l1 contracts are already deployed + // we are setting up against a remote environment, l1 contracts are already deployed const aztecNodeUrl = getAztecNodeUrl(); logger(`Creating Aztec Node client to remote host ${aztecNodeUrl}`); const aztecNode = createAztecNodeClient(aztecNodeUrl); @@ -187,11 +174,13 @@ async function setupWithSandbox( logger('JSON RPC client connected to PXE'); logger(`Retrieving contract addresses from ${PXE_URL}`); const l1Contracts = (await pxeClient.getNodeInfo()).l1ContractAddresses; - logger('PXE created, constructing wallets from initial sandbox accounts...'); - const wallets = await getSandboxAccountsWallets(pxeClient); + logger('PXE created, constructing available wallets from already registered accounts...'); + const wallets = await getDeployedTestAccountsWallets(pxeClient); if (wallets.length < numberOfAccounts) { - wallets.push(...(await createAccounts(pxeClient, numberOfAccounts - wallets.length))); + const numNewAccounts = numberOfAccounts - wallets.length; + logger(`Deploying ${numNewAccounts} accounts...`); + wallets.push(...(await createAccounts(pxeClient, numNewAccounts))); } const walletClient = createWalletClient({ @@ -232,7 +221,7 @@ type SetupOptions = { /** State load */ stateLoad?: string } & Partial { describe('on local sandbox', () => { beforeAll(async () => { const pxe = createPXEClient(PXE_URL); - await waitForSandbox(pxe); + await waitForPXE(pxe); }); // docs:start:sandbox-example @@ -66,7 +65,7 @@ describe('guides/dapp/testing', () => { beforeEach(async () => { // docs:start:use-existing-wallets pxe = createPXEClient(PXE_URL); - [owner, recipient] = await getSandboxAccountsWallets(pxe); + [owner, recipient] = await getDeployedTestAccountsWallets(pxe); token = await TokenContract.deploy(owner, owner.getCompleteAddress()).send().deployed(); // docs:end:use-existing-wallets }, 30_000); @@ -224,45 +223,4 @@ describe('guides/dapp/testing', () => { }, 30_000); }); }); - - describe('on in-proc sandbox', () => { - describe('token contract', () => { - let pxe: PXE; - let stop: () => Promise; - let owner: AccountWallet; - let recipient: AccountWallet; - let token: TokenContract; - - beforeAll(async () => { - // docs:start:in-proc-sandbox - ({ pxe, stop } = await createSandbox()); - // docs:end:in-proc-sandbox - owner = await createAccount(pxe); - recipient = await createAccount(pxe); - token = await TokenContract.deploy(owner, owner.getCompleteAddress()).send().deployed(); - }, 60_000); - - // docs:start:stop-in-proc-sandbox - afterAll(() => stop()); - // docs:end:stop-in-proc-sandbox - - it('increases recipient funds on mint', async () => { - const recipientAddress = recipient.getAddress(); - expect(await token.methods.balance_of_private(recipientAddress).view()).toEqual(0n); - - const mintAmount = 20n; - const secret = Fr.random(); - const secretHash = computeMessageSecretHash(secret); - const receipt = await token.methods.mint_private(mintAmount, secretHash).send().wait(); - - const storageSlot = new Fr(5); - const note = new Note([new Fr(mintAmount), secretHash]); - const extendedNote = new ExtendedNote(note, recipientAddress, token.address, storageSlot, receipt.txHash); - await pxe.addNote(extendedNote); - - await token.methods.redeem_shield(recipientAddress, mintAmount, secret).send().wait(); - expect(await token.methods.balance_of_private(recipientAddress).view()).toEqual(20n); - }, 30_000); - }); - }); }); diff --git a/yarn-project/end-to-end/src/guides/up_quick_start.test.ts b/yarn-project/end-to-end/src/guides/up_quick_start.test.ts index 82b227054a6..dfacf8687cf 100644 --- a/yarn-project/end-to-end/src/guides/up_quick_start.test.ts +++ b/yarn-project/end-to-end/src/guides/up_quick_start.test.ts @@ -1,11 +1,13 @@ -import { waitForSandbox } from '@aztec/aztec.js'; +import { createPXEClient, waitForPXE } from '@aztec/aztec.js'; import { execSync } from 'child_process'; +const { PXE_URL = '' } = process.env; + // Entrypoint for running the up-quick-start script on the CI describe('guides/up_quick_start', () => { it('works', async () => { - await waitForSandbox(); + await waitForPXE(createPXEClient(PXE_URL)); execSync( `DEBUG="aztec:*" PXE_URL=\${PXE_URL:-http://localhost:8080} PATH=$PATH:../node_modules/.bin ./src/guides/up_quick_start.sh`, { diff --git a/yarn-project/end-to-end/src/pxe.test.ts b/yarn-project/end-to-end/src/pxe.test.ts new file mode 100644 index 00000000000..0b355e3b803 --- /dev/null +++ b/yarn-project/end-to-end/src/pxe.test.ts @@ -0,0 +1,12 @@ +import { waitForPXE } from '@aztec/aztec.js'; +import { pxeTestSuite } from '@aztec/pxe'; + +import { setup } from './fixtures/utils.js'; + +const setupEnv = async () => { + const { pxe } = await setup(0); + await waitForPXE(pxe); + return pxe; +}; + +pxeTestSuite('pxe', setupEnv); diff --git a/yarn-project/end-to-end/src/pxe_sandbox.test.ts b/yarn-project/end-to-end/src/pxe_sandbox.test.ts deleted file mode 100644 index c39f0edfd14..00000000000 --- a/yarn-project/end-to-end/src/pxe_sandbox.test.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { createPXEClient, waitForSandbox } from '@aztec/aztec.js'; -import { pxeTestSuite } from '@aztec/pxe'; - -const { PXE_URL = 'http://localhost:8080' } = process.env; - -const setup = async () => { - const pxe = createPXEClient(PXE_URL); - await waitForSandbox(pxe); - return pxe; -}; - -pxeTestSuite('pxe_sandbox', setup); diff --git a/yarn-project/end-to-end/src/sample-dapp/ci/index.test.mjs b/yarn-project/end-to-end/src/sample-dapp/ci/index.test.mjs index a2b67b509bc..5544f249352 100644 --- a/yarn-project/end-to-end/src/sample-dapp/ci/index.test.mjs +++ b/yarn-project/end-to-end/src/sample-dapp/ci/index.test.mjs @@ -1,12 +1,14 @@ -import { waitForSandbox } from '@aztec/aztec.js'; +import { createPXEClient, waitForPXE } from '@aztec/aztec.js'; import { deploy } from '../deploy.mjs'; import { main } from '../index.mjs'; +const { PXE_URL = '' } = process.env; + // Tests on our CI that all scripts included in the guide work fine describe('sample-dapp', () => { it('deploys and runs without errors', async () => { - await waitForSandbox(); + await waitForPXE(createPXEClient(PXE_URL)); await deploy(); await main(); }, 90_000); diff --git a/yarn-project/end-to-end/src/sample-dapp/deploy.mjs b/yarn-project/end-to-end/src/sample-dapp/deploy.mjs index 62c6f98ba94..f3043b64d2b 100644 --- a/yarn-project/end-to-end/src/sample-dapp/deploy.mjs +++ b/yarn-project/end-to-end/src/sample-dapp/deploy.mjs @@ -1,4 +1,4 @@ -import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; +import { getInitialTestAccountsWallets } from '@aztec/accounts/testing'; import { Contract, createPXEClient } from '@aztec/aztec.js'; import { TokenContractArtifact } from '@aztec/noir-contracts/Token'; @@ -10,7 +10,7 @@ const { PXE_URL = 'http://localhost:8080' } = process.env; async function main() { const pxe = createPXEClient(PXE_URL); - const [ownerWallet] = await getSandboxAccountsWallets(pxe); + const [ownerWallet] = await getInitialTestAccountsWallets(pxe); const ownerAddress = ownerWallet.getCompleteAddress(); const token = await Contract.deploy(ownerWallet, TokenContractArtifact, [ownerAddress]).send().deployed(); diff --git a/yarn-project/end-to-end/src/sample-dapp/index.mjs b/yarn-project/end-to-end/src/sample-dapp/index.mjs index 32d67453da9..36f2b82a6f4 100644 --- a/yarn-project/end-to-end/src/sample-dapp/index.mjs +++ b/yarn-project/end-to-end/src/sample-dapp/index.mjs @@ -1,4 +1,4 @@ -import { getSandboxAccountsWallets } from '@aztec/accounts/testing'; +import { getInitialTestAccountsWallets } from '@aztec/accounts/testing'; import { ExtendedNote, Fr, Note, computeMessageSecretHash, createPXEClient } from '@aztec/aztec.js'; import { fileURLToPath } from '@aztec/foundation/url'; @@ -27,7 +27,7 @@ async function showPrivateBalances(pxe) { } async function mintPrivateFunds(pxe) { - const [owner] = await getSandboxAccountsWallets(pxe); + const [owner] = await getInitialTestAccountsWallets(pxe); const token = await getToken(owner); await showPrivateBalances(pxe); @@ -49,7 +49,7 @@ async function mintPrivateFunds(pxe) { async function transferPrivateFunds(pxe) { // docs:start:transferPrivateFunds - const [owner, recipient] = await getSandboxAccountsWallets(pxe); + const [owner, recipient] = await getInitialTestAccountsWallets(pxe); const token = await getToken(owner); const tx = token.methods.transfer(owner.getAddress(), recipient.getAddress(), 1n, 0).send(); @@ -78,7 +78,7 @@ async function showPublicBalances(pxe) { async function mintPublicFunds(pxe) { // docs:start:mintPublicFunds - const [owner] = await getSandboxAccountsWallets(pxe); + const [owner] = await getInitialTestAccountsWallets(pxe); const token = await getToken(owner); const tx = token.methods.mint_public(owner.getAddress(), 100n).send(); diff --git a/yarn-project/end-to-end/src/sample-dapp/index.test.mjs b/yarn-project/end-to-end/src/sample-dapp/index.test.mjs index 69e4fb2a9b5..7724756ef16 100644 --- a/yarn-project/end-to-end/src/sample-dapp/index.test.mjs +++ b/yarn-project/end-to-end/src/sample-dapp/index.test.mjs @@ -6,7 +6,7 @@ import { Note, computeMessageSecretHash, createPXEClient, - waitForSandbox, + waitForPXE, } from '@aztec/aztec.js'; import { TokenContractArtifact } from '@aztec/noir-contracts/Token'; @@ -17,7 +17,7 @@ describe('token', () => { let owner, recipient, token; beforeAll(async () => { const pxe = createPXEClient(PXE_URL); - await waitForSandbox(pxe); + await waitForPXE(pxe); owner = await createAccount(pxe); recipient = await createAccount(pxe); diff --git a/yarn-project/end-to-end/src/shared/browser.ts b/yarn-project/end-to-end/src/shared/browser.ts index 4b1eb21ce01..164474f899f 100644 --- a/yarn-project/end-to-end/src/shared/browser.ts +++ b/yarn-project/end-to-end/src/shared/browser.ts @@ -1,4 +1,5 @@ /* eslint-disable no-console */ +import * as AztecAccountsSchnorr from '@aztec/accounts/schnorr'; import * as AztecAccountsSingleKey from '@aztec/accounts/single_key'; import * as AztecAccountsTesting from '@aztec/accounts/testing'; import * as AztecJs from '@aztec/aztec.js'; @@ -18,22 +19,37 @@ declare global { /** * The aztec.js library. */ - AztecJs: typeof AztecJs & typeof AztecAccountsSingleKey & typeof AztecAccountsTesting; + AztecJs: typeof AztecJs & typeof AztecAccountsSingleKey & typeof AztecAccountsTesting & typeof AztecAccountsSchnorr; } } const __filename = AztecJs.fileURLToPath(import.meta.url); const __dirname = dirname(__filename); -const PORT = 3000; - -const { PXE_URL } = process.env; - -const conditionalDescribe = () => (PXE_URL ? describe : describe.skip); const privKey = AztecJs.GrumpkinScalar.random(); -export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugLogger) => - conditionalDescribe()('e2e_aztec.js_browser', () => { +export const browserTestSuite = ( + setup: () => Promise<{ + /** + * The webserver instance. + */ + server: Server; + /** + * The webserver URL. + */ + webServerURL: string; + /** + * The PXE webserver instance. + */ + pxeServer: Server | undefined; + /** + * The url of the PXE + */ + pxeURL: string; + }>, + pageLogger: AztecJs.DebugLogger, +) => + describe('e2e_aztec.js_browser', () => { const initialBalance = 33n; const transferAmount = 3n; @@ -42,14 +58,17 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL let app: Koa; let testClient: AztecJs.PXE; let server: Server; + let webServerURL: string; + let pxeServer: Server | undefined; + let pxeURL: string; let browser: Browser; let page: Page; beforeAll(async () => { - server = setup(); - testClient = AztecJs.createPXEClient(PXE_URL!); - await AztecJs.waitForSandbox(testClient); + ({ server, pxeURL, pxeServer, webServerURL } = await setup()); + testClient = AztecJs.createPXEClient(pxeURL); + await AztecJs.waitForPXE(testClient); app = new Koa(); app.use(serve(path.resolve(__dirname, './web'))); @@ -73,7 +92,7 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL page.on('pageerror', err => { pageLogger.error(err.toString()); }); - await page.goto(`http://localhost:${PORT}/index.html`); + await page.goto(`${webServerURL}/index.html`); while (!(await page.evaluate(() => !!window.AztecJs))) { pageLogger('Waiting for window.AztecJs...'); await AztecJs.sleep(1000); @@ -83,6 +102,7 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL afterAll(async () => { await browser.close(); server.close(); + pxeServer?.close(); }); it('Loads Aztec.js in the browser', async () => { @@ -106,7 +126,7 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL console.log(`Created Account: ${addressString}`); return addressString; }, - PXE_URL, + pxeURL, privKey.toString(), ); const accounts = await testClient.getRegisteredAccounts(); @@ -138,16 +158,16 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL Contract, AztecAddress, createPXEClient: createPXEClient, - getSandboxAccountsWallets, + getDeployedTestAccountsWallets, } = window.AztecJs; const pxe = createPXEClient(rpcUrl!); - const owner = (await pxe.getRegisteredAccounts())[0].address; - const [wallet] = await getSandboxAccountsWallets(pxe); + const [wallet] = await getDeployedTestAccountsWallets(pxe); + const owner = wallet.getCompleteAddress().address; const contract = await Contract.at(AztecAddress.fromString(contractAddress), TokenContractArtifact, wallet); const balance = await contract.methods.balance_of_private(owner).view({ from: owner }); return balance; }, - PXE_URL, + pxeURL, (await getTokenAddress()).toString(), TokenContractArtifact, ); @@ -162,18 +182,22 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL AztecAddress, Contract, createPXEClient: createPXEClient, - getSandboxAccountsWallets, + getDeployedTestAccountsWallets, + getUnsafeSchnorrAccount, } = window.AztecJs; const pxe = createPXEClient(rpcUrl!); - const accounts = await pxe.getRegisteredAccounts(); - const receiver = accounts[1].address; - const [wallet] = await getSandboxAccountsWallets(pxe); + const newReceiverAccount = await getUnsafeSchnorrAccount(pxe, AztecJs.GrumpkinScalar.random()).waitDeploy(); + const receiverAddress = newReceiverAccount.getCompleteAddress().address; + const [wallet] = await getDeployedTestAccountsWallets(pxe); const contract = await Contract.at(AztecAddress.fromString(contractAddress), TokenContractArtifact, wallet); - await contract.methods.transfer(accounts[0].address, receiver, transferAmount, 0).send().wait(); + await contract.methods + .transfer(wallet.getCompleteAddress().address, receiverAddress, transferAmount, 0) + .send() + .wait(); console.log(`Transferred ${transferAmount} tokens to new Account`); - return await contract.methods.balance_of_private(receiver).view({ from: receiver }); + return await contract.methods.balance_of_private(receiverAddress).view({ from: receiverAddress }); }, - PXE_URL, + pxeURL, (await getTokenAddress()).toString(), transferAmount, TokenContractArtifact, @@ -183,31 +207,38 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL const deployTokenContract = async () => { const txHash = await page.evaluate( - async (rpcUrl, privateKeyString, initialBalance, TokenContractArtifact) => { + async (rpcUrl, initialBalance, TokenContractArtifact) => { const { - GrumpkinScalar, DeployMethod, createPXEClient, - getUnsafeSchnorrAccount, + getSchnorrAccount, Contract, Fr, ExtendedNote, Note, computeMessageSecretHash, - getSandboxAccountsWallets, + getDeployedTestAccountsWallets, + INITIAL_TEST_ENCRYPTION_KEYS, + INITIAL_TEST_SIGNING_KEYS, + INITIAL_TEST_ACCOUNT_SALTS, } = window.AztecJs; const pxe = createPXEClient(rpcUrl!); - let accounts = await pxe.getRegisteredAccounts(); - if (accounts.length === 0) { - // This test needs an account for deployment. We create one in case there is none available in the PXE. - const privateKey = GrumpkinScalar.fromString(privateKeyString); - await getUnsafeSchnorrAccount(pxe, privateKey).waitDeploy(); - accounts = await pxe.getRegisteredAccounts(); + + // we need to ensure that a known account is present in order to create a wallet + const knownAccounts = await getDeployedTestAccountsWallets(pxe); + if (!knownAccounts.length) { + const newAccount = await getSchnorrAccount( + pxe, + INITIAL_TEST_ENCRYPTION_KEYS[0], + INITIAL_TEST_SIGNING_KEYS[0], + INITIAL_TEST_ACCOUNT_SALTS[0], + ).waitDeploy(); + knownAccounts.push(newAccount); } - const [owner] = await getSandboxAccountsWallets(pxe); + const owner = knownAccounts[0]; const ownerAddress = owner.getAddress(); const tx = new DeployMethod( - accounts[0].publicKey, + owner.getCompleteAddress().publicKey, pxe, TokenContractArtifact, (a: AztecJs.AztecAddress) => Contract.at(a, TokenContractArtifact, owner), @@ -235,8 +266,7 @@ export const browserTestSuite = (setup: () => Server, pageLogger: AztecJs.DebugL return txHash.toString(); }, - PXE_URL, - privKey.toString(), + pxeURL, initialBalance, TokenContractArtifact, ); diff --git a/yarn-project/end-to-end/src/shared/cli.ts b/yarn-project/end-to-end/src/shared/cli.ts index 17e50bee797..75a95afbaab 100644 --- a/yarn-project/end-to-end/src/shared/cli.ts +++ b/yarn-project/end-to-end/src/shared/cli.ts @@ -8,10 +8,18 @@ const TRANSFER_BALANCE = 3000; export const cliTestSuite = ( name: string, - setup: () => Promise, + setup: () => Promise<{ + /** + * The PXE instance. + */ + pxe: PXE; + /** + * The URL of the PXE RPC server. + */ + rpcURL: string; + }>, cleanup: () => Promise, debug: DebugLogger, - rpcUrl = 'http://localhost:8080', ) => describe(name, () => { let cli: ReturnType; @@ -19,12 +27,13 @@ export const cliTestSuite = ( let existingAccounts: CompleteAddress[]; let contractAddress: AztecAddress; let log: (msg: string) => void; + let rpcURL = ''; // All logs emitted by the cli will be collected here, and reset between tests const logs: string[] = []; beforeAll(async () => { - pxe = await setup(); + ({ pxe, rpcURL } = await setup()); log = (msg: string) => { logs.push(msg); debug(msg); @@ -49,7 +58,7 @@ export const cliTestSuite = ( const run = (cmd: string, addRpcUrl = true) => { const args = stringArgv(cmd, 'node', 'dest/bin/index.js'); if (addRpcUrl) { - args.push('--rpc-url', rpcUrl); + args.push('--rpc-url', rpcURL); } const res = cli.parseAsync(args); resetCli(); diff --git a/yarn-project/end-to-end/src/web/main.ts b/yarn-project/end-to-end/src/web/main.ts index 924b01eb9d4..992b578f291 100644 --- a/yarn-project/end-to-end/src/web/main.ts +++ b/yarn-project/end-to-end/src/web/main.ts @@ -1,3 +1,4 @@ export * from '@aztec/aztec.js'; export * from '@aztec/accounts/testing'; export * from '@aztec/accounts/single_key'; +export * from '@aztec/accounts/schnorr'; diff --git a/yarn-project/end-to-end/tsconfig.json b/yarn-project/end-to-end/tsconfig.json index b6911d791d6..80b2045a8b3 100644 --- a/yarn-project/end-to-end/tsconfig.json +++ b/yarn-project/end-to-end/tsconfig.json @@ -15,9 +15,6 @@ { "path": "../aztec-node" }, - { - "path": "../aztec-sandbox" - }, { "path": "../aztec.js" }, diff --git a/yarn-project/foundation/src/json-rpc/server/index.ts b/yarn-project/foundation/src/json-rpc/server/index.ts index 9a32d317b08..a20b679993b 100644 --- a/yarn-project/foundation/src/json-rpc/server/index.ts +++ b/yarn-project/foundation/src/json-rpc/server/index.ts @@ -1,2 +1,2 @@ -export { JsonRpcServer, createStatusRouter } from './json_rpc_server.js'; +export { JsonRpcServer, createStatusRouter, startHttpRpcServer } from './json_rpc_server.js'; export { JsonProxy } from './json_proxy.js'; diff --git a/yarn-project/foundation/src/json-rpc/server/json_rpc_server.ts b/yarn-project/foundation/src/json-rpc/server/json_rpc_server.ts index 64651ea30bf..ea1bd7e2d05 100644 --- a/yarn-project/foundation/src/json-rpc/server/json_rpc_server.ts +++ b/yarn-project/foundation/src/json-rpc/server/json_rpc_server.ts @@ -201,3 +201,25 @@ export function createStatusRouter(apiPrefix = '') { }); return router; } + +/** + * Creates an http server that forwards calls to the underlying instance and starts it on the given port. + * @param instance - Instance to wrap in a JSON-RPC server. + * @param jsonRpcFactoryFunc - Function that wraps the instance in a JSON-RPC server. + * @param port - Port to listen in. + * @returns A running http server. + */ +export function startHttpRpcServer( + instance: T, + jsonRpcFactoryFunc: (instance: T) => JsonRpcServer, + port: string | number, +): http.Server { + const rpcServer = jsonRpcFactoryFunc(instance); + + const app = rpcServer.getApp(); + + const httpServer = http.createServer(app.callback()); + httpServer.listen(port); + + return httpServer; +} diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index 51d9df89fab..651afaec957 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -72,7 +72,7 @@ export class PXEService implements PXE { private contractDataOracle: ContractDataOracle; private simulator: AcirSimulator; private log: DebugLogger; - private sandboxVersion: string; + private nodeVersion: string; // serialize synchronizer and calls to simulateTx. // ensures that state is not changed while simulating private jobQueue = new SerialQueue(); @@ -89,7 +89,7 @@ export class PXEService implements PXE { this.contractDataOracle = new ContractDataOracle(db, node); this.simulator = getAcirSimulator(db, node, keyStore, this.contractDataOracle); - this.sandboxVersion = getPackageInfo().version; + this.nodeVersion = getPackageInfo().version; } /** @@ -481,7 +481,7 @@ export class PXEService implements PXE { ]); const nodeInfo: NodeInfo = { - sandboxVersion: this.sandboxVersion, + nodeVersion: this.nodeVersion, compatibleNargoVersion: NoirWasmVersion, chainId, protocolVersion: version, diff --git a/yarn-project/types/src/interfaces/node-info.ts b/yarn-project/types/src/interfaces/node-info.ts index 3aaef041da8..1831263c0e3 100644 --- a/yarn-project/types/src/interfaces/node-info.ts +++ b/yarn-project/types/src/interfaces/node-info.ts @@ -7,9 +7,9 @@ export interface NodeInfo { /** * Version as tracked in the aztec-packages repository. */ - sandboxVersion: string; + nodeVersion: string; /** - * The nargo version compatible with this sandbox version + * The nargo version compatible with this node version */ compatibleNargoVersion: string; /** diff --git a/yarn-project/types/src/interfaces/pxe.ts b/yarn-project/types/src/interfaces/pxe.ts index 1ae517bc3f0..ca21564c751 100644 --- a/yarn-project/types/src/interfaces/pxe.ts +++ b/yarn-project/types/src/interfaces/pxe.ts @@ -229,7 +229,7 @@ export interface PXE { getBlockNumber(): Promise; /** - * Returns the information about the server's node. Includes current Sandbox version, compatible Noir version, + * Returns the information about the server's node. Includes current Node version, compatible Noir version, * L1 chain identifier, protocol version, and L1 address of the rollup contract. * @returns - The node information. */ diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index fdd12b043ff..6cd9c7ffcd5 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -196,7 +196,7 @@ __metadata: languageName: unknown linkType: soft -"@aztec/aztec-sandbox@workspace:^, @aztec/aztec-sandbox@workspace:aztec-sandbox": +"@aztec/aztec-sandbox@workspace:aztec-sandbox": version: 0.0.0-use.local resolution: "@aztec/aztec-sandbox@workspace:aztec-sandbox" dependencies: @@ -366,7 +366,6 @@ __metadata: "@aztec/accounts": "workspace:^" "@aztec/archiver": "workspace:^" "@aztec/aztec-node": "workspace:^" - "@aztec/aztec-sandbox": "workspace:^" "@aztec/aztec.js": "workspace:^" "@aztec/circuits.js": "workspace:^" "@aztec/cli": "workspace:^"