Search in sources :

Example 81 with Keccak256

use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.

the class BlockValidatorTest method getUsedUncles.

@Test
public void getUsedUncles() {
    IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    Block uncle1a = blockGenerator.createChildBlock(genesis);
    Block uncle1b = blockGenerator.createChildBlock(genesis);
    List<BlockHeader> uncles1 = new ArrayList<>();
    uncles1.add(uncle1a.getHeader());
    uncles1.add(uncle1b.getHeader());
    Block block1 = blockGenerator.createChildBlock(genesis, null, uncles1, 1, null);
    Block uncle2a = blockGenerator.createChildBlock(genesis);
    Block uncle2b = blockGenerator.createChildBlock(genesis);
    List<BlockHeader> uncles2 = new ArrayList<>();
    uncles2.add(uncle2a.getHeader());
    uncles2.add(uncle2b.getHeader());
    Block block2 = blockGenerator.createChildBlock(block1, null, uncles2, 1, null);
    Block block3 = blockGenerator.createChildBlock(block2, null, uncles2, 1, null);
    store.saveBlock(genesis, TEST_DIFFICULTY, true);
    store.saveBlock(uncle1a, TEST_DIFFICULTY, false);
    store.saveBlock(uncle1b, TEST_DIFFICULTY, false);
    store.saveBlock(block1, TEST_DIFFICULTY, true);
    store.saveBlock(uncle2a, TEST_DIFFICULTY, false);
    store.saveBlock(uncle2b, TEST_DIFFICULTY, false);
    store.saveBlock(block2, TEST_DIFFICULTY, true);
    Set<Keccak256> used = FamilyUtils.getUsedUncles(store, block3, 6);
    Assert.assertFalse(used.isEmpty());
    Assert.assertFalse(used.contains(block3.getHash()));
    Assert.assertFalse(used.contains(block2.getHash()));
    Assert.assertTrue(used.contains(uncle2a.getHash()));
    Assert.assertTrue(used.contains(uncle2b.getHash()));
    Assert.assertFalse(used.contains(block1.getHash()));
    Assert.assertTrue(used.contains(uncle1a.getHash()));
    Assert.assertTrue(used.contains(uncle1b.getHash()));
    Assert.assertFalse(used.contains(genesis.getHash()));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) ArrayList(java.util.ArrayList) SimpleBlock(co.rsk.peg.simples.SimpleBlock) Keccak256(co.rsk.crypto.Keccak256) HashMapDB(org.ethereum.datasource.HashMapDB) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 82 with Keccak256

use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.

the class BlockValidatorTest method getThreeAncestorSet.

@Test
public void getThreeAncestorSet() {
    IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    store.saveBlock(genesis, TEST_DIFFICULTY, true);
    Block block1 = blockGenerator.createChildBlock(genesis);
    store.saveBlock(block1, TEST_DIFFICULTY, true);
    Block block2 = blockGenerator.createChildBlock(block1);
    store.saveBlock(block2, TEST_DIFFICULTY, true);
    Block block3 = blockGenerator.createChildBlock(block2);
    store.saveBlock(block3, TEST_DIFFICULTY, true);
    Block block4 = blockGenerator.createChildBlock(block3);
    store.saveBlock(block4, TEST_DIFFICULTY, true);
    Block block5 = blockGenerator.createChildBlock(block4);
    store.saveBlock(block5, TEST_DIFFICULTY, true);
    Set<Keccak256> ancestors = FamilyUtils.getAncestors(store, block5, 3);
    Assert.assertFalse(ancestors.isEmpty());
    Assert.assertEquals(3, ancestors.size());
    Assert.assertFalse(ancestors.contains(genesis.getHash()));
    Assert.assertFalse(ancestors.contains(block1.getHash()));
    Assert.assertTrue(ancestors.contains(block2.getHash()));
    Assert.assertTrue(ancestors.contains(block3.getHash()));
    Assert.assertTrue(ancestors.contains(block4.getHash()));
    Assert.assertFalse(ancestors.contains(block5.getHash()));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) SimpleBlock(co.rsk.peg.simples.SimpleBlock) Keccak256(co.rsk.crypto.Keccak256) HashMapDB(org.ethereum.datasource.HashMapDB) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 83 with Keccak256

use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.

the class BlockValidatorTest method getBlockOneAncestorSet.

@Test
public void getBlockOneAncestorSet() {
    IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    store.saveBlock(genesis, TEST_DIFFICULTY, true);
    Block block = new BlockGenerator().createChildBlock(genesis);
    Set<Keccak256> ancestors = FamilyUtils.getAncestors(store, block, 6);
    Assert.assertFalse(ancestors.isEmpty());
    Assert.assertTrue(ancestors.contains(genesis.getHash()));
    Assert.assertFalse(ancestors.contains(block.getHash()));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) SimpleBlock(co.rsk.peg.simples.SimpleBlock) Keccak256(co.rsk.crypto.Keccak256) HashMapDB(org.ethereum.datasource.HashMapDB) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 84 with Keccak256

use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.

the class FamilyUtilsTest method getFamilyGetAncestorsUpToLevel.

@Test
public void getFamilyGetAncestorsUpToLevel() {
    BlockStore store = createBlockStore();
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    Block block1 = blockGenerator.createChildBlock(genesis);
    Block block2 = blockGenerator.createChildBlock(block1);
    Block block3 = blockGenerator.createChildBlock(block2);
    store.saveBlock(genesis, TEST_DIFFICULTY, true);
    store.saveBlock(block1, TEST_DIFFICULTY, true);
    store.saveBlock(block2, TEST_DIFFICULTY, true);
    store.saveBlock(block3, TEST_DIFFICULTY, true);
    Set<Keccak256> family = FamilyUtils.getFamily(store, block3, 2);
    Assert.assertNotNull(family);
    Assert.assertFalse(family.isEmpty());
    Assert.assertEquals(2, family.size());
    Assert.assertFalse(family.contains(genesis.getHash()));
    Assert.assertFalse(family.contains(block3.getHash()));
    Assert.assertTrue(family.contains(block1.getHash()));
    Assert.assertTrue(family.contains(block2.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 85 with Keccak256

use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.

the class FamilyUtilsTest method getEmptyFamilyForGenesis.

@Test
public void getEmptyFamilyForGenesis() {
    BlockStore store = createBlockStore();
    Block genesis = new BlockGenerator().getGenesisBlock();
    store.saveBlock(genesis, TEST_DIFFICULTY, true);
    Set<Keccak256> family = FamilyUtils.getFamily(store, genesis, 6);
    Assert.assertNotNull(family);
    Assert.assertTrue(family.isEmpty());
}
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)

Aggregations

Keccak256 (co.rsk.crypto.Keccak256)102 Test (org.junit.Test)53 Block (org.ethereum.core.Block)40 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)15 BigInteger (java.math.BigInteger)14 RskSystemProperties (co.rsk.config.RskSystemProperties)8 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)8 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)8 HashMapDB (org.ethereum.datasource.HashMapDB)8 RepositoryImpl (co.rsk.db.RepositoryImpl)7 ArrayList (java.util.ArrayList)7 Blockchain (org.ethereum.core.Blockchain)7 BlockStore (org.ethereum.db.BlockStore)7 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)7 RLPList (org.ethereum.util.RLPList)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 Script (co.rsk.bitcoinj.script.Script)5 Coin (co.rsk.core.Coin)5 IOException (java.io.IOException)5 BlockHeader (org.ethereum.core.BlockHeader)5