@@ -3,8 +3,9 @@ use crate::{
33 test_utils:: { execute_loaded_fixture, load_test_fixture, run_test_fixture} ,
44} ;
55use alloy_consensus:: Header ;
6- use alloy_eips:: Encodable2718 ;
7- use op_alloy_consensus:: { OpReceiptEnvelope , SDMGasEntry , build_post_exec_tx} ;
6+ use alloy_eips:: eip2718:: { Decodable2718 , Encodable2718 } ;
7+ use alloy_primitives:: b256;
8+ use op_alloy_consensus:: { OpReceiptEnvelope , OpTxEnvelope , SDMGasEntry , build_post_exec_tx} ;
89use rstest:: rstest;
910use std:: path:: PathBuf ;
1011
@@ -16,6 +17,11 @@ fn post_exec_fixture_path() -> PathBuf {
1617 PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "testdata/block-26207960.tar.gz" )
1718}
1819
20+ /// Premium-produced, Lagoon-active block with a non-empty `PostExec` refund payload.
21+ fn premium_sdm_fixture_path ( ) -> PathBuf {
22+ PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "testdata/block-7-sdm-premium.tar.gz" )
23+ }
24+
1925fn fixture_block_number ( parent_header : & Header ) -> u64 {
2026 parent_header. number + 1
2127}
@@ -139,6 +145,47 @@ async fn post_exec_valid_empty_payload_executes_without_state_or_gas_change() {
139145 assert_ne ! ( outcome. header. receipts_root, baseline. header. receipts_root) ;
140146}
141147
148+ #[ tokio:: test]
149+ async fn post_exec_nonzero_payload_applies_refunds_and_matches_op_reth ( ) {
150+ let loaded = load_test_fixture ( premium_sdm_fixture_path ( ) ) . await ;
151+ let expected_block_hash = loaded. fixture . expected_block_hash ;
152+ let timestamp = loaded. fixture . executing_payload . payload_attributes . timestamp ;
153+ assert ! ( loaded. fixture. rollup_config. is_lagoon_active( timestamp) ) ;
154+ assert_eq ! (
155+ expected_block_hash,
156+ b256!( "a128f899f6bff19247a2656364c3e440de4bc1292347bf3b8f6f4f717765c0b2" ) ,
157+ "fixture must remain pinned to the premium-produced block"
158+ ) ;
159+
160+ let encoded = loaded
161+ . fixture
162+ . executing_payload
163+ . transactions
164+ . as_ref ( )
165+ . and_then ( |transactions| transactions. last ( ) )
166+ . expect ( "premium fixture must contain transactions" ) ;
167+ let envelope =
168+ OpTxEnvelope :: decode_2718_exact ( encoded. as_ref ( ) ) . expect ( "trailing tx must decode" ) ;
169+ let OpTxEnvelope :: PostExec ( post_exec) = envelope else {
170+ panic ! ( "premium fixture must end in a PostExec transaction" )
171+ } ;
172+ assert ! ( !post_exec. inner( ) . payload. gas_refund_entries. is_empty( ) ) ;
173+ let refund_total: u64 =
174+ post_exec. inner ( ) . payload . gas_refund_entries . iter ( ) . map ( |entry| entry. gas_refund ) . sum ( ) ;
175+ assert ! ( refund_total > 0 , "premium fixture refund must be non-zero" ) ;
176+ assert_eq ! ( refund_total, 630_000 ) ;
177+
178+ let outcome = execute_loaded_fixture ( loaded, None ) . expect ( "premium SDM fixture executes" ) ;
179+ assert_eq ! ( outcome. header. hash( ) , expected_block_hash) ;
180+ assert_eq ! (
181+ outcome. header. state_root,
182+ b256!( "483d0a88146a80c0d5a592879f2d04f060b7515a1bad20f295fd4b601db20b93" )
183+ ) ;
184+ assert_eq ! ( outcome. execution_result. gas_used, 885_842 ) ;
185+ let evm_gas_used = 1_515_842 ;
186+ assert_eq ! ( outcome. execution_result. gas_used, evm_gas_used - refund_total) ;
187+ }
188+
142189#[ tokio:: test]
143190async fn post_exec_payload_rejects_deposit_target ( ) {
144191 let mut loaded = load_test_fixture ( post_exec_fixture_path ( ) ) . await ;
0 commit comments