Search in sources :

Example 1 with Eth62MessageFactory

use of org.ethereum.net.eth.message.Eth62MessageFactory in project rskj by rsksmart.

the class RskMessageTest method encodeDecodeGetBlockMessage.

@Test
public void encodeDecodeGetBlockMessage() {
    Block block = new BlockGenerator().getBlock(1);
    GetBlockMessage message = new GetBlockMessage(block.getHash().getBytes());
    RskMessage rskmessage = new RskMessage(config, message);
    byte[] encoded = rskmessage.getEncoded();
    Eth62MessageFactory factory = new Eth62MessageFactory(config);
    EthMessage ethmessage = (EthMessage) factory.create((byte) 0x08, encoded);
    Assert.assertNotNull(ethmessage);
    Assert.assertEquals(EthMessageCodes.RSK_MESSAGE, ethmessage.getCommand());
    RskMessage result = (RskMessage) ethmessage;
    Assert.assertNotNull(result.getMessage());
    Message resultMessage = result.getMessage();
    Assert.assertEquals(MessageType.GET_BLOCK_MESSAGE, resultMessage.getMessageType());
    Assert.assertArrayEquals(block.getHash().getBytes(), ((GetBlockMessage) resultMessage).getBlockHash());
}
Also used : EthMessage(org.ethereum.net.eth.message.EthMessage) EthMessage(org.ethereum.net.eth.message.EthMessage) Eth62MessageFactory(org.ethereum.net.eth.message.Eth62MessageFactory) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 2 with Eth62MessageFactory

use of org.ethereum.net.eth.message.Eth62MessageFactory in project rskj by rsksmart.

the class RskMessageTest method encodeDecodeStatusMessage.

@Test
public void encodeDecodeStatusMessage() {
    Block block = new BlockGenerator().getBlock(1);
    Status status = new Status(block.getNumber(), block.getHash().getBytes());
    StatusMessage message = new StatusMessage(status);
    RskMessage rskmessage = new RskMessage(config, message);
    byte[] encoded = rskmessage.getEncoded();
    Eth62MessageFactory factory = new Eth62MessageFactory(config);
    EthMessage ethmessage = (EthMessage) factory.create((byte) 0x08, encoded);
    Assert.assertNotNull(ethmessage);
    Assert.assertEquals(EthMessageCodes.RSK_MESSAGE, ethmessage.getCommand());
    RskMessage result = (RskMessage) ethmessage;
    Assert.assertNotNull(result.getMessage());
    Message resultMessage = result.getMessage();
    Assert.assertEquals(MessageType.STATUS_MESSAGE, resultMessage.getMessageType());
    Assert.assertArrayEquals(block.getHash().getBytes(), ((StatusMessage) resultMessage).getStatus().getBestBlockHash());
    Assert.assertEquals(block.getNumber(), ((StatusMessage) resultMessage).getStatus().getBestBlockNumber());
}
Also used : Status(co.rsk.net.Status) EthMessage(org.ethereum.net.eth.message.EthMessage) EthMessage(org.ethereum.net.eth.message.EthMessage) Eth62MessageFactory(org.ethereum.net.eth.message.Eth62MessageFactory) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 3 with Eth62MessageFactory

use of org.ethereum.net.eth.message.Eth62MessageFactory in project rskj by rsksmart.

the class RskMessageTest method encodeDecodeBlockMessage.

@Test
public void encodeDecodeBlockMessage() {
    Block block = new BlockGenerator().getBlock(1);
    BlockMessage message = new BlockMessage(block);
    RskMessage rskmessage = new RskMessage(config, message);
    byte[] encoded = rskmessage.getEncoded();
    Eth62MessageFactory factory = new Eth62MessageFactory(config);
    EthMessage ethmessage = (EthMessage) factory.create((byte) 0x08, encoded);
    Assert.assertNotNull(ethmessage);
    Assert.assertEquals(EthMessageCodes.RSK_MESSAGE, ethmessage.getCommand());
    RskMessage result = (RskMessage) ethmessage;
    Assert.assertNotNull(result.getMessage());
    Message resultMessage = result.getMessage();
    Assert.assertEquals(MessageType.BLOCK_MESSAGE, resultMessage.getMessageType());
    Assert.assertEquals(block.getHash(), ((BlockMessage) resultMessage).getBlock().getHash());
    Assert.assertArrayEquals(block.getEncoded(), ((BlockMessage) resultMessage).getBlock().getEncoded());
    Assert.assertEquals(block.getNumber(), ((BlockMessage) resultMessage).getBlock().getNumber());
}
Also used : EthMessage(org.ethereum.net.eth.message.EthMessage) EthMessage(org.ethereum.net.eth.message.EthMessage) Eth62MessageFactory(org.ethereum.net.eth.message.Eth62MessageFactory) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Aggregations

BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)3 Block (org.ethereum.core.Block)3 Eth62MessageFactory (org.ethereum.net.eth.message.Eth62MessageFactory)3 EthMessage (org.ethereum.net.eth.message.EthMessage)3 Test (org.junit.Test)3 Status (co.rsk.net.Status)1