use of org.ethereum.core.Blockchain 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);
}
use of org.ethereum.core.Blockchain 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 org.ethereum.core.Blockchain 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 org.ethereum.core.Blockchain 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 org.ethereum.core.Blockchain 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());
}
Aggregations