use of org.aion.zero.impl.valid.EnergyLimitRule in project aion by aionnetwork.
the class EnergyLimitRuleTest method testEnergyLimitLowerBound.
@Test
public void testEnergyLimitLowerBound() {
final long INITIAL_VAL = 0l;
A0BlockHeader parentHeader = new A0BlockHeader.Builder().withEnergyLimit(0l).build();
A0BlockHeader currentHeader = new A0BlockHeader.Builder().withEnergyLimit(1l).build();
List<IValidRule.RuleError> errors = new ArrayList<>();
EnergyLimitRule rule = new EnergyLimitRule(constants.getEnergyDivisorLimitLong(), constants.getEnergyLowerBoundLong());
boolean res = rule.validate(currentHeader, parentHeader, errors);
assertThat(res).isEqualTo(false);
assertThat(errors).isNotEmpty();
}
use of org.aion.zero.impl.valid.EnergyLimitRule in project aion by aionnetwork.
the class EnergyLimitRuleTest method testEnergyLimitBounds.
@Test
public void testEnergyLimitBounds() {
final long INITIAL_VAL = 1000000l;
final long DIVISOR = 1024;
EnergyLimitRule rule = new EnergyLimitRule(constants.getEnergyDivisorLimitLong(), constants.getEnergyLowerBoundLong());
A0BlockHeader parentHeader = new A0BlockHeader.Builder().withEnergyLimit(1000000l).build();
long boundShiftLimit = INITIAL_VAL / DIVISOR;
A0BlockHeader upperCurrentBlock = new A0BlockHeader.Builder().withEnergyLimit(INITIAL_VAL + boundShiftLimit).build();
List<IValidRule.RuleError> errors = new ArrayList<>();
// upper bound
boolean res = rule.validate(upperCurrentBlock, parentHeader, errors);
assertThat(res).isEqualTo(true);
assertThat(errors).isEmpty();
errors.clear();
A0BlockHeader invalidCurrentHeader = new A0BlockHeader.Builder().withEnergyLimit(INITIAL_VAL + boundShiftLimit + 1).build();
res = rule.validate(invalidCurrentHeader, parentHeader, errors);
assertThat(res).isEqualTo(false);
assertThat(errors).isNotEmpty();
errors.clear();
// lower bound
A0BlockHeader lowerCurrentHeader = new A0BlockHeader.Builder().withEnergyLimit(INITIAL_VAL - boundShiftLimit).build();
res = rule.validate(lowerCurrentHeader, parentHeader, errors);
assertThat(res).isEqualTo(true);
assertThat(errors).isEmpty();
errors.clear();
A0BlockHeader invalidLowerCurrentHeader = new A0BlockHeader.Builder().withEnergyLimit(INITIAL_VAL - boundShiftLimit - 1).build();
res = rule.validate(invalidLowerCurrentHeader, parentHeader, errors);
assertThat(res).isEqualTo(false);
assertThat(errors).isNotEmpty();
errors.clear();
}
Aggregations