Repository navigation
test: run integration suite against released live node #405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Cryptoloveer
wants to merge
4
commits into
attocash:main
Choose a base branch
from
Cryptoloveer:test/live-node-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
978a8ec
test: run integration suite against released live node
Cryptoloveer 8c3ac81
Merge branch 'main' into test/live-node-integration
Cryptoloveer 53d0737
fix: reference hyphenated CI matrix key safely
Cryptoloveer 07ea043
Merge branch 'main' into test/live-node-integration
Cryptoloveer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -9,10 +9,14 @@ import cash.atto.node.network.NetworkProperties | |
| import cash.atto.node.transaction.Transaction | ||
| import io.cucumber.java.en.Given | ||
| import io.r2dbc.spi.Option | ||
| import org.springframework.beans.factory.annotation.Value | ||
| import org.springframework.boot.builder.SpringApplicationBuilder | ||
| import org.springframework.boot.r2dbc.autoconfigure.R2dbcConnectionDetails | ||
| import org.springframework.core.io.DefaultResourceLoader | ||
| import org.springframework.r2dbc.core.DatabaseClient | ||
| import org.testcontainers.containers.GenericContainer | ||
| import org.testcontainers.images.PullPolicy | ||
| import org.testcontainers.utility.DockerImageName | ||
| import java.io.Closeable | ||
| import java.io.File | ||
| import java.net.ServerSocket | ||
|
|
@@ -24,81 +28,99 @@ class NodeStepDefinition( | |
| private val transaction: Transaction, | ||
| private val connectionDetails: R2dbcConnectionDetails, | ||
| private val databaseClient: DatabaseClient, | ||
| @Value("\${atto.test.neighbour-mode:classpath}") private val neighbourMode: String, | ||
| ) { | ||
| @Given("^the neighbour node (\\w+)$") | ||
| fun startNeighbour(shortId: String) { | ||
| val nodeName = "Node $shortId" | ||
| val classLoader = createClassLoader() | ||
| val starter = | ||
| Runnable { | ||
| Thread.currentThread().contextClassLoader = classLoader | ||
| val ports = randomPorts() | ||
| val websocketPort = ports[0] | ||
| val httpPort = ports[1] | ||
|
|
||
| val ports = randomPorts() | ||
| val websocketPort = ports[0] | ||
| val httpPort = ports[1] | ||
| val sql = "DROP DATABASE IF EXISTS $shortId; CREATE DATABASE $shortId" | ||
| databaseClient | ||
| .sql(sql) | ||
| .fetch() | ||
| .rowsUpdated() | ||
| .block() | ||
|
|
||
| val sql = "DROP DATABASE IF EXISTS $shortId; CREATE DATABASE $shortId" | ||
| databaseClient | ||
| .sql(sql) | ||
| .fetch() | ||
| .rowsUpdated() | ||
| .block() | ||
| val options = connectionDetails.connectionFactoryOptions | ||
| val driver = options.getRequiredValue(Option.valueOf<String>("driver")) as String | ||
| val host = options.getRequiredValue(Option.valueOf<String>("host")) as String | ||
| val port = options.getRequiredValue(Option.valueOf<Int>("port")) as Int | ||
| val user = options.getRequiredValue(Option.valueOf<String>("user")) as String | ||
| val password = options.getRequiredValue(Option.valueOf<String>("password")) as String | ||
| val privateKey = AttoPrivateKey.generate() | ||
|
|
||
| val options = connectionDetails.connectionFactoryOptions | ||
| val driver = options.getRequiredValue(Option.valueOf<String>("driver")) as String | ||
| val host = options.getRequiredValue(Option.valueOf<String>("host")) as String | ||
| val port = options.getRequiredValue(Option.valueOf<Int>("port")) as Int | ||
| val user = options.getRequiredValue(Option.valueOf<String>("user")) as String | ||
| val password = options.getRequiredValue(Option.valueOf<String>("password")) as String | ||
| val args = | ||
| arrayOf( | ||
| "--spring.application.name=neighbour-atto-node-$shortId", | ||
| "--server.port=$httpPort", | ||
| "--NODE_NAME=$nodeName", | ||
| "--management.server.port=", | ||
| "--atto.test.mysql-container.enabled=false", | ||
| "--spring.r2dbc.url=r2dbc:$driver://$host:$port/$shortId", | ||
| "--spring.r2dbc.username=$user", | ||
| "--spring.r2dbc.password=$password", | ||
| "--spring.flyway.url=jdbc:$driver://$host:$port/$shortId", | ||
| "--spring.flyway.user=$user", | ||
| "--spring.flyway.password=$password", | ||
| "--atto.node.public-uri=ws://localhost:$websocketPort", | ||
| "--websocket.port=$websocketPort", | ||
| "--atto.signer.key=${privateKey.value.toHex()}", | ||
| "--atto.transaction.genesis=${transaction.toAttoTransaction().toBuffer().toHex()}", | ||
| ) | ||
|
|
||
| val privateKey = AttoPrivateKey.generate() | ||
| when (neighbourMode) { | ||
| CLASSPATH_MODE -> startClasspathNode(nodeName, args) | ||
| LIVE_MODE -> startLiveNode(args) | ||
| else -> error("Unsupported neighbour mode: $neighbourMode") | ||
| } | ||
|
|
||
| val args = | ||
| arrayOf( | ||
| "--spring.application.name=neighbour-atto-node-$shortId", | ||
| "--server.port=$httpPort", | ||
| "--NODE_NAME=$nodeName", | ||
| "--management.server.port=", | ||
| "--atto.test.mysql-container.enabled=false", | ||
| "--spring.r2dbc.url=r2dbc:$driver://$host:$port/$shortId", | ||
| "--spring.r2dbc.username=$user", | ||
| "--spring.r2dbc.password=$password", | ||
| "--spring.flyway.url=jdbc:$driver://$host:$port/$shortId", | ||
| "--spring.flyway.user=$user", | ||
| "--spring.flyway.password=$password", | ||
| "--atto.node.public-uri=ws://localhost:$websocketPort", | ||
| "--websocket.port=$websocketPort", | ||
| "--atto.signer.key=${privateKey.value.toHex()}", | ||
| "--atto.transaction.genesis=${transaction.toAttoTransaction().toBuffer().toHex()}", | ||
| ) | ||
| PropertyHolder.add(shortId, privateKey.toSignerBlocking()) | ||
| PropertyHolder.add(shortId, privateKey.toPublicKeyBlocking()) | ||
| PropertyHolder.add(shortId, AttoAlgorithm.V1) | ||
| PropertyHolder.add(shortId, Neighbour(websocketPort, httpPort)) | ||
| } | ||
|
|
||
| @Given("is a default node") | ||
| fun setAsDefaultNode() { | ||
| val neighbour = PropertyHolder[Neighbour::class.java] | ||
| networkProperties.defaultNodes.add("ws://localhost:${neighbour.websocketPort}") | ||
| } | ||
|
|
||
| private fun startClasspathNode( | ||
| nodeName: String, | ||
| args: Array<String>, | ||
| ) { | ||
| val classLoader = createClassLoader() | ||
| val starter = | ||
| Runnable { | ||
| Thread.currentThread().contextClassLoader = classLoader | ||
| val context = | ||
| SpringApplicationBuilder(Application::class.java) | ||
| .resourceLoader(DefaultResourceLoader(classLoader)) | ||
| .run(*args) as Closeable | ||
|
|
||
| NodeHolder.add(context, classLoader) | ||
|
|
||
| PropertyHolder.add(shortId, context) | ||
| PropertyHolder.add(shortId, privateKey.toSignerBlocking()) | ||
| PropertyHolder.add(shortId, privateKey.toPublicKeyBlocking()) | ||
| PropertyHolder.add(shortId, AttoAlgorithm.V1) | ||
| PropertyHolder.add(shortId, Neighbour(websocketPort, httpPort)) | ||
| } | ||
|
|
||
| val futureTask = FutureTask(starter, null) | ||
| val neighbourThread = Thread(futureTask) | ||
|
|
||
| neighbourThread.contextClassLoader = classLoader | ||
| neighbourThread.name = nodeName | ||
| neighbourThread.start() | ||
|
|
||
| futureTask.get() | ||
| } | ||
|
|
||
| @Given("is a default node") | ||
| fun setAsDefaultNode() { | ||
| val neighbour = PropertyHolder[Neighbour::class.java] | ||
| networkProperties.defaultNodes.add("ws://localhost:${neighbour.websocketPort}") | ||
| private fun startLiveNode(args: Array<String>) { | ||
|
Comment on lines
115
to
+116
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Loopback should be allowed, the node blocks loopback with the default configs. |
||
| val container = GenericContainer<Nothing>(DockerImageName.parse(LIVE_NODE_IMAGE)) | ||
| container.withImagePullPolicy(PullPolicy.alwaysPull()) | ||
| container.withNetworkMode("host") | ||
| container.withEnv("SPRING_PROFILES_ACTIVE", "default,json") | ||
| container.withCommand(*args) | ||
| container.start() | ||
| NodeHolder.add(Closeable { container.stop() }, null) | ||
| } | ||
|
|
||
| private fun randomPorts(count: Int = 2): List<UShort> { | ||
|
|
@@ -121,4 +143,10 @@ class NodeStepDefinition( | |
| val urlArray = Array(urlList.size) { urlList[it] } | ||
| return URLClassLoader(urlArray, ClassLoader.getSystemClassLoader()) | ||
| } | ||
|
|
||
| private companion object { | ||
| const val CLASSPATH_MODE = "classpath" | ||
| const val LIVE_MODE = "live" | ||
| const val LIVE_NODE_IMAGE = "ghcr.io/attocash/node:live" | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This need to be forward to the test. The current implementation as-is always use classpath