Skip to content

Commit

Permalink
test: add test with walltime anvil
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Aug 30, 2024
1 parent 40a035e commit 434aada
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 3 deletions.
67 changes: 67 additions & 0 deletions yarn-project/end-to-end/src/e2e_devnet.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { getSchnorrAccount } from '@aztec/accounts/schnorr';
import { type DebugLogger, Fr, GrumpkinScalar, type PXE, type SentTx, TxStatus } from '@aztec/aztec.js';
import { EthAddress } from '@aztec/circuits.js';
import { type PXEService } from '@aztec/pxe';

import { privateKeyToAccount } from 'viem/accounts';

import { getPrivateKeyFromIndex, setup } from './fixtures/utils.js';

describe('e2e_devnet', () => {
let logger: DebugLogger;
let teardown: () => Promise<void>;
let pxe: PXE;

beforeEach(async () => {
const account = privateKeyToAccount(`0x${getPrivateKeyFromIndex(0)!.toString('hex')}`);
const initialValidators = [EthAddress.fromString(account.address)];

({ teardown, logger, pxe } = await setup(0, { initialValidators, l1BlockTime: 12 }));
});

afterEach(() => teardown());

it('should produce blocks with a bunch of transactions', async () => {
for (let i = 0; i < 4; i++) {
const txs = await submitTxsTo(pxe as PXEService, 8);
await Promise.all(
txs.map(async (tx, j) => {
logger.info(`Waiting for tx ${i - j}: ${await tx.getTxHash()} to be mined`);
return tx.wait();
}),
);
}
});

// submits a set of transactions to the provided Private eXecution Environment (PXE)
const submitTxsTo = async (pxe: PXEService, numTxs: number) => {
const txs: SentTx[] = [];
for (let i = 0; i < numTxs; i++) {
// const tx = getSchnorrAccount(pxe, Fr.random(), GrumpkinScalar.random(), Fr.random()).deploy();
const accountManager = getSchnorrAccount(pxe, Fr.random(), GrumpkinScalar.random(), Fr.random());
const deployMethod = await accountManager.getDeployMethod();
await deployMethod.create({
contractAddressSalt: accountManager.salt,
skipClassRegistration: true,
skipPublicDeployment: true,
universalDeploy: true,
});
await deployMethod.prove({});
const tx = deployMethod.send();

const txHash = await tx.getTxHash();

logger.info(`Tx sent with hash ${txHash}`);
const receipt = await tx.getReceipt();
expect(receipt).toEqual(
expect.objectContaining({
status: TxStatus.PENDING,
error: '',
}),
);
logger.info(`Receipt received for ${txHash}`);
txs.push(tx);
}
return txs;
};
});
12 changes: 9 additions & 3 deletions yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ type SetupOptions = {
salt?: number;
/** An initial set of validators */
initialValidators?: EthAddress[];
/** Anvil block time (interval) */
l1BlockTime?: number;
} & Partial<AztecNodeConfig>;

/** Context for an end-to-end test as returned by the `setup` function */
Expand Down Expand Up @@ -354,7 +356,7 @@ export async function setup(
);
}

const res = await startAnvil();
const res = await startAnvil(opts.l1BlockTime);
anvil = res.anvil;
config.l1RpcUrl = res.rpcUrl;
}
Expand Down Expand Up @@ -504,7 +506,7 @@ export function getL1WalletClient(rpcUrl: string, index: number) {
* Ensures there's a running Anvil instance and returns the RPC URL.
* @returns
*/
export async function startAnvil(): Promise<{ anvil: Anvil; rpcUrl: string }> {
export async function startAnvil(l1BlockTime?: number): Promise<{ anvil: Anvil; rpcUrl: string }> {
let rpcUrl: string | undefined = undefined;

// Start anvil.
Expand All @@ -513,7 +515,11 @@ export async function startAnvil(): Promise<{ anvil: Anvil; rpcUrl: string }> {
async () => {
const ethereumHostPort = await getPort();
rpcUrl = `http://127.0.0.1:${ethereumHostPort}`;
const anvil = createAnvil({ anvilBinary: './scripts/anvil_kill_wrapper.sh', port: ethereumHostPort });
const anvil = createAnvil({
anvilBinary: './scripts/anvil_kill_wrapper.sh',
port: ethereumHostPort,
blockTime: l1BlockTime,
});
await anvil.start();
return anvil;
},
Expand Down

0 comments on commit 434aada

Please sign in to comment.