@@ -73,3 +73,85 @@ fn changed_usdc_storage_slots<R>(state: &ExecutionOutcome<R>) -> impl Iterator<I
7373 } )
7474 } )
7575}
76+
77+ #[ cfg( test) ]
78+ mod tests {
79+ use super :: * ;
80+ use alloy_primitives:: { map:: HashMap , FlaggedStorage , U256 } ;
81+ use reth_execution_types:: { BundleStateInit , RevertsInit } ;
82+
83+ #[ test]
84+ fn reloads_only_queued_senders_with_changed_usdc_slots ( ) {
85+ let affected = alloy_primitives:: address!( "000000000000000000000000000000000000000a" ) ;
86+ let unaffected = alloy_primitives:: address!( "000000000000000000000000000000000000000b" ) ;
87+ let queued_senders = HashSet :: from ( [ affected, unaffected] ) ;
88+ let state = ExecutionOutcome :: < ( ) > :: new_init (
89+ {
90+ let mut init = BundleStateInit :: default ( ) ;
91+ init. insert (
92+ crate :: usdc:: USDC_CONTRACT ,
93+ (
94+ None ,
95+ None ,
96+ HashMap :: from_iter ( [ (
97+ crate :: usdc:: usdc_balance_storage_key ( & affected) ,
98+ ( FlaggedStorage :: ZERO , FlaggedStorage :: from ( U256 :: from ( 1 ) ) ) ,
99+ ) ] ) ,
100+ ) ,
101+ ) ;
102+ init
103+ } ,
104+ RevertsInit :: default ( ) ,
105+ [ ] ,
106+ vec ! [ ] ,
107+ 0 ,
108+ vec ! [ ] ,
109+ ) ;
110+
111+ let dirty = queued_senders_with_changed_usdc_slots ( & queued_senders, None , & state)
112+ . collect :: < HashSet < _ > > ( ) ;
113+
114+ assert_eq ! ( dirty, HashSet :: from( [ affected] ) ) ;
115+ }
116+
117+ #[ test]
118+ fn includes_changed_slots_from_old_and_new_state ( ) {
119+ let queued_sender = alloy_primitives:: address!( "000000000000000000000000000000000000000a" ) ;
120+ let queued_senders = HashSet :: from ( [ queued_sender] ) ;
121+ let old = ExecutionOutcome :: < ( ) > :: new_init (
122+ {
123+ let mut init = BundleStateInit :: default ( ) ;
124+ init. insert (
125+ crate :: usdc:: USDC_CONTRACT ,
126+ (
127+ None ,
128+ None ,
129+ HashMap :: from_iter ( [ (
130+ crate :: usdc:: usdc_balance_storage_key ( & queued_sender) ,
131+ ( FlaggedStorage :: ZERO , FlaggedStorage :: from ( U256 :: from ( 1 ) ) ) ,
132+ ) ] ) ,
133+ ) ,
134+ ) ;
135+ init
136+ } ,
137+ RevertsInit :: default ( ) ,
138+ [ ] ,
139+ vec ! [ ] ,
140+ 0 ,
141+ vec ! [ ] ,
142+ ) ;
143+ let new = ExecutionOutcome :: < ( ) > :: new_init (
144+ BundleStateInit :: default ( ) ,
145+ RevertsInit :: default ( ) ,
146+ [ ] ,
147+ vec ! [ ] ,
148+ 0 ,
149+ vec ! [ ] ,
150+ ) ;
151+
152+ let dirty = queued_senders_with_changed_usdc_slots ( & queued_senders, Some ( & old) , & new)
153+ . collect :: < HashSet < _ > > ( ) ;
154+
155+ assert_eq ! ( dirty, HashSet :: from( [ queued_sender] ) ) ;
156+ }
157+ }
0 commit comments