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());
}
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()));
}
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()));
}
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;
}
}
Aggregations