Search in sources :

Example 71 with BlockHeader

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

the class PrevMinGasPriceValidatorTest method noParentBlock.

@Test
public void noParentBlock() {
    BlockHeader header = Mockito.mock(BlockHeader.class);
    Block block = Mockito.mock(Block.class);
    Mockito.when(block.getHeader()).thenReturn(header);
    Mockito.when(header.getParentHash()).thenReturn(new Keccak256(PARENT_HASH));
    Mockito.when(header.getMinimumGasPrice()).thenReturn(BLOCK_MGP);
    PrevMinGasPriceRule pmgpv = new PrevMinGasPriceRule();
    Assert.assertFalse(pmgpv.isValid(header, null));
}
Also used : Block(org.ethereum.core.Block) Keccak256(co.rsk.crypto.Keccak256) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 72 with BlockHeader

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

the class PrevMinGasPriceValidatorTest method validMGPInNewBlock.

@Test
public void validMGPInNewBlock() {
    BlockHeader header = Mockito.mock(BlockHeader.class);
    Block block = Mockito.mock(Block.class);
    Mockito.when(block.getHeader()).thenReturn(header);
    Block parent = Mockito.mock(Block.class);
    Mockito.when(header.getParentHash()).thenReturn(new Keccak256(PARENT_HASH));
    Mockito.when(header.getMinimumGasPrice()).thenReturn(BLOCK_MGP);
    Mockito.when(parent.getMinimumGasPrice()).thenReturn(PARENT_BLOCK_MGP);
    PrevMinGasPriceRule pmgpv = new PrevMinGasPriceRule();
    Assert.assertFalse(pmgpv.isValid(header, parent));
}
Also used : Block(org.ethereum.core.Block) Keccak256(co.rsk.crypto.Keccak256) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 73 with BlockHeader

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

the class PrevMinGasPriceValidatorTest method noMinGasPrice.

@Test
public void noMinGasPrice() {
    BlockHeader header = Mockito.mock(BlockHeader.class);
    Block block = Mockito.mock(Block.class);
    Mockito.when(block.getHeader()).thenReturn(header);
    Block parent = Mockito.mock(Block.class);
    Mockito.when(header.isGenesis()).thenReturn(false);
    Mockito.when(header.getMinimumGasPrice()).thenReturn(null);
    PrevMinGasPriceRule pmgpv = new PrevMinGasPriceRule();
    Assert.assertFalse(pmgpv.isValid(header, parent));
}
Also used : Block(org.ethereum.core.Block) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 74 with BlockHeader

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

the class BlockTimeStampValidationRuleTest method blockInTheFuture.

@Test
public void blockInTheFuture() {
    int validPeriod = 540;
    BlockTimeStampValidationRule validationRule = new BlockTimeStampValidationRule(validPeriod, preRskip179Config, timeProvider);
    when(timeProvider.currentTimeMillis()).thenReturn(10_000_000L);
    BlockHeader header = mock(BlockHeader.class);
    Block block = mock(Block.class);
    when(block.getHeader()).thenReturn(header);
    when(header.getTimestamp()).thenReturn(10_000L + 2 * validPeriod);
    assertFalse(validationRule.isValid(header));
}
Also used : BtcBlock(co.rsk.bitcoinj.core.BtcBlock) Block(org.ethereum.core.Block) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 75 with BlockHeader

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

the class BlockTimeStampValidationRuleTest method blockTimeLowerThanParentTime.

@Test
public void blockTimeLowerThanParentTime() {
    int validPeriod = 540;
    BlockTimeStampValidationRule validationRule = new BlockTimeStampValidationRule(validPeriod, preRskip179Config, timeProvider);
    when(timeProvider.currentTimeMillis()).thenReturn(10_000_000L);
    BlockHeader header = mock(BlockHeader.class);
    Block block = mock(Block.class);
    when(block.getHeader()).thenReturn(header);
    Block parent = mock(Block.class);
    when(header.getTimestamp()).thenReturn(10_000L);
    when(parent.getTimestamp()).thenReturn(10_000L + 1000);
    assertFalse(validationRule.isValid(header, parent));
}
Also used : BtcBlock(co.rsk.bitcoinj.core.BtcBlock) Block(org.ethereum.core.Block) BlockHeader(org.ethereum.core.BlockHeader) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

BlockHeader (org.ethereum.core.BlockHeader)189 Test (org.junit.Test)128 Block (org.ethereum.core.Block)83 Keccak256 (co.rsk.crypto.Keccak256)31 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)30 ArrayList (java.util.ArrayList)23 BlockStore (org.ethereum.db.BlockStore)21 RLPList (org.ethereum.util.RLPList)20 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)14 BtcBlock (co.rsk.bitcoinj.core.BtcBlock)9 BlockDifficulty (co.rsk.core.BlockDifficulty)7 ConsensusValidationMainchainView (co.rsk.core.bc.ConsensusValidationMainchainView)7 ForkDetectionDataCalculator (co.rsk.mine.ForkDetectionDataCalculator)7 BigInteger (java.math.BigInteger)7 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)6 SimplePeer (co.rsk.net.simples.SimplePeer)6 BlockBuilder (co.rsk.test.builders.BlockBuilder)6 Trie (co.rsk.trie.Trie)4 Before (org.junit.Before)4 DifficultyCalculator (co.rsk.core.DifficultyCalculator)3