use of org.ethereum.db.MutableRepository in project rskj by rsksmart.
the class TransactionExecutorTest method remascTxIsReceivedAndShouldntBeInCache.
@Test
public void remascTxIsReceivedAndShouldntBeInCache() {
ReceivedTxSignatureCache receivedTxSignatureCache = mock(ReceivedTxSignatureCache.class);
BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(receivedTxSignatureCache);
MutableRepository cacheTrack = mock(MutableRepository.class);
when(repository.startTracking()).thenReturn(cacheTrack);
RskAddress sender = PrecompiledContracts.REMASC_ADDR;
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));
Transaction transaction = getTransaction(sender, receiver, gasLimit, txNonce, gasPrice, value);
when(executionBlock.getGasLimit()).thenReturn(BigInteger.valueOf(6800000).toByteArray());
when(repository.getNonce(sender)).thenReturn(BigInteger.valueOf(1L));
when(repository.getBalance(sender)).thenReturn(new Coin(BigInteger.valueOf(0L)));
TransactionExecutor txExecutor = new TransactionExecutor(constants, activationConfig, transaction, txIndex, rskAddress, repository, blockStore, receiptStore, blockFactory, programInvokeFactory, executionBlock, gasUsedInTheBlock, vmConfig, true, precompiledContracts, deletedAccounts, blockTxSignatureCache);
assertEquals(0, transaction.transactionCost(constants, activationConfig.forBlock(executionBlock.getNumber())));
assertFalse(txExecutor.executeTransaction());
assertFalse(blockTxSignatureCache.containsTx(transaction));
}
use of org.ethereum.db.MutableRepository in project rskj by rsksmart.
the class TransactionExecutorTest method txInBlockIsExecutedAndShouldBeAddedInCache.
@Test
public void txInBlockIsExecutedAndShouldBeAddedInCache() {
ReceivedTxSignatureCache receivedTxSignatureCache = mock(ReceivedTxSignatureCache.class);
BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(receivedTxSignatureCache);
MutableRepository cacheTrack = mock(MutableRepository.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(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);
assertTrue(executeValidTransaction(transaction, blockTxSignatureCache));
assertTrue(blockTxSignatureCache.containsTx(transaction));
assertArrayEquals(blockTxSignatureCache.getSender(transaction).getBytes(), sender.getBytes());
}
use of org.ethereum.db.MutableRepository in project rskj by rsksmart.
the class TransactionExecutorTest method TwoTxsAreInBlockAndThemShouldBeContainedInCache.
@Test
public void TwoTxsAreInBlockAndThemShouldBeContainedInCache() {
ReceivedTxSignatureCache receivedTxSignatureCache = mock(ReceivedTxSignatureCache.class);
BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(receivedTxSignatureCache);
MutableRepository cacheTrack = mock(MutableRepository.class);
when(repository.startTracking()).thenReturn(cacheTrack);
RskAddress sender = new RskAddress("0000000000000000000000000000000000000001");
RskAddress sender2 = new RskAddress("0000000000000000000000000000000000000003");
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(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);
assertTrue(executeValidTransaction(transaction, blockTxSignatureCache));
when(repository.getNonce(sender2)).thenReturn(BigInteger.valueOf(1L));
when(repository.getBalance(sender2)).thenReturn(new Coin(BigInteger.valueOf(68000L)));
Transaction transaction2 = getTransaction(sender2, receiver, gasLimit, txNonce, gasPrice, value);
assertTrue(executeValidTransaction(transaction2, blockTxSignatureCache));
assertTrue(blockTxSignatureCache.containsTx(transaction));
assertArrayEquals(blockTxSignatureCache.getSender(transaction).getBytes(), sender.getBytes());
assertTrue(blockTxSignatureCache.containsTx(transaction2));
assertArrayEquals(blockTxSignatureCache.getSender(transaction2).getBytes(), sender2.getBytes());
}
use of org.ethereum.db.MutableRepository in project rskj by rsksmart.
the class MutableTrieCacheTest method testStorageKeysNoTrie.
@Test
public void testStorageKeysNoTrie() {
// SUTs
MutableTrieImpl baseMutableTrie = new MutableTrieImpl(null, new Trie());
MutableTrieCache mtCache = new MutableTrieCache(baseMutableTrie);
// setup
// helpers for interacting with the SUTs
MutableRepository cacheRepository = new MutableRepository(mtCache);
RskAddress addr = new RskAddress("b86ca7db8c7ae687ac8d098789987eee12333fc7");
DataWord skzero = DataWord.ZERO;
DataWord sk120 = toStorageKey("120");
DataWord sk121 = toStorageKey("121");
cacheRepository.addStorageBytes(addr, sk120, toBytes("HAL"));
cacheRepository.addStorageBytes(addr, sk121, toBytes("HAL"));
cacheRepository.addStorageBytes(addr, skzero, toBytes("HAL"));
Iterator<DataWord> storageKeys = mtCache.getStorageKeys(addr);
Set<DataWord> keys = new HashSet<>();
storageKeys.forEachRemaining(keys::add);
assertTrue(keys.contains(sk120));
assertTrue(keys.contains(sk121));
assertTrue(keys.contains(skzero));
assertEquals(3, keys.size());
}
use of org.ethereum.db.MutableRepository in project rskj by rsksmart.
the class RepositoryMigrationTest method test.
@Test
public void test() {
final RskAddress COW = new RskAddress("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
final BigInteger accountNonce = BigInteger.valueOf(9);
TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
Repository repository = new MutableRepository(trieStore, new Trie(trieStore));
AccountState accountState = repository.createAccount(COW);
accountState.setNonce(accountNonce);
repository.updateAccountState(COW, accountState);
repository.commit();
Assert.assertThat(repository.getAccountState(COW).getNonce(), is(accountNonce));
}
Aggregations