Skip to content

Commit 1e5e8aa

Browse files
Test Coverage Added
1 parent c352931 commit 1e5e8aa

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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.Finality
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.assertNotNull
17+
18+
class QueryTest {
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.ViewAccountByFinality(
46+
finality = Finality.FINAL,
47+
accountId = AccountId("neardome2340.near"),
48+
requestType = RpcQueryRequest.ViewAccountByFinality.RequestType.VIEW_ACCOUNT
49+
)
50+
)
51+
val result = response.getResultOrNull<RpcQueryResponse>()
52+
println("ViewAccountByFinality Response: $result")
53+
54+
assertNotNull(response is RpcResponse.Success)
55+
}
56+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 { true }
55+
}
56+
}

0 commit comments

Comments
 (0)