Selaa lähdekoodia

fix slice unpack bug in accounts/abi (#18321)

* fix slice unpack bug in accounts/abi
weimumu 6 vuotta sitten
vanhempi
commit
3ad73443c7
2 muutettua tiedostoa jossa 6 lisäystä ja 1 poistoa
  1. 1 1
      accounts/abi/unpack.go
  2. 5 0
      accounts/abi/unpack_test.go

+ 1 - 1
accounts/abi/unpack.go

@@ -151,7 +151,7 @@ func forEachUnpack(t Type, output []byte, start, size int) (interface{}, error)
 	// Arrays have packed elements, resulting in longer unpack steps.
 	// Slices have just 32 bytes per element (pointing to the contents).
 	elemSize := 32
-	if t.T == ArrayTy {
+	if t.T == ArrayTy || t.T == SliceTy {
 		elemSize = getFullElemSize(t.Elem)
 	}
 

+ 5 - 0
accounts/abi/unpack_test.go

@@ -191,6 +191,11 @@ var unpackTests = []unpackTest{
 		enc:  "0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",
 		want: [][2]uint8{{1, 2}},
 	},
+	{
+		def:  `[{"type": "uint8[2][]"}]`,
+		enc:  "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",
+		want: [][2]uint8{{1, 2}, {1, 2}},
+	},
 	{
 		def:  `[{"type": "uint16[]"}]`,
 		enc:  "0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",