use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class BridgeUtilsTest method isFreeBridgeTx.
private void isFreeBridgeTx(boolean expected, RskAddress destinationAddress, byte[] privKeyBytes) {
Bridge bridge = new Bridge(config, PrecompiledContracts.BRIDGE_ADDR);
org.ethereum.core.Transaction rskTx = CallTransaction.createCallTransaction(config, 0, 1, 1, destinationAddress, 0, Bridge.UPDATE_COLLECTIONS);
rskTx.sign(privKeyBytes);
Block rskExecutionBlock = new BlockGenerator().createChildBlock(Genesis.getInstance(config));
bridge.init(rskTx, rskExecutionBlock, null, null, null, null);
Assert.assertEquals(expected, BridgeUtils.isFreeBridgeTx(config, rskTx, rskExecutionBlock.getNumber()));
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class BlockStoreTest method releaseRange.
@Test
public void releaseRange() {
BlockStore store = new BlockStore();
final BlockGenerator generator = new BlockGenerator();
Block genesis = generator.getGenesisBlock();
List<Block> blocks1 = generator.getBlockChain(genesis, 1000);
List<Block> blocks2 = generator.getBlockChain(genesis, 1000);
for (Block b : blocks1) store.saveBlock(b);
for (Block b : blocks2) store.saveBlock(b);
Assert.assertEquals(2000, store.size());
store.releaseRange(1, 1000);
Assert.assertEquals(0, store.size());
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class BlockStoreTest method saveAndGetBlockByHash.
@Test
public void saveAndGetBlockByHash() {
BlockStore store = new BlockStore();
Block block = new BlockGenerator().getGenesisBlock();
store.saveBlock(block);
Assert.assertSame(block, store.getBlockByHash(block.getHash().getBytes()));
Assert.assertEquals(0, store.minimalHeight());
Assert.assertEquals(0, store.maximumHeight());
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class BlockStoreTest method saveAndGetBlocksByNumber.
@Test
public void saveAndGetBlocksByNumber() {
BlockStore store = new BlockStore();
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block block1 = blockGenerator.createChildBlock(genesis);
Block block2 = blockGenerator.createChildBlock(genesis);
store.saveBlock(block1);
store.saveBlock(block2);
List<Block> blocks = store.getBlocksByNumber(1);
Assert.assertTrue(blocks.contains(block1));
Assert.assertTrue(blocks.contains(block2));
Assert.assertEquals(2, store.size());
Assert.assertEquals(1, store.minimalHeight());
Assert.assertEquals(1, store.maximumHeight());
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class BlockStoreTest method saveTwoBlocksRemoveOne.
@Test
public void saveTwoBlocksRemoveOne() {
BlockStore store = new BlockStore();
BlockGenerator blockGenerator = new BlockGenerator();
Block parent = blockGenerator.getGenesisBlock();
Block adam = blockGenerator.createChildBlock(parent);
Block eve = blockGenerator.createChildBlock(adam);
store.saveBlock(adam);
store.saveBlock(eve);
Assert.assertEquals(1, store.minimalHeight());
Assert.assertEquals(2, store.maximumHeight());
store.removeBlock(adam);
Assert.assertNull(store.getBlockByHash(adam.getHash().getBytes()));
Assert.assertEquals(1, store.size());
Assert.assertEquals(2, store.minimalHeight());
Assert.assertEquals(2, store.maximumHeight());
List<Block> childrenByNumber = store.getBlocksByNumber(eve.getNumber());
Assert.assertNotNull(childrenByNumber);
Assert.assertEquals(1, childrenByNumber.size());
Assert.assertEquals(eve.getHash(), childrenByNumber.get(0).getHash());
List<Block> childrenByParent = store.getBlocksByParentHash(adam.getHash());
Assert.assertNotNull(childrenByParent);
Assert.assertEquals(1, childrenByParent.size());
Assert.assertEquals(eve.getHash(), childrenByParent.get(0).getHash());
Block daugther = store.getBlockByHash(eve.getHash().getBytes());
Assert.assertNotNull(daugther);
Assert.assertEquals(eve.getHash(), daugther.getHash());
}
Aggregations