Search in sources :

Example 21 with ContractExeException

use of org.tron.core.exception.ContractExeException 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 22 with ContractExeException

use of org.tron.core.exception.ContractExeException 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 23 with ContractExeException

use of org.tron.core.exception.ContractExeException 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 24 with ContractExeException

use of org.tron.core.exception.ContractExeException 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)

Example 25 with ContractExeException

use of org.tron.core.exception.ContractExeException in project java-tron by tronprotocol.

the class VoteWitnessActuator method execute.

@Override
public boolean execute(TransactionResultCapsule ret) throws ContractExeException {
    long fee = calcFee();
    try {
        VoteWitnessContract voteContract = contract.unpack(VoteWitnessContract.class);
        countVoteAccount(voteContract);
        ret.setStatus(fee, code.SUCESS);
    } catch (InvalidProtocolBufferException e) {
        logger.debug(e.getMessage(), e);
        ret.setStatus(fee, code.FAILED);
        throw new ContractExeException(e.getMessage());
    }
    return true;
}
Also used : VoteWitnessContract(org.tron.protos.Contract.VoteWitnessContract) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ContractExeException(org.tron.core.exception.ContractExeException)

Aggregations

ContractExeException (org.tron.core.exception.ContractExeException)28 ContractValidateException (org.tron.core.exception.ContractValidateException)20 AccountCapsule (org.tron.core.capsule.AccountCapsule)19 Test (org.junit.Test)16 TransactionResultCapsule (org.tron.core.capsule.TransactionResultCapsule)15 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)9 DateTime (org.joda.time.DateTime)5 AssetIssueCapsule (org.tron.core.capsule.AssetIssueCapsule)4 BlockCapsule (org.tron.core.capsule.BlockCapsule)4 ValidateSignatureException (org.tron.core.exception.ValidateSignatureException)4 ByteString (com.google.protobuf.ByteString)3 Dialog (org.tron.core.db.AbstractRevokingStore.Dialog)3 BalanceInsufficientException (org.tron.core.exception.BalanceInsufficientException)3 RevokingStoreIllegalStateException (org.tron.core.exception.RevokingStoreIllegalStateException)3 TransactionCapsule (org.tron.core.capsule.TransactionCapsule)2 UnLinkedBlockException (org.tron.core.exception.UnLinkedBlockException)2 Contract (org.tron.protos.Contract)2 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 NumberMessage (org.tron.api.GrpcAPI.NumberMessage)1