Remove dependency on json-rpc provider for `reverts`
This commit is contained in:
parent
f545169331
commit
c5a40e5f9d
|
@ -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
|
||||
|
|
|
@ -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].} =
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue