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
|
JsonRpcProviderError* = object of EthersError
|
||||||
SubscriptionHandler = proc(id, arguments: JsonNode): Future[void] {.gcsafe, upraises:[].}
|
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)
|
raise newException(JsonRpcProviderError, message)
|
||||||
|
|
||||||
template convertError(body) =
|
template convertError(body) =
|
||||||
|
@ -4,8 +4,7 @@ import pkg/ethers
|
|||||||
|
|
||||||
proc revertReason*(e: ref JsonRpcProviderError): string =
|
proc revertReason*(e: ref JsonRpcProviderError): string =
|
||||||
try:
|
try:
|
||||||
let json = parseJson(e.msg)
|
var msg = e.msg
|
||||||
var msg = json{"message"}.getStr
|
|
||||||
const revertPrefixes = @[
|
const revertPrefixes = @[
|
||||||
# hardhat
|
# hardhat
|
||||||
"Error: VM Exception while processing transaction: reverted with " &
|
"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
|
discard await call # TODO test this
|
||||||
return false
|
return false
|
||||||
except JsonRpcProviderError:
|
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.} =
|
proc reverts*[T](call: Future[T], reason: string): Future[bool] {.async.} =
|
||||||
try:
|
try:
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import std/json
|
|
||||||
import std/strformat
|
import std/strformat
|
||||||
import pkg/asynctest
|
import pkg/asynctest
|
||||||
import pkg/chronos
|
import pkg/chronos
|
||||||
@ -9,10 +8,8 @@ import ./hardhat
|
|||||||
suite "Testing helpers":
|
suite "Testing helpers":
|
||||||
|
|
||||||
let revertReason = "revert reason"
|
let revertReason = "revert reason"
|
||||||
let rpcResponse = %* {
|
let rpcResponse = "Error: VM Exception while processing transaction: " &
|
||||||
"message": "Error: VM Exception while processing transaction: " &
|
fmt"reverted with reason string '{revertReason}'"
|
||||||
fmt"reverted with reason string '{revertReason}'"
|
|
||||||
}
|
|
||||||
|
|
||||||
test "checks that call reverts":
|
test "checks that call reverts":
|
||||||
proc call() {.async.} =
|
proc call() {.async.} =
|
||||||
@ -58,9 +55,8 @@ suite "Testing helpers":
|
|||||||
|
|
||||||
test "revert handles non-standard revert prefix":
|
test "revert handles non-standard revert prefix":
|
||||||
let nonStdMsg = fmt"Provider VM Exception: reverted with {revertReason}"
|
let nonStdMsg = fmt"Provider VM Exception: reverted with {revertReason}"
|
||||||
let nonStdRpcResponse = %* { "message": nonStdMsg }
|
|
||||||
proc call() {.async.} =
|
proc call() {.async.} =
|
||||||
raise newException(JsonRpcProviderError, $nonStdRpcResponse)
|
raise newException(JsonRpcProviderError, nonStdMsg)
|
||||||
|
|
||||||
check await call().reverts(nonStdMsg)
|
check await call().reverts(nonStdMsg)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user