Search in sources :

Example 6 with PrecompiledContract

use of org.aion.precompiled.type.PrecompiledContract in project aion by aionnetwork.

the class EDVerifyContractTest method shouldFailIfNotEnoughEnergy.

@Test
public void shouldFailIfNotEnoughEnergy() {
    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);
    PrecompiledTransactionResult result = contract.execute(input, 2999L);
    assertEquals("OUT_OF_NRG", 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 7 with PrecompiledContract

use of org.aion.precompiled.type.PrecompiledContract in project aion by aionnetwork.

the class EDVerifyContractTest method shouldFailIfNotEnoughEnergy.

@Test
public void shouldFailIfNotEnoughEnergy() {
    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);
    PrecompiledTransactionResult result = contract.execute(input, 2999L);
    assertEquals("OUT_OF_NRG", 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 8 with PrecompiledContract

use of org.aion.precompiled.type.PrecompiledContract in project aion by aionnetwork.

the class EDVerifyContractTest method emptyInputTest.

@Test
public void emptyInputTest() {
    byte[] input = new byte[128];
    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 9 with PrecompiledContract

use of org.aion.precompiled.type.PrecompiledContract in project aion by aionnetwork.

the class BenchmarkTest method benchBlake2bHash.

@Test
public void benchBlake2bHash() {
    PrecompiledTransactionContext context = new PrecompiledTransactionContext(ContractInfo.BLAKE_2B.contractAddress, origin, caller, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), txHash, txHash, blockNumber, nrgLimit, depth);
    ExternalStateForTests externalStateForTests = ExternalStateForTests.usingDefaultRepository();
    PrecompiledContract ct;
    // warm up
    for (int i = 0; i < WARMUP; i++) {
        ct = cf.getPrecompiledContract(context, externalStateForTests);
        ct.execute(txHash, context.transactionEnergy);
    }
    long t1 = System.currentTimeMillis();
    for (int i = 0; i < BENCH; i++) {
        ct = cf.getPrecompiledContract(context, externalStateForTests);
        ct.execute(txHash, context.transactionEnergy);
    }
    System.out.println("Bench blake2b: " + String.valueOf(System.currentTimeMillis() - t1) + "ms");
}
Also used : PrecompiledContract(org.aion.precompiled.type.PrecompiledContract) PrecompiledTransactionContext(org.aion.precompiled.type.PrecompiledTransactionContext) ExternalStateForTests(org.aion.zero.impl.precompiled.ExternalStateForTests) Test(org.junit.Test)

Example 10 with PrecompiledContract

use of org.aion.precompiled.type.PrecompiledContract in project aion by aionnetwork.

the class EDVerifyContractTest method emptyInputTest.

@Test
public void emptyInputTest() {
    byte[] input = new byte[128];
    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(), ownerAddr));
}
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

PrecompiledContract (org.aion.precompiled.type.PrecompiledContract)11 PrecompiledTransactionContext (org.aion.precompiled.type.PrecompiledTransactionContext)11 Test (org.junit.Test)11 ContractFactory (org.aion.precompiled.ContractFactory)10 PrecompiledTransactionResult (org.aion.precompiled.PrecompiledTransactionResult)10 ExternalStateForTests (org.aion.zero.impl.precompiled.ExternalStateForTests)1