From 363a0f67d4fdb7d08c60f6197bb252bb7eee6207 Mon Sep 17 00:00:00 2001 From: Reynold Morel Date: Wed, 1 Nov 2023 11:33:05 -0400 Subject: [PATCH 1/2] Update the repository passed to the precompiled contract init method --- .../src/main/java/org/ethereum/core/TransactionExecutor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rskj-core/src/main/java/org/ethereum/core/TransactionExecutor.java b/rskj-core/src/main/java/org/ethereum/core/TransactionExecutor.java index 45caa37c5af..0bb6a14216e 100644 --- a/rskj-core/src/main/java/org/ethereum/core/TransactionExecutor.java +++ b/rskj-core/src/main/java/org/ethereum/core/TransactionExecutor.java @@ -307,7 +307,7 @@ private void call() { if (precompiledContract != null) { Metric metric = profiler.start(Profiler.PROFILING_TYPE.PRECOMPILED_CONTRACT_INIT); - precompiledContract.init(tx, executionBlock, track, blockStore, receiptStore, result.getLogInfoList()); + precompiledContract.init(tx, executionBlock, cacheTrack, blockStore, receiptStore, result.getLogInfoList()); profiler.stop(metric); metric = profiler.start(Profiler.PROFILING_TYPE.PRECOMPILED_CONTRACT_EXECUTE); From b6aaf723cc52b805b5b2731a90e1e618606b7afc Mon Sep 17 00:00:00 2001 From: Reynold Morel Date: Wed, 1 Nov 2023 15:25:11 -0400 Subject: [PATCH 2/2] Add test to check that correct repository is used --- .../core/TransactionExecutorTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/rskj-core/src/test/java/org/ethereum/core/TransactionExecutorTest.java b/rskj-core/src/test/java/org/ethereum/core/TransactionExecutorTest.java index cef9f217744..616367860f0 100644 --- a/rskj-core/src/test/java/org/ethereum/core/TransactionExecutorTest.java +++ b/rskj-core/src/test/java/org/ethereum/core/TransactionExecutorTest.java @@ -37,6 +37,7 @@ import java.math.BigInteger; import java.util.HashSet; +import java.util.List; import java.util.Random; import java.util.Set; @@ -174,6 +175,33 @@ void TwoTxsAreInBlockAndThemShouldBeContainedInCache() { assertArrayEquals(blockTxSignatureCache.getSender(transaction2).getBytes(), sender2.getBytes()); } + @Test + void PrecompiledContractInitShouldBeCalledWithCacheTrack() { + ReceivedTxSignatureCache receivedTxSignatureCache = mock(ReceivedTxSignatureCache.class); + BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(receivedTxSignatureCache); + MutableRepository cacheTrack = mock(MutableRepository.class); + PrecompiledContracts.PrecompiledContract precompiledContract = mock(PrecompiledContracts.PrecompiledContract.class); + + when(repository.startTracking()).thenReturn(cacheTrack); + + RskAddress sender = new RskAddress("0000000000000000000000000000000000000001"); + RskAddress receiver = new RskAddress("0000000000000000000000000000000000000002"); + byte[] gasLimit = BigInteger.valueOf(4000000).toByteArray(); + byte[] txNonce = BigInteger.valueOf(1L).toByteArray(); + Coin gasPrice = Coin.valueOf(1); + Coin value = new Coin(BigInteger.valueOf(2)); + + + when(precompiledContracts.getContractForAddress(any(ActivationConfig.ForBlock.class), eq(DataWord.valueOf(receiver.getBytes())))).thenReturn(precompiledContract); + when(repository.getNonce(sender)).thenReturn(BigInteger.valueOf(1L)); + when(repository.getBalance(sender)).thenReturn(new Coin(BigInteger.valueOf(68000L))); + Transaction transaction = getTransaction(sender, receiver, gasLimit, txNonce, gasPrice, value, 1); + + assertTrue(executeValidTransaction(transaction, blockTxSignatureCache)); + + verify(precompiledContract).init(eq(transaction), eq(executionBlock), eq(cacheTrack), eq(blockStore), eq(receiptStore), any(List.class)); + } + @Test void InvalidTxsIsInBlockAndShouldntBeInCache(){ ReceivedTxSignatureCache receivedTxSignatureCache = mock(ReceivedTxSignatureCache.class);