validators for starknet, vara and solana (#350)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package io.emeraldpay.dshackle.upstream.polkadot
|
||||
|
||||
import io.emeraldpay.dshackle.data.BlockId
|
||||
import io.emeraldpay.dshackle.upstream.UpstreamAvailability
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
@@ -31,6 +32,34 @@ val example = """
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
val healthOk = """{
|
||||
"peers": 16,
|
||||
"isSyncing": false,
|
||||
"shouldHavePeers": true
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
val healthOk2 = """{
|
||||
"peers": 0,
|
||||
"isSyncing": false,
|
||||
"shouldHavePeers": false
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
val healthBadPeers = """{
|
||||
"peers": 0,
|
||||
"isSyncing": false,
|
||||
"shouldHavePeers": true
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
val healthBadSyncing = """{
|
||||
"peers": 16,
|
||||
"isSyncing": true,
|
||||
"shouldHavePeers": true
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
class PolkadotChainSpecificTest {
|
||||
@Test
|
||||
fun parseResponse() {
|
||||
@@ -41,4 +70,32 @@ class PolkadotChainSpecificTest {
|
||||
Assertions.assertThat(result.upstreamId).isEqualTo("1")
|
||||
Assertions.assertThat(result.parentHash).isEqualTo(BlockId.from("0xb52a9b51fb698a891cf378b990b0b6a5743e52fa5175b44a8a6d4e0b2cfd0a53"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun validateHealth() {
|
||||
Assertions.assertThat(PolkadotChainSpecific.validate(healthOk.toByteArray(), 10, "test")).isEqualTo(
|
||||
UpstreamAvailability.OK,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun validateHealthWithoutPeersOk() {
|
||||
Assertions.assertThat(PolkadotChainSpecific.validate(healthOk2.toByteArray(), 10, "test")).isEqualTo(
|
||||
UpstreamAvailability.OK,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun validateHealthWithoutPeers() {
|
||||
Assertions.assertThat(PolkadotChainSpecific.validate(healthBadPeers.toByteArray(), 10, "test")).isEqualTo(
|
||||
UpstreamAvailability.IMMATURE,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun validateHealthSyncing() {
|
||||
Assertions.assertThat(PolkadotChainSpecific.validate(healthBadSyncing.toByteArray(), 10, "test")).isEqualTo(
|
||||
UpstreamAvailability.SYNCING,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.emeraldpay.dshackle.upstream.starknet
|
||||
|
||||
import io.emeraldpay.dshackle.data.BlockId
|
||||
import io.emeraldpay.dshackle.upstream.UpstreamAvailability
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
@@ -19,6 +20,28 @@ val example = """
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
val syncingGood = """
|
||||
{
|
||||
"current_block_hash": "0x2672c3bd6afd698cf979ead19e486cad0c113e1ea7c55467a4c514128b3fe2c",
|
||||
"current_block_num": 426006,
|
||||
"highest_block_hash": "0x2672c3bd6afd698cf979ead19e486cad0c113e1ea7c55467a4c514128b3fe2c",
|
||||
"highest_block_num": 426006,
|
||||
"starting_block_hash": "0x43734ae66b4f11afa254d0ac5e8f3bc599638c8c92ca97f82e680c4a012005a",
|
||||
"starting_block_num": 397751
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
val syncingBad = """
|
||||
{
|
||||
"current_block_hash": "0x2672c3bd6afd698cf979ead19e486cad0c113e1ea7c55467a4c514128b3fe2c",
|
||||
"current_block_num": 426006,
|
||||
"highest_block_hash": "0x2672c3bd6afd698cf979ead19e486cad0c113e1ea7c55467a4c514128b3fe2c",
|
||||
"highest_block_num": 526006,
|
||||
"starting_block_hash": "0x43734ae66b4f11afa254d0ac5e8f3bc599638c8c92ca97f82e680c4a012005a",
|
||||
"starting_block_num": 397751
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
class StarknetChainSpecificTest {
|
||||
@Test
|
||||
fun parseResponse() {
|
||||
@@ -29,4 +52,14 @@ class StarknetChainSpecificTest {
|
||||
Assertions.assertThat(result.upstreamId).isEqualTo("1")
|
||||
Assertions.assertThat(result.parentHash).isEqualTo(BlockId.from("07cc1e178c848b0bdfa047a414d9a8bee4f6cb76f25f312f2d42e058ea91d78b"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun validateOk() {
|
||||
Assertions.assertThat(StarknetChainSpecific.validate(syncingGood.toByteArray(), 10, "test")).isEqualTo(UpstreamAvailability.OK)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun validateSyncing() {
|
||||
Assertions.assertThat(StarknetChainSpecific.validate(syncingBad.toByteArray(), 10, "test")).isEqualTo(UpstreamAvailability.SYNCING)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user