Skip to content

Commit 280c5f5

Browse files
authored
refactor: un-exposing PXE from e2e tests (#17163)
e2e tests should interact only with a wallet (and maybe a node) because PXE is becoming only a lib used by a wallet. This PR is a step in that direction. # Followup work 1. Drop PXE JSON RPC server, 2. have Wallet instantiate PXE instead of having it passed in as an arg to a constructor, 3. revisit the PXE methods exposed on the TestWallet.
2 parents 6d45a1b + 6456144 commit 280c5f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+384
-517
lines changed

yarn-project/accounts/src/testing/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import {
1818
} from './configuration.js';
1919

2020
export {
21-
type InitialAccountData,
2221
INITIAL_TEST_ACCOUNT_SALTS,
2322
INITIAL_TEST_ENCRYPTION_KEYS,
2423
INITIAL_TEST_SECRET_KEYS,
2524
INITIAL_TEST_SIGNING_KEYS,
25+
type InitialAccountData,
2626
} from './configuration.js';
2727

2828
/**
@@ -45,10 +45,11 @@ export function getInitialTestAccountsData(): Promise<InitialAccountData[]> {
4545

4646
/**
4747
* Queries a PXE for it's registered accounts.
48-
* @param pxe - PXE instance.
48+
* @param testWalletOrPxe - Test wallet or pxe instance to use to get the registered accounts.
4949
* @returns A set of key data for each of the initial accounts.
5050
*/
51-
export async function getDeployedTestAccounts(pxe: PXE): Promise<InitialAccountData[]> {
51+
export async function getDeployedTestAccounts(testWalletOrPxe: { getPxe(): PXE } | PXE): Promise<InitialAccountData[]> {
52+
const pxe = 'getPxe' in testWalletOrPxe ? testWalletOrPxe.getPxe() : testWalletOrPxe;
5253
const registeredAccounts = await pxe.getRegisteredAccounts();
5354
const testAccounts = await getInitialTestAccountsData();
5455
return testAccounts.filter(t => registeredAccounts.some(r => r.address.equals(t.address)));

yarn-project/aztec/src/cli/aztec_start_action.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
6363
const { startBlobSink } = await import('./cmds/start_blob_sink.js');
6464
await startBlobSink(options, signalHandlers, userLog);
6565
} else if (options.pxe) {
66-
const { startPXE } = await import('./cmds/start_pxe.js');
67-
({ config } = await startPXE(options, signalHandlers, services, userLog));
66+
const { startPXEServiceGetWallet } = await import('./cmds/start_pxe.js');
67+
({ config } = await startPXEServiceGetWallet(options, services, userLog));
6868
} else if (options.archiver) {
6969
const { startArchiver } = await import('./cmds/start_archiver.js');
7070
({ config } = await startArchiver(options, signalHandlers, services));

yarn-project/aztec/src/cli/cmds/start_bot.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { type BotConfig, BotRunner, botConfigMappings, getBotRunnerApiHandler } from '@aztec/bot';
22
import type { NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server';
33
import type { LogFn } from '@aztec/foundation/log';
4-
import { type AztecNode, type PXE, createAztecNodeClient } from '@aztec/stdlib/interfaces/client';
4+
import { type AztecNode, type AztecNodeAdmin, createAztecNodeClient } from '@aztec/stdlib/interfaces/client';
55
import type { TelemetryClient } from '@aztec/telemetry-client';
66
import {
77
getConfigEnvVars as getTelemetryClientConfig,
88
initTelemetryClient,
99
makeTracedFetch,
1010
} from '@aztec/telemetry-client';
11+
import { TestWallet } from '@aztec/test-wallet';
1112

1213
import { extractRelevantOptions } from '../util.js';
1314
import { getVersions } from '../versioning.js';
@@ -32,28 +33,28 @@ export async function startBot(
3233
throw new Error('The bot requires access to a Node');
3334
}
3435

35-
const node = createAztecNodeClient(config.nodeUrl, getVersions(), fetch);
36+
const aztecNode = createAztecNodeClient(config.nodeUrl, getVersions(), fetch);
3637

37-
// Start a PXE client that is used by the bot if required
38-
let pxe: PXE | undefined;
39-
if (options.pxe) {
40-
const { addPXE } = await import('./start_pxe.js');
41-
({ pxe } = await addPXE(options, signalHandlers, services, userLog, { node }));
42-
}
38+
// Start a PXE client and get a wallet that is used by the bot if required
39+
const { startPXEServiceGetWallet } = await import('./start_pxe.js');
40+
const { wallet } = await startPXEServiceGetWallet(options, services, userLog, { node: aztecNode });
4341

4442
const telemetry = initTelemetryClient(getTelemetryClientConfig());
45-
await addBot(options, signalHandlers, services, { pxe, telemetry, node });
43+
await addBot(options, signalHandlers, services, wallet, aztecNode, telemetry, undefined);
4644
}
4745

4846
export function addBot(
4947
options: any,
5048
signalHandlers: (() => Promise<void>)[],
5149
services: NamespacedApiHandlers,
52-
deps: { pxe?: PXE; node?: AztecNode; telemetry: TelemetryClient },
50+
wallet: TestWallet,
51+
aztecNode: AztecNode,
52+
telemetry: TelemetryClient,
53+
aztecNodeAdmin?: AztecNodeAdmin,
5354
) {
5455
const config = extractRelevantOptions<BotConfig>(options, botConfigMappings, 'bot');
5556

56-
const botRunner = new BotRunner(config, deps);
57+
const botRunner = new BotRunner(config, wallet, aztecNode, telemetry, aztecNodeAdmin);
5758
if (!config.noStart) {
5859
void botRunner.start(); // Do not block since bot setup takes time
5960
}

yarn-project/aztec/src/cli/cmds/start_node.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { getPublicClient } from '@aztec/ethereum';
77
import { SecretValue } from '@aztec/foundation/config';
88
import type { NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server';
99
import type { LogFn } from '@aztec/foundation/log';
10-
import { AztecNodeAdminApiSchema, AztecNodeApiSchema, type PXE } from '@aztec/stdlib/interfaces/client';
10+
import { AztecNodeAdminApiSchema, AztecNodeApiSchema } from '@aztec/stdlib/interfaces/client';
1111
import { P2PApiSchema } from '@aztec/stdlib/interfaces/server';
1212
import {
1313
type TelemetryClientConfig,
@@ -128,17 +128,13 @@ export async function startNode(
128128
// Add node stop function to signal handlers
129129
signalHandlers.push(node.stop.bind(node));
130130

131-
// Add a PXE client that connects to this node if requested
132-
let pxe: PXE | undefined;
133-
if (options.pxe) {
134-
const { addPXE } = await import('./start_pxe.js');
135-
({ pxe } = await addPXE(options, signalHandlers, services, userLog, { node }));
136-
}
137-
138131
// Add a txs bot if requested
139132
if (options.bot) {
140133
const { addBot } = await import('./start_bot.js');
141-
await addBot(options, signalHandlers, services, { pxe, node, telemetry });
134+
const { startPXEServiceGetWallet } = await import('./start_pxe.js');
135+
const { wallet } = await startPXEServiceGetWallet(options, services, userLog, { node });
136+
137+
await addBot(options, signalHandlers, services, wallet, node, telemetry, undefined);
142138
}
143139

144140
if (nodeConfig.autoUpdate !== 'disabled' && nodeConfig.autoUpdateUrl) {
Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,21 @@
11
import type { NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server';
22
import type { LogFn } from '@aztec/foundation/log';
3-
import {
4-
type CliPXEOptions,
5-
type PXEService,
6-
type PXEServiceConfig,
7-
allPxeConfigMappings,
8-
createPXEService,
9-
} from '@aztec/pxe/server';
3+
import { type CliPXEOptions, type PXEServiceConfig, allPxeConfigMappings, createPXEService } from '@aztec/pxe/server';
104
import { type AztecNode, PXESchema, createAztecNodeClient } from '@aztec/stdlib/interfaces/client';
115
import { makeTracedFetch } from '@aztec/telemetry-client';
6+
import { TestWallet } from '@aztec/test-wallet';
127

138
import { extractRelevantOptions } from '../util.js';
149
import { getVersions } from '../versioning.js';
1510

16-
export type { PXEServiceConfig, CliPXEOptions };
11+
export type { CliPXEOptions, PXEServiceConfig };
1712

18-
export async function startPXE(
13+
export async function startPXEServiceGetWallet(
1914
options: any,
20-
signalHandlers: (() => Promise<void>)[],
21-
services: NamespacedApiHandlers,
22-
userLog: LogFn,
23-
): Promise<{ pxe: PXEService; config: PXEServiceConfig & CliPXEOptions }> {
24-
return await addPXE(options, signalHandlers, services, userLog, {});
25-
}
26-
27-
export async function addPXE(
28-
options: any,
29-
_signalHandlers: (() => Promise<void>)[],
3015
services: NamespacedApiHandlers,
3116
userLog: LogFn,
3217
deps: { node?: AztecNode } = {},
33-
): Promise<{ pxe: PXEService; config: PXEServiceConfig & CliPXEOptions }> {
18+
): Promise<{ wallet: TestWallet; config: PXEServiceConfig & CliPXEOptions }> {
3419
const pxeConfig = extractRelevantOptions<PXEServiceConfig & CliPXEOptions>(options, allPxeConfigMappings, 'pxe');
3520
const nodeUrl = pxeConfig.nodeUrl;
3621

@@ -42,8 +27,10 @@ export async function addPXE(
4227
const node = deps.node ?? createAztecNodeClient(nodeUrl!, getVersions(pxeConfig), makeTracedFetch([1, 2, 3], true));
4328
const pxe = await createPXEService(node, pxeConfig as PXEServiceConfig);
4429

30+
const wallet = new TestWallet(pxe, node);
31+
4532
// Add PXE to services list
4633
services.pxe = [pxe, PXESchema];
4734

48-
return { pxe, config: pxeConfig };
35+
return { wallet, config: pxeConfig };
4936
}

yarn-project/aztec/src/examples/token.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const TRANSFER_AMOUNT = 33n;
2222
async function main() {
2323
logger.info('Running token contract test on HTTP interface.');
2424

25-
const accounts = await getDeployedTestAccounts(pxe);
25+
const accounts = await getDeployedTestAccounts(wallet);
2626
const [alice, bob] = await Promise.all(
2727
accounts.map(async acc => {
2828
const accountManager = await wallet.createSchnorrAccount(acc.secret, acc.salt);

yarn-project/aztec/src/sandbox/banana_fpc.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { FPCContract } from '@aztec/noir-contracts.js/FPC';
66
import { TokenContract } from '@aztec/noir-contracts.js/Token';
77
import { AztecAddress } from '@aztec/stdlib/aztec-address';
88
import { type ContractInstanceWithAddress, getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
9-
import type { PXE } from '@aztec/stdlib/interfaces/client';
9+
import type { TestWallet } from '@aztec/test-wallet';
1010

1111
const BANANA_COIN_SALT = new Fr(0);
1212
const bananaCoinArgs = {
@@ -62,20 +62,20 @@ export async function setupBananaFPC(initialAccounts: InitialAccountData[], wall
6262
log(`FPC: ${fpc.address}`);
6363
}
6464

65-
export async function getDeployedBananaCoinAddress(pxe: PXE) {
65+
export async function getDeployedBananaCoinAddress(wallet: TestWallet) {
6666
const initialAccounts = await getInitialTestAccountsData();
6767
const bananaCoin = await getBananaCoinAddress(initialAccounts);
68-
const contracts = await pxe.getContracts();
68+
const contracts = await wallet.getContracts();
6969
if (!contracts.find(c => c.equals(bananaCoin))) {
7070
throw new Error('BananaCoin not deployed.');
7171
}
7272
return bananaCoin;
7373
}
7474

75-
export async function getDeployedBananaFPCAddress(pxe: PXE) {
75+
export async function getDeployedBananaFPCAddress(wallet: TestWallet) {
7676
const initialAccounts = await getInitialTestAccountsData();
7777
const fpc = await getBananaFPCInstance(initialAccounts);
78-
const contracts = await pxe.getContracts();
78+
const contracts = await wallet.getContracts();
7979
if (!contracts.find(c => c.equals(fpc.address))) {
8080
throw new Error('BananaFPC not deployed.');
8181
}

yarn-project/aztec/src/sandbox/sponsored_fpc.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import {
2-
type ContractInstanceWithAddress,
3-
Fr,
4-
type PXE,
5-
getContractInstanceFromInstantiationParams,
6-
} from '@aztec/aztec.js';
1+
import { type ContractInstanceWithAddress, Fr, getContractInstanceFromInstantiationParams } from '@aztec/aztec.js';
72
import { SPONSORED_FPC_SALT } from '@aztec/constants';
83
import { SponsoredFPCContract } from '@aztec/noir-contracts.js/SponsoredFPC';
4+
import type { TestWallet } from '@aztec/test-wallet';
95

106
async function getSponsoredFPCInstance(): Promise<ContractInstanceWithAddress> {
117
return await getContractInstanceFromInstantiationParams(SponsoredFPCContract.artifact, {
@@ -17,9 +13,9 @@ export async function getSponsoredFPCAddress() {
1713
return (await getSponsoredFPCInstance()).address;
1814
}
1915

20-
export async function getDeployedSponsoredFPCAddress(pxe: PXE) {
16+
export async function getDeployedSponsoredFPCAddress(wallet: TestWallet) {
2117
const fpc = await getSponsoredFPCAddress();
22-
const contracts = await pxe.getContracts();
18+
const contracts = await wallet.getContracts();
2319
if (!contracts.find(c => c.equals(fpc))) {
2420
throw new Error('SponsoredFPC not deployed.');
2521
}

yarn-project/aztec/src/testing/aztec_cheat_codes.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import { Fr } from '@aztec/foundation/fields';
22
import { createLogger } from '@aztec/foundation/log';
33
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
44
import { deriveStorageSlotInMap } from '@aztec/stdlib/hash';
5-
import type { AztecNode, PXE } from '@aztec/stdlib/interfaces/client';
6-
import type { Note } from '@aztec/stdlib/note';
5+
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
6+
import type { Note, NotesFilter, UniqueNote } from '@aztec/stdlib/note';
77

88
/**
99
* A class that provides utility functions for interacting with the aztec chain.
1010
*/
1111
export class AztecCheatCodes {
1212
constructor(
1313
/**
14-
* The PXE Service to use for interacting with the chain
14+
* The test wallet or pxe to use for getting notes
1515
*/
16-
public pxe: PXE,
16+
public testWalletOrPxe: { getNotes(filter: NotesFilter): Promise<UniqueNote[]> },
1717
/**
1818
* The Aztec Node to use for interacting with the chain
1919
*/
@@ -71,7 +71,7 @@ export class AztecCheatCodes {
7171
* @returns The notes stored at the given slot
7272
*/
7373
public async loadPrivate(recipient: AztecAddress, contract: AztecAddress, slot: Fr | bigint): Promise<Note[]> {
74-
const extendedNotes = await this.pxe.getNotes({
74+
const extendedNotes = await this.testWalletOrPxe.getNotes({
7575
recipient,
7676
contractAddress: contract,
7777
storageSlot: new Fr(slot),

yarn-project/aztec/src/testing/cheat_codes.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { retryUntil } from '@aztec/aztec.js';
22
import { EthCheatCodes, RollupCheatCodes } from '@aztec/ethereum/test';
33
import type { SequencerClient } from '@aztec/sequencer-client';
4-
import type { AztecNode, PXE } from '@aztec/stdlib/interfaces/client';
4+
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
5+
import type { NotesFilter, UniqueNote } from '@aztec/stdlib/note';
56

67
import { AztecCheatCodes } from './aztec_cheat_codes.js';
78

@@ -18,9 +19,13 @@ export class CheatCodes {
1819
public rollup: RollupCheatCodes,
1920
) {}
2021

21-
static async create(rpcUrls: string[], pxe: PXE, node: AztecNode): Promise<CheatCodes> {
22+
static async create(
23+
rpcUrls: string[],
24+
testWalletOrPxe: { getNotes(filter: NotesFilter): Promise<UniqueNote[]> },
25+
node: AztecNode,
26+
): Promise<CheatCodes> {
2227
const ethCheatCodes = new EthCheatCodes(rpcUrls);
23-
const aztecCheatCodes = new AztecCheatCodes(pxe, node);
28+
const aztecCheatCodes = new AztecCheatCodes(testWalletOrPxe, node);
2429
const rollupCheatCodes = new RollupCheatCodes(
2530
ethCheatCodes,
2631
await node.getNodeInfo().then(n => n.l1ContractAddresses),

0 commit comments

Comments
 (0)