Skip to content

Commit

Permalink
convert all sep tests, platform api, callback api and health endpoint…
Browse files Browse the repository at this point in the history
… tests
  • Loading branch information
lijamie98 committed Oct 31, 2023
1 parent 791a579 commit 8f0c30c
Show file tree
Hide file tree
Showing 11 changed files with 4,132 additions and 486 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package org.stellar.anchor.platform

import io.ktor.client.plugins.*
import io.ktor.http.*
import kotlinx.coroutines.runBlocking
import org.stellar.anchor.platform.test.*
import org.stellar.anchor.util.Sep1Helper
import org.stellar.walletsdk.ApplicationConfiguration
import org.stellar.walletsdk.StellarConfiguration
import org.stellar.walletsdk.Wallet
import org.stellar.walletsdk.anchor.auth
import org.stellar.walletsdk.horizon.SigningKeyPair

open class AbstractIntegrationTest(private val config: TestConfig) {
companion object {
Expand All @@ -21,15 +29,7 @@ open class AbstractIntegrationTest(private val config: TestConfig) {

val testProfileRunner = TestProfileExecutor(config)
lateinit var sep6Tests: Sep6Tests
lateinit var sep10Tests: Sep10Tests
lateinit var sep12Tests: Sep12Tests
lateinit var sep24Tests: Sep24Tests
lateinit var sep31Tests: Sep31Tests
lateinit var sep38Tests: Sep38Tests
lateinit var sepHealthTests: SepHealthTests
lateinit var platformApiTests: PlatformApiTests
lateinit var platformApiCustodyTests: PlatformApiCustodyTests
lateinit var callbackApiTests: CallbackApiTests
lateinit var stellarObserverTests: StellarObserverTests
lateinit var custodyApiTests: CustodyApiTests
lateinit var eventProcessingServerTests: EventProcessingServerTests
Expand All @@ -50,26 +50,16 @@ open class AbstractIntegrationTest(private val config: TestConfig) {
testProfileRunner.shutdown()
}

private fun setupTests() {
private fun setupTests() = runBlocking {
// Query SEP-1
val toml =
Sep1Helper.parse(resourceAsString("${config.env["anchor.domain"]}/.well-known/stellar.toml"))

// Create Sep10Tests
sep10Tests = Sep10Tests(toml)

// Get JWT
val jwt = sep10Tests.sep10Client.auth()
val jwt = auth()

sep6Tests = Sep6Tests(toml)
sep12Tests = Sep12Tests(config, toml, jwt)
sep24Tests = Sep24Tests(config, toml, jwt)
sep31Tests = Sep31Tests(config, toml, jwt)
sep38Tests = Sep38Tests(config, toml, jwt)
sepHealthTests = SepHealthTests(config, toml, jwt)
platformApiTests = PlatformApiTests(config, toml, jwt)
platformApiCustodyTests = PlatformApiCustodyTests(config, toml, jwt)
callbackApiTests = CallbackApiTests(config, toml, jwt)
stellarObserverTests = StellarObserverTests()
custodyApiTests = CustodyApiTests(config, toml, jwt)
sep24E2eTests = Sep24End2EndTests(config, jwt)
Expand All @@ -80,4 +70,15 @@ open class AbstractIntegrationTest(private val config: TestConfig) {
sep31CustodyRpcE2eTests = Sep31CustodyRpcEnd2EndTests(config, toml, jwt)
eventProcessingServerTests = EventProcessingServerTests(config, toml, jwt)
}

private suspend fun auth(): String {
val wallet =
Wallet(
StellarConfiguration.Testnet,
ApplicationConfiguration { defaultRequest { url { protocol = URLProtocol.HTTP } } }
)
val walletKeyPair = SigningKeyPair.fromSecret(CLIENT_WALLET_SECRET)
val anchor = wallet.anchor(config.env["anchor.domain"]!!)
return anchor.auth().authenticate(walletKeyPair).token
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,54 +29,12 @@ class AnchorPlatformIntegrationTest :
}
}

@Test
@Order(11)
fun runSep10Test() {
singleton.sep10Tests.testAll()
}

@Test
@Order(12)
fun runSep12Test() {
singleton.sep12Tests.testAll()
}

@Test
@Order(13)
fun runSep24Test() {
singleton.sep24Tests.testAll()
}

@Test
@Order(14)
fun runSep31Test() {
singleton.sep31Tests.testAll()
}

@Test
@Order(15)
fun runSep38Test() {
singleton.sep38Tests.testAll()
}

@Test
@Order(16)
fun runSep6Test() {
singleton.sep6Tests.testAll()
}

@Test
@Order(21)
fun runSepHealthTest() {
singleton.sepHealthTests.testAll()
}

@Test
@Order(31)
fun runPlatformApiTest() {
singleton.platformApiTests.testAll()
}

@Test
@Order(41)
fun runCallbackApiTest() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.stellar.anchor.platform.test
package org.stellar.anchor.platform.subtest

import com.google.gson.Gson
import java.time.Instant
Expand All @@ -10,6 +10,7 @@ import java.util.concurrent.TimeUnit
import okhttp3.OkHttpClient
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.skyscreamer.jsonassert.JSONAssert
import org.stellar.anchor.api.callback.GetCustomerRequest
Expand All @@ -24,10 +25,11 @@ import org.stellar.anchor.platform.TestConfig
import org.stellar.anchor.platform.callback.RestCustomerIntegration
import org.stellar.anchor.platform.callback.RestFeeIntegration
import org.stellar.anchor.platform.callback.RestRateIntegration
import org.stellar.anchor.platform.test.testCustomer1Json
import org.stellar.anchor.platform.test.testCustomer2Json
import org.stellar.anchor.util.GsonUtils
import org.stellar.anchor.util.Sep1Helper

class CallbackApiTests(val config: TestConfig, val toml: Sep1Helper.TomlContent, val jwt: String) {
class CallbackApiTests : SepTests(TestConfig(testProfileName = "default")) {

companion object {
private const val JWT_EXPIRATION_MILLISECONDS: Long = 10000
Expand All @@ -36,7 +38,7 @@ class CallbackApiTests(val config: TestConfig, val toml: Sep1Helper.TomlContent,
"stellar:USDC:GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP"
}

private val sep12Client: Sep12Client = Sep12Client(toml.getString("KYC_SERVER"), jwt)
private val sep12Client: Sep12Client = Sep12Client(toml.getString("KYC_SERVER"), token.token)

private val httpClient: OkHttpClient =
OkHttpClient.Builder()
Expand Down Expand Up @@ -67,13 +69,15 @@ class CallbackApiTests(val config: TestConfig, val toml: Sep1Helper.TomlContent,
private val rfiClient =
RestFeeIntegration(config.env["reference.server.url"]!!, httpClient, authHelper, gson)

private fun testCustomerIntegration() {
@Test
fun testCustomerIntegration() {
assertThrows<NotFoundException> {
rci.getCustomer(GetCustomerRequest.builder().id("1").build())
}
}

private fun testRate_indicativePrice() {
@Test
fun testRate_indicativePrice() {
val result =
rriClient.getRate(
GetRateRequest.builder()
Expand Down Expand Up @@ -107,7 +111,8 @@ class CallbackApiTests(val config: TestConfig, val toml: Sep1Helper.TomlContent,
JSONAssert.assertEquals(wantBody, org.stellar.anchor.platform.gson.toJson(result), true)
}

private fun testRate_firm() {
@Test
fun testRate_firm() {
val rate =
rriClient
.getRate(
Expand Down Expand Up @@ -169,7 +174,8 @@ class CallbackApiTests(val config: TestConfig, val toml: Sep1Helper.TomlContent,
JSONAssert.assertEquals(wantBody, org.stellar.anchor.platform.gson.toJson(gotQuote), true)
}

private fun testGetFee() {
@Test
fun testGetFee() {
// Create sender customer
val senderCustomerRequest =
GsonUtils.getInstance().fromJson(testCustomer1Json, Sep12PutCustomerRequest::class.java)
Expand Down Expand Up @@ -204,13 +210,4 @@ class CallbackApiTests(val config: TestConfig, val toml: Sep1Helper.TomlContent,
true
)
}

fun testAll() {
println("Performing Callback API tests...")

testCustomerIntegration()
testRate_indicativePrice()
testRate_firm()
testGetFee()
}
}
Loading

0 comments on commit 8f0c30c

Please sign in to comment.