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