mirror of
https://github.com/logos-storage/nim-ethers.git
synced 2026-02-27 09:03:06 +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 =
|
func address*(contract: Contract): Address =
|
||||||
contract.address
|
contract.address
|
||||||
|
|
||||||
template raiseContractError(message: string) =
|
template raiseContractError(message: string, parent: ref Exception = nil) =
|
||||||
raise newException(ContractError, message)
|
raise newException(ContractError, message, parent)
|
||||||
|
|
||||||
proc createTransaction(contract: Contract,
|
proc createTransaction(contract: Contract,
|
||||||
function: string,
|
function: string,
|
||||||
@ -250,6 +250,8 @@ proc confirm*(tx: Future[?TransactionResponse],
|
|||||||
## `await token.connect(signer0)
|
## `await token.connect(signer0)
|
||||||
## .mint(accounts[1], 100.u256)
|
## .mint(accounts[1], 100.u256)
|
||||||
## .confirm(3)`
|
## .confirm(3)`
|
||||||
|
## Will raise ContractError with revert reason if TransactionReceipt.Status
|
||||||
|
## is Failed
|
||||||
without response =? (await tx):
|
without response =? (await tx):
|
||||||
raise newException(
|
raise newException(
|
||||||
EthersError,
|
EthersError,
|
||||||
|
|||||||
@ -195,7 +195,7 @@ method getRevertReason*(
|
|||||||
): Future[?string] {.base, async.} =
|
): Future[?string] {.base, async.} =
|
||||||
|
|
||||||
if receipt.status != TransactionStatus.Failure:
|
if receipt.status != TransactionStatus.Failure:
|
||||||
raiseProviderError "cannot get revert reason, transaction not failed"
|
return none string
|
||||||
|
|
||||||
without blockNumber =? receipt.blockNumber:
|
without blockNumber =? receipt.blockNumber:
|
||||||
return none string
|
return none string
|
||||||
|
|||||||
@ -30,7 +30,6 @@ type
|
|||||||
provider: JsonRpcProvider
|
provider: JsonRpcProvider
|
||||||
address: ?Address
|
address: ?Address
|
||||||
JsonRpcProviderError* = object of ProviderError
|
JsonRpcProviderError* = object of ProviderError
|
||||||
nonce*: ?UInt256
|
|
||||||
JsonRpcSubscription* = ref object of Subscription
|
JsonRpcSubscription* = ref object of Subscription
|
||||||
subscriptions: JsonRpcSubscriptions
|
subscriptions: JsonRpcSubscriptions
|
||||||
id: JsonNode
|
id: JsonNode
|
||||||
@ -41,21 +40,7 @@ proc raiseJsonRpcProviderError(message: string) {.upraises: [JsonRpcProviderErro
|
|||||||
message = parseJson(message){"message"}.getStr
|
message = parseJson(message){"message"}.getStr
|
||||||
except Exception:
|
except Exception:
|
||||||
discard
|
discard
|
||||||
let ex = newException(JsonRpcProviderError, message)
|
raise 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)
|
|
||||||
|
|
||||||
template convertError(body) =
|
template convertError(body) =
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import std/strutils
|
import std/strutils
|
||||||
|
import ./contract
|
||||||
import ./provider
|
import ./provider
|
||||||
import ./signer
|
import ./signer
|
||||||
|
|
||||||
|
|||||||
@ -99,20 +99,3 @@ for url in ["ws://localhost:8545", "http://localhost:8545"]:
|
|||||||
discard await provider.subscribe(proc(_: Block) = discard)
|
discard await provider.subscribe(proc(_: Block) = discard)
|
||||||
expect JsonRpcProviderError:
|
expect JsonRpcProviderError:
|
||||||
discard await provider.getSigner().sendTransaction(Transaction.example)
|
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