Search in sources :

Example 11 with World

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));
}
Also used : SimpleTransactionPool(co.rsk.net.simples.SimpleTransactionPool) TxHandler(co.rsk.net.handler.TxHandler) SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) World(co.rsk.test.World) TxHandlerImpl(co.rsk.net.handler.TxHandlerImpl) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) PeerScoring(co.rsk.scoring.PeerScoring) PeerScoringManager(co.rsk.scoring.PeerScoringManager) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) CompositeEthereumListener(org.ethereum.listener.CompositeEthereumListener) SimpleBlockProcessor(co.rsk.net.simples.SimpleBlockProcessor) RepositoryImpl(co.rsk.db.RepositoryImpl) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 12 with World

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());
}
Also used : SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) DummyBlockValidationRule(co.rsk.validators.DummyBlockValidationRule) World(co.rsk.test.World) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 13 with World

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());
}
Also used : SimpleMessageChannel(co.rsk.net.simples.SimpleMessageChannel) World(co.rsk.test.World) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) SyncConfiguration(co.rsk.net.sync.SyncConfiguration) Test(org.junit.Test)

Example 14 with World

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);
}
Also used : SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) DummyBlockValidationRule(co.rsk.validators.DummyBlockValidationRule) Blockchain(org.ethereum.core.Blockchain) World(co.rsk.test.World) SyncConfiguration(co.rsk.net.sync.SyncConfiguration)

Example 15 with World

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);
}
Also used : Blockchain(org.ethereum.core.Blockchain) World(co.rsk.test.World)

Aggregations

World (co.rsk.test.World)134 Test (org.junit.Test)114 BlockBuilder (co.rsk.test.builders.BlockBuilder)36 AccountBuilder (co.rsk.test.builders.AccountBuilder)33 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)24 DslParser (co.rsk.test.dsl.DslParser)23 Block (org.ethereum.core.Block)20 Blockchain (org.ethereum.core.Blockchain)19 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)15 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)15 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)14 TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)14 ArrayList (java.util.ArrayList)13 SimpleEthereum (org.ethereum.rpc.Simples.SimpleEthereum)13 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)11 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)11 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)11 BigInteger (java.math.BigInteger)10 DummyBlockValidationRule (co.rsk.validators.DummyBlockValidationRule)9 Account (org.ethereum.core.Account)8