Search in sources :

Example 11 with AccountCapsule

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

the class AccountStore method getSun.

/**
 * Max TRX account.
 */
public AccountCapsule getSun() {
    byte[] data = dbSource.getData(ByteString.copyFrom(ByteArray.fromHexString(ACCOUNT_SUN_ADDRESS)).toByteArray());
    AccountCapsule accountCapsule = new AccountCapsule(data);
    return accountCapsule;
}
Also used : AccountCapsule(org.tron.core.capsule.AccountCapsule)

Example 12 with AccountCapsule

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

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

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

the class CreateAccountActuatorTest method createCapsule.

/**
 * create temp Capsule test need.
 */
@Before
public void createCapsule() {
    AccountCapsule ownerCapsule = new AccountCapsule(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS_SECOND)), ByteString.copyFromUtf8(ACCOUNT_NAME_SECOND), AccountType.AssetIssue);
    dbManager.getAccountStore().put(ownerCapsule.getAddress().toByteArray(), ownerCapsule);
    dbManager.getAccountStore().delete(ByteArray.fromHexString(OWNER_ADDRESS_FRIST));
}
Also used : AccountCapsule(org.tron.core.capsule.AccountCapsule) Before(org.junit.Before)

Example 15 with AccountCapsule

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

Aggregations

AccountCapsule (org.tron.core.capsule.AccountCapsule)42 ContractExeException (org.tron.core.exception.ContractExeException)22 ContractValidateException (org.tron.core.exception.ContractValidateException)20 TransactionResultCapsule (org.tron.core.capsule.TransactionResultCapsule)16 Test (org.junit.Test)15 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)9 DateTime (org.joda.time.DateTime)7 ByteString (com.google.protobuf.ByteString)5 Before (org.junit.Before)5 AssetIssueCapsule (org.tron.core.capsule.AssetIssueCapsule)5 BalanceInsufficientException (org.tron.core.exception.BalanceInsufficientException)5 WitnessCapsule (org.tron.core.capsule.WitnessCapsule)3 Args (org.tron.core.config.args.Args)3 GenesisBlock (org.tron.core.config.args.GenesisBlock)3 Contract (org.tron.protos.Contract)3 AccountStore (org.tron.core.db.AccountStore)2 TransferAssetContract (org.tron.protos.Contract.TransferAssetContract)2 RamUsageEstimator (com.carrotsearch.sizeof.RamUsageEstimator)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1