Search in sources :

Example 66 with BlockGenerator

use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.

the class BlockHeadersMessageTest method getBlockHeader.

@Test
public void getBlockHeader() {
    Block block = new BlockGenerator().getBlock(1);
    BlockHeadersMessage message = new BlockHeadersMessage(block.getHeader());
    Assert.assertSame(block.getHeader(), message.getBlockHeaders().get(0));
}
Also used : Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 67 with BlockGenerator

use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.

the class BlockRequestMessageTest method createWithBlockHash.

@Test
public void createWithBlockHash() {
    byte[] hash = new BlockGenerator().getGenesisBlock().getHash().getBytes();
    BlockRequestMessage message = new BlockRequestMessage(100, hash);
    Assert.assertEquals(100, message.getId());
    Assert.assertArrayEquals(hash, message.getBlockHash());
    Assert.assertEquals(MessageType.BLOCK_REQUEST_MESSAGE, message.getMessageType());
}
Also used : BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 68 with BlockGenerator

use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.

the class BlockResponseMessageTest method createWithBlockHash.

@Test
public void createWithBlockHash() {
    Block block = new BlockGenerator().getBlock(1);
    BlockResponseMessage message = new BlockResponseMessage(100, block);
    Assert.assertEquals(100, message.getId());
    Assert.assertEquals(block.getHash(), message.getBlock().getHash());
    Assert.assertEquals(MessageType.BLOCK_RESPONSE_MESSAGE, message.getMessageType());
}
Also used : Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 69 with BlockGenerator

use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.

the class BodyRequestMessageTest method createWithBlockHash.

@Test
public void createWithBlockHash() {
    byte[] hash = new BlockGenerator().getGenesisBlock().getHash().getBytes();
    BodyRequestMessage message = new BodyRequestMessage(100, hash);
    Assert.assertEquals(100, message.getId());
    Assert.assertArrayEquals(hash, message.getBlockHash());
    Assert.assertEquals(MessageType.BODY_REQUEST_MESSAGE, message.getMessageType());
}
Also used : BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 70 with BlockGenerator

use of co.rsk.blockchain.utils.BlockGenerator in project rskj by rsksmart.

the class BodyResponseMessageTest method createMessage.

@Test
public void createMessage() {
    List<Transaction> transactions = new ArrayList<>();
    for (int k = 1; k <= 10; k++) transactions.add(createTransaction(k));
    List<BlockHeader> uncles = new ArrayList<>();
    BlockGenerator blockGenerator = new BlockGenerator();
    Block parent = blockGenerator.getGenesisBlock();
    for (int k = 1; k < 10; k++) {
        Block block = blockGenerator.createChildBlock(parent);
        uncles.add(block.getHeader());
        parent = block;
    }
    BodyResponseMessage message = new BodyResponseMessage(100, transactions, uncles);
    Assert.assertEquals(100, message.getId());
    Assert.assertNotNull(message.getTransactions());
    Assert.assertEquals(transactions.size(), message.getTransactions().size());
    Assert.assertEquals(transactions, message.getTransactions());
    Assert.assertNotNull(message.getUncles());
    Assert.assertEquals(uncles.size(), message.getUncles().size());
    for (int k = 0; k < uncles.size(); k++) Assert.assertArrayEquals(uncles.get(k).getEncoded(), message.getUncles().get(k).getEncoded());
}
Also used : Transaction(org.ethereum.core.Transaction) ArrayList(java.util.ArrayList) Block(org.ethereum.core.Block) BlockHeader(org.ethereum.core.BlockHeader) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) 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