Short nodeId (#541)

This commit is contained in:
KirillPamPam
2024-08-06 13:46:17 +04:00
committed by GitHub
parent 642e3851f8
commit 0f143c905e
20 changed files with 108 additions and 54 deletions

View File

@@ -581,7 +581,7 @@ class NativeCallSpec extends Specification {
setup:
def nativeCall = nativeCall()
def ctx = new NativeCall.ValidCallContext(1, null, Stub(Multistream), new Selector.UpstreamFilter(Selector.empty), new AlwaysQuorum(),
new NativeCall.ParsedCallDetails("eth_getFilterUpdates", new ListParams("0xabcd")),
new NativeCall.ParsedCallDetails("eth_getFilterUpdates", new ListParams("0xabcdcd")),
new NativeCall.WithFilterIdDecorator(), new NativeCall.NoneResultDecorator(), null, false, "reqId", 1)
when:
def act = nativeCall.parseParams(ctx)
@@ -609,7 +609,7 @@ class NativeCallSpec extends Specification {
def nativeCall = nativeCall(multistreamHolder)
nativeCall.requestReaderFactory = Mock(RequestReaderFactory) {
1 * create(_) >> Mock(RequestReader) {
1 * read(_) >> Mono.just(new RequestReader.Result("\"0xab\"".bytes, null, 1, List.of(new Upstream.UpstreamSettingsData((byte) 255, "", "")), null))
1 * read(_) >> Mono.just(new RequestReader.Result("\"0xab\"".bytes, null, 1, List.of(new Upstream.UpstreamSettingsData((short) 65535, "", "")), null))
}
}
def call = new NativeCall.ValidCallContext(1, 10, multistream, new Selector.UpstreamFilter(Selector.empty), quorum,
@@ -620,7 +620,7 @@ class NativeCallSpec extends Specification {
def resp = nativeCall.executeOnRemote(call).block(Duration.ofSeconds(1))
def act = objectMapper.readValue(resp.result, Object)
then:
act == "0xabff"
act == "0xabffff"
resp.nonce == 10
}
@@ -653,7 +653,7 @@ class NativeCallSpec extends Specification {
def resp = nativeCall.executeOnRemote(call).block(Duration.ofSeconds(1))
def act = objectMapper.readValue(resp.result, Object)
then:
act == "0xab01"
act == "0xab0001"
resp.nonce == 10
}

View File

@@ -194,12 +194,12 @@ class EthereumCallSelectorSpec extends Specification {
expect:
callSelector.getMatcher("eth_getFilterChanges", param, head, true).block()
== new Selector.SameNodeMatcher((byte)hash)
== new Selector.SameNodeMatcher((short)hash)
where:
param | hash
'["0xff09"]' | 9
'["0xff"]' | 255
'["0x0009"]' | 9
'["0x00ff"]' | 255
'[""]' | 0
'["0x0"]' | 0
}

View File

@@ -0,0 +1,42 @@
package io.emeraldpay.dshackle.startup.configure
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.MethodSource
class UpstreamCreatorTest {
@ParameterizedTest
@MethodSource("data")
fun `test getHash`(
inputHash: Int?,
obj: Any,
answer: Short,
) {
val hash = UpstreamCreator.getHash(inputHash, obj, hashes)
assertThat(hash).isEqualTo(answer)
println(hashes)
}
companion object {
private val hashes = HashSet<Short>()
@JvmStatic
fun data(): List<Arguments> =
listOf(
Arguments.of(49, 1, 49.toShort()),
Arguments.of(4000, 1, 4000.toShort()),
Arguments.of(24000, 1, 24000.toShort()),
Arguments.of(null, 49, (-49).toShort()),
Arguments.of(null, 49, (32718).toShort()),
Arguments.of(null, 49, (-32719).toShort()),
Arguments.of(null, 49, (-32768).toShort()),
Arguments.of(null, 49, (-32767).toShort()),
Arguments.of(null, 32718, (-32718).toShort()),
Arguments.of(null, 32718, (-50).toShort()),
)
}
}

View File

@@ -22,7 +22,7 @@ import reactor.core.scheduler.Schedulers
class GenericGrpcUpstreamTest {
private val parentId = "testParent"
private val hash: Byte = 0x01
private val hash: Short = 0x01
private val role = UpstreamsConfig.UpstreamRole.PRIMARY
private val headSink = Sinks.many().multicast().directBestEffort<BlockchainOuterClass.ChainHead>()
private val remote =

View File

@@ -26,7 +26,7 @@ upstreams:
ws:
url: "ws://localhost:9546"
- id: invalid_node_id
node-id: 256
node-id: 100000
chain: ethereum
connection:
grpc: