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());
}
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);
}
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));
}
Aggregations