use of org.aion.zero.impl.valid.EnergyConsumedRule in project aion by aionnetwork.
the class EnergyConsumedRuleTest method testEnergyExceedsBounds.
// should indicate error if energyConsumed exceeds bounds
@Test
public void testEnergyExceedsBounds() {
final long upperBound = 1000000L;
final long energyConsumed = 1000001L;
when(mockHeader.getEnergyConsumed()).thenReturn(energyConsumed);
when(mockHeader.getEnergyLimit()).thenReturn(upperBound);
List<IValidRule.RuleError> errors = new ArrayList<>();
EnergyConsumedRule rule = new EnergyConsumedRule();
boolean ret = rule.validate(mockHeader, errors);
assertThat(ret).isFalse();
assertThat(errors).isNotEmpty();
}
use of org.aion.zero.impl.valid.EnergyConsumedRule in project aion by aionnetwork.
the class ChainConfiguration method createBlockHeaderValidatorForImport.
public BlockHeaderValidator createBlockHeaderValidatorForImport() {
List<BlockHeaderRule> powRules = Arrays.asList(new HeaderSealTypeRule(), new AionExtraDataRule(this.getConstants().getMaximumExtraDataSize()), new EnergyConsumedRule(), new AionPOWRule(), new EquihashSolutionRule(this.getEquihashValidator()));
List<BlockHeaderRule> posRules = Arrays.asList(new HeaderSealTypeRule(), new AionExtraDataRule(this.getConstants().getMaximumExtraDataSize()), new EnergyConsumedRule(), new SignatureRule());
Map<Seal, List<BlockHeaderRule>> unityRules = new EnumMap<>(Seal.class);
unityRules.put(Seal.PROOF_OF_WORK, powRules);
unityRules.put(Seal.PROOF_OF_STAKE, posRules);
return new BlockHeaderValidator(unityRules);
}
use of org.aion.zero.impl.valid.EnergyConsumedRule in project aion by aionnetwork.
the class EnergyConsumedRuleTest method testEnergyLimitBounds.
// ensure that energyConsumed does not exceed energyLimit bound
@Test
public void testEnergyLimitBounds() {
final long upperBound = 1000000L;
when(mockHeader.getEnergyConsumed()).thenReturn(0L);
when(mockHeader.getEnergyLimit()).thenReturn(upperBound);
EnergyConsumedRule rule = new EnergyConsumedRule();
List<IValidRule.RuleError> errors = new ArrayList<>();
boolean ret = rule.validate(mockHeader, errors);
assertThat(ret).isTrue();
assertThat(errors).isEmpty();
// now test the upper bound consumed == bound
when(mockHeader.getEnergyConsumed()).thenReturn(upperBound);
when(mockHeader.getEnergyLimit()).thenReturn(upperBound);
}
use of org.aion.zero.impl.valid.EnergyConsumedRule in project aion by aionnetwork.
the class ChainConfiguration method createBlockHeaderValidator.
public BlockHeaderValidator createBlockHeaderValidator() {
List<BlockHeaderRule> powRules = Arrays.asList(new HeaderSealTypeRule(), new FutureBlockRule(), new AionExtraDataRule(this.getConstants().getMaximumExtraDataSize()), new EnergyConsumedRule(), new AionPOWRule(), new EquihashSolutionRule(this.getEquihashValidator()));
List<BlockHeaderRule> posRules = Arrays.asList(new HeaderSealTypeRule(), new FutureBlockRule(), new AionExtraDataRule(this.getConstants().getMaximumExtraDataSize()), new EnergyConsumedRule(), new SignatureRule());
Map<Seal, List<BlockHeaderRule>> unityRules = new EnumMap<>(Seal.class);
unityRules.put(Seal.PROOF_OF_WORK, powRules);
unityRules.put(Seal.PROOF_OF_STAKE, posRules);
return new BlockHeaderValidator(unityRules);
}
Aggregations