Skip to content

Commit

Permalink
Allowing zero-length in static array (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangsu authored Nov 29, 2022
1 parent 278bd82 commit 755a940
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion abi/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (t Type) String() string {
}
}

var staticArrayRegexp = regexp.MustCompile(`^([a-z\d\[\](),]+)\[([1-9][\d]*)]$`)
var staticArrayRegexp = regexp.MustCompile(`^([a-z\d\[\](),]+)\[(0|[1-9][\d]*)]$`)
var ufixedRegexp = regexp.MustCompile(`^ufixed([1-9][\d]*)x([1-9][\d]*)$`)

// TypeOf parses an ABI type string.
Expand Down
13 changes: 12 additions & 1 deletion abi/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,18 @@ func TestTypeFromStringValid(t *testing.T) {
uint16(200),
),
},
{
input: "ufixed64x10[0]",
testType: "static array",
expected: makeStaticArrayType(
Type{
kind: Ufixed,
bitSize: uint16(64),
precision: uint16(10),
},
uint16(0),
),
},
// tuple type
{
input: "()",
Expand Down Expand Up @@ -509,7 +521,6 @@ func TestTypeFromStringInvalid(t *testing.T) {
"[][][]",
"stuff[]",
// static array
"ufixed32x10[0]",
"byte[10 ]",
"uint64[0x21]",
// tuple
Expand Down

0 comments on commit 755a940

Please sign in to comment.