Skip to content

Commit

Permalink
Merge pull request #5244 from ghubstan/001-adjust-apitest-for-grpc-cl…
Browse files Browse the repository at this point in the history
…ient

Refactor apitest cases to use GrpcClient
  • Loading branch information
sqrrm authored Feb 26, 2021
2 parents acaa115 + 6c0eac8 commit 11a1167
Show file tree
Hide file tree
Showing 25 changed files with 470 additions and 978 deletions.
54 changes: 32 additions & 22 deletions apitest/src/test/java/bisq/apitest/ApiTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,27 @@

package bisq.apitest;

import java.net.InetAddress;

import java.io.IOException;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;

import javax.annotation.Nullable;

import org.junit.jupiter.api.TestInfo;

import static bisq.apitest.config.BisqAppConfig.alicedaemon;
import static bisq.apitest.config.BisqAppConfig.arbdaemon;
import static bisq.apitest.config.BisqAppConfig.bobdaemon;
import static java.net.InetAddress.getLoopbackAddress;
import static java.util.Arrays.stream;
import static java.util.concurrent.TimeUnit.MILLISECONDS;



import bisq.apitest.config.ApiTestConfig;
import bisq.apitest.config.BisqAppConfig;
import bisq.apitest.method.BitcoinCliHelper;
import bisq.cli.GrpcStubs;
import bisq.cli.GrpcClient;

/**
* Base class for all test types: 'method', 'scenario' and 'e2e'.
Expand All @@ -50,8 +51,8 @@
* <p>
* Those documents contain information about the configurations used by this test harness:
* bitcoin-core's bitcoin.conf and blocknotify values, bisq instance options, the DAO genesis
* transaction id, initial BSQ and BTC balances for Bob & Alice accounts, and default
* PerfectMoney dummy payment accounts (USD) for Bob and Alice.
* transaction id, initial BSQ and BTC balances for Bob & Alice accounts, and Bob and
* Alice's default payment accounts.
* <p>
* During a build, the
* <a href="https://github.com/bisq-network/bisq/blob/master/docs/dao-setup.zip">dao-setup.zip</a>
Expand All @@ -69,8 +70,12 @@ public class ApiTestCase {
protected static ApiTestConfig config;
protected static BitcoinCliHelper bitcoinCli;

// gRPC service stubs are used by method & scenario tests, but not e2e tests.
private static final Map<BisqAppConfig, GrpcStubs> grpcStubsCache = new HashMap<>();
@Nullable
protected static GrpcClient arbClient;
@Nullable
protected static GrpcClient aliceClient;
@Nullable
protected static GrpcClient bobClient;

public static void setUpScaffold(Enum<?>... supportingApps)
throws InterruptedException, ExecutionException, IOException {
Expand All @@ -79,6 +84,7 @@ public static void setUpScaffold(Enum<?>... supportingApps)
.setUp();
config = scaffold.config;
bitcoinCli = new BitcoinCliHelper((config));
createGrpcClients();
}

public static void setUpScaffold(String[] params)
Expand All @@ -90,24 +96,28 @@ public static void setUpScaffold(String[] params)
scaffold = new Scaffold(params).setUp();
config = scaffold.config;
bitcoinCli = new BitcoinCliHelper((config));
createGrpcClients();
}

public static void tearDownScaffold() {
scaffold.tearDown();
}

protected static String getEnumArrayAsString(Enum<?>[] supportingApps) {
return stream(supportingApps).map(Enum::name).collect(Collectors.joining(","));
}

protected static GrpcStubs grpcStubs(BisqAppConfig bisqAppConfig) {
if (grpcStubsCache.containsKey(bisqAppConfig)) {
return grpcStubsCache.get(bisqAppConfig);
} else {
GrpcStubs stubs = new GrpcStubs(InetAddress.getLoopbackAddress().getHostAddress(),
bisqAppConfig.apiPort, config.apiPassword);
grpcStubsCache.put(bisqAppConfig, stubs);
return stubs;
protected static void createGrpcClients() {
if (config.supportingApps.contains(alicedaemon.name())) {
aliceClient = new GrpcClient(getLoopbackAddress().getHostAddress(),
alicedaemon.apiPort,
config.apiPassword);
}
if (config.supportingApps.contains(bobdaemon.name())) {
bobClient = new GrpcClient(getLoopbackAddress().getHostAddress(),
bobdaemon.apiPort,
config.apiPassword);
}
if (config.supportingApps.contains(arbdaemon.name())) {
arbClient = new GrpcClient(getLoopbackAddress().getHostAddress(),
arbdaemon.apiPort,
config.apiPassword);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package bisq.apitest.method;

import bisq.proto.grpc.GetMethodHelpRequest;

import lombok.extern.slf4j.Slf4j;

import org.junit.jupiter.api.AfterAll;
Expand Down Expand Up @@ -51,10 +49,7 @@ public static void setUp() {
@Test
@Order(1)
public void testGetCreateOfferHelp() {
var help = grpcStubs(alicedaemon).helpService
.getMethodHelp(GetMethodHelpRequest.newBuilder()
.setMethodName(createoffer.name()).build())
.getMethodHelp();
var help = aliceClient.getMethodHelp(createoffer);
assertNotNull(help);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package bisq.apitest.method;

import bisq.proto.grpc.GetVersionRequest;

import lombok.extern.slf4j.Slf4j;

import org.junit.jupiter.api.AfterAll;
Expand Down Expand Up @@ -51,8 +49,7 @@ public static void setUp() {
@Test
@Order(1)
public void testGetVersion() {
var version = grpcStubs(alicedaemon).versionService
.getVersion(GetVersionRequest.newBuilder().build()).getVersion();
var version = aliceClient.getVersion();
assertEquals(VERSION, version);
}

Expand Down
Loading

0 comments on commit 11a1167

Please sign in to comment.