1717import static org .hyperledger .besu .ethereum .trie .pathbased .common .worldview .WorldStateConfig .createStatefulConfigWithTrie ;
1818import static org .junit .jupiter .api .Assertions .assertTrue ;
1919import static org .mockito .ArgumentMatchers .any ;
20+ import static org .mockito .ArgumentMatchers .argThat ;
2021import static org .mockito .ArgumentMatchers .eq ;
2122import static org .mockito .Mockito .mock ;
2223import static org .mockito .Mockito .times ;
3435import org .hyperledger .besu .ethereum .mainnet .MainnetTransactionProcessor ;
3536import org .hyperledger .besu .ethereum .mainnet .TransactionValidationParams ;
3637import org .hyperledger .besu .ethereum .mainnet .ValidationResult ;
38+ import org .hyperledger .besu .ethereum .mainnet .block .access .list .BlockAccessList .BlockAccessListBuilder ;
39+ import org .hyperledger .besu .ethereum .mainnet .block .access .list .PartialBlockAccessView ;
3740import org .hyperledger .besu .ethereum .processing .TransactionProcessingResult ;
3841import org .hyperledger .besu .ethereum .transaction .TransactionInvalidReason ;
3942import org .hyperledger .besu .ethereum .trie .pathbased .bonsai .cache .CodeCache ;
4245import org .hyperledger .besu .ethereum .trie .pathbased .bonsai .storage .BonsaiWorldStateKeyValueStorage ;
4346import org .hyperledger .besu .ethereum .trie .pathbased .bonsai .worldview .BonsaiWorldState ;
4447import org .hyperledger .besu .ethereum .trie .pathbased .common .trielog .NoOpTrieLogManager ;
45- import org .hyperledger .besu .ethereum .trie .pathbased .common .worldview .accumulator .PathBasedWorldStateUpdateAccumulator ;
4648import org .hyperledger .besu .ethereum .worldstate .DataStorageConfiguration ;
4749import org .hyperledger .besu .ethereum .worldstate .WorldStateArchive ;
4850import org .hyperledger .besu .evm .blockhash .BlockHashLookup ;
4951import org .hyperledger .besu .evm .internal .EvmConfiguration ;
5052import org .hyperledger .besu .evm .tracing .OperationTracer ;
53+ import org .hyperledger .besu .evm .worldstate .WorldUpdater ;
5154import org .hyperledger .besu .metrics .noop .NoOpMetricsSystem ;
5255
5356import java .util .Collections ;
@@ -118,7 +121,7 @@ void testRunTransaction() {
118121
119122 Mockito .when (
120123 transactionProcessor .processTransaction (
121- any (), any (), any (), any (), any (), any (), any (), any ()))
124+ any (), any (), any (), any (), any (), any (), any (), any (), any () ))
122125 .thenReturn (
123126 TransactionProcessingResult .successful (
124127 Collections .emptyList (),
@@ -135,18 +138,20 @@ void testRunTransaction() {
135138 transaction ,
136139 miningBeneficiary ,
137140 (__ , ___ ) -> Hash .EMPTY ,
138- blobGasPrice );
141+ blobGasPrice ,
142+ Optional .empty ());
139143
140144 verify (transactionProcessor , times (1 ))
141145 .processTransaction (
142- any (PathBasedWorldStateUpdateAccumulator .class ),
146+ any (WorldUpdater .class ),
143147 eq (blockHeader ),
144148 eq (transaction ),
145149 eq (miningBeneficiary ),
146150 any (OperationTracer .class ),
147151 any (BlockHashLookup .class ),
148152 eq (TransactionValidationParams .processingBlock ()),
149- eq (blobGasPrice ));
153+ eq (blobGasPrice ),
154+ eq (Optional .empty ()));
150155
151156 assertTrue (
152157 processor
@@ -162,7 +167,7 @@ void testRunTransactionWithFailure() {
162167 Wei blobGasPrice = Wei .ZERO ;
163168
164169 when (transactionProcessor .processTransaction (
165- any (), any (), any (), any (), any (), any (), any (), any ()))
170+ any (), any (), any (), any (), any (), any (), any (), any (), any () ))
166171 .thenReturn (
167172 TransactionProcessingResult .failed (
168173 0 ,
@@ -180,7 +185,8 @@ void testRunTransactionWithFailure() {
180185 transaction ,
181186 miningBeneficiary ,
182187 (__ , ___ ) -> Hash .EMPTY ,
183- blobGasPrice );
188+ blobGasPrice ,
189+ Optional .empty ());
184190
185191 Optional <TransactionProcessingResult > result =
186192 processor .applyParallelizedTransactionResult (
@@ -196,7 +202,7 @@ void testRunTransactionWithConflict() {
196202
197203 Mockito .when (
198204 transactionProcessor .processTransaction (
199- any (), any (), any (), any (), any (), any (), any (), any ()))
205+ any (), any (), any (), any (), any (), any (), any (), any (), any () ))
200206 .thenReturn (
201207 TransactionProcessingResult .successful (
202208 Collections .emptyList (),
@@ -213,18 +219,20 @@ void testRunTransactionWithConflict() {
213219 transaction ,
214220 miningBeneficiary ,
215221 (__ , ___ ) -> Hash .EMPTY ,
216- blobGasPrice );
222+ blobGasPrice ,
223+ Optional .empty ());
217224
218225 verify (transactionProcessor , times (1 ))
219226 .processTransaction (
220- any (PathBasedWorldStateUpdateAccumulator .class ),
227+ any (WorldUpdater .class ),
221228 eq (blockHeader ),
222229 eq (transaction ),
223230 eq (miningBeneficiary ),
224231 any (OperationTracer .class ),
225232 any (BlockHashLookup .class ),
226233 eq (TransactionValidationParams .processingBlock ()),
227- eq (blobGasPrice ));
234+ eq (blobGasPrice ),
235+ eq (Optional .empty ()));
228236
229237 // simulate a conflict
230238 when (transactionCollisionDetector .hasCollision (any (), any (), any (), any ())).thenReturn (true );
@@ -234,4 +242,63 @@ void testRunTransactionWithConflict() {
234242 worldState , miningBeneficiary , transaction , 0 , Optional .empty (), Optional .empty ());
235243 assertTrue (result .isEmpty (), "Expected no transaction result to be applied due to conflict" );
236244 }
245+
246+ @ Test
247+ void testApplyResultUsesAccessLocationTrackerAndUpdatesPartialBlockAccessView () {
248+ Address miningBeneficiary = Address .fromHexString ("0x1" );
249+ Wei blobGasPrice = Wei .ZERO ;
250+
251+ PartialBlockAccessView partialView = mock (PartialBlockAccessView .class );
252+ PartialBlockAccessView .AccountChanges beneficiaryChanges =
253+ mock (PartialBlockAccessView .AccountChanges .class );
254+ when (beneficiaryChanges .getAddress ()).thenReturn (miningBeneficiary );
255+ when (partialView .accountChanges ()).thenReturn (Collections .singletonList (beneficiaryChanges ));
256+
257+ when (transactionProcessor .processTransaction (
258+ any (), any (), any (), any (), any (), any (), any (), any (), any ()))
259+ .thenReturn (
260+ TransactionProcessingResult .successful (
261+ Collections .emptyList (),
262+ 0 ,
263+ 0 ,
264+ Bytes .EMPTY ,
265+ Optional .of (partialView ),
266+ ValidationResult .valid ()));
267+
268+ BlockAccessListBuilder balBuilder = mock (BlockAccessListBuilder .class );
269+
270+ processor .runTransaction (
271+ protocolContext ,
272+ blockHeader ,
273+ 0 ,
274+ transaction ,
275+ miningBeneficiary ,
276+ (__ , ___ ) -> Hash .EMPTY ,
277+ blobGasPrice ,
278+ Optional .of (balBuilder ));
279+
280+ verify (transactionProcessor )
281+ .processTransaction (
282+ any (WorldUpdater .class ),
283+ eq (blockHeader ),
284+ eq (transaction ),
285+ eq (miningBeneficiary ),
286+ any (OperationTracer .class ),
287+ any (BlockHashLookup .class ),
288+ eq (TransactionValidationParams .processingBlock ()),
289+ eq (blobGasPrice ),
290+ argThat (Optional ::isPresent ));
291+
292+ when (transactionCollisionDetector .hasCollision (any (), any (), any (), any ())).thenReturn (false );
293+
294+ Optional <TransactionProcessingResult > maybeResult =
295+ processor .applyParallelizedTransactionResult (
296+ worldState , miningBeneficiary , transaction , 0 , Optional .empty (), Optional .empty ());
297+
298+ assertTrue (
299+ maybeResult .isPresent (), "Expected the parallelized transaction result to be applied" );
300+ TransactionProcessingResult result = maybeResult .get ();
301+ assertTrue (result .getPartialBlockAccessView ().isPresent (), "Expected BAL view to be present" );
302+ verify (beneficiaryChanges ).setPostBalance (any (Wei .class ));
303+ }
237304}
0 commit comments