use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class BlockValidatorTest method processBlockWithInvalidPrevMGP.
@Test
public void processBlockWithInvalidPrevMGP() {
BlockStore blockStore = Mockito.mock(org.ethereum.db.BlockStore.class);
Repository repository = Mockito.mock(Repository.class);
Mockito.when(repository.getSnapshotTo(Mockito.any())).thenReturn(repository);
Mockito.when(repository.getNonce(Mockito.any())).thenReturn(BigInteger.ZERO);
Block parent = new BlockBuilder().minGasPrice(BigInteger.ZERO).parent(new BlockGenerator().getGenesisBlock()).build();
Block block = new BlockBuilder().minGasPrice(BigInteger.TEN).parent(parent).build();
Mockito.when(blockStore.getBlockByHash(block.getParentHash().getBytes())).thenReturn(parent);
BlockValidatorImpl validator = new BlockValidatorBuilder().addPrevMinGasPriceRule().blockStore(blockStore).build();
Assert.assertFalse(validator.isValid(block));
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class BlockValidatorTest method processBlockWithInvalidMGPTxs.
@Test
public void processBlockWithInvalidMGPTxs() {
BlockStore blockStore = Mockito.mock(org.ethereum.db.BlockStore.class);
Repository repository = Mockito.mock(Repository.class);
Mockito.when(repository.getSnapshotTo(Mockito.any())).thenReturn(repository);
Mockito.when(repository.getNonce(Mockito.any())).thenReturn(BigInteger.ZERO);
Block parent = new BlockBuilder().minGasPrice(BigInteger.ZERO).parent(new BlockGenerator().getGenesisBlock()).build();
List<Transaction> txs = new ArrayList<>();
Transaction tx = Transaction.create(config, "0000000000000000000000000000000000000006", BigInteger.ZERO, BigInteger.ZERO, BigInteger.ONE, BigInteger.TEN);
tx.sign(new byte[] { 22, 11, 00 });
txs.add(tx);
Block block = new BlockBuilder().minGasPrice(BigInteger.TEN).transactions(txs).parent(parent).build();
Mockito.when(blockStore.getBlockByHash(block.getParentHash().getBytes())).thenReturn(parent);
BlockValidatorImpl validator = new BlockValidatorBuilder().addTxsMinGasPriceRule().blockStore(blockStore).build();
Assert.assertFalse(validator.isValid(block));
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class TransactionPoolImplTest method retractBlockAddsTransactionsAsPending.
@Test
public void retractBlockAddsTransactionsAsPending() {
BlockChainImpl blockchain = createBlockchain();
Coin balance = Coin.valueOf(1000000);
TransactionPoolImpl transactionPool = createSampleNewTransactionPoolWithAccounts(3, balance, blockchain);
transactionPool.processBest(blockchain.getBestBlock());
Transaction tx1 = createSampleTransaction(1, 2, 1000, 0);
Transaction tx2 = createSampleTransaction(1, 2, 3000, 1);
Transaction tx3 = createSampleTransaction(2, 3, 1000, 0);
Transaction tx4 = createSampleTransaction(2, 3, 3000, 1);
transactionPool.addTransaction(tx1);
transactionPool.addTransaction(tx2);
List<Transaction> txs = new ArrayList<>();
txs.add(tx3);
txs.add(tx4);
Block block = new BlockBuilder().parent(new BlockGenerator().getGenesisBlock()).transactions(txs).build();
transactionPool.retractBlock(block);
List<Transaction> alltxs = transactionPool.getPendingTransactions();
Assert.assertNotNull(alltxs);
Assert.assertFalse(alltxs.isEmpty());
Assert.assertEquals(4, alltxs.size());
Assert.assertTrue(alltxs.contains(tx1));
Assert.assertTrue(alltxs.contains(tx2));
Assert.assertTrue(alltxs.contains(tx3));
Assert.assertTrue(alltxs.contains(tx4));
List<Transaction> ptxs = transactionPool.getPendingTransactions();
Assert.assertNotNull(ptxs);
Assert.assertFalse(ptxs.isEmpty());
Assert.assertEquals(4, ptxs.size());
Assert.assertTrue(ptxs.contains(tx1));
Assert.assertTrue(ptxs.contains(tx2));
Assert.assertTrue(ptxs.contains(tx3));
Assert.assertTrue(ptxs.contains(tx4));
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class Web3ImplTest method getTransactionReceipt.
@Test
public void getTransactionReceipt() throws Exception {
ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
World world = new World(receiptStore);
Web3Impl web3 = createWeb3(world, receiptStore);
Account acc1 = new AccountBuilder(world).name("acc1").balance(Coin.valueOf(2000000)).build();
Account acc2 = new AccountBuilder().name("acc2").build();
Transaction tx = new TransactionBuilder().sender(acc1).receiver(acc2).value(BigInteger.valueOf(1000000)).build();
List<Transaction> txs = new ArrayList<>();
txs.add(tx);
Block genesis = world.getBlockChain().getBestBlock();
Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
org.junit.Assert.assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block1));
String hashString = tx.getHash().toHexString();
TransactionReceiptDTO tr = web3.eth_getTransactionReceipt(hashString);
org.junit.Assert.assertNotNull(tr);
org.junit.Assert.assertEquals("0x" + hashString, tr.transactionHash);
String trxFrom = TypeConverter.toJsonHex(tx.getSender().getBytes());
org.junit.Assert.assertEquals(trxFrom, tr.from);
String trxTo = TypeConverter.toJsonHex(tx.getReceiveAddress().getBytes());
org.junit.Assert.assertEquals(trxTo, tr.to);
String blockHashString = "0x" + block1.getHash();
org.junit.Assert.assertEquals(blockHashString, tr.blockHash);
String blockNumberAsHex = "0x" + Long.toHexString(block1.getNumber());
org.junit.Assert.assertEquals(blockNumberAsHex, tr.blockNumber);
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class Web3ImplTest method getUnknownTransactionByBlockNumberAndIndex.
@Test
public void getUnknownTransactionByBlockNumberAndIndex() throws Exception {
World world = new World();
Web3Impl web3 = createWeb3(world);
Block genesis = world.getBlockChain().getBestBlock();
Block block1 = new BlockBuilder(world).parent(genesis).build();
org.junit.Assert.assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block1));
TransactionResultDTO tr = web3.eth_getTransactionByBlockNumberAndIndex("0x1", "0x0");
Assert.assertNull(tr);
}
Aggregations