Skip to content

Commit

Permalink
Unit tests for latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
counters committed Apr 14, 2022
1 parent 7b018c2 commit 6ce6d69
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
19 changes: 13 additions & 6 deletions src/test/kotlin/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ import counters.minter.sdk.minter_api.http.HttpOptions

class Config {
companion object {
// private val hostname = "node-api.testnet.minter.network"
// private val hostname = "node2.knife.io"
private val hostname = "node-api.testnet.minter.network"
// private val hostname = "node-api.taconet.minter.network"
private val hostname = "localhost"
val httpOptions = HttpOptions(raw = "http://${hostname}:8843/v2", timeout = 60000)
// val httpOptions = HttpOptions(raw = "https://node-api.testnet.minter.network/v2")
val grpcOptions = GrpcOptions(hostname = hostname, deadline = 30000)
// private val hostname = "localhost"
// val httpOptions = HttpOptions(raw = "http://${hostname}:8843/v2"/*, timeout = 60000*/)
val httpOptions = HttpOptions(raw = "https://node-api.testnet.minter.network/v2")
// val grpcOptions = GrpcOptions(hostname = hostname/*, deadline = 30000*/)
val grpcOptions = GrpcOptions(hostname = hostname, port = 28842/*, deadline = 30000*/)

val network = Utils.Network.Mainnet4
// val network = Utils.Network.Mainnet5
val network = Utils.Network.TestNet
// val network = Utils.Network.Taconet13

val exception = true
//const val exception = false
}
}
1 change: 1 addition & 0 deletions src/test/kotlin/counters/minter/sdk/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Utils(val network: Network) {
Mainnet4("minter-mainnet-4"),
Mainnet5("minter-mainnet-5"),
Taconet13("v2.6.0-testnet13"),
TestNet("minter3-testnet1"),

}

Expand Down
42 changes: 33 additions & 9 deletions src/test/kotlin/counters/minter/sdk/minter_api/MinterApiTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.util.concurrent.Semaphore
import kotlin.random.Random
Expand All @@ -30,9 +31,16 @@ internal class MinterApiTest {
private val minterHttpApi = MinterApi(null, Config.httpOptions)
private val minterGrpcApi = MinterApi(Config.grpcOptions, null)

@BeforeEach
internal fun setUp() {
minterHttpApi.exception = Config.exception
minterGrpcApi.exception = Config.exception
}

@AfterEach
internal fun tearDown() {
minterGrpcApi.shutdown()
minterHttpApi.shutdown()
}

@Test
Expand Down Expand Up @@ -157,7 +165,11 @@ internal class MinterApiTest {
expected.await()?.let {
if (type == TransactionTypes.VOTE_COMMISSION) {
assertVOTE_COMMISSION(it, actual.await())
} else {
} else if (expected.await()?.optData!=null && actual.await()?.optData!=null) {
assertEquals(expected.await()!!.copy(optData = null), actual.await()!!.copy(optData = null))
// assertEquals(expected.await()!!.copy(amount = null), actual.await()!!.copy(amount = null))
// assertEquals(expected.await()?.amount!!, actual.await()?.amount!!, 0.0001)
} else {
assertEquals(it, actual.await())
}
/* if (type == TransactionTypes.VOTE_COMMISSION) {
Expand All @@ -178,13 +190,17 @@ internal class MinterApiTest {
runBlocking {
TransactionTypes.values().forEach { type ->
Utils(Config.network).getFailedTransactions(type, 10, true).forEach {
println("$type: $it")
// println("$type: $it")
val expected = async { minterHttpApi.getTransactionCoroutines(it) }
val actual = async { minterGrpcApi.getTransactionCoroutines(it) }
expected.await()?.let {
if (type == TransactionTypes.VOTE_COMMISSION) {
assertVOTE_COMMISSION(it, actual.await())
} else {
} else if (expected.await()?.optData!=null && actual.await()?.optData!=null) {
assertEquals(expected.await()!!.copy(optData = null), actual.await()!!.copy(optData = null))
// assertEquals(expected.await()!!.copy(amount = null), actual.await()!!.copy(amount = null))
// assertEquals(expected.await()?.amount!!, actual.await()?.amount!!, 0.0001)
} else {
assertEquals(it, actual.await())
}
} ?: run {
Expand All @@ -199,24 +215,31 @@ internal class MinterApiTest {
@Test
fun getOneTypeTransactionCoroutines() {
runBlocking {
val type = TransactionTypes.TypeSend
LibTransactionTypes.mapTypeTrs[type]?.count()?.let { count ->
val index = Random.nextInt(1, count - 1).dec()
val type = TransactionTypes.LOCK_STAKE
// LibTransactionTypes.mapTypeTrs[type]?.count()?.let { count ->
// Utils(Config.network).getNumismatistsAddresses(10, true).forEach {
// val index = Random.nextInt(1, count - 1).dec()
// "Mt1b1ba5298ce9771b58ec9bc252b9a18fc6eb301dfca585c64c44b8a63f7089f1".let {
Utils(Config.network).getTransactions(type, 10, true).forEach {
println(it)
// LibTransactionTypes.mapTypeTrs[type]?.getOrNull(index)?.let {
val expected = async { minterHttpApi.getTransactionCoroutines(it) }
val actual = async { minterGrpcApi.getTransactionCoroutines(it) }
// val actualValue = actual.await()
assertNotEquals(null, actual.await())
if (type == TransactionTypes.VOTE_COMMISSION) {
assertVOTE_COMMISSION(expected.await(), actual.await())
} else if (expected.await()?.optData!=null && actual.await()?.optData!=null) {
assertEquals(expected.await()!!.copy(optData = null), actual.await()!!.copy(optData = null))
// assertEquals(expected.await()!!.copy(amount = null), actual.await()!!.copy(amount = null))
// assertEquals(expected.await()?.amount!!, actual.await()?.amount!!, 0.0001)
// assertEquals((expected.await()?.optData!! as Long),( actual.await()?.optData!! as Long))
} else {
assertEquals(expected.await(), actual.await())
}
return@runBlocking
}
}
// }
assert(false)
}
}
Expand Down Expand Up @@ -329,7 +352,8 @@ internal class MinterApiTest {
@Test
fun getAddress() {
// "Mx170efb7414ba43bfbcd6aac831abc289de916635".let {
transactionsByType(TransactionTypes.TypeDeclareCandidacy)?.first()?.from?.let {
// transactionsByType(TransactionTypes.TypeDeclareCandidacy)?.first()?.from?.let {
Utils(Config.network).getNumismatistsAddresses(10, true).forEach {
// println(it)
minterHttpApi.getAddress(address = it, height = null, delegated = true)?.let { address ->
// println(address)
Expand Down Expand Up @@ -884,7 +908,7 @@ internal class MinterApiTest {

@Test
fun getTransactionsRaw() {
val transactionType = TransactionTypes.TypeDeclareCandidacy
val transactionType = TransactionTypes.TypeSend
assertEquals(transactionType.int, transactionsByType(transactionType)?.first()?.type)
}

Expand Down

0 comments on commit 6ce6d69

Please sign in to comment.