use of co.rsk.net.Status in project rskj by rsksmart.
the class MessageTest 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);
byte[] encoded = message.getEncoded();
Message result = Message.create(encoded);
Assert.assertNotNull(result);
Assert.assertArrayEquals(encoded, result.getEncoded());
Assert.assertEquals(MessageType.STATUS_MESSAGE, result.getMessageType());
StatusMessage newmessage = (StatusMessage) result;
Assert.assertArrayEquals(block.getHash().getBytes(), newmessage.getStatus().getBestBlockHash());
Assert.assertEquals(block.getNumber(), newmessage.getStatus().getBestBlockNumber());
Assert.assertNull(newmessage.getStatus().getBestBlockParentHash());
Assert.assertNull(newmessage.getStatus().getTotalDifficulty());
}
use of co.rsk.net.Status in project rskj by rsksmart.
the class StatusMessageTest method createWithGenesisBestBlockNumberAndHash.
@Test
public void createWithGenesisBestBlockNumberAndHash() {
Block genesis = new BlockGenerator().getGenesisBlock();
Status status = new Status(genesis.getNumber(), genesis.getHash().getBytes());
StatusMessage message = new StatusMessage(status);
Assert.assertEquals(MessageType.STATUS_MESSAGE, message.getMessageType());
Assert.assertSame(status, message.getStatus());
Assert.assertEquals(0, message.getStatus().getBestBlockNumber());
Assert.assertArrayEquals(genesis.getHash().getBytes(), message.getStatus().getBestBlockHash());
}
use of co.rsk.net.Status 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 co.rsk.net.Status in project rskj by rsksmart.
the class MessageTest method encodeDecodeStatusMessageUsingGenesisBlock.
@Test
public void encodeDecodeStatusMessageUsingGenesisBlock() {
Block block = new BlockGenerator().getBlock(0);
Status status = new Status(block.getNumber(), block.getHash().getBytes());
StatusMessage message = new StatusMessage(status);
byte[] encoded = message.getEncoded();
Message result = Message.create(encoded);
Assert.assertNotNull(result);
Assert.assertArrayEquals(encoded, result.getEncoded());
Assert.assertEquals(MessageType.STATUS_MESSAGE, result.getMessageType());
StatusMessage newmessage = (StatusMessage) result;
Assert.assertArrayEquals(block.getHash().getBytes(), newmessage.getStatus().getBestBlockHash());
Assert.assertEquals(block.getNumber(), newmessage.getStatus().getBestBlockNumber());
}
use of co.rsk.net.Status in project rskj by rsksmart.
the class MessageTest method encodeDecodeStatusMessageWithCompleteArguments.
@Test
public void encodeDecodeStatusMessageWithCompleteArguments() {
Block block = new BlockGenerator().getBlock(1);
Status status = new Status(block.getNumber(), block.getHash().getBytes(), block.getParentHash().getBytes(), new BlockDifficulty(BigInteger.TEN));
StatusMessage message = new StatusMessage(status);
byte[] encoded = message.getEncoded();
Message result = Message.create(encoded);
Assert.assertNotNull(result);
Assert.assertArrayEquals(encoded, result.getEncoded());
Assert.assertEquals(MessageType.STATUS_MESSAGE, result.getMessageType());
StatusMessage newmessage = (StatusMessage) result;
Assert.assertArrayEquals(block.getHash().getBytes(), newmessage.getStatus().getBestBlockHash());
Assert.assertEquals(block.getNumber(), newmessage.getStatus().getBestBlockNumber());
}
Aggregations