use of co.rsk.blockchain.utils.BlockGenerator 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.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class MessageTest method encodeDecodeNewBlockHashesMessage.
@Test
public void encodeDecodeNewBlockHashesMessage() {
List<Block> blocks = new BlockGenerator().getBlockChain(10);
Block b1 = blocks.get(5);
Block b2 = blocks.get(7);
List<BlockIdentifier> identifiers = new LinkedList<>();
identifiers.add(new BlockIdentifier(b1.getHash().getBytes(), b1.getNumber()));
identifiers.add(new BlockIdentifier(b2.getHash().getBytes(), b2.getNumber()));
NewBlockHashesMessage message = new NewBlockHashesMessage(identifiers);
byte[] encoded = message.getEncoded();
Message result = Message.create(encoded);
Assert.assertNotNull(result);
Assert.assertArrayEquals(encoded, result.getEncoded());
Assert.assertEquals(MessageType.NEW_BLOCK_HASHES, result.getMessageType());
NewBlockHashesMessage decodedMessage = (NewBlockHashesMessage) result;
Assert.assertNotNull(decodedMessage.getBlockIdentifiers());
List<BlockIdentifier> decodedIdentifiers = decodedMessage.getBlockIdentifiers();
Assert.assertEquals(identifiers.size(), decodedIdentifiers.size());
for (int i = 0; i < identifiers.size(); i++) {
Assert.assertEquals(identifiers.get(i).getNumber(), decodedIdentifiers.get(i).getNumber());
Assert.assertArrayEquals(identifiers.get(i).getHash(), decodedIdentifiers.get(i).getHash());
}
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class MessageTest method encodeDecodeBlockMessage.
@Test
public void encodeDecodeBlockMessage() {
Block block = new BlockGenerator().getBlock(1);
BlockMessage message = new BlockMessage(block);
byte[] encoded = message.getEncoded();
Message result = Message.create(encoded);
Assert.assertNotNull(result);
Assert.assertArrayEquals(encoded, result.getEncoded());
Assert.assertEquals(MessageType.BLOCK_MESSAGE, result.getMessageType());
BlockMessage newmessage = (BlockMessage) result;
Assert.assertEquals(block.getNumber(), newmessage.getBlock().getNumber());
Assert.assertEquals(block.getHash(), newmessage.getBlock().getHash());
Assert.assertArrayEquals(block.getEncoded(), newmessage.getBlock().getEncoded());
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class NewBlockHashTest method createWithBlockHash.
@Test
public void createWithBlockHash() {
byte[] hash = new BlockGenerator().getGenesisBlock().getHash().getBytes();
NewBlockHashMessage message = new NewBlockHashMessage(hash);
Assert.assertArrayEquals(hash, message.getBlockHash());
Assert.assertEquals(MessageType.NEW_BLOCK_HASH_MESSAGE, message.getMessageType());
}
use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.
the class NewBlockHashesTest method getBlockIdentifier.
@Test
public void getBlockIdentifier() {
Block block = new BlockGenerator().getBlock(1);
List<BlockIdentifier> blockIdentifierList = new LinkedList<>();
blockIdentifierList.add(new BlockIdentifier(block.getHash().getBytes(), block.getNumber()));
NewBlockHashesMessage message = new NewBlockHashesMessage(blockIdentifierList);
List<BlockIdentifier> identifiers = message.getBlockIdentifiers();
Assert.assertEquals(1, identifiers.size());
Assert.assertEquals(blockIdentifierList.get(0).getNumber(), identifiers.get(0).getNumber());
Assert.assertArrayEquals(blockIdentifierList.get(0).getHash(), identifiers.get(0).getHash());
}
Aggregations