Tighten createoffer param validation (only bsq swaps supported)

This commit is contained in:
ghubstan 2021-11-25 17:31:54 -03:00
parent 35aeb61338
commit eff10842b9
No known key found for this signature in database
GPG Key ID: E35592D6800A861E
2 changed files with 21 additions and 1 deletions

View File

@ -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");

View File

@ -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[]{