mirror of
https://github.com/logos-storage/nim-ethers.git
synced 2026-01-10 01:23:05 +00:00
remove nonce in error, clean up testing
This commit is contained in:
parent
74ea3fbb99
commit
512b29bf72
@ -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,
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import std/strutils
|
||||
import ./contract
|
||||
import ./provider
|
||||
import ./signer
|
||||
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user