Search in sources :

Example 1 with AionExtraDataRule

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();
}
Also used : AionExtraDataRule(org.aion.zero.impl.valid.AionExtraDataRule) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with AionExtraDataRule

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);
}
Also used : GreatGrandParentBlockHeaderValidator(org.aion.zero.impl.valid.GreatGrandParentBlockHeaderValidator) ParentBlockHeaderValidator(org.aion.zero.impl.valid.ParentBlockHeaderValidator) GrandParentBlockHeaderValidator(org.aion.zero.impl.valid.GrandParentBlockHeaderValidator) BlockHeaderValidator(org.aion.zero.impl.valid.BlockHeaderValidator) EquihashSolutionRule(org.aion.zero.impl.valid.EquihashSolutionRule) SignatureRule(org.aion.zero.impl.valid.SignatureRule) EnergyConsumedRule(org.aion.zero.impl.valid.EnergyConsumedRule) HeaderSealTypeRule(org.aion.zero.impl.valid.HeaderSealTypeRule) AionExtraDataRule(org.aion.zero.impl.valid.AionExtraDataRule) Seal(org.aion.zero.impl.types.BlockHeader.Seal) List(java.util.List) DependentBlockHeaderRule(org.aion.zero.impl.valid.DependentBlockHeaderRule) BlockHeaderRule(org.aion.zero.impl.valid.BlockHeaderRule) GreatGrandParentDependantBlockHeaderRule(org.aion.zero.impl.valid.GreatGrandParentDependantBlockHeaderRule) GrandParentDependantBlockHeaderRule(org.aion.zero.impl.valid.GrandParentDependantBlockHeaderRule) AionPOWRule(org.aion.zero.impl.valid.AionPOWRule) EnumMap(java.util.EnumMap)

Example 3 with AionExtraDataRule

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();
}
Also used : AionExtraDataRule(org.aion.zero.impl.valid.AionExtraDataRule) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with AionExtraDataRule

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();
}
Also used : AionExtraDataRule(org.aion.zero.impl.valid.AionExtraDataRule) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with AionExtraDataRule

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);
}
Also used : GreatGrandParentBlockHeaderValidator(org.aion.zero.impl.valid.GreatGrandParentBlockHeaderValidator) ParentBlockHeaderValidator(org.aion.zero.impl.valid.ParentBlockHeaderValidator) GrandParentBlockHeaderValidator(org.aion.zero.impl.valid.GrandParentBlockHeaderValidator) BlockHeaderValidator(org.aion.zero.impl.valid.BlockHeaderValidator) FutureBlockRule(org.aion.zero.impl.valid.FutureBlockRule) EquihashSolutionRule(org.aion.zero.impl.valid.EquihashSolutionRule) SignatureRule(org.aion.zero.impl.valid.SignatureRule) EnergyConsumedRule(org.aion.zero.impl.valid.EnergyConsumedRule) HeaderSealTypeRule(org.aion.zero.impl.valid.HeaderSealTypeRule) AionExtraDataRule(org.aion.zero.impl.valid.AionExtraDataRule) Seal(org.aion.zero.impl.types.BlockHeader.Seal) List(java.util.List) DependentBlockHeaderRule(org.aion.zero.impl.valid.DependentBlockHeaderRule) BlockHeaderRule(org.aion.zero.impl.valid.BlockHeaderRule) GreatGrandParentDependantBlockHeaderRule(org.aion.zero.impl.valid.GreatGrandParentDependantBlockHeaderRule) GrandParentDependantBlockHeaderRule(org.aion.zero.impl.valid.GrandParentDependantBlockHeaderRule) AionPOWRule(org.aion.zero.impl.valid.AionPOWRule) EnumMap(java.util.EnumMap)

Aggregations

AionExtraDataRule (org.aion.zero.impl.valid.AionExtraDataRule)5 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 EnumMap (java.util.EnumMap)2 List (java.util.List)2 Seal (org.aion.zero.impl.types.BlockHeader.Seal)2 AionPOWRule (org.aion.zero.impl.valid.AionPOWRule)2 BlockHeaderRule (org.aion.zero.impl.valid.BlockHeaderRule)2 BlockHeaderValidator (org.aion.zero.impl.valid.BlockHeaderValidator)2 DependentBlockHeaderRule (org.aion.zero.impl.valid.DependentBlockHeaderRule)2 EnergyConsumedRule (org.aion.zero.impl.valid.EnergyConsumedRule)2 EquihashSolutionRule (org.aion.zero.impl.valid.EquihashSolutionRule)2 GrandParentBlockHeaderValidator (org.aion.zero.impl.valid.GrandParentBlockHeaderValidator)2 GrandParentDependantBlockHeaderRule (org.aion.zero.impl.valid.GrandParentDependantBlockHeaderRule)2 GreatGrandParentBlockHeaderValidator (org.aion.zero.impl.valid.GreatGrandParentBlockHeaderValidator)2 GreatGrandParentDependantBlockHeaderRule (org.aion.zero.impl.valid.GreatGrandParentDependantBlockHeaderRule)2 HeaderSealTypeRule (org.aion.zero.impl.valid.HeaderSealTypeRule)2 ParentBlockHeaderValidator (org.aion.zero.impl.valid.ParentBlockHeaderValidator)2 SignatureRule (org.aion.zero.impl.valid.SignatureRule)2 FutureBlockRule (org.aion.zero.impl.valid.FutureBlockRule)1