Search in sources :

Example 46 with PrecompiledTransactionResult

use of org.aion.precompiled.PrecompiledTransactionResult 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 47 with PrecompiledTransactionResult

use of org.aion.precompiled.PrecompiledTransactionResult 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 48 with PrecompiledTransactionResult

use of org.aion.precompiled.PrecompiledTransactionResult 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 49 with PrecompiledTransactionResult

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

the class TotalCurrencyContractTest method TestUpdateMultipleChains.

@Test
public void TestUpdateMultipleChains() {
    System.out.println("Running TestUpdateMultipleChains.");
    byte[] input0 = constructUpdateInput((byte) 0x0, (byte) 0x0);
    byte[] input1 = constructUpdateInput((byte) 0x1, (byte) 0x0);
    byte[] input2 = constructUpdateInput((byte) 0x10, (byte) 0x0);
    tcc.execute(input0, COST);
    tcc.execute(input1, COST);
    tcc.execute(input1, COST);
    tcc.execute(input2, COST);
    tcc.execute(input2, COST);
    tcc.execute(input2, COST);
    tcc.execute(input2, COST);
    PrecompiledTransactionResult res = // get chain 0.
    tcc.execute(new byte[] { (byte) 0x0 }, COST);
    assertTrue(res.getStatus().isSuccess());
    assertEquals(AMT, new BigInteger(res.getReturnData()));
    // get chain 1.
    res = tcc.execute(new byte[] { (byte) 0x1 }, COST);
    assertTrue(res.getStatus().isSuccess());
    assertEquals(AMT.multiply(BigInteger.valueOf(2)), new BigInteger(res.getReturnData()));
    // get chain 16.
    res = tcc.execute((new byte[] { (byte) 0x10 }), COST);
    assertTrue(res.getStatus().isSuccess());
    assertEquals(AMT.multiply(BigInteger.valueOf(4)), new BigInteger(res.getReturnData()));
}
Also used : PrecompiledTransactionResult(org.aion.precompiled.PrecompiledTransactionResult) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 50 with PrecompiledTransactionResult

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

the class TotalCurrencyContractTest method TestGetTotalAmountInsufficientNrg.

@Test
public void TestGetTotalAmountInsufficientNrg() {
    System.out.println("Running TestGetTotalAmountInsufficientNrg");
    byte[] payload = new byte[] { 0 };
    PrecompiledTransactionResult res = tcc.execute(payload, COST - 1);
    assertEquals("OUT_OF_NRG", res.getStatus().causeOfError);
    assertEquals(0, res.getEnergyRemaining());
}
Also used : PrecompiledTransactionResult(org.aion.precompiled.PrecompiledTransactionResult) Test(org.junit.Test)

Aggregations

PrecompiledTransactionResult (org.aion.precompiled.PrecompiledTransactionResult)114 Test (org.junit.Test)103 PrecompiledTransactionContext (org.aion.precompiled.type.PrecompiledTransactionContext)39 AionAddress (org.aion.types.AionAddress)36 TokenBridgeContract (org.aion.precompiled.contracts.ATB.TokenBridgeContract)26 ECKey (org.aion.crypto.ECKey)25 AbiEncoder (org.aion.precompiled.encoding.AbiEncoder)25 AddressFVM (org.aion.precompiled.encoding.AddressFVM)25 AbiEncoder (org.aion.zero.impl.precompiled.encoding.AbiEncoder)25 AddressFVM (org.aion.zero.impl.precompiled.encoding.AddressFVM)25 BigInteger (java.math.BigInteger)24 ListFVM (org.aion.precompiled.encoding.ListFVM)23 ListFVM (org.aion.zero.impl.precompiled.encoding.ListFVM)23 BridgeTransfer (org.aion.precompiled.contracts.ATB.BridgeTransfer)16 ContractFactory (org.aion.precompiled.ContractFactory)12 Uint128FVM (org.aion.precompiled.encoding.Uint128FVM)11 Uint128FVM (org.aion.zero.impl.precompiled.encoding.Uint128FVM)11 PrecompiledContract (org.aion.precompiled.type.PrecompiledContract)10 InternalTransaction (org.aion.types.InternalTransaction)7 Log (org.aion.types.Log)6