use of org.hyperledger.besu.ethereum.core.Difficulty in project besu by hyperledger.
the class JsonRpcHttpServiceTest method blockWithMetadataAndTxHashes.
public BlockWithMetadata<Hash, Hash> blockWithMetadataAndTxHashes(final Block block) {
final Difficulty td = block.getHeader().getDifficulty().add(10L);
final int size = block.calculateSize();
final List<Hash> txs = block.getBody().getTransactions().stream().map(Transaction::getHash).collect(Collectors.toList());
final List<Hash> ommers = block.getBody().getOmmers().stream().map(BlockHeader::getHash).collect(Collectors.toList());
return new BlockWithMetadata<>(block.getHeader(), txs, ommers, td, size);
}
use of org.hyperledger.besu.ethereum.core.Difficulty in project besu by hyperledger.
the class ConstantFieldValidationRuleTest method difficultyFieldIsValidatedCorrectly.
@Test
public void difficultyFieldIsValidatedCorrectly() {
final ConstantFieldValidationRule<Difficulty> uut = new ConstantFieldValidationRule<>("Difficulty", BlockHeader::getDifficulty, Difficulty.ONE);
final BlockHeaderTestFixture blockHeaderBuilder = new BlockHeaderTestFixture();
blockHeaderBuilder.difficulty(Difficulty.ONE);
BlockHeader header = blockHeaderBuilder.buildHeader();
assertThat(uut.validate(header, null)).isTrue();
blockHeaderBuilder.difficulty(Difficulty.ZERO);
header = blockHeaderBuilder.buildHeader();
assertThat(uut.validate(header, null)).isFalse();
}
use of org.hyperledger.besu.ethereum.core.Difficulty in project besu by hyperledger.
the class CliqueDifficultyValidationRuleTest method isFalseIfInTurnValidatorSuppliesDifficultyOfOne.
@Test
public void isFalseIfInTurnValidatorSuppliesDifficultyOfOne() {
final long IN_TURN_BLOCK_NUMBER = validatorList.size();
final Difficulty REPORTED_DIFFICULTY = Difficulty.ONE;
blockHeaderBuilder.number(IN_TURN_BLOCK_NUMBER - 1L);
final BlockHeader parentHeader = TestHelpers.createCliqueSignedBlockHeader(blockHeaderBuilder, proposerKeyPair, validatorList);
blockHeaderBuilder.number(IN_TURN_BLOCK_NUMBER).difficulty(REPORTED_DIFFICULTY);
final BlockHeader newBlock = TestHelpers.createCliqueSignedBlockHeader(blockHeaderBuilder, proposerKeyPair, validatorList);
final CliqueDifficultyValidationRule diffValidationRule = new CliqueDifficultyValidationRule();
assertThat(diffValidationRule.validate(newBlock, parentHeader, cliqueProtocolContext)).isFalse();
}
use of org.hyperledger.besu.ethereum.core.Difficulty in project besu by hyperledger.
the class CliqueDifficultyValidationRuleTest method isFalseIfOutTurnValidatorSuppliesDifficultyOfTwo.
@Test
public void isFalseIfOutTurnValidatorSuppliesDifficultyOfTwo() {
final long OUT_OF_TURN_BLOCK_NUMBER = validatorList.size() - 1L;
final Difficulty REPORTED_DIFFICULTY = Difficulty.of(2);
blockHeaderBuilder.number(OUT_OF_TURN_BLOCK_NUMBER - 1L);
final BlockHeader parentHeader = TestHelpers.createCliqueSignedBlockHeader(blockHeaderBuilder, proposerKeyPair, validatorList);
blockHeaderBuilder.number(OUT_OF_TURN_BLOCK_NUMBER).difficulty(REPORTED_DIFFICULTY);
final BlockHeader newBlock = TestHelpers.createCliqueSignedBlockHeader(blockHeaderBuilder, proposerKeyPair, validatorList);
final CliqueDifficultyValidationRule diffValidationRule = new CliqueDifficultyValidationRule();
assertThat(diffValidationRule.validate(newBlock, parentHeader, cliqueProtocolContext)).isFalse();
}
use of org.hyperledger.besu.ethereum.core.Difficulty in project besu by hyperledger.
the class CliqueDifficultyValidationRuleTest method isTrueIfInTurnValidatorSuppliesDifficultyOfTwo.
@Test
public void isTrueIfInTurnValidatorSuppliesDifficultyOfTwo() {
// i.e. proposer is 'in turn'
final long IN_TURN_BLOCK_NUMBER = validatorList.size();
final Difficulty REPORTED_DIFFICULTY = Difficulty.of(2);
blockHeaderBuilder.number(IN_TURN_BLOCK_NUMBER - 1L);
final BlockHeader parentHeader = TestHelpers.createCliqueSignedBlockHeader(blockHeaderBuilder, proposerKeyPair, validatorList);
blockHeaderBuilder.number(IN_TURN_BLOCK_NUMBER).difficulty(REPORTED_DIFFICULTY);
final BlockHeader newBlock = TestHelpers.createCliqueSignedBlockHeader(blockHeaderBuilder, proposerKeyPair, validatorList);
final CliqueDifficultyValidationRule diffValidationRule = new CliqueDifficultyValidationRule();
assertThat(diffValidationRule.validate(newBlock, parentHeader, cliqueProtocolContext)).isTrue();
}
Aggregations