Search in sources :

Example 1 with TransactionResultCapsule

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

the class AssetIssueActuatorTest method rightAssetIssue.

@Test
public void rightAssetIssue() {
    AssetIssueActuator actuator = new AssetIssueActuator(getContract(), 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));
        AssetIssueCapsule assetIssueCapsule = dbManager.getAssetIssueStore().get(ByteString.copyFromUtf8(NAME).toByteArray());
        Assert.assertNotNull(assetIssueCapsule);
        Assert.assertEquals(owner.getBalance(), 0L);
        Assert.assertEquals(owner.getAssetMap().get(NAME).longValue(), 10000L);
    } catch (ContractValidateException e) {
        Assert.assertFalse(e instanceof ContractValidateException);
    } catch (ContractExeException e) {
        Assert.assertFalse(e instanceof ContractExeException);
    } finally {
        dbManager.getAssetIssueStore().delete(ByteArray.fromString(NAME));
    }
}
Also used : AccountCapsule(org.tron.core.capsule.AccountCapsule) TransactionResultCapsule(org.tron.core.capsule.TransactionResultCapsule) ContractValidateException(org.tron.core.exception.ContractValidateException) AssetIssueCapsule(org.tron.core.capsule.AssetIssueCapsule) ContractExeException(org.tron.core.exception.ContractExeException) Test(org.junit.Test)

Example 2 with TransactionResultCapsule

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

the class AssetIssueActuatorTest method repeatAssetIssue.

@Test
public void repeatAssetIssue() {
    AssetIssueActuator actuator = new AssetIssueActuator(getContract(), dbManager);
    TransactionResultCapsule ret = new TransactionResultCapsule();
    try {
        dbManager.getAssetIssueStore().put(ByteArray.fromString(NAME), new AssetIssueCapsule(getContract().unpack(Contract.AssetIssueContract.class)));
        actuator.validate();
        actuator.execute(ret);
        Assert.assertTrue(false);
    } catch (ContractValidateException e) {
        Assert.assertTrue(e instanceof ContractValidateException);
        AccountCapsule owner = dbManager.getAccountStore().get(ByteArray.fromHexString(OWNER_ADDRESS));
        AssetIssueCapsule assetIssueCapsule = dbManager.getAssetIssueStore().get(ByteArray.fromString(NAME));
        Assert.assertNotNull(assetIssueCapsule);
        Assert.assertNull(owner.getInstance().getAssetMap().get(NAME));
    } catch (ContractExeException e) {
        Assert.assertFalse(e instanceof ContractExeException);
    } catch (InvalidProtocolBufferException e) {
        Assert.assertFalse(e instanceof InvalidProtocolBufferException);
    } finally {
        dbManager.getAssetIssueStore().delete(ByteArray.fromString(NAME));
    }
}
Also used : AccountCapsule(org.tron.core.capsule.AccountCapsule) TransactionResultCapsule(org.tron.core.capsule.TransactionResultCapsule) ContractValidateException(org.tron.core.exception.ContractValidateException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) AssetIssueCapsule(org.tron.core.capsule.AssetIssueCapsule) Contract(org.tron.protos.Contract) ContractExeException(org.tron.core.exception.ContractExeException) Test(org.junit.Test)

Example 3 with TransactionResultCapsule

use of org.tron.core.capsule.TransactionResultCapsule 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 4 with TransactionResultCapsule

use of org.tron.core.capsule.TransactionResultCapsule 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 5 with TransactionResultCapsule

use of org.tron.core.capsule.TransactionResultCapsule 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)

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