@@ -428,6 +428,14 @@ mod tests {
428428 handle. stopped ( ) . await ;
429429 }
430430
431+ /// Test that the server returns an error when the request size exceeds the limit.
432+ /// The server should return HTTP 413 (Request Entity Too Large).
433+ /// In this test, the request size limit is set to 100 kB, and we are expecting
434+ /// that to fit about 250 receipts. We also test with 300 receipts, which should
435+ /// exceed the limit.
436+ /// We conclude that a limit of 10MB should fit about 25k receipts, and thus
437+ /// the TAP spec will require that the aggregator supports up to 15k receipts
438+ /// per aggregation request as a safe limit.
431439 #[ rstest]
432440 #[ tokio:: test]
433441 async fn request_size_limit (
@@ -437,14 +445,20 @@ mod tests {
437445 allocation_ids : Vec < Address > ,
438446 #[ values( "0.0" ) ] api_version : & str ,
439447 ) {
440- // Set the request size limit to 10 kB to easily trigger the HTTP 413 error.
441- let small_request_size_limit = 10 * 1024 ;
448+ // Set the request byte size limit to a value that easily triggers the HTTP 413
449+ // error.
450+ let http_request_size_limit = 100 * 1024 ;
451+
452+ // Number of receipts that is just above the number that would fit within the
453+ // request size limit. This value is hard-coded here because it supports the
454+ // maximum number of receipts per aggregate value we wrote in the spec / docs.
455+ let number_of_receipts_to_exceed_limit = 300 ;
442456
443457 // Start the JSON-RPC server.
444458 let ( handle, local_addr) = server:: run_server (
445459 0 ,
446460 keys. 0 . clone ( ) ,
447- small_request_size_limit ,
461+ http_request_size_limit ,
448462 http_response_size_limit,
449463 http_max_concurrent_connections,
450464 )
@@ -456,33 +470,40 @@ mod tests {
456470 . build ( format ! ( "http://127.0.0.1:{}" , local_addr. port( ) ) )
457471 . unwrap ( ) ;
458472
459- // Create 100 receipts
473+ // Create receipts
460474 let mut receipts = Vec :: new ( ) ;
461- for _ in 1 ..100 {
475+ for _ in 1 ..number_of_receipts_to_exceed_limit {
462476 receipts. push (
463- EIP712SignedMessage :: new ( Receipt :: new ( allocation_ids[ 0 ] , 42 ) . unwrap ( ) , & keys. 0 )
464- . await
465- . unwrap ( ) ,
477+ EIP712SignedMessage :: new (
478+ Receipt :: new ( allocation_ids[ 0 ] , u128:: MAX / 1000 ) . unwrap ( ) ,
479+ & keys. 0 ,
480+ )
481+ . await
482+ . unwrap ( ) ,
466483 ) ;
467484 }
468485
469486 // Skipping receipts validation in this test, aggregate_receipts assumes receipts are valid.
470487 // Create RAV through the JSON-RPC server.
471- // Test with only 10 receipts
488+ // Test with a number of receipts that stays within request size limit
472489 let res: Result <
473490 server:: JsonRpcResponse < EIP712SignedMessage < ReceiptAggregateVoucher > > ,
474491 jsonrpsee:: core:: Error ,
475492 > = client
476493 . request (
477494 "aggregate_receipts" ,
478- rpc_params ! ( api_version, & receipts[ ..10 ] , None :: <( ) >) ,
495+ rpc_params ! (
496+ api_version,
497+ & receipts[ ..number_of_receipts_to_exceed_limit - 50 ] ,
498+ None :: <( ) >
499+ ) ,
479500 )
480501 . await ;
481502
482503 assert ! ( res. is_ok( ) ) ;
483504
484505 // Create RAV through the JSON-RPC server.
485- // Test with all 100 receipts
506+ // Test with all receipts to exceed request size limit
486507 let res: Result <
487508 server:: JsonRpcResponse < EIP712SignedMessage < ReceiptAggregateVoucher > > ,
488509 jsonrpsee:: core:: Error ,
0 commit comments