Search in sources :

Example 6 with Status

use of co.rsk.net.Status in project rskj by rsksmart.

the class StatusMessageTest method createWithBestBlockNumberAndHash.

@Test
public void createWithBestBlockNumberAndHash() {
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    Block block = blockGenerator.createChildBlock(genesis);
    Status status = new Status(block.getNumber(), block.getHash().getBytes());
    StatusMessage message = new StatusMessage(status);
    Assert.assertEquals(MessageType.STATUS_MESSAGE, message.getMessageType());
    Assert.assertSame(status, message.getStatus());
    Assert.assertEquals(1, message.getStatus().getBestBlockNumber());
    Assert.assertArrayEquals(block.getHash().getBytes(), message.getStatus().getBestBlockHash());
    Assert.assertNull(message.getStatus().getBestBlockParentHash());
    Assert.assertNull(message.getStatus().getTotalDifficulty());
}
Also used : Status(co.rsk.net.Status) Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 7 with Status

use of co.rsk.net.Status in project rskj by rsksmart.

the class StatusMessageTest method createWithCompleteArguments.

@Test
public void createWithCompleteArguments() {
    BlockGenerator blockGenerator = new BlockGenerator();
    Block genesis = blockGenerator.getGenesisBlock();
    Block block = blockGenerator.createChildBlock(genesis);
    Status status = new Status(block.getNumber(), block.getHash().getBytes(), block.getParentHash().getBytes(), new BlockDifficulty(BigInteger.TEN));
    StatusMessage message = new StatusMessage(status);
    Assert.assertEquals(MessageType.STATUS_MESSAGE, message.getMessageType());
    Assert.assertSame(status, message.getStatus());
    Assert.assertEquals(1, message.getStatus().getBestBlockNumber());
    Assert.assertArrayEquals(block.getHash().getBytes(), message.getStatus().getBestBlockHash());
    Assert.assertNotNull(message.getStatus().getBestBlockParentHash());
    Assert.assertArrayEquals(block.getParentHash().getBytes(), message.getStatus().getBestBlockParentHash());
    Assert.assertNotNull(message.getStatus().getTotalDifficulty());
    Assert.assertEquals(new BlockDifficulty(BigInteger.TEN), message.getStatus().getTotalDifficulty());
}
Also used : Status(co.rsk.net.Status) BlockDifficulty(co.rsk.core.BlockDifficulty) Block(org.ethereum.core.Block) 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