use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class NodeBlockProcessorTest method processBlockAddingToBlockchain.
@Test
public void processBlockAddingToBlockchain() {
Blockchain blockchain = new BlockChainBuilder().ofSize(10);
Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
NetBlockStore store = new NetBlockStore();
Block genesis = blockchain.getBlockByNumber(0);
store.saveBlock(genesis);
Block block = new BlockGenerator().createChildBlock(blockchain.getBlockByNumber(10));
Assert.assertEquals(11, block.getNumber());
Assert.assertArrayEquals(blockchain.getBestBlockHash(), block.getParentHash().getBytes());
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
processor.processBlock(null, block);
Assert.assertFalse(store.hasBlock(block));
Assert.assertEquals(11, blockchain.getBestBlock().getNumber());
Assert.assertArrayEquals(block.getHash().getBytes(), blockchain.getBestBlockHash());
Assert.assertEquals(1, store.size());
}
use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class NodeBlockProcessorTest method advancedBlock.
@Test
public void advancedBlock() throws UnknownHostException {
final NetBlockStore store = new NetBlockStore();
final Peer sender = new SimplePeer();
final BlockNodeInformation nodeInformation = new BlockNodeInformation();
final SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
final Blockchain blockchain = new BlockChainBuilder().ofSize(0);
final long advancedBlockNumber = syncConfiguration.getChunkSize() * syncConfiguration.getMaxSkeletonChunks() + blockchain.getBestBlock().getNumber() + 1;
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
Assert.assertTrue(processor.isAdvancedBlock(advancedBlockNumber));
Assert.assertFalse(processor.isAdvancedBlock(advancedBlockNumber - 1));
}
use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class NodeBlockProcessorTest method processTenBlocksWithHoleAddingToBlockchain.
@Test
public void processTenBlocksWithHoleAddingToBlockchain() {
Blockchain blockchain = new BlockChainBuilder().ofSize(0);
NetBlockStore store = new NetBlockStore();
Block genesis = blockchain.getBestBlock();
List<Block> blocks = new BlockGenerator().getBlockChain(genesis, 10);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
TestSystemProperties config = new TestSystemProperties();
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration, DummyBlockValidator.VALID_RESULT_INSTANCE);
final NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
for (int k = 0; k < 10; k++) if (k != 5)
processor.processBlock(null, blocks.get(9 - k));
processor.processBlock(null, genesis);
processor.processBlock(null, blocks.get(4));
Assert.assertEquals(10, blockchain.getBestBlock().getNumber());
Assert.assertEquals(0, store.size());
}
use of co.rsk.config.TestSystemProperties in project rskj by rsksmart.
the class Web3ImplScoringTest method createWeb3.
private static Web3Impl createWeb3(PeerScoringManager peerScoringManager) {
SimpleEthereum rsk = new SimpleEthereum();
World world = new World();
rsk.blockchain = world.getBlockChain();
MiningMainchainView miningMainchainView = new MiningMainchainViewImpl(world.getBlockStore(), 2);
Wallet wallet = WalletFactory.createWallet();
TestSystemProperties config = new TestSystemProperties();
PersonalModule pm = new PersonalModuleWalletEnabled(config, rsk, wallet, null);
EthModule em = new EthModule(config.getNetworkConstants().getBridgeConstants(), config.getNetworkConstants().getChainId(), world.getBlockChain(), null, null, new ExecutionBlockRetriever(miningMainchainView, world.getBlockChain(), null, null), null, new EthModuleWalletEnabled(wallet), null, new BridgeSupportFactory(null, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig()), config.getGasEstimationCap());
TxPoolModule tpm = new TxPoolModuleImpl(Web3Mocks.getMockTransactionPool());
DebugModule dm = new DebugModuleImpl(null, null, Web3Mocks.getMockMessageHandler(), null);
return new Web3RskImpl(rsk, world.getBlockChain(), config, Web3Mocks.getMockMinerClient(), Web3Mocks.getMockMinerServer(), pm, em, null, tpm, null, dm, null, null, Web3Mocks.getMockChannelManager(), peerScoringManager, null, null, null, null, null, null, null, null, null, null, null);
}
use of co.rsk.config.TestSystemProperties 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