From eff10842b936adb4c9ad70a5e5cffe0053e1fb59 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Thu, 25 Nov 2021 17:31:54 -0300 Subject: [PATCH] Tighten createoffer param validation (only bsq swaps supported) --- .../bisq/cli/opts/CreateOfferOptionParser.java | 5 ++++- .../java/bisq/cli/opts/OptionParsersTest.java | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cli/src/main/java/bisq/cli/opts/CreateOfferOptionParser.java b/cli/src/main/java/bisq/cli/opts/CreateOfferOptionParser.java index ba3a6b36cd..f75ee37db5 100644 --- a/cli/src/main/java/bisq/cli/opts/CreateOfferOptionParser.java +++ b/cli/src/main/java/bisq/cli/opts/CreateOfferOptionParser.java @@ -86,6 +86,9 @@ public class CreateOfferOptionParser extends AbstractMethodOptionParser implemen throw new IllegalArgumentException("no btc amount specified"); if (getIsSwap()) { + if (!options.valueOf(currencyCodeOpt).equalsIgnoreCase("bsq")) + throw new IllegalArgumentException("only bsq swaps are currently supported"); + if (options.has(paymentAccountIdOpt)) throw new IllegalArgumentException("cannot use a payment account id in bsq swap offer"); @@ -97,7 +100,7 @@ public class CreateOfferOptionParser extends AbstractMethodOptionParser implemen if (!options.has(fixedPriceOpt) || options.valueOf(fixedPriceOpt).isEmpty()) throw new IllegalArgumentException("no fixed price specified"); - + } else { if (!options.has(paymentAccountIdOpt) || options.valueOf(paymentAccountIdOpt).isEmpty()) throw new IllegalArgumentException("no payment account id specified"); diff --git a/cli/src/test/java/bisq/cli/opts/OptionParsersTest.java b/cli/src/test/java/bisq/cli/opts/OptionParsersTest.java index 0e58159b20..ba527a88e5 100644 --- a/cli/src/test/java/bisq/cli/opts/OptionParsersTest.java +++ b/cli/src/test/java/bisq/cli/opts/OptionParsersTest.java @@ -204,6 +204,23 @@ public class OptionParsersTest { assertEquals("no fixed price specified", exception.getMessage()); } + @Test + public void testCreateBsqSwapOfferWithIncorrectCurrencyCodeOptShouldThrowException() { + String[] args = new String[]{ + PASSWORD_OPT, + createoffer.name(), + "--" + OPT_SWAP + "=" + "true", + "--" + OPT_DIRECTION + "=" + "sell", + "--" + OPT_CURRENCY_CODE + "=" + "xmr", + "--" + OPT_MIN_AMOUNT + "=" + "0.075", + "--" + OPT_AMOUNT + "=" + "0.125", + "--" + OPT_FIXED_PRICE + "=" + "0.00005555" + }; + Throwable exception = assertThrows(RuntimeException.class, () -> + new CreateOfferOptionParser(args).parse()); + assertEquals("only bsq swaps are currently supported", exception.getMessage()); + } + @Test public void testValidCreateBsqSwapOfferOpts() { String[] args = new String[]{