Skip to content

Commit

Permalink
Merge pull request #5081 from ghubstan/04-posix-cli-opts+method-help
Browse files Browse the repository at this point in the history
Use posix-style CLI opts, provide method help
  • Loading branch information
sqrrm authored Jan 16, 2021
2 parents f838b1a + 1ad7b35 commit 44cbea8
Show file tree
Hide file tree
Showing 47 changed files with 2,430 additions and 388 deletions.
26 changes: 13 additions & 13 deletions apitest/scripts/mainnet-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
run ./bisq-cli --bogus getversion
[ "$status" -eq 1 ]
echo "actual output: $output" >&2
[ "$output" = "Error: bogus is not a recognized option" ]
[ "$output" = "Error: missing required 'password' option" ]
}

@test "test missing required password option error" {
Expand Down Expand Up @@ -61,7 +61,7 @@
}

@test "test setwalletpassword \"a b c\"" {
run ./bisq-cli --password=xyz setwalletpassword "a b c"
run ./bisq-cli --password=xyz setwalletpassword --wallet-password="a b c"
[ "$status" -eq 0 ]
echo "actual output: $output" >&2
[ "$output" = "wallet encrypted" ]
Expand All @@ -76,15 +76,15 @@
}

@test "test unlockwallet without timeout arg" {
run ./bisq-cli --password=xyz unlockwallet "a b c"
run ./bisq-cli --password=xyz unlockwallet --wallet-password="a b c"
[ "$status" -eq 1 ]
echo "actual output: $output" >&2
[ "$output" = "Error: no unlock timeout specified" ]
}


@test "test unlockwallet \"a b c\" 8" {
run ./bisq-cli --password=xyz unlockwallet "a b c" 8
run ./bisq-cli --password=xyz unlockwallet --wallet-password="a b c" --timeout=8
[ "$status" -eq 0 ]
echo "actual output: $output" >&2
[ "$output" = "wallet unlocked" ]
Expand All @@ -97,7 +97,7 @@
}

@test "test unlockwallet \"a b c\" 6" {
run ./bisq-cli --password=xyz unlockwallet "a b c" 6
run ./bisq-cli --password=xyz unlockwallet --wallet-password="a b c" --timeout=6
[ "$status" -eq 0 ]
echo "actual output: $output" >&2
[ "$output" = "wallet unlocked" ]
Expand All @@ -111,14 +111,14 @@
}

@test "test setwalletpassword incorrect old pwd error" {
run ./bisq-cli --password=xyz setwalletpassword "z z z" "d e f"
run ./bisq-cli --password=xyz setwalletpassword --wallet-password="z z z" --new-wallet-password="d e f"
[ "$status" -eq 1 ]
echo "actual output: $output" >&2
[ "$output" = "Error: incorrect old password" ]
}

@test "test setwalletpassword oldpwd newpwd" {
run ./bisq-cli --password=xyz setwalletpassword "a b c" "d e f"
run ./bisq-cli --password=xyz setwalletpassword --wallet-password="a b c" --new-wallet-password="d e f"
[ "$status" -eq 0 ]
echo "actual output: $output" >&2
[ "$output" = "wallet encrypted with new password" ]
Expand All @@ -133,7 +133,7 @@
}

@test "test removewalletpassword" {
run ./bisq-cli --password=xyz removewalletpassword "d e f"
run ./bisq-cli --password=xyz removewalletpassword --wallet-password="d e f"
[ "$status" -eq 0 ]
echo "actual output: $output" >&2
[ "$output" = "wallet decrypted" ]
Expand Down Expand Up @@ -163,7 +163,7 @@
}

@test "test getaddressbalance bogus address argument" {
run ./bisq-cli --password=xyz getaddressbalance bogus
run ./bisq-cli --password=xyz getaddressbalance --address=bogus
[ "$status" -eq 1 ]
echo "actual output: $output" >&2
[ "$output" = "Error: address bogus not found in wallet" ]
Expand All @@ -183,21 +183,21 @@
run ./bisq-cli --password=xyz getoffers
[ "$status" -eq 1 ]
echo "actual output: $output" >&2
[ "$output" = "Error: incorrect parameter count, expecting direction (buy|sell), currency code" ]
[ "$output" = "Error: no direction (buy|sell) specified" ]
}

@test "test getoffers sell eur check return status" {
run ./bisq-cli --password=xyz getoffers sell eur
run ./bisq-cli --password=xyz getoffers --direction=sell --currency-code=eur
[ "$status" -eq 0 ]
}

@test "test getoffers buy eur check return status" {
run ./bisq-cli --password=xyz getoffers buy eur
run ./bisq-cli --password=xyz getoffers --direction=buy --currency-code=eur
[ "$status" -eq 0 ]
}

@test "test getoffers sell gbp check return status" {
run ./bisq-cli --password=xyz getoffers sell gbp
run ./bisq-cli --password=xyz getoffers --direction=sell --currency-code=gbp
[ "$status" -eq 0 ]
}

Expand Down
65 changes: 65 additions & 0 deletions apitest/src/test/java/bisq/apitest/method/GetMethodHelpTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.apitest.method;

import bisq.proto.grpc.GetMethodHelpRequest;

import lombok.extern.slf4j.Slf4j;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

import static bisq.apitest.config.BisqAppConfig.alicedaemon;
import static bisq.cli.Method.createoffer;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.MethodOrderer.OrderAnnotation;

@Disabled
@Slf4j
@TestMethodOrder(OrderAnnotation.class)
public class GetMethodHelpTest extends MethodTest {

@BeforeAll
public static void setUp() {
try {
setUpScaffold(alicedaemon);
} catch (Exception ex) {
fail(ex);
}
}

@Test
@Order(1)
public void testGetCreateOfferHelp() {
var help = grpcStubs(alicedaemon).helpService
.getMethodHelp(GetMethodHelpRequest.newBuilder()
.setMethodName(createoffer.name()).build())
.getMethodHelp();
assertNotNull(help);
}

@AfterAll
public static void tearDown() {
tearDownScaffold();
}
}
10 changes: 10 additions & 0 deletions apitest/src/test/java/bisq/apitest/method/MethodTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import bisq.proto.grpc.GetAddressBalanceRequest;
import bisq.proto.grpc.GetBalancesRequest;
import bisq.proto.grpc.GetFundingAddressesRequest;
import bisq.proto.grpc.GetMethodHelpRequest;
import bisq.proto.grpc.GetMyOfferRequest;
import bisq.proto.grpc.GetOfferRequest;
import bisq.proto.grpc.GetPaymentAccountFormRequest;
Expand Down Expand Up @@ -271,6 +272,10 @@ protected final WithdrawFundsRequest createWithdrawFundsRequest(String tradeId,
.build();
}

protected final GetMethodHelpRequest createGetMethodHelpRequest(String methodName) {
return GetMethodHelpRequest.newBuilder().setMethodName(methodName).build();
}

// Convenience methods for calling frequently used & thoroughly tested gRPC services.
protected final BalancesInfo getBalances(BisqAppConfig bisqAppConfig, String currencyCode) {
return grpcStubs(bisqAppConfig).walletsService.getBalances(
Expand Down Expand Up @@ -490,6 +495,11 @@ public bisq.core.payment.PaymentAccount createDummyF2FAccount(BisqAppConfig bisq
return f2FAccount;
}

protected final String getMethodHelp(BisqAppConfig bisqAppConfig, String methodName) {
var req = createGetMethodHelpRequest(methodName);
return grpcStubs(bisqAppConfig).helpService.getMethodHelp(req).getMethodHelp();
}

// Static conveniences for test methods and test case fixture setups.

protected static RegisterDisputeAgentRequest createRegisterDisputeAgentRequest(String disputeAgentType) {
Expand Down
8 changes: 8 additions & 0 deletions apitest/src/test/java/bisq/apitest/scenario/StartupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@


import bisq.apitest.method.CallRateMeteringInterceptorTest;
import bisq.apitest.method.GetMethodHelpTest;
import bisq.apitest.method.GetVersionTest;
import bisq.apitest.method.MethodTest;
import bisq.apitest.method.RegisterDisputeAgentsTest;
Expand Down Expand Up @@ -92,6 +93,13 @@ public void testRegisterDisputeAgents() {
test.testRegisterRefundAgent();
}

@Test
@Order(4)
public void testGetCreateOfferHelp() {
GetMethodHelpTest test = new GetMethodHelpTest();
test.testGetCreateOfferHelp();
}

@AfterAll
public static void tearDown() {
tearDownScaffold();
Expand Down
Loading

0 comments on commit 44cbea8

Please sign in to comment.