mirror of
https://github.com/bisq-network/bisq.git
synced 2025-01-18 13:25:14 +01:00
Show CLI err msgs if invalid takeoffer params are used for taking bsq swap
This commit is contained in:
parent
d32fd4e97b
commit
23b9e1d9c2
@ -31,6 +31,14 @@ public class TakeBsqSwapOfferOptionParser extends OfferIdOptionParser implements
|
||||
.withRequiredArg()
|
||||
.defaultsTo("0");
|
||||
|
||||
final OptionSpec<String> paymentAccountIdOpt = parser.accepts(OPT_PAYMENT_ACCOUNT_ID, "not used when taking bsq swaps")
|
||||
.withRequiredArg()
|
||||
.defaultsTo("invalid param");
|
||||
|
||||
final OptionSpec<String> 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 class TakeBsqSwapOfferOptionParser extends OfferIdOptionParser implements
|
||||
|
||||
// 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");
|
||||
|
@ -3,7 +3,6 @@ package bisq.cli.opts;
|
||||
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 class OptionParsersTest {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user