11package io.github.hosseinkarami_dev.near.rpc.client
22
3+ import io.github.hosseinkarami_dev.near.rpc.client.Utils.getResultOrNull
4+ import io.github.hosseinkarami_dev.near.rpc.models.RpcStatusResponse
35import io.ktor.client.HttpClient
46import io.ktor.client.engine.cio.CIO
57import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
68import io.ktor.serialization.kotlinx.json.json
79import kotlinx.coroutines.test.runTest
810import org.junit.jupiter.api.Test
11+ import kotlin.test.AfterTest
12+ import kotlin.test.BeforeTest
13+ import kotlin.test.assertNotNull
914
1015class NearClientTest {
1116
12- private val httpClient = HttpClient (CIO ) {
13- install(ContentNegotiation ) {
14- json()
17+ private lateinit var httpClient: HttpClient
18+ private lateinit var nearClient: NearClient
19+
20+ @BeforeTest
21+ fun setup () {
22+ httpClient = HttpClient (CIO ) {
23+ install(ContentNegotiation ) {
24+ json()
25+ }
1526 }
27+
28+ nearClient = NearClient (
29+ httpClient = httpClient,
30+ baseUrl = " https://rpc.testnet.near.org"
31+ )
32+ }
33+
34+ @AfterTest
35+ fun teardown () {
36+ httpClient.close()
1637 }
17- //
18- // private val nearClient = NearClient(
19- // httpClient = httpClient,
20- // baseUrl = "https://rpc.mainnet.near.org"
21- // )
2238
2339 @Test
24- fun testTransactionStatus () = runTest {
40+ fun testStatus () = runTest {
41+ val response = nearClient.status()
42+ val result = response.getResultOrNull<RpcStatusResponse >()
43+ assertNotNull(result)
44+ println (" Status response: $result " )
2545 }
2646}
0 commit comments