Search in sources :

Example 16 with ContractExeException

use of org.tron.core.exception.ContractExeException in project java-tron by tronprotocol.

the class TransferActuatorTest method moreAssetIssue.

@Test
public void moreAssetIssue() {
    TransferActuator actuator = new TransferActuator(getContract(10000L), dbManager);
    TransactionResultCapsule ret = new TransactionResultCapsule();
    try {
        actuator.validate();
        actuator.execute(ret);
        Assert.assertTrue(true);
    } catch (ContractValidateException e) {
        Assert.assertFalse(e instanceof ContractValidateException);
    } catch (ContractExeException e) {
        Assert.assertTrue(e instanceof ContractExeException);
        Assert.assertEquals(ret.getInstance().getRet(), code.FAILED);
    }
    AccountCapsule owner = dbManager.getAccountStore().get(ByteArray.fromHexString(OWNER_ADDRESS));
    AccountCapsule toAccount = dbManager.getAccountStore().get(ByteArray.fromHexString(TO_ADDRESS));
    logger.info(owner.getBalance() + ")))))");
    Assert.assertEquals(owner.getBalance(), 0 - ChainConstant.TRANSFER_FEE);
    Assert.assertEquals(toAccount.getBalance(), 10000 + 100L);
}
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 17 with ContractExeException

use of org.tron.core.exception.ContractExeException 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);
    }
}
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 18 with ContractExeException

use of org.tron.core.exception.ContractExeException in project java-tron by tronprotocol.

the class ManagerTest method fork.

@Test
public void fork() {
    Args.setParam(new String[] { "--witness" }, Configuration.getByPath(Constant.NORMAL_CONF));
    long size = dbManager.getBlockStore().dbSource.allKeys().size();
    String key = "00f31db24bfbd1a2ef19beddca0a0fa37632eded9ac666a05d3bd925f01dde1f62";
    byte[] privateKey = ByteArray.fromHexString(key);
    final ECKey ecKey = ECKey.fromPrivate(privateKey);
    byte[] address = ecKey.getAddress();
    WitnessCapsule witnessCapsule = new WitnessCapsule(ByteString.copyFrom(address));
    dbManager.addWitness(witnessCapsule);
    dbManager.addWitness(witnessCapsule);
    dbManager.addWitness(witnessCapsule);
    IntStream.range(0, 5).forEach(i -> {
        try {
            dbManager.generateBlock(witnessCapsule, System.currentTimeMillis(), privateKey);
        } catch (ValidateSignatureException | ContractValidateException | ContractExeException | UnLinkedBlockException e) {
            logger.debug(e.getMessage(), e);
        }
    });
    try {
        long num = dbManager.getDynamicPropertiesStore().getLatestBlockHeaderNumber();
        BlockCapsule blockCapsule1 = new BlockCapsule(num, dbManager.getHead().getParentHash().getByteString(), System.currentTimeMillis(), witnessCapsule.getAddress());
        blockCapsule1.generatedByMyself = true;
        BlockCapsule blockCapsule2 = new BlockCapsule(num + 1, blockCapsule1.getBlockId().getByteString(), System.currentTimeMillis(), witnessCapsule.getAddress());
        blockCapsule2.generatedByMyself = true;
        logger.error("******1*******" + "block1 id:" + blockCapsule1.getBlockId());
        logger.error("******2*******" + "block2 id:" + blockCapsule2.getBlockId());
        dbManager.pushBlock(blockCapsule1);
        dbManager.pushBlock(blockCapsule2);
        logger.error("******in blockStore block size:" + dbManager.getBlockStore().dbSource.allKeys().size());
        logger.error("******in blockStore block:" + dbManager.getBlockStore().dbSource.allKeys().stream().map(ByteArray::toHexString).collect(Collectors.toList()));
        Assert.assertNotNull(dbManager.getBlockStore().get(blockCapsule1.getBlockId().getBytes()));
        Assert.assertNotNull(dbManager.getBlockStore().get(blockCapsule2.getBlockId().getBytes()));
        Assert.assertEquals(dbManager.getBlockStore().get(blockCapsule2.getBlockId().getBytes()).getParentHash(), blockCapsule1.getBlockId());
        Assert.assertEquals(dbManager.getBlockStore().dbSource.allKeys().size(), size + 6);
        Assert.assertEquals(dbManager.getBlockIdByNum(dbManager.getHead().getNum() - 1), blockCapsule1.getBlockId());
        Assert.assertEquals(dbManager.getBlockIdByNum(dbManager.getHead().getNum() - 2), blockCapsule1.getParentHash());
        Assert.assertEquals(blockCapsule2.getBlockId().getByteString(), dbManager.getDynamicPropertiesStore().getLatestBlockHeaderHash());
        Assert.assertEquals(dbManager.getHead().getBlockId().getByteString(), dbManager.getDynamicPropertiesStore().getLatestBlockHeaderHash());
    } catch (ValidateSignatureException | ContractValidateException | ContractExeException | UnLinkedBlockException e) {
        logger.debug(e.getMessage(), e);
    }
    dbManager.getWitnesses().clear();
}
Also used : WitnessCapsule(org.tron.core.capsule.WitnessCapsule) ValidateSignatureException(org.tron.core.exception.ValidateSignatureException) ContractValidateException(org.tron.core.exception.ContractValidateException) ECKey(org.tron.common.crypto.ECKey) ByteString(com.google.protobuf.ByteString) UnLinkedBlockException(org.tron.core.exception.UnLinkedBlockException) BlockCapsule(org.tron.core.capsule.BlockCapsule) ContractExeException(org.tron.core.exception.ContractExeException) Test(org.junit.Test)

Example 19 with ContractExeException

use of org.tron.core.exception.ContractExeException 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);
    }
}
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 20 with ContractExeException

use of org.tron.core.exception.ContractExeException 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);
    }
}
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

ContractExeException (org.tron.core.exception.ContractExeException)28 ContractValidateException (org.tron.core.exception.ContractValidateException)20 AccountCapsule (org.tron.core.capsule.AccountCapsule)19 Test (org.junit.Test)16 TransactionResultCapsule (org.tron.core.capsule.TransactionResultCapsule)15 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)9 DateTime (org.joda.time.DateTime)5 AssetIssueCapsule (org.tron.core.capsule.AssetIssueCapsule)4 BlockCapsule (org.tron.core.capsule.BlockCapsule)4 ValidateSignatureException (org.tron.core.exception.ValidateSignatureException)4 ByteString (com.google.protobuf.ByteString)3 Dialog (org.tron.core.db.AbstractRevokingStore.Dialog)3 BalanceInsufficientException (org.tron.core.exception.BalanceInsufficientException)3 RevokingStoreIllegalStateException (org.tron.core.exception.RevokingStoreIllegalStateException)3 TransactionCapsule (org.tron.core.capsule.TransactionCapsule)2 UnLinkedBlockException (org.tron.core.exception.UnLinkedBlockException)2 Contract (org.tron.protos.Contract)2 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 NumberMessage (org.tron.api.GrpcAPI.NumberMessage)1