use of org.hyperledger.besu.evm.log.LogsBloomFilter in project besu by hyperledger.
the class DifficultyCalculatorTests method testDifficulty.
private void testDifficulty(final String testFile, final ProtocolSchedule protocolSchedule, final MainnetBlockHeaderFunctions blockHeaderFunctions, final ObjectNode testObject) {
final var fields = testObject.fields();
while (fields.hasNext()) {
final var entry = fields.next();
final JsonNode value = entry.getValue();
final long currentBlockNumber = extractLong(value, "currentBlockNumber");
String parentUncles = value.get("parentUncles").asText();
final BlockHeader testHeader = BlockHeaderBuilder.create().parentHash(Hash.EMPTY).coinbase(Address.ZERO).gasLimit(Long.MAX_VALUE).stateRoot(Hash.EMPTY).transactionsRoot(Hash.EMPTY).receiptsRoot(Hash.EMPTY).logsBloom(new LogsBloomFilter()).gasUsed(0).extraData(Bytes.of()).mixHash(Hash.EMPTY).nonce(0).blockHeaderFunctions(blockHeaderFunctions).timestamp(extractLong(value, "parentTimestamp")).difficulty(Difficulty.fromHexString(value.get("parentDifficulty").asText())).ommersHash(parentUncles.equals("0x00") ? Hash.EMPTY_LIST_HASH : Hash.fromHexStringLenient(parentUncles)).number(currentBlockNumber).buildBlockHeader();
final long currentTime = extractLong(value, "currentTimestamp");
final UInt256 currentDifficulty = UInt256.fromHexString(value.get("currentDifficulty").asText());
final var spec = protocolSchedule.getByBlockNumber(currentBlockNumber);
final var calculator = spec.getDifficultyCalculator();
assertThat(UInt256.valueOf(calculator.nextDifficulty(currentTime, testHeader, null))).describedAs("File %s Test %s", testFile, entry.getKey()).isEqualTo(currentDifficulty);
}
}
use of org.hyperledger.besu.evm.log.LogsBloomFilter in project besu by hyperledger.
the class DifficultyCalculatorTests method testDifficultyCalculation.
@Test
public void testDifficultyCalculation() throws IOException {
MainnetBlockHeaderFunctions blockHeaderFunctions = new MainnetBlockHeaderFunctions();
final ObjectNode testObject = JsonUtil.objectNodeFromString(Resources.toString(DifficultyCalculatorTests.class.getResource(testFile), StandardCharsets.UTF_8));
final var fields = testObject.fields();
while (fields.hasNext()) {
final var entry = fields.next();
final JsonNode value = entry.getValue();
final long currentBlockNumber = extractLong(value, "currentBlockNumber");
final BlockHeader testHeader = BlockHeaderBuilder.create().parentHash(Hash.EMPTY).coinbase(Address.ZERO).gasLimit(Long.MAX_VALUE).stateRoot(Hash.EMPTY).transactionsRoot(Hash.EMPTY).receiptsRoot(Hash.EMPTY).logsBloom(new LogsBloomFilter()).gasUsed(0).extraData(Bytes.of()).mixHash(Hash.EMPTY).nonce(0).blockHeaderFunctions(blockHeaderFunctions).timestamp(extractLong(value, "parentTimestamp")).difficulty(Difficulty.fromHexString(value.get("parentDifficulty").asText())).ommersHash(Hash.fromHexString(value.get("parentUncles").asText())).number(currentBlockNumber).buildBlockHeader();
final long currentTime = extractLong(value, "currentTimestamp");
final UInt256 currentDifficulty = UInt256.fromHexString(value.get("currentDifficulty").asText());
final var spec = protocolSchedule.getByBlockNumber(currentBlockNumber);
final var calculator = spec.getDifficultyCalculator();
assertThat(UInt256.valueOf(calculator.nextDifficulty(currentTime, testHeader, null))).describedAs("File %s Test %s", testFile, entry.getKey()).isEqualTo(currentDifficulty);
}
}
Aggregations