@@ -9,7 +9,7 @@ use crate::{
99} ;
1010use alloy:: {
1111 consensus:: { Header , Receipt as AlloyReceipt , Signed , TxLegacy } ,
12- primitives:: { B256 , BlockNumber , Signature , TxKind , U256 } ,
12+ primitives:: { B256 , BlockNumber , Bytes , Log , Signature , TxKind , U256 , address } ,
1313} ;
1414use signet_storage_types:: { Receipt , TransactionSigned } ;
1515
@@ -54,6 +54,23 @@ fn make_test_receipt() -> Receipt {
5454 }
5555}
5656
57+ /// Create a test receipt with the given number of logs.
58+ fn make_test_receipt_with_logs ( log_count : usize , cumulative_gas : u64 ) -> Receipt {
59+ let logs = ( 0 ..log_count)
60+ . map ( |_| {
61+ Log :: new_unchecked (
62+ address ! ( "0x0000000000000000000000000000000000000001" ) ,
63+ vec ! [ ] ,
64+ Bytes :: new ( ) ,
65+ )
66+ } )
67+ . collect ( ) ;
68+ Receipt {
69+ inner : AlloyReceipt { status : true . into ( ) , cumulative_gas_used : cumulative_gas, logs } ,
70+ ..Default :: default ( )
71+ }
72+ }
73+
5774/// Create test block data with transactions and receipts.
5875fn make_test_block_with_txs ( block_number : BlockNumber , tx_count : usize ) -> BlockData {
5976 let header = Header { number : block_number, ..Default :: default ( ) } ;
@@ -244,33 +261,53 @@ pub async fn test_latest_block_tracking<B: ColdStorage>(backend: &B) -> ColdResu
244261
245262/// Test get_receipt_with_context returns complete receipt context.
246263pub async fn test_get_receipt_with_context < B : ColdStorage > ( backend : & B ) -> ColdResult < ( ) > {
247- let block = make_test_block_with_txs ( 700 , 3 ) ;
248- let expected_header = block. header . clone ( ) ;
249- let tx_hash = * block. transactions [ 1 ] . tx_hash ( ) ;
264+ // Block with 3 receipts having 2, 3, and 1 logs respectively.
265+ let header = Header { number : 700 , ..Default :: default ( ) } ;
266+ let transactions: Vec < _ > = ( 0 ..3 ) . map ( |i| make_test_tx ( 700 * 100 + i) ) . collect ( ) ;
267+ let receipts = vec ! [
268+ make_test_receipt_with_logs( 2 , 21000 ) ,
269+ make_test_receipt_with_logs( 3 , 42000 ) ,
270+ make_test_receipt_with_logs( 1 , 63000 ) ,
271+ ] ;
272+ let block = BlockData :: new ( header. clone ( ) , transactions. clone ( ) , receipts, vec ! [ ] , None ) ;
273+ let tx_hash = * transactions[ 1 ] . tx_hash ( ) ;
250274
251275 backend. append_block ( block) . await ?;
252276
253- // Lookup by block+index
254- let ctx = backend
277+ // First receipt: prior_cumulative_gas=0, first_log_index=0
278+ let first = backend
279+ . get_receipt_with_context ( ReceiptSpecifier :: BlockAndIndex { block : 700 , index : 0 } )
280+ . await ?
281+ . unwrap ( ) ;
282+ assert_eq ! ( first. header, header) ;
283+ assert_eq ! ( first. receipt. meta( ) . block_number( ) , 700 ) ;
284+ assert_eq ! ( first. receipt. meta( ) . transaction_index( ) , 0 ) ;
285+ assert_eq ! ( first. prior_cumulative_gas, 0 ) ;
286+ assert_eq ! ( first. first_log_index, 0 ) ;
287+
288+ // Second receipt: prior_cumulative_gas=21000, first_log_index=2
289+ let second = backend
255290 . get_receipt_with_context ( ReceiptSpecifier :: BlockAndIndex { block : 700 , index : 1 } )
256291 . await ?
257292 . unwrap ( ) ;
258- assert_eq ! ( ctx . header , expected_header ) ;
259- assert_eq ! ( ctx . receipt . meta ( ) . block_number ( ) , 700 ) ;
260- assert_eq ! ( ctx . receipt . meta ( ) . transaction_index ( ) , 1 ) ;
293+ assert_eq ! ( second . receipt . meta ( ) . transaction_index ( ) , 1 ) ;
294+ assert_eq ! ( second . prior_cumulative_gas , 21000 ) ;
295+ assert_eq ! ( second . first_log_index , 2 ) ;
261296
262- // prior_cumulative_gas should equal receipt[0].cumulative_gas_used
263- let first = backend
264- . get_receipt_with_context ( ReceiptSpecifier :: BlockAndIndex { block : 700 , index : 0 } )
297+ // Third receipt: prior_cumulative_gas=42000, first_log_index=5 (2+3)
298+ let third = backend
299+ . get_receipt_with_context ( ReceiptSpecifier :: BlockAndIndex { block : 700 , index : 2 } )
265300 . await ?
266301 . unwrap ( ) ;
267- assert_eq ! ( first. prior_cumulative_gas, 0 ) ;
268- assert_eq ! ( ctx. prior_cumulative_gas, first. receipt. inner( ) . inner. cumulative_gas_used) ;
302+ assert_eq ! ( third. receipt. meta( ) . transaction_index( ) , 2 ) ;
303+ assert_eq ! ( third. prior_cumulative_gas, 42000 ) ;
304+ assert_eq ! ( third. first_log_index, 5 ) ;
269305
270306 // Lookup by tx hash
271307 let by_hash =
272308 backend. get_receipt_with_context ( ReceiptSpecifier :: TxHash ( tx_hash) ) . await ?. unwrap ( ) ;
273309 assert_eq ! ( by_hash. receipt. meta( ) . transaction_index( ) , 1 ) ;
310+ assert_eq ! ( by_hash. first_log_index, 2 ) ;
274311
275312 // Non-existent returns None
276313 assert ! (
0 commit comments