use of org.tron.core.capsule.AccountCapsule in project java-tron by tronprotocol.
the class TransferActuatorTest method createCapsule.
/**
* create temp Capsule test need.
*/
@Before
public void createCapsule() {
AccountCapsule ownerCapsule = new AccountCapsule(ByteString.copyFromUtf8("owner"), ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS)), AccountType.Normal, 10000L);
AccountCapsule toAccountCapsule = new AccountCapsule(ByteString.copyFromUtf8("toAccount"), ByteString.copyFrom(ByteArray.fromHexString(TO_ADDRESS)), AccountType.Normal, 100L);
dbManager.getAccountStore().put(ownerCapsule.getAddress().toByteArray(), ownerCapsule);
dbManager.getAccountStore().put(toAccountCapsule.getAddress().toByteArray(), toAccountCapsule);
}
use of org.tron.core.capsule.AccountCapsule in project java-tron by tronprotocol.
the class TransferActuatorTest method perfectAssetIssue.
@Test
public void perfectAssetIssue() {
TransferActuator actuator = new TransferActuator(getContract(9999L), 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 - 9999 - ChainConstant.TRANSFER_FEE);
Assert.assertEquals(toAccount.getBalance(), 10099L);
} catch (ContractValidateException e) {
Assert.assertFalse(e instanceof ContractValidateException);
} catch (ContractExeException e) {
Assert.assertFalse(e instanceof ContractExeException);
}
}
use of org.tron.core.capsule.AccountCapsule in project java-tron by tronprotocol.
the class TransferAssetActuatorTest method perfectTransfer.
/**
* Unit test.
*/
@Test
public void perfectTransfer() {
TransferAssetActuator actuator = new TransferAssetActuator(getContract(10000L), 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(), 0L);
Assert.assertEquals(toAccount.getInstance().getAssetMap().get(ASSET_NAME).longValue(), 10000L);
} catch (ContractValidateException e) {
Assert.assertFalse(e instanceof ContractValidateException);
} catch (ContractExeException e) {
Assert.assertFalse(e instanceof ContractExeException);
}
}
use of org.tron.core.capsule.AccountCapsule in project java-tron by tronprotocol.
the class AssetIssueActuatorTest method createCapsule.
/**
* create temp Capsule test need.
*/
@Before
public void createCapsule() {
AccountCapsule ownerCapsule = new AccountCapsule(ByteString.copyFromUtf8("owner"), ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS)), AccountType.AssetIssue, ChainConstant.ASSET_ISSUE_FEE);
dbManager.getAccountStore().put(ownerCapsule.getAddress().toByteArray(), ownerCapsule);
}
use of org.tron.core.capsule.AccountCapsule 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);
}
}
Aggregations