solana support (#339)

This commit is contained in:
a10zn8
2023-11-13 17:01:58 +03:00
committed by GitHub
parent e5f844b091
commit 2e80da58df
39 changed files with 513 additions and 249 deletions

View File

@@ -41,11 +41,11 @@ class NativeSubscribeSpec extends Specification {
def subscribe = Mock(EthereumEgressSubscription) {
1 * it.subscribe("newHeads", null, _ as Selector.AnyLabelMatcher) >> Flux.just("{}")
1 * it.getAvailableTopics() >> ["newHeads"]
}
def up = Mock(GenericMultistream) {
1 * it.tryProxySubscribe(_ as Selector.AnyLabelMatcher, call) >> null
1 * it.getEgressSubscription() >> subscribe
1 * it.getSubscriptionTopics() >> ["newHeads"]
2 * it.getEgressSubscription() >> subscribe
}
def nativeSubscribe = new NativeSubscribe(new MultistreamHolderMock(Chain.ETHEREUM__MAINNET, up), signer)
@@ -81,11 +81,11 @@ class NativeSubscribeSpec extends Specification {
println("ok: $ok")
ok
}, _ as Selector.AnyLabelMatcher) >> Flux.just("{}")
1 * it.getAvailableTopics() >> ["logs"]
}
def up = Mock(GenericMultistream) {
1 * it.tryProxySubscribe(_ as Selector.AnyLabelMatcher, call) >> null
1 * it.getEgressSubscription() >> subscribe
1 * it.getSubscriptionTopics() >> ["logs"]
2 * it.getEgressSubscription() >> subscribe
}
def nativeSubscribe = new NativeSubscribe(new MultistreamHolderMock(Chain.ETHEREUM__MAINNET, up), signer)
@@ -106,10 +106,14 @@ class NativeSubscribeSpec extends Specification {
.setChainValue(Chain.ETHEREUM__MAINNET.id)
.setMethod("newHeads")
.build()
def subscribe = Mock(EthereumEgressSubscription) {
1 * it.getAvailableTopics() >> ["newHeads"]
}
def up = Mock(GenericMultistream) {
1 * it.tryProxySubscribe(_ as Selector.AnyLabelMatcher, call) >> Flux.just("{}")
0 * it.getEgressSubscription()
1 * it.getSubscriptionTopics() >> ["newHeads"]
1 * it.getEgressSubscription() >> subscribe
}
def nativeSubscribe = new NativeSubscribe(new MultistreamHolderMock(Chain.ETHEREUM__MAINNET, up), signer)

View File

@@ -74,7 +74,6 @@ class GenericUpstreamMock extends GenericUpstream {
new ConnectorFactoryMock(api, new EthereumHeadMock()),
io.emeraldpay.dshackle.upstream.starknet.StarknetChainSpecific.INSTANCE.&validator,
io.emeraldpay.dshackle.upstream.starknet.StarknetChainSpecific.INSTANCE.&labelDetector,
io.emeraldpay.dshackle.upstream.starknet.StarknetChainSpecific.INSTANCE.&subscriptionTopics,
)
this.ethereumHeadMock = this.getHead() as EthereumHeadMock
setLag(0)

View File

@@ -79,7 +79,6 @@ class FilteredApisSpec extends Specification {
connectorFactory,
cs.&validator,
cs.&labelDetector,
cs.&subscriptionTopics,
)
}
def matcher = new Selector.LabelMatcher("test", ["foo"])

View File

@@ -0,0 +1,35 @@
package io.emeraldpay.dshackle.upstream.solana
import io.emeraldpay.dshackle.data.BlockId
import org.assertj.core.api.Assertions
import org.junit.jupiter.api.Test
val example = """{
"context": {
"slot": 112301554
},
"value": {
"slot": 112301554,
"block": {
"previousBlockhash": "GJp125YAN4ufCSUvZJVdCyWQJ7RPWMmwxoyUQySydZA",
"blockhash": "6ojMHjctdqfB55JDpEpqfHnP96fiaHEcvzEQ2NNcxzHP",
"parentSlot": 112301553,
"blockTime": 1639926816,
"blockHeight": 101210751
},
"err": null
}
}
""".trimIndent()
class SolanaChainSpecificTest {
@Test
fun parseBlock() {
val result = SolanaChainSpecific.parseHeader(example.toByteArray(), "1")
Assertions.assertThat(result.height).isEqualTo(101210751)
Assertions.assertThat(result.hash).isEqualTo(BlockId.fromBase64("6ojMHjctdqfB55JDpEpqfHnP96fiaHEcvzEQ2NNcxzHP"))
Assertions.assertThat(result.upstreamId).isEqualTo("1")
Assertions.assertThat(result.parentHash).isEqualTo(BlockId.fromBase64("GJp125YAN4ufCSUvZJVdCyWQJ7RPWMmwxoyUQySydZA"))
}
}