Remove JSON wrapper from error in JSON RPC provider

This commit is contained in:
Mark Spanbroek 2022-09-20 12:18:01 +02:00 committed by markspanbroek
parent cac6026b34
commit f545169331
3 changed files with 11 additions and 11 deletions

View File

@ -28,7 +28,12 @@ type
JsonRpcProviderError* = object of EthersError
SubscriptionHandler = proc(id, arguments: JsonNode): Future[void] {.gcsafe, upraises:[].}
template raiseProviderError(message: string) =
proc raiseProviderError(message: string) {.upraises: [JsonRpcProviderError].} =
var message = message
try:
message = parseJson(message){"message"}.getStr
except Exception:
discard
raise newException(JsonRpcProviderError, message)
template convertError(body) =

View File

@ -4,8 +4,7 @@ import pkg/ethers
proc revertReason*(e: ref JsonRpcProviderError): string =
try:
let json = parseJson(e.msg)
var msg = json{"message"}.getStr
var msg = e.msg
const revertPrefixes = @[
# hardhat
"Error: VM Exception while processing transaction: reverted with " &
@ -28,7 +27,7 @@ proc reverts*[T](call: Future[T]): Future[bool] {.async.} =
discard await call # TODO test this
return false
except JsonRpcProviderError:
return true # TODO: check that error started with revert prefix
return true
proc reverts*[T](call: Future[T], reason: string): Future[bool] {.async.} =
try:

View File

@ -1,4 +1,3 @@
import std/json
import std/strformat
import pkg/asynctest
import pkg/chronos
@ -9,10 +8,8 @@ import ./hardhat
suite "Testing helpers":
let revertReason = "revert reason"
let rpcResponse = %* {
"message": "Error: VM Exception while processing transaction: " &
fmt"reverted with reason string '{revertReason}'"
}
let rpcResponse = "Error: VM Exception while processing transaction: " &
fmt"reverted with reason string '{revertReason}'"
test "checks that call reverts":
proc call() {.async.} =
@ -58,9 +55,8 @@ suite "Testing helpers":
test "revert handles non-standard revert prefix":
let nonStdMsg = fmt"Provider VM Exception: reverted with {revertReason}"
let nonStdRpcResponse = %* { "message": nonStdMsg }
proc call() {.async.} =
raise newException(JsonRpcProviderError, $nonStdRpcResponse)
raise newException(JsonRpcProviderError, nonStdMsg)
check await call().reverts(nonStdMsg)