Search in sources :

Example 11 with TransactionResultCapsule

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

the class ParticipateAssetIssueActuatorTest method ExchangeDevisibleTest.

@Test
public void ExchangeDevisibleTest() {
    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 12 with TransactionResultCapsule

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

the class ParticipateAssetIssueActuatorTest method rightAssetIssue.

@Test
public void rightAssetIssue() {
    DateTime now = DateTime.now();
    initAssetIssue(now.minusDays(1).getMillis(), now.plusDays(1).getMillis());
    ParticipateAssetIssueActuator actuator = new ParticipateAssetIssueActuator(getContract(1000L), 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(), 9000L);
        Assert.assertEquals(toAccount.getBalance(), 11000L);
        Assert.assertEquals(owner.getAssetMap().get(ASSET_NAME).longValue(), (1000L) / 2 * 11);
        Assert.assertEquals(toAccount.getAssetMap().get(ASSET_NAME).longValue(), 10000000L - (1000L) / 2 * 11);
    } 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) DateTime(org.joda.time.DateTime) ContractExeException(org.tron.core.exception.ContractExeException) Test(org.junit.Test)

Example 13 with TransactionResultCapsule

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

the class TransferActuatorTest method rightAssetIssue.

@Test
public void rightAssetIssue() {
    TransferActuator actuator = new TransferActuator(getContract(AMOUNT), 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 - AMOUNT - ChainConstant.TRANSFER_FEE);
        Assert.assertEquals(toAccount.getBalance(), 100 + AMOUNT);
    } 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 14 with TransactionResultCapsule

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

the class TransferAssetActuatorTest method rightTransfer.

/**
 * Unit test.
 */
@Test
public void rightTransfer() {
    TransferAssetActuator actuator = new TransferAssetActuator(getContract(100L), 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(), 9900L);
        Assert.assertEquals(toAccount.getInstance().getAssetMap().get(ASSET_NAME).longValue(), 100L);
    } 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 15 with TransactionResultCapsule

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

the class TransferAssetActuatorTest method wrongTransfer.

/**
 * Unit test.
 */
@Test
public void wrongTransfer() {
    TransferAssetActuator actuator = new TransferAssetActuator(getContract(10001L), dbManager);
    TransactionResultCapsule ret = new TransactionResultCapsule();
    try {
        actuator.validate();
        actuator.execute(ret);
        Assert.assertTrue(false);
    } catch (ContractValidateException e) {
        Assert.assertTrue(e instanceof ContractValidateException);
        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.getAssetMap().get(ASSET_NAME).longValue(), 10000L);
        Assert.assertTrue(isNullOrZero(toAccount.getAssetMap().get(ASSET_NAME)));
    } 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