From 512b29bf725c87543390fe9deff3dbb5f3f480bd Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Wed, 18 Oct 2023 14:36:39 +1100 Subject: [PATCH] remove nonce in error, clean up testing --- ethers/contract.nim | 6 ++++-- ethers/provider.nim | 2 +- ethers/providers/jsonrpc.nim | 17 +---------------- ethers/testing.nim | 1 + .../providers/jsonrpc/testJsonRpcProvider.nim | 17 ----------------- 5 files changed, 7 insertions(+), 36 deletions(-) diff --git a/ethers/contract.nim b/ethers/contract.nim index e4fb046..fdb5744 100644 --- a/ethers/contract.nim +++ b/ethers/contract.nim @@ -58,8 +58,8 @@ func signer*(contract: Contract): ?Signer = func address*(contract: Contract): Address = contract.address -template raiseContractError(message: string) = - raise newException(ContractError, message) +template raiseContractError(message: string, parent: ref Exception = nil) = + raise newException(ContractError, message, parent) proc createTransaction(contract: Contract, function: string, @@ -250,6 +250,8 @@ proc confirm*(tx: Future[?TransactionResponse], ## `await token.connect(signer0) ## .mint(accounts[1], 100.u256) ## .confirm(3)` + ## Will raise ContractError with revert reason if TransactionReceipt.Status + ## is Failed without response =? (await tx): raise newException( EthersError, diff --git a/ethers/provider.nim b/ethers/provider.nim index 98fd973..25ba3c7 100644 --- a/ethers/provider.nim +++ b/ethers/provider.nim @@ -195,7 +195,7 @@ method getRevertReason*( ): Future[?string] {.base, async.} = if receipt.status != TransactionStatus.Failure: - raiseProviderError "cannot get revert reason, transaction not failed" + return none string without blockNumber =? receipt.blockNumber: return none string diff --git a/ethers/providers/jsonrpc.nim b/ethers/providers/jsonrpc.nim index 4b76ebb..8050e49 100644 --- a/ethers/providers/jsonrpc.nim +++ b/ethers/providers/jsonrpc.nim @@ -30,7 +30,6 @@ type provider: JsonRpcProvider address: ?Address JsonRpcProviderError* = object of ProviderError - nonce*: ?UInt256 JsonRpcSubscription* = ref object of Subscription subscriptions: JsonRpcSubscriptions id: JsonNode @@ -41,21 +40,7 @@ proc raiseJsonRpcProviderError(message: string) {.upraises: [JsonRpcProviderErro message = parseJson(message){"message"}.getStr except Exception: discard - let ex = newException(JsonRpcProviderError, message) - ex[].nonce = nonce - raise ex - -template convertError(nonce = none UInt256, body) = - try: - body - except JsonRpcError as error: - trace "jsonrpc error", error = error.msg - raiseProviderError(error.msg, nonce) - # Catch all ValueErrors for now, at least until JsonRpcError is actually - # raised. PR created: https://github.com/status-im/nim-json-rpc/pull/151 - except ValueError as error: - trace "jsonrpc error (from rpc client)", error = error.msg - raiseProviderError(error.msg, nonce) + raise newException(JsonRpcProviderError, message) template convertError(body) = try: diff --git a/ethers/testing.nim b/ethers/testing.nim index 8162ab6..c380461 100644 --- a/ethers/testing.nim +++ b/ethers/testing.nim @@ -1,4 +1,5 @@ import std/strutils +import ./contract import ./provider import ./signer diff --git a/testmodule/providers/jsonrpc/testJsonRpcProvider.nim b/testmodule/providers/jsonrpc/testJsonRpcProvider.nim index 1065e32..ee00acc 100644 --- a/testmodule/providers/jsonrpc/testJsonRpcProvider.nim +++ b/testmodule/providers/jsonrpc/testJsonRpcProvider.nim @@ -99,20 +99,3 @@ for url in ["ws://localhost:8545", "http://localhost:8545"]: discard await provider.subscribe(proc(_: Block) = discard) expect JsonRpcProviderError: discard await provider.getSigner().sendTransaction(Transaction.example) - - test "JsonRpcProviderError contains nonce": - let signer = provider.getSigner() - var transaction = Transaction.example - var populated: Transaction - try: - populated = await signer.populateTransaction(transaction) - populated.chainId = some 0.u256 - let confirming = signer.sendTransaction(populated).confirm(1) - await sleepAsync(100.millis) # wait for tx to be mined - await provider.mineBlocks(1) - discard await confirming - except JsonRpcProviderError as e: - check e.nonce.isSome - check e.nonce == populated.nonce - return - fail()