problem: hardcoded methods are not called

This commit is contained in:
Igor Artamonov
2020-05-14 22:37:46 -04:00
parent bbc21684ae
commit af4aba69e7
4 changed files with 65 additions and 14 deletions

View File

@@ -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"
}

View File

@@ -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"
}
}