Search in sources :

Example 71 with BlockGenerator

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

Example 72 with BlockGenerator

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

Example 73 with BlockGenerator

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

Example 74 with BlockGenerator

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

Example 75 with BlockGenerator

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

Aggregations

BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)250 Test (org.junit.Test)237 Block (org.ethereum.core.Block)104 ArrayList (java.util.ArrayList)39 Blockchain (org.ethereum.core.Blockchain)38 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)36 RskSystemProperties (co.rsk.config.RskSystemProperties)35 SimpleBlock (co.rsk.peg.simples.SimpleBlock)34 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)33 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)31 HashMapDB (org.ethereum.datasource.HashMapDB)22 BlockBuilder (co.rsk.test.builders.BlockBuilder)17 Keccak256 (co.rsk.crypto.Keccak256)15 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)15 BlockStore (org.ethereum.db.BlockStore)15 World (co.rsk.test.World)14 RepositoryImpl (co.rsk.db.RepositoryImpl)13 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)13 Ignore (org.junit.Ignore)12 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)10