mirror of
https://github.com/logos-storage/nim-ethers.git
synced 2026-01-03 22:23:06 +00:00
Handle custom errors when estimating gas
This commit is contained in:
parent
4441050c3d
commit
a29e86bfc8
@ -5,6 +5,7 @@ import ../signer
|
|||||||
import ./contract
|
import ./contract
|
||||||
import ./contractcall
|
import ./contractcall
|
||||||
import ./transactions
|
import ./transactions
|
||||||
|
import ./errors
|
||||||
import ./syntax
|
import ./syntax
|
||||||
|
|
||||||
type ContractGasEstimations[C] = distinct C
|
type ContractGasEstimations[C] = distinct C
|
||||||
@ -42,4 +43,4 @@ func createGasEstimationCall*(procedure: NimNode): NimNode =
|
|||||||
result.addAsyncPragma()
|
result.addAsyncPragma()
|
||||||
result.addUsedPragma()
|
result.addUsedPragma()
|
||||||
result.addEstimateCall()
|
result.addEstimateCall()
|
||||||
|
result.addErrorHandling()
|
||||||
|
|||||||
@ -97,7 +97,7 @@ suite "Contract custom errors":
|
|||||||
expect ErrorWithArguments:
|
expect ErrorWithArguments:
|
||||||
await contract.revertsMultipleErrors(simple = false)
|
await contract.revertsMultipleErrors(simple = false)
|
||||||
|
|
||||||
test "handles gas estimation errors":
|
test "handles gas estimation errors when calling a contract function":
|
||||||
proc revertsTransaction(contract: TestCustomErrors)
|
proc revertsTransaction(contract: TestCustomErrors)
|
||||||
{.contract, errors:[ErrorWithArguments].}
|
{.contract, errors:[ErrorWithArguments].}
|
||||||
|
|
||||||
@ -109,6 +109,18 @@ suite "Contract custom errors":
|
|||||||
check error.arguments.one == 1.u256
|
check error.arguments.one == 1.u256
|
||||||
check error.arguments.two == true
|
check error.arguments.two == true
|
||||||
|
|
||||||
|
test "handles errors when only doing gas estimation":
|
||||||
|
proc revertsTransaction(contract: TestCustomErrors)
|
||||||
|
{.contract, errors:[ErrorWithArguments], used.}
|
||||||
|
|
||||||
|
let contract = contract.connect(provider.getSigner())
|
||||||
|
try:
|
||||||
|
discard await contract.estimateGas.revertsTransaction()
|
||||||
|
fail()
|
||||||
|
except ErrorWithArguments as error:
|
||||||
|
check error.arguments.one == 1.u256
|
||||||
|
check error.arguments.two == true
|
||||||
|
|
||||||
test "handles transaction submission errors":
|
test "handles transaction submission errors":
|
||||||
proc revertsTransaction(contract: TestCustomErrors)
|
proc revertsTransaction(contract: TestCustomErrors)
|
||||||
{.contract, errors:[ErrorWithArguments].}
|
{.contract, errors:[ErrorWithArguments].}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user