problem: net_version response is a plain number, should be string encoded

This commit is contained in:
Igor Artamonov
2020-08-23 21:41:21 -04:00
parent fdd6d6afac
commit f7e1a9289b
2 changed files with 8 additions and 6 deletions

View File

@@ -108,23 +108,25 @@ class DefaultEthereumMethods(
} }
override fun executeHardcoded(method: String): ByteArray { override fun executeHardcoded(method: String): ByteArray {
// note that the value is in json representation, i.e. if it's a string it should be with quotes,
// that's why "\"0x0\"", "\"1\"", etc. But just "true" for a boolean, or "[]" for array.
val json = when (method) { val json = when (method) {
"net_version" -> { "net_version" -> {
when { when {
Chain.ETHEREUM == chain -> { Chain.ETHEREUM == chain -> {
"1" "\"1\""
} }
Chain.ETHEREUM_CLASSIC == chain -> { Chain.ETHEREUM_CLASSIC == chain -> {
"1" "\"1\""
} }
Chain.TESTNET_MORDEN == chain -> { Chain.TESTNET_MORDEN == chain -> {
"2" "\"2\""
} }
Chain.TESTNET_KOVAN == chain -> { Chain.TESTNET_KOVAN == chain -> {
"42" "\"42\""
} }
Chain.TESTNET_GOERLI == chain -> { Chain.TESTNET_GOERLI == chain -> {
"5" "\"5\""
} }
else -> throw RpcException(-32602, "Invalid chain") else -> throw RpcException(-32602, "Invalid chain")
} }

View File

@@ -19,7 +19,7 @@ class HardcodedCallsSpec extends Specification {
when: when:
def act = client.execute("net_version", []) def act = client.execute("net_version", [])
then: then:
act.result == 1 act.result == "1"
act.error == null act.error == null
} }