mirror of
https://github.com/status-im/nim-ethers.git
synced 2025-01-12 00:24:54 +00:00
Remove JSON wrapper from error in JSON RPC provider
This commit is contained in:
parent
cac6026b34
commit
f545169331
@ -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) =
|
||||
|
@ -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:
|
||||
|
@ -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: " &
|
||||
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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user