Search in sources :

Example 31 with MutableRepository

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));
}
Also used : Coin(co.rsk.core.Coin) MutableRepository(org.ethereum.db.MutableRepository) RskAddress(co.rsk.core.RskAddress) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 32 with MutableRepository

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());
}
Also used : Coin(co.rsk.core.Coin) MutableRepository(org.ethereum.db.MutableRepository) RskAddress(co.rsk.core.RskAddress) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 33 with MutableRepository

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());
}
Also used : Coin(co.rsk.core.Coin) MutableRepository(org.ethereum.db.MutableRepository) RskAddress(co.rsk.core.RskAddress) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 34 with MutableRepository

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());
}
Also used : MutableRepository(org.ethereum.db.MutableRepository) RskAddress(co.rsk.core.RskAddress) DataWord(org.ethereum.vm.DataWord) MutableTrie(co.rsk.trie.MutableTrie) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 35 with MutableRepository

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));
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) Repository(org.ethereum.core.Repository) MutableRepository(org.ethereum.db.MutableRepository) MutableRepository(org.ethereum.db.MutableRepository) RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger) AccountState(org.ethereum.core.AccountState) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Aggregations

MutableRepository (org.ethereum.db.MutableRepository)40 Test (org.junit.Test)31 Trie (co.rsk.trie.Trie)26 RskAddress (co.rsk.core.RskAddress)21 Repository (org.ethereum.core.Repository)15 TrieStore (co.rsk.trie.TrieStore)12 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)12 HashMapDB (org.ethereum.datasource.HashMapDB)12 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)9 BigInteger (java.math.BigInteger)8 Coin (co.rsk.core.Coin)7 DataWord (org.ethereum.vm.DataWord)7 MutableTrieImpl (co.rsk.db.MutableTrieImpl)6 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)5 MutableTrie (co.rsk.trie.MutableTrie)4 ArrayList (java.util.ArrayList)4 Block (org.ethereum.core.Block)4 TestGenesisLoader (co.rsk.core.genesis.TestGenesisLoader)2 HashMapBlocksIndex (co.rsk.db.HashMapBlocksIndex)2 CountDownLatch (java.util.concurrent.CountDownLatch)2