problem: hardcoded methods are not called
This commit is contained in:
@@ -40,7 +40,7 @@ class AggregatedCallMethods(
|
||||
*/
|
||||
override fun getQuorumFor(method: String): CallQuorum {
|
||||
return delegates.find {
|
||||
it.isAllowed(method)
|
||||
it.isAllowed(method) || it.isHardcoded(method)
|
||||
}?.getQuorumFor(method) ?: throw IllegalStateException("No quorum for $method")
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ class AggregatedCallMethods(
|
||||
* @return true if there is at least one delegate that allows the method and it's hardcoded on that delegate
|
||||
*/
|
||||
override fun isHardcoded(method: String): Boolean {
|
||||
return delegates.any { it.isAllowed(method) && it.isHardcoded(method) }
|
||||
return delegates.any { it.isHardcoded(method) }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,7 +70,7 @@ class AggregatedCallMethods(
|
||||
*/
|
||||
override fun executeHardcoded(method: String): ByteArray {
|
||||
return delegates.find {
|
||||
it.isAllowed(method) && it.isHardcoded(method)
|
||||
it.isHardcoded(method)
|
||||
}?.executeHardcoded(method) ?: throw IllegalStateException("No hardcoded for $method")
|
||||
}
|
||||
}
|
||||
@@ -47,18 +47,18 @@ class NativeCallRouter(
|
||||
)
|
||||
|
||||
override fun read(key: JsonRpcRequest): Mono<JsonRpcResponse> {
|
||||
if (!methods.isAllowed(key.method)) {
|
||||
return Mono.error(RpcException(RpcResponseError.CODE_METHOD_NOT_EXIST, "Unsupported method"))
|
||||
}
|
||||
if (methods.isHardcoded(key.method)) {
|
||||
return Mono.just(methods.executeHardcoded(key.method))
|
||||
.map { JsonRpcResponse(it, null) }
|
||||
}
|
||||
if (!methods.isAllowed(key.method)) {
|
||||
return Mono.error(RpcException(RpcResponseError.CODE_METHOD_NOT_EXIST, "Unsupported method"))
|
||||
}
|
||||
val common = commonRequests(key)
|
||||
if (common != null) {
|
||||
return common.map { JsonRpcResponse(it, null) }
|
||||
}
|
||||
return directApi.read(key)
|
||||
return Mono.empty()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -84,16 +84,34 @@ class AggregatedCallMethodsSpec extends Specification {
|
||||
setup:
|
||||
def delegate1 = Mock(CallMethods) {
|
||||
_ * getSupportedMethods() >> ["eth_no_test", "foo_bar"]
|
||||
1 * isAllowed("eth_test") >> false
|
||||
1 * isAllowed("eth_no_test") >> true
|
||||
|
||||
1 * isHardcoded("eth_no_test") >> false
|
||||
}
|
||||
def delegate2 = Mock(CallMethods) {
|
||||
_ * getSupportedMethods() >> ["eth_test", "foo_bar"]
|
||||
1 * isAllowed("eth_test") >> true
|
||||
1 * isAllowed("eth_no_test") >> false
|
||||
1 * isHardcoded("eth_test") >> true
|
||||
}
|
||||
def aggregate = new AggregatedCallMethods([delegate1, delegate2])
|
||||
when:
|
||||
def act = aggregate.isHardcoded("eth_test")
|
||||
then:
|
||||
act
|
||||
|
||||
when:
|
||||
act = aggregate.isHardcoded("eth_no_test")
|
||||
then:
|
||||
!act
|
||||
}
|
||||
|
||||
def "Can be hardcoded if not allowed"() {
|
||||
setup:
|
||||
def delegate1 = Mock(CallMethods) {
|
||||
_ * getSupportedMethods() >> ["eth_no_test", "foo_bar"]
|
||||
_ * isAllowed(_) >> false
|
||||
1 * isHardcoded("eth_no_test") >> false
|
||||
}
|
||||
def delegate2 = Mock(CallMethods) {
|
||||
_ * getSupportedMethods() >> ["eth_test", "foo_bar"]
|
||||
_ * isAllowed(_) >> false
|
||||
1 * isHardcoded("eth_test") >> true
|
||||
}
|
||||
def aggregate = new AggregatedCallMethods([delegate1, delegate2])
|
||||
@@ -112,11 +130,10 @@ class AggregatedCallMethodsSpec extends Specification {
|
||||
setup:
|
||||
def delegate1 = Mock(CallMethods) {
|
||||
_ * getSupportedMethods() >> ["eth_no_test", "foo_bar"]
|
||||
1 * isAllowed("eth_test") >> false
|
||||
1 * isHardcoded("eth_test") >> false
|
||||
}
|
||||
def delegate2 = Mock(CallMethods) {
|
||||
_ * getSupportedMethods() >> ["eth_test", "foo_bar"]
|
||||
1 * isAllowed("eth_test") >> true
|
||||
1 * isHardcoded("eth_test") >> true
|
||||
1 * executeHardcoded("eth_test") >> "hello"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package io.emeraldpay.dshackle.upstream.ethereum
|
||||
|
||||
import io.emeraldpay.dshackle.cache.Caches
|
||||
import io.emeraldpay.dshackle.reader.EmptyReader
|
||||
import io.emeraldpay.dshackle.test.TestingCommons
|
||||
import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods
|
||||
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest
|
||||
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse
|
||||
import io.emeraldpay.grpc.Chain
|
||||
import spock.lang.Specification
|
||||
|
||||
import java.time.Duration
|
||||
|
||||
class NativeCallRouterSpec extends Specification {
|
||||
|
||||
def "Calls hardcoded"() {
|
||||
setup:
|
||||
def methods = new DefaultEthereumMethods(TestingCommons.objectMapper(), Chain.ETHEREUM)
|
||||
def router = new NativeCallRouter(
|
||||
TestingCommons.objectMapper(),
|
||||
new EthereumReader(
|
||||
TestingCommons.aggregatedUpstream(TestingCommons.api()),
|
||||
Caches.default(TestingCommons.objectMapper()),
|
||||
TestingCommons.objectMapper()
|
||||
),
|
||||
new EmptyReader<JsonRpcRequest, JsonRpcResponse>(),
|
||||
methods
|
||||
)
|
||||
when:
|
||||
def act = router.read(new JsonRpcRequest("eth_coinbase", [])).block(Duration.ofSeconds(1))
|
||||
then:
|
||||
act.resultAsProcessedString == "0x0000000000000000000000000000000000000000"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user