use of org.tron.core.exception.ContractExeException in project java-tron by tronprotocol.
the class ParticipateAssetIssueActuatorTest method rightAssetIssue.
@Test
public void rightAssetIssue() {
DateTime now = DateTime.now();
initAssetIssue(now.minusDays(1).getMillis(), now.plusDays(1).getMillis());
ParticipateAssetIssueActuator actuator = new ParticipateAssetIssueActuator(getContract(1000L), 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(), 9000L);
Assert.assertEquals(toAccount.getBalance(), 11000L);
Assert.assertEquals(owner.getAssetMap().get(ASSET_NAME).longValue(), (1000L) / 2 * 11);
Assert.assertEquals(toAccount.getAssetMap().get(ASSET_NAME).longValue(), 10000000L - (1000L) / 2 * 11);
} catch (ContractValidateException e) {
Assert.assertFalse(e instanceof ContractValidateException);
} catch (ContractExeException e) {
Assert.assertFalse(e instanceof ContractExeException);
}
}
use of org.tron.core.exception.ContractExeException in project java-tron by tronprotocol.
the class TransferActuatorTest method rightAssetIssue.
@Test
public void rightAssetIssue() {
TransferActuator actuator = new TransferActuator(getContract(AMOUNT), 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 - AMOUNT - ChainConstant.TRANSFER_FEE);
Assert.assertEquals(toAccount.getBalance(), 100 + AMOUNT);
} catch (ContractValidateException e) {
Assert.assertFalse(e instanceof ContractValidateException);
} catch (ContractExeException e) {
Assert.assertFalse(e instanceof ContractExeException);
}
}
use of org.tron.core.exception.ContractExeException in project java-tron by tronprotocol.
the class TransferAssetActuatorTest method rightTransfer.
/**
* Unit test.
*/
@Test
public void rightTransfer() {
TransferAssetActuator actuator = new TransferAssetActuator(getContract(100L), 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(), 9900L);
Assert.assertEquals(toAccount.getInstance().getAssetMap().get(ASSET_NAME).longValue(), 100L);
} catch (ContractValidateException e) {
Assert.assertFalse(e instanceof ContractValidateException);
} catch (ContractExeException e) {
Assert.assertFalse(e instanceof ContractExeException);
}
}
use of org.tron.core.exception.ContractExeException in project java-tron by tronprotocol.
the class TransferAssetActuatorTest method wrongTransfer.
/**
* Unit test.
*/
@Test
public void wrongTransfer() {
TransferAssetActuator actuator = new TransferAssetActuator(getContract(10001L), dbManager);
TransactionResultCapsule ret = new TransactionResultCapsule();
try {
actuator.validate();
actuator.execute(ret);
Assert.assertTrue(false);
} catch (ContractValidateException e) {
Assert.assertTrue(e instanceof ContractValidateException);
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.getAssetMap().get(ASSET_NAME).longValue(), 10000L);
Assert.assertTrue(isNullOrZero(toAccount.getAssetMap().get(ASSET_NAME)));
} catch (ContractExeException e) {
Assert.assertFalse(e instanceof ContractExeException);
}
}
use of org.tron.core.exception.ContractExeException in project java-tron by tronprotocol.
the class VoteWitnessActuator method execute.
@Override
public boolean execute(TransactionResultCapsule ret) throws ContractExeException {
long fee = calcFee();
try {
VoteWitnessContract voteContract = contract.unpack(VoteWitnessContract.class);
countVoteAccount(voteContract);
ret.setStatus(fee, code.SUCESS);
} catch (InvalidProtocolBufferException e) {
logger.debug(e.getMessage(), e);
ret.setStatus(fee, code.FAILED);
throw new ContractExeException(e.getMessage());
}
return true;
}
Aggregations