From 23b9e1d9c2234a114360ca37b88bb218689f3238 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Sun, 11 Sep 2022 12:28:38 -0300 Subject: [PATCH] Show CLI err msgs if invalid takeoffer params are used for taking bsq swap --- .../opts/TakeBsqSwapOfferOptionParser.java | 18 +++++++ .../java/bisq/cli/opts/OptionParsersTest.java | 51 ++++++++++++++++++- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/cli/src/main/java/bisq/cli/opts/TakeBsqSwapOfferOptionParser.java b/cli/src/main/java/bisq/cli/opts/TakeBsqSwapOfferOptionParser.java index e3301b88b33..be9df70eccd 100644 --- a/cli/src/main/java/bisq/cli/opts/TakeBsqSwapOfferOptionParser.java +++ b/cli/src/main/java/bisq/cli/opts/TakeBsqSwapOfferOptionParser.java @@ -31,6 +31,14 @@ public class TakeBsqSwapOfferOptionParser extends OfferIdOptionParser implements .withRequiredArg() .defaultsTo("0"); + final OptionSpec paymentAccountIdOpt = parser.accepts(OPT_PAYMENT_ACCOUNT_ID, "not used when taking bsq swaps") + .withRequiredArg() + .defaultsTo("invalid param"); + + final OptionSpec takerFeeCurrencyCodeOpt = parser.accepts(OPT_FEE_CURRENCY, "not used when taking bsq swaps") + .withOptionalArg() + .defaultsTo("invalid param"); + public TakeBsqSwapOfferOptionParser(String[] args) { super(args, true); } @@ -40,6 +48,16 @@ public TakeBsqSwapOfferOptionParser parse() { // Super class will short-circuit parsing if help option is present. + if (options.has(paymentAccountIdOpt)) { + throw new IllegalArgumentException("the " + OPT_PAYMENT_ACCOUNT_ID + + " param is not used for swaps; the internal default swap account is always used"); + } + + if (options.has(takerFeeCurrencyCodeOpt)) { + throw new IllegalArgumentException("the " + OPT_FEE_CURRENCY + + " param is not used for swaps; fees are always paid in bsq"); + } + if (options.has(amountOpt)) { if (options.valueOf(amountOpt).isEmpty()) throw new IllegalArgumentException("no intended btc trade amount specified"); diff --git a/cli/src/test/java/bisq/cli/opts/OptionParsersTest.java b/cli/src/test/java/bisq/cli/opts/OptionParsersTest.java index 04c479889d3..a026f2df738 100644 --- a/cli/src/test/java/bisq/cli/opts/OptionParsersTest.java +++ b/cli/src/test/java/bisq/cli/opts/OptionParsersTest.java @@ -3,7 +3,6 @@ import org.junit.jupiter.api.Test; import static bisq.cli.Method.*; -import static bisq.cli.Method.takeoffer; import static bisq.cli.opts.OptLabel.*; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -444,4 +443,54 @@ public void testTakeOffer() { assertEquals(takerFeeCurrencyCode, parser.getTakerFeeCurrencyCode()); assertEquals(amount, parser.getAmount()); } + + @Test + public void testTakeBsqSwapOfferWithInvalidFeeCurrencyParam() { + var offerId = "ABC-OFFER-ID"; + var takerFeeCurrencyCode = "BSQ"; + var amount = "0.05"; + String[] args = new String[]{ + PASSWORD_OPT, + takeoffer.name(), + "--" + OPT_OFFER_ID + "=" + offerId, + "--" + OPT_FEE_CURRENCY + "=" + takerFeeCurrencyCode, + "--" + OPT_AMOUNT + "=" + amount + }; + Throwable exception = assertThrows(RuntimeException.class, () -> + new TakeBsqSwapOfferOptionParser(args).parse()); + assertEquals("the fee-currency param is not used for swaps; fees are always paid in bsq", exception.getMessage()); + } + + @Test + public void testTakeBsqSwapOfferWithInvalidPaymentAccountIdParam() { + var offerId = "ABC-OFFER-ID"; + var paymentAccountId = "ABC-ACCT-ID"; + var amount = "0.05"; + String[] args = new String[]{ + PASSWORD_OPT, + takeoffer.name(), + "--" + OPT_OFFER_ID + "=" + offerId, + "--" + OPT_PAYMENT_ACCOUNT_ID + "=" + paymentAccountId, + "--" + OPT_AMOUNT + "=" + amount + }; + Throwable exception = assertThrows(RuntimeException.class, () -> + new TakeBsqSwapOfferOptionParser(args).parse()); + assertEquals("the payment-account-id param is not used for swaps; the internal default swap account is always used", + exception.getMessage()); + } + + @Test + public void testTakeBsqSwapOffer() { + var offerId = "ABC-OFFER-ID"; + var amount = "0.05"; + String[] args = new String[]{ + PASSWORD_OPT, + takeoffer.name(), + "--" + OPT_OFFER_ID + "=" + offerId, + "--" + OPT_AMOUNT + "=" + amount + }; + var parser = new TakeBsqSwapOfferOptionParser(args).parse(); + assertEquals(offerId, parser.getOfferId()); + assertEquals(amount, parser.getAmount()); + } }