Search in sources :

Example 51 with PrecompiledTransactionResult

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

the class TotalCurrencyContractTest method TestGetTotalAmount.

// <------------------------------------------------------------------------------------------->
@Test
public void TestGetTotalAmount() {
    System.out.println("Running TestGetTotalAmount.");
    // input == chainID
    byte[] payload = new byte[] { 0 };
    PrecompiledTransactionResult res = tcc.execute(payload, COST);
    System.out.println("Contract result: " + res.toString());
    assertTrue(res.getStatus().isSuccess());
    assertEquals(0L, res.getEnergyRemaining());
}
Also used : PrecompiledTransactionResult(org.aion.precompiled.PrecompiledTransactionResult) Test(org.junit.Test)

Example 52 with PrecompiledTransactionResult

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

the class TotalCurrencyContractTest method TestSubtractTotalAmountBelowZero.

@Test
public void TestSubtractTotalAmountBelowZero() {
    System.out.println("Running TestSubtractTotalAmountBelowZero.");
    // 0x1 == subtract
    byte[] input = constructUpdateInput((byte) 0x0, (byte) 0x1);
    PrecompiledTransactionResult res = tcc.execute(input, COST);
    assertEquals("FAILURE", res.getStatus().causeOfError);
    assertEquals(0L, res.getEnergyRemaining());
    // Verify total amount is non-negative.
    res = tcc.execute(new byte[] { (byte) 0x0 }, COST);
    assertEquals(BigInteger.ZERO, new BigInteger(1, res.getReturnData()));
}
Also used : PrecompiledTransactionResult(org.aion.precompiled.PrecompiledTransactionResult) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 53 with PrecompiledTransactionResult

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

the class TotalCurrencyContractTest method TestUpdateAndGetTotalAmount.

@Test
public void TestUpdateAndGetTotalAmount() {
    System.out.println("Running TestUpdateAndGetTotalAmount.");
    byte[] input = constructUpdateInput((byte) 0x0, (byte) 0x0);
    PrecompiledTransactionResult res = tcc.execute(input, COST);
    assertTrue(res.getStatus().isSuccess());
    assertEquals(0L, res.getEnergyRemaining());
    tcc = new TotalCurrencyContract(state, ADDR, new AionAddress(ownerKey.getAddress()));
    input = new byte[] { (byte) 0x0 };
    res = tcc.execute(input, COST);
    assertTrue(res.getStatus().isSuccess());
    assertEquals(AMT, new BigInteger(1, res.getReturnData()));
}
Also used : PrecompiledTransactionResult(org.aion.precompiled.PrecompiledTransactionResult) AionAddress(org.aion.types.AionAddress) BigInteger(java.math.BigInteger) TotalCurrencyContract(org.aion.precompiled.contracts.TotalCurrencyContract) Test(org.junit.Test)

Example 54 with PrecompiledTransactionResult

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

the class TotalCurrencyContractTest method TestBadSignum.

@Test
public void TestBadSignum() {
    System.out.println("Running TestBadSigum.");
    // only 0, 1 are valid.
    byte[] input = constructUpdateInput((byte) 0x0, (byte) 0x2);
    PrecompiledTransactionResult res = tcc.execute(input, COST);
    assertEquals("FAILURE", res.getStatus().causeOfError);
    assertEquals(0L, res.getEnergyRemaining());
}
Also used : PrecompiledTransactionResult(org.aion.precompiled.PrecompiledTransactionResult) Test(org.junit.Test)

Example 55 with PrecompiledTransactionResult

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

the class TotalCurrencyContractTest method TestUpdateTotalAmount.

@Test
public void TestUpdateTotalAmount() {
    System.out.println("Running TestUpdateTotalAmount.");
    byte[] input = constructUpdateInput((byte) 0x0, (byte) 0x0);
    PrecompiledTransactionResult res = tcc.execute(input, COST);
    assertTrue(res.getStatus().isSuccess());
    assertEquals(0L, 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