use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class WorldTest method saveAndGetBlock.
@Test
public void saveAndGetBlock() {
World world = new World();
Block block = new BlockGenerator().getBlock(1);
world.saveBlock("b01", block);
Assert.assertSame(block, world.getBlockByName("b01"));
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class BlockBuilderTest method buildBlockWithDifficulty.
@Test
public void buildBlockWithDifficulty() {
Block genesis = new BlockGenerator().getGenesisBlock();
BlockBuilder builder = new BlockBuilder();
Block block = builder.parent(genesis).difficulty(1).build();
Assert.assertNotNull(block);
Assert.assertEquals(1, block.getNumber());
Assert.assertEquals(BigInteger.ONE, block.getDifficulty().asBigInteger());
Assert.assertEquals(genesis.getHash(), block.getParentHash());
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class BlockchainTest method tryToConnectWithCompetingChain.
@Test
public void tryToConnectWithCompetingChain() {
// Two competing blockchains of the same size (2)
Blockchain blockchain = createBlockchain();
BlockGenerator blockGenerator = new BlockGenerator();
Block block1 = blockGenerator.createChildBlock(blockchain.getBestBlock());
Block block2 = blockGenerator.createChildBlock(block1, 0, 5);
Block block1b = blockGenerator.createChildBlock(blockchain.getBestBlock());
Block block2b = blockGenerator.createChildBlock(block1b, 0, 4);
// genesis <- block1 <- block2
// genesis <- block1b <- block2b
Assert.assertEquals(ImportResult.NO_PARENT, blockchain.tryToConnect(block2));
Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(block1));
Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(block2));
Assert.assertEquals(ImportResult.IMPORTED_NOT_BEST, blockchain.tryToConnect(block1b));
Assert.assertEquals(ImportResult.EXIST, blockchain.tryToConnect(block1));
Assert.assertEquals(ImportResult.EXIST, blockchain.tryToConnect(block1b));
Assert.assertEquals(ImportResult.IMPORTED_NOT_BEST, blockchain.tryToConnect(block2b));
Assert.assertEquals(blockchain.getBestBlock(), block2);
Assert.assertEquals(2, block2.getNumber());
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class BlockchainTest method checkItDoesntAddAnInvalidBlock.
@Test
public void checkItDoesntAddAnInvalidBlock() {
Blockchain blockchain = createBlockchain();
BlockGenerator blockGenerator = new BlockGenerator();
Block block1 = blockGenerator.createChildBlock(blockchain.getBestBlock());
ImportResult importResult1 = blockchain.tryToConnect(block1);
assertTrue(importResult1.isSuccessful());
Block block2 = blockGenerator.createChildBlock(blockchain.getBestBlock());
Block block2b = blockGenerator.createBlock(10, 5);
Block block3 = Block.fromValidData(block2.getHeader(), block2b.getTransactionsList(), block2b.getUncleList());
ImportResult importResult2 = blockchain.tryToConnect(block3);
Assert.assertFalse(importResult2.isSuccessful());
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class BlockchainTest method addFirstBlock.
@Test
public void addFirstBlock() {
Blockchain blockchain = createBlockchain();
Block block = new BlockGenerator().createChildBlock(blockchain.getBestBlock());
blockchain.tryToConnect(block);
Assert.assertEquals(blockchain.getBestBlock(), block);
}
Aggregations