Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions yarn-project/archiver/src/archiver/archiver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { EthAddress } from '@aztec/foundation/eth-address';
import { Fr } from '@aztec/foundation/fields';
import { sleep } from '@aztec/foundation/sleep';
import { AvailabilityOracleAbi, type InboxAbi, RollupAbi } from '@aztec/l1-artifacts';
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';

import { type MockProxy, mock } from 'jest-mock-extended';
import {
Expand All @@ -25,6 +24,7 @@ import {

import { Archiver } from './archiver.js';
import { type ArchiverDataStore } from './archiver_store.js';
import { type ArchiverInstrumentation } from './instrumentation.js';
import { MemoryArchiverStore } from './memory_archiver_store/memory_archiver_store.js';

describe('Archiver', () => {
Expand All @@ -35,31 +35,46 @@ describe('Archiver', () => {
const blockNumbers = [1, 2, 3];

let publicClient: MockProxy<PublicClient<HttpTransport, Chain>>;
let instrumentation: MockProxy<ArchiverInstrumentation>;
let archiverStore: ArchiverDataStore;
let proverId: Fr;
let now: number;

let archiver: Archiver;

beforeEach(() => {
publicClient = mock<PublicClient<HttpTransport, Chain>>();
now = +new Date();
publicClient = mock<PublicClient<HttpTransport, Chain>>({
getBlock: ((args: any) => ({
timestamp: args.blockNumber * 1000n + BigInt(now),
})) as any,
});
instrumentation = mock({ isEnabled: () => true });
archiverStore = new MemoryArchiverStore(1000);
proverId = Fr.random();
});

afterEach(async () => {
await archiver?.stop();
});

it('can start, sync and stop and handle l1 to l2 messages and logs', async () => {
const archiver = new Archiver(
archiver = new Archiver(
publicClient,
rollupAddress,
availabilityOracleAddress,
inboxAddress,
registryAddress,
archiverStore,
1000,
new NoopTelemetryClient(),
instrumentation,
);

let latestBlockNum = await archiver.getBlockNumber();
expect(latestBlockNum).toEqual(0);

const blocks = blockNumbers.map(x => L2Block.random(x, 4, x, x + 1, 2, 2));
blocks.forEach((b, i) => (b.header.globalVariables.timestamp = new Fr(now + 1000 * (i + 1))));
const publishTxs = blocks.map(block => block.body).map(makePublishTx);
const rollupTxs = blocks.map(makeRollupTx);

Expand Down Expand Up @@ -157,20 +172,23 @@ describe('Archiver', () => {
expect((await archiver.getBlocks(1, 100)).map(b => b.number)).toEqual([1, 2, 3]);
expect((await archiver.getBlocks(1, 100, true)).map(b => b.number)).toEqual([1]);

await archiver.stop();
// Check instrumentation of proven blocks
expect(instrumentation.processProofsVerified).toHaveBeenCalledWith([
{ delay: 1000n, l1BlockNumber: 102n, l2BlockNumber: 1n, proverId: proverId.toString() },
]);
}, 10_000);

it('does not sync past current block number', async () => {
const numL2BlocksInTest = 2;
const archiver = new Archiver(
archiver = new Archiver(
publicClient,
rollupAddress,
availabilityOracleAddress,
inboxAddress,
registryAddress,
archiverStore,
1000,
new NoopTelemetryClient(),
instrumentation,
);

let latestBlockNum = await archiver.getBlockNumber();
Expand Down Expand Up @@ -207,8 +225,6 @@ describe('Archiver', () => {

latestBlockNum = await archiver.getBlockNumber();
expect(latestBlockNum).toEqual(numL2BlocksInTest);

await archiver.stop();
}, 10_000);

// logs should be created in order of how archiver syncs.
Expand Down
Loading