From 58c4c32440d7b876b476723fad7a99677cfcbcc8 Mon Sep 17 00:00:00 2001 From: Jamie Li Date: Thu, 16 Nov 2023 15:29:53 -0800 Subject: [PATCH] [ANCHOR-535] Clean up test profiles (#1199) ### Description 1. Test profiles are stacked on top of the `default` profile. This is to simplify and avoid env variables duplications in different profiles to increase the code readability. 2. Simplify the test profiles. 3. Add `exitStatus` to the `waitForTxnStatus` function to shorten the test failure time. ### Context CI improvement. --- ...d2End with RPC Test - no fullstack.run.xml | 38 ------------- ...End with RPC Test - with fullstack.run.xml | 38 ------------- .../platform/e2etest/Sep24End2EndTests.kt | 21 ++++---- .../platform/e2etest/Sep6End2EndTest.kt | 2 +- .../integrationtest/CallbackApiTests.kt | 2 +- .../integrationtest/EventProcessingTests.kt | 3 +- .../integrationtest/PlatformApiTests.kt | 2 +- .../platform/integrationtest/Sep10Tests.kt | 2 +- .../platform/integrationtest/Sep12Tests.kt | 2 +- .../platform/integrationtest/Sep24Tests.kt | 2 +- .../platform/integrationtest/Sep31Tests.kt | 2 +- .../platform/integrationtest/Sep38Tests.kt | 2 +- .../platform/integrationtest/Sep6Tests.kt | 2 +- .../integrationtest/ServerHealthTests.kt | 2 +- .../integrationtest/StellarObserverTests.kt | 2 +- .../anchor/platform/DatabaseMigrationTests.kt | 2 +- .../PlatformApiKeyAuthIntegrationTest.kt | 2 +- .../PlatformJwtAuthIntegrationTest.kt | 2 +- .../org/stellar/anchor/platform/TestConfig.kt | 54 ++++++++++++++----- .../anchor/platform/TestProfileRunner.kt | 2 +- .../platform/run_profiles/RunAllServers.kt | 2 +- .../run_profiles/RunAllServersWithDocker.kt | 2 +- .../run_profiles/RunDockerDevStack.kt | 2 +- .../run_profiles/RunEventProcessingServer.kt | 2 +- .../run_profiles/RunKotlinReferenceServer.kt | 2 +- .../run_profiles/RunPlatformServer.kt | 2 +- .../run_profiles/RunSEP24NoFrontend.kt | 2 +- .../platform/run_profiles/RunSepServer.kt | 3 +- .../run_profiles/RunStellarObserver.kt | 3 +- .../platform/run_profiles/RunWalletServer.kt | 2 +- .../profiles/default-custody/config.env | 53 ++---------------- .../profiles/default-custody/test.env | 16 +----- .../resources/profiles/default-rpc/config.env | 51 ------------------ .../resources/profiles/default-rpc/test.env | 14 ----- .../config.env | 0 .../test.env | 0 36 files changed, 81 insertions(+), 259 deletions(-) delete mode 100644 .run/Test - Fireblocks End2End with RPC Test - no fullstack.run.xml delete mode 100644 .run/Test - Fireblocks End2End with RPC Test - with fullstack.run.xml rename service-runner/src/main/resources/profiles/{default-custody-rpc => unused-default-custody-rpc}/config.env (100%) rename service-runner/src/main/resources/profiles/{default-custody-rpc => unused-default-custody-rpc}/test.env (100%) diff --git a/.run/Test - Fireblocks End2End with RPC Test - no fullstack.run.xml b/.run/Test - Fireblocks End2End with RPC Test - no fullstack.run.xml deleted file mode 100644 index b37321614d..0000000000 --- a/.run/Test - Fireblocks End2End with RPC Test - no fullstack.run.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.run/Test - Fireblocks End2End with RPC Test - with fullstack.run.xml b/.run/Test - Fireblocks End2End with RPC Test - with fullstack.run.xml deleted file mode 100644 index d54abfe16d..0000000000 --- a/.run/Test - Fireblocks End2End with RPC Test - with fullstack.run.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/e2etest/Sep24End2EndTests.kt b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/e2etest/Sep24End2EndTests.kt index 45dd7d73f5..594882135f 100644 --- a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/e2etest/Sep24End2EndTests.kt +++ b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/e2etest/Sep24End2EndTests.kt @@ -51,7 +51,7 @@ const val DEPOSIT_FUND_CLIENT_SECRET_2 = "SCW2SJEPTL4K7FFPFOFABFEFZJCG6LHULWVJX6 @TestInstance(PER_CLASS) @Execution(CONCURRENT) -class Sep24End2EndTests : AbstractIntegrationTests(TestConfig(testProfileName = "default")) { +class Sep24End2EndTests : AbstractIntegrationTests(TestConfig()) { private val client = HttpClient { install(HttpTimeout) { requestTimeoutMillis = 300000 @@ -95,7 +95,7 @@ class Sep24End2EndTests : AbstractIntegrationTests(TestConfig(testProfileName = assertEquals(amount, (interactiveJwt.claims["data"] as Map<*, *>)["amount"], amount) // Wait for the status to change to COMPLETED - waitForTxnStatus(response.id, COMPLETED, token) + waitForTxnStatus(response.id, COMPLETED, ERROR, token) // Check if the transaction can be listed by stellar transaction id val fetchedTxn = anchor.interactive().getTransaction(response.id, token) as DepositTransaction @@ -202,7 +202,7 @@ class Sep24End2EndTests : AbstractIntegrationTests(TestConfig(testProfileName = info("accessing ${withdrawTxn.url}...") assertEquals(200, resp.status.value) // Wait for the status to change to PENDING_USER_TRANSFER_START - waitForTxnStatus(withdrawTxn.id, PENDING_USER_TRANSFER_START, token) + waitForTxnStatus(withdrawTxn.id, PENDING_USER_TRANSFER_START, ERROR, token) // Submit transfer transaction val walletTxn = (anchor.interactive().getTransaction(withdrawTxn.id, token) as WithdrawalTransaction) @@ -218,7 +218,7 @@ class Sep24End2EndTests : AbstractIntegrationTests(TestConfig(testProfileName = wallet.stellar().submitTransaction(transfer) } // Wait for the status to change to PENDING_USER_TRANSFER_END - waitForTxnStatus(withdrawTxn.id, COMPLETED, token) + waitForTxnStatus(withdrawTxn.id, COMPLETED, ERROR, token) // Check if the transaction can be listed by stellar transaction id val fetchTxn = @@ -278,6 +278,7 @@ class Sep24End2EndTests : AbstractIntegrationTests(TestConfig(testProfileName = private suspend fun waitForTxnStatus( id: String, expectedStatus: TransactionStatus, + exitStatus: TransactionStatus, token: AuthToken ) { var status: TransactionStatus? = null @@ -285,20 +286,18 @@ class Sep24End2EndTests : AbstractIntegrationTests(TestConfig(testProfileName = for (i in 0..maxTries) { // Get transaction info val transaction = anchor.interactive().getTransaction(id, token) - if (status != transaction.status) { status = transaction.status - info( "Transaction(id=${transaction.id}) status changed to $status. Message: ${transaction.message}" ) } - delay(1.seconds) + if (transaction.status == expectedStatus) return - if (transaction.status == expectedStatus) { - return - } + if (transaction.status == exitStatus) break + + delay(1.seconds) } fail("Transaction wasn't $expectedStatus in $maxTries tries, last status: $status") @@ -334,7 +333,7 @@ class Sep24End2EndTests : AbstractIntegrationTests(TestConfig(testProfileName = val deposits = (0..1).map { val txnId = makeDeposit(asset, amount, token).id - waitForTxnStatus(txnId, COMPLETED, token) + waitForTxnStatus(txnId, COMPLETED, ERROR, token) txnId } val history = anchor.interactive().getTransactionsForAsset(asset, token) diff --git a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/e2etest/Sep6End2EndTest.kt b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/e2etest/Sep6End2EndTest.kt index 61239efa18..a151395a85 100644 --- a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/e2etest/Sep6End2EndTest.kt +++ b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/e2etest/Sep6End2EndTest.kt @@ -29,7 +29,7 @@ import org.stellar.walletsdk.horizon.sign @TestInstance(TestInstance.Lifecycle.PER_CLASS) @Execution(ExecutionMode.CONCURRENT) -class Sep6End2EndTest : AbstractIntegrationTests(TestConfig(testProfileName = "default")) { +class Sep6End2EndTest : AbstractIntegrationTests(TestConfig()) { private val maxTries = 30 private val anchorReferenceServerClient = AnchorReferenceServerClient(Url(config.env["reference.server.url"]!!)) diff --git a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/CallbackApiTests.kt b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/CallbackApiTests.kt index 1e37ed2fcd..d0a177dbbd 100644 --- a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/CallbackApiTests.kt +++ b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/CallbackApiTests.kt @@ -33,7 +33,7 @@ import org.stellar.anchor.util.GsonUtils @TestInstance(TestInstance.Lifecycle.PER_CLASS) @Execution(ExecutionMode.SAME_THREAD) @TestMethodOrder(MethodOrderer.OrderAnnotation::class) -class CallbackApiTests : AbstractIntegrationTests(TestConfig(testProfileName = "default")) { +class CallbackApiTests : AbstractIntegrationTests(TestConfig()) { companion object { private const val JWT_EXPIRATION_MILLISECONDS: Long = 10000 diff --git a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/EventProcessingTests.kt b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/EventProcessingTests.kt index 89ffac5bd4..ce27eb9ae8 100644 --- a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/EventProcessingTests.kt +++ b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/EventProcessingTests.kt @@ -9,8 +9,7 @@ import org.stellar.anchor.platform.config.PropertyEventConfig import org.stellar.anchor.platform.event.DefaultEventService import org.stellar.anchor.util.GsonUtils -class EventProcessingServerTests : - AbstractIntegrationTests(TestConfig(testProfileName = "default")) { +class EventProcessingServerTests : AbstractIntegrationTests(TestConfig()) { companion object { val eventConfig = GsonUtils.getInstance().fromJson(eventConfigJson, PropertyEventConfig::class.java)!! diff --git a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/PlatformApiTests.kt b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/PlatformApiTests.kt index be7dfc7cc4..9f5b3fdfba 100644 --- a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/PlatformApiTests.kt +++ b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/PlatformApiTests.kt @@ -26,7 +26,7 @@ import org.stellar.anchor.platform.AbstractIntegrationTests import org.stellar.anchor.platform.TestConfig import org.stellar.anchor.util.GsonUtils -class PlatformApiTests : AbstractIntegrationTests(TestConfig(testProfileName = "default")) { +class PlatformApiTests : AbstractIntegrationTests(TestConfig()) { private val gson = GsonUtils.getInstance() private val platformApiClient = diff --git a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep10Tests.kt b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep10Tests.kt index ac05b3bc56..c5f5e8dae5 100644 --- a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep10Tests.kt +++ b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep10Tests.kt @@ -7,7 +7,7 @@ import org.stellar.anchor.api.sep.sep10.ValidationRequest import org.stellar.anchor.client.Sep10Client import org.stellar.anchor.platform.* -class Sep10Tests : AbstractIntegrationTests(TestConfig(testProfileName = "default")) { +class Sep10Tests : AbstractIntegrationTests(TestConfig()) { lateinit var sep10Client: Sep10Client lateinit var sep10ClientMultiSig: Sep10Client diff --git a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep12Tests.kt b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep12Tests.kt index 9e42014129..dd3f7ff0b9 100644 --- a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep12Tests.kt +++ b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep12Tests.kt @@ -15,7 +15,7 @@ import org.stellar.sdk.KeyPair import org.stellar.walletsdk.anchor.auth import org.stellar.walletsdk.horizon.SigningKeyPair -open class Sep12Tests : AbstractIntegrationTests(TestConfig(testProfileName = "default")) { +open class Sep12Tests : AbstractIntegrationTests(TestConfig()) { init { runBlocking { // We have to override the default CLIENT_WALLET_SECRET because the deletion of the customer diff --git a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep24Tests.kt b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep24Tests.kt index b58c477b97..754a3a23d4 100644 --- a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep24Tests.kt +++ b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep24Tests.kt @@ -36,7 +36,7 @@ import org.stellar.walletsdk.asset.IssuedAssetId @TestInstance(TestInstance.Lifecycle.PER_CLASS) @Execution(SAME_THREAD) @TestMethodOrder(OrderAnnotation::class) -class Sep24Tests : AbstractIntegrationTests(TestConfig(testProfileName = "default")) { +class Sep24Tests : AbstractIntegrationTests(TestConfig()) { private val jwtService: JwtService = JwtService( config.env["secret.sep10.jwt_secret"]!!, diff --git a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep31Tests.kt b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep31Tests.kt index 9461c16d54..e30d4bd675 100644 --- a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep31Tests.kt +++ b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep31Tests.kt @@ -40,7 +40,7 @@ lateinit var savedTxn: Sep31GetTransactionResponse @TestInstance(TestInstance.Lifecycle.PER_CLASS) @Execution(SAME_THREAD) @TestMethodOrder(MethodOrderer.OrderAnnotation::class) -class Sep31Tests : AbstractIntegrationTests(TestConfig(testProfileName = "default")) { +class Sep31Tests : AbstractIntegrationTests(TestConfig()) { private val sep12Client: Sep12Client = Sep12Client(toml.getString("KYC_SERVER"), this.token.token) private val sep31Client: Sep31Client = Sep31Client(toml.getString("DIRECT_PAYMENT_SERVER"), this.token.token) diff --git a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep38Tests.kt b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep38Tests.kt index 0e03e4c712..e41ee854a6 100644 --- a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep38Tests.kt +++ b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep38Tests.kt @@ -13,7 +13,7 @@ import org.stellar.anchor.platform.TestConfig import org.stellar.anchor.platform.printRequest import org.stellar.anchor.platform.printResponse -class Sep38Tests : AbstractIntegrationTests(TestConfig(testProfileName = "default")) { +class Sep38Tests : AbstractIntegrationTests(TestConfig()) { private val sep38Client: Sep38Client = Sep38Client(toml.getString("ANCHOR_QUOTE_SERVER"), this.token.token) diff --git a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep6Tests.kt b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep6Tests.kt index 52ffb84692..fadf870f71 100644 --- a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep6Tests.kt +++ b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/Sep6Tests.kt @@ -12,7 +12,7 @@ import org.stellar.anchor.platform.TestConfig import org.stellar.anchor.platform.gson import org.stellar.anchor.util.Log -class Sep6Tests : AbstractIntegrationTests(TestConfig(testProfileName = "default")) { +class Sep6Tests : AbstractIntegrationTests(TestConfig()) { private val sep6Client = Sep6Client(toml.getString("TRANSFER_SERVER"), token.token) private val sep38Client = Sep38Client(toml.getString("ANCHOR_QUOTE_SERVER"), this.token.token) diff --git a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/ServerHealthTests.kt b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/ServerHealthTests.kt index 2d2cacbe30..19642e6030 100644 --- a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/ServerHealthTests.kt +++ b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/ServerHealthTests.kt @@ -7,7 +7,7 @@ import org.stellar.anchor.auth.AuthHelper import org.stellar.anchor.platform.TestConfig class PlatformServerHealthTests { - val config = TestConfig(testProfileName = "default") + val config = TestConfig() private val platformApiClient = PlatformApiClient(AuthHelper.forNone(), config.env["sep.server.url"]!!) diff --git a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/StellarObserverTests.kt b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/StellarObserverTests.kt index 4f3d070ae4..cfd40a9333 100644 --- a/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/StellarObserverTests.kt +++ b/essential-tests/src/testFixtures/kotlin/org/stellar/anchor/platform/integrationtest/StellarObserverTests.kt @@ -9,7 +9,7 @@ import org.stellar.anchor.platform.AbstractIntegrationTests import org.stellar.anchor.platform.TestConfig import org.stellar.anchor.platform.gson -class StellarObserverTests : AbstractIntegrationTests(TestConfig(testProfileName = "default")) { +class StellarObserverTests : AbstractIntegrationTests(TestConfig()) { companion object { const val OBSERVER_HEALTH_SERVER_PORT = 8083 } diff --git a/extended-tests/src/test/kotlin/org/stellar/anchor/platform/DatabaseMigrationTests.kt b/extended-tests/src/test/kotlin/org/stellar/anchor/platform/DatabaseMigrationTests.kt index 075b15f733..e3f446d943 100644 --- a/extended-tests/src/test/kotlin/org/stellar/anchor/platform/DatabaseMigrationTests.kt +++ b/extended-tests/src/test/kotlin/org/stellar/anchor/platform/DatabaseMigrationTests.kt @@ -5,7 +5,7 @@ import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.Test val PostgresConfig = - TestConfig("default").also { + TestConfig().also { it.env[RUN_ALL_SERVERS] = "false" it.env[RUN_SEP_SERVER] = "true" it.env["data.flyway_enabled"] = "true" diff --git a/extended-tests/src/test/kotlin/org/stellar/anchor/platform/PlatformApiKeyAuthIntegrationTest.kt b/extended-tests/src/test/kotlin/org/stellar/anchor/platform/PlatformApiKeyAuthIntegrationTest.kt index 01dbbdd1f4..07e33c8e2a 100644 --- a/extended-tests/src/test/kotlin/org/stellar/anchor/platform/PlatformApiKeyAuthIntegrationTest.kt +++ b/extended-tests/src/test/kotlin/org/stellar/anchor/platform/PlatformApiKeyAuthIntegrationTest.kt @@ -21,7 +21,7 @@ internal class PlatformApiKeyAuthIntegrationTest : AbstractAuthIntegrationTest() println("Running PlatformApiKeyAuthIntegrationTest") testProfileRunner = TestProfileExecutor( - TestConfig(testProfileName = "default").also { + TestConfig().also { it.env[RUN_DOCKER] = "true" it.env[RUN_ALL_SERVERS] = "false" it.env[RUN_PLATFORM_SERVER] = "true" diff --git a/extended-tests/src/test/kotlin/org/stellar/anchor/platform/PlatformJwtAuthIntegrationTest.kt b/extended-tests/src/test/kotlin/org/stellar/anchor/platform/PlatformJwtAuthIntegrationTest.kt index 50877054b6..0c47948fe9 100644 --- a/extended-tests/src/test/kotlin/org/stellar/anchor/platform/PlatformJwtAuthIntegrationTest.kt +++ b/extended-tests/src/test/kotlin/org/stellar/anchor/platform/PlatformJwtAuthIntegrationTest.kt @@ -30,7 +30,7 @@ internal class PlatformJwtAuthIntegrationTest : AbstractAuthIntegrationTest() { println("Running PlatformJwtAuthIntegrationTest") testProfileRunner = TestProfileExecutor( - TestConfig(testProfileName = "default").also { + TestConfig().also { it.env[RUN_DOCKER] = "true" it.env[RUN_ALL_SERVERS] = "false" it.env[RUN_PLATFORM_SERVER] = "true" diff --git a/service-runner/src/main/kotlin/org/stellar/anchor/platform/TestConfig.kt b/service-runner/src/main/kotlin/org/stellar/anchor/platform/TestConfig.kt index 38b6c50a40..5524094e98 100644 --- a/service-runner/src/main/kotlin/org/stellar/anchor/platform/TestConfig.kt +++ b/service-runner/src/main/kotlin/org/stellar/anchor/platform/TestConfig.kt @@ -1,21 +1,49 @@ package org.stellar.anchor.platform -data class TestConfig(var testProfileName: String) { +import org.stellar.anchor.util.StringHelper.isNotEmpty + +/** + * TestConfig is a class that reads and merges env variables from the following files in the + * following order: The later files override the previous ones. + * - profiles/default/test.env + * - profiles/default/config.env + * - profiles/{testProfileName}/test.env (if testProfileName is not empty) + * - profiles/{testProfileName}/config.env (if testProfileName is not empty) + * - system env variables + * + * It also allows to override env variables with a custom function. + * + * @param testProfileName - name of the test profile to use. If null, the default test profile will + * be used. + * @param customize - a function that allows to override env variables + * @constructor creates a TestConfig instance + */ +class TestConfig { val env = mutableMapOf() // override test profile name with TEST_PROFILE_NAME system env variable - private val profileName = System.getenv("TEST_PROFILE_NAME") ?: testProfileName + private val envProfileName = System.getenv("TEST_PROFILE_NAME") ?: null + + constructor(testProfileName: String? = null, customize: () -> Unit = {}) { + var profileName = testProfileName + if (System.getenv("TEST_PROFILE_NAME") != null) profileName = System.getenv("TEST_PROFILE_NAME") + + if (this.envProfileName != null) profileName = this.envProfileName + // starting from the default test.env file + env.putAll(readResourceAsMap("profiles/default/test.env")) + env.putAll(readResourceAsMap("profiles/default/config.env")) + // if test profile name is not "default", read test.env and config.env files + if (isNotEmpty(profileName) && !"default".equals(profileName, ignoreCase = true)) { + // read and merge test.env file + env.putAll(readResourceAsMap("profiles/${profileName}/test.env")) + // read and merge config.env file + env.putAll(readResourceAsMap("profiles/${profileName}/config.env")) + } + + // customize env variables + customize() - init { - // read test.env file - val testEnv = readResourceAsMap("profiles/${profileName}/test.env") - // read config.env file - val configEnv = readResourceAsMap("profiles/${profileName}/config.env") - // read system env variables - val configSystem = readSystemEnvAsMap() - // merge test.env, config.env and system env variables - env.putAll(testEnv) - env.putAll(configEnv) - env.putAll(configSystem) + // read and merge system env variables + env.putAll(readSystemEnvAsMap()) } private fun readSystemEnvAsMap(): Map { diff --git a/service-runner/src/main/kotlin/org/stellar/anchor/platform/TestProfileRunner.kt b/service-runner/src/main/kotlin/org/stellar/anchor/platform/TestProfileRunner.kt index e02bd19ae7..a91eaa75b7 100644 --- a/service-runner/src/main/kotlin/org/stellar/anchor/platform/TestProfileRunner.kt +++ b/service-runner/src/main/kotlin/org/stellar/anchor/platform/TestProfileRunner.kt @@ -28,7 +28,7 @@ lateinit var testProfileExecutor: TestProfileExecutor fun main() = runBlocking { info("Starting TestPfofileExecutor...") - testProfileExecutor = TestProfileExecutor(TestConfig(testProfileName = "default")) + testProfileExecutor = TestProfileExecutor(TestConfig()) launch { Runtime.getRuntime() diff --git a/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunAllServers.kt b/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunAllServers.kt index 97d9105a95..8966736b29 100644 --- a/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunAllServers.kt +++ b/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunAllServers.kt @@ -7,7 +7,7 @@ import kotlinx.coroutines.runBlocking import org.stellar.anchor.platform.* fun main() = runBlocking { - testProfileExecutor = TestProfileExecutor(TestConfig(testProfileName = "default")) + testProfileExecutor = TestProfileExecutor(TestConfig()) launch { registerShutdownHook(testProfileExecutor) } testProfileExecutor.start(true) { it.env[RUN_DOCKER] = "false" diff --git a/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunAllServersWithDocker.kt b/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunAllServersWithDocker.kt index 57ddd4b7da..53e33b865f 100644 --- a/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunAllServersWithDocker.kt +++ b/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunAllServersWithDocker.kt @@ -7,7 +7,7 @@ import kotlinx.coroutines.runBlocking import org.stellar.anchor.platform.* fun main() = runBlocking { - testProfileExecutor = TestProfileExecutor(TestConfig(testProfileName = "default")) + testProfileExecutor = TestProfileExecutor(TestConfig()) launch { registerShutdownHook(testProfileExecutor) } testProfileExecutor.start(true) { it.env[RUN_DOCKER] = "true" diff --git a/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunDockerDevStack.kt b/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunDockerDevStack.kt index 2e01219e6f..1b12cbc112 100644 --- a/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunDockerDevStack.kt +++ b/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunDockerDevStack.kt @@ -8,7 +8,7 @@ import kotlinx.coroutines.runBlocking import org.stellar.anchor.platform.* fun main() = runBlocking { - testProfileExecutor = TestProfileExecutor(TestConfig(testProfileName = "default")) + testProfileExecutor = TestProfileExecutor(TestConfig()) launch { registerShutdownHook(testProfileExecutor) } testProfileExecutor.start(true) { it.env[RUN_DOCKER] = "true" diff --git a/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunEventProcessingServer.kt b/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunEventProcessingServer.kt index 3b9f2f58a8..4d8c0ec357 100644 --- a/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunEventProcessingServer.kt +++ b/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunEventProcessingServer.kt @@ -7,7 +7,7 @@ import kotlinx.coroutines.runBlocking import org.stellar.anchor.platform.* fun main() = runBlocking { - testProfileExecutor = TestProfileExecutor(TestConfig(testProfileName = "default")) + testProfileExecutor = TestProfileExecutor(TestConfig()) launch { registerShutdownHook(testProfileExecutor) } testProfileExecutor.start(true) { it.env[RUN_DOCKER] = "false" diff --git a/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunKotlinReferenceServer.kt b/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunKotlinReferenceServer.kt index 1c4c23cc5a..2a628d1a9a 100644 --- a/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunKotlinReferenceServer.kt +++ b/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunKotlinReferenceServer.kt @@ -6,7 +6,7 @@ import kotlinx.coroutines.runBlocking import org.stellar.anchor.platform.* fun main() = runBlocking { - testProfileExecutor = TestProfileExecutor(TestConfig(testProfileName = "default")) + testProfileExecutor = TestProfileExecutor(TestConfig()) registerShutdownHook(testProfileExecutor) testProfileExecutor.start(true) { it.env[RUN_DOCKER] = "false" diff --git a/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunPlatformServer.kt b/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunPlatformServer.kt index b4ae0041b3..2010fd2fa2 100644 --- a/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunPlatformServer.kt +++ b/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunPlatformServer.kt @@ -7,7 +7,7 @@ import kotlinx.coroutines.runBlocking import org.stellar.anchor.platform.* fun main() = runBlocking { - testProfileExecutor = TestProfileExecutor(TestConfig(testProfileName = "default")) + testProfileExecutor = TestProfileExecutor(TestConfig()) launch { registerShutdownHook(testProfileExecutor) } testProfileExecutor.start(true) { it.env[RUN_DOCKER] = "false" diff --git a/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunSEP24NoFrontend.kt b/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunSEP24NoFrontend.kt index 461353990c..f6f9347bd8 100644 --- a/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunSEP24NoFrontend.kt +++ b/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunSEP24NoFrontend.kt @@ -7,7 +7,7 @@ import kotlinx.coroutines.runBlocking import org.stellar.anchor.platform.* fun main() = runBlocking { - testProfileExecutor = TestProfileExecutor(TestConfig(testProfileName = "default")) + testProfileExecutor = TestProfileExecutor(TestConfig()) launch { registerShutdownHook(testProfileExecutor) } testProfileExecutor.start(true) { it.env[RUN_DOCKER] = "false" diff --git a/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunSepServer.kt b/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunSepServer.kt index 384568b734..fe840a05b5 100644 --- a/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunSepServer.kt +++ b/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunSepServer.kt @@ -4,11 +4,10 @@ package org.stellar.anchor.platform.run_profiles import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking -import org.stellar.anchor.client.* import org.stellar.anchor.platform.* fun main() = runBlocking { - testProfileExecutor = TestProfileExecutor(TestConfig(testProfileName = "default")) + testProfileExecutor = TestProfileExecutor(TestConfig()) launch { registerShutdownHook(testProfileExecutor) } testProfileExecutor.start(true) { it.env[RUN_DOCKER] = "false" diff --git a/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunStellarObserver.kt b/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunStellarObserver.kt index d4b5893dbf..4ea893ba8d 100644 --- a/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunStellarObserver.kt +++ b/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunStellarObserver.kt @@ -4,11 +4,10 @@ package org.stellar.anchor.platform.run_profiles import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking -import org.stellar.anchor.client.* import org.stellar.anchor.platform.* fun main() = runBlocking { - testProfileExecutor = TestProfileExecutor(TestConfig(testProfileName = "default")) + testProfileExecutor = TestProfileExecutor(TestConfig()) launch { registerShutdownHook(testProfileExecutor) } testProfileExecutor.start(true) { it.env[RUN_DOCKER] = "false" diff --git a/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunWalletServer.kt b/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunWalletServer.kt index 5f4a1c394f..f950400e95 100644 --- a/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunWalletServer.kt +++ b/service-runner/src/main/kotlin/org/stellar/anchor/platform/run_profiles/RunWalletServer.kt @@ -6,7 +6,7 @@ import kotlinx.coroutines.runBlocking import org.stellar.anchor.platform.* fun main() = runBlocking { - testProfileExecutor = TestProfileExecutor(TestConfig(testProfileName = "default")) + testProfileExecutor = TestProfileExecutor(TestConfig()) registerShutdownHook(testProfileExecutor) testProfileExecutor.start(true) { it.env[RUN_DOCKER] = "false" diff --git a/service-runner/src/main/resources/profiles/default-custody/config.env b/service-runner/src/main/resources/profiles/default-custody/config.env index 5ce0f9026d..eff0403db4 100644 --- a/service-runner/src/main/resources/profiles/default-custody/config.env +++ b/service-runner/src/main/resources/profiles/default-custody/config.env @@ -1,61 +1,14 @@ -# secrets -secret.data.username=postgres -secret.data.password=password -secret.platform_api.auth_secret=myAnchorToPlatformSecret -secret.callback_api.auth_secret=myPlatformToAnchorSecret -secret.sep10.jwt_secret=secret_sep10_secret -secret.sep10.signing_seed=SAX3AH622R2XT6DXWWSRIDCMMUCCMATBZ5U6XKJWDO7M2EJUBFC3AW5X -secret.sep24.interactive_url.jwt_secret=secret_sep24_interactive_url_jwt_secret -secret.sep24.more_info_url.jwt_secret=secret_sep24_more_info_url_jwt_secret -secret.custody_server.auth_secret=myPlatformToCustodySecret secret.custody.fireblocks.api_key=testApiKey secret.custody.fireblocks.secret_key=MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAJPq9AU6f8GrkSccloRb+UJmbxilZ7iLkvp0FeR/yymQuJDMNXPXwt5MYR9VJoY0uMDHThaEwbQAc2M4L9wl0EtsESebODUTqnsWZ8/a6GsmvIM3kz02ZOUHLst0krSkECPUHLLUKuw/HWz3LWxWLeqVRIcsCwKJNaBPZJzFw/8PAgMBAAECgYBhWXSYLFQApmW1k/8LxWxa4wei9Nk6f8GPy+7Mn76Z8IFH6t4TC6FYpHQXJvdfxDsDxSgDcgP574IBfu0gulJHEIsoDy1xR8TPobfhwoS1NJn70a8KQA6Whu+K5pjJxGUC7bpJH4ZK0O+szB1mNC0WgUywIc0lXCFFnCrgbNFWQQJBAM7+zgHAyD6rqQem09JcabMkwxu0mYih1mvQ3uv/fay8BdgZAqMuacMAPQ/A1TLeuTbMQ0LojnK/QlotbhHVnSkCQQC27684POaRrVIsVo5uKvQsKSNlYPpvGrGapHKiVgIQYfZSEY9SrazqKbA5yux0OR8ZFFSiJCThRElpzhnWFYl3AkEArNsLnVsn3W3sUX93FAwoGHlylQhTzk2XiaF7BwjsIftBxhvcn/h6SWVBmI4ne7uSX7hj0tPxYNFmz3dwm2QPQQJBAKS8mPSy2wtqoiotVBvfcHzoGujrePpednuFBXosq7UnEpN7Hq7cmW9RVVHl7CMJYXjLNx/AHroBLX8rS1bflCcCQBclpUG1PybVy1jHXTdI0w6zB6AwjaeFN5x4+b7hRe29yLNF532uIatxif19LHb5jUC7EefpLWBxx/bB4JCIyug= -# logging -app_logging.stellar_level=DEBUG -app_logging.request_logger_enabled=true -# events -events.enabled=true -events.queue.type=kafka -events.queue.kafka.bootstrap_server=kafka:29092 -# callback API endpoint -callback_api.base_url=http://reference-server:8091/ -# platform API endpoint -platform_api.base_url=http://platform:8085/ -custody_server.base_url=http://custody-server:8086 -# data -data.type=postgres -data.server=db:5432 -data.database=postgres -data.flyway_enabled=true -# assets -assets.type=file -assets.value=/config/assets.yaml + # seps -sep1.enabled=true -sep1.toml.type=file -sep1.toml.value=/config/stellar.localhost.toml -sep6.enabled=true -sep10.enabled=true -sep12.enabled=true -sep31.enabled=true -sep38.enabled=true -sep24.enabled=true -sep24.interactive_url.base_url=http://localhost:8091/sep24/interactive -sep24.more_info_url.base_url=http://localhost:8091/sep24/transaction/more_info sep6.deposit_info_generator_type=custody sep24.deposit_info_generator_type=custody sep31.deposit_info_generator_type=custody + +# custody custody.type=fireblocks custody.fireblocks.vault_account_id=1 custody.fireblocks.public_key=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCT6vQFOn/Bq5EnHJaEW/lCZm8YpWe4i5L6dBXkf8spkLiQzDVz18LeTGEfVSaGNLjAx04WhMG0AHNjOC/cJdBLbBEnmzg1E6p7FmfP2uhrJryDN5M9NmTlBy7LdJK0pBAj1Byy1CrsPx1s9y1sVi3qlUSHLAsCiTWgT2ScxcP/DwIDAQAB custody.fireblocks.asset_mappings=XLM_USDC_T_CEKS stellar:USDC:GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5\nXLM_TEST stellar:native custody.fireblocks.reconciliation.cron_expression=0/10 * * * * * -# clients -clients[0].name=reference -clients[0].type=noncustodial -clients[0].domain=wallet-server:8092 -clients[0].callback_url=http://wallet-server:8092/callbacks -clients[1].name=referenceCustodial -clients[1].type=custodial -clients[1].signing_key=GDJLBYYKMCXNVVNABOE66NYXQGIA5AC5D223Z2KF6ZEYK4UBCA7FKLTG -clients[1].callback_url=http://wallet-server:8092/callbacks \ No newline at end of file diff --git a/service-runner/src/main/resources/profiles/default-custody/test.env b/service-runner/src/main/resources/profiles/default-custody/test.env index 50a2648dcd..1e6b699be2 100644 --- a/service-runner/src/main/resources/profiles/default-custody/test.env +++ b/service-runner/src/main/resources/profiles/default-custody/test.env @@ -1,15 +1 @@ -# Test configurations -anchor.domain=http://localhost:8080 -sep.server.url=http://localhost:8080 -reference.server.url=http://localhost:8091 -observer.server.url=http://localhost:8083 -platform.server.url=http://localhost:8085 -custody.server.url=http://localhost:8086 -wallet.server.url=http://localhost:8092 -run_docker=true -run_all_servers=true - -# Kotlin reference server configuration -app.custodyEnabled=true -wallet.hostname=wallet-server:8092 -sep24.interactiveJwtKey=secret_sep24_interactive_url_jwt_secret \ No newline at end of file +app.custodyEnabled=true \ No newline at end of file diff --git a/service-runner/src/main/resources/profiles/default-rpc/config.env b/service-runner/src/main/resources/profiles/default-rpc/config.env index 9efef89cf5..e69de29bb2 100644 --- a/service-runner/src/main/resources/profiles/default-rpc/config.env +++ b/service-runner/src/main/resources/profiles/default-rpc/config.env @@ -1,51 +0,0 @@ -# secrets -secret.data.username=postgres -secret.data.password=password -secret.platform_api.auth_secret=myAnchorToPlatformSecret -secret.callback_api.auth_secret=myPlatformToAnchorSecret -secret.sep10.jwt_secret=secret_sep10_secret -secret.sep10.signing_seed=SAX3AH622R2XT6DXWWSRIDCMMUCCMATBZ5U6XKJWDO7M2EJUBFC3AW5X -secret.sep24.interactive_url.jwt_secret=secret_sep24_interactive_url_jwt_secret -secret.sep24.more_info_url.jwt_secret=secret_sep24_more_info_url_jwt_secret -secret.custody_server.auth_secret=myPlatformToCustodySecret -# logging -app_logging.stellar_level=DEBUG -app_logging.request_logger_enabled=true -# events -events.enabled=true -events.queue.type=kafka -events.queue.kafka.bootstrap_server=kafka:29092 -# callback API endpoint -callback_api.base_url=http://reference-server:8091/ -# platform API endpoint -platform_api.base_url=http://platform:8085/ -custody_server.base_url=http://custody-server:8086 -# data -data.type=postgres -data.server=db:5432 -data.database=postgres -data.flyway_enabled=true -# assets -assets.type=file -assets.value=/config/assets.yaml -# seps -sep1.enabled=true -sep1.toml.type=file -sep1.toml.value=/config/stellar.localhost.toml -sep6.enabled=true -sep10.enabled=true -sep12.enabled=true -sep31.enabled=true -sep38.enabled=true -sep24.enabled=true -sep24.interactive_url.base_url=http://localhost:8091/sep24/interactive -sep24.more_info_url.base_url=http://localhost:8091/sep24/transaction/more_info -# clients -clients[0].name=reference -clients[0].type=noncustodial -clients[0].domain=wallet-server:8092 -clients[0].callback_url=http://wallet-server:8092/callbacks -clients[1].name=referenceCustodial -clients[1].type=custodial -clients[1].signing_key=GDJLBYYKMCXNVVNABOE66NYXQGIA5AC5D223Z2KF6ZEYK4UBCA7FKLTG -clients[1].callback_url=http://wallet-server:8092/callbacks \ No newline at end of file diff --git a/service-runner/src/main/resources/profiles/default-rpc/test.env b/service-runner/src/main/resources/profiles/default-rpc/test.env index 406a8bc727..72c050d5d4 100644 --- a/service-runner/src/main/resources/profiles/default-rpc/test.env +++ b/service-runner/src/main/resources/profiles/default-rpc/test.env @@ -1,15 +1 @@ -# Test configurations -anchor.domain=http://localhost:8080 -sep.server.url=http://localhost:8080 -reference.server.url=http://localhost:8091 -observer.server.url=http://localhost:8083 -platform.server.url=http://localhost:8085 -custody.server.url=http://localhost:8086 -wallet.server.url=http://localhost:8092 -run_docker=true -run_all_servers=true - -# Kotlin reference server configuration app.rpcEnabled=true -wallet.hostname=wallet-server:8092 -sep24.interactiveJwtKey=secret_sep24_interactive_url_jwt_secret \ No newline at end of file diff --git a/service-runner/src/main/resources/profiles/default-custody-rpc/config.env b/service-runner/src/main/resources/profiles/unused-default-custody-rpc/config.env similarity index 100% rename from service-runner/src/main/resources/profiles/default-custody-rpc/config.env rename to service-runner/src/main/resources/profiles/unused-default-custody-rpc/config.env diff --git a/service-runner/src/main/resources/profiles/default-custody-rpc/test.env b/service-runner/src/main/resources/profiles/unused-default-custody-rpc/test.env similarity index 100% rename from service-runner/src/main/resources/profiles/default-custody-rpc/test.env rename to service-runner/src/main/resources/profiles/unused-default-custody-rpc/test.env