Skip to content

Commit

Permalink
Merge pull request #2162 from rsksmart/use-cached-repository
Browse files Browse the repository at this point in the history
Update the repository passed to the precompiled contract init method
  • Loading branch information
Vovchyk authored Nov 20, 2023
2 parents 3542363 + b6aaf72 commit a63d4b8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import java.math.BigInteger;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a63d4b8

Please sign in to comment.