Skip to content

Commit

Permalink
update tests to work locally as well
Browse files Browse the repository at this point in the history
  • Loading branch information
spypsy committed Oct 23, 2023
1 parent 2907005 commit f4c69e4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
19 changes: 17 additions & 2 deletions yarn-project/end-to-end/src/e2e_card_game.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { AccountWallet, AztecAddress, Wallet, getSandboxAccountsWallets } from '@aztec/aztec.js';
import {
AccountWallet,
AztecAddress,
Wallet,
deployInitialSandboxAccounts,
getSandboxAccountsWallets,
} from '@aztec/aztec.js';
import { DebugLogger } from '@aztec/foundation/log';
import { CardGameContract } from '@aztec/noir-contracts/types';
import { PXE } from '@aztec/types';
Expand All @@ -7,6 +13,8 @@ import { setup } from './fixtures/utils.js';

/* eslint-disable camelcase */

const { PXE_URL } = process.env;

interface Card {
points: bigint;
strength: bigint;
Expand Down Expand Up @@ -65,7 +73,14 @@ describe('e2e_card_game', () => {
// 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));
wallets = await getSandboxAccountsWallets(pxe);

// 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()));
}
[firstPlayerWallet, secondPlayerWallet, thirdPlayerWallet] = wallets;
[firstPlayer, secondPlayer, thirdPlayer] = wallets.map(a => a.getAddress());
await deployContract();
Expand Down
19 changes: 17 additions & 2 deletions yarn-project/end-to-end/src/e2e_cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
import { startHttpRpcServer } from '@aztec/aztec-sandbox';
import { PXE, createDebugLogger } from '@aztec/aztec.js';
import { createPXERpcServer } from '@aztec/pxe';

import { setup as e2eSetup } from './fixtures/utils.js';
import { cliTestSuite } from './shared/cli.js';

const { PXE_URL } = process.env;
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;
}

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}`);
}
return pxe;
};

const testCleanup = async () => {
http?.close();
await teardown();
};

cliTestSuite('E2E CLI Test', testSetup, testCleanup, createDebugLogger('aztec:e2e_cli'), PXE_URL);
cliTestSuite('E2E CLI Test', testSetup, testCleanup, createDebugLogger('aztec:e2e_cli'), RPC_URL);
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import {
import { Fr, GrumpkinScalar } from '@aztec/foundation/fields';
import { DebugLogger } from '@aztec/foundation/log';
import { TokenContract } from '@aztec/noir-contracts/types';
import { AztecNode, PXE, TxStatus } from '@aztec/types';
import { AztecNode, CompleteAddress, PXE, TxStatus } from '@aztec/types';

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;
Expand Down Expand Up @@ -45,12 +47,18 @@ describe('e2e_multiple_accounts_1_enc_key', () => {

// Verify that all accounts use the same encryption key
const encryptionPublicKey = await generatePublicKey(encryptionPrivateKey);

// Disregard sandbox accounts
const sandBoxWallets = await getSandboxAccountsWallets(pxe);
const allAccounts = await pxe.getRegisteredAccounts();
const keyAccounts = allAccounts.filter(
acc => !sandBoxWallets.map(wlt => wlt.getAddress().toString()).includes(acc.address.toString()),
);
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) {
expect(account.publicKey).toEqual(encryptionPublicKey);
}
Expand Down

0 comments on commit f4c69e4

Please sign in to comment.