From 6d6777e8c39d28b611f42d36bf0760a187010bf6 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Wed, 20 Mar 2024 11:40:59 +0100 Subject: [PATCH] test custom errors with struct arguments --- testmodule/testCustomErrors.nim | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/testmodule/testCustomErrors.nim b/testmodule/testCustomErrors.nim index 2104622..f2fb2cf 100644 --- a/testmodule/testCustomErrors.nim +++ b/testmodule/testCustomErrors.nim @@ -10,6 +10,14 @@ suite "Contract custom errors": SimpleError = object of SolidityError ErrorWithArguments = object of SolidityError arguments: tuple[one: UInt256, two: bool] + ErrorWithStaticStruct = object of SolidityError + arguments: tuple[one: Static, two: Static] + ErrorWithDynamicStruct = object of SolidityError + arguments: tuple[one: Dynamic, two: Dynamic] + ErrorWithDynamicAndStaticStruct = object of SolidityError + arguments: tuple[one: Dynamic, two: Static] + Static = (UInt256, UInt256) + Dynamic = (string, UInt256) var contract: TestCustomErrors var provider: JsonRpcProvider @@ -43,3 +51,36 @@ suite "Contract custom errors": except ErrorWithArguments as error: check error.arguments.one == 1 check error.arguments.two == true + + test "handles error with static struct arguments": + proc revertsErrorWithStaticStruct(contract: TestCustomErrors) + {.contract, pure, errors:[ErrorWithStaticStruct].} + + try: + await contract.revertsErrorWithStaticStruct() + fail() + except ErrorWithStaticStruct as error: + check error.arguments.one == (1.u256, 2.u256) + check error.arguments.two == (3.u256, 4.u256) + + test "handles error with dynamic struct arguments": + proc revertsErrorWithDynamicStruct(contract: TestCustomErrors) + {.contract, pure, errors:[ErrorWithDynamicStruct].} + + try: + await contract.revertsErrorWithDynamicStruct() + fail() + except ErrorWithDynamicStruct as error: + check error.arguments.one == ("1", 2.u256) + check error.arguments.two == ("3", 4.u256) + + test "handles error with dynamic and static struct arguments": + proc revertsErrorWithDynamicAndStaticStruct(contract: TestCustomErrors) + {.contract, pure, errors:[ErrorWithDynamicAndStaticStruct].} + + try: + await contract.revertsErrorWithDynamicAndStaticStruct() + fail() + except ErrorWithDynamicAndStaticStruct as error: + check error.arguments.one == ("1", 2.u256) + check error.arguments.two == (3.u256, 4.u256)