From 7eb6f932bc61026b7720df28f1ba3b78e379bcbf Mon Sep 17 00:00:00 2001 From: Igor Artamonov Date: Tue, 16 Mar 2021 17:12:03 -0400 Subject: [PATCH] solution: make sure eth_call works with block ref and error response --- testing/README.adoc | 41 +++++++++++++++++++ .../groovy/testing/TestcaseHandler.groovy | 5 +++ .../testing/trial/proxy/GivesErrorSpec.groovy | 17 ++++++++ 3 files changed, 63 insertions(+) create mode 100644 testing/README.adoc diff --git a/testing/README.adoc b/testing/README.adoc new file mode 100644 index 000000000..e92380f2b --- /dev/null +++ b/testing/README.adoc @@ -0,0 +1,41 @@ += Dshackle Integration Testing + +Test for a correct work using a simulation of different upstream behaviours and checking the Dshackle against it. + +.Modules: +- `dshackle` - Dshackle config used for testing environment +- `simple-upstream` - upstream simulator with predefines responses +- `trial` - actual tests + +== How to run + +NOTE: Run commands in project's root dir + +=== Run upstream emulator + +[source,bash] +---- +cd testing/simple-upstream && ./gradlew run +---- + +=== Run Dshackle + +[source,bash] +---- +./gradlew run --args="--configPath=./testing/dshackle/dshackle.yaml" +---- + +or, if you want to make sure you compile and use version with your latest changes (usually unnecessary, but still): + +[source,bash] +---- +./gradlew clean compileKotlin run --args="--configPath=./testing/dshackle/dshackle.yaml" +---- + +=== Run tests + +[source,bash] +---- +cd testing/trial && ./gradlew check +---- + diff --git a/testing/simple-upstream/src/main/groovy/testing/TestcaseHandler.groovy b/testing/simple-upstream/src/main/groovy/testing/TestcaseHandler.groovy index 4f5630528..2c60ebe1c 100644 --- a/testing/simple-upstream/src/main/groovy/testing/TestcaseHandler.groovy +++ b/testing/simple-upstream/src/main/groovy/testing/TestcaseHandler.groovy @@ -29,6 +29,11 @@ class TestcaseHandler implements CallHandler { && params[0].toLowerCase() == "0xd949bc0fe1a5d16f4522bc47933554dcc4ada0493ff71ee1973b2410257af9fe".toLowerCase()) { return resourceResponse.respondWith("trace-0xd949bc.json") } + // https://github.com/emeraldpay/dshackle/issues/67 + if (method == "eth_call" + && params[0].to?.toLowerCase() == "0xdAC17F958D2ee523a2206206994597C13D831ec7".toLowerCase()) { + return Result.error(-32000, "invalid opcode: opcode 0xfe not defined") + } return null } } diff --git a/testing/trial/src/test/groovy/io/emeraldpay/dshackle/testing/trial/proxy/GivesErrorSpec.groovy b/testing/trial/src/test/groovy/io/emeraldpay/dshackle/testing/trial/proxy/GivesErrorSpec.groovy index 88a56ea72..e5733ee5a 100644 --- a/testing/trial/src/test/groovy/io/emeraldpay/dshackle/testing/trial/proxy/GivesErrorSpec.groovy +++ b/testing/trial/src/test/groovy/io/emeraldpay/dshackle/testing/trial/proxy/GivesErrorSpec.groovy @@ -34,4 +34,21 @@ class GivesErrorSpec extends Specification { } } + def "Dispatch error from upstream when block is specified"() { + // issue #67 + when: + def call = [ + to : "0xdAC17F958D2ee523a2206206994597C13D831ec7", + from: "0xEF65ffB384c99a00403EAa22115323a555700D79", + data: "0xa9059cbb0000000000000000000000003f5ce5fbfe3e9af3971dd833d26ba9b5c936f0be000000000000000000000000000000000000000000000000000000004856fb60" + ] + def act = client.execute("eth_call", [call, "0x100000"]) + then: + act.result == null + act.error != null + with(act.error) { + code == -32000 + message == "invalid opcode: opcode 0xfe not defined" + } + } }