Search in sources :

Example 1 with ContractFactory

use of org.aion.precompiled.ContractFactory in project aion by aionnetwork.

the class EDVerifyContractTest method invalidInputLengthTest.

@Test
public void invalidInputLengthTest() {
    // note the length is 129
    byte[] input = new byte[129];
    input[128] = 0x1;
    PrecompiledTransactionContext ctx = new PrecompiledTransactionContext(ContractInfo.ED_VERIFY.contractAddress, origin, caller, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), txHash, txHash, blockNumber, nrgLimit, depth);
    PrecompiledContract contract = new ContractFactory().getPrecompiledContract(ctx, externalStateForTests);
    PrecompiledTransactionResult result = contract.execute(input, 21000L);
    assertEquals("FAILURE", result.getStatus().causeOfError);
}
Also used : PrecompiledContract(org.aion.precompiled.type.PrecompiledContract) PrecompiledTransactionResult(org.aion.precompiled.PrecompiledTransactionResult) PrecompiledTransactionContext(org.aion.precompiled.type.PrecompiledTransactionContext) ContractFactory(org.aion.precompiled.ContractFactory) Test(org.junit.Test)

Example 2 with ContractFactory

use of org.aion.precompiled.ContractFactory in project aion by aionnetwork.

the class EDVerifyContractTest method shouldReturnSuccessTestingWith256.

@Test
public void shouldReturnSuccessTestingWith256() {
    byte[] input = setupInput();
    PrecompiledTransactionContext ctx = new PrecompiledTransactionContext(ContractInfo.ED_VERIFY.contractAddress, origin, caller, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), txHash, txHash, blockNumber, nrgLimit, depth);
    PrecompiledContract contract = new ContractFactory().getPrecompiledContract(ctx, externalStateForTests);
    assertNotNull(contract);
    PrecompiledTransactionResult result = contract.execute(input, 21000L);
    assertThat(result.getStatus().isSuccess());
    assertThat(Arrays.equals(result.getReturnData(), pubKey));
}
Also used : PrecompiledContract(org.aion.precompiled.type.PrecompiledContract) PrecompiledTransactionResult(org.aion.precompiled.PrecompiledTransactionResult) PrecompiledTransactionContext(org.aion.precompiled.type.PrecompiledTransactionContext) ContractFactory(org.aion.precompiled.ContractFactory) Test(org.junit.Test)

Example 3 with ContractFactory

use of org.aion.precompiled.ContractFactory in project aion by aionnetwork.

the class EDVerifyContractTest method incorrectInputTest.

@Test
public void incorrectInputTest() {
    byte[] input = setupInput();
    // modify sig
    input[22] = (byte) ((int) (input[32]) - 10);
    // modify sig
    input[33] = (byte) ((int) (input[33]) + 4);
    // modify sig
    input[99] = (byte) ((int) (input[33]) - 40);
    PrecompiledTransactionContext ctx = new PrecompiledTransactionContext(ContractInfo.ED_VERIFY.contractAddress, origin, caller, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), txHash, txHash, blockNumber, nrgLimit, depth);
    PrecompiledContract contract = new ContractFactory().getPrecompiledContract(ctx, externalStateForTests);
    assertNotNull(contract);
    PrecompiledTransactionResult result = contract.execute(input, 21000L);
    assertThat(result.getStatus().isSuccess());
    assertThat(Arrays.equals(result.getReturnData(), AddressUtils.ZERO_ADDRESS.toByteArray()));
}
Also used : PrecompiledContract(org.aion.precompiled.type.PrecompiledContract) PrecompiledTransactionResult(org.aion.precompiled.PrecompiledTransactionResult) PrecompiledTransactionContext(org.aion.precompiled.type.PrecompiledTransactionContext) ContractFactory(org.aion.precompiled.ContractFactory) Test(org.junit.Test)

Example 4 with ContractFactory

use of org.aion.precompiled.ContractFactory in project aion by aionnetwork.

the class EDVerifyContractTest method invalidInputLengthTest.

@Test
public void invalidInputLengthTest() {
    // note the length is 129
    byte[] input = new byte[129];
    input[128] = 0x1;
    PrecompiledTransactionContext ctx = new PrecompiledTransactionContext(ContractInfo.ED_VERIFY.contractAddress, origin, caller, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), txHash, txHash, blockNumber, nrgLimit, depth);
    PrecompiledContract contract = new ContractFactory().getPrecompiledContract(ctx, externalStateForTests);
    PrecompiledTransactionResult result = contract.execute(input, 21000L);
    assertEquals("FAILURE", result.getStatus().causeOfError);
}
Also used : PrecompiledContract(org.aion.precompiled.type.PrecompiledContract) PrecompiledTransactionResult(org.aion.precompiled.PrecompiledTransactionResult) PrecompiledTransactionContext(org.aion.precompiled.type.PrecompiledTransactionContext) ContractFactory(org.aion.precompiled.ContractFactory) Test(org.junit.Test)

Example 5 with ContractFactory

use of org.aion.precompiled.ContractFactory in project aion by aionnetwork.

the class EDVerifyContractTest method incorrectInputTest.

@Test
public void incorrectInputTest() {
    byte[] input = setupInput();
    // modify sig
    input[22] = (byte) ((int) (input[32]) - 10);
    // modify sig
    input[33] = (byte) ((int) (input[33]) + 4);
    // modify sig
    input[99] = (byte) ((int) (input[33]) - 40);
    PrecompiledTransactionContext ctx = new PrecompiledTransactionContext(ContractInfo.ED_VERIFY.contractAddress, origin, caller, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), txHash, txHash, blockNumber, nrgLimit, depth);
    PrecompiledContract contract = new ContractFactory().getPrecompiledContract(ctx, externalStateForTests);
    assertNotNull(contract);
    PrecompiledTransactionResult result = contract.execute(input, 21000L);
    assertThat(result.getStatus().isSuccess());
    assertThat(Arrays.equals(result.getReturnData(), AddressUtils.ZERO_ADDRESS.toByteArray()));
}
Also used : PrecompiledContract(org.aion.precompiled.type.PrecompiledContract) PrecompiledTransactionResult(org.aion.precompiled.PrecompiledTransactionResult) PrecompiledTransactionContext(org.aion.precompiled.type.PrecompiledTransactionContext) ContractFactory(org.aion.precompiled.ContractFactory) Test(org.junit.Test)

Aggregations

ContractFactory (org.aion.precompiled.ContractFactory)13 PrecompiledTransactionResult (org.aion.precompiled.PrecompiledTransactionResult)12 PrecompiledContract (org.aion.precompiled.type.PrecompiledContract)10 PrecompiledTransactionContext (org.aion.precompiled.type.PrecompiledTransactionContext)10 Test (org.junit.Test)10 AionAddress (org.aion.types.AionAddress)1 Before (org.junit.Before)1