Search in sources :

Example 11 with ActivationConfig

use of org.ethereum.config.blockchain.upgrades.ActivationConfig in project rskj by rsksmart.

the class BridgeTest method receiveHeader_after_RSKIP200_Ok.

@Test
public void receiveHeader_after_RSKIP200_Ok() throws VMException {
    ActivationConfig activations = spy(ActivationConfigsForTest.genesis());
    doReturn(true).when(activations).isActive(eq(RSKIP200), anyLong());
    Bridge bridge = spy(getBridgeInstance(mock(BridgeSupport.class), activations));
    NetworkParameters networkParameters = constants.bridgeConstants.getBtcParams();
    co.rsk.bitcoinj.core.BtcBlock block = new co.rsk.bitcoinj.core.BtcBlock(networkParameters, 1, PegTestUtils.createHash(1), PegTestUtils.createHash(1), 1, Utils.encodeCompactBits(networkParameters.getMaxTarget()), 1, new ArrayList<>()).cloneAsHeader();
    Object[] parameters = new Object[] { block.bitcoinSerialize() };
    byte[] data = Bridge.RECEIVE_HEADER.encode(parameters);
    byte[] result = bridge.execute(data);
    verify(bridge, times(1)).receiveHeader(eq(parameters));
    assertEquals(BigInteger.valueOf(0), Bridge.RECEIVE_HEADER.decodeResult(result)[0]);
}
Also used : co.rsk.bitcoinj.core(co.rsk.bitcoinj.core) NetworkParameters(co.rsk.bitcoinj.core.NetworkParameters) ArrayList(java.util.ArrayList) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 12 with ActivationConfig

use of org.ethereum.config.blockchain.upgrades.ActivationConfig in project rskj by rsksmart.

the class BlockToMineBuilderTest method setUp.

@Before
public void setUp() {
    validationRules = mock(BlockValidationRule.class);
    RepositoryLocator repositoryLocator = mock(RepositoryLocator.class);
    StateRootHandler stateRootHandler = mock(StateRootHandler.class);
    MiningConfig miningConfig = mock(MiningConfig.class);
    DifficultyCalculator difficultyCalculator = mock(DifficultyCalculator.class);
    MinimumGasPriceCalculator minimumGasPriceCalculator = mock(MinimumGasPriceCalculator.class);
    MinerUtils minerUtils = mock(MinerUtils.class);
    activationConfig = mock(ActivationConfig.class);
    blockExecutor = mock(BlockExecutor.class);
    blockBuilder = new BlockToMineBuilder(activationConfig, miningConfig, repositoryLocator, mock(BlockStore.class), mock(TransactionPool.class), difficultyCalculator, new GasLimitCalculator(Constants.mainnet()), new ForkDetectionDataCalculator(), validationRules, mock(MinerClock.class), new BlockFactory(activationConfig), blockExecutor, minimumGasPriceCalculator, minerUtils);
    BlockDifficulty blockDifficulty = mock(BlockDifficulty.class);
    Repository snapshot = mock(Repository.class);
    GasLimitConfig gasLimitConfig = new GasLimitConfig(0, 0, false);
    when(minerUtils.getAllTransactions(any())).thenReturn(new ArrayList<>());
    when(minerUtils.filterTransactions(any(), any(), any(), any(), any())).thenReturn(new ArrayList<>());
    when(repositoryLocator.snapshotAt(any())).thenReturn(snapshot);
    when(minimumGasPriceCalculator.calculate(any())).thenReturn(mock(Coin.class));
    when(stateRootHandler.translate(any())).thenReturn(TestUtils.randomHash());
    when(miningConfig.getGasLimit()).thenReturn(gasLimitConfig);
    when(miningConfig.getUncleListLimit()).thenReturn(10);
    when(miningConfig.getCoinbaseAddress()).thenReturn(TestUtils.randomAddress());
    when(difficultyCalculator.calcDifficulty(any(), any())).thenReturn(blockDifficulty);
}
Also used : BlockExecutor(co.rsk.core.bc.BlockExecutor) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) RepositoryLocator(co.rsk.db.RepositoryLocator) StateRootHandler(co.rsk.db.StateRootHandler) MiningConfig(co.rsk.config.MiningConfig) DifficultyCalculator(co.rsk.core.DifficultyCalculator) BlockDifficulty(co.rsk.core.BlockDifficulty) Coin(co.rsk.core.Coin) GasLimitConfig(co.rsk.config.GasLimitConfig) BlockValidationRule(co.rsk.validators.BlockValidationRule) Before(org.junit.Before)

Example 13 with ActivationConfig

use of org.ethereum.config.blockchain.upgrades.ActivationConfig in project rskj by rsksmart.

the class ForkDetectionDataRuleTest method invalidForRskip110ActiveAndForkDetectionDataBecauseDataDoesNotMatch.

@Test
public void invalidForRskip110ActiveAndForkDetectionDataBecauseDataDoesNotMatch() {
    long blockNumber = 4242;
    enableRulesAt(blockNumber, ConsensusRule.RSKIP110);
    Keccak256 parentBlockHash = new Keccak256(getRandomHash());
    int requiredBlocksForForkDataCalculation = 449;
    List<BlockHeader> previousBlocks = IntStream.range(0, requiredBlocksForForkDataCalculation).mapToObj(i -> mock(BlockHeader.class)).collect(Collectors.toList());
    ConsensusValidationMainchainView mainchainView = mock(ConsensusValidationMainchainView.class);
    when(mainchainView.get(parentBlockHash, requiredBlocksForForkDataCalculation)).thenReturn(previousBlocks);
    ForkDetectionDataCalculator calculator = mock(ForkDetectionDataCalculator.class);
    Keccak256 blockHash = new Keccak256(getRandomHash());
    byte[] forkDetectionData = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
    when(calculator.calculateWithBlockHeaders(previousBlocks)).thenReturn(forkDetectionData);
    ForkDetectionDataRule rule = new ForkDetectionDataRule(activationConfig, mainchainView, calculator, requiredBlocksForForkDataCalculation);
    BlockHeader header = mock(BlockHeader.class);
    when(header.getNumber()).thenReturn(blockNumber);
    when(header.getHash()).thenReturn(blockHash);
    when(header.getParentHash()).thenReturn(parentBlockHash);
    byte[] headerForkDetectionData = new byte[] { 1, 2, 3, 4, 5, 6, 42, 8, 9, 10, 11, 12 };
    when(header.getMiningForkDetectionData()).thenReturn(headerForkDetectionData);
    assertFalse(rule.isValid(header));
}
Also used : IntStream(java.util.stream.IntStream) ForkDetectionDataCalculator(co.rsk.mine.ForkDetectionDataCalculator) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) BlockHeader(org.ethereum.core.BlockHeader) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Keccak256(co.rsk.crypto.Keccak256) Collectors(java.util.stream.Collectors) Block(org.ethereum.core.Block) ArrayList(java.util.ArrayList) SecureRandom(java.security.SecureRandom) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConsensusRule(org.ethereum.config.blockchain.upgrades.ConsensusRule) AdditionalMatchers.geq(org.mockito.AdditionalMatchers.geq) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) Keccak256(co.rsk.crypto.Keccak256) BlockHeader(org.ethereum.core.BlockHeader) ForkDetectionDataCalculator(co.rsk.mine.ForkDetectionDataCalculator) Test(org.junit.Test)

Example 14 with ActivationConfig

use of org.ethereum.config.blockchain.upgrades.ActivationConfig in project rskj by rsksmart.

the class ForkDetectionDataRuleTest method validForRskip110ActiveAndForkDetectionData.

@Test
public void validForRskip110ActiveAndForkDetectionData() {
    long blockNumber = 4242;
    enableRulesAt(blockNumber, ConsensusRule.RSKIP110);
    Keccak256 parentBlockHash = new Keccak256(getRandomHash());
    int requiredBlocksForForkDataCalculation = 449;
    List<BlockHeader> previousBlocks = IntStream.range(0, requiredBlocksForForkDataCalculation).mapToObj(i -> mock(BlockHeader.class)).collect(Collectors.toList());
    ConsensusValidationMainchainView mainchainView = mock(ConsensusValidationMainchainView.class);
    when(mainchainView.get(parentBlockHash, requiredBlocksForForkDataCalculation)).thenReturn(previousBlocks);
    ForkDetectionDataCalculator calculator = mock(ForkDetectionDataCalculator.class);
    Keccak256 blockHash = new Keccak256(getRandomHash());
    byte[] forkDetectionData = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
    when(calculator.calculateWithBlockHeaders(previousBlocks)).thenReturn(forkDetectionData);
    ForkDetectionDataRule rule = new ForkDetectionDataRule(activationConfig, mainchainView, calculator, requiredBlocksForForkDataCalculation);
    BlockHeader header = mock(BlockHeader.class);
    when(header.getNumber()).thenReturn(blockNumber);
    when(header.getHash()).thenReturn(blockHash);
    when(header.getParentHash()).thenReturn(parentBlockHash);
    when(header.getMiningForkDetectionData()).thenReturn(forkDetectionData);
    assertTrue(rule.isValid(header));
}
Also used : IntStream(java.util.stream.IntStream) ForkDetectionDataCalculator(co.rsk.mine.ForkDetectionDataCalculator) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) BlockHeader(org.ethereum.core.BlockHeader) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Keccak256(co.rsk.crypto.Keccak256) Collectors(java.util.stream.Collectors) Block(org.ethereum.core.Block) ArrayList(java.util.ArrayList) SecureRandom(java.security.SecureRandom) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConsensusRule(org.ethereum.config.blockchain.upgrades.ConsensusRule) AdditionalMatchers.geq(org.mockito.AdditionalMatchers.geq) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) Keccak256(co.rsk.crypto.Keccak256) BlockHeader(org.ethereum.core.BlockHeader) ForkDetectionDataCalculator(co.rsk.mine.ForkDetectionDataCalculator) Test(org.junit.Test)

Example 15 with ActivationConfig

use of org.ethereum.config.blockchain.upgrades.ActivationConfig in project rskj by rsksmart.

the class ProofOfWorkRuleTest method bytesAfterMergedMiningHashAreLessThan128.

@Test
public void bytesAfterMergedMiningHashAreLessThan128() {
    RskSystemProperties props = new TestSystemProperties() {

        @Override
        public ActivationConfig getActivationConfig() {
            return ActivationConfigsForTest.all();
        }
    };
    ActivationConfig config = props.getActivationConfig();
    Constants networkConstants = props.getNetworkConstants();
    BlockGenerator blockGenerator = new BlockGenerator(networkConstants, config);
    Block newBlock = blockGenerator.getBlock(1);
    while (newBlock.getNumber() < 455) newBlock = blockGenerator.createChildBlock(newBlock);
    String output1 = "6a24b9e11b6de9aa87561948d72e494fed2fb56bf8fd4193425f9350037f34dec5b13be7a86e";
    String output2 = "aa21a9ed90a5e7d6d8093d20aa54fb01f57da374e016d4a01ddec0210088675e5e3fee4e";
    byte[] mergedMiningLink = org.bouncycastle.util.Arrays.concatenate(RskMiningConstants.RSK_TAG, newBlock.getHashForMergedMining());
    co.rsk.bitcoinj.core.NetworkParameters params = co.rsk.bitcoinj.params.RegTestParams.get();
    co.rsk.bitcoinj.core.BtcTransaction bitcoinMergedMiningCoinbaseTransaction = MinerUtils.getBitcoinCoinbaseTransaction(params, mergedMiningLink);
    bitcoinMergedMiningCoinbaseTransaction.addOutput(new co.rsk.bitcoinj.core.TransactionOutput(params, bitcoinMergedMiningCoinbaseTransaction, co.rsk.bitcoinj.core.Coin.valueOf(0), Hex.decode(output1)));
    bitcoinMergedMiningCoinbaseTransaction.addOutput(new co.rsk.bitcoinj.core.TransactionOutput(params, bitcoinMergedMiningCoinbaseTransaction, co.rsk.bitcoinj.core.Coin.valueOf(0), Hex.decode(output2)));
    Block newBlock1 = new BlockMiner(config).mineBlock(newBlock, bitcoinMergedMiningCoinbaseTransaction);
    ProofOfWorkRule rule = new ProofOfWorkRule(props);
    assertTrue(rule.isValid(newBlock1));
}
Also used : RskMiningConstants(co.rsk.config.RskMiningConstants) Constants(org.ethereum.config.Constants) BlockMiner(co.rsk.blockchain.utils.BlockMiner) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Block(org.ethereum.core.Block) RskSystemProperties(co.rsk.config.RskSystemProperties) TestSystemProperties(co.rsk.config.TestSystemProperties) ParameterizedNetworkUpgradeTest(co.rsk.mine.ParameterizedNetworkUpgradeTest) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Aggregations

ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)30 Test (org.junit.Test)25 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)19 RskAddress (co.rsk.core.RskAddress)9 RskSystemProperties (co.rsk.config.RskSystemProperties)8 Before (org.junit.Before)8 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)7 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)6 Keccak256 (co.rsk.crypto.Keccak256)5 Trie (co.rsk.trie.Trie)5 TrieStore (co.rsk.trie.TrieStore)5 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)5 BigInteger (java.math.BigInteger)5 Constants (org.ethereum.config.Constants)5 BlockStoreException (co.rsk.bitcoinj.store.BlockStoreException)4 TestSystemProperties (co.rsk.config.TestSystemProperties)4 IOException (java.io.IOException)4 CallTransaction (org.ethereum.core.CallTransaction)4 Transaction (org.ethereum.core.Transaction)4 EVMAssembler (co.rsk.asm.EVMAssembler)3