use of org.aion.precompiled.PrecompiledTransactionResult in project aion by aionnetwork.
the class TotalCurrencyContractTest method TestUpdateTotalNotOwner.
@Test
public void TestUpdateTotalNotOwner() {
System.out.println("Running TestUpdateTotalNotOwner.");
TotalCurrencyContract contract = new TotalCurrencyContract(ExternalStateForTests.usingDefaultRepository(), ADDR, // diff owner.
new AionAddress(getRandomAddr()));
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.PrecompiledTransactionResult in project aion by aionnetwork.
the class TotalCurrencyContractTest method TestSubtractTotalAmount.
@Test
public void TestSubtractTotalAmount() {
System.out.println("Running TestSubtractTotalAmount.");
// First give some positive balance to take away.
byte[] input = constructUpdateInput((byte) 0x0, (byte) 0x0);
tcc.execute(input, COST);
tcc.execute(input, COST);
tcc.execute(input, COST);
// Remove the balance.
input = constructUpdateInput((byte) 0x0, (byte) 0x1);
tcc.execute(input, COST);
PrecompiledTransactionResult res = tcc.execute(new byte[] { (byte) 0x0 }, COST);
assertEquals(TransactionStatus.successful(), res.getStatus());
assertEquals(AMT.multiply(BigInteger.valueOf(2)), new BigInteger(res.getReturnData()));
tcc.execute(input, COST);
tcc.execute(input, COST);
res = tcc.execute(new byte[] { (byte) 0x0 }, COST);
assertEquals(TransactionStatus.successful(), res.getStatus());
assertEquals(BigInteger.ZERO, new BigInteger(res.getReturnData()));
}
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());
}
use of org.aion.precompiled.PrecompiledTransactionResult in project aion by aionnetwork.
the class TokenBridgeContractTest method testMinThreshold.
@Test
public void testMinThreshold() {
// override defaults
this.contract = new TokenBridgeContract(context(OWNER_ADDR, CONTRACT_ADDR), ExternalStateForTests.usingRepository(this.repository), OWNER_ADDR, CONTRACT_ADDR);
this.connector = this.contract.getConnector();
ListFVM encodingList = new ListFVM();
for (byte[] k : members) {
encodingList.add(new AddressFVM(k));
}
byte[] payload = new AbiEncoder(BridgeFuncSig.SIG_RING_INITIALIZE.getSignature(), encodingList).encodeBytes();
PrecompiledTransactionResult result = this.contract.execute(payload, DEFAULT_NRG);
assertEquals(result.getStatus(), TransactionStatus.successful());
// try before
byte[] callPayload = new AbiEncoder(BridgeFuncSig.PURE_MIN_THRESH.getSignature(), encodingList).encodeBytes();
PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG);
assertTrue(transferResult.getStatus().isSuccess());
assertThat(transferResult.getReturnData()).isEqualTo(new DataWord(new BigInteger("3")).getData());
// explicitly set the min threshold to 5
this.connector.setMinThresh(5);
// try after
byte[] callPayload2 = new AbiEncoder(BridgeFuncSig.PURE_MIN_THRESH.getSignature(), encodingList).encodeBytes();
PrecompiledTransactionResult transferResult2 = this.contract.execute(callPayload2, DEFAULT_NRG);
assertTrue(transferResult2.getStatus().isSuccess());
assertThat(transferResult2.getReturnData()).isEqualTo(new DataWord(new BigInteger("5")).getData());
// try setting threshold greater than number of validator members
this.connector.setMinThresh(10);
// try after
byte[] callPayload3 = new AbiEncoder(BridgeFuncSig.PURE_MIN_THRESH.getSignature(), encodingList).encodeBytes();
PrecompiledTransactionResult transferResult3 = this.contract.execute(callPayload3, DEFAULT_NRG);
assertTrue(transferResult3.getStatus().isSuccess());
assertThat(transferResult3.getReturnData()).isEqualTo(new DataWord(new BigInteger("10")).getData());
}
use of org.aion.precompiled.PrecompiledTransactionResult in project aion by aionnetwork.
the class TokenBridgeContractTest method testTransferHugeListLength.
@Test
public void testTransferHugeListLength() {
BridgeTransfer[] transfers = new BridgeTransfer[10];
for (int i = 0; i < 10; i++) {
// generate a unique sourceTransactionHash for each transfer
byte[] sourceTransactionHash = capabilities.blake2b(Integer.toString(i).getBytes());
transfers[i] = BridgeTransfer.getInstance(BigInteger.ONE, capabilities.computeA0Address(capabilities.blake2b(Integer.toHexString(i).getBytes())), sourceTransactionHash);
}
// setup
ReturnDataFromSetup fromSetup = setupForTest(transfers, members);
PrecompiledTransactionContext submitBundleContext = fromSetup.submitBundleContext;
byte[] payloadHash = fromSetup.payloadHash;
byte[] callPayload = fromSetup.callPayload;
callPayload[50] = (byte) 0x128;
PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG);
assertEquals("FAILURE", transferResult.getStatus().causeOfError);
// VERIFICATION failure
assertThat(this.contract.execute(ByteUtil.merge(BridgeFuncSig.PURE_ACTION_MAP.getBytes(), payloadHash), 21000L).getReturnData()).isEqualTo(new byte[32]);
assertEquals("FAILURE", transferResult.getStatus().causeOfError);
// check that nothing has been changed from the failed transfer
for (BridgeTransfer b : transfers) {
assertThat(this.repository.getBalance(new AionAddress(b.getRecipient()))).isEqualTo(BigInteger.ZERO);
}
assertThat(this.repository.getBalance(CONTRACT_ADDR)).isEqualTo(BigInteger.valueOf(10));
assertThat(submitBundleContext.getInternalTransactions()).isEmpty();
assertThat(submitBundleContext.getLogs()).isEmpty();
}
Aggregations