Skip to content

refactor: un-exposing PXE from e2e tests#17163

Merged
benesjan merged 1 commit intonextfrom
09-19-refactor_un-exposing_pxe_from_e2e_tests
Sep 22, 2025
Merged

refactor: un-exposing PXE from e2e tests#17163
benesjan merged 1 commit intonextfrom
09-19-refactor_un-exposing_pxe_from_e2e_tests

Conversation

@benesjan
Copy link
Contributor

@benesjan benesjan commented Sep 19, 2025

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.

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@benesjan benesjan marked this pull request as ready for review September 19, 2025 14:18
@benesjan benesjan marked this pull request as draft September 22, 2025 07:35
export type { CliPXEOptions, PXEServiceConfig };

export async function startPXE(
export async function startPXEServicesGetWallet(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We now always just used the pxe to instantiate a test wallet so I just return a wallet from this function. This will get nuked in a followup PR when PXE will stop being a service.

Comment on lines -44 to -77
dependencies: { pxe?: PXE; nodeAdmin?: AztecNodeAdmin; node?: AztecNode },
) {
if (config.flushSetupTransactions && !dependencies.nodeAdmin) {
throw new Error(
`Either a node admin client or node admin url must be provided if transaction flushing is requested`,
);
}
if (config.senderPrivateKey && config.senderPrivateKey.getValue() && !dependencies.node) {
throw new Error(
`Either a node client or node url must be provided for bridging L1 fee juice to deploy an account with private key`,
);
}
if (!dependencies.pxe && !config.pxeUrl) {
throw new Error(`Either a PXE client or a PXE URL must be provided`);
}

this.nodeAdmin = dependencies.nodeAdmin;

if (dependencies.pxe) {
this.log.info(`Using local PXE`);
this.pxe = dependencies.pxe;
} else {
this.log.info(`Using remote PXE at ${config.pxeUrl!}`);
this.pxe = createPXEClient(config.pxeUrl!, getVersions(), makeTracedFetch([1, 2, 3], false));
}

if (dependencies.node) {
this.node = dependencies.node;
} else {
this.node = createAztecNodeClient(config.nodeUrl!, getVersions(), makeTracedFetch([1, 2, 3], false));
}

this.wallet = new TestWallet(this.pxe, this.node);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was all very messy and the functionality seems to have been completely unused as we always fed in the real instances.

Comment on lines -29 to -38
this.tracer = dependencies.telemetry.getTracer('Bot');
if (!dependencies.node && !config.nodeUrl) {
throw new Error(`Missing node URL in config or dependencies`);
}
const versions = getVersions();
const fetch = makeTracedFetch([1, 2, 3], true);
this.node = dependencies.node ?? createAztecNodeClient(config.nodeUrl!, versions, fetch);
this.nodeAdmin =
dependencies.nodeAdmin ??
(config.nodeAdminUrl ? createAztecNodeAdminClient(config.nodeAdminUrl, versions, fetch) : undefined);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same here. This seems to have been unused.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would ask @alexghr to make sure this is not used with certain configs in production

Copy link
Contributor Author

@benesjan benesjan Sep 22, 2025

Choose a reason for hiding this comment

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

By dropping the ugly unreadable dependencies arg and having real types there, the type checker figured out that nowhere in the code we pass in those values as undefined.

So this shouldn't be a problem.

But agree that would be good to get Alex's feedback as it's strange that it was unused.

Copy link
Contributor

Choose a reason for hiding this comment

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

This code path used to run before v2 but in this #16962 I changed it to create a node client as part of start_node so I guess it's no longer used. This is ok to remove!

return pxe;
};

pxeTestSuite('e2e_pxe', setupEnv);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since PXE is becoming library, this became pointless.

wallet = new TestWalletInternals(wallet.getPxe(), aztecNode);

const accountManager = await AccountManager.create(wallet, pxe, secret, accountContract, salt);
const accountManager = await AccountManager.create(wallet, wallet.getPxe(), secret, accountContract, salt);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The .getPxe() getter is a temporary workaround that will get resolved once Wallet instantiates the PXE.

@benesjan benesjan force-pushed the 09-19-refactor_un-exposing_pxe_from_e2e_tests branch from 8a22b91 to 66e9d87 Compare September 22, 2025 08:32
* @param startingBlock - First l2 block to process.
* @returns The new PXE.
*/
export async function createNewPXE(node: AztecNode, contract: BenchmarkingContract): Promise<PXEService> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was unused

* The test wallet or pxe to use for getting notes
*/
public pxe: PXE,
public testWalletOrPxe: { getNotes(filter: NotesFilter): Promise<UniqueNote[]> },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using TestWallet here would make this unusable for externals as it's likely their wallet will not expose the getNotes method. Just having the method defined in the type makes this PR a non-breaking change. Everything else should not be facing externals.

Copy link
Contributor

Choose a reason for hiding this comment

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

If this is unused, I would drop the loadPrivate method. That is a (testing) wallet utility

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure if this is unused as this can be used by externals. Or do you expect externals to use our testing wallet?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or their own. But this is false advertisement, I would deprecate it even if they're using it (because it uses the wrong mental model)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would say this being on a cheatcode class makes it ok to have this method. It might also be useful when debugging typescript tests. We should just instruct devs to not use it in production (implement a utility function for that if needed). WDYT?

@benesjan benesjan marked this pull request as ready for review September 22, 2025 09:22
*/
export async function getDeployedTestAccounts(pxe: PXE): Promise<InitialAccountData[]> {
export async function getDeployedTestAccounts(testWalletOrPxe: { getPxe(): PXE } | PXE): Promise<InitialAccountData[]> {
const pxe = 'getPxe' in testWalletOrPxe ? testWalletOrPxe.getPxe() : testWalletOrPxe;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needed to do this ugly hack because currently TestWallet doesn't correctly load the accounts that were registered in PXE before the Wallet was instantiated. This will be easy to tackle once Wallets instantiate PXE instead of having it passed in as an arg.

Copy link
Contributor

Choose a reason for hiding this comment

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

This utility should just die. InitialAccountData contains everything theTestWallt needs to create the accounts. If they're not deployed, well, the consumer should do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it makes sense to address this in step 2 of followup work as then only wallet will have access to pxe making it a necessity that this is dropped.

@benesjan benesjan requested a review from Thunkar September 22, 2025 11:16
export type { PXEServiceConfig, CliPXEOptions };
export type { CliPXEOptions, PXEServiceConfig };

export async function startPXE(
Copy link
Contributor

Choose a reason for hiding this comment

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

I would drop "pxe" from the name here and just go for createWallet

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I plan on just nuking this utility in step 1 or 2 of followup work. All these utils will change once PXE is not a standalone service. Now it's actually starting a PXE service and createWallet would be quite misleading name for this reason:
image

);
const crowdfundingInstance = await crowdfundingDeployment.getInstance();
await pxe.registerAccount(crowdfundingSecretKey, await computePartialAddress(crowdfundingInstance));
await wallet.registerAccount(crowdfundingSecretKey, await computePartialAddress(crowdfundingInstance));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to extend registerContract so it accepts keys

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's beyond the scope of this PR. The point of this PR is to just un-expose PXE from tests. The test wallet functions will be revisited in a followup work:

image


async registerRandomAccount(): Promise<AztecAddress> {
const completeAddress = await this.pxe.registerAccount(Fr.random(), Fr.random());
const completeAddress = await this.wallet.registerAccount(Fr.random(), Fr.random());
Copy link
Contributor

Choose a reason for hiding this comment

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

I dislike that the testwallet is getting so many methods. I'd try to refactor this into wallet-only tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Beyond the scope of this PR. You agreed last week on the process of:

  1. Moving the functions onto TestWallet,
  2. unexposing pxe from tests,
  3. then revisiting the methods.

I think this is the only reasonable approach how to make this big pxe refactor reviewable.

* @returns Private eXecution Environment (PXE), logger and teardown function.
* @returns A test wallet, logger and teardown function.
*/
export async function setupPXEService(
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd go with createWallet, the fact that it starts a PXE is internal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's starting a pxe service which is an exposed service so would say that name would be misleading. Anyway makes sense to address in step 1 of followup work section.

return this.pxe.simulateTx(txRequest, true /* simulatePublic */, true, true, { contracts: contractOverrides });
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

These are way too much. Idk if now, but they need to go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See step 3:

image

@benesjan benesjan requested a review from Thunkar September 22, 2025 13:02
@benesjan benesjan enabled auto-merge September 22, 2025 13:50
@AztecBot AztecBot force-pushed the 09-19-refactor_un-exposing_pxe_from_e2e_tests branch from a6f92f4 to 96e86f7 Compare September 22, 2025 13:52
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.
@AztecBot AztecBot force-pushed the 09-19-refactor_un-exposing_pxe_from_e2e_tests branch from 96e86f7 to 6456144 Compare September 22, 2025 13:56
@benesjan benesjan added this pull request to the merge queue Sep 22, 2025
Merged via the queue into next with commit 280c5f5 Sep 22, 2025
15 checks passed
@benesjan benesjan deleted the 09-19-refactor_un-exposing_pxe_from_e2e_tests branch September 22, 2025 14:44
AztecBot pushed a commit that referenced this pull request Sep 24, 2025
PXE is becoming just a lib used by the wallet and for this reason I am dropping the corresponding JSON RPC Server.

This leads to a large refactor of basically all the setups that dealt with PXE and wallets.

This is a followup work of [this PR](#17163) in which I had this tasks planned:
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.

In this PR I tackled points 1 and 2.
github-merge-queue bot pushed a commit that referenced this pull request Sep 24, 2025
PXE is becoming just a lib used by the wallet and for this reason I am
dropping the corresponding JSON RPC Server.

This leads to a large refactor of basically all the setups that dealt
with PXE and wallets.

This is a followup work of [this
PR](#17163) in which
I had this tasks planned:
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.

In this PR I tackled points 1 and 2.
mralj pushed a commit that referenced this pull request Oct 13, 2025
PXE is becoming just a lib used by the wallet and for this reason I am dropping the corresponding JSON RPC Server.

This leads to a large refactor of basically all the setups that dealt with PXE and wallets.

This is a followup work of [this PR](#17163) in which I had this tasks planned:
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.

In this PR I tackled points 1 and 2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants