Skip to content

Commit 21a5067

Browse files
Test Coverage Added
1 parent 95f3b51 commit 21a5067

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.CryptoHash
5+
import io.github.hosseinkarami_dev.near.rpc.models.RpcSendTransactionRequest
6+
import io.github.hosseinkarami_dev.near.rpc.models.RpcValidatorResponse
7+
import io.github.hosseinkarami_dev.near.rpc.models.SignedTransaction
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 BroadcastTxAsyncTest {
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.broadcastTxAsync(
45+
RpcSendTransactionRequest(
46+
signedTxBase64 = SignedTransaction("DgAAAHNlbmRlci50ZXN0bmV0AOrmAai64SZOv9e/naX4W15pJx0GAap35wTT1T/DwcbbDwAAAAAAAAAQAAAAcmVjZWl2ZXIudGVzdG5ldNMnL7URB1cxPOu3G8jTqlEwlcasagIbKlAJlF5ywVFLAQAAAAMAAACh7czOG8LTAAAAAAAAAGQcOG03xVSFQFjoagOb4NBBqWhERnnz45LY4+52JgZhm1iQKz7qAdPByrGFDQhQ2Mfga8RlbysuQ8D8LlA6bQE="),
47+
)
48+
)
49+
val result = response.getResultOrNull<CryptoHash>()
50+
println("broadcastTxAsync Response: $result")
51+
assertNotNull(response !is RpcResponse.Failure)
52+
}
53+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.CryptoHash
5+
import io.github.hosseinkarami_dev.near.rpc.models.RpcSendTransactionRequest
6+
import io.github.hosseinkarami_dev.near.rpc.models.RpcTransactionResponse
7+
import io.github.hosseinkarami_dev.near.rpc.models.SignedTransaction
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 BroadcastTxCommitTest {
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.broadcastTxCommit(
45+
RpcSendTransactionRequest(
46+
signedTxBase64 = SignedTransaction("DgAAAHNlbmRlci50ZXN0bmV0AOrmAai64SZOv9e/naX4W15pJx0GAap35wTT1T/DwcbbDwAAAAAAAAAQAAAAcmVjZWl2ZXIudGVzdG5ldNMnL7URB1cxPOu3G8jTqlEwlcasagIbKlAJlF5ywVFLAQAAAAMAAACh7czOG8LTAAAAAAAAAGQcOG03xVSFQFjoagOb4NBBqWhERnnz45LY4+52JgZhm1iQKz7qAdPByrGFDQhQ2Mfga8RlbysuQ8D8LlA6bQE="),
47+
)
48+
)
49+
val result = response.getResultOrNull<RpcTransactionResponse>()
50+
println("broadcastTxCommit Response: $result")
51+
assertNotNull(response !is RpcResponse.Failure)
52+
}
53+
}

0 commit comments

Comments
 (0)