refactor: un-exposing PXE from e2e tests#17163
Conversation
| export type { CliPXEOptions, PXEServiceConfig }; | ||
|
|
||
| export async function startPXE( | ||
| export async function startPXEServicesGetWallet( |
There was a problem hiding this comment.
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.
| 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); | ||
| } |
There was a problem hiding this comment.
This was all very messy and the functionality seems to have been completely unused as we always fed in the real instances.
| 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); |
There was a problem hiding this comment.
Same here. This seems to have been unused.
There was a problem hiding this comment.
I would ask @alexghr to make sure this is not used with certain configs in production
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
The .getPxe() getter is a temporary workaround that will get resolved once Wallet instantiates the PXE.
8a22b91 to
66e9d87
Compare
| * @param startingBlock - First l2 block to process. | ||
| * @returns The new PXE. | ||
| */ | ||
| export async function createNewPXE(node: AztecNode, contract: BenchmarkingContract): Promise<PXEService> { |
| * The test wallet or pxe to use for getting notes | ||
| */ | ||
| public pxe: PXE, | ||
| public testWalletOrPxe: { getNotes(filter: NotesFilter): Promise<UniqueNote[]> }, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
If this is unused, I would drop the loadPrivate method. That is a (testing) wallet utility
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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?
| */ | ||
| 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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| export type { PXEServiceConfig, CliPXEOptions }; | ||
| export type { CliPXEOptions, PXEServiceConfig }; | ||
|
|
||
| export async function startPXE( |
There was a problem hiding this comment.
I would drop "pxe" from the name here and just go for createWallet
| ); | ||
| const crowdfundingInstance = await crowdfundingDeployment.getInstance(); | ||
| await pxe.registerAccount(crowdfundingSecretKey, await computePartialAddress(crowdfundingInstance)); | ||
| await wallet.registerAccount(crowdfundingSecretKey, await computePartialAddress(crowdfundingInstance)); |
There was a problem hiding this comment.
I think it would be better to extend registerContract so it accepts keys
|
|
||
| async registerRandomAccount(): Promise<AztecAddress> { | ||
| const completeAddress = await this.pxe.registerAccount(Fr.random(), Fr.random()); | ||
| const completeAddress = await this.wallet.registerAccount(Fr.random(), Fr.random()); |
There was a problem hiding this comment.
I dislike that the testwallet is getting so many methods. I'd try to refactor this into wallet-only tests
There was a problem hiding this comment.
Beyond the scope of this PR. You agreed last week on the process of:
- Moving the functions onto TestWallet,
- unexposing pxe from tests,
- 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( |
There was a problem hiding this comment.
I'd go with createWallet, the fact that it starts a PXE is internal
There was a problem hiding this comment.
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 }); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
These are way too much. Idk if now, but they need to go
a6f92f4 to
96e86f7
Compare
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.
96e86f7 to
6456144
Compare
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.
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.
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.




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