use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class BlockValidatorTest method validateBlockWithTransaction.
@Test
public void validateBlockWithTransaction() {
BlockChainImpl blockChain = BlockChainImplTest.createBlockChain();
Block genesis = BlockChainImplTest.getGenesisBlock(blockChain);
genesis.seal();
Block parent = new BlockBuilder().parent(genesis).build();
parent.seal();
List<Transaction> txs = new ArrayList<>();
txs.add(BlockExecutorTest.generateBlockWithOneTransaction().getTransaction());
Block block = new BlockBuilder().parent(parent).transactions(txs).build();
;
block.seal();
Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(genesis));
Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(parent));
BlockValidator validator = createValidator(blockChain.getBlockStore());
Assert.assertTrue(validator.isValid(block));
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class BlockValidatorTest method parentInvalidNumber.
@Test
public void parentInvalidNumber() {
IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block block = new BlockBuilder().parent(genesis).build();
block.getHeader().setNumber(25L);
BlockValidatorImpl validator = new BlockValidatorBuilder().addParentNumberRule().blockStore(store).build();
Assert.assertFalse(validator.isValid(block));
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class Web3ImplLogsTest method getWorld3WithBlockWithEventInContractCreation.
public static World getWorld3WithBlockWithEventInContractCreation(RskSystemProperties config, ReceiptStore receiptStore) {
World world = new World(receiptStore);
Account acc1 = new AccountBuilder(world).name("notDefault").balance(Coin.valueOf(10000000)).build();
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();
blockChain.tryToConnect(block1);
return world;
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class Web3ImplLogsTest method getWeb3WithContractCreationWithoutEvents.
private Web3Impl getWeb3WithContractCreationWithoutEvents() {
World world = new World();
Account acc1 = new AccountBuilder(world).name("notDefault").balance(Coin.valueOf(10000000)).build();
Block genesis = world.getBlockByName("g00");
/* contract compiled in data attribute of tx
contract greeter {
address owner;
modifier onlyOwner { if (msg.sender != owner) throw; _ ; }
function greeter() public {
owner = msg.sender;
}
function greet(string param) onlyOwner constant returns (string) {
return param;
}
} */
Transaction tx = new TransactionBuilder().sender(acc1).gasLimit(BigInteger.valueOf(100000)).gasPrice(BigInteger.ONE).data(compiledGreeter).build();
List<Transaction> txs = new ArrayList<>();
txs.add(tx);
BlockChainImpl blockChain = world.getBlockChain();
Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
blockChain.tryToConnect(block1);
TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), blockChain.getBlockStore(), null, null, null, 10, 100);
Web3Impl web3 = createWeb3(world.getBlockChain(), transactionPool);
web3.personal_newAccountWithSeed("notDefault");
return web3;
}
Aggregations