Search in sources :

Example 6 with BlockHeader

use of org.ethereum.core.BlockHeader in project rskj by rsksmart.

the class RskCustomCacheTest method addElement.

@Test
public void addElement() {
    RskCustomCache cache = new RskCustomCache(TIME_TO_LIVE);
    BlockHeader header1 = Mockito.mock(BlockHeader.class);
    cache.put(KEY, header1);
    Assert.assertNotNull(cache.get(KEY));
    Assert.assertEquals(header1, cache.get(KEY));
}
Also used : BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 7 with BlockHeader

use of org.ethereum.core.BlockHeader in project rskj by rsksmart.

the class RskCustomCacheTest method getElement.

@Test
public void getElement() {
    RskCustomCache cache = new RskCustomCache(TIME_TO_LIVE);
    BlockHeader header1 = Mockito.mock(BlockHeader.class);
    cache.put(KEY, header1);
    Assert.assertNotNull(cache.get(KEY));
    Assert.assertNull(cache.get(OTHER_KEY));
}
Also used : BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 8 with BlockHeader

use of org.ethereum.core.BlockHeader in project rskj by rsksmart.

the class BlockUnclesValidationRuleTest method rejectBlockWithSiblingUncle.

@Test
public void rejectBlockWithSiblingUncle() {
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    Block block1 = blockGenerator.createChildBlock(genesis);
    Block uncle = blockGenerator.createChildBlock(block1);
    List<BlockHeader> uncles = new ArrayList<>();
    uncles.add(uncle.getHeader());
    Block block = blockGenerator.createChildBlock(block1, null, uncles, 1, null);
    BlockChainImpl blockChain = BlockChainImplTest.createBlockChain();
    BlockStore store = blockChain.getBlockStore();
    store.saveBlock(genesis, new BlockDifficulty(BigInteger.valueOf(1)), true);
    store.saveBlock(block1, new BlockDifficulty(BigInteger.valueOf(2)), true);
    BlockUnclesValidationRule rule = new BlockUnclesValidationRule(config, store, 10, 10, new BlockCompositeRule(), new BlockParentCompositeRule());
    Assert.assertFalse(rule.isValid(block));
}
Also used : BlockDifficulty(co.rsk.core.BlockDifficulty) BlockStore(org.ethereum.db.BlockStore) ArrayList(java.util.ArrayList) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) Block(org.ethereum.core.Block) BlockHeader(org.ethereum.core.BlockHeader) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test) BlockChainImplTest(co.rsk.core.bc.BlockChainImplTest)

Example 9 with BlockHeader

use of org.ethereum.core.BlockHeader in project rskj by rsksmart.

the class ExtraDataRuleTests method blockWithValidLongerExtraDataThanAccepted.

@Test
public void blockWithValidLongerExtraDataThanAccepted() {
    BlockHeader blockHeader = Mockito.mock(BlockHeader.class);
    Mockito.when(blockHeader.getExtraData()).thenReturn(new byte[43]);
    Block block = new Block(blockHeader);
    ExtraDataRule rule = new ExtraDataRule(42);
    Assert.assertFalse(rule.isValid(block));
}
Also used : Block(org.ethereum.core.Block) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 10 with BlockHeader

use of org.ethereum.core.BlockHeader in project rskj by rsksmart.

the class ExtraDataRuleTests method blockWithValidExtraData.

@Test
public void blockWithValidExtraData() {
    BlockHeader blockHeader = Mockito.mock(BlockHeader.class);
    Mockito.when(blockHeader.getExtraData()).thenReturn(new byte[32]);
    Block block = new Block(blockHeader);
    ExtraDataRule rule = new ExtraDataRule(42);
    Assert.assertTrue(rule.isValid(block));
}
Also used : Block(org.ethereum.core.Block) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Aggregations

BlockHeader (org.ethereum.core.BlockHeader)65 Test (org.junit.Test)36 Block (org.ethereum.core.Block)27 ArrayList (java.util.ArrayList)13 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)9 BlockDifficulty (co.rsk.core.BlockDifficulty)5 Keccak256 (co.rsk.crypto.Keccak256)5 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)4 BlockBuilder (co.rsk.test.builders.BlockBuilder)4 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)4 BlockStore (org.ethereum.db.BlockStore)4 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)3 BigInteger (java.math.BigInteger)3 MainNetConfig (org.ethereum.config.net.MainNetConfig)3 DataWord (org.ethereum.vm.DataWord)3 DifficultyCalculator (co.rsk.core.DifficultyCalculator)2 BlockChainImplTest (co.rsk.core.bc.BlockChainImplTest)2 HashSet (java.util.HashSet)2 Bloom (org.ethereum.core.Bloom)2 Transaction (org.ethereum.core.Transaction)2