Support enums in a function signature

This commit is contained in:
Mark Spanbroek 2022-06-09 15:51:48 +02:00 committed by markspanbroek
parent b111c27b61
commit f4ea25cb57
2 changed files with 6 additions and 0 deletions

View File

@ -37,6 +37,7 @@ solidityType Int256, "int256"
solidityType bool, "bool" solidityType bool, "bool"
solidityType string, "string" solidityType string, "string"
solidityType Address, "address" solidityType Address, "address"
solidityType enum, "uint8"
func solidityType*[N: static int, T](_: type array[N, T]): string = func solidityType*[N: static int, T](_: type array[N, T]): string =
when T is byte: when T is byte:

View File

@ -4,6 +4,10 @@ import pkg/contractabi
suite "function selector": suite "function selector":
type SomeEnum = enum
One
Two
test "translates nim types into solidity types": test "translates nim types into solidity types":
check solidityType(uint8) == "uint8" check solidityType(uint8) == "uint8"
check solidityType(uint16) == "uint16" check solidityType(uint16) == "uint16"
@ -29,6 +33,7 @@ suite "function selector":
check solidityType(array[4, string]) == "string[4]" check solidityType(array[4, string]) == "string[4]"
check solidityType(seq[string]) == "string[]" check solidityType(seq[string]) == "string[]"
check solidityType((Address, string, bool)) == "(address,string,bool)" check solidityType((Address, string, bool)) == "(address,string,bool)"
check solidityType(SomeEnum) == "uint8"
test "calculates solidity function selector": test "calculates solidity function selector":
check $selector("transfer", (Address, UInt256)) == "0xa9059cbb" check $selector("transfer", (Address, UInt256)) == "0xa9059cbb"