use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class Web3ImplLogsTest method getWeb3WithContractCall.
private Web3Impl getWeb3WithContractCall(World world) {
Account acc1 = new AccountBuilder(world).name("notDefault").balance(Coin.valueOf(10000000)).build();
// acc1 Account created address should be 661b05ca9eb621164906671efd2731ce0d7dd8b4
Block genesis = world.getBlockByName("g00");
Transaction tx;
tx = getContractTransaction(acc1);
List<Transaction> txs = new ArrayList<>();
txs.add(tx);
BlockChainImpl blockChain = world.getBlockChain();
Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(block1));
byte[] contractAddress = tx.getContractAddress().getBytes();
// Now create a transaction that invokes Increment()
Transaction tx2 = getContractTransactionWithInvoke(acc1, contractAddress);
List<Transaction> tx2s = new ArrayList<>();
tx2s.add(tx2);
Block block2 = new BlockBuilder(world).parent(block1).transactions(tx2s).build();
Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(block2));
Transaction tx3 = getContractTransactionWithCall(acc1, contractAddress);
List<Transaction> tx3s = new ArrayList<>();
tx3s.add(tx3);
Block block3 = new BlockBuilder(world).parent(block2).transactions(tx3s).build();
Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(block3));
TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), blockChain.getBlockStore(), null, null, null, 10, 100);
Web3Impl web3 = createWeb3(world.getBlockChain(), transactionPool);
web3.personal_newAccountWithSeed("default");
web3.personal_newAccountWithSeed("notDefault");
return web3;
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class BlockValidatorTest method validateEmptyBlock.
@Test
public void validateEmptyBlock() {
IndexedBlockStore blockStore = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
Block genesis = new BlockGenerator().getGenesisBlock();
blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
Block block = new BlockBuilder().parent(genesis).build();
BlockValidator validator = createValidator(blockStore);
Assert.assertTrue(validator.isValid(block));
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class BlockValidatorTest method remascTxNotInLastPosition.
@Test
public void remascTxNotInLastPosition() {
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
List<Transaction> txs = new ArrayList<>();
Transaction tx = Transaction.create(config, "0000000000000000000000000000000000000006", BigInteger.ZERO, BigInteger.ZERO, BigInteger.valueOf(12L), BigInteger.TEN);
tx.sign(new byte[] {});
txs.add(new RemascTransaction(BigInteger.ONE.longValue()));
txs.add(tx);
Block block = new BlockBuilder().parent(genesis).transactions(txs).build();
BlockValidatorImpl validator = new BlockValidatorBuilder().addRemascValidationRule().build();
Assert.assertFalse(validator.isValid(block));
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class BlockValidatorTest method validateHeader.
@Test
public void validateHeader() {
IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block parent = new BlockBuilder().parent(genesis).build();
Block block = new BlockBuilder().parent(parent).build();
store.saveBlock(parent, TEST_DIFFICULTY, true);
BlockValidatorImpl validator = new BlockValidatorBuilder().addParentBlockHeaderValidator().addBlockRootValidationRule().addBlockUnclesValidationRule(null).blockStore(store).build();
Assert.assertTrue(validator.isValid(block));
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class BlockValidatorTest method invalidTxNonce.
@Test
public void invalidTxNonce() {
BlockChainImpl blockChain = BlockChainImplTest.createBlockChain();
Block genesis = BlockChainImplTest.getGenesisBlock(blockChain);
List<Transaction> txs = new ArrayList<>();
Transaction tx = Transaction.create(config, "0000000000000000000000000000000000000006", BigInteger.ZERO, BigInteger.TEN, BigInteger.valueOf(12L), BigInteger.TEN);
tx.sign(new byte[] {});
txs.add(tx);
Block block = new BlockBuilder().parent(genesis).transactions(txs).build();
block.getHeader().setNumber(25L);
BlockValidatorImpl validator = new BlockValidatorBuilder().addBlockTxsValidationRule(blockChain.getRepository()).build();
Assert.assertFalse(validator.isValid(block));
}
Aggregations