@@ -3,6 +3,7 @@ import { Secp256k1Signer } from '@aztec/foundation/crypto';
3
3
import { Fr } from '@aztec/foundation/fields' ;
4
4
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop' ;
5
5
6
+ import { jest } from '@jest/globals' ;
6
7
import { type MockProxy , mock } from 'jest-mock-extended' ;
7
8
8
9
import { type PoolInstrumentation } from '../instrumentation.js' ;
@@ -30,6 +31,11 @@ describe('MemoryAttestationPool', () => {
30
31
( ap as any ) . metrics = metricsMock ;
31
32
} ) ;
32
33
34
+ const createAttestationsForSlot = ( slotNumber : number ) => {
35
+ const archive = Fr . random ( ) ;
36
+ return signers . map ( signer => mockAttestation ( signer , slotNumber , archive ) ) ;
37
+ } ;
38
+
33
39
it ( 'should add attestations to pool' , async ( ) => {
34
40
const slotNumber = 420 ;
35
41
const archive = Fr . random ( ) ;
@@ -171,4 +177,29 @@ describe('MemoryAttestationPool', () => {
171
177
const retreivedAttestationsAfterDelete = await ap . getAttestationsForSlot ( BigInt ( slotNumber ) , proposalId ) ;
172
178
expect ( retreivedAttestationsAfterDelete . length ) . toBe ( 0 ) ;
173
179
} ) ;
180
+
181
+ it ( 'Should delete attestations older than a given slot' , async ( ) => {
182
+ const slotNumbers = [ 1 , 2 , 3 , 69 , 72 , 74 , 88 , 420 ] ;
183
+ const attestations = slotNumbers . map ( slotNumber => createAttestationsForSlot ( slotNumber ) ) . flat ( ) ;
184
+ const proposalId = attestations [ 0 ] . archive . toString ( ) ;
185
+
186
+ await ap . addAttestations ( attestations ) ;
187
+
188
+ const attestationsForSlot1 = await ap . getAttestationsForSlot ( BigInt ( 1 ) , proposalId ) ;
189
+ expect ( attestationsForSlot1 . length ) . toBe ( signers . length ) ;
190
+
191
+ const deleteAttestationsSpy = jest . spyOn ( ap , 'deleteAttestationsForSlot' ) ;
192
+
193
+ await ap . deleteAttestationsOlderThan ( BigInt ( 73 ) ) ;
194
+
195
+ const attestationsForSlot1AfterDelete = await ap . getAttestationsForSlot ( BigInt ( 1 ) , proposalId ) ;
196
+ expect ( attestationsForSlot1AfterDelete . length ) . toBe ( 0 ) ;
197
+
198
+ expect ( deleteAttestationsSpy ) . toHaveBeenCalledTimes ( 5 ) ;
199
+ expect ( deleteAttestationsSpy ) . toHaveBeenCalledWith ( BigInt ( 1 ) ) ;
200
+ expect ( deleteAttestationsSpy ) . toHaveBeenCalledWith ( BigInt ( 2 ) ) ;
201
+ expect ( deleteAttestationsSpy ) . toHaveBeenCalledWith ( BigInt ( 3 ) ) ;
202
+ expect ( deleteAttestationsSpy ) . toHaveBeenCalledWith ( BigInt ( 69 ) ) ;
203
+ expect ( deleteAttestationsSpy ) . toHaveBeenCalledWith ( BigInt ( 72 ) ) ;
204
+ } ) ;
174
205
} ) ;
0 commit comments