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
Show file tree
Hide file tree
Changes from 4 commits
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions build.gradle
Expand Up @@ -378,6 +378,17 @@ configure(project(':cli')) {
implementation "ch.qos.logback:logback-classic:$logbackVersion"
compileOnly "org.projectlombok:lombok:$lombokVersion"
annotationProcessor "org.projectlombok:lombok:$lombokVersion"

testImplementation "org.junit.jupiter:junit-jupiter-api:$jupiterVersion"
testImplementation "org.junit.jupiter:junit-jupiter-params:$jupiterVersion"
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$jupiterVersion")
testAnnotationProcessor "org.projectlombok:lombok:$lombokVersion"
testCompileOnly "org.projectlombok:lombok:$lombokVersion"
testRuntime "javax.annotation:javax.annotation-api:$javaxAnnotationVersion"
}

test {
useJUnitPlatform()
}
}

Expand Down
Expand Up @@ -38,7 +38,7 @@ public CancelOfferOptionParser parse() {
if (options.has(helpOpt))
return this;

if (!options.has(offerIdOpt))
if (!options.has(offerIdOpt) || options.valueOf(offerIdOpt).isEmpty())
throw new IllegalArgumentException("no offer id specified");

return this;
Expand Down
16 changes: 11 additions & 5 deletions cli/src/main/java/bisq/cli/opts/CreateOfferOptionParser.java
Expand Up @@ -70,22 +70,28 @@ public CreateOfferOptionParser parse() {
if (options.has(helpOpt))
return this;

if (!options.has(paymentAccountIdOpt))
if (!options.has(paymentAccountIdOpt) || options.valueOf(paymentAccountIdOpt).isEmpty())
throw new IllegalArgumentException("no payment account id specified");

if (!options.has(directionOpt))
if (!options.has(directionOpt) || options.valueOf(directionOpt).isEmpty())
throw new IllegalArgumentException("no direction (buy|sell) specified");

if (!options.has(currencyCodeOpt))
if (!options.has(currencyCodeOpt) || options.valueOf(currencyCodeOpt).isEmpty())
throw new IllegalArgumentException("no currency code specified");

if (!options.has(amountOpt))
if (!options.has(amountOpt) || options.valueOf(amountOpt).isEmpty())
throw new IllegalArgumentException("no btc amount specified");

if (!options.has(mktPriceMarginOpt) && !options.has(fixedPriceOpt))
throw new IllegalArgumentException("no market price margin or fixed price specified");

if (!options.has(securityDepositOpt))
if (options.has(mktPriceMarginOpt) && options.valueOf(mktPriceMarginOpt).isEmpty())
throw new IllegalArgumentException("no market price margin specified");

if (options.has(fixedPriceOpt) && options.valueOf(fixedPriceOpt).isEmpty())
throw new IllegalArgumentException("no fixed price specified");

if (!options.has(securityDepositOpt) || options.valueOf(securityDepositOpt).isEmpty())
throw new IllegalArgumentException("no security deposit specified");

return this;
Expand Down
Expand Up @@ -43,7 +43,7 @@ public CreatePaymentAcctOptionParser parse() {
if (options.has(helpOpt))
return this;

if (!options.has(paymentAcctFormPathOpt))
if (!options.has(paymentAcctFormPathOpt) || options.valueOf(paymentAcctFormPathOpt).isEmpty())
throw new IllegalArgumentException("no path to json payment account form specified");

Path path = Paths.get(options.valueOf(paymentAcctFormPathOpt));
Expand Down
Expand Up @@ -38,7 +38,7 @@ public GetAddressBalanceOptionParser parse() {
if (options.has(helpOpt))
return this;

if (!options.has(addressOpt))
if (!options.has(addressOpt) || options.valueOf(addressOpt).isEmpty())
throw new IllegalArgumentException("no address specified");

return this;
Expand Down
Expand Up @@ -38,7 +38,7 @@ public GetBTCMarketPriceOptionParser parse() {
if (options.has(helpOpt))
return this;

if (!options.has(currencyCodeOpt))
if (!options.has(currencyCodeOpt) || options.valueOf(currencyCodeOpt).isEmpty())
throw new IllegalArgumentException("no currency code specified");

return this;
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main/java/bisq/cli/opts/GetOfferOptionParser.java
Expand Up @@ -38,7 +38,7 @@ public GetOfferOptionParser parse() {
if (options.has(helpOpt))
return this;

if (!options.has(offerIdOpt))
if (!options.has(offerIdOpt) || options.valueOf(offerIdOpt).isEmpty())
throw new IllegalArgumentException("no offer id specified");

return this;
Expand Down
4 changes: 2 additions & 2 deletions cli/src/main/java/bisq/cli/opts/GetOffersOptionParser.java
Expand Up @@ -42,10 +42,10 @@ public GetOffersOptionParser parse() {
if (options.has(helpOpt))
return this;

if (!options.has(directionOpt))
if (!options.has(directionOpt) || options.valueOf(directionOpt).isEmpty())
throw new IllegalArgumentException("no direction (buy|sell) specified");

if (!options.has(currencyCodeOpt))
if (!options.has(currencyCodeOpt) || options.valueOf(currencyCodeOpt).isEmpty())
throw new IllegalArgumentException("no currency code specified");

return this;
Expand Down
Expand Up @@ -39,7 +39,7 @@ public GetPaymentAcctFormOptionParser parse() {
if (options.has(helpOpt))
return this;

if (!options.has(paymentMethodIdOpt))
if (!options.has(paymentMethodIdOpt) || options.valueOf(paymentMethodIdOpt).isEmpty())
throw new IllegalArgumentException("no payment method id specified");

return this;
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main/java/bisq/cli/opts/GetTradeOptionParser.java
Expand Up @@ -44,7 +44,7 @@ public GetTradeOptionParser parse() {
if (options.has(helpOpt))
return this;

if (!options.has(tradeIdOpt))
if (!options.has(tradeIdOpt) || options.valueOf(tradeIdOpt).isEmpty())
throw new IllegalArgumentException("no trade id specified");

return this;
Expand Down
Expand Up @@ -38,7 +38,7 @@ public GetTransactionOptionParser parse() {
if (options.has(helpOpt))
return this;

if (!options.has(txIdOpt))
if (!options.has(txIdOpt) || options.valueOf(txIdOpt).isEmpty())
throw new IllegalArgumentException("no tx id specified");

return this;
Expand Down
Expand Up @@ -42,10 +42,10 @@ public RegisterDisputeAgentOptionParser parse() {
if (options.has(helpOpt))
return this;

if (!options.has(disputeAgentTypeOpt))
if (!options.has(disputeAgentTypeOpt) || options.valueOf(disputeAgentTypeOpt).isEmpty())
throw new IllegalArgumentException("no dispute agent type specified");

if (!options.has(registrationKeyOpt))
if (!options.has(registrationKeyOpt) || options.valueOf(registrationKeyOpt).isEmpty())
throw new IllegalArgumentException("no registration key specified");

return this;
Expand Down
Expand Up @@ -38,7 +38,7 @@ public RemoveWalletPasswordOptionParser parse() {
if (options.has(helpOpt))
return this;

if (!options.has(passwordOpt))
if (!options.has(passwordOpt) || options.valueOf(passwordOpt).isEmpty())
throw new IllegalArgumentException("no password specified");

return this;
Expand Down
4 changes: 2 additions & 2 deletions cli/src/main/java/bisq/cli/opts/SendBsqOptionParser.java
Expand Up @@ -48,10 +48,10 @@ public SendBsqOptionParser parse() {
if (options.has(helpOpt))
return this;

if (!options.has(addressOpt))
if (!options.has(addressOpt) || options.valueOf(addressOpt).isEmpty())
throw new IllegalArgumentException("no bsq address specified");

if (!options.has(amountOpt))
if (!options.has(amountOpt) || options.valueOf(amountOpt).isEmpty())
throw new IllegalArgumentException("no bsq amount specified");

return this;
Expand Down
4 changes: 2 additions & 2 deletions cli/src/main/java/bisq/cli/opts/SendBtcOptionParser.java
Expand Up @@ -53,10 +53,10 @@ public SendBtcOptionParser parse() {
if (options.has(helpOpt))
return this;

if (!options.has(addressOpt))
if (!options.has(addressOpt) || options.valueOf(addressOpt).isEmpty())
throw new IllegalArgumentException("no btc address specified");

if (!options.has(amountOpt))
if (!options.has(amountOpt) || options.valueOf(amountOpt).isEmpty())
throw new IllegalArgumentException("no btc amount specified");

return this;
Expand Down
Expand Up @@ -39,7 +39,7 @@ public SetTxFeeRateOptionParser parse() {
if (options.has(helpOpt))
return this;

if (!options.has(feeRateOpt))
if (!options.has(feeRateOpt) || options.valueOf(feeRateOpt).isEmpty())
throw new IllegalArgumentException("no tx fee rate specified");

return this;
Expand Down
Expand Up @@ -44,7 +44,7 @@ public SetWalletPasswordOptionParser parse() {
if (options.has(helpOpt))
return this;

if (!options.has(passwordOpt))
if (!options.has(passwordOpt) || options.valueOf(passwordOpt).isEmpty())
throw new IllegalArgumentException("no password specified");

return this;
Expand Down
4 changes: 2 additions & 2 deletions cli/src/main/java/bisq/cli/opts/TakeOfferOptionParser.java
Expand Up @@ -47,10 +47,10 @@ public TakeOfferOptionParser parse() {
if (options.has(helpOpt))
return this;

if (!options.has(offerIdOpt))
if (!options.has(offerIdOpt) || options.valueOf(offerIdOpt).isEmpty())
throw new IllegalArgumentException("no offer id specified");

if (!options.has(paymentAccountIdOpt))
if (!options.has(paymentAccountIdOpt) || options.valueOf(paymentAccountIdOpt).isEmpty())
throw new IllegalArgumentException("no payment account id specified");

return this;
Expand Down
Expand Up @@ -44,7 +44,7 @@ public UnlockWalletOptionParser parse() {
if (options.has(helpOpt))
return this;

if (!options.has(passwordOpt))
if (!options.has(passwordOpt) || options.valueOf(passwordOpt).isEmpty())
throw new IllegalArgumentException("no password specified");

if (!options.has(unlockTimeoutOpt) || options.valueOf(unlockTimeoutOpt) <= 0)
Expand Down
Expand Up @@ -48,10 +48,10 @@ public WithdrawFundsOptionParser parse() {
if (options.has(helpOpt))
return this;

if (!options.has(tradeIdOpt))
if (!options.has(tradeIdOpt) || options.valueOf(tradeIdOpt).isEmpty())
throw new IllegalArgumentException("no trade id specified");

if (!options.has(addressOpt))
if (!options.has(addressOpt) || options.valueOf(addressOpt).isEmpty())
throw new IllegalArgumentException("no destination address specified");

return this;
Expand Down
16 changes: 8 additions & 8 deletions cli/src/test/java/bisq/cli/GetOffersSmokeTest.java
Expand Up @@ -16,24 +16,24 @@ public class GetOffersSmokeTest {
public static void main(String[] args) {

out.println(">>> getoffers buy usd");
CliMain.main(new String[]{"--password=xyz", "getoffers", "buy", "usd"});
CliMain.main(new String[]{"--password=xyz", "getoffers", "--direction=buy", "--currency-code=usd"});
out.println(">>> getoffers sell usd");
CliMain.main(new String[]{"--password=xyz", "getoffers", "sell", "usd"});
CliMain.main(new String[]{"--password=xyz", "getoffers", "--direction=sell", "--currency-code=usd"});

out.println(">>> getoffers buy eur");
CliMain.main(new String[]{"--password=xyz", "getoffers", "buy", "eur"});
CliMain.main(new String[]{"--password=xyz", "getoffers", "--direction=buy", "--currency-code=eur"});
out.println(">>> getoffers sell eur");
CliMain.main(new String[]{"--password=xyz", "getoffers", "sell", "eur"});
CliMain.main(new String[]{"--password=xyz", "getoffers", "--direction=sell", "--currency-code=eur"});

out.println(">>> getoffers buy gbp");
CliMain.main(new String[]{"--password=xyz", "getoffers", "buy", "gbp"});
CliMain.main(new String[]{"--password=xyz", "getoffers", "--direction=buy", "--currency-code=gbp"});
out.println(">>> getoffers sell gbp");
CliMain.main(new String[]{"--password=xyz", "getoffers", "sell", "gbp"});
CliMain.main(new String[]{"--password=xyz", "getoffers", "--direction=sell", "--currency-code=gbp"});

out.println(">>> getoffers buy brl");
CliMain.main(new String[]{"--password=xyz", "getoffers", "buy", "brl"});
CliMain.main(new String[]{"--password=xyz", "getoffers", "--direction=buy", "--currency-code=brl"});
out.println(">>> getoffers sell brl");
CliMain.main(new String[]{"--password=xyz", "getoffers", "sell", "brl"});
CliMain.main(new String[]{"--password=xyz", "getoffers", "--direction=sell", "--currency-code=brl"});
}

}