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]);
}
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);
}
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));
}
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));
}
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));
}
Aggregations