Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Oct 2, 2023
1 parent e8d68fb commit 9dc1588
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 49 deletions.
4 changes: 2 additions & 2 deletions yarn-project/canary/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
},
"references": [
{
"path": "../circuits.js"
"path": "../aztec.js"
},
{
"path": "../aztec.js"
"path": "../circuits.js"
},
{
"path": "../cli"
Expand Down
10 changes: 4 additions & 6 deletions yarn-project/end-to-end/src/e2e_cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { AztecNodeService } from '@aztec/aztec-node';
import { startHttpRpcServer } from '@aztec/aztec-sandbox';
import { PXE, createDebugLogger } from '@aztec/aztec.js';
import { PXEService, createPXERpcServer } from '@aztec/pxe';
import { createPXERpcServer } from '@aztec/pxe';

import { cliTestSuite } from './canary/cli.js';
import { setup as e2eSetup } from './fixtures/utils.js';
Expand All @@ -11,22 +10,21 @@ const RPC_URL = `http://localhost:${HTTP_PORT}`;
const debug = createDebugLogger('aztec:e2e_cli');

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

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

const testCleanup = async () => {
http.close();
await aztecNode?.stop();
await (pxe as PXEService).stop();
await teardown();
};

cliTestSuite('E2E CLI Test', testSetup, testCleanup, createDebugLogger('aztec:e2e_cli'), RPC_URL);
5 changes: 2 additions & 3 deletions yarn-project/end-to-end/src/e2e_multi_transfer.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { AztecNodeService } from '@aztec/aztec-node';
import { AztecAddress, Contract, Wallet } from '@aztec/aztec.js';
import { DebugLogger } from '@aztec/foundation/log';
import { MultiTransferContract, PrivateTokenAirdropContract } from '@aztec/noir-contracts/types';
import { CompleteAddress } from '@aztec/types';
import { AztecNode, CompleteAddress } from '@aztec/types';

import { expectsNumOfEncryptedLogsInTheLastBlockToBe, setup } from './fixtures/utils.js';

Expand All @@ -14,7 +13,7 @@ import { expectsNumOfEncryptedLogsInTheLastBlockToBe, setup } from './fixtures/u
describe('multi-transfer payments', () => {
const numberOfAccounts = 12;

let aztecNode: AztecNodeService | undefined;
let aztecNode: AztecNode | undefined;
let wallet: Wallet;
let logger: DebugLogger;
let teardown: () => Promise<void>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { AztecNodeService } from '@aztec/aztec-node';
import { AztecAddress, Wallet, computeMessageSecretHash, generatePublicKey, getSchnorrAccount } from '@aztec/aztec.js';
import { Fr, GrumpkinScalar } from '@aztec/circuits.js';
import { DebugLogger } from '@aztec/foundation/log';
import { TokenContract } from '@aztec/noir-contracts/types';
import { PXE, TxStatus } from '@aztec/types';
import { AztecNode, PXE, TxStatus } from '@aztec/types';

import { expectsNumOfEncryptedLogsInTheLastBlockToBe, setup } from './fixtures/utils.js';

describe('e2e_multiple_accounts_1_enc_key', () => {
let aztecNode: AztecNodeService | undefined;
let aztecNode: AztecNode | undefined;
let pxe: PXE;
const wallets: Wallet[] = [];
const accounts: AztecAddress[] = [];
Expand Down
5 changes: 2 additions & 3 deletions yarn-project/end-to-end/src/e2e_non_contract_account.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { AztecNodeService } from '@aztec/aztec-node';
import { AztecAddress, SignerlessWallet, Wallet } from '@aztec/aztec.js';
import { DebugLogger } from '@aztec/foundation/log';
import { PokeableTokenContract } from '@aztec/noir-contracts/types';
import { CompleteAddress, PXE, TxStatus } from '@aztec/types';
import { AztecNode, CompleteAddress, PXE, TxStatus } from '@aztec/types';

import { expectsNumOfEncryptedLogsInTheLastBlockToBe, setup } from './fixtures/utils.js';

describe('e2e_non_contract_account', () => {
let aztecNode: AztecNodeService | undefined;
let aztecNode: AztecNode | undefined;
let pxe: PXE;
let wallet: Wallet;
let sender: AztecAddress;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { AztecNodeService } from '@aztec/aztec-node';
import { AztecAddress, Fr, Wallet } from '@aztec/aztec.js';
import { DebugLogger } from '@aztec/foundation/log';
import { PendingCommitmentsContract } from '@aztec/noir-contracts/types';
import { CompleteAddress, TxStatus } from '@aztec/types';
import { AztecNode, CompleteAddress, TxStatus } from '@aztec/types';

import { setup } from './fixtures/utils.js';

describe('e2e_pending_commitments_contract', () => {
let aztecNode: AztecNodeService | undefined;
let aztecNode: AztecNode | undefined;
let wallet: Wallet;
let logger: DebugLogger;
let owner: AztecAddress;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { AztecNodeService } from '@aztec/aztec-node';
import { AztecAddress, Wallet } from '@aztec/aztec.js';
import { DebugLogger } from '@aztec/foundation/log';
import { PrivateTokenContract } from '@aztec/noir-contracts/types';
import { CompleteAddress, TxStatus } from '@aztec/types';
import { AztecNode, CompleteAddress, TxStatus } from '@aztec/types';

import { expectsNumOfEncryptedLogsInTheLastBlockToBe, setup } from './fixtures/utils.js';

describe('e2e_private_token_contract', () => {
let aztecNode: AztecNodeService | undefined;
let aztecNode: AztecNode | undefined;
let wallet: Wallet;
let logger: DebugLogger;
let owner: AztecAddress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { DebugLogger } from '@aztec/foundation/log';
import { OutboxAbi } from '@aztec/l1-artifacts';
import { TokenBridgeContract, TokenContract } from '@aztec/noir-contracts/types';
import { PXEService } from '@aztec/pxe';
import { PXE, TxStatus } from '@aztec/types';
import { AztecNode, PXE, TxStatus } from '@aztec/types';

import { Chain, HttpTransport, PublicClient, getContract } from 'viem';

Expand All @@ -20,7 +20,7 @@ import { deployAndInitializeTokenAndBridgeContracts } from './utils.js';
*/
export class CrossChainTestHarness {
static async new(
aztecNode: AztecNodeService | undefined,
aztecNode: AztecNode | undefined,
pxeService: PXE,
deployL1ContractsValues: DeployL1Contracts,
accounts: CompleteAddress[],
Expand Down Expand Up @@ -89,7 +89,7 @@ export class CrossChainTestHarness {
}
constructor(
/** AztecNode. */
public aztecNode: AztecNodeService | undefined,
public aztecNode: AztecNode | undefined,
/** Private eXecution Environment (PXE). */
public pxeService: PXE,
/** CheatCodes. */
Expand Down Expand Up @@ -338,7 +338,7 @@ export class CrossChainTestHarness {
}

async stop() {
await this.aztecNode?.stop();
if (this.aztecNode instanceof AztecNodeService) await this.aztecNode?.stop();
if (this.pxeService instanceof PXEService) {
await this.pxeService?.stop();
}
Expand Down
39 changes: 19 additions & 20 deletions yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
EthCheatCodes,
Wallet,
createAccounts,
createPXEClient as createJsonRpcClient,
createPXEClient,
getSandboxAccountsWallets,
} from '@aztec/aztec.js';
import { CircuitsWasm, GeneratorIndex } from '@aztec/circuits.js';
Expand Down Expand Up @@ -42,7 +42,7 @@ import {
} from '@aztec/l1-artifacts';
import { NonNativeTokenContract, TokenBridgeContract, TokenContract } from '@aztec/noir-contracts/types';
import { PXEService, createPXEService, getPXEServiceConfig } from '@aztec/pxe';
import { L2BlockL2Logs, LogType, PXE, TxStatus } from '@aztec/types';
import { AztecNode, L2BlockL2Logs, LogType, PXE, TxStatus, createAztecNodeRpcClient } from '@aztec/types';

import {
Account,
Expand Down Expand Up @@ -76,10 +76,7 @@ export const waitForPXE = async (pxe: PXE, logger: DebugLogger) => {
}, 'RPC Get Node Info');
};

const createAztecNode = async (
nodeConfig: AztecNodeConfig,
logger: DebugLogger,
): Promise<AztecNodeService | undefined> => {
const createAztecNode = async (nodeConfig: AztecNodeConfig, logger: DebugLogger): Promise<AztecNode | undefined> => {
if (SANDBOX_URL) {
logger(`Not creating Aztec Node as we are running against a sandbox at ${SANDBOX_URL}`);
return undefined;
Expand Down Expand Up @@ -136,7 +133,7 @@ export const setupL1Contracts = async (
*/
export async function setupPXEService(
numberOfAccounts: number,
aztecNode: AztecNodeService,
aztecNode: AztecNode,
logger = getLogger(),
useLogSuffix = false,
): Promise<{
Expand Down Expand Up @@ -175,18 +172,20 @@ export async function setupPXEService(
* @param account - The account for use in create viem wallets.
* @param config - The aztec Node Configuration
* @param logger - The logger to be used
* @returns Private eXecution Environment (PXE) client, viem wallets, contract addreses etc.
* @returns Private eXecution Environment (PXE) client, viem wallets, contract addresses etc.
*/
async function setupWithSandbox(account: Account, config: AztecNodeConfig, logger: DebugLogger) {
// we are setting up against the sandbox, l1 contracts are already deployed
logger(`Creating JSON RPC client to remote host ${SANDBOX_URL}`);
const jsonClient = createJsonRpcClient(SANDBOX_URL);
await waitForPXE(jsonClient, logger);
logger(`Creating Aztec Node client to remote host ${SANDBOX_URL}`);
const aztecNode = createAztecNodeRpcClient('http://localhost:8079');
logger(`Creating PXE client to remote host ${SANDBOX_URL}`);
const pxeClient = createPXEClient(SANDBOX_URL);
await waitForPXE(pxeClient, logger);
logger('JSON RPC client connected to PXE');
logger(`Retrieving contract addresses from ${SANDBOX_URL}`);
const l1Contracts = (await jsonClient.getNodeInfo()).l1ContractAddresses;
const l1Contracts = (await pxeClient.getNodeInfo()).l1ContractAddresses;
logger('PXE created, constructing wallets from initial sandbox accounts...');
const wallets = await getSandboxAccountsWallets(jsonClient);
const wallets = await getSandboxAccountsWallets(pxeClient);

const walletClient = createWalletClient<HttpTransport, Chain, HDAccount>({
account,
Expand All @@ -202,13 +201,13 @@ async function setupWithSandbox(account: Account, config: AztecNodeConfig, logge
walletClient,
publicClient,
};
const cheatCodes = await CheatCodes.create(config.rpcUrl, jsonClient!);
const cheatCodes = await CheatCodes.create(config.rpcUrl, pxeClient!);
const teardown = () => Promise.resolve();
return {
aztecNode: undefined,
pxe: jsonClient,
aztecNode,
pxe: pxeClient,
deployL1ContractsValues,
accounts: await jsonClient!.getRegisteredAccounts(),
accounts: await pxeClient!.getRegisteredAccounts(),
config,
wallet: wallets[0],
wallets,
Expand All @@ -229,7 +228,7 @@ export async function setup(
/**
* The Aztec Node service.
*/
aztecNode: AztecNodeService | undefined;
aztecNode: AztecNode | undefined;
/**
* The Private eXecution Environment (PXE).
*/
Expand Down Expand Up @@ -300,7 +299,7 @@ export async function setup(
const cheatCodes = await CheatCodes.create(config.rpcUrl, pxe!);

const teardown = async () => {
await aztecNode?.stop();
if (aztecNode instanceof AztecNodeService) await aztecNode?.stop();
if (pxe instanceof PXEService) await pxe?.stop();
};

Expand Down Expand Up @@ -528,7 +527,7 @@ export function delay(ms: number): Promise<void> {
* @param numEncryptedLogs - The number of expected logs.
*/
export const expectsNumOfEncryptedLogsInTheLastBlockToBe = async (
aztecNode: AztecNodeService | undefined,
aztecNode: AztecNode | undefined,
numEncryptedLogs: number,
) => {
if (!aztecNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { EthAddress } from '@aztec/foundation/eth-address';
import { DebugLogger } from '@aztec/foundation/log';
import { UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts';
import { UniswapContract } from '@aztec/noir-contracts/types';
import { PXE, TxStatus } from '@aztec/types';
import { AztecNode, PXE, TxStatus } from '@aztec/types';

import { getContract, parseEther } from 'viem';

Expand All @@ -31,7 +31,7 @@ describe('uniswap_trade_on_l1_from_l2', () => {
const WETH9_ADDRESS: EthAddress = EthAddress.fromString('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2');
const DAI_ADDRESS: EthAddress = EthAddress.fromString('0x6B175474E89094C44Da98b954EedeAC495271d0F');

let aztecNode: AztecNodeService | undefined;
let aztecNode: AztecNode | undefined;
let pxe: PXE;
let logger: DebugLogger;
let teardown: () => Promise<void>;
Expand Down

0 comments on commit 9dc1588

Please sign in to comment.