Skip to content

Commit

Permalink
Condition updates.
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Terry <mark.terry@consensys.net>
  • Loading branch information
mark-terry committed Feb 15, 2021
1 parent 4f17898 commit bc2dcac
Showing 1 changed file with 23 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
package org.hyperledger.besu.tests.container;

import java.io.IOException;
import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.util.concurrent.TimeUnit;

import org.assertj.core.api.Assertions;
import io.reactivex.subscribers.TestSubscriber;
import org.awaitility.Awaitility;
import org.awaitility.core.ThrowingRunnable;
import org.junit.After;
Expand All @@ -30,15 +28,17 @@
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.startupcheck.MinimumDurationRunningStartupCheckStrategy;
import org.testcontainers.utility.MountableFile;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.methods.response.EthBlockNumber;
import org.web3j.protocol.core.methods.response.Web3ClientVersion;
import org.web3j.protocol.http.HttpService;

@SuppressWarnings({"rawtypes", "unchecked"})
public class ContainerTestBase {
private final String besuVersion = "20.10.3";
private final String goQuorumVersion = "21.1";
private final String goQuorumVersion = "21.1.0";
private final String tesseraVersion = "21.1.0";

private final Network containerNetwork = Network.SHARED;
private Web3j besuWeb3j;
Expand Down Expand Up @@ -136,12 +136,12 @@ private GenericContainer buildBesuContainer() {
"--rpc-http-port",
besuRpcPort.toString(),
"--rpc-http-api",
"ADMIN,WEB3");
"ADMIN,ETH,WEB3");
}

private GenericContainer buildTesseraContainer(
final String ipcPath, final String ipcBindDir, final String containerIpcPath) {
return new GenericContainer("quorumengineering/tessera")
return new GenericContainer("quorumengineering/tessera:" + tesseraVersion)
.withNetwork(containerNetwork)
.withClasspathResourceMapping(
hostTesseraResources, containerTesseraResources, BindMode.READ_ONLY)
Expand All @@ -151,9 +151,7 @@ private GenericContainer buildTesseraContainer(
"-o serverConfigs[1].serverAddress=unix:" + containerIpcPath,
"-o keys.keyData[0].privateKeyPath=" + tesseraContainerPrivKeyPath,
"-o keys.keyData[0].publicKeyPath=" + tesseraContainerPubKeyPath)
.withExposedPorts(tesseraRestPort)
.withStartupCheckStrategy(
new MinimumDurationRunningStartupCheckStrategy(Duration.ofSeconds(15)));
.withExposedPorts(tesseraRestPort);
}

private GenericContainer buildGoQuorumContainer(
Expand Down Expand Up @@ -185,36 +183,31 @@ private GenericContainer buildGoQuorumContainer(
"3",
"--nousb",
"--nodekey",
goQuorumContainerDatadir + "/nodeKey")
.withStartupCheckStrategy(
new MinimumDurationRunningStartupCheckStrategy(Duration.ofSeconds(10)));
goQuorumContainerDatadir + "/nodeKey");
}

private Web3j buildWeb3J(final String containerIpAddress, final Integer mappedPort) {
return Web3j.build(new HttpService("http://" + containerIpAddress + ":" + mappedPort));
}

private void assertClientVersion(final Web3j web3, final String clientString) {
web3.web3ClientVersion()
.flowable()
.subscribe(
web3ClientVersion ->
Assertions.assertThat(web3ClientVersion.getWeb3ClientVersion())
.contains(clientString))
.dispose();
final TestSubscriber<Web3ClientVersion> testSubscriber = new TestSubscriber<>();
web3.web3ClientVersion().flowable().subscribe(testSubscriber);
testSubscriber.assertNoErrors();
testSubscriber.assertValue(
web3ClientVersion -> web3ClientVersion.getWeb3ClientVersion().contains(clientString));

testSubscriber.dispose();
}

private void assertBlockHeight(final Web3j web3j, final int blockHeight) {
web3j
.ethBlockNumber()
.flowable()
.subscribe(
ethBlockNumber -> {
Assertions.assertThat(ethBlockNumber.getBlockNumber())
.isGreaterThanOrEqualTo(BigInteger.valueOf(blockHeight));
},
throwable -> {})
.dispose();
final TestSubscriber<EthBlockNumber> testSubscriber = new TestSubscriber<>();
web3j.ethBlockNumber().flowable().subscribe(testSubscriber);
testSubscriber.assertNoErrors();
testSubscriber.assertValue(
ethBlockNumber -> ethBlockNumber.getBlockNumber().intValueExact() >= blockHeight);

testSubscriber.dispose();
}

public static void waitFor(final int timeout, final ThrowingRunnable condition) {
Expand Down

0 comments on commit bc2dcac

Please sign in to comment.