Search in sources :

Example 11 with ForkUtility

use of org.aion.zero.impl.forks.ForkUtility in project aion by aionnetwork.

the class BeaconHashValidatorTest method validateTxForPendingStateWithoutBeaconHash.

@Test
public void validateTxForPendingStateWithoutBeaconHash() {
    long unityForkNumber = 3;
    ForkUtility forkUtility = new ForkUtility();
    forkUtility.enableUnityFork(unityForkNumber);
    IAionBlockchain blockchain = mock(IAionBlockchain.class);
    Block bestBlock = mock(Block.class);
    when(blockchain.getBestBlock()).thenReturn(bestBlock);
    AionTransaction tx = AionTransaction.createWithoutKey(// nonce - any val
    new byte[] { 1 }, new AionAddress(// sender - any val
    ByteUtil.hexStringToBytes("0xa000000000000000000000000000000000000000000000000000000000000000")), new AionAddress(// destination - any val
    ByteUtil.hexStringToBytes("0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")), // value - any val
    new byte[] { 1 }, // data - any val
    new byte[] {}, // energyLimit - any val
    1l, // energyPrice - any val
    1l, // type - any val
    (byte) 1, // beacon hash - absent
    null);
    BeaconHashValidator unit = new BeaconHashValidator(blockchain, forkUtility);
    when(bestBlock.getNumber()).thenReturn(unityForkNumber - 2);
    assertWithMessage("validation should pass for pending state if beacon hash absent").that(unit.validateTxForPendingState(tx)).isTrue();
    when(bestBlock.getNumber()).thenReturn(unityForkNumber - 1);
    assertWithMessage("validation should pass for pending state if beacon hash absent").that(unit.validateTxForPendingState(tx)).isTrue();
    when(bestBlock.getNumber()).thenReturn(unityForkNumber);
    assertWithMessage("validation should pass for pending state if beacon hash absent").that(unit.validateTxForPendingState(tx)).isTrue();
}
Also used : AionAddress(org.aion.types.AionAddress) Block(org.aion.zero.impl.types.Block) IAionBlockchain(org.aion.zero.impl.blockchain.IAionBlockchain) AionTransaction(org.aion.base.AionTransaction) ForkUtility(org.aion.zero.impl.forks.ForkUtility) Test(org.junit.Test)

Aggregations

ForkUtility (org.aion.zero.impl.forks.ForkUtility)11 Test (org.junit.Test)11 AionTransaction (org.aion.base.AionTransaction)10 AionAddress (org.aion.types.AionAddress)10 IAionBlockchain (org.aion.zero.impl.blockchain.IAionBlockchain)10 Block (org.aion.zero.impl.types.Block)10