Search in sources :

Example 6 with TransactionResultCapsule

use of org.tron.core.capsule.TransactionResultCapsule in project java-tron by tronprotocol.

the class ParticipateAssetIssueActuatorTest method NegativeAmountTest.

@Test
public void NegativeAmountTest() {
    DateTime now = DateTime.now();
    initAssetIssue(now.minusDays(1).getMillis(), now.plusDays(1).getMillis());
    ParticipateAssetIssueActuator actuator = new ParticipateAssetIssueActuator(getContract(-999L), dbManager);
    TransactionResultCapsule ret = new TransactionResultCapsule();
    try {
        actuator.validate();
        actuator.execute(ret);
    } catch (ContractValidateException e) {
        Assert.assertTrue(e instanceof ContractValidateException);
        AccountCapsule owner = dbManager.getAccountStore().get(ByteArray.fromHexString(OWNER_ADDRESS));
        AccountCapsule toAccount = dbManager.getAccountStore().get(ByteArray.fromHexString(TO_ADDRESS));
        Assert.assertEquals(owner.getBalance(), 10000L);
        Assert.assertEquals(toAccount.getBalance(), 10000L);
        Assert.assertTrue(isNullOrZero(owner.getAssetMap().get(ASSET_NAME)));
        Assert.assertEquals(toAccount.getAssetMap().get(ASSET_NAME).longValue(), 10000000L);
    } catch (ContractExeException e) {
        Assert.assertFalse(e instanceof ContractExeException);
    }
}
Also used : AccountCapsule(org.tron.core.capsule.AccountCapsule) TransactionResultCapsule(org.tron.core.capsule.TransactionResultCapsule) ContractValidateException(org.tron.core.exception.ContractValidateException) DateTime(org.joda.time.DateTime) ContractExeException(org.tron.core.exception.ContractExeException) Test(org.junit.Test)

Example 7 with TransactionResultCapsule

use of org.tron.core.capsule.TransactionResultCapsule in project java-tron by tronprotocol.

the class ParticipateAssetIssueActuatorTest method AssetIssueTimeRight.

@Test
public void AssetIssueTimeRight() {
    DateTime now = DateTime.now();
    initAssetIssue(now.minusDays(1).getMillis(), now.getMillis());
    ParticipateAssetIssueActuator actuator = new ParticipateAssetIssueActuator(getContract(1000L), dbManager);
    TransactionResultCapsule ret = new TransactionResultCapsule();
    try {
        actuator.validate();
        actuator.execute(ret);
    } catch (ContractValidateException e) {
        Assert.assertTrue(e instanceof ContractValidateException);
        AccountCapsule owner = dbManager.getAccountStore().get(ByteArray.fromHexString(OWNER_ADDRESS));
        AccountCapsule toAccount = dbManager.getAccountStore().get(ByteArray.fromHexString(TO_ADDRESS));
        Assert.assertEquals(owner.getBalance(), 10000L);
        Assert.assertEquals(toAccount.getBalance(), 10000L);
        Assert.assertTrue(isNullOrZero(owner.getAssetMap().get(ASSET_NAME)));
        Assert.assertEquals(toAccount.getAssetMap().get(ASSET_NAME).longValue(), 10000000L);
    } catch (ContractExeException e) {
        Assert.assertFalse(e instanceof ContractExeException);
    }
}
Also used : AccountCapsule(org.tron.core.capsule.AccountCapsule) TransactionResultCapsule(org.tron.core.capsule.TransactionResultCapsule) ContractValidateException(org.tron.core.exception.ContractValidateException) DateTime(org.joda.time.DateTime) ContractExeException(org.tron.core.exception.ContractExeException) Test(org.junit.Test)

Example 8 with TransactionResultCapsule

use of org.tron.core.capsule.TransactionResultCapsule in project java-tron by tronprotocol.

the class TransferActuatorTest method moreAssetIssue.

@Test
public void moreAssetIssue() {
    TransferActuator actuator = new TransferActuator(getContract(10000L), dbManager);
    TransactionResultCapsule ret = new TransactionResultCapsule();
    try {
        actuator.validate();
        actuator.execute(ret);
        Assert.assertTrue(true);
    } catch (ContractValidateException e) {
        Assert.assertFalse(e instanceof ContractValidateException);
    } catch (ContractExeException e) {
        Assert.assertTrue(e instanceof ContractExeException);
        Assert.assertEquals(ret.getInstance().getRet(), code.FAILED);
    }
    AccountCapsule owner = dbManager.getAccountStore().get(ByteArray.fromHexString(OWNER_ADDRESS));
    AccountCapsule toAccount = dbManager.getAccountStore().get(ByteArray.fromHexString(TO_ADDRESS));
    logger.info(owner.getBalance() + ")))))");
    Assert.assertEquals(owner.getBalance(), 0 - ChainConstant.TRANSFER_FEE);
    Assert.assertEquals(toAccount.getBalance(), 10000 + 100L);
}
Also used : AccountCapsule(org.tron.core.capsule.AccountCapsule) TransactionResultCapsule(org.tron.core.capsule.TransactionResultCapsule) ContractValidateException(org.tron.core.exception.ContractValidateException) ContractExeException(org.tron.core.exception.ContractExeException) Test(org.junit.Test)

Example 9 with TransactionResultCapsule

use of org.tron.core.capsule.TransactionResultCapsule in project java-tron by tronprotocol.

the class TransferActuatorTest method perfectAssetIssue.

@Test
public void perfectAssetIssue() {
    TransferActuator actuator = new TransferActuator(getContract(9999L), dbManager);
    TransactionResultCapsule ret = new TransactionResultCapsule();
    try {
        actuator.validate();
        actuator.execute(ret);
        Assert.assertEquals(ret.getInstance().getRet(), code.SUCESS);
        AccountCapsule owner = dbManager.getAccountStore().get(ByteArray.fromHexString(OWNER_ADDRESS));
        AccountCapsule toAccount = dbManager.getAccountStore().get(ByteArray.fromHexString(TO_ADDRESS));
        Assert.assertEquals(owner.getBalance(), 10000 - 9999 - ChainConstant.TRANSFER_FEE);
        Assert.assertEquals(toAccount.getBalance(), 10099L);
    } catch (ContractValidateException e) {
        Assert.assertFalse(e instanceof ContractValidateException);
    } catch (ContractExeException e) {
        Assert.assertFalse(e instanceof ContractExeException);
    }
}
Also used : AccountCapsule(org.tron.core.capsule.AccountCapsule) TransactionResultCapsule(org.tron.core.capsule.TransactionResultCapsule) ContractValidateException(org.tron.core.exception.ContractValidateException) ContractExeException(org.tron.core.exception.ContractExeException) Test(org.junit.Test)

Example 10 with TransactionResultCapsule

use of org.tron.core.capsule.TransactionResultCapsule in project java-tron by tronprotocol.

the class TransferAssetActuatorTest method perfectTransfer.

/**
 * Unit test.
 */
@Test
public void perfectTransfer() {
    TransferAssetActuator actuator = new TransferAssetActuator(getContract(10000L), dbManager);
    TransactionResultCapsule ret = new TransactionResultCapsule();
    try {
        actuator.validate();
        actuator.execute(ret);
        Assert.assertEquals(ret.getInstance().getRet(), code.SUCESS);
        AccountCapsule owner = dbManager.getAccountStore().get(ByteArray.fromHexString(OWNER_ADDRESS));
        AccountCapsule toAccount = dbManager.getAccountStore().get(ByteArray.fromHexString(TO_ADDRESS));
        Assert.assertEquals(owner.getInstance().getAssetMap().get(ASSET_NAME).longValue(), 0L);
        Assert.assertEquals(toAccount.getInstance().getAssetMap().get(ASSET_NAME).longValue(), 10000L);
    } catch (ContractValidateException e) {
        Assert.assertFalse(e instanceof ContractValidateException);
    } catch (ContractExeException e) {
        Assert.assertFalse(e instanceof ContractExeException);
    }
}
Also used : AccountCapsule(org.tron.core.capsule.AccountCapsule) TransactionResultCapsule(org.tron.core.capsule.TransactionResultCapsule) ContractValidateException(org.tron.core.exception.ContractValidateException) ContractExeException(org.tron.core.exception.ContractExeException) Test(org.junit.Test)

Aggregations

TransactionResultCapsule (org.tron.core.capsule.TransactionResultCapsule)16 Test (org.junit.Test)15 AccountCapsule (org.tron.core.capsule.AccountCapsule)15 ContractExeException (org.tron.core.exception.ContractExeException)15 ContractValidateException (org.tron.core.exception.ContractValidateException)15 DateTime (org.joda.time.DateTime)5 AssetIssueCapsule (org.tron.core.capsule.AssetIssueCapsule)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Actuator (org.tron.core.actuator.Actuator)1 Contract (org.tron.protos.Contract)1