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());
}
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));
}
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));
}
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));
}
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));
}
Aggregations