Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/EVM/ABI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,11 @@ basicType v =
, P.string "bytes" $> AbiBytesDynamicType
, P.string "tuple" $> AbiTupleType v
, P.string "function" $> AbiFunctionType

-- Fallback for user-defined types (e.g. enums like "Order.OrderType").
-- Solidity libraries emit qualified enum names in their ABI instead of
-- the underlying uint8. Treat any unrecognized identifier as uint8.
, P.try (P.some (P.alphaNumChar P.<|> P.char '.') $> AbiUIntType 8)
]

where
Expand Down
9 changes: 9 additions & 0 deletions test/test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,15 @@ tests = testGroup "hevm"
case readP_to_S (parseAbiValue (AbiBytesType 4)) threeBytes of
[] -> pure () -- Expected: parsing should fail
_ -> internalError "Should reject 3-byte value for bytes4"
, test "ABI-user-defined-enum-type" $ do
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should rename this to ABI-parsing-types? And add tests for all the standard types?

-- User-defined types like enums (e.g. "Order.OrderType") should parse as uint8
assertEqualM "qualified enum" (Just (AbiUIntType 8)) (parseTypeName mempty "Order.OrderType")
assertEqualM "simple enum" (Just (AbiUIntType 8)) (parseTypeName mempty "MyEnum")
-- Should also work with array suffixes
assertEqualM "enum array" (Just (AbiArrayDynamicType (AbiUIntType 8))) (parseTypeName mempty "Order.OrderType[]")
-- Standard types should still work
assertEqualM "uint256" (Just (AbiUIntType 256)) (parseTypeName mempty "uint256")
assertEqualM "address" (Just AbiAddressType) (parseTypeName mempty "address")
]
, testGroup "Solidity-Expressions"
[ test "Trivial" $
Expand Down
Loading