Search in sources :

Example 36 with PrecompiledTransactionResult

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());
}
Also used : PrecompiledTransactionResult(org.aion.precompiled.PrecompiledTransactionResult) AionAddress(org.aion.types.AionAddress) Test(org.junit.Test)

Example 37 with PrecompiledTransactionResult

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()));
}
Also used : PrecompiledTransactionResult(org.aion.precompiled.PrecompiledTransactionResult) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 38 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 39 with PrecompiledTransactionResult

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());
}
Also used : PrecompiledTransactionResult(org.aion.precompiled.PrecompiledTransactionResult) AddressFVM(org.aion.precompiled.encoding.AddressFVM) AbiEncoder(org.aion.precompiled.encoding.AbiEncoder) BigInteger(java.math.BigInteger) DataWord(org.aion.precompiled.util.DataWord) ListFVM(org.aion.precompiled.encoding.ListFVM) Test(org.junit.Test)

Example 40 with PrecompiledTransactionResult

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();
}
Also used : PrecompiledTransactionResult(org.aion.precompiled.PrecompiledTransactionResult) AionAddress(org.aion.types.AionAddress) PrecompiledTransactionContext(org.aion.precompiled.type.PrecompiledTransactionContext) 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