-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
coordinator: add Web3jClientManager to improve test code reuse (#85)
coordinator: add Web3jClientManager to improve integration test code reuse and debugging
- Loading branch information
Showing
8 changed files
with
81 additions
and
26 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
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
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
58 changes: 58 additions & 0 deletions
58
...or/ethereum/test-utils/src/main/kotlin/net/consensys/zkevm/ethereum/Web3jClientManager.kt
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,58 @@ | ||
package net.consensys.zkevm.ethereum | ||
|
||
import net.consensys.linea.web3j.okHttpClientBuilder | ||
import org.apache.logging.log4j.Level | ||
import org.apache.logging.log4j.LogManager | ||
import org.apache.logging.log4j.Logger | ||
import org.web3j.protocol.Web3j | ||
import org.web3j.protocol.http.HttpService | ||
import org.web3j.utils.Async | ||
|
||
/** | ||
* Helper Object to create Web3j clients for L1 and L2 | ||
* that allow overriding default log values for testing and debugging easily | ||
*/ | ||
object Web3jClientManager { | ||
val l1RpcUrl: String = System.getProperty("L1_RPC", "http://localhost:8445") | ||
val l2RpcUrl: String = System.getProperty("L2_RPC", "http://localhost:8545") | ||
val l1Client: Web3j = buildL1Client() | ||
val l2Client: Web3j = buildL2Client() | ||
|
||
fun buildL1Client( | ||
rpcUrl: String = l1RpcUrl, | ||
log: Logger = LogManager.getLogger("test.clients.l1.web3j-default"), | ||
requestResponseLogLevel: Level = Level.TRACE, | ||
failuresLogLevel: Level = Level.DEBUG | ||
): Web3j { | ||
return buildWeb3Client(rpcUrl, log, requestResponseLogLevel, failuresLogLevel) | ||
} | ||
|
||
fun buildL2Client( | ||
rpcUrl: String = l2RpcUrl, | ||
log: Logger = LogManager.getLogger("test.clients.l2.web3j-default"), | ||
requestResponseLogLevel: Level = Level.TRACE, | ||
failuresLogLevel: Level = Level.DEBUG | ||
): Web3j { | ||
return buildWeb3Client(rpcUrl, log, requestResponseLogLevel, failuresLogLevel) | ||
} | ||
|
||
fun buildWeb3Client( | ||
rpcUrl: String, | ||
log: Logger = LogManager.getLogger("test.clients.web3j"), | ||
requestResponseLogLevel: Level = Level.TRACE, | ||
failuresLogLevel: Level = Level.DEBUG | ||
): Web3j { | ||
return Web3j.build( | ||
HttpService( | ||
rpcUrl, | ||
okHttpClientBuilder( | ||
logger = log, | ||
requestResponseLogLevel = requestResponseLogLevel, | ||
failuresLogLevel = failuresLogLevel | ||
).build() | ||
), | ||
500, | ||
Async.defaultExecutorService() | ||
) | ||
} | ||
} |
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