Skip to content

Commit

Permalink
migrate to rpc-solana for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Funkatronics committed Jun 7, 2024
1 parent cf0f652 commit d29b82d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 208 deletions.
5 changes: 4 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[versions]
kotlinxCoroutines = "1.7.3"
ktor = "2.3.11"
rpcCore = "0.2.6"

# Plugin versions
androidGradlePlugin = "8.0.2"
Expand All @@ -18,7 +19,9 @@ kotlinx-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-cor
ktor-client-core = { group = "io.ktor", name = "ktor-client-core", version.ref = "ktor" }
ktor-client-cio = { group = "io.ktor", name = "ktor-client-cio", version.ref = "ktor" }
multimult = { group = "io.github.funkatronics", name = "multimult", version = "0.2.1" }
rpc-core = { group = "com.solanamobile", name = "rpc-core", version = "0.2.5" }
rpc-core = { group = "com.solanamobile", name = "rpc-core", version.ref = "rpcCore" }
rpc-ktordriver = { group = "com.solanamobile", name = "rpc-ktordriver", version.ref = "rpcCore" }
rpc-solana = { group = "com.solanamobile", name = "rpc-solana", version.ref = "rpcCore" }

[plugins]
android-library = { id = "com.android.library", version.ref = "androidGradlePlugin" }
Expand Down
2 changes: 2 additions & 0 deletions solana/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ kotlin {
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.cio)
implementation(libs.rpc.core)
implementation(libs.rpc.ktordriver)
implementation(libs.rpc.solana)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.solana.programs

import com.solana.config.TestConfig
import com.solana.networking.KtorNetworkDriver
import com.solana.publickey.SolanaPublicKey
import com.solana.rpc.SolanaRpcClient
import com.solana.transaction.Message
import com.solana.transaction.Transaction
import com.solana.util.RpcClient
import diglol.crypto.Ed25519
import kotlinx.coroutines.test.runTest
import kotlin.test.Test
Expand All @@ -18,7 +19,7 @@ class MemoProgramTests {
// given
val keyPair = Ed25519.generateKeyPair()
val pubkey = SolanaPublicKey(keyPair.publicKey)
val rpc = RpcClient(TestConfig.RPC_URL)
val rpc = SolanaRpcClient(TestConfig.RPC_URL, KtorNetworkDriver())
val message = "hello solana!"

// when
Expand All @@ -33,7 +34,7 @@ class MemoProgramTests {
Transaction(listOf(sig), this)
}

val response = rpc.sendTransaction(transaction)
val response = rpc.sendTransaction(transaction, true)

// then
assertNull(airdropResponse.error)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.solana.programs

import com.solana.config.TestConfig
import com.solana.networking.KtorNetworkDriver
import com.solana.publickey.SolanaPublicKey
import com.solana.rpc.Commitment
import com.solana.rpc.SolanaRpcClient
import com.solana.rpc.TransactionOptions
import com.solana.transaction.Message
import com.solana.transaction.Transaction
import com.solana.util.RpcClient
import diglol.crypto.Ed25519
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.withContext
import kotlin.test.Test
Expand All @@ -25,7 +26,7 @@ class SystemProgramTests {
val newAccountKeyPair = Ed25519.generateKeyPair()
val payerPubkey = SolanaPublicKey(payerKeyPair.publicKey)
val newAccountPubkey = SolanaPublicKey(newAccountKeyPair.publicKey)
val rpc = RpcClient(TestConfig.RPC_URL)
val rpc = SolanaRpcClient(TestConfig.RPC_URL, KtorNetworkDriver())

// when
val airdropResponse = rpc.requestAirdrop(payerPubkey, 0.1f)
Expand All @@ -49,7 +50,9 @@ class SystemProgramTests {
}

withContext(Dispatchers.Default.limitedParallelism(1)) {
rpc.sendAndConfirmTransaction(transaction)
rpc.sendTransaction(transaction, true).apply {
result?.let { rpc.confirmTransaction(it, TransactionOptions(Commitment.CONFIRMED)) }
}
}

val response = rpc.getBalance(newAccountPubkey)
Expand All @@ -69,7 +72,7 @@ class SystemProgramTests {
val receiverKeyPair = Ed25519.generateKeyPair()
val payerPubkey = SolanaPublicKey(payerKeyPair.publicKey)
val receiverPubkey = SolanaPublicKey(receiverKeyPair.publicKey)
val rpc = RpcClient(TestConfig.RPC_URL)
val rpc = SolanaRpcClient(TestConfig.RPC_URL, KtorNetworkDriver())
val balance = 10000000L // lamports

// when
Expand All @@ -85,7 +88,9 @@ class SystemProgramTests {
}

withContext(Dispatchers.Default.limitedParallelism(1)) {
rpc.sendAndConfirmTransaction(transaction)
rpc.sendTransaction(transaction, true).apply {
result?.let { rpc.confirmTransaction(it, TransactionOptions(Commitment.CONFIRMED)) }
}
}

val response = rpc.getBalance(receiverPubkey)
Expand Down
197 changes: 0 additions & 197 deletions solana/src/commonTest/kotlin/com/solana/util/RpcClient.kt

This file was deleted.

0 comments on commit d29b82d

Please sign in to comment.