Search in sources :

Example 6 with BlockGenerator

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()));
}
Also used : co.rsk.bitcoinj.core(co.rsk.bitcoinj.core) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator)

Example 7 with BlockGenerator

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());
}
Also used : Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 8 with BlockGenerator

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());
}
Also used : Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 9 with BlockGenerator

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());
}
Also used : Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 10 with BlockGenerator

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());
}
Also used : Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Aggregations

BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)250 Test (org.junit.Test)237 Block (org.ethereum.core.Block)104 ArrayList (java.util.ArrayList)39 Blockchain (org.ethereum.core.Blockchain)38 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)36 RskSystemProperties (co.rsk.config.RskSystemProperties)35 SimpleBlock (co.rsk.peg.simples.SimpleBlock)34 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)33 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)31 HashMapDB (org.ethereum.datasource.HashMapDB)22 BlockBuilder (co.rsk.test.builders.BlockBuilder)17 Keccak256 (co.rsk.crypto.Keccak256)15 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)15 BlockStore (org.ethereum.db.BlockStore)15 World (co.rsk.test.World)14 RepositoryImpl (co.rsk.db.RepositoryImpl)13 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)13 Ignore (org.junit.Ignore)12 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)10