Search in sources :

Example 41 with BlockGenerator

use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.

the class BlockchainVMTest method genesisTest.

@Test
public void genesisTest() {
    Block genesis = new BlockGenerator().getGenesisBlock();
    Assert.assertEquals(0, genesis.getNumber());
}
Also used : BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 42 with BlockGenerator

use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.

the class BlockValidatorTest method validateEmptyBlock.

@Test
public void validateEmptyBlock() {
    IndexedBlockStore blockStore = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
    Block genesis = new BlockGenerator().getGenesisBlock();
    blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
    Block block = new BlockBuilder().parent(genesis).build();
    BlockValidator validator = createValidator(blockStore);
    Assert.assertTrue(validator.isValid(block));
}
Also used : IndexedBlockStore(org.ethereum.db.IndexedBlockStore) SimpleBlock(co.rsk.peg.simples.SimpleBlock) HashMapDB(org.ethereum.datasource.HashMapDB) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockValidator(co.rsk.validators.BlockValidator) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 43 with BlockGenerator

use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.

the class BlockValidatorTest method blockInTheFuture.

@Test
public void blockInTheFuture() {
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    int validPeriod = 6000;
    Block block = Mockito.mock(Block.class);
    Mockito.when(block.getTimestamp()).thenReturn((System.currentTimeMillis() / 1000) + 2 * validPeriod);
    Mockito.when(block.getParentHash()).thenReturn(genesis.getHash());
    BlockValidatorImpl validator = new BlockValidatorBuilder().addBlockTimeStampValidationRule(validPeriod).build();
    Assert.assertFalse(validator.isValid(block));
    Mockito.when(block.getTimestamp()).thenReturn((System.currentTimeMillis() / 1000) + validPeriod);
    Assert.assertTrue(validator.isValid(block));
}
Also used : SimpleBlock(co.rsk.peg.simples.SimpleBlock) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 44 with BlockGenerator

use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.

the class BlockValidatorTest method invalidUncleHasNoSavedParent.

@Test
public void invalidUncleHasNoSavedParent() {
    IndexedBlockStore store = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    Block uncle1a = blockGenerator.createChildBlock(new BlockGenerator().createChildBlock(genesis));
    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(block1, TEST_DIFFICULTY, true);
    BlockValidatorImpl validator = new BlockValidatorBuilder().addBlockUnclesValidationRule(store).blockStore(store).build();
    Assert.assertFalse(validator.isValid(block1));
}
Also used : 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 45 with BlockGenerator

use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.

the class BlockValidatorTest method invalidUnclesHash.

@Test
public void invalidUnclesHash() {
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    Block block1 = blockGenerator.createChildBlock(genesis);
    block1.getHeader().setUnclesHash(new byte[] { 0x01 });
    BlockValidatorImpl validator = new BlockValidatorBuilder().addBlockUnclesValidationRule(null).build();
    Assert.assertFalse(validator.isValid(block1));
}
Also used : SimpleBlock(co.rsk.peg.simples.SimpleBlock) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Aggregations

BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)250 Test (org.junit.Test)237 Block (org.ethereum.core.Block)104 ArrayList (java.util.ArrayList)39 Blockchain (org.ethereum.core.Blockchain)38 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)36 RskSystemProperties (co.rsk.config.RskSystemProperties)35 SimpleBlock (co.rsk.peg.simples.SimpleBlock)34 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)33 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)31 HashMapDB (org.ethereum.datasource.HashMapDB)22 BlockBuilder (co.rsk.test.builders.BlockBuilder)17 Keccak256 (co.rsk.crypto.Keccak256)15 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)15 BlockStore (org.ethereum.db.BlockStore)15 World (co.rsk.test.World)14 RepositoryImpl (co.rsk.db.RepositoryImpl)13 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)13 Ignore (org.junit.Ignore)12 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)10