use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class Web3ImplTest method getBlockByNumberRetrieveEarliestBlock.
@Test
public void getBlockByNumberRetrieveEarliestBlock() {
World world = new World();
Web3Impl web3 = createWeb3(world);
Block genesis = world.getBlockChain().getBestBlock();
Block block1 = new BlockBuilder(world.getBlockChain(), world.getBridgeSupportFactory(), world.getBlockStore()).trieStore(world.getTrieStore()).parent(genesis).build();
assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block1));
String bnOrId = "earliest";
BlockResultDTO blockResult = web3.eth_getBlockByNumber(bnOrId, false);
assertNotNull(blockResult);
String blockHash = genesis.getHashJsonString();
assertEquals(blockHash, blockResult.getHash());
String hexString = web3.rsk_getRawBlockHeaderByNumber(bnOrId).replace("0x", "");
Keccak256 obtainedBlockHash = new Keccak256(HashUtil.keccak256(Hex.decode(hexString)));
assertEquals(blockHash, obtainedBlockHash.toJsonString());
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class AsyncNodeBlockProcessorUnclesTest method addBlockWithTwoKnownUncles.
@Test(timeout = WAIT_TIME)
public void addBlockWithTwoKnownUncles() throws InterruptedException {
org.ethereum.db.BlockStore blockStore = blockChainBuilder.getBlockStore();
Block genesis = blockChain.getBestBlock();
BlockBuilder blockBuilder = new BlockBuilder(blockChain, null, blockStore).trieStore(blockChainBuilder.getTrieStore());
blockBuilder.parent(blockChain.getBestBlock());
Block block1 = blockBuilder.parent(genesis).build();
Block uncle1 = blockBuilder.parent(genesis).build();
Block uncle2 = blockBuilder.parent(genesis).build();
List<BlockHeader> uncles = new ArrayList<>();
uncles.add(uncle1.getHeader());
uncles.add(uncle2.getHeader());
Block block2 = blockBuilder.parent(block1).uncles(uncles).build();
processor.processBlock(null, block1);
processor.processBlock(null, uncle1);
processor.processBlock(null, uncle2);
SimplePeer sender = new SimplePeer();
processor.processBlock(sender, block2);
listener.waitForBlock(block2.getHash());
Assert.assertEquals(2, blockChain.getBestBlock().getNumber());
Assert.assertArrayEquals(block2.getHash().getBytes(), blockChain.getBestBlockHash());
Assert.assertTrue(sender.getGetBlockMessages().isEmpty());
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class AsyncNodeBlockProcessorUnclesTest method rejectBlockWithTwoUnknownUnclesAndUnknownParent.
@Test
public void rejectBlockWithTwoUnknownUnclesAndUnknownParent() throws InterruptedException {
Block genesis = blockChain.getBestBlock();
Block block1 = new BlockBuilder(null, null, null).parent(genesis).build();
Block uncle1 = new BlockBuilder(null, null, null).parent(genesis).build();
Block uncle2 = new BlockBuilder(null, null, null).parent(genesis).build();
List<BlockHeader> uncles = new ArrayList<>();
uncles.add(uncle1.getHeader());
uncles.add(uncle2.getHeader());
Block block2 = new BlockBuilder(null, null, null).parent(block1).uncles(uncles).build();
SimplePeer sender = new SimplePeer();
processor.processBlock(sender, block2);
Assert.assertEquals(0, blockChain.getBestBlock().getNumber());
Assert.assertArrayEquals(genesis.getHash().getBytes(), blockChain.getBestBlockHash());
Assert.assertEquals(1, sender.getGetBlockMessages().size());
Assert.assertTrue(sender.getGetBlockMessagesHashes().contains(block1.getHash()));
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class AsyncNodeBlockProcessorUnclesTest method addBlockWithoutUncles.
@Test(timeout = WAIT_TIME)
public void addBlockWithoutUncles() throws InterruptedException {
Block genesis = blockChain.getBestBlock();
Block block1 = new BlockBuilder(null, null, null).parent(genesis).build();
processor.processBlock(null, block1);
listener.waitForBlock(block1.getHash());
Assert.assertEquals(1, blockChain.getBestBlock().getNumber());
Assert.assertArrayEquals(block1.getHash().getBytes(), blockChain.getBestBlockHash());
}
use of co.rsk.test.builders.BlockBuilder in project rskj by rsksmart.
the class NodeBlockProcessorUnclesTest method addBlockWithTwoUnknownUncles.
@Test
public void addBlockWithTwoUnknownUncles() {
BlockChainBuilder blockChainBuilder = new BlockChainBuilder();
BlockChainImpl blockChain = blockChainBuilder.build();
org.ethereum.db.BlockStore blockStore = blockChainBuilder.getBlockStore();
NodeBlockProcessor processor = createNodeBlockProcessor(blockChain);
Block genesis = blockChain.getBestBlock();
BlockBuilder blockBuilder = new BlockBuilder(blockChain, null, blockStore).trieStore(blockChainBuilder.getTrieStore());
blockBuilder.parent(blockChain.getBestBlock());
Block block1 = blockBuilder.parent(genesis).build();
Block uncle1 = blockBuilder.parent(genesis).build();
Block uncle2 = blockBuilder.parent(genesis).build();
List<BlockHeader> uncles = new ArrayList<>();
uncles.add(uncle1.getHeader());
uncles.add(uncle2.getHeader());
Block block2 = blockBuilder.parent(block1).uncles(uncles).build();
processor.processBlock(null, block1);
SimplePeer sender = new SimplePeer();
processor.processBlock(sender, block2);
Assert.assertEquals(2, blockChain.getBestBlock().getNumber());
Assert.assertArrayEquals(block2.getHash().getBytes(), blockChain.getBestBlockHash());
Assert.assertEquals(0, sender.getGetBlockMessages().size());
}
Aggregations