use of org.ethereum.db.BlockStore in project rskj by rsksmart.
the class BlockValidatorTest method processBlockWithInvalidMGPTxs.
@Test
public void processBlockWithInvalidMGPTxs() {
BlockStore blockStore = Mockito.mock(org.ethereum.db.BlockStore.class);
Repository repository = Mockito.mock(Repository.class);
Mockito.when(repository.getSnapshotTo(Mockito.any())).thenReturn(repository);
Mockito.when(repository.getNonce(Mockito.any())).thenReturn(BigInteger.ZERO);
Block parent = new BlockBuilder().minGasPrice(BigInteger.ZERO).parent(new BlockGenerator().getGenesisBlock()).build();
List<Transaction> txs = new ArrayList<>();
Transaction tx = Transaction.create(config, "0000000000000000000000000000000000000006", BigInteger.ZERO, BigInteger.ZERO, BigInteger.ONE, BigInteger.TEN);
tx.sign(new byte[] { 22, 11, 00 });
txs.add(tx);
Block block = new BlockBuilder().minGasPrice(BigInteger.TEN).transactions(txs).parent(parent).build();
Mockito.when(blockStore.getBlockByHash(block.getParentHash().getBytes())).thenReturn(parent);
BlockValidatorImpl validator = new BlockValidatorBuilder().addTxsMinGasPriceRule().blockStore(blockStore).build();
Assert.assertFalse(validator.isValid(block));
}
use of org.ethereum.db.BlockStore in project rskj by rsksmart.
the class FamilyUtilsTest method getFamilyGetAncestorsWithUncles.
@Test
public void getFamilyGetAncestorsWithUncles() {
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.getFamily(store, block3, 2);
Assert.assertNotNull(family);
Assert.assertFalse(family.isEmpty());
Assert.assertEquals(4, family.size());
Assert.assertFalse(family.contains(genesis.getHash()));
Assert.assertTrue(family.contains(block1.getHash()));
Assert.assertFalse(family.contains(uncle11.getHash()));
Assert.assertFalse(family.contains(uncle12.getHash()));
Assert.assertTrue(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()));
family = FamilyUtils.getFamily(store, block3, 3);
Assert.assertNotNull(family);
Assert.assertFalse(family.isEmpty());
Assert.assertEquals(7, family.size());
Assert.assertTrue(family.contains(genesis.getHash()));
Assert.assertTrue(family.contains(block1.getHash()));
Assert.assertTrue(family.contains(uncle11.getHash()));
Assert.assertTrue(family.contains(uncle12.getHash()));
Assert.assertTrue(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()));
}
use of org.ethereum.db.BlockStore in project rskj by rsksmart.
the class HashRateCalculatorTest method init.
@Before
public void init() {
blockStore = Mockito.mock(BlockStore.class);
block = Mockito.mock(Block.class);
blockHeader = Mockito.mock(BlockHeader.class);
Mockito.when(block.getHeader()).thenReturn(blockHeader);
Mockito.when(block.getHash()).thenReturn(new Keccak256(FAKE_GENERIC_HASH));
Mockito.when(blockHeader.getParentHash()).thenReturn(new Keccak256(FAKE_GENERIC_HASH)).thenReturn(new Keccak256(OHTER_FAKE_GENERIC_HASH)).thenReturn(new Keccak256(FAKE_GENERIC_HASH)).thenReturn(null);
Mockito.when(blockHeader.getHash()).thenReturn(new Keccak256(FAKE_GENERIC_HASH));
Mockito.when(blockStore.getBlockByHash(Mockito.any())).thenReturn(block).thenReturn(block).thenReturn(block).thenReturn(null);
Mockito.when(blockStore.getBestBlock()).thenReturn(block);
Mockito.when(blockStore.getBlockByHash(Mockito.any())).thenReturn(block);
}
use of org.ethereum.db.BlockStore in project rskj by rsksmart.
the class BlockForkTest method calculateForkLengthTwo.
@Test
public void calculateForkLengthTwo() {
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, 2, store, blockGenerator);
BlockFork fork = new BlockFork();
fork.calculate(oldBranch.get(1), newBranch.get(1), 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(2, 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());
}
use of org.ethereum.db.BlockStore in project rskj by rsksmart.
the class BlockForkTest method calculateForkLengthThreeOldTwoNew.
@Test
public void calculateForkLengthThreeOldTwoNew() {
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, 3, store, blockGenerator);
List<Block> newBranch = makeChain(parent, 2, store, blockGenerator);
BlockFork fork = new BlockFork();
fork.calculate(oldBranch.get(2), newBranch.get(1), store);
Assert.assertEquals(parent.getHash(), fork.getCommonAncestor().getHash());
Assert.assertFalse(fork.getOldBlocks().isEmpty());
Assert.assertEquals(3, 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.assertEquals(oldBranch.get(2).getHash(), fork.getOldBlocks().get(2).getHash());
Assert.assertFalse(fork.getNewBlocks().isEmpty());
Assert.assertEquals(2, 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());
}
Aggregations