Search in sources :

Example 36 with TrieStoreImpl

use of co.rsk.trie.TrieStoreImpl in project rskj by rsksmart.

the class BlockExecutorTest method executeAndFillBlockWithTxToExcludeBecauseSenderHasNoBalance.

@Test
public void executeAndFillBlockWithTxToExcludeBecauseSenderHasNoBalance() {
    TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
    Repository repository = new MutableRepository(new MutableTrieImpl(trieStore, new Trie(trieStore)));
    Repository track = repository.startTracking();
    Account account = createAccount("acctest1", track, Coin.valueOf(30000));
    Account account2 = createAccount("acctest2", track, Coin.valueOf(10L));
    Account account3 = createAccount("acctest3", track, Coin.ZERO);
    track.commit();
    Assert.assertFalse(Arrays.equals(EMPTY_TRIE_HASH, repository.getRoot()));
    BlockExecutor executor = buildBlockExecutor(trieStore);
    Transaction tx3 = Transaction.builder().nonce(repository.getNonce(account.getAddress())).gasPrice(BigInteger.ONE).gasLimit(BigInteger.valueOf(21000)).destination(account2.getAddress()).chainId(CONFIG.getNetworkConstants().getChainId()).value(BigInteger.TEN).build();
    tx3.sign(account.getEcKey().getPrivKeyBytes());
    Transaction tx = tx3;
    Transaction tx1 = Transaction.builder().nonce(repository.getNonce(account3.getAddress())).gasPrice(BigInteger.ONE).gasLimit(BigInteger.valueOf(21000)).destination(account2.getAddress()).chainId(CONFIG.getNetworkConstants().getChainId()).value(BigInteger.TEN).build();
    tx1.sign(account3.getEcKey().getPrivKeyBytes());
    Transaction tx2 = tx1;
    List<Transaction> txs = new ArrayList<>();
    txs.add(tx);
    txs.add(tx2);
    List<BlockHeader> uncles = new ArrayList<>();
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    genesis.setStateRoot(repository.getRoot());
    Block block = blockGenerator.createChildBlock(genesis, txs, uncles, 1, null);
    executor.executeAndFill(block, genesis.getHeader());
    // Check tx2 was excluded
    Assert.assertEquals(1, block.getTransactionsList().size());
    Assert.assertEquals(tx, block.getTransactionsList().get(0));
    Assert.assertArrayEquals(calculateTxTrieRoot(Collections.singletonList(tx), block.getNumber()), block.getTxTrieRoot());
    Assert.assertEquals(3141592, new BigInteger(1, block.getGasLimit()).longValue());
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) ArrayList(java.util.ArrayList) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) MutableRepository(org.ethereum.db.MutableRepository) MutableRepository(org.ethereum.db.MutableRepository) BigInteger(java.math.BigInteger) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 37 with TrieStoreImpl

use of co.rsk.trie.TrieStoreImpl in project rskj by rsksmart.

the class BlockExecutorTest method generateBlockWithOneStrangeTransaction.

public TestObjects generateBlockWithOneStrangeTransaction(int strangeTransactionType) {
    TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
    Repository repository = new MutableRepository(trieStore, new Trie(trieStore));
    Repository track = repository.startTracking();
    Account account = createAccount("acctest1", track, Coin.valueOf(30000));
    Account account2 = createAccount("acctest2", track, Coin.valueOf(10L));
    track.commit();
    Assert.assertFalse(Arrays.equals(EMPTY_TRIE_HASH, repository.getRoot()));
    BlockExecutor executor = buildBlockExecutor(trieStore);
    List<Transaction> txs = new ArrayList<>();
    Transaction tx = createStrangeTransaction(account, account2, BigInteger.TEN, repository.getNonce(account.getAddress()), strangeTransactionType);
    txs.add(tx);
    List<BlockHeader> uncles = new ArrayList<>();
    Block genesis = BlockChainImplTest.getGenesisBlock(trieStore);
    genesis.setStateRoot(repository.getRoot());
    Block block = new BlockGenerator().createChildBlock(genesis, txs, uncles, 1, null);
    // Forces all transactions included
    executor.executeAndFillReal(block, genesis.getHeader());
    repository.save();
    return new TestObjects(trieStore, block, genesis, tx, account);
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) ArrayList(java.util.ArrayList) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) MutableRepository(org.ethereum.db.MutableRepository) MutableRepository(org.ethereum.db.MutableRepository) Trie(co.rsk.trie.Trie)

Example 38 with TrieStoreImpl

use of co.rsk.trie.TrieStoreImpl 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

TrieStoreImpl (co.rsk.trie.TrieStoreImpl)38 HashMapDB (org.ethereum.datasource.HashMapDB)34 TrieStore (co.rsk.trie.TrieStore)25 Trie (co.rsk.trie.Trie)21 Test (org.junit.Test)20 MutableRepository (org.ethereum.db.MutableRepository)12 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)8 RskAddress (co.rsk.core.RskAddress)8 DataWord (org.ethereum.vm.DataWord)8 TrieImpl (co.rsk.trie.TrieImpl)7 Repository (org.ethereum.core.Repository)7 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)7 RepositoryImpl (co.rsk.db.RepositoryImpl)6 ArrayList (java.util.ArrayList)6 TestUtils.randomDataWord (org.ethereum.TestUtils.randomDataWord)6 MutableTrieImpl (co.rsk.db.MutableTrieImpl)5 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)5 RskSystemProperties (co.rsk.config.RskSystemProperties)4 DummyBlockValidator (co.rsk.validators.DummyBlockValidator)4 ProgramInvokeFactoryImpl (org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)4