Skip to content

Commit

Permalink
Merge pull request #5238 from ghubstan/03-fix-settxfeerate-bug
Browse files Browse the repository at this point in the history
Adjust api to new minimum fee per vbyte
  • Loading branch information
sqrrm authored Feb 26, 2021
2 parents 8b70278 + e125ba8 commit b5793b5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion apitest/src/test/java/bisq/apitest/scenario/WalletTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
10 changes: 8 additions & 2 deletions core/src/main/java/bisq/core/api/CoreWalletsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/bisq/core/api/model/TxFeeRateInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
'}';
}
Expand Down

0 comments on commit b5793b5

Please sign in to comment.