use of co.rsk.test.World in project rskj by rsksmart.
the class NodeMessageHandlerTest method processTooMuchGasTransactionMessage.
@Test
public void processTooMuchGasTransactionMessage() throws UnknownHostException {
PeerScoringManager scoring = createPeerScoringManager();
final SimpleChannelManager channelManager = new SimpleChannelManager();
final World world = new World();
final Blockchain blockchain = world.getBlockChain();
TransactionPool state = mock(TransactionPool.class);
BlockProcessor blockProcessor = mock(BlockProcessor.class);
Mockito.when(blockProcessor.hasBetterBlockToSync()).thenReturn(false);
TxHandler txHandler = new TxHandlerImpl(config, mock(CompositeEthereumListener.class), mock(RepositoryImpl.class), blockchain);
final NodeMessageHandler handler = new NodeMessageHandler(config, blockProcessor, null, channelManager, state, txHandler, scoring, new ProofOfWorkRule(config).setFallbackMiningEnabled(false));
final SimpleMessageChannel sender = new SimpleMessageChannel();
final List<Transaction> txs = new ArrayList<>();
BigInteger value = BigInteger.ONE;
BigInteger nonce = BigInteger.ZERO;
BigInteger gasPrice = BigInteger.ONE;
BigInteger gasLimit = BigDecimal.valueOf(Math.pow(2, 60)).add(BigDecimal.ONE).toBigInteger();
txs.add(TransactionUtils.createTransaction(TransactionUtils.getPrivateKeyBytes(), TransactionUtils.getAddress(), value, nonce, gasPrice, gasLimit));
final TransactionsMessage message = new TransactionsMessage(txs);
handler.processMessage(sender, message);
Assert.assertNotNull(channelManager.getTransactions());
Assert.assertEquals(0, channelManager.getTransactions().size());
Assert.assertFalse(scoring.isEmpty());
PeerScoring pscoring = scoring.getPeerScoring(sender.getPeerNodeID());
Assert.assertNotNull(pscoring);
Assert.assertFalse(pscoring.isEmpty());
// besides this
Assert.assertEquals(1, pscoring.getTotalEventCounter());
Assert.assertEquals(1, pscoring.getEventCounter(EventType.VALID_TRANSACTION));
}
use of co.rsk.test.World in project rskj by rsksmart.
the class NodeMessageHandlerTest method processGetBlockHeaderMessageUsingEmptyStore.
@Test
public void processGetBlockHeaderMessageUsingEmptyStore() throws UnknownHostException {
final Block block = new BlockGenerator().getBlock(3);
final World world = new World();
final Blockchain blockchain = world.getBlockChain();
final BlockStore store = new BlockStore();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
final NodeBlockProcessor bp = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
final NodeMessageHandler handler = new NodeMessageHandler(config, bp, null, null, null, null, null, new DummyBlockValidationRule());
final SimpleMessageChannel sender = new SimpleMessageChannel();
handler.processMessage(sender, new GetBlockHeadersMessage(block.getHash().getBytes(), 1));
Assert.assertTrue(sender.getMessages().isEmpty());
}
use of co.rsk.test.World in project rskj by rsksmart.
the class NodeMessageHandlerTest method processGetBlockMessageUsingBlockInStore.
@Test
public void processGetBlockMessageUsingBlockInStore() throws UnknownHostException {
final Block block = new BlockGenerator().getBlock(3);
final World world = new World();
final Blockchain blockchain = world.getBlockChain();
final BlockStore store = new BlockStore();
store.saveBlock(block);
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
final NodeBlockProcessor bp = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
final NodeMessageHandler handler = new NodeMessageHandler(config, bp, null, null, null, null, null, new ProofOfWorkRule(config).setFallbackMiningEnabled(false));
final SimpleMessageChannel sender = new SimpleMessageChannel();
handler.processMessage(sender, new GetBlockMessage(block.getHash().getBytes()));
Assert.assertFalse(sender.getMessages().isEmpty());
Assert.assertEquals(1, sender.getMessages().size());
final Message message = sender.getMessages().get(0);
Assert.assertEquals(MessageType.BLOCK_MESSAGE, message.getMessageType());
final BlockMessage bMessage = (BlockMessage) message;
Assert.assertEquals(block.getHash(), bMessage.getBlock().getHash());
}
use of co.rsk.test.World in project rskj by rsksmart.
the class NodeMessageHandlerUtil method createHandler.
public static NodeMessageHandler createHandler(BlockValidationRule validationRule) {
final World world = new World();
final BlockStore store = new BlockStore();
final Blockchain blockchain = world.getBlockChain();
BlockNodeInformation nodeInformation = new BlockNodeInformation();
SyncConfiguration syncConfiguration = SyncConfiguration.IMMEDIATE_FOR_TESTING;
BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, syncConfiguration);
SyncProcessor syncProcessor = new SyncProcessor(config, blockchain, blockSyncService, RskMockFactory.getPeerScoringManager(), RskMockFactory.getChannelManager(), syncConfiguration, new DummyBlockValidationRule(), DIFFICULTY_CALCULATOR);
NodeBlockProcessor processor = new NodeBlockProcessor(store, blockchain, nodeInformation, blockSyncService, syncConfiguration);
return new NodeMessageHandler(config, processor, syncProcessor, new SimpleChannelManager(), null, null, RskMockFactory.getPeerScoringManager(), validationRule);
}
use of co.rsk.test.World in project rskj by rsksmart.
the class NodeMessageHandlerUtil method createHandlerWithSyncProcessor.
public static NodeMessageHandler createHandlerWithSyncProcessor(SyncConfiguration syncConfiguration, ChannelManager channelManager) {
final World world = new World();
final Blockchain blockchain = world.getBlockChain();
return createHandlerWithSyncProcessor(blockchain, syncConfiguration, channelManager);
}
Aggregations