Search in sources :

Example 76 with BlockGenerator

use of co.rsk.blockchain.utils.BlockGenerator 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 77 with BlockGenerator

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

the class ProofOfWorkRuleTest method test_1.

@Test
public void test_1() {
    // mined block
    Block b = BlockMiner.mineBlock(new BlockGenerator().getBlock(1));
    assertTrue(rule.isValid(b));
}
Also used : Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Test(org.junit.Test)

Example 78 with BlockGenerator

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

the class ProofOfWorkRuleTest method test_2.

@Ignore
// invalid block
@Test
public void test_2() {
    // mined block
    Block b = BlockMiner.mineBlock(new BlockGenerator().getBlock(1));
    byte[] mergeMiningHeader = b.getBitcoinMergedMiningHeader();
    // TODO improve, the mutated block header could be still valid
    mergeMiningHeader[0]++;
    b.setBitcoinMergedMiningHeader(mergeMiningHeader);
    assertFalse(rule.isValid(b));
}
Also used : Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 79 with BlockGenerator

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

the class ProofOfWorkRuleTest method test_3.

@Ignore
// stress test
@Test
public void test_3() {
    int iterCnt = 1_000_000;
    // mined block
    Block b = BlockMiner.mineBlock(new BlockGenerator().getBlock(1));
    long start = System.currentTimeMillis();
    for (int i = 0; i < iterCnt; i++) rule.isValid(b);
    long total = System.currentTimeMillis() - start;
    System.out.println(String.format("Time: total = %d ms, per block = %.2f ms", total, (double) total / iterCnt));
}
Also used : Block(org.ethereum.core.Block) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 80 with BlockGenerator

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

the class ProofOfWorkRuleTest method test_RSKTagInCoinbaseTransactionTooFar.

@Test
public void test_RSKTagInCoinbaseTransactionTooFar() {
    /* This test is about a rsk block, with a compressed coinbase that leaves more than 64 bytes before the start of the RSK tag. */
    BlockGenerator blockGenerator = new BlockGenerator();
    byte[] prefix = new byte[1000];
    byte[] bytes = org.spongycastle.util.Arrays.concatenate(prefix, RskMiningConstants.RSK_TAG);
    // mined block
    Block b = mineBlockWithCoinbaseTransactionWithCompressedCoinbaseTransactionPrefix(blockGenerator.getBlock(1), bytes);
    Assert.assertFalse(rule.isValid(b));
}
Also used : Block(org.ethereum.core.Block) 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