Search in sources :

Example 1 with TotalCurrencyContract

use of org.aion.precompiled.contracts.TotalCurrencyContract in project aion by aionnetwork.

the class TotalCurrencyContractTest method TestUpdateTotalNotOwner.

@Test
public void TestUpdateTotalNotOwner() {
    System.out.println("Running TestUpdateTotalNotOwner.");
    TotalCurrencyContract contract = new TotalCurrencyContract(state, ADDR, // diff owner.
    new AionAddress(ECKeyFac.inst().create().getAddress()));
    byte[] input = constructUpdateInput((byte) 0x0, (byte) 0x0);
    PrecompiledTransactionResult res = contract.execute(input, COST);
    assertEquals("FAILURE", res.getStatus().causeOfError);
    assertEquals(0L, res.getEnergyRemaining());
}
Also used : PrecompiledTransactionResult(org.aion.precompiled.PrecompiledTransactionResult) AionAddress(org.aion.types.AionAddress) TotalCurrencyContract(org.aion.precompiled.contracts.TotalCurrencyContract) Test(org.junit.Test)

Example 2 with TotalCurrencyContract

use of org.aion.precompiled.contracts.TotalCurrencyContract 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 3 with TotalCurrencyContract

use of org.aion.precompiled.contracts.TotalCurrencyContract in project aion by aionnetwork.

the class TotalCurrencyContractTest method setup.

@Before
public void setup() {
    state = ExternalStateForTests.usingDefaultRepository();
    ownerKey = ECKeyFac.inst().create();
    tcc = new TotalCurrencyContract(state, ADDR, new AionAddress(ownerKey.getAddress()));
}
Also used : AionAddress(org.aion.types.AionAddress) TotalCurrencyContract(org.aion.precompiled.contracts.TotalCurrencyContract) Before(org.junit.Before)

Example 4 with TotalCurrencyContract

use of org.aion.precompiled.contracts.TotalCurrencyContract in project aion by aionnetwork.

the class ContractFactory method getPrecompiledContract.

/**
 * Returns a new pre-compiled contract such that the address of the new contract is address.
 * Returns null if address does not map to any known contracts.
 *
 * @param context Passed in execution context.
 * @param externalState The current state of the world.
 * @return the specified pre-compiled address.
 */
public PrecompiledContract getPrecompiledContract(PrecompiledTransactionContext context, IExternalStateForPrecompiled externalState) {
    boolean fork_032 = externalState.isFork032Enabled();
    // TODO: need to provide a real solution for the repository here ....
    AionAddress destination = context.destinationAddress;
    if (destination.equals(ContractInfo.TOKEN_BRIDGE.contractAddress)) {
        TokenBridgeContract contract = new TokenBridgeContract(context, externalState, ContractInfo.TOKEN_BRIDGE.ownerAddress, ContractInfo.TOKEN_BRIDGE.contractAddress);
        if (!context.originAddress.equals(ContractInfo.TOKEN_BRIDGE.ownerAddress) && !contract.isInitialized()) {
            return null;
        }
        return contract;
    } else if (destination.equals(ContractInfo.ED_VERIFY.contractAddress)) {
        return fork_032 ? new EDVerifyContract() : null;
    } else if (destination.equals(ContractInfo.BLAKE_2B.contractAddress)) {
        return fork_032 ? new Blake2bHashContract() : null;
    } else if (destination.equals(ContractInfo.TRANSACTION_HASH.contractAddress)) {
        return fork_032 ? new TXHashContract(context) : null;
    } else if (destination.equals(ContractInfo.TOTAL_CURRENCY.contractAddress)) {
        return fork_032 ? null : new TotalCurrencyContract(externalState, context.senderAddress, ContractInfo.TOTAL_CURRENCY.ownerAddress);
    } else {
        return null;
    }
}
Also used : Blake2bHashContract(org.aion.precompiled.contracts.Blake2bHashContract) AionAddress(org.aion.types.AionAddress) TokenBridgeContract(org.aion.precompiled.contracts.ATB.TokenBridgeContract) EDVerifyContract(org.aion.precompiled.contracts.EDVerifyContract) TotalCurrencyContract(org.aion.precompiled.contracts.TotalCurrencyContract) TXHashContract(org.aion.precompiled.contracts.TXHashContract)

Aggregations

TotalCurrencyContract (org.aion.precompiled.contracts.TotalCurrencyContract)4 AionAddress (org.aion.types.AionAddress)4 PrecompiledTransactionResult (org.aion.precompiled.PrecompiledTransactionResult)2 Test (org.junit.Test)2 BigInteger (java.math.BigInteger)1 TokenBridgeContract (org.aion.precompiled.contracts.ATB.TokenBridgeContract)1 Blake2bHashContract (org.aion.precompiled.contracts.Blake2bHashContract)1 EDVerifyContract (org.aion.precompiled.contracts.EDVerifyContract)1 TXHashContract (org.aion.precompiled.contracts.TXHashContract)1 Before (org.junit.Before)1