use of org.aion.zero.impl.valid.AionExtraDataRule in project aion by aionnetwork.
the class ExtraDataRuleTest method testEmptyByteArray.
@Test
public void testEmptyByteArray() {
byte[] EMPTY_BYTE_ARR = new byte[0];
when(mockHeader.getExtraData()).thenReturn(EMPTY_BYTE_ARR);
List<IValidRule.RuleError> errors = new ArrayList<>();
AionExtraDataRule dataRule = new AionExtraDataRule(constants.getMaximumExtraDataSize());
boolean res = dataRule.validate(mockHeader, errors);
assertThat(res).isEqualTo(true);
assertThat(errors).isEmpty();
}
use of org.aion.zero.impl.valid.AionExtraDataRule 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.AionExtraDataRule in project aion by aionnetwork.
the class ExtraDataRuleTest method testInvalidLargerByteArray.
@Test
public void testInvalidLargerByteArray() {
byte[] LARGE_BYTE_ARRAY = new byte[33];
when(mockHeader.getExtraData()).thenReturn(LARGE_BYTE_ARRAY);
List<IValidRule.RuleError> errors = new ArrayList<>();
AionExtraDataRule dataRule = new AionExtraDataRule(constants.getMaximumExtraDataSize());
boolean res = dataRule.validate(mockHeader, errors);
assertThat(res).isEqualTo(false);
assertThat(errors).isNotEmpty();
}
use of org.aion.zero.impl.valid.AionExtraDataRule in project aion by aionnetwork.
the class ExtraDataRuleTest method testNullByteArray.
// even though this should never happen in production
@Test
public void testNullByteArray() {
when(mockHeader.getExtraData()).thenReturn(null);
List<IValidRule.RuleError> errors = new ArrayList<>();
AionExtraDataRule dataRule = new AionExtraDataRule(constants.getMaximumExtraDataSize());
boolean res = dataRule.validate(mockHeader, errors);
assertThat(res).isEqualTo(true);
assertThat(errors).isEmpty();
}
use of org.aion.zero.impl.valid.AionExtraDataRule 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