Search in sources :

Example 1 with Status

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());
}
Also used : Status(co.rsk.net.Status) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 2 with Status

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());
}
Also used : Status(co.rsk.net.Status) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 3 with Status

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());
}
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 4 with Status

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());
}
Also used : Status(co.rsk.net.Status) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 5 with Status

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());
}
Also used : Status(co.rsk.net.Status) BlockDifficulty(co.rsk.core.BlockDifficulty) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Aggregations

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