Search in sources :

Example 6 with CustomFixedFee

use of com.hedera.hashgraph.sdk.CustomFixedFee in project hedera-mirror-node by hashgraph.

the class TokenFeature method verifyTokenWithCustomFeesSchedule.

private void verifyTokenWithCustomFeesSchedule(TokenId tokenId, String createdTimestamp) {
    MirrorTokenResponse response = verifyToken(tokenId);
    MirrorCustomFees expected = new MirrorCustomFees();
    expected.setCreatedTimestamp(createdTimestamp);
    for (CustomFee customFee : tokenCustomFees.get(tokenId)) {
        if (customFee instanceof CustomFixedFee) {
            CustomFixedFee sdkFixedFee = (CustomFixedFee) customFee;
            MirrorFixedFee fixedFee = new MirrorFixedFee();
            fixedFee.setAmount(sdkFixedFee.getAmount());
            fixedFee.setCollectorAccountId(sdkFixedFee.getFeeCollectorAccountId().toString());
            if (sdkFixedFee.getDenominatingTokenId() != null) {
                fixedFee.setDenominatingTokenId(sdkFixedFee.getDenominatingTokenId().toString());
            }
            expected.getFixedFees().add(fixedFee);
        } else {
            CustomFractionalFee sdkFractionalFee = (CustomFractionalFee) customFee;
            MirrorFractionalFee fractionalFee = new MirrorFractionalFee();
            MirrorFraction fraction = new MirrorFraction();
            fraction.setNumerator(sdkFractionalFee.getNumerator());
            fraction.setDenominator(sdkFractionalFee.getDenominator());
            fractionalFee.setAmount(fraction);
            fractionalFee.setCollectorAccountId(sdkFractionalFee.getFeeCollectorAccountId().toString());
            fractionalFee.setDenominatingTokenId(tokenId.toString());
            if (sdkFractionalFee.getMax() != 0) {
                fractionalFee.setMaximum(sdkFractionalFee.getMax());
            }
            fractionalFee.setMinimum(sdkFractionalFee.getMin());
            expected.getFractionalFees().add(fractionalFee);
        }
    }
    MirrorCustomFees actual = response.getCustomFees();
    assertThat(actual).usingRecursiveComparison(RecursiveComparisonConfiguration.builder().withIgnoreCollectionOrder(true).build()).isEqualTo(expected);
}
Also used : MirrorCustomFees(com.hedera.mirror.test.e2e.acceptance.props.MirrorCustomFees) MirrorFraction(com.hedera.mirror.test.e2e.acceptance.props.MirrorFraction) CustomFractionalFee(com.hedera.hashgraph.sdk.CustomFractionalFee) CustomFee(com.hedera.hashgraph.sdk.CustomFee) MirrorAssessedCustomFee(com.hedera.mirror.test.e2e.acceptance.props.MirrorAssessedCustomFee) CustomFixedFee(com.hedera.hashgraph.sdk.CustomFixedFee) MirrorFractionalFee(com.hedera.mirror.test.e2e.acceptance.props.MirrorFractionalFee) MirrorFixedFee(com.hedera.mirror.test.e2e.acceptance.props.MirrorFixedFee) MirrorTokenResponse(com.hedera.mirror.test.e2e.acceptance.response.MirrorTokenResponse)

Example 7 with CustomFixedFee

use of com.hedera.hashgraph.sdk.CustomFixedFee in project hedera-sdk-java by hashgraph.

the class TokenCreateIntegrationTest method canCreateRoyaltyFee.

@Test
@DisplayName("Can create NFT with royalty fee")
void canCreateRoyaltyFee() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var tokenId = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setTreasuryAccountId(testEnv.operatorId).setSupplyKey(testEnv.operatorKey).setAdminKey(testEnv.operatorKey).setTokenType(TokenType.NON_FUNGIBLE_UNIQUE).setCustomFees(Collections.singletonList(new CustomRoyaltyFee().setNumerator(1).setDenominator(10).setFallbackFee(new CustomFixedFee().setHbarAmount(new Hbar(1))).setFeeCollectorAccountId(testEnv.operatorId))).execute(testEnv.client).getReceipt(testEnv.client).tokenId;
    testEnv.close(tokenId);
}
Also used : CustomRoyaltyFee(com.hedera.hashgraph.sdk.CustomRoyaltyFee) CustomFixedFee(com.hedera.hashgraph.sdk.CustomFixedFee) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 8 with CustomFixedFee

use of com.hedera.hashgraph.sdk.CustomFixedFee in project hedera-sdk-java by hashgraph.

the class TokenCreateIntegrationTest method canCreateTokenWithCustomFees.

@Test
@DisplayName("Can create token with custom fees")
void canCreateTokenWithCustomFees() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    var customFees = new ArrayList<CustomFee>();
    customFees.add(new CustomFixedFee().setAmount(10).setFeeCollectorAccountId(testEnv.operatorId));
    customFees.add(new CustomFractionalFee().setNumerator(1).setDenominator(20).setMin(1).setMax(10).setFeeCollectorAccountId(testEnv.operatorId));
    var tokenId = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setTreasuryAccountId(testEnv.operatorId).setAdminKey(testEnv.operatorKey).setCustomFees(customFees).execute(testEnv.client).getReceipt(testEnv.client).tokenId;
    testEnv.close(tokenId);
}
Also used : CustomFractionalFee(com.hedera.hashgraph.sdk.CustomFractionalFee) ArrayList(java.util.ArrayList) CustomFixedFee(com.hedera.hashgraph.sdk.CustomFixedFee) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 9 with CustomFixedFee

use of com.hedera.hashgraph.sdk.CustomFixedFee in project hedera-sdk-java by hashgraph.

the class TokenTransferIntegrationTest method insufficientBalanceForFee.

@Test
@DisplayName("Cannot transfer tokens if balance is insufficient to pay fee")
void insufficientBalanceForFee() throws Exception {
    var testEnv = new IntegrationTestEnv(1).useThrowawayAccount();
    PrivateKey key1 = PrivateKey.generateED25519();
    PrivateKey key2 = PrivateKey.generateED25519();
    var accountId1 = new AccountCreateTransaction().setKey(key1).setInitialBalance(new Hbar(2)).execute(testEnv.client).getReceipt(testEnv.client).accountId;
    var accountId2 = new AccountCreateTransaction().setKey(key2).setInitialBalance(new Hbar(2)).execute(testEnv.client).getReceipt(testEnv.client).accountId;
    var tokenId = new TokenCreateTransaction().setTokenName("ffff").setTokenSymbol("F").setInitialSupply(1).setCustomFees(Collections.singletonList(new CustomFixedFee().setAmount(5000_000_000L).setFeeCollectorAccountId(testEnv.operatorId))).setTreasuryAccountId(testEnv.operatorId).setAdminKey(testEnv.operatorKey).setFeeScheduleKey(testEnv.operatorKey).execute(testEnv.client).getReceipt(testEnv.client).tokenId;
    new TokenAssociateTransaction().setAccountId(accountId1).setTokenIds(Collections.singletonList(tokenId)).freezeWith(testEnv.client).sign(key1).execute(testEnv.client).getReceipt(testEnv.client);
    new TokenAssociateTransaction().setAccountId(accountId2).setTokenIds(Collections.singletonList(tokenId)).freezeWith(testEnv.client).sign(key2).execute(testEnv.client).getReceipt(testEnv.client);
    new TransferTransaction().addTokenTransfer(tokenId, testEnv.operatorId, -1).addTokenTransfer(tokenId, accountId1, 1).freezeWith(testEnv.client).sign(key1).execute(testEnv.client).getReceipt(testEnv.client);
    assertThatExceptionOfType(ReceiptStatusException.class).isThrownBy(() -> {
        new TransferTransaction().addTokenTransfer(tokenId, accountId1, -1).addTokenTransfer(tokenId, accountId2, 1).freezeWith(testEnv.client).sign(key1).sign(key2).execute(testEnv.client).getReceipt(testEnv.client);
    }).satisfies(error -> assertThat(error.getMessage()).containsAnyOf(Status.INSUFFICIENT_SENDER_ACCOUNT_BALANCE_FOR_CUSTOM_FEE.toString(), Status.INSUFFICIENT_PAYER_BALANCE_FOR_CUSTOM_FEE.toString()));
    testEnv.wipeAccountHbars(accountId1, key1);
    testEnv.wipeAccountHbars(accountId2, key2);
    testEnv.close();
}
Also used : PrivateKey(com.hedera.hashgraph.sdk.PrivateKey) TokenAssociateTransaction(com.hedera.hashgraph.sdk.TokenAssociateTransaction) CustomFixedFee(com.hedera.hashgraph.sdk.CustomFixedFee) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenCreateTransaction(com.hedera.hashgraph.sdk.TokenCreateTransaction) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) AccountCreateTransaction(com.hedera.hashgraph.sdk.AccountCreateTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

CustomFixedFee (com.hedera.hashgraph.sdk.CustomFixedFee)9 TokenCreateTransaction (com.hedera.hashgraph.sdk.TokenCreateTransaction)7 CustomFractionalFee (com.hedera.hashgraph.sdk.CustomFractionalFee)6 DisplayName (org.junit.jupiter.api.DisplayName)6 Test (org.junit.jupiter.api.Test)6 Hbar (com.hedera.hashgraph.sdk.Hbar)3 TokenFeeScheduleUpdateTransaction (com.hedera.hashgraph.sdk.TokenFeeScheduleUpdateTransaction)3 ArrayList (java.util.ArrayList)3 AccountCreateTransaction (com.hedera.hashgraph.sdk.AccountCreateTransaction)2 AccountId (com.hedera.hashgraph.sdk.AccountId)2 CustomFee (com.hedera.hashgraph.sdk.CustomFee)2 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)2 TokenAssociateTransaction (com.hedera.hashgraph.sdk.TokenAssociateTransaction)2 TokenInfoQuery (com.hedera.hashgraph.sdk.TokenInfoQuery)2 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)2 Var (com.google.errorprone.annotations.Var)1 AccountBalanceQuery (com.hedera.hashgraph.sdk.AccountBalanceQuery)1 AccountDeleteTransaction (com.hedera.hashgraph.sdk.AccountDeleteTransaction)1 Client (com.hedera.hashgraph.sdk.Client)1 CustomRoyaltyFee (com.hedera.hashgraph.sdk.CustomRoyaltyFee)1