Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix required opt validation bugs in CLI #5274

Closed
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d60c0dd
Display buyer's cost in api's gettrade output
ghubstan Feb 26, 2021
e2bb64d
Merge branch 'master' into 01-show-cost-in-trade-output
ghubstan Feb 27, 2021
e5291e9
Use the logger of the gRPC service throwing an exception
ghubstan Feb 27, 2021
e5a0a39
Permit some gRPC excptions to be logged only as warning
ghubstan Feb 27, 2021
320e63c
Log 'trade not found' a warning instead of full stack trace
ghubstan Feb 27, 2021
98ff6cf
Fix test bug
ghubstan Feb 27, 2021
e8d1f03
Clean up call rate meter config file in test teardown
ghubstan Feb 27, 2021
f90d2ce
Fix test bug
ghubstan Feb 27, 2021
6b2c386
Fix call rate metering interceptor bug
ghubstan Feb 28, 2021
675ce98
Make test call rate = default call rate
ghubstan Feb 28, 2021
7249509
No need to wait, default+test call rate > 2x / second
ghubstan Feb 28, 2021
3feacf4
Remove unused import
ghubstan Feb 28, 2021
3bbefff
Adjust mainnet bats test to default rate meter interceptors
ghubstan Feb 28, 2021
b618776
Wait 3 secs after removing password (for wallet save)
ghubstan Feb 28, 2021
19aed84
Fix getunusedbsqaddress test
ghubstan Feb 28, 2021
3f84246
Improve interceptor's rate metering key definition and lookup
ghubstan Feb 28, 2021
392c0f5
Fix CLI number opt validation, improve server-not-up msg
ghubstan Mar 1, 2021
2473ff6
Fix tx-fee-rate formatting (and math) bug in cli/CurrencyFormat
ghubstan Mar 2, 2021
8590c67
Remove warning supression
ghubstan Mar 2, 2021
e0bf773
Add link to api-beta-test-guide.md
ghubstan Mar 3, 2021
a2000bd
Explain how to manually register test dispute agents
ghubstan Mar 3, 2021
cfaa539
Fix opt validation bugs in CLI
ghubstan Mar 4, 2021
62ff79d
Update cli getoffers smoke test to posix style opts
ghubstan Mar 5, 2021
d01a7b7
Improve required-argument opt validation
ghubstan Mar 5, 2021
304781c
Add jupiter test support to :cli subproject
ghubstan Mar 5, 2021
9c12b31
Add new cli option parser test
ghubstan Mar 5, 2021
a13ef79
Handle require-arg options missing the = sign
ghubstan Mar 5, 2021
70da6d1
Parse args in opts test, no exception = pass
ghubstan Mar 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions cli/src/test/java/bisq/cli/opt/OptionParsersTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package bisq.cli.opt;

import org.junit.jupiter.api.Test;

import static bisq.cli.Method.canceloffer;
import static bisq.cli.Method.createoffer;
import static bisq.cli.Method.createpaymentacct;
import static bisq.cli.opts.OptLabel.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;



import bisq.cli.opts.CancelOfferOptionParser;
import bisq.cli.opts.CreateOfferOptionParser;
import bisq.cli.opts.CreatePaymentAcctOptionParser;


public class OptionParsersTest {

private static final String PASSWORD_OPT = "--" + OPT_PASSWORD + "=" + "xyz";

// CancelOffer opt parsing tests

@Test
public void testCancelOfferWithMissingOfferIdOptShouldThrowException() {
String[] args = new String[]{
PASSWORD_OPT,
canceloffer.name()
};
Throwable exception = assertThrows(RuntimeException.class, () ->
new CancelOfferOptionParser(args).parse());
assertEquals("no offer id specified", exception.getMessage());
}

@Test
public void testCancelOfferWithEmptyOfferIdOptShouldThrowException() {
String[] args = new String[]{
PASSWORD_OPT,
canceloffer.name(),
"--" + OPT_OFFER_ID + "=" // missing opt value
};
Throwable exception = assertThrows(RuntimeException.class, () ->
new CancelOfferOptionParser(args).parse());
assertEquals("no offer id specified", exception.getMessage());
}

@Test
public void testCancelOfferWithMissingOfferIdValueShouldThrowException() {
String[] args = new String[]{
PASSWORD_OPT,
canceloffer.name(),
"--" + OPT_OFFER_ID // missing equals sign & opt value
};
Throwable exception = assertThrows(RuntimeException.class, () ->
new CancelOfferOptionParser(args).parse());
assertEquals("Option offer-id requires an argument", exception.getMessage());
}

@Test
public void testValidCancelOfferOpts() {
String[] args = new String[]{
PASSWORD_OPT,
canceloffer.name(),
"--" + OPT_OFFER_ID + "=" + "ABC-OFFER-ID"
};
new CancelOfferOptionParser(args).parse();
}

// CreateOffer opt parsing tests

@Test
public void testCreateOfferOptParserWithMissingPaymentAccountIdOptShouldThrowException() {
String[] args = new String[]{
PASSWORD_OPT,
createoffer.name()
};
Throwable exception = assertThrows(RuntimeException.class, () ->
new CreateOfferOptionParser(args).parse());
assertEquals("no payment account id specified", exception.getMessage());
}

@Test
public void testCreateOfferOptParserWithMissingDirectionOptShouldThrowException() {
String[] args = new String[]{
PASSWORD_OPT,
createoffer.name(),
"--" + OPT_PAYMENT_ACCOUNT + "=" + "abc-payment-acct-id-123"
};
Throwable exception = assertThrows(RuntimeException.class, () ->
new CreateOfferOptionParser(args).parse());
assertEquals("no direction (buy|sell) specified", exception.getMessage());
}

@Test
public void testCreateOfferOptParserWithMissingDirectionOptValueShouldThrowException() {
String[] args = new String[]{
PASSWORD_OPT,
createoffer.name(),
"--" + OPT_PAYMENT_ACCOUNT + "=" + "abc-payment-acct-id-123",
"--" + OPT_DIRECTION + "=" + ""
};
Throwable exception = assertThrows(RuntimeException.class, () ->
new CreateOfferOptionParser(args).parse());
assertEquals("no direction (buy|sell) specified", exception.getMessage());
}

@Test
public void testValidCreateOfferOpts() {
String[] args = new String[]{
PASSWORD_OPT,
createoffer.name(),
"--" + OPT_PAYMENT_ACCOUNT + "=" + "abc-payment-acct-id-123",
"--" + OPT_DIRECTION + "=" + "BUY",
"--" + OPT_CURRENCY_CODE + "=" + "EUR",
"--" + OPT_AMOUNT + "=" + "0.125",
"--" + OPT_MKT_PRICE_MARGIN + "=" + "0.0",
"--" + OPT_SECURITY_DEPOSIT + "=" + "25.0"
};
ghubstan marked this conversation as resolved.
Show resolved Hide resolved
}

// CreatePaymentAcct opt parser tests

@Test
public void testCreatePaymentAcctOptParserWithMissingPaymentFormOptShouldThrowException() {
String[] args = new String[]{
PASSWORD_OPT,
createpaymentacct.name()
// OPT_PAYMENT_ACCOUNT_FORM
};
Throwable exception = assertThrows(RuntimeException.class, () ->
new CreatePaymentAcctOptionParser(args).parse());
assertEquals("no path to json payment account form specified", exception.getMessage());
}

@Test
public void testCreatePaymentAcctOptParserWithMissingPaymentFormOptValueShouldThrowException() {
String[] args = new String[]{
PASSWORD_OPT,
createpaymentacct.name(),
"--" + OPT_PAYMENT_ACCOUNT_FORM + "="
};
Throwable exception = assertThrows(RuntimeException.class, () ->
new CreatePaymentAcctOptionParser(args).parse());
assertEquals("no path to json payment account form specified", exception.getMessage());
}

@Test
public void testCreatePaymentAcctOptParserWithInvalidPaymentFormOptValueShouldThrowException() {
String[] args = new String[]{
PASSWORD_OPT,
createpaymentacct.name(),
"--" + OPT_PAYMENT_ACCOUNT_FORM + "=" + "/tmp/milkyway/solarsystem/mars"
};
Throwable exception = assertThrows(RuntimeException.class, () ->
new CreatePaymentAcctOptionParser(args).parse());
assertEquals("json payment account form '/tmp/milkyway/solarsystem/mars' could not be found",
exception.getMessage());
}
}