Add test to see if hardhat returns reason string (it doesn't)

This commit is contained in:
Eric 2023-09-22 12:05:47 +10:00
parent a6aeb7ec49
commit affaa2e621
No known key found for this signature in database
3 changed files with 28 additions and 7 deletions

View File

@ -261,7 +261,7 @@ proc confirm*(tx: Future[?TransactionResponse],
# TODO: handle TransactionStatus.Invalid?
if receipt.status == TransactionStatus.Failure:
logScope:
transactionHash = receipt.transactionHash
transactionHash = receipt.transactionHash.to0xHex
trace "transaction failed, replaying transaction to get revert reason"

View File

@ -156,14 +156,11 @@ proc replay*(provider: Provider, tx: PastTransaction, blockNumber: UInt256) {.as
method getRevertReason*(
provider: Provider,
receipt: TransactionReceipt
hash: TransactionHash,
blockNumber: UInt256
): Future[?string] {.base, async.} =
if receipt.status != TransactionStatus.Failure:
raiseProviderError "cannot get revert reason, transaction not failed"
without blockNumber =? receipt.blockNumber or
transaction =? await provider.getTransaction(receipt.transactionHash):
without transaction =? await provider.getTransaction(hash):
return none string
try:
@ -173,6 +170,29 @@ method getRevertReason*(
# should contain the revert reason
return some e.msg
method getRevertReason*(
provider: Provider,
receipt: TransactionReceipt
): Future[?string] {.base, async.} =
if receipt.status != TransactionStatus.Failure:
raiseProviderError "cannot get revert reason, transaction not failed"
without blockNumber =? receipt.blockNumber:
return none string
return await provider.getRevertReason(receipt.transactionHash, blockNumber)
# without blockNumber =? receipt.blockNumber or
# transaction =? await provider.getTransaction(receipt.transactionHash):
# return none string
# try:
# await provider.replay(transaction, blockNumber)
# return none string
# except ProviderError as e:
# # should contain the revert reason
# return some e.msg
proc confirm*(tx: TransactionResponse,
confirmations = EthersDefaultConfirmations,
timeout = EthersReceiptTimeoutBlks):

View File

@ -2,6 +2,7 @@ import std/json
import std/options
import pkg/asynctest
import pkg/questionable
import pkg/stew/byteutils
import pkg/stint
import pkg/ethers
import pkg/ethers/erc20