use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class GasLimitRuleTests method getBlock.
private static Block getBlock(long gasLimitValue) {
byte[] gasLimit = new DataWord(gasLimitValue).getData();
BlockHeader header = new BlockHeader(null, null, RskAddress.nullAddress().getBytes(), null, BlockDifficulty.ZERO.getBytes(), 0, gasLimit, 0, 0, null, null, 0);
return new Block(header);
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class LocalBasicTest method runDifficultyTest.
@Test
public void runDifficultyTest() throws IOException, ParseException {
config.setGenesisInfo("frontier.json");
config.setBlockchainConfig(new MainNetConfig());
String json = getJSON("difficulty");
DifficultyTestSuite testSuite = new DifficultyTestSuite(json);
for (DifficultyTestCase testCase : testSuite.getTestCases()) {
logger.info("Running {}\n", testCase.getName());
BlockHeader current = testCase.getCurrent();
BlockHeader parent = testCase.getParent();
BlockDifficulty calc = new DifficultyCalculator(config).calcDifficulty(current, parent);
int c = calc.compareTo(parent.getDifficulty());
if (c > 0)
logger.info(" Difficulty increase test\n");
else if (c < 0)
logger.info(" Difficulty decrease test\n");
else
logger.info(" Difficulty without change test\n");
assertEquals(testCase.getExpectedDifficulty(), calc);
}
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class HashRateCalculatorTest method init.
@Before
public void init() {
blockStore = Mockito.mock(BlockStore.class);
block = Mockito.mock(Block.class);
blockHeader = Mockito.mock(BlockHeader.class);
Mockito.when(block.getHeader()).thenReturn(blockHeader);
Mockito.when(block.getHash()).thenReturn(new Keccak256(FAKE_GENERIC_HASH));
Mockito.when(blockHeader.getParentHash()).thenReturn(new Keccak256(FAKE_GENERIC_HASH)).thenReturn(new Keccak256(OHTER_FAKE_GENERIC_HASH)).thenReturn(new Keccak256(FAKE_GENERIC_HASH)).thenReturn(null);
Mockito.when(blockHeader.getHash()).thenReturn(new Keccak256(FAKE_GENERIC_HASH));
Mockito.when(blockStore.getBlockByHash(Mockito.any())).thenReturn(block).thenReturn(block).thenReturn(block).thenReturn(null);
Mockito.when(blockStore.getBestBlock()).thenReturn(block);
Mockito.when(blockStore.getBlockByHash(Mockito.any())).thenReturn(block);
}
use of org.ethereum.core.BlockHeader 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());
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class DifficultyRuleTest method getHeader.
private static BlockHeader getHeader(long difficultyValue) {
byte[] difficulty = new DataWord(difficultyValue).getData();
BlockHeader header = new BlockHeader(null, null, RskAddress.nullAddress().getBytes(), null, difficulty, 0, null, 0, 0, null, null, 0);
return header;
}
Aggregations