Search in sources :

Example 16 with BlockStore

use of org.ethereum.db.BlockStore in project rskj by rsksmart.

the class FamilyUtilsTest method getFamilyGetParent.

@Test
public void getFamilyGetParent() {
    BlockStore store = createBlockStore();
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    Block block1 = blockGenerator.createChildBlock(genesis);
    store.saveBlock(genesis, TEST_DIFFICULTY, true);
    store.saveBlock(block1, TEST_DIFFICULTY, true);
    Set<Keccak256> family = FamilyUtils.getFamily(store, block1, 6);
    Assert.assertNotNull(family);
    Assert.assertFalse(family.isEmpty());
    Assert.assertEquals(1, family.size());
    Assert.assertTrue(family.contains(genesis.getHash()));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockStore(org.ethereum.db.BlockStore) Block(org.ethereum.core.Block) Keccak256(co.rsk.crypto.Keccak256) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 17 with BlockStore

use of org.ethereum.db.BlockStore in project rskj by rsksmart.

the class FamilyUtilsTest method getUncles.

@Test
public void getUncles() {
    BlockStore store = createBlockStore();
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    Block block1 = blockGenerator.createChildBlock(genesis);
    Block uncle11 = blockGenerator.createChildBlock(genesis);
    Block uncle12 = blockGenerator.createChildBlock(genesis);
    Block block2 = blockGenerator.createChildBlock(block1);
    Block uncle21 = blockGenerator.createChildBlock(block1);
    Block uncle22 = blockGenerator.createChildBlock(block1);
    Block block3 = blockGenerator.createChildBlock(block2);
    Block uncle31 = blockGenerator.createChildBlock(block2);
    Block uncle32 = blockGenerator.createChildBlock(block2);
    store.saveBlock(genesis, TEST_DIFFICULTY, true);
    store.saveBlock(block1, TEST_DIFFICULTY, true);
    store.saveBlock(uncle11, TEST_DIFFICULTY, false);
    store.saveBlock(uncle12, TEST_DIFFICULTY, false);
    store.saveBlock(block2, TEST_DIFFICULTY, true);
    store.saveBlock(uncle21, TEST_DIFFICULTY, false);
    store.saveBlock(uncle22, TEST_DIFFICULTY, false);
    store.saveBlock(block3, TEST_DIFFICULTY, true);
    store.saveBlock(uncle31, TEST_DIFFICULTY, false);
    store.saveBlock(uncle32, TEST_DIFFICULTY, false);
    Set<Keccak256> family = FamilyUtils.getUncles(store, block3, 3);
    Assert.assertNotNull(family);
    Assert.assertFalse(family.isEmpty());
    Assert.assertEquals(4, family.size());
    Assert.assertFalse(family.contains(genesis.getHash()));
    Assert.assertFalse(family.contains(block1.getHash()));
    Assert.assertTrue(family.contains(uncle11.getHash()));
    Assert.assertTrue(family.contains(uncle12.getHash()));
    Assert.assertFalse(family.contains(block2.getHash()));
    Assert.assertTrue(family.contains(uncle21.getHash()));
    Assert.assertTrue(family.contains(uncle22.getHash()));
    Assert.assertFalse(family.contains(block3.getHash()));
    Assert.assertFalse(family.contains(uncle31.getHash()));
    Assert.assertFalse(family.contains(uncle32.getHash()));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockStore(org.ethereum.db.BlockStore) Block(org.ethereum.core.Block) Keccak256(co.rsk.crypto.Keccak256) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 18 with BlockStore

use of org.ethereum.db.BlockStore in project rskj by rsksmart.

the class BlockForkTest method calculateParentChild.

@Test
public void calculateParentChild() {
    BlockStore store = createBlockStore();
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    Block block = blockGenerator.createChildBlock(genesis);
    store.saveBlock(genesis, TEST_DIFFICULTY, true);
    store.saveBlock(block, TEST_DIFFICULTY, true);
    BlockFork fork = new BlockFork();
    fork.calculate(genesis, block, store);
    Assert.assertSame(genesis, fork.getCommonAncestor());
    Assert.assertTrue(fork.getOldBlocks().isEmpty());
    Assert.assertFalse(fork.getNewBlocks().isEmpty());
    Assert.assertEquals(1, fork.getNewBlocks().size());
    Assert.assertSame(block, fork.getNewBlocks().get(0));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockStore(org.ethereum.db.BlockStore) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 19 with BlockStore

use of org.ethereum.db.BlockStore in project rskj by rsksmart.

the class BlockForkTest method calculateForkLengthTwoOldThreeNew.

@Test
public void calculateForkLengthTwoOldThreeNew() {
    BlockStore store = createBlockStore();
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    Block parent = blockGenerator.createChildBlock(genesis);
    store.saveBlock(genesis, TEST_DIFFICULTY, true);
    store.saveBlock(parent, TEST_DIFFICULTY, true);
    List<Block> oldBranch = makeChain(parent, 2, store, blockGenerator);
    List<Block> newBranch = makeChain(parent, 3, store, blockGenerator);
    BlockFork fork = new BlockFork();
    fork.calculate(oldBranch.get(1), newBranch.get(2), store);
    Assert.assertEquals(parent.getHash(), fork.getCommonAncestor().getHash());
    Assert.assertFalse(fork.getOldBlocks().isEmpty());
    Assert.assertEquals(2, fork.getOldBlocks().size());
    Assert.assertEquals(oldBranch.get(0).getHash(), fork.getOldBlocks().get(0).getHash());
    Assert.assertEquals(oldBranch.get(1).getHash(), fork.getOldBlocks().get(1).getHash());
    Assert.assertFalse(fork.getNewBlocks().isEmpty());
    Assert.assertEquals(3, fork.getNewBlocks().size());
    Assert.assertEquals(newBranch.get(0).getHash(), fork.getNewBlocks().get(0).getHash());
    Assert.assertEquals(newBranch.get(1).getHash(), fork.getNewBlocks().get(1).getHash());
    Assert.assertEquals(newBranch.get(2).getHash(), fork.getNewBlocks().get(2).getHash());
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockStore(org.ethereum.db.BlockStore) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 20 with BlockStore

use of org.ethereum.db.BlockStore in project rskj by rsksmart.

the class BlockUnclesValidationRuleTest method rejectBlockWithUncleHavingHigherNumber.

@Test
public void rejectBlockWithUncleHavingHigherNumber() {
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    Block block1 = blockGenerator.createChildBlock(genesis);
    Block uncle1 = blockGenerator.createChildBlock(block1);
    Block uncle2 = blockGenerator.createChildBlock(uncle1);
    List<BlockHeader> uncles = new ArrayList<>();
    uncles.add(uncle2.getHeader());
    Block block = blockGenerator.createChildBlock(block1, null, uncles, 1, null);
    BlockChainImpl blockChain = BlockChainImplTest.createBlockChain();
    BlockStore store = blockChain.getBlockStore();
    store.saveBlock(genesis, new BlockDifficulty(BigInteger.valueOf(1)), true);
    store.saveBlock(block1, new BlockDifficulty(BigInteger.valueOf(2)), true);
    BlockUnclesValidationRule rule = new BlockUnclesValidationRule(config, store, 10, 10, new BlockCompositeRule(), new BlockParentCompositeRule());
    Assert.assertFalse(rule.isValid(block));
}
Also used : BlockDifficulty(co.rsk.core.BlockDifficulty) BlockStore(org.ethereum.db.BlockStore) ArrayList(java.util.ArrayList) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) Block(org.ethereum.core.Block) BlockHeader(org.ethereum.core.BlockHeader) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test) BlockChainImplTest(co.rsk.core.bc.BlockChainImplTest)

Aggregations

BlockStore (org.ethereum.db.BlockStore)24 Test (org.junit.Test)20 Block (org.ethereum.core.Block)17 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)15 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)14 Keccak256 (co.rsk.crypto.Keccak256)7 ArrayList (java.util.ArrayList)5 RskSystemProperties (co.rsk.config.RskSystemProperties)4 BlockHeader (org.ethereum.core.BlockHeader)4 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)3 BlockChainImplTest (co.rsk.core.bc.BlockChainImplTest)3 SimpleBlock (co.rsk.peg.simples.SimpleBlock)3 PersonalModule (co.rsk.rpc.modules.personal.PersonalModule)3 BlockBuilder (co.rsk.test.builders.BlockBuilder)3 BlockDifficulty (co.rsk.core.BlockDifficulty)2 RemascTransaction (co.rsk.remasc.RemascTransaction)2 PersonalModuleWalletDisabled (co.rsk.rpc.modules.personal.PersonalModuleWalletDisabled)2 TxPoolModule (co.rsk.rpc.modules.txpool.TxPoolModule)2 TxPoolModuleImpl (co.rsk.rpc.modules.txpool.TxPoolModuleImpl)2 Repository (org.ethereum.core.Repository)2