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));
}
}
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));
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations