@@ -231,4 +231,78 @@ mod tests {
231231 let decoded = StateChanges :: decode_cfg ( encoded, & cfg ( ) ) . expect ( "decode changes" ) ;
232232 assert_eq ! ( changes, decoded) ;
233233 }
234+
235+ #[ test]
236+ fn test_empty_state_changes_roundtrip ( ) {
237+ let changes = StateChanges :: default ( ) ;
238+ assert ! ( changes. is_empty( ) ) ;
239+ let encoded = changes. encode ( ) ;
240+ let decoded = StateChanges :: decode_cfg ( encoded, & cfg ( ) ) . expect ( "decode empty" ) ;
241+ assert_eq ! ( changes, decoded) ;
242+ assert ! ( decoded. is_empty( ) ) ;
243+ }
244+
245+ #[ test]
246+ fn test_account_change_roundtrip ( ) {
247+ let mut storage = BTreeMap :: new ( ) ;
248+ storage. insert ( U256 :: from ( 1u64 ) , U256 :: from ( 100u64 ) ) ;
249+ let change = AccountChange {
250+ touched : true ,
251+ created : true ,
252+ selfdestructed : false ,
253+ nonce : 42 ,
254+ balance : U256 :: from ( 1_000_000u64 ) ,
255+ code_hash : B256 :: repeat_byte ( 0xAB ) ,
256+ storage,
257+ } ;
258+
259+ let encoded = change. encode ( ) ;
260+ let decoded = AccountChange :: decode_cfg ( encoded, & cfg ( ) ) . expect ( "decode change" ) ;
261+ assert_eq ! ( change, decoded) ;
262+ }
263+
264+ #[ test]
265+ fn test_account_change_empty_storage ( ) {
266+ let change = AccountChange {
267+ touched : false ,
268+ created : false ,
269+ selfdestructed : true ,
270+ nonce : 0 ,
271+ balance : U256 :: ZERO ,
272+ code_hash : B256 :: ZERO ,
273+ storage : BTreeMap :: new ( ) ,
274+ } ;
275+
276+ let encoded = change. encode ( ) ;
277+ let decoded = AccountChange :: decode_cfg ( encoded, & cfg ( ) ) . expect ( "decode" ) ;
278+ assert_eq ! ( change, decoded) ;
279+ }
280+
281+ #[ test]
282+ fn test_state_changes_is_empty ( ) {
283+ let mut changes = StateChanges :: default ( ) ;
284+ assert ! ( changes. is_empty( ) ) ;
285+
286+ changes. accounts . insert (
287+ Address :: ZERO ,
288+ AccountChange {
289+ touched : true ,
290+ created : false ,
291+ selfdestructed : false ,
292+ nonce : 1 ,
293+ balance : U256 :: from ( 100u64 ) ,
294+ code_hash : B256 :: ZERO ,
295+ storage : BTreeMap :: new ( ) ,
296+ } ,
297+ ) ;
298+ assert ! ( !changes. is_empty( ) ) ;
299+ }
300+
301+ #[ test]
302+ fn test_state_changes_cfg_debug ( ) {
303+ let cfg = StateChangesCfg { max_accounts : 10 , max_storage_slots : 20 } ;
304+ let debug_str = format ! ( "{:?}" , cfg) ;
305+ assert ! ( debug_str. contains( "max_accounts: 10" ) ) ;
306+ assert ! ( debug_str. contains( "max_storage_slots: 20" ) ) ;
307+ }
234308}
0 commit comments