1+ package io.github.hosseinkarami_dev.near.rpc.client
2+
3+ import io.github.hosseinkarami_dev.near.rpc.client.Utils.getResultOrNull
4+ import io.github.hosseinkarami_dev.near.rpc.models.AccountId
5+ import io.github.hosseinkarami_dev.near.rpc.models.BlockId
6+ import io.github.hosseinkarami_dev.near.rpc.models.RpcQueryRequest
7+ import io.github.hosseinkarami_dev.near.rpc.models.RpcQueryResponse
8+ import io.ktor.client.HttpClient
9+ import io.ktor.client.engine.cio.CIO
10+ import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
11+ import io.ktor.serialization.kotlinx.json.json
12+ import kotlinx.coroutines.test.runTest
13+ import org.junit.jupiter.api.Test
14+ import kotlin.test.AfterTest
15+ import kotlin.test.BeforeTest
16+ import kotlin.test.assertTrue
17+
18+ class QueryTest2 {
19+
20+ private lateinit var httpClient: HttpClient
21+ private lateinit var nearClient: NearClient
22+
23+ @BeforeTest
24+ fun setup () {
25+ httpClient = HttpClient (CIO ) {
26+ install(ContentNegotiation ) {
27+ json()
28+ }
29+ }
30+
31+ nearClient = NearClient (
32+ httpClient = httpClient,
33+ baseUrl = " https://rpc.mainnet.near.org"
34+ )
35+ }
36+
37+ @AfterTest
38+ fun teardown () {
39+ httpClient.close()
40+ }
41+
42+ @Test
43+ fun testStatus () = runTest {
44+ val response = nearClient.query(
45+ RpcQueryRequest .ViewAccountByBlockId (
46+ accountId = AccountId (" relay.tg" ),
47+ blockId = BlockId .BlockHeight (167692398U ),
48+ requestType = RpcQueryRequest .ViewAccountByBlockId .RequestType .VIEW_ACCOUNT
49+ )
50+ )
51+
52+ val result = response.getResultOrNull<RpcQueryResponse >()
53+ println (" ViewAccountByBlockId Response: $result " )
54+ assertTrue { response is RpcResponse .Success }
55+ }
56+ }
0 commit comments