Skip to content

Commit

Permalink
test: update sequencer to look for min 2 txs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed Oct 16, 2023
1 parent 29d7567 commit b886a9d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 23 deletions.
58 changes: 35 additions & 23 deletions yarn-project/end-to-end/src/e2e_deploy_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { AztecAddress, Contract, ContractDeployer, EthAddress, Fr, Wallet, isCon
import { CompleteAddress, getContractDeploymentInfo } from '@aztec/circuits.js';
import { DebugLogger } from '@aztec/foundation/log';
import { TestContractArtifact, TokenContractArtifact } from '@aztec/noir-contracts/artifacts';
import { SequencerClient } from '@aztec/sequencer-client';
import { PXE, TxStatus } from '@aztec/types';

import { setup } from './fixtures/utils.js';
Expand All @@ -11,10 +12,11 @@ describe('e2e_deploy_contract', () => {
let accounts: CompleteAddress[];
let logger: DebugLogger;
let wallet: Wallet;
let sequencer: SequencerClient | undefined;
let teardown: () => Promise<void>;

beforeEach(async () => {
({ teardown, pxe, accounts, logger, wallet } = await setup());
({ teardown, pxe, accounts, logger, wallet, sequencer } = await setup());
}, 100_000);

afterEach(() => teardown());
Expand Down Expand Up @@ -130,35 +132,45 @@ describe('e2e_deploy_contract', () => {
});

it('it should not deploy a contract which failed the public part of the execution', async () => {
// This test requires at least another good transaction to go through in the same block as the bad one.
// I deployed the same contract again but it could really be any valid transaction here.
const goodDeploy = new ContractDeployer(TokenContractArtifact, wallet).deploy(AztecAddress.random());
const badDeploy = new ContractDeployer(TokenContractArtifact, wallet).deploy(AztecAddress.ZERO);
sequencer?.updateSequencerConfig({
minTxsPerBlock: 2,
});

await Promise.all([
goodDeploy.simulate({ skipPublicSimulation: true }),
badDeploy.simulate({ skipPublicSimulation: true }),
]);
try {
// This test requires at least another good transaction to go through in the same block as the bad one.
// I deployed the same contract again but it could really be any valid transaction here.
const goodDeploy = new ContractDeployer(TokenContractArtifact, wallet).deploy(AztecAddress.random());
const badDeploy = new ContractDeployer(TokenContractArtifact, wallet).deploy(AztecAddress.ZERO);

const [goodTx, badTx] = [
goodDeploy.send({ skipPublicSimulation: true }),
badDeploy.send({ skipPublicSimulation: true }),
];
await Promise.all([
goodDeploy.simulate({ skipPublicSimulation: true }),
badDeploy.simulate({ skipPublicSimulation: true }),
]);

const [goodTxPromiseResult, badTxReceiptResult] = await Promise.allSettled([goodTx.wait(), badTx.wait()]);
const [goodTx, badTx] = [
goodDeploy.send({ skipPublicSimulation: true }),
badDeploy.send({ skipPublicSimulation: true }),
];

expect(goodTxPromiseResult.status).toBe('fulfilled');
expect(badTxReceiptResult.status).toBe('rejected');
const [goodTxPromiseResult, badTxReceiptResult] = await Promise.allSettled([goodTx.wait(), badTx.wait()]);

const [goodTxReceipt, badTxReceipt] = await Promise.all([goodTx.getReceipt(), badTx.getReceipt()]);
expect(goodTxPromiseResult.status).toBe('fulfilled');
expect(badTxReceiptResult.status).toBe('rejected');

expect(goodTxReceipt.blockNumber).toEqual(expect.any(Number));
expect(badTxReceipt.blockNumber).toBeUndefined();
const [goodTxReceipt, badTxReceipt] = await Promise.all([goodTx.getReceipt(), badTx.getReceipt()]);

await expect(pxe.getExtendedContractData(goodDeploy.completeAddress!.address)).resolves.toBeDefined();
await expect(pxe.getExtendedContractData(goodDeploy.completeAddress!.address)).resolves.toBeDefined();
expect(goodTxReceipt.blockNumber).toEqual(expect.any(Number));
expect(badTxReceipt.blockNumber).toBeUndefined();

await expect(pxe.getContractData(badDeploy.completeAddress!.address)).resolves.toBeUndefined();
await expect(pxe.getExtendedContractData(badDeploy.completeAddress!.address)).resolves.toBeUndefined();
await expect(pxe.getExtendedContractData(goodDeploy.completeAddress!.address)).resolves.toBeDefined();
await expect(pxe.getExtendedContractData(goodDeploy.completeAddress!.address)).resolves.toBeDefined();

await expect(pxe.getContractData(badDeploy.completeAddress!.address)).resolves.toBeUndefined();
await expect(pxe.getExtendedContractData(badDeploy.completeAddress!.address)).resolves.toBeUndefined();
} finally {
sequencer?.updateSequencerConfig({
minTxsPerBlock: 1,
});
}
});
});
6 changes: 6 additions & 0 deletions yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
} from '@aztec/l1-artifacts';
import { TokenBridgeContract, TokenContract } from '@aztec/noir-contracts/types';
import { PXEService, createPXEService, getPXEServiceConfig } from '@aztec/pxe';
import { SequencerClient } from '@aztec/sequencer-client';
import { AztecNode, L2BlockL2Logs, LogType, PXE, TxStatus, createAztecNodeRpcClient } from '@aztec/types';

import * as path from 'path';
Expand Down Expand Up @@ -206,6 +207,7 @@ async function setupWithSandbox(account: Account, config: AztecNodeConfig, logge
const teardown = () => Promise.resolve();
return {
aztecNode,
sequencer: undefined,
pxe: pxeClient,
deployL1ContractsValues,
accounts: await pxeClient!.getRegisteredAccounts(),
Expand All @@ -225,6 +227,8 @@ type SetupOptions = { /** State load */ stateLoad?: string } & Partial<AztecNode
export type EndToEndContext = {
/** The Aztec Node service or client a connected to it. */
aztecNode: AztecNode | undefined;
/** A client to the sequencer service */
sequencer: SequencerClient | undefined;
/** The Private eXecution Environment (PXE). */
pxe: PXE;
/** Return values from deployL1Contracts function. */
Expand Down Expand Up @@ -286,6 +290,7 @@ export async function setup(numberOfAccounts = 1, opts: SetupOptions = {}): Prom

logger('Creating and synching an aztec node...');
const aztecNode = await AztecNodeService.createAndSync(config);
const sequencer = aztecNode.getSequencer();

const { pxe, accounts, wallets } = await setupPXEService(numberOfAccounts, aztecNode!, logger);

Expand All @@ -306,6 +311,7 @@ export async function setup(numberOfAccounts = 1, opts: SetupOptions = {}): Prom
wallets,
logger,
cheatCodes,
sequencer,
teardown,
};
}
Expand Down

0 comments on commit b886a9d

Please sign in to comment.