@@ -10,7 +10,6 @@ import { EthAddress } from '@aztec/foundation/eth-address';
10
10
import { Fr } from '@aztec/foundation/fields' ;
11
11
import { sleep } from '@aztec/foundation/sleep' ;
12
12
import { AvailabilityOracleAbi , type InboxAbi , RollupAbi } from '@aztec/l1-artifacts' ;
13
- import { NoopTelemetryClient } from '@aztec/telemetry-client/noop' ;
14
13
15
14
import { type MockProxy , mock } from 'jest-mock-extended' ;
16
15
import {
@@ -25,6 +24,7 @@ import {
25
24
26
25
import { Archiver } from './archiver.js' ;
27
26
import { type ArchiverDataStore } from './archiver_store.js' ;
27
+ import { type ArchiverInstrumentation } from './instrumentation.js' ;
28
28
import { MemoryArchiverStore } from './memory_archiver_store/memory_archiver_store.js' ;
29
29
30
30
describe ( 'Archiver' , ( ) => {
@@ -35,31 +35,46 @@ describe('Archiver', () => {
35
35
const blockNumbers = [ 1 , 2 , 3 ] ;
36
36
37
37
let publicClient : MockProxy < PublicClient < HttpTransport , Chain > > ;
38
+ let instrumentation : MockProxy < ArchiverInstrumentation > ;
38
39
let archiverStore : ArchiverDataStore ;
39
40
let proverId : Fr ;
41
+ let now : number ;
42
+
43
+ let archiver : Archiver ;
40
44
41
45
beforeEach ( ( ) => {
42
- publicClient = mock < PublicClient < HttpTransport , Chain > > ( ) ;
46
+ now = + new Date ( ) ;
47
+ publicClient = mock < PublicClient < HttpTransport , Chain > > ( {
48
+ getBlock : ( ( args : any ) => ( {
49
+ timestamp : args . blockNumber * 1000n + BigInt ( now ) ,
50
+ } ) ) as any ,
51
+ } ) ;
52
+ instrumentation = mock ( { isEnabled : ( ) => true } ) ;
43
53
archiverStore = new MemoryArchiverStore ( 1000 ) ;
44
54
proverId = Fr . random ( ) ;
45
55
} ) ;
46
56
57
+ afterEach ( async ( ) => {
58
+ await archiver ?. stop ( ) ;
59
+ } ) ;
60
+
47
61
it ( 'can start, sync and stop and handle l1 to l2 messages and logs' , async ( ) => {
48
- const archiver = new Archiver (
62
+ archiver = new Archiver (
49
63
publicClient ,
50
64
rollupAddress ,
51
65
availabilityOracleAddress ,
52
66
inboxAddress ,
53
67
registryAddress ,
54
68
archiverStore ,
55
69
1000 ,
56
- new NoopTelemetryClient ( ) ,
70
+ instrumentation ,
57
71
) ;
58
72
59
73
let latestBlockNum = await archiver . getBlockNumber ( ) ;
60
74
expect ( latestBlockNum ) . toEqual ( 0 ) ;
61
75
62
76
const blocks = blockNumbers . map ( x => L2Block . random ( x , 4 , x , x + 1 , 2 , 2 ) ) ;
77
+ blocks . forEach ( ( b , i ) => ( b . header . globalVariables . timestamp = new Fr ( now + 1000 * ( i + 1 ) ) ) ) ;
63
78
const publishTxs = blocks . map ( block => block . body ) . map ( makePublishTx ) ;
64
79
const rollupTxs = blocks . map ( makeRollupTx ) ;
65
80
@@ -157,20 +172,23 @@ describe('Archiver', () => {
157
172
expect ( ( await archiver . getBlocks ( 1 , 100 ) ) . map ( b => b . number ) ) . toEqual ( [ 1 , 2 , 3 ] ) ;
158
173
expect ( ( await archiver . getBlocks ( 1 , 100 , true ) ) . map ( b => b . number ) ) . toEqual ( [ 1 ] ) ;
159
174
160
- await archiver . stop ( ) ;
175
+ // Check instrumentation of proven blocks
176
+ expect ( instrumentation . processProofsVerified ) . toHaveBeenCalledWith ( [
177
+ { delay : 1000n , l1BlockNumber : 102n , l2BlockNumber : 1n , proverId : proverId . toString ( ) } ,
178
+ ] ) ;
161
179
} , 10_000 ) ;
162
180
163
181
it ( 'does not sync past current block number' , async ( ) => {
164
182
const numL2BlocksInTest = 2 ;
165
- const archiver = new Archiver (
183
+ archiver = new Archiver (
166
184
publicClient ,
167
185
rollupAddress ,
168
186
availabilityOracleAddress ,
169
187
inboxAddress ,
170
188
registryAddress ,
171
189
archiverStore ,
172
190
1000 ,
173
- new NoopTelemetryClient ( ) ,
191
+ instrumentation ,
174
192
) ;
175
193
176
194
let latestBlockNum = await archiver . getBlockNumber ( ) ;
@@ -207,8 +225,6 @@ describe('Archiver', () => {
207
225
208
226
latestBlockNum = await archiver . getBlockNumber ( ) ;
209
227
expect ( latestBlockNum ) . toEqual ( numL2BlocksInTest ) ;
210
-
211
- await archiver . stop ( ) ;
212
228
} , 10_000 ) ;
213
229
214
230
// logs should be created in order of how archiver syncs.
0 commit comments