use of co.rsk.peg.simples.SimpleBlock in project rskj by rsksmart.
the class BlockValidatorTest method invalidUncleHasNoCommonAncestor.
@Test
public void invalidUncleHasNoCommonAncestor() {
IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
BlockGenerator blockGenerator = new BlockGenerator();
Block genesis = blockGenerator.getGenesisBlock();
Block uncle1a = blockGenerator.createChildBlock(new SimpleBlock(null, null, TestUtils.randomAddress().getBytes(), null, TEST_DIFFICULTY.getBytes(), 0, null, 0L, 0L, new byte[] {}, null, null, null, Block.getTxTrie(null).getHash().getBytes(), null, null, null));
List<BlockHeader> uncles1 = new ArrayList<>();
uncles1.add(uncle1a.getHeader());
Block block1 = blockGenerator.createChildBlock(genesis, null, uncles1, 1, null);
store.saveBlock(genesis, TEST_DIFFICULTY, true);
store.saveBlock(uncle1a, TEST_DIFFICULTY, false);
store.saveBlock(block1, TEST_DIFFICULTY, true);
BlockValidatorImpl validator = new BlockValidatorBuilder().addBlockUnclesValidationRule(store).blockStore(store).build();
Assert.assertFalse(validator.isValid(block1));
}
use of co.rsk.peg.simples.SimpleBlock in project rskj by rsksmart.
the class BlockGenerator method createSimpleChildBlock.
public Block createSimpleChildBlock(Block parent, int ntxs) {
Bloom logBloom = new Bloom();
List<Transaction> txs = new ArrayList<>();
for (int ntx = 0; ntx < ntxs; ntx++) {
txs.add(new SimpleRskTransaction(PegTestUtils.createHash3().getBytes()));
}
return new SimpleBlock(// parent hash
parent.getHash().getBytes(), // uncle hash
EMPTY_LIST_HASH, // coinbase
parent.getCoinbase().getBytes(), // logs bloom
logBloom.getData(), // difficulty
parent.getDifficulty().getBytes(), parent.getNumber() + 1, parent.getGasLimit(), parent.getGasUsed(), parent.getTimestamp() + ++count, // extraData
EMPTY_BYTE_ARRAY, // mixHash
EMPTY_BYTE_ARRAY, // provisory nonce
BigInteger.ZERO.toByteArray(), // receipts root
EMPTY_TRIE_HASH, // transaction receipts
EMPTY_TRIE_HASH, // state root
EMPTY_TRIE_HASH, // transaction list
txs, // uncle list
null);
}
Aggregations