use of co.rsk.core.DifficultyCalculator in project rskj by rsksmart.
the class Web3ImplSnapshotTest method getMinerServerForTest.
private MinerServer getMinerServerForTest(SimpleEthereum ethereum, MinerClock clock) {
BlockValidationRule rule = new MinerManagerTest.BlockValidationRuleDummy();
DifficultyCalculator difficultyCalculator = new DifficultyCalculator(config.getActivationConfig(), config.getNetworkConstants());
MiningConfig miningConfig = ConfigUtils.getDefaultMiningConfig();
return new MinerServerImpl(config, ethereum, mainchainView, factory.getNodeBlockProcessor(), new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new BlockToMineBuilder(config.getActivationConfig(), miningConfig, factory.getRepositoryLocator(), factory.getBlockStore(), factory.getTransactionPool(), difficultyCalculator, new GasLimitCalculator(config.getNetworkConstants()), new ForkDetectionDataCalculator(), rule, clock, blockFactory, factory.getBlockExecutor(), new MinimumGasPriceCalculator(Coin.valueOf(miningConfig.getMinGasPriceTarget())), new MinerUtils()), clock, blockFactory, new BuildInfo("cb7f28e", "master"), miningConfig);
}
use of co.rsk.core.DifficultyCalculator in project rskj by rsksmart.
the class OneAsyncNodeTest method createNode.
private static SimpleAsyncNode createNode() {
final World world = new World();
final NetBlockStore store = new NetBlockStore();
final Blockchain blockchain = world.getBlockChain();
TestSystemProperties config = new TestSystemProperties();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
SimpleChannelManager channelManager = new SimpleChannelManager();
SyncProcessor syncProcessor = new SyncProcessor(blockchain, mock(org.ethereum.db.BlockStore.class), mock(ConsensusValidationMainchainView.class), blockSyncService, syncConfiguration, new BlockFactory(config.getActivationConfig()), new DummyBlockValidationRule(), new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), new DifficultyCalculator(config.getActivationConfig(), config.getNetworkConstants()), new PeersInformation(channelManager, syncConfiguration, blockchain, RskMockFactory.getPeerScoringManager()), mock(Genesis.class), mock(EthereumListener.class));
NodeMessageHandler handler = new NodeMessageHandler(config, processor, syncProcessor, channelManager, null, RskMockFactory.getPeerScoringManager(), mock(StatusResolver.class));
return new SimpleAsyncNode(handler, blockchain, syncProcessor, channelManager);
}
use of co.rsk.core.DifficultyCalculator in project rskj by rsksmart.
the class BlockDifficultyValidationRuleTest method testDifficulty.
@Test
public void testDifficulty() {
DifficultyCalculator difficultyCalculator = new DifficultyCalculator(activationConfig, networkConstants);
BlockDifficultyRule validationRule = new BlockDifficultyRule(difficultyCalculator);
Block block = Mockito.mock(Block.class);
Block parent = Mockito.mock(Block.class);
long parentTimestamp = 0;
long blockTimeStamp = 10;
BlockDifficulty parentDifficulty = new BlockDifficulty(new BigInteger("2048"));
BlockDifficulty blockDifficulty = new BlockDifficulty(new BigInteger("2049"));
// blockDifficulty = blockDifficulty.add(AbstractConfig.getConstants().getDifficultyBoundDivisor());
Mockito.when(block.getDifficulty()).thenReturn(blockDifficulty);
BlockHeader blockHeader = getEmptyHeader(blockDifficulty, blockTimeStamp, 1);
BlockHeader parentHeader = Mockito.mock(BlockHeader.class);
Mockito.when(parentHeader.getDifficulty()).thenReturn(parentDifficulty);
Mockito.when(block.getHeader()).thenReturn(blockHeader);
Mockito.when(parent.getHeader()).thenReturn(parentHeader);
Mockito.when(parent.getDifficulty()).thenReturn(parentDifficulty);
Mockito.when(parent.getTimestamp()).thenReturn(parentTimestamp);
Assert.assertEquals(validationRule.isValid(block, parent), true);
}
Aggregations