diff --git a/apitest/src/test/java/bisq/apitest/method/wallet/BtcTxFeeRateTest.java b/apitest/src/test/java/bisq/apitest/method/wallet/BtcTxFeeRateTest.java index 07b56eb7916..d5a4e4ef340 100644 --- a/apitest/src/test/java/bisq/apitest/method/wallet/BtcTxFeeRateTest.java +++ b/apitest/src/test/java/bisq/apitest/method/wallet/BtcTxFeeRateTest.java @@ -2,6 +2,8 @@ import bisq.core.api.model.TxFeeRateInfo; +import io.grpc.StatusRuntimeException; + import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.AfterAll; @@ -15,8 +17,11 @@ import static bisq.apitest.Scaffold.BitcoinCoreApp.bitcoind; import static bisq.apitest.config.BisqAppConfig.alicedaemon; import static bisq.apitest.config.BisqAppConfig.seednode; +import static bisq.common.config.BaseCurrencyNetwork.BTC_DAO_REGTEST; +import static java.lang.String.format; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.MethodOrderer.OrderAnnotation; @@ -50,17 +55,28 @@ public void testGetTxFeeRate(final TestInfo testInfo) { @Test @Order(2) - public void testSetTxFeeRate(final TestInfo testInfo) { - TxFeeRateInfo txFeeRateInfo = setTxFeeRate(alicedaemon, 10); + public void testSetInvalidTxFeeRateShouldThrowException(final TestInfo testInfo) { + Throwable exception = assertThrows(StatusRuntimeException.class, () -> + setTxFeeRate(alicedaemon, 10)); + String expectedExceptionMessage = + format("UNKNOWN: tx fee rate preference must be >= %d sats/byte", + BTC_DAO_REGTEST.getDefaultMinFeePerVbyte()); + assertEquals(expectedExceptionMessage, exception.getMessage()); + } + + @Test + @Order(3) + public void testSetValidTxFeeRate(final TestInfo testInfo) { + TxFeeRateInfo txFeeRateInfo = setTxFeeRate(alicedaemon, 15); log.debug("{} -> Fee rates with custom preference: {}", testName(testInfo), txFeeRateInfo); assertTrue(txFeeRateInfo.isUseCustomTxFeeRate()); - assertEquals(10, txFeeRateInfo.getCustomTxFeeRate()); + assertEquals(15, txFeeRateInfo.getCustomTxFeeRate()); assertTrue(txFeeRateInfo.getFeeServiceRate() > 0); } @Test - @Order(3) + @Order(4) public void testUnsetTxFeeRate(final TestInfo testInfo) { TxFeeRateInfo txFeeRateInfo = unsetTxFeeRate(alicedaemon); log.debug("{} -> Fee rate with no preference: {}", testName(testInfo), txFeeRateInfo); diff --git a/apitest/src/test/java/bisq/apitest/scenario/WalletTest.java b/apitest/src/test/java/bisq/apitest/scenario/WalletTest.java index 0fff4bf694d..a3ebba4ca2f 100644 --- a/apitest/src/test/java/bisq/apitest/scenario/WalletTest.java +++ b/apitest/src/test/java/bisq/apitest/scenario/WalletTest.java @@ -104,7 +104,8 @@ public void testTxFeeRateMethods(final TestInfo testInfo) { BtcTxFeeRateTest test = new BtcTxFeeRateTest(); test.testGetTxFeeRate(testInfo); - test.testSetTxFeeRate(testInfo); + test.testSetInvalidTxFeeRateShouldThrowException(testInfo); + test.testSetValidTxFeeRate(testInfo); test.testUnsetTxFeeRate(testInfo); } diff --git a/core/src/main/java/bisq/core/api/CoreWalletsService.java b/core/src/main/java/bisq/core/api/CoreWalletsService.java index 0ef5a22d2fd..b048fcefe97 100644 --- a/core/src/main/java/bisq/core/api/CoreWalletsService.java +++ b/core/src/main/java/bisq/core/api/CoreWalletsService.java @@ -79,6 +79,7 @@ import javax.annotation.Nullable; +import static bisq.common.config.BaseCurrencyNetwork.BTC_DAO_REGTEST; import static bisq.core.btc.wallet.Restrictions.getMinNonDustOutput; import static bisq.core.util.ParsingUtils.parseToCoin; import static java.lang.String.format; @@ -311,8 +312,13 @@ public void onFailure(Throwable t) { void setTxFeeRatePreference(long txFeeRate, ResultHandler resultHandler) { - if (txFeeRate <= 0) - throw new IllegalStateException("cannot create transactions without fees"); + long minFeePerVbyte = BTC_DAO_REGTEST.getDefaultMinFeePerVbyte(); + // TODO Replace line above with line below, after commit + // c33ac1b9834fb9f7f14e553d09776f94efc9d13d is merged. + // long minFeePerVbyte = feeService.getMinFeePerVByte(); + if (txFeeRate < minFeePerVbyte) + throw new IllegalStateException( + format("tx fee rate preference must be >= %d sats/byte", minFeePerVbyte)); preferences.setUseCustomWithdrawalTxFee(true); Coin satsPerByte = Coin.valueOf(txFeeRate); diff --git a/core/src/main/java/bisq/core/api/model/TxFeeRateInfo.java b/core/src/main/java/bisq/core/api/model/TxFeeRateInfo.java index d6014ddce30..330eb163584 100644 --- a/core/src/main/java/bisq/core/api/model/TxFeeRateInfo.java +++ b/core/src/main/java/bisq/core/api/model/TxFeeRateInfo.java @@ -67,8 +67,8 @@ public static TxFeeRateInfo fromProto(bisq.proto.grpc.TxFeeRateInfo proto) { public String toString() { return "TxFeeRateInfo{" + "\n" + " useCustomTxFeeRate=" + useCustomTxFeeRate + "\n" + - ", customTxFeeRate=" + customTxFeeRate + "sats/byte" + "\n" + - ", feeServiceRate=" + feeServiceRate + "sats/byte" + "\n" + + ", customTxFeeRate=" + customTxFeeRate + " sats/byte" + "\n" + + ", feeServiceRate=" + feeServiceRate + " sats/byte" + "\n" + ", lastFeeServiceRequestTs=" + lastFeeServiceRequestTs + "\n" + '}'; }