Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Cleanup sandbox dependent tests #3861

Merged
merged 60 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
b93d531
Initial cleanup
PhilWindle Jan 5, 2024
db662e8
Formatting
PhilWindle Jan 5, 2024
7076ee6
Formatting
PhilWindle Jan 5, 2024
3453dce
Cleanup
PhilWindle Jan 5, 2024
a30be6a
Fixes
PhilWindle Jan 5, 2024
28a1ef5
Fixes
PhilWindle Jan 5, 2024
9231590
Extract accounts out of aztecjs into new package and update imports
spalladino Jan 4, 2024
e370f7b
Remove unneeded types in package.common
spalladino Jan 4, 2024
431f72b
Fix sample-dapp tests
spalladino Jan 5, 2024
ef4c2ba
Remove web build from accounts package
spalladino Jan 5, 2024
d8c2892
Build web package specific for e2e tests
spalladino Jan 5, 2024
3378e09
Fix package local json
spalladino Jan 5, 2024
695bccc
Order tsconfig refs
spalladino Jan 5, 2024
1b0a10b
Update readmes
spalladino Jan 5, 2024
b71c0e6
Format
spalladino Jan 5, 2024
88fb559
Fix links in docs
spalladino Jan 5, 2024
2774060
Update docs content
spalladino Jan 5, 2024
4504a69
Fix boxes and format
spalladino Jan 5, 2024
867350a
Remove unused web build entrypoint for account package
spalladino Jan 5, 2024
362f4d8
Add accounts api reference to docsite
spalladino Jan 5, 2024
b9bbe1f
Fixes
PhilWindle Jan 5, 2024
2d942fb
Fixes
PhilWindle Jan 5, 2024
74a2193
Fixes
PhilWindle Jan 5, 2024
6fb4248
Fix
PhilWindle Jan 5, 2024
e8c44ab
Fixes
PhilWindle Jan 5, 2024
74149e2
Fixes
PhilWindle Jan 6, 2024
ea1d635
Formatting
PhilWindle Jan 6, 2024
1896b72
More cleanup
PhilWindle Jan 8, 2024
796a6bd
More cleanup
PhilWindle Jan 8, 2024
940b161
More cleanup
PhilWindle Jan 8, 2024
d96bae8
Merge branch 'palla/accounts-out-of-aztecjs' into pw/cleanup-tests
PhilWindle Jan 8, 2024
c1c5a81
Merge cleanup
PhilWindle Jan 8, 2024
463c858
More cleanup
PhilWindle Jan 8, 2024
a1ac6bc
Merge branch 'master' into pw/cleanup-tests
PhilWindle Jan 8, 2024
8c00e6c
Formatting
PhilWindle Jan 8, 2024
74d179a
Removed debug comment
PhilWindle Jan 8, 2024
4c169f3
Fixes
PhilWindle Jan 8, 2024
2f38742
Merge branch 'master' into pw/cleanup-tests
PhilWindle Jan 8, 2024
848497c
Fixes
PhilWindle Jan 8, 2024
29a2aa7
Merge branch 'pw/cleanup-tests' of github.com:AztecProtocol/aztec-pac…
PhilWindle Jan 8, 2024
9247064
Formatting
PhilWindle Jan 8, 2024
2b01828
Fixes
PhilWindle Jan 8, 2024
53ecc7c
Formatting
PhilWindle Jan 8, 2024
2e7d550
Formatting
PhilWindle Jan 8, 2024
3f68a96
More cleanup
PhilWindle Jan 8, 2024
b5334bd
Fixes
PhilWindle Jan 8, 2024
c237ea1
Another fix
PhilWindle Jan 8, 2024
b54ec49
More cleanup
PhilWindle Jan 8, 2024
1881d06
Cleanup
PhilWindle Jan 8, 2024
0c3355c
Formatting
PhilWindle Jan 8, 2024
0d36628
Cleanup
PhilWindle Jan 8, 2024
b011582
Fixes
PhilWindle Jan 9, 2024
224c50b
More cleanup
PhilWindle Jan 9, 2024
7003e5a
Merge branch 'master' into pw/cleanup-tests
PhilWindle Jan 9, 2024
5a01b07
Formatting
PhilWindle Jan 9, 2024
df057ed
Fix
PhilWindle Jan 9, 2024
2cde2bd
Formatting
PhilWindle Jan 9, 2024
a3b13f1
Fixes
PhilWindle Jan 9, 2024
9a54b82
Formatting
PhilWindle Jan 9, 2024
bdaae06
Merge branch 'master' into pw/cleanup-tests
PhilWindle Jan 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,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 @@ -776,7 +776,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 @@ -1187,9 +1187,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 @@ -1223,9 +1223,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
25 changes: 25 additions & 0 deletions boxes/blank-react/src/sandbox/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { createPXEClient, PXE } from '@aztec/aztec.js';

const { PXE_URL = 'http://localhost:8080' } = process.env;

export const waitForSandbox = async (pxe?: PXE) => {
pxe = pxe ?? createPXEClient(PXE_URL);
while (true) {
try {
await pxe!.getNodeInfo();
return true;
} catch (error) {
await new Promise(resolve => {
setTimeout(resolve, 1000);
});
}
}
};

// assumes sandbox is running locally, which this script does not trigger
// as well as anvil. anvil can be started with yarn test:integration
export const setupSandbox = async () => {
const pxe = createPXEClient(PXE_URL);
await waitForSandbox(pxe);
return pxe;
};
12 changes: 1 addition & 11 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 { setupSandbox } from '../sandbox/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 Down
25 changes: 25 additions & 0 deletions boxes/blank/src/sandbox/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { createPXEClient, PXE } from '@aztec/aztec.js';

const { PXE_URL = 'http://localhost:8080' } = process.env;

export const waitForSandbox = async (pxe?: PXE) => {
pxe = pxe ?? createPXEClient(PXE_URL);
while (true) {
try {
await pxe!.getNodeInfo();
return true;
} catch (error) {
await new Promise(resolve => {
setTimeout(resolve, 1000);
});
}
}
};

// assumes sandbox is running locally, which this script does not trigger
// as well as anvil. anvil can be started with yarn test:integration
export const setupSandbox = async () => {
const pxe = createPXEClient(PXE_URL);
await waitForSandbox(pxe);
return pxe;
};
12 changes: 1 addition & 11 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 { setupSandbox } from '../sandbox/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 Down
25 changes: 25 additions & 0 deletions boxes/token/src/sandbox/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { createPXEClient, PXE } from '@aztec/aztec.js';

const { PXE_URL = 'http://localhost:8080' } = process.env;

export const waitForSandbox = async (pxe?: PXE) => {
pxe = pxe ?? createPXEClient(PXE_URL);
while (true) {
try {
await pxe!.getNodeInfo();
return true;
} catch (error) {
await new Promise(resolve => {
setTimeout(resolve, 1000);
});
}
}
};

// assumes sandbox is running locally, which this script does not trigger
// as well as anvil. anvil can be started with yarn test:integration
export const setupSandbox = async () => {
const pxe = createPXEClient(PXE_URL);
await waitForSandbox(pxe);
return pxe;
};
12 changes: 1 addition & 11 deletions boxes/token/src/tests/token.contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,10 @@ import {
computeAuthWitMessageHash,
computeMessageSecretHash,
createDebugLogger,
createPXEClient,
getSandboxAccountsWallets,
waitForSandbox,
} from '@aztec/aztec.js';
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 { setupSandbox } from '../sandbox/index.js';

const TIMEOUT = 60_000;

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export {

export { getSchnorrAccount, AccountManager, getUnsafeSchnorrAccount } from './account_manager/index.js';

export { waitForSandbox, getSandboxAccountsWallets, deployInitialSandboxAccounts } from './sandbox/index.js';
export { getSandboxAccountsWallets, deployInitialSandboxAccounts } from './sandbox/index.js';

export { AccountWalletWithPrivateKey, AccountWallet, Wallet, SignerlessWallet } from './wallet/index.js';

Expand Down
18 changes: 0 additions & 18 deletions yarn-project/aztec.js/src/sandbox/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Fr, GrumpkinScalar } from '@aztec/foundation/fields';
import { sleep } from '@aztec/foundation/sleep';
import { PXE } from '@aztec/types';

import { getSchnorrAccount } from '../account_manager/index.js';
import { createPXEClient } from '../pxe_client.js';
import { AccountWalletWithPrivateKey } from '../wallet/index.js';

export const INITIAL_SANDBOX_ENCRYPTION_KEYS = [
Expand Down Expand Up @@ -65,19 +63,3 @@ export async function deployInitialSandboxAccounts(pxe: PXE) {
);
return accounts;
}

/**
* 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);
}
}
}
Comment on lines -8 to -22
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about keeping this function but renaming it to waitForPXE..?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, just saw we have it but as part of the e2e utils. I think it makes sense to promote it to an util here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

34 changes: 17 additions & 17 deletions yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import { createDebugLogger, fileURLToPath } from '@aztec/aztec.js';
import { createPXERpcServer } 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 PXE_PORT = 3001;

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.
* To run the test, do the following:
* 1) Build the whole repository,
* 2) go to `yarn-project/aztec.js` 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'`,
* 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
* unexpectedly running in the background. Kill it with `killall chrome`
*/
const setupApp = () => {

const setupApp = async () => {
const { pxe: pxeService } = await setup(1);
let pxeURL = PXE_URL;
if (!PXE_URL) {
const pxeRPCServer = createPXERpcServer(pxeService);
pxeRPCServer.start(PXE_PORT);
pxeURL = `http://localhost:${PXE_PORT}`;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that PXE_URL here is the URL to a running instance of the pxe. So, if it's set, we shouldn't need to run setup, right?

Copy link
Collaborator Author

@PhilWindle PhilWindle Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setup also ensures you have the required number of accounts deployed (in this case, 1).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah you're right, I missed the if PXE_URL check within setup


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, pxeURL };
};

browserTestSuite(setupApp, pageLogger);
44 changes: 30 additions & 14 deletions yarn-project/end-to-end/src/e2e_card_game.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ import {
AccountWallet,
AztecAddress,
DebugLogger,
GrumpkinScalar,
PXE,
Wallet,
deployInitialSandboxAccounts,
getSandboxAccountsWallets,
generatePublicKey,
getSchnorrAccount,
} 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;
Expand Down Expand Up @@ -53,6 +52,12 @@ function unwrapOptions<T>(options: NoirOption<T>[]): T[] {

const GAME_ID = 42;

const ENCRYPTION_KEYS = [
GrumpkinScalar.fromString('2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281'),
GrumpkinScalar.fromString('aebd1b4be76efa44f5ee655c20bf9ea60f7ae44b9a7fd1fd9f189c7a0b0cdae'),
GrumpkinScalar.fromString('0f6addf0da06c33293df974a565b03d1ab096090d907d98055a8b7f4954e120c'),
];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the accounts PR I'm not exporting these from @aztec/accounts/testing. Maybe it makes sense to load that import, so we avoid duplicating these constants? I know the test would pass anyway, since they'd be automatically created, but it'd be slower.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


describe('e2e_card_game', () => {
let pxe: PXE;
let logger: DebugLogger;
Expand All @@ -72,17 +77,28 @@ describe('e2e_card_game', () => {
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()));
({ pxe, logger, teardown, wallets } = await setup(0));

const preRegisteredAccounts = await pxe.getRegisteredAccounts();

const toRegister = 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);
Comment on lines +90 to +95
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's not part of this PR, but should we do this in a beforeAll instead of a beforeEach to speed things up?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, yes.

}
logger('Account contracts deployed');

[firstPlayerWallet, secondPlayerWallet, thirdPlayerWallet] = wallets;
[firstPlayer, secondPlayer, thirdPlayer] = wallets.map(a => a.getAddress());
await deployContract();
Expand Down
15 changes: 3 additions & 12 deletions yarn-project/end-to-end/src/e2e_cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,18 @@ 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');

let http: ReturnType<typeof startHttpRpcServer>;
let pxe: PXE;
let teardown: () => Promise<void>;

// Use Sandbox PXE URL if we're running against sandbox
const { PXE_URL } = process.env;
if (PXE_URL) {
RPC_URL = PXE_URL;
}
Comment on lines -17 to -20
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this? I think it's useful to be able to run this suite against a running server, so we don't have to recreate it every time. And it's not like it assumes it's a sandbox: it just requires a pxe.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I realise the issues with the changes I made. Should be sorted now.


const testSetup = async () => {
const context = await e2eSetup(2);
debug(`Environment set up`);
({ pxe, teardown } = context);
if (!PXE_URL) {
http = startHttpRpcServer(pxe, createPXERpcServer, HTTP_PORT);
debug(`HTTP RPC server started in port ${HTTP_PORT}`);
}
http = startHttpRpcServer(pxe, createPXERpcServer, HTTP_PORT);
debug(`HTTP RPC server started in port ${HTTP_PORT}`);
return pxe;
};

Expand All @@ -35,4 +26,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'));
Loading
Loading