Search in sources :

Example 1 with SimpleBlock

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));
}
Also used : SimpleBlock(co.rsk.peg.simples.SimpleBlock) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) ArrayList(java.util.ArrayList) SimpleBlock(co.rsk.peg.simples.SimpleBlock) HashMapDB(org.ethereum.datasource.HashMapDB) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 2 with SimpleBlock

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);
}
Also used : SimpleBlock(co.rsk.peg.simples.SimpleBlock) SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) ArrayList(java.util.ArrayList)

Aggregations

SimpleBlock (co.rsk.peg.simples.SimpleBlock)2 ArrayList (java.util.ArrayList)2 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)1 SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)1 HashMapDB (org.ethereum.datasource.HashMapDB)1 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)1 Test (org.junit.Test)1