Skip to content

Commit

Permalink
chore: Cleanup sandbox dependent tests (#3861)
Browse files Browse the repository at this point in the history
This PR removed the assumption of some tests running against the
sandbox.

Only boxes and docs tests imply sandbox usage.

# Checklist:
Remove the checklist to signal you've completed it. Enable auto-merge if
the PR is ready to merge.
- [ ] If the pull request requires a cryptography review (e.g.
cryptographic algorithm implementations) I have added the 'crypto' tag.
- [ ] I have reviewed my diff in github, line by line and removed
unexpected formatting changes, testing logs, or commented-out code.
- [ ] Every change is related to the PR description.
- [ ] I have
[linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
this pull request to relevant issues (if any exist).

---------

Co-authored-by: Santiago Palladino <[email protected]>
  • Loading branch information
PhilWindle and spalladino authored Jan 9, 2024
1 parent 22c65bf commit 158c5be
Show file tree
Hide file tree
Showing 60 changed files with 388 additions and 371 deletions.
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions boxes/blank-react/src/environment/index.ts
Original file line number Diff line number Diff line change
@@ -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;
};
4 changes: 2 additions & 2 deletions boxes/blank-react/src/scripts/util.ts
Original file line number Diff line number Diff line change
@@ -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 => {
Expand All @@ -27,7 +27,7 @@ export function convertArgs(functionAbi: FunctionArtifact, args: any): Fr[] {
* @returns
*/
export async function getWallet(account: CompleteAddress, pxe: PXE): Promise<AccountWallet> {
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.`);
Expand Down
14 changes: 2 additions & 12 deletions boxes/blank-react/src/tests/blank.contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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...');
Expand All @@ -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;

Expand Down
11 changes: 11 additions & 0 deletions boxes/blank/src/environment/index.ts
Original file line number Diff line number Diff line change
@@ -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;
};
8 changes: 4 additions & 4 deletions boxes/blank/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -45,7 +45,7 @@ if (typeof document !== 'undefined') {
export async function handleDeployClick(): Promise<string> {
// 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(),
Expand All @@ -60,7 +60,7 @@ export async function handleDeployClick(): Promise<string> {
// 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);
Expand Down Expand Up @@ -115,7 +115,7 @@ export async function callContractFunction(
* @returns
*/
export async function getWallet(account: CompleteAddress, pxe: PXE): Promise<AccountWallet> {
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.`);
Expand Down
14 changes: 2 additions & 12 deletions boxes/blank/src/tests/blank.contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;

Expand Down
11 changes: 11 additions & 0 deletions boxes/token/src/environment/index.ts
Original file line number Diff line number Diff line change
@@ -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;
};
4 changes: 2 additions & 2 deletions boxes/token/src/scripts/util.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -42,7 +42,7 @@ export function convertArgs(functionAbi: FunctionArtifact, args: any): Fr[] {
* @returns
*/
export async function getWallet(account: CompleteAddress, pxe: PXE): Promise<AccountWallet> {
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.`);
Expand Down
18 changes: 4 additions & 14 deletions boxes/token/src/tests/token.contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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())}`);
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/dev_docs/cli/blank_box.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/dev_docs/tutorials/uniswap/typescript_glue_code.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/dev_docs/tutorials/writing_dapp/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
computeMessageSecretHash,
createAccount,
createPXEClient,
waitForSandbox,
waitForPXE,
} from "@aztec/aztec.js";
import { TokenContractArtifact } from "@aztec/noir-contracts/Token";

Expand Down
Loading

0 comments on commit 158c5be

Please sign in to comment.