-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b4ae86
commit 1229157
Showing
8 changed files
with
152 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
consensus-client-it/src/test/scala/units/docker/BesuContainer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package units.docker | ||
|
||
import org.testcontainers.containers.BindMode | ||
import org.testcontainers.containers.Network.NetworkImpl | ||
import org.web3j.protocol.Web3j | ||
import org.web3j.protocol.http.HttpService | ||
import sttp.client3.{Identity, SttpBackend} | ||
import units.client.JsonRpcClient | ||
import units.client.engine.{EngineApiClient, HttpEngineApiClient, LoggedEngineApiClient} | ||
import units.docker.EcContainer.{EnginePort, RpcPort} | ||
import units.http.OkHttpLogger | ||
import units.test.TestEnvironment.ConfigsDir | ||
|
||
import scala.concurrent.duration.DurationInt | ||
|
||
class BesuContainer(network: NetworkImpl, number: Int, ip: String)(implicit httpClientBackend: SttpBackend[Identity, Any]) | ||
extends EcContainer(number) { | ||
protected override val container = new GenericContainer(DockerImages.BesuExecutionClient) | ||
.withNetwork(network) | ||
.withExposedPorts(RpcPort, EnginePort) | ||
.withEnv("LOG4J_CONFIGURATION_FILE", "/config/log4j2.xml") | ||
.withEnv("ROOT_LOG_FILE_LEVEL", "TRACE") | ||
.withFileSystemBind(s"$ConfigsDir/ec-common/genesis.json", "/genesis.json", BindMode.READ_ONLY) | ||
.withFileSystemBind(s"$ConfigsDir/besu", "/config", BindMode.READ_ONLY) | ||
.withFileSystemBind(s"$ConfigsDir/besu/run-besu.sh", "/tmp/run.sh", BindMode.READ_ONLY) | ||
.withFileSystemBind(s"$ConfigsDir/ec-common/p2p-key-$number.hex", "/etc/secrets/p2p-key", BindMode.READ_ONLY) | ||
.withFileSystemBind(s"$logFile", "/opt/besu/logs/besu.log", BindMode.READ_WRITE) | ||
.withCreateContainerCmdModifier { cmd => | ||
cmd | ||
.withName(s"${network.getName}-$hostName") | ||
.withHostName(hostName) | ||
.withIpv4Address(ip) | ||
.withEntrypoint("/tmp/run.sh") | ||
.withStopTimeout(5) | ||
} | ||
|
||
override lazy val engineApi: EngineApiClient = new LoggedEngineApiClient( | ||
new HttpEngineApiClient( | ||
JsonRpcClient.Config(apiUrl = s"http://${container.getHost}:$enginePort", apiRequestRetries = 5, apiRequestRetryWaitTime = 1.second), | ||
httpClientBackend | ||
) | ||
) | ||
|
||
override lazy val web3j = Web3j.build( | ||
new HttpService( | ||
s"http://${container.getHost}:$rpcPort", | ||
HttpService.getOkHttpClientBuilder | ||
.addInterceptor(OkHttpLogger) | ||
.build() | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
consensus-client-it/src/test/scala/units/docker/GethContainer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package units.docker | ||
|
||
import okhttp3.Interceptor | ||
import org.testcontainers.containers.BindMode | ||
import org.testcontainers.containers.Network.NetworkImpl | ||
import org.web3j.protocol.Web3j | ||
import org.web3j.protocol.http.HttpService | ||
import pdi.jwt.{JwtAlgorithm, JwtClaim, JwtJson} | ||
import sttp.client3.{Identity, SttpBackend} | ||
import units.client.JwtAuthenticationBackend | ||
import units.client.engine.{EngineApiClient, HttpEngineApiClient, LoggedEngineApiClient} | ||
import units.docker.EcContainer.{EnginePort, RpcPort} | ||
import units.http.OkHttpLogger | ||
import units.test.TestEnvironment.ConfigsDir | ||
|
||
import java.time.Clock | ||
import scala.io.Source | ||
|
||
class GethContainer(network: NetworkImpl, number: Int, ip: String)(implicit httpClientBackend: SttpBackend[Identity, Any]) | ||
extends EcContainer(number) { | ||
protected override val container = new GenericContainer(DockerImages.GethExecutionClient) | ||
.withNetwork(network) | ||
.withExposedPorts(RpcPort, EnginePort) | ||
.withFileSystemBind(s"$ConfigsDir/ec-common/genesis.json", "/tmp/genesis.json", BindMode.READ_ONLY) | ||
.withFileSystemBind(s"$ConfigsDir/geth/run-geth.sh", "/tmp/run.sh", BindMode.READ_ONLY) | ||
.withFileSystemBind(s"$ConfigsDir/ec-common/p2p-key-$number.hex", "/etc/secrets/p2p-key", BindMode.READ_ONLY) | ||
.withFileSystemBind(s"$ConfigsDir/ec-common/jwt-secret-$number.hex", "/etc/secrets/jwtsecret", BindMode.READ_ONLY) | ||
.withFileSystemBind(s"$logFile", "/root/logs/log", BindMode.READ_WRITE) | ||
.withCreateContainerCmdModifier { cmd => | ||
cmd | ||
.withName(s"${network.getName}-$hostName") | ||
.withHostName(hostName) | ||
.withIpv4Address(ip) | ||
.withEntrypoint("/tmp/run.sh") | ||
.withStopTimeout(5) | ||
} | ||
|
||
lazy val jwtSecretKey = { | ||
val src = Source.fromFile(s"$ConfigsDir/ec-common/jwt-secret-$number.hex") | ||
try src.getLines().next() | ||
finally src.close() | ||
} | ||
|
||
override lazy val engineApi: EngineApiClient = new LoggedEngineApiClient( | ||
new HttpEngineApiClient( | ||
engineApiConfig, | ||
new JwtAuthenticationBackend(jwtSecretKey, httpClientBackend) | ||
) | ||
) | ||
|
||
override lazy val web3j = Web3j.build( | ||
new HttpService( | ||
s"http://${container.getHost}:$rpcPort", | ||
HttpService.getOkHttpClientBuilder | ||
.addInterceptor { (chain: Interceptor.Chain) => | ||
val orig = chain.request() | ||
val jwtToken = JwtJson.encode(JwtClaim().issuedNow(Clock.systemUTC), jwtSecretKey, JwtAlgorithm.HS256) | ||
val request = orig | ||
.newBuilder() | ||
.header("Authorization", s"Bearer $jwtToken") | ||
.build() | ||
|
||
chain.proceed(request) | ||
} | ||
.addInterceptor(OkHttpLogger) | ||
.build() | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters