Skip to content

Commit

Permalink
chore: Refactor e2e test teardown (#2513)
Browse files Browse the repository at this point in the history
Removes the repeated teardown snippet that stopped the aztec node and
rpc server in favor of a callback returned by the `setup` method itself.
  • Loading branch information
spalladino authored Sep 26, 2023
1 parent fc00553 commit 2e43248
Show file tree
Hide file tree
Showing 26 changed files with 112 additions and 255 deletions.
11 changes: 4 additions & 7 deletions yarn-project/end-to-end/src/e2e_2_rpc_servers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('e2e_2_rpc_servers', () => {
let userA: CompleteAddress;
let userB: CompleteAddress;
let logger: DebugLogger;
let teardownA: () => Promise<void>;

beforeEach(async () => {
// this test can't be run against the sandbox as it requires 2 RPC servers
Expand All @@ -39,6 +40,7 @@ describe('e2e_2_rpc_servers', () => {
accounts,
wallets: [walletA],
logger,
teardown: teardownA,
} = await setup(1));
[userA] = accounts;

Expand All @@ -51,13 +53,8 @@ describe('e2e_2_rpc_servers', () => {
}, 100_000);

afterEach(async () => {
await aztecNode?.stop();
if (aztecRpcServerA instanceof AztecRPCServer) {
await aztecRpcServerA?.stop();
}
if (aztecRpcServerB instanceof AztecRPCServer) {
await aztecRpcServerB?.stop();
}
await teardownA();
if (aztecRpcServerB instanceof AztecRPCServer) await aztecRpcServerB.stop();
});

const awaitUserSynchronized = async (wallet: Wallet, owner: AztecAddress) => {
Expand Down
8 changes: 1 addition & 7 deletions yarn-project/end-to-end/src/e2e_account_contracts.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { AztecRPCServer } from '@aztec/aztec-rpc';
import {
AccountContract,
AccountManager,
Expand Down Expand Up @@ -45,12 +44,7 @@ function itShouldBehaveLikeAnAccountContract(
child = await ChildContract.deploy(wallet).send().deployed();
}, 60_000);

afterEach(async () => {
await context.aztecNode?.stop();
if (context.aztecRpcServer instanceof AztecRPCServer) {
await context.aztecRpcServer.stop();
}
});
afterEach(() => context.teardown());

it('calls a private function', async () => {
const { logger } = context;
Expand Down
23 changes: 6 additions & 17 deletions yarn-project/end-to-end/src/e2e_block_building.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { AztecNodeService } from '@aztec/aztec-node';
import { AztecRPCServer } from '@aztec/aztec-rpc';
import { BatchCall, ContractDeployer, Fr, Wallet, isContractDeployed } from '@aztec/aztec.js';
import { CircuitsWasm } from '@aztec/circuits.js';
import { pedersenPlookupCommitInputs } from '@aztec/circuits.js/barretenberg';
Expand All @@ -13,24 +11,19 @@ import times from 'lodash.times';
import { setup } from './fixtures/utils.js';

describe('e2e_block_building', () => {
let aztecNode: AztecNodeService | undefined;
let aztecRpcServer: AztecRPC;
let logger: DebugLogger;
let wallet: Wallet;
let teardown: () => Promise<void>;

describe('multi-txs block', () => {
const abi = TestContractAbi;

beforeAll(async () => {
({ aztecNode, aztecRpcServer, logger, wallet } = await setup(1));
({ teardown, aztecRpcServer, logger, wallet } = await setup(1));
}, 100_000);

afterAll(async () => {
await aztecNode?.stop();
if (aztecRpcServer instanceof AztecRPCServer) {
await aztecRpcServer?.stop();
}
});
afterAll(() => teardown());

it('assembles a block with multiple txs', async () => {
// Assemble N contract deployment txs
Expand Down Expand Up @@ -63,18 +56,14 @@ describe('e2e_block_building', () => {
// Regressions for https://github.com/AztecProtocol/aztec-packages/issues/2502
describe('double-spends on the same block', () => {
let contract: TestContract;
let teardown: () => Promise<void>;

beforeAll(async () => {
({ aztecNode, aztecRpcServer, logger, wallet } = await setup(1));
({ teardown, aztecRpcServer, logger, wallet } = await setup(1));
contract = await TestContract.deploy(wallet).send().deployed();
}, 100_000);

afterAll(async () => {
await aztecNode?.stop();
if (aztecRpcServer instanceof AztecRPCServer) {
await aztecRpcServer?.stop();
}
});
afterAll(() => teardown());

it('drops tx with private nullifier already emitted on the same block', async () => {
const nullifier = Fr.random();
Expand Down
13 changes: 3 additions & 10 deletions yarn-project/end-to-end/src/e2e_card_game.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { AztecNodeService } from '@aztec/aztec-node';
import { AztecRPCServer } from '@aztec/aztec-rpc';
import { AccountWallet, AztecAddress, Wallet, deployInitialSandboxAccounts } from '@aztec/aztec.js';
import { DebugLogger } from '@aztec/foundation/log';
import { CardGameContract } from '@aztec/noir-contracts/types';
Expand Down Expand Up @@ -46,9 +44,9 @@ function unwrapOptions<T>(options: NoirOption<T>[]): T[] {
const GAME_ID = 42;

describe('e2e_card_game', () => {
let aztecNode: AztecNodeService | undefined;
let aztecRpcServer: AztecRPC;
let logger: DebugLogger;
let teardown: () => Promise<void>;

let wallets: AccountWallet[];
let firstPlayerWallet: Wallet;
Expand All @@ -66,19 +64,14 @@ describe('e2e_card_game', () => {
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.
({ aztecNode, aztecRpcServer, logger } = await setup(0));
({ aztecRpcServer, logger, teardown } = await setup(0));
wallets = await Promise.all((await deployInitialSandboxAccounts(aztecRpcServer)).map(a => a.account.getWallet()));
[firstPlayerWallet, secondPlayerWallet, thirdPlayerWallet] = wallets;
[firstPlayer, secondPlayer, thirdPlayer] = wallets.map(a => a.getAddress());
await deployContract();
}, 100_000);

afterEach(async () => {
await aztecNode?.stop();
if (aztecRpcServer instanceof AztecRPCServer) {
await aztecRpcServer?.stop();
}
});
afterEach(() => teardown());

const deployContract = async () => {
logger(`Deploying L2 contract...`);
Expand Down
14 changes: 4 additions & 10 deletions yarn-project/end-to-end/src/e2e_cheat_codes.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AztecNodeService } from '@aztec/aztec-node';
import { AztecRPCServer, EthAddress } from '@aztec/aztec-rpc';
import { EthAddress } from '@aztec/aztec-rpc';
import { CheatCodes, Wallet } from '@aztec/aztec.js';
import { RollupAbi } from '@aztec/l1-artifacts';
import { TestContract } from '@aztec/noir-contracts/types';
Expand All @@ -10,30 +9,25 @@ import { Account, Chain, HttpTransport, PublicClient, WalletClient, getAddress,
import { setup } from './fixtures/utils.js';

describe('e2e_cheat_codes', () => {
let aztecNode: AztecNodeService | undefined;
let aztecRpcServer: AztecRPC;
let wallet: Wallet;
let cc: CheatCodes;
let teardown: () => Promise<void>;

let walletClient: WalletClient<HttpTransport, Chain, Account>;
let publicClient: PublicClient<HttpTransport, Chain>;
let rollupAddress: EthAddress;

beforeAll(async () => {
let deployL1ContractsValues;
({ aztecNode, aztecRpcServer, wallet, cheatCodes: cc, deployL1ContractsValues } = await setup());
({ teardown, aztecRpcServer, wallet, cheatCodes: cc, deployL1ContractsValues } = await setup());

walletClient = deployL1ContractsValues.walletClient;
publicClient = deployL1ContractsValues.publicClient;
rollupAddress = deployL1ContractsValues.rollupAddress;
}, 100_000);

afterAll(async () => {
await aztecNode?.stop();
if (aztecRpcServer instanceof AztecRPCServer) {
await aztecRpcServer?.stop();
}
});
afterAll(() => teardown());

describe('L1 only', () => {
describe('mine', () => {
Expand Down
20 changes: 8 additions & 12 deletions yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { AztecNodeService } from '@aztec/aztec-node';
import { AztecRPCServer } from '@aztec/aztec-rpc';
import { AccountWallet, AztecAddress } from '@aztec/aztec.js';
import { Fr, FunctionSelector } from '@aztec/circuits.js';
import { EthAddress } from '@aztec/foundation/eth-address';
import { DebugLogger } from '@aztec/foundation/log';
import { TokenBridgeContract, TokenContract } from '@aztec/noir-contracts/types';
import { AztecRPC, TxStatus } from '@aztec/types';
import { TxStatus } from '@aztec/types';

import { CrossChainTestHarness } from './fixtures/cross_chain_test_harness.js';
import { delay, hashPayload, setup } from './fixtures/utils.js';

describe('e2e_cross_chain_messaging', () => {
let aztecNode: AztecNodeService;
let aztecRpcServer: AztecRPC;
let logger: DebugLogger;
let teardown: () => Promise<void>;

let user1Wallet: AccountWallet;
let user2Wallet: AccountWallet;
Expand All @@ -28,16 +25,18 @@ describe('e2e_cross_chain_messaging', () => {
beforeEach(async () => {
const {
aztecNode,
aztecRpcServer: aztecRpcServer_,
aztecRpcServer,
deployL1ContractsValues,
accounts,
wallets,
logger: logger_,
cheatCodes,
teardown: teardown_,
} = await setup(2);

crossChainTestHarness = await CrossChainTestHarness.new(
aztecNode,
aztecRpcServer_,
aztecRpcServer,
deployL1ContractsValues,
accounts,
wallets[0],
Expand All @@ -50,18 +49,15 @@ describe('e2e_cross_chain_messaging', () => {
ethAccount = crossChainTestHarness.ethAccount;
ownerAddress = crossChainTestHarness.ownerAddress;
outbox = crossChainTestHarness.outbox;
aztecRpcServer = crossChainTestHarness.aztecRpcServer;
user1Wallet = wallets[0];
user2Wallet = wallets[1];
logger = logger_;
teardown = teardown_;
logger('Successfully deployed contracts and initialized portal');
}, 100_000);

afterEach(async () => {
await aztecNode?.stop();
if (aztecRpcServer instanceof AztecRPCServer) {
await aztecRpcServer?.stop();
}
await teardown();
await crossChainTestHarness?.stop();
});

Expand Down
13 changes: 3 additions & 10 deletions yarn-project/end-to-end/src/e2e_deploy_contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { AztecNodeService } from '@aztec/aztec-node';
import { AztecRPCServer } from '@aztec/aztec-rpc';
import { AztecAddress, Contract, ContractDeployer, Fr, Wallet, isContractDeployed } from '@aztec/aztec.js';
import { CompleteAddress, getContractDeploymentInfo } from '@aztec/circuits.js';
import { DebugLogger } from '@aztec/foundation/log';
Expand All @@ -9,22 +7,17 @@ import { AztecRPC, TxStatus } from '@aztec/types';
import { setup } from './fixtures/utils.js';

describe('e2e_deploy_contract', () => {
let aztecNode: AztecNodeService | undefined;
let aztecRpcServer: AztecRPC;
let accounts: CompleteAddress[];
let logger: DebugLogger;
let wallet: Wallet;
let teardown: () => Promise<void>;

beforeEach(async () => {
({ aztecNode, aztecRpcServer, accounts, logger, wallet } = await setup());
({ teardown, aztecRpcServer, accounts, logger, wallet } = await setup());
}, 100_000);

afterEach(async () => {
await aztecNode?.stop();
if (aztecRpcServer instanceof AztecRPCServer) {
await aztecRpcServer?.stop();
}
});
afterEach(() => teardown());

/**
* Milestone 1.1.
Expand Down
11 changes: 3 additions & 8 deletions yarn-project/end-to-end/src/e2e_escrow_contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { AztecNodeService } from '@aztec/aztec-node';
import { AztecRPCServer } from '@aztec/aztec-rpc';
import { AccountWallet, AztecAddress, BatchCall, computeMessageSecretHash, generatePublicKey } from '@aztec/aztec.js';
import { CompleteAddress, Fr, GrumpkinPrivateKey, GrumpkinScalar, getContractDeploymentInfo } from '@aztec/circuits.js';
import { DebugLogger } from '@aztec/foundation/log';
Expand All @@ -10,12 +8,12 @@ import { AztecRPC, PublicKey, TxStatus } from '@aztec/types';
import { setup } from './fixtures/utils.js';

describe('e2e_escrow_contract', () => {
let aztecNode: AztecNodeService | undefined;
let aztecRpcServer: AztecRPC;
let wallet: AccountWallet;
let recipientWallet: AccountWallet;
let accounts: CompleteAddress[];
let logger: DebugLogger;
let teardown: () => Promise<void>;

let token: TokenContract;
let escrowContract: EscrowContract;
Expand All @@ -28,7 +26,7 @@ describe('e2e_escrow_contract', () => {
beforeEach(async () => {
// Setup environment
({
aztecNode,
teardown,
aztecRpcServer,
accounts,
wallets: [wallet, recipientWallet],
Expand Down Expand Up @@ -66,10 +64,7 @@ describe('e2e_escrow_contract', () => {
logger(`Token contract deployed at ${token.address}`);
}, 100_000);

afterEach(async () => {
await aztecNode?.stop();
if (aztecRpcServer instanceof AztecRPCServer) await aztecRpcServer.stop();
}, 30_000);
afterEach(() => teardown(), 30_000);

const expectBalance = async (who: AztecAddress, expectedBalance: bigint) => {
const balance = await token.methods.balance_of_private(who).view({ from: who });
Expand Down
16 changes: 4 additions & 12 deletions yarn-project/end-to-end/src/e2e_lending_contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { AztecNodeService } from '@aztec/aztec-node';
import { AztecRPCServer } from '@aztec/aztec-rpc';
import { AccountWallet, CheatCodes, Fr, SentTx, computeMessageSecretHash } from '@aztec/aztec.js';
import { CircuitsWasm, CompleteAddress, FunctionSelector, GeneratorIndex } from '@aztec/circuits.js';
import { pedersenPlookupCompressWithHashIndex } from '@aztec/circuits.js/barretenberg';
import { DebugLogger } from '@aztec/foundation/log';
import { LendingContract, PriceFeedContract, TokenContract } from '@aztec/noir-contracts/types';
import { AztecRPC, TxStatus } from '@aztec/types';
import { TxStatus } from '@aztec/types';

import { jest } from '@jest/globals';

Expand All @@ -14,11 +12,10 @@ import { LendingAccount, LendingSimulator, TokenSimulator } from './simulators/i

describe('e2e_lending_contract', () => {
jest.setTimeout(100_000);
let aztecNode: AztecNodeService | undefined;
let aztecRpcServer: AztecRPC;
let wallet: AccountWallet;
let accounts: CompleteAddress[];
let logger: DebugLogger;
let teardown: () => Promise<void>;

let cc: CheatCodes;
const TIME_JUMP = 100;
Expand Down Expand Up @@ -81,7 +78,7 @@ describe('e2e_lending_contract', () => {
};

beforeAll(async () => {
({ aztecNode, aztecRpcServer, logger, cheatCodes: cc, wallet, accounts } = await setup(1));
({ teardown, logger, cheatCodes: cc, wallet, accounts } = await setup(1));
({ lendingContract, priceFeedContract, collateralAsset, stableCoin } = await deployContracts());

lendingAccount = new LendingAccount(accounts[0].address, new Fr(42));
Expand All @@ -98,12 +95,7 @@ describe('e2e_lending_contract', () => {
);
}, 200_000);

afterAll(async () => {
await aztecNode?.stop();
if (aztecRpcServer instanceof AztecRPCServer) {
await aztecRpcServer?.stop();
}
});
afterAll(() => teardown());

afterEach(async () => {
await lendingSim.check();
Expand Down
Loading

0 comments on commit 2e43248

Please sign in to comment.