mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-12 01:41:36 +00:00
accounts/abi: fix index error
This commit is contained in:
parent
6ece4cd143
commit
73d7f7c36e
2 changed files with 21 additions and 1 deletions
|
|
@ -126,7 +126,7 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty
|
|||
var varSize int
|
||||
if len(parsedType[3]) > 0 {
|
||||
var err error
|
||||
varSize, err = strconv.Atoi(parsedType[2])
|
||||
varSize, err = strconv.Atoi(parsedType[3])
|
||||
if err != nil {
|
||||
return Type{}, fmt.Errorf("abi: error parsing variable size: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package abi
|
|||
import (
|
||||
"math/big"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
|
|
@ -378,3 +379,22 @@ func TestNewFixedBytesOver32(t *testing.T) {
|
|||
t.Errorf("fixed bytes with size over 32 is not spec'd")
|
||||
}
|
||||
}
|
||||
|
||||
// TestNewTypeFixedPointWrongSizeSubmatch is a regression test for a bug in NewType
|
||||
// that used the wrong regexp submatch (parsedType[2]) for the first numeric size.
|
||||
// For types like fixed128x18, the overall second group is "128x18", not an integer
|
||||
// string; the first integer is parsedType[3] ("128"). The bug caused strconv.Atoi
|
||||
// to fail with "error parsing variable size" instead of the intended "unsupported
|
||||
// arg type" outcome for unimplemented fixed-point encodings.
|
||||
func TestNewTypeFixedPointWrongSizeSubmatch(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, s := range []string{"fixed128x18", "ufixed256x10"} {
|
||||
_, err := NewType(s, "", nil)
|
||||
if err == nil {
|
||||
t.Fatalf("type %q: expected error for unsupported fixed-point type", s)
|
||||
}
|
||||
if strings.Contains(err.Error(), "error parsing variable size") {
|
||||
t.Fatalf("type %q: got size parse error (wrong regexp submatch); want unsupported: %v", s, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue