Skip to content

Commit

Permalink
refactor: deploying accounts after key registry
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed May 10, 2024
1 parent 6b1282c commit 7ab6e64
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export class ClientProverTest {

this.logger.debug(`Main setup completed, initializing full prover PXE...`);
({ pxe: this.fullProverPXE, teardown: this.provenPXETeardown } = await setupPXEService(
0,
this.aztecNode,
{
proverEnabled: false,
Expand Down
9 changes: 4 additions & 5 deletions yarn-project/end-to-end/src/e2e_2_pxes.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getUnsafeSchnorrAccount } from '@aztec/accounts/single_key';
import { createAccounts } from '@aztec/accounts/testing';
import {
type AztecAddress,
type AztecNode,
Expand Down Expand Up @@ -40,11 +41,9 @@ describe('e2e_2_pxes', () => {
teardown: teardownA,
} = await setup(1));

({
pxe: pxeB,
wallets: [walletB],
teardown: teardownB,
} = await setupPXEService(1, aztecNode!, {}, undefined, true));
({ pxe: pxeB, teardown: teardownB } = await setupPXEService(aztecNode!, {}, undefined, true));

[walletB] = await createAccounts(pxeB, 1);
});

afterEach(async () => {
Expand Down
8 changes: 8 additions & 0 deletions yarn-project/end-to-end/src/fixtures/snapshot_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import {
EthCheatCodes,
Fr,
GrumpkinPrivateKey,
SignerlessWallet,
type Wallet,
} from '@aztec/aztec.js';
import { deployInstance, registerContractClass } from '@aztec/aztec.js/deployment';
import { DefaultMultiCallEntrypoint } from '@aztec/aztec.js/entrypoint';
import { asyncMap } from '@aztec/foundation/async-map';
import { type Logger, createDebugLogger } from '@aztec/foundation/log';
import { makeBackoff, retry } from '@aztec/foundation/retry';
Expand All @@ -27,6 +29,7 @@ import { mnemonicToAccount } from 'viem/accounts';
import { MNEMONIC } from './fixtures.js';
import { getACVMConfig } from './get_acvm_config.js';
import { setupL1Contracts } from './setup_l1_contracts.js';
import { deployCanonicalKeyRegistry } from './utils.js';

export type SubsystemsContext = {
anvil: Anvil;
Expand Down Expand Up @@ -264,6 +267,11 @@ async function setupFromFresh(statePath: string | undefined, logger: Logger): Pr
pxeConfig.dataDirectory = statePath;
const pxe = await createPXEService(aztecNode, pxeConfig);

logger.verbose('Deploying key registry...');
await deployCanonicalKeyRegistry(
new SignerlessWallet(pxe, new DefaultMultiCallEntrypoint(aztecNodeConfig.chainId, aztecNodeConfig.version)),
);

if (statePath) {
writeFileSync(`${statePath}/aztec_node_config.json`, JSON.stringify(aztecNodeConfig));
}
Expand Down
32 changes: 13 additions & 19 deletions yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ async function initGasBridge({ walletClient, l1ContractAddresses }: DeployL1Cont

/**
* Sets up Private eXecution Environment (PXE).
* @param numberOfAccounts - The number of new accounts to be created once the PXE is initiated.
* @param aztecNode - An instance of Aztec Node.
* @param opts - Partial configuration for the PXE service.
* @param firstPrivKey - The private key of the first account to be created.
Expand All @@ -163,7 +162,6 @@ async function initGasBridge({ walletClient, l1ContractAddresses }: DeployL1Cont
* @returns Private eXecution Environment (PXE), accounts, wallets and logger.
*/
export async function setupPXEService(
numberOfAccounts: number,
aztecNode: AztecNode,
opts: Partial<PXEServiceConfig> = {},
logger = getLogger(),
Expand All @@ -174,10 +172,6 @@ export async function setupPXEService(
* The PXE instance.
*/
pxe: PXEService;
/**
* The wallets to be used.
*/
wallets: AccountWalletWithSecretKey[];
/**
* Logger instance named as the current test.
*/
Expand All @@ -190,15 +184,12 @@ export async function setupPXEService(
const pxeServiceConfig = { ...getPXEServiceConfig(), ...opts };
const pxe = await createPXEService(aztecNode, pxeServiceConfig, useLogSuffix, proofCreator);

const wallets = await createAccounts(pxe, numberOfAccounts);

const teardown = async () => {
await pxe.stop();
};

return {
pxe,
wallets,
logger,
teardown,
};
Expand Down Expand Up @@ -230,14 +221,6 @@ async function setupWithRemoteEnvironment(
logger.verbose('JSON RPC client connected to PXE');
logger.verbose(`Retrieving contract addresses from ${PXE_URL}`);
const l1Contracts = (await pxeClient.getNodeInfo()).l1ContractAddresses;
logger.verbose('PXE created, constructing available wallets from already registered accounts...');
const wallets = await getDeployedTestAccountsWallets(pxeClient);

if (wallets.length < numberOfAccounts) {
const numNewAccounts = numberOfAccounts - wallets.length;
logger.verbose(`Deploying ${numNewAccounts} accounts...`);
wallets.push(...(await createAccounts(pxeClient, numNewAccounts)));
}

const walletClient = createWalletClient<HttpTransport, Chain, HDAccount>({
account,
Expand Down Expand Up @@ -269,6 +252,15 @@ async function setupWithRemoteEnvironment(
);
}

logger.verbose('Constructing available wallets from already registered accounts...');
const wallets = await getDeployedTestAccountsWallets(pxeClient);

if (wallets.length < numberOfAccounts) {
const numNewAccounts = numberOfAccounts - wallets.length;
logger.verbose(`Deploying ${numNewAccounts} accounts...`);
wallets.push(...(await createAccounts(pxeClient, numNewAccounts)));
}

return {
aztecNode,
sequencer: undefined,
Expand Down Expand Up @@ -400,7 +392,8 @@ export async function setup(
const prover = aztecNode.getProver();

logger.verbose('Creating a pxe...');
const { pxe, wallets } = await setupPXEService(numberOfAccounts, aztecNode!, pxeOpts, logger);

const { pxe } = await setupPXEService(aztecNode!, pxeOpts, logger);

logger.verbose('Deploying key registry...');
await deployCanonicalKeyRegistry(
Expand All @@ -414,6 +407,7 @@ export async function setup(
);
}

const wallets = await createAccounts(pxe, numberOfAccounts);
const cheatCodes = CheatCodes.create(config.rpcUrl, pxe!);

const teardown = async () => {
Expand Down Expand Up @@ -616,7 +610,7 @@ export async function deployCanonicalGasToken(deployer: Wallet) {
await expect(deployer.isContractPubliclyDeployed(gasToken.address)).resolves.toBe(true);
}

async function deployCanonicalKeyRegistry(deployer: Wallet) {
export async function deployCanonicalKeyRegistry(deployer: Wallet) {
const canonicalKeyRegistry = getCanonicalKeyRegistry();

// We check to see if there exists a contract at the canonical Key Registry address with the same contract class id as we expect. This means that
Expand Down

0 comments on commit 7ab6e64

Please sign in to comment.