use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class BlockchainTest method connectOneChainThenConnectAnotherChain.
@Test
public void connectOneChainThenConnectAnotherChain() {
Blockchain blockchain = createBlockchain();
final int height = 200;
final long chain1Diff = 2;
final long chain2Diff = 1;
BlockGenerator blockGenerator = new BlockGenerator();
List<Block> chain1 = blockGenerator.getBlockChain(blockchain.getBestBlock(), height, chain1Diff);
List<Block> chain2 = blockGenerator.getBlockChain(blockchain.getBestBlock(), height, chain2Diff);
for (Block b : chain1) Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(b));
for (Block b : chain2) Assert.assertEquals(ImportResult.IMPORTED_NOT_BEST, blockchain.tryToConnect(b));
Block newblock = blockGenerator.createChildBlock(chain2.get(chain2.size() - 1), 0, 2 * height * chain2Diff);
Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(newblock));
Assert.assertEquals(blockchain.getBestBlock(), newblock);
Assert.assertEquals(chain2.size() + 1, newblock.getNumber());
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class BlockchainTest method childBlock.
@Test
public void childBlock() {
Blockchain blockchain = createBlockchain();
Block block = new BlockGenerator().createChildBlock(blockchain.getBestBlock());
Assert.assertNotNull(block);
Assert.assertEquals(1, block.getNumber());
Assert.assertEquals(blockchain.getBestBlock().getHash(), block.getParentHash());
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class BlockchainTest method addTwoBlocks.
@Test
public void addTwoBlocks() {
Blockchain blockchain = createBlockchain();
BlockGenerator blockGenerator = new BlockGenerator();
Block block1 = blockGenerator.createChildBlock(blockchain.getBestBlock());
Block block2 = blockGenerator.createChildBlock(block1);
blockchain.tryToConnect(block1);
blockchain.tryToConnect(block2);
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 tryToConnectWithFork.
@Test
public void tryToConnectWithFork() {
Blockchain blockchain = createBlockchain();
BlockGenerator blockGenerator = new BlockGenerator();
Block block1 = blockGenerator.createChildBlock(blockchain.getBestBlock(), 0, 1);
Block block1b = blockGenerator.createChildBlock(blockchain.getBestBlock(), 0, 2);
Block block2 = blockGenerator.createChildBlock(block1, 0, 3);
Block block2b = blockGenerator.createChildBlock(block1b, 0, 1);
Block block3b = blockGenerator.createChildBlock(block2b, 0, 4);
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.IMPORTED_NOT_BEST, blockchain.tryToConnect(block2b));
Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(block3b));
Assert.assertEquals(blockchain.getBestBlock(), block3b);
Assert.assertEquals(3, block3b.getNumber());
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class FileBlockRecorderTest method writeBlock.
@Test
public void writeBlock() throws Exception {
FileBlockRecorder recorder = new FileBlockRecorder("testrecorder.txt");
recorder.writeBlock(new BlockGenerator().getGenesisBlock());
File file = new File("testrecorder.txt");
Assert.assertTrue(file.exists());
recorder.close();
Assert.assertTrue(file.delete());
}
Aggregations