Handle custom errors when estimating gas

This commit is contained in:
Mark Spanbroek 2025-04-10 09:47:16 +02:00
parent 55ab97fb7b
commit c4f1d7529c
No known key found for this signature in database
GPG Key ID: FBE3E9548D427C00
2 changed files with 15 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import ../signer
import ./contract
import ./contractcall
import ./transactions
import ./errors
import ./syntax
type ContractGasEstimations[C] = distinct C
@ -42,4 +43,4 @@ func createGasEstimationCall*(procedure: NimNode): NimNode =
result.addAsyncPragma()
result.addUsedPragma()
result.addEstimateCall()
result.addErrorHandling()

View File

@ -97,7 +97,7 @@ suite "Contract custom errors":
expect ErrorWithArguments:
await contract.revertsMultipleErrors(simple = false)
test "handles gas estimation errors":
test "handles gas estimation errors when calling a contract function":
proc revertsTransaction(contract: TestCustomErrors)
{.contract, errors:[ErrorWithArguments].}
@ -109,6 +109,18 @@ suite "Contract custom errors":
check error.arguments.one == 1.u256
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":
proc revertsTransaction(contract: TestCustomErrors)
{.contract, errors:[ErrorWithArguments].}