Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import static com.hedera.services.bdd.spec.transactions.TxnUtils.asId;
import static com.hedera.services.bdd.spec.transactions.TxnUtils.asIdWithAlias;
import static com.hedera.services.bdd.spec.transactions.TxnUtils.extractTxnId;
import static com.hedera.services.bdd.suites.HapiSuite.ONE_HBAR;
import static com.hedera.services.bdd.suites.HapiSuite.ONE_HUNDRED_HBARS;
import static java.util.Collections.EMPTY_LIST;
import static java.util.stream.Collectors.toList;

Expand All @@ -29,7 +31,6 @@
import com.hedera.services.bdd.spec.queries.meta.HapiGetTxnRecord;
import com.hedera.services.bdd.spec.transactions.TxnUtils;
import com.hedera.services.bdd.spec.utilops.mod.BodyMutation;
import com.hedera.services.bdd.suites.HapiSuite;
import com.hederahashgraph.api.proto.java.AccountID;
import com.hederahashgraph.api.proto.java.CustomFeeLimit;
import com.hederahashgraph.api.proto.java.Duration;
Expand Down Expand Up @@ -297,7 +298,7 @@ protected Transaction finalizedTxn(
final double tinybarFee = centsFee
/ spec.ratesProvider().rates().getCentEquiv()
* spec.ratesProvider().rates().getHbarEquiv()
* HapiSuite.ONE_HBAR;
* ONE_HBAR;
fee = Optional.of((long) tinybarFee);
}
Consumer<TransactionBody.Builder> netDef = fee.map(amount -> minDef.andThen(b -> b.setTransactionFee(amount)))
Expand All @@ -318,9 +319,14 @@ protected Transaction finalizedTxn(
} else {
final Key payerKey =
spec.registry().getKey(payer.orElse(spec.setup().defaultPayerName()));
final int numPayerKeys = hardcodedNumPayerKeys.orElse(spec.keys().controlledKeyCount(payerKey, overrides));
final long customFee = feeFor(spec, provisional, numPayerKeys);
netDef = netDef.andThen(b -> b.setTransactionFee(customFee));
if (simpleFeesEnabled(spec)) {
netDef = netDef.andThen(b -> b.setTransactionFee(ONE_HUNDRED_HBARS));
} else {
final int numPayerKeys =
hardcodedNumPayerKeys.orElse(spec.keys().controlledKeyCount(payerKey, overrides));
final long customFee = feeFor(spec, provisional, numPayerKeys);
netDef = netDef.andThen(b -> b.setTransactionFee(customFee));
}
txn = getSigned(spec, spec.txns().getReadyToSign(netDef, bodyMutation, spec), keys);
}

Expand Down Expand Up @@ -481,4 +487,11 @@ public static void registerTransaction(final HapiSpec spec, final String txnName
spec.registry().saveTxnId(txnName, txnId);
}
}

private boolean simpleFeesEnabled(HapiSpec spec) {
return spec.targetNetworkOrThrow()
.startupProperties()
.get("fees.simpleFeesEnabled")
.equals("true");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,22 @@
import static com.hedera.services.bdd.spec.transactions.token.CustomFeeSpecs.fixedHbarFee;
import static com.hedera.services.bdd.spec.transactions.token.TokenMovement.moving;
import static com.hedera.services.bdd.spec.transactions.token.TokenMovement.movingUnique;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.doSeveralWithStartupConfig;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.doWithStartupConfig;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.overridingTwo;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.sleepFor;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.sourcing;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.specOps;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.validateChargedUsd;
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.validateChargedUsdWithin;
import static com.hedera.services.bdd.suites.HapiSuite.GENESIS;
import static com.hedera.services.bdd.suites.HapiSuite.ONE_HBAR;
import static com.hedera.services.bdd.suites.HapiSuite.ONE_HUNDRED_HBARS;
import static com.hedera.services.bdd.suites.HapiSuite.THREE_MONTHS_IN_SECONDS;
import static com.hedera.services.bdd.suites.HapiSuite.TOKEN_TREASURY;
import static com.hedera.services.bdd.suites.hip1261.utils.SimpleFeesScheduleConstantsInUsd.CRYPTO_APPROVE_ALLOWANCE_FEE;
import static com.hedera.services.bdd.suites.hip1261.utils.SimpleFeesScheduleConstantsInUsd.CRYPTO_UPDATE_FEE;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_MAX_AUTO_ASSOCIATIONS;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.REQUESTED_NUM_AUTOMATIC_ASSOCIATIONS_EXCEEDS_ASSOCIATION_LIMIT;
import static com.hederahashgraph.api.proto.java.TokenType.FUNGIBLE_COMMON;
Expand Down Expand Up @@ -218,44 +223,40 @@ final Stream<DynamicTest> cryptoApproveAllowanceBaseUSDFee() {
.payingWith(OWNER)
.addCryptoAllowance(OWNER, SPENDER, 100L)
.via("approve")
.fee(ONE_HBAR)
.blankMemo()
.logged(),
.blankMemo(),
validateChargedUsdWithin("approve", 0.05, 0.01),
cryptoApproveAllowance()
.payingWith(OWNER)
.addTokenAllowance(OWNER, FUNGIBLE_TOKEN, SPENDER, 100L)
.via("approveTokenTxn")
.fee(ONE_HBAR)
.blankMemo()
.logged(),
.blankMemo(),
validateChargedUsdWithin("approveTokenTxn", 0.05012, 0.01),
cryptoApproveAllowance()
.payingWith(OWNER)
.addNftAllowance(OWNER, NON_FUNGIBLE_TOKEN, SPENDER, false, List.of(1L))
.via("approveNftTxn")
.fee(ONE_HBAR)
.blankMemo()
.logged(),
.blankMemo(),
validateChargedUsdWithin("approveNftTxn", 0.050101, 0.01),
cryptoApproveAllowance()
.payingWith(OWNER)
.addNftAllowance(OWNER, NON_FUNGIBLE_TOKEN, ANOTHER_SPENDER, true, List.of())
.via("approveForAllNftTxn")
.fee(ONE_HBAR)
.blankMemo()
.logged(),
.blankMemo(),
validateChargedUsdWithin("approveForAllNftTxn", 0.05, 0.01),
cryptoApproveAllowance()
.payingWith(OWNER)
.addCryptoAllowance(OWNER, SECOND_SPENDER, 100L)
.addTokenAllowance(OWNER, FUNGIBLE_TOKEN, SECOND_SPENDER, 100L)
.addNftAllowance(OWNER, NON_FUNGIBLE_TOKEN, SECOND_SPENDER, false, List.of(1L))
.via(APPROVE_TXN)
.fee(ONE_HBAR)
.blankMemo()
.logged(),
validateChargedUsdWithin(APPROVE_TXN, 0.05238, 0.01),
.blankMemo(),
doWithStartupConfig("fees.simpleFeesEnabled", flag -> {
if ("true".equals(flag)) {
return validateChargedUsdWithin(APPROVE_TXN, 3 * CRYPTO_APPROVE_ALLOWANCE_FEE, 0.01);
} else {
return validateChargedUsdWithin(APPROVE_TXN, 0.05238, 0.01);
}
}),
getAccountDetails(OWNER)
.payingWith(GENESIS)
.has(accountDetailsWith()
Expand All @@ -269,26 +270,38 @@ final Stream<DynamicTest> cryptoApproveAllowanceBaseUSDFee() {
.payingWith(OWNER)
.addCryptoAllowance(OWNER, SECOND_SPENDER, 200L)
.via("approveModifyCryptoTxn")
.fee(ONE_HBAR)
.blankMemo()
.logged(),
validateChargedUsdWithin("approveModifyCryptoTxn", 0.049375, 0.01),
.blankMemo(),
doWithStartupConfig("fees.simpleFeesEnabled", flag -> {
if ("true".equals(flag)) {
return validateChargedUsdWithin("approveModifyCryptoTxn", CRYPTO_APPROVE_ALLOWANCE_FEE, 0.01);
} else {
return validateChargedUsdWithin("approveModifyCryptoTxn", 0.049375, 0.01);
}
}),
cryptoApproveAllowance()
.payingWith(OWNER)
.addTokenAllowance(OWNER, FUNGIBLE_TOKEN, SECOND_SPENDER, 200L)
.via("approveModifyTokenTxn")
.fee(ONE_HBAR)
.blankMemo()
.logged(),
validateChargedUsdWithin("approveModifyTokenTxn", 0.04943, 0.01),
.blankMemo(),
doWithStartupConfig("fees.simpleFeesEnabled", flag -> {
if ("true".equals(flag)) {
return validateChargedUsdWithin("approveModifyTokenTxn", CRYPTO_APPROVE_ALLOWANCE_FEE, 0.01);
} else {
return validateChargedUsdWithin("approveModifyTokenTxn", 0.04943, 0.01);
}
}),
cryptoApproveAllowance()
.payingWith(OWNER)
.addNftAllowance(OWNER, NON_FUNGIBLE_TOKEN, ANOTHER_SPENDER, false, List.of())
.via("approveModifyNftTxn")
.fee(ONE_HBAR)
.blankMemo()
.logged(),
validateChargedUsdWithin("approveModifyNftTxn", 0.049375, 0.01),
.blankMemo(),
doWithStartupConfig("fees.simpleFeesEnabled", flag -> {
if ("true".equals(flag)) {
return validateChargedUsdWithin("approveModifyNftTxn", CRYPTO_APPROVE_ALLOWANCE_FEE, 0.01);
} else {
return validateChargedUsdWithin("approveModifyNftTxn", 0.049375, 0.01);
}
}),
getAccountDetails(OWNER)
.payingWith(GENESIS)
.has(accountDetailsWith()
Expand Down Expand Up @@ -380,11 +393,23 @@ final Stream<DynamicTest> cryptoUpdateBaseUSDFee() {
.maxAutomaticAssociations(-1)
.via(validNegativeTxn),
getAccountInfo(autoAssocTarget).hasMaxAutomaticAssociations(-1).logged(),
validateChargedUsd(baseTxn, BASE_FEE_WITH_EXPIRY_CRYPTO_UPDATE, allowedPercentDiff),
validateChargedUsd(plusOneTxn, BASE_FEE_CRYPTO_UPDATE, allowedPercentDiff),
validateChargedUsd(plusTenTxn, BASE_FEE_CRYPTO_UPDATE, allowedPercentDiff),
validateChargedUsd(plusFiveKTxn, BASE_FEE_CRYPTO_UPDATE, allowedPercentDiff),
validateChargedUsd(validNegativeTxn, BASE_FEE_CRYPTO_UPDATE, allowedPercentDiff));
doSeveralWithStartupConfig("fees.simpleFeesEnabled", flag -> {
if ("true".equals(flag)) {
return specOps(
validateChargedUsd(baseTxn, CRYPTO_UPDATE_FEE, allowedPercentDiff),
validateChargedUsd(plusOneTxn, CRYPTO_UPDATE_FEE, allowedPercentDiff),
validateChargedUsd(plusTenTxn, CRYPTO_UPDATE_FEE, allowedPercentDiff),
validateChargedUsd(plusFiveKTxn, CRYPTO_UPDATE_FEE, allowedPercentDiff),
validateChargedUsd(validNegativeTxn, CRYPTO_UPDATE_FEE, allowedPercentDiff));
} else {
return specOps(
validateChargedUsd(baseTxn, BASE_FEE_WITH_EXPIRY_CRYPTO_UPDATE, allowedPercentDiff),
validateChargedUsd(plusOneTxn, BASE_FEE_CRYPTO_UPDATE, allowedPercentDiff),
validateChargedUsd(plusTenTxn, BASE_FEE_CRYPTO_UPDATE, allowedPercentDiff),
validateChargedUsd(plusFiveKTxn, BASE_FEE_CRYPTO_UPDATE, allowedPercentDiff),
validateChargedUsd(validNegativeTxn, BASE_FEE_CRYPTO_UPDATE, allowedPercentDiff));
}
}));
}

@HapiTest
Expand Down Expand Up @@ -455,12 +480,10 @@ final Stream<DynamicTest> cryptoTransferBaseUSDFee() {
.via(nftXferTxn),
cryptoTransfer(moving(1, fungibleTokenWithCustomFee).between(nonTreasurySender, RECEIVER))
.blankMemo()
.fee(ONE_HBAR)
.payingWith(nonTreasurySender)
.via(htsXferTxnWithCustomFee),
cryptoTransfer(movingUnique(nonFungibleTokenWithCustomFee, 1).between(nonTreasurySender, RECEIVER))
.blankMemo()
.fee(ONE_HBAR)
.payingWith(nonTreasurySender)
.via(nftXferTxnWithCustomFee),
validateChargedUsdWithin(hbarXferTxn, BASE_FEE_HBAR_CRYPTO_TRANSFER, 1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class SimpleFeesScheduleConstantsInUsd {
public static final long CRYPTO_CREATE_INCLUDED_KEYS = 1L;
public static final long CRYPTO_CREATE_INCLUDED_HOOKS = 0L;

public static final double CRYPTO_UPDATE_FEE = 0.00022;
public static final double CRYPTO_UPDATE_BASE_FEE_USD = 0.00012;
public static final long CRYPTO_UPDATE_INCLUDED_KEYS = 1L;
public static final long CRYPTO_UPDATE_INCLUDED_HOOKS = 0L;
Expand Down
Loading