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());
}
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());
}
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());
}
Aggregations