Remove dependency on json-rpc provider for `reverts`

This commit is contained in:
Mark Spanbroek 2022-09-20 13:24:47 +02:00 committed by markspanbroek
parent f545169331
commit c5a40e5f9d
4 changed files with 11 additions and 11 deletions

View File

@ -10,6 +10,7 @@ push: {.upraises: [].}
type
Provider* = ref object of RootObj
ProviderError* = object of EthersError
Subscription* = ref object of RootObj
Filter* = object
address*: Address

View File

@ -25,7 +25,7 @@ type
JsonRpcSigner* = ref object of Signer
provider: JsonRpcProvider
address: ?Address
JsonRpcProviderError* = object of EthersError
JsonRpcProviderError* = object of ProviderError
SubscriptionHandler = proc(id, arguments: JsonNode): Future[void] {.gcsafe, upraises:[].}
proc raiseProviderError(message: string) {.upraises: [JsonRpcProviderError].} =

View File

@ -1,8 +1,7 @@
import std/json
import std/strutils
import pkg/ethers
proc revertReason*(e: ref JsonRpcProviderError): string =
proc revertReason*(e: ref ProviderError): string =
try:
var msg = e.msg
const revertPrefixes = @[
@ -26,7 +25,7 @@ proc reverts*[T](call: Future[T]): Future[bool] {.async.} =
else:
discard await call # TODO test this
return false
except JsonRpcProviderError:
except ProviderError:
return true
proc reverts*[T](call: Future[T], reason: string): Future[bool] {.async.} =
@ -36,5 +35,5 @@ proc reverts*[T](call: Future[T], reason: string): Future[bool] {.async.} =
else:
discard await call # TODO test this
return false
except JsonRpcProviderError as error:
except ProviderError as error:
return reason == error.revertReason

View File

@ -13,13 +13,13 @@ suite "Testing helpers":
test "checks that call reverts":
proc call() {.async.} =
raise newException(JsonRpcProviderError, $rpcResponse)
raise newException(ProviderError, $rpcResponse)
check await call().reverts()
test "checks reason for revert":
proc call() {.async.} =
raise newException(JsonRpcProviderError, $rpcResponse)
raise newException(ProviderError, $rpcResponse)
check await call().reverts(revertReason)
@ -28,14 +28,14 @@ suite "Testing helpers":
check not await call().reverts()
test "reverts only checks JsonRpcProviderErrors":
test "reverts only checks ProviderErrors":
proc call() {.async.} =
raise newException(ContractError, "test")
expect ContractError:
check await call().reverts()
test "reverts with reason only checks JsonRpcProviderErrors":
test "reverts with reason only checks ProviderErrors":
proc call() {.async.} =
raise newException(ContractError, "test")
@ -49,14 +49,14 @@ suite "Testing helpers":
test "reverts is false when the revert reason doesn't match":
proc call() {.async.} =
raise newException(JsonRpcProviderError, "other reason")
raise newException(ProviderError, "other reason")
check not await call().reverts(revertReason)
test "revert handles non-standard revert prefix":
let nonStdMsg = fmt"Provider VM Exception: reverted with {revertReason}"
proc call() {.async.} =
raise newException(JsonRpcProviderError, nonStdMsg)
raise newException(ProviderError, nonStdMsg)
check await call().reverts(nonStdMsg)