Search in sources :

Example 11 with ContractExeException

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

the class CreateAccountActuatorTest method firstCreateAccount.

/**
 * Unit test.
 */
@Test
public void firstCreateAccount() {
    CreateAccountActuator actuator = new CreateAccountActuator(getContract(ACCOUNT_NAME_FRIST, OWNER_ADDRESS_FRIST), dbManager);
    TransactionResultCapsule ret = new TransactionResultCapsule();
    try {
        actuator.validate();
        actuator.execute(ret);
        Assert.assertEquals(ret.getInstance().getRet(), code.SUCESS);
        AccountCapsule accountCapsule = dbManager.getAccountStore().get(ByteArray.fromHexString(OWNER_ADDRESS_FRIST));
        Assert.assertNotNull(accountCapsule);
        Assert.assertEquals(accountCapsule.getInstance().getAccountName(), ByteString.copyFromUtf8(ACCOUNT_NAME_FRIST));
    } 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 12 with ContractExeException

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

the class CreateAccountActuatorTest method secondCreateAccount.

/**
 * Unit test.
 */
@Test
public void secondCreateAccount() {
    CreateAccountActuator actuator = new CreateAccountActuator(getContract(ACCOUNT_NAME_SECOND, OWNER_ADDRESS_SECOND), dbManager);
    TransactionResultCapsule ret = new TransactionResultCapsule();
    try {
        actuator.validate();
        actuator.execute(ret);
    } catch (ContractValidateException e) {
        Assert.assertTrue(e instanceof ContractValidateException);
        AccountCapsule accountCapsule = dbManager.getAccountStore().get(ByteArray.fromHexString(OWNER_ADDRESS_SECOND));
        Assert.assertNotNull(accountCapsule);
        Assert.assertEquals(accountCapsule.getInstance().getAccountName(), ByteString.copyFromUtf8(ACCOUNT_NAME_SECOND));
    } 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 13 with ContractExeException

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

the class ParticipateAssetIssueActuatorTest method AssetIssueTimeLeft.

@Test
public void AssetIssueTimeLeft() {
    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 14 with ContractExeException

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

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

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