Skip to content

Commit

Permalink
Add test to check that correct repository is used
Browse files Browse the repository at this point in the history
  • Loading branch information
rmoreliovlabs committed Nov 20, 2023
1 parent 363a0f6 commit b6aaf72
Showing 1 changed file with 28 additions and 0 deletions.
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 b6aaf72

Please sign in to comment.