@@ -10,7 +10,7 @@ import { sleep } from '@aztec/foundation/sleep';
1010import { DateProvider } from '@aztec/foundation/timer' ;
1111import { type BlockProposal , PeerErrorSeverity } from '@aztec/stdlib/p2p' ;
1212import { makeBlockHeader , makeBlockProposal } from '@aztec/stdlib/testing' ;
13- import { Tx , TxArray , TxHash , type TxValidationResult } from '@aztec/stdlib/tx' ;
13+ import { Tx , TxArray , TxHash , type TxValidationResult , type TxValidator } from '@aztec/stdlib/tx' ;
1414
1515import { describe , expect , it , jest } from '@jest/globals' ;
1616import type { PeerId } from '@libp2p/interface' ;
@@ -26,16 +26,12 @@ import { BatchTxRequester } from './batch_tx_requester.js';
2626import { DEFAULT_BATCH_TX_REQUESTER_BAD_PEER_THRESHOLD , DEFAULT_BATCH_TX_REQUESTER_TX_BATCH_SIZE } from './config.js' ;
2727import type { BatchTxRequesterLibP2PService , IPeerPenalizer } from './interface.js' ;
2828import { type IPeerCollection , PeerCollection , RATE_LIMIT_EXCEEDED_PEER_CACHE_TTL } from './peer_collection.js' ;
29- import type { IBatchRequestTxValidator } from './tx_validator.js' ;
3029
3130/** Mock tx validator for testing that always returns valid */
32- class AlwaysValidTxValidator implements IBatchRequestTxValidator {
33- validateRequestedTx ( _tx : Tx ) : Promise < TxValidationResult > {
31+ class AlwaysValidTxValidator implements TxValidator {
32+ validateTx ( _tx : Tx ) : Promise < TxValidationResult > {
3433 return Promise . resolve ( { result : 'valid' } ) ;
3534 }
36- validateRequestedTxs ( txs : Tx [ ] ) : Promise < TxValidationResult [ ] > {
37- return Promise . resolve ( txs . map ( ( ) => ( { result : 'valid' } ) ) ) ;
38- }
3935}
4036
4137const TEST_TIMEOUT = 15_000 ;
@@ -49,7 +45,7 @@ describe('BatchTxRequester', () => {
4945 let connectionSampler : MockProxy < ConnectionSampler > ;
5046 let reqResp : MockProxy < ReqRespInterface > ;
5147 let mockP2PService : MockProxy < BatchTxRequesterLibP2PService > ;
52- let txValidator : IBatchRequestTxValidator ;
48+ let txValidator : TxValidator ;
5349
5450 beforeEach ( async ( ) => {
5551 logger = createLogger ( 'test' ) ;
@@ -1191,13 +1187,12 @@ describe('BatchTxRequester', () => {
11911187
11921188 const invalidTxIndices = new Set ( [ 2 , 3 , 7 ] ) ; // Mark transactions at indices 2, 3, and 7 as invalid
11931189
1194- const customValidator : IBatchRequestTxValidator = {
1195- validateRequestedTx : ( tx : Tx ) => {
1190+ const customValidator : TxValidator = {
1191+ validateTx : ( tx : Tx ) => {
11961192 const txIndex = missing . findIndex ( h => h . equals ( tx . txHash ) ) ;
11971193 const isInvalid = invalidTxIndices . has ( txIndex ) ;
11981194 return Promise . resolve ( isInvalid ? { result : 'invalid' , reason : [ 'test invalid' ] } : { result : 'valid' } ) ;
11991195 } ,
1200- validateRequestedTxs : ( txs : Tx [ ] ) => Promise . all ( txs . map ( tx => customValidator . validateRequestedTx ( tx ) ) ) ,
12011196 } ;
12021197
12031198 const { mockImplementation } = createRequestLogger ( blockProposal , new Set ( ) , peerTransactions ) ;
@@ -1271,13 +1266,12 @@ describe('BatchTxRequester', () => {
12711266 // Validator that rejects transactions at specific indices
12721267 // Even indices are rejected, odd indices are accepted
12731268 const invalidTxIndices = new Set ( [ 0 , 2 , 4 , 6 , 8 , 10 ] ) ;
1274- const mixedValidator : IBatchRequestTxValidator = {
1275- validateRequestedTx : ( tx : Tx ) => {
1269+ const mixedValidator : TxValidator = {
1270+ validateTx : ( tx : Tx ) => {
12761271 const txIndex = missing . findIndex ( h => h . equals ( tx . txHash ) ) ;
12771272 const isInvalid = invalidTxIndices . has ( txIndex ) ;
12781273 return Promise . resolve ( isInvalid ? { result : 'invalid' , reason : [ 'test invalid' ] } : { result : 'valid' } ) ;
12791274 } ,
1280- validateRequestedTxs : ( txs : Tx [ ] ) => Promise . all ( txs . map ( tx => mixedValidator . validateRequestedTx ( tx ) ) ) ,
12811275 } ;
12821276
12831277 const { mockImplementation } = createRequestLogger ( blockProposal , new Set ( ) , peerTransactions ) ;
@@ -1329,8 +1323,8 @@ describe('BatchTxRequester', () => {
13291323 connectionSampler . getPeerListSortedByConnectionCountAsc . mockReturnValue ( [ peer ] ) ;
13301324
13311325 // Validator that throws errors for specific transactions
1332- const throwingValidator : IBatchRequestTxValidator = {
1333- validateRequestedTx : ( tx : Tx ) => {
1326+ const throwingValidator : TxValidator = {
1327+ validateTx : ( tx : Tx ) => {
13341328 const txIndex = missing . findIndex ( h => h . equals ( tx . txHash ) ) ;
13351329
13361330 // Throw error for transactions at indices 1 and 3
@@ -1345,7 +1339,6 @@ describe('BatchTxRequester', () => {
13451339
13461340 return Promise . resolve ( { result : 'valid' } ) ;
13471341 } ,
1348- validateRequestedTxs : ( txs : Tx [ ] ) => Promise . all ( txs . map ( tx => throwingValidator . validateRequestedTx ( tx ) ) ) ,
13491342 } ;
13501343
13511344 const peerTransactions = new Map ( [ [ peer . toString ( ) , Array . from ( { length : txCount } , ( _ , i ) => i ) ] ] ) ;
@@ -1698,13 +1691,12 @@ describe('BatchTxRequester', () => {
16981691
16991692 const invalidTxIndices = new Set ( [ 1 , 6 ] ) ; // Mark some transactions as invalid
17001693
1701- const customValidator : IBatchRequestTxValidator = {
1702- validateRequestedTx : ( tx : Tx ) => {
1694+ const customValidator : TxValidator = {
1695+ validateTx : ( tx : Tx ) => {
17031696 const txIndex = missing . findIndex ( h => h . equals ( tx . txHash ) ) ;
17041697 const isInvalid = invalidTxIndices . has ( txIndex ) ;
17051698 return Promise . resolve ( isInvalid ? { result : 'invalid' , reason : [ 'test invalid' ] } : { result : 'valid' } ) ;
17061699 } ,
1707- validateRequestedTxs : ( txs : Tx [ ] ) => Promise . all ( txs . map ( tx => customValidator . validateRequestedTx ( tx ) ) ) ,
17081700 } ;
17091701
17101702 const { mockImplementation } = createRequestLogger ( blockProposal , new Set ( ) , peerTransactions ) ;
0 commit comments