diff options
-rw-r--r-- | .travis.yml | 17 | ||||
-rw-r--r-- | accounts/abi/abi.go | 52 | ||||
-rw-r--r-- | accounts/abi/abi_test.go | 25 | ||||
-rw-r--r-- | accounts/abi/reflect.go | 4 | ||||
-rw-r--r-- | accounts/abi/type.go | 9 | ||||
-rw-r--r-- | appveyor.yml | 40 | ||||
-rw-r--r-- | build/ci.go | 10 |
7 files changed, 113 insertions, 44 deletions
diff --git a/.travis.yml b/.travis.yml index a2271de12..51af0570b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,7 @@ matrix: # This builder does the Ubuntu PPA and Linux Azure uploads - os: linux dist: trusty + sudo: required go: 1.7 env: - ubuntu-ppa @@ -27,17 +28,31 @@ matrix: addons: apt: packages: - - gcc-multilib - devscripts - debhelper - dput + - gcc-multilib script: + # Build for the primary platforms that Trusty can manage - go run build/ci.go debsrc -signer "Felix Lange (Geth CI Testing Key) <fjl@twurst.com>" -upload ppa:lp-fjl/geth-ci-testing - go run build/ci.go install - go run build/ci.go archive -type tar -signer LINUX_SIGNING_KEY -upload gethstore/builds - go run build/ci.go install -arch 386 - go run build/ci.go archive -arch 386 -type tar -signer LINUX_SIGNING_KEY -upload gethstore/builds + # Switch over GCC to cross compilation (breaks 386, hence why do it here only) + - sudo -E apt-get -yq --no-install-suggests --no-install-recommends --force-yes install gcc-arm-linux-gnueabi libc6-dev-armel-cross gcc-arm-linux-gnueabihf libc6-dev-armhf-cross gcc-aarch64-linux-gnu libc6-dev-arm64-cross + - sudo ln -s /usr/include/asm-generic /usr/include/asm + + - GOARM=5 CC=arm-linux-gnueabi-gcc go run build/ci.go install -arch arm + - GOARM=5 go run build/ci.go archive -arch arm -type tar -signer LINUX_SIGNING_KEY -upload gethstore/builds + - GOARM=6 CC=arm-linux-gnueabi-gcc go run build/ci.go install -arch arm + - GOARM=6 go run build/ci.go archive -arch arm -type tar -signer LINUX_SIGNING_KEY -upload gethstore/builds + - GOARM=7 CC=arm-linux-gnueabihf-gcc go run build/ci.go install -arch arm + - GOARM=7 go run build/ci.go archive -arch arm -type tar -signer LINUX_SIGNING_KEY -upload gethstore/builds + - CC=aarch64-linux-gnu-gcc go run build/ci.go install -arch arm64 + - go run build/ci.go archive -arch arm64 -type tar -signer LINUX_SIGNING_KEY -upload gethstore/builds + # This builder does the OSX Azure uploads - os: osx go: 1.7 diff --git a/accounts/abi/abi.go b/accounts/abi/abi.go index c127cd7a9..2efac1307 100644 --- a/accounts/abi/abi.go +++ b/accounts/abi/abi.go @@ -98,28 +98,46 @@ func toGoSlice(i int, t Argument, output []byte) (interface{}, error) { case HashTy: // hash must be of slice hash refSlice = reflect.ValueOf([]common.Hash(nil)) case FixedBytesTy: - refSlice = reflect.ValueOf([]byte(nil)) + refSlice = reflect.ValueOf([][]byte(nil)) default: // no other types are supported return nil, fmt.Errorf("abi: unsupported slice type %v", elem.T) } - // get the offset which determines the start of this array ... - offset := int(common.BytesToBig(output[index : index+32]).Uint64()) - if offset+32 > len(output) { - return nil, fmt.Errorf("abi: cannot marshal in to go slice: offset %d would go over slice boundary (len=%d)", len(output), offset+32) - } - slice := output[offset:] - // ... starting with the size of the array in elements ... - size := int(common.BytesToBig(slice[:32]).Uint64()) - slice = slice[32:] - // ... and make sure that we've at the very least the amount of bytes - // available in the buffer. - if size*32 > len(slice) { - return nil, fmt.Errorf("abi: cannot marshal in to go slice: insufficient size output %d require %d", len(output), offset+32+size*32) + var slice []byte + var size int + var offset int + if t.Type.IsSlice { + + // get the offset which determines the start of this array ... + offset = int(common.BytesToBig(output[index : index+32]).Uint64()) + if offset+32 > len(output) { + return nil, fmt.Errorf("abi: cannot marshal in to go slice: offset %d would go over slice boundary (len=%d)", len(output), offset+32) + } + + slice = output[offset:] + // ... starting with the size of the array in elements ... + size = int(common.BytesToBig(slice[:32]).Uint64()) + slice = slice[32:] + // ... and make sure that we've at the very least the amount of bytes + // available in the buffer. + if size*32 > len(slice) { + return nil, fmt.Errorf("abi: cannot marshal in to go slice: insufficient size output %d require %d", len(output), offset+32+size*32) + } + + // reslice to match the required size + slice = slice[:(size * 32)] + } else if t.Type.IsArray { + //get the number of elements in the array + size = t.Type.SliceSize + + //check to make sure array size matches up + if index+32*size > len(output) { + return nil, fmt.Errorf("abi: cannot marshal in to go array: offset %d would go over slice boundary (len=%d)", len(output), index+32*size) + } + //slice is there for a fixed amount of times + slice = output[index : index+size*32] } - // reslice to match the required size - slice = slice[:(size * 32)] for i := 0; i < size; i++ { var ( inter interface{} // interface type @@ -136,6 +154,8 @@ func toGoSlice(i int, t Argument, output []byte) (interface{}, error) { inter = common.BytesToAddress(returnOutput) case HashTy: inter = common.BytesToHash(returnOutput) + case FixedBytesTy: + inter = returnOutput } // append the item to our reflect slice refSlice = reflect.Append(refSlice, reflect.ValueOf(inter)) diff --git a/accounts/abi/abi_test.go b/accounts/abi/abi_test.go index 7916e595d..85e25f9ea 100644 --- a/accounts/abi/abi_test.go +++ b/accounts/abi/abi_test.go @@ -357,8 +357,6 @@ func TestMethodPack(t *testing.T) { } sig := abi.Methods["slice"].Id() - sig = append(sig, common.LeftPadBytes([]byte{32}, 32)...) - sig = append(sig, common.LeftPadBytes([]byte{2}, 32)...) sig = append(sig, common.LeftPadBytes([]byte{1}, 32)...) sig = append(sig, common.LeftPadBytes([]byte{2}, 32)...) @@ -406,8 +404,6 @@ func TestMethodPack(t *testing.T) { } sig = abi.Methods["slice256"].Id() - sig = append(sig, common.LeftPadBytes([]byte{32}, 32)...) - sig = append(sig, common.LeftPadBytes([]byte{2}, 32)...) sig = append(sig, common.LeftPadBytes([]byte{1}, 32)...) sig = append(sig, common.LeftPadBytes([]byte{2}, 32)...) @@ -931,6 +927,7 @@ func TestUnmarshal(t *testing.T) { { "name" : "bytes", "constant" : false, "outputs": [ { "type": "bytes" } ] }, { "name" : "fixed", "constant" : false, "outputs": [ { "type": "bytes32" } ] }, { "name" : "multi", "constant" : false, "outputs": [ { "type": "bytes" }, { "type": "bytes" } ] }, + { "name" : "intArraySingle", "constant" : false, "outputs": [ { "type": "uint256[3]" } ] }, { "name" : "addressSliceSingle", "constant" : false, "outputs": [ { "type": "address[]" } ] }, { "name" : "addressSliceDouble", "constant" : false, "outputs": [ { "name": "a", "type": "address[]" }, { "name": "b", "type": "address[]" } ] }, { "name" : "mixedBytes", "constant" : true, "outputs": [ { "name": "a", "type": "bytes" }, { "name": "b", "type": "bytes32" } ] }]` @@ -1083,6 +1080,26 @@ func TestUnmarshal(t *testing.T) { t.Errorf("expected %x, got %x", fixed, out[1]) } + buff.Reset() + buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")) + buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002")) + buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000003")) + // marshal int array + var intArray [3]*big.Int + err = abi.Unpack(&intArray, "intArraySingle", buff.Bytes()) + if err != nil { + t.Error(err) + } + var testAgainstIntArray [3]*big.Int + testAgainstIntArray[0] = big.NewInt(1) + testAgainstIntArray[1] = big.NewInt(2) + testAgainstIntArray[2] = big.NewInt(3) + + for i, Int := range intArray { + if Int.Cmp(testAgainstIntArray[i]) != 0 { + t.Errorf("expected %v, got %v", testAgainstIntArray[i], Int) + } + } // marshal address slice buff.Reset() buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020")) // offset diff --git a/accounts/abi/reflect.go b/accounts/abi/reflect.go index ab5020200..7970ba8ac 100644 --- a/accounts/abi/reflect.go +++ b/accounts/abi/reflect.go @@ -78,10 +78,6 @@ func set(dst, src reflect.Value, output Argument) error { case dstType.AssignableTo(src.Type()): dst.Set(src) case dstType.Kind() == reflect.Array && srcType.Kind() == reflect.Slice: - if !dstType.Elem().AssignableTo(r_byte) { - return fmt.Errorf("abi: cannot unmarshal %v in to array of elem %v", src.Type(), dstType.Elem()) - } - if dst.Len() < output.Type.SliceSize { return fmt.Errorf("abi: cannot unmarshal src (len=%d) in to dst (len=%d)", output.Type.SliceSize, dst.Len()) } diff --git a/accounts/abi/type.go b/accounts/abi/type.go index 2235bad61..39b843f81 100644 --- a/accounts/abi/type.go +++ b/accounts/abi/type.go @@ -170,6 +170,7 @@ func (t Type) pack(v reflect.Value) ([]byte, error) { if (t.IsSlice || t.IsArray) && t.T != BytesTy && t.T != FixedBytesTy { var packed []byte + for i := 0; i < v.Len(); i++ { val, err := t.Elem.pack(v.Index(i)) if err != nil { @@ -177,7 +178,11 @@ func (t Type) pack(v reflect.Value) ([]byte, error) { } packed = append(packed, val...) } - return packBytesSlice(packed, v.Len()), nil + if t.IsSlice { + return packBytesSlice(packed, v.Len()), nil + } else if t.IsArray { + return packed, nil + } } return packElement(t, v), nil @@ -186,5 +191,5 @@ func (t Type) pack(v reflect.Value) ([]byte, error) { // requireLengthPrefix returns whether the type requires any sort of length // prefixing. func (t Type) requiresLengthPrefix() bool { - return t.T != FixedBytesTy && (t.T == StringTy || t.T == BytesTy || t.IsSlice || t.IsArray) + return t.T != FixedBytesTy && (t.T == StringTy || t.T == BytesTy || t.IsSlice) } diff --git a/appveyor.yml b/appveyor.yml index 0b1c919d8..ef2731951 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,28 +6,34 @@ clone_depth: 5 version: "{branch}.{build}" environment: global: - # Go stuff GOPATH: c:\gopath - GO: c:\go\bin\go - GOROOT: c:\go - CC: C:\msys64\mingw64\bin\gcc.exe - # MSYS2 stuff - MSYS2_ARCH: x86_64 - MSYSTEM: MINGW64 - PATH: C:\msys64\mingw64\bin\;%PATH% + CC: gcc.exe + matrix: + - GETH_ARCH: amd64 + MSYS2_ARCH: x86_64 + MSYS2_BITS: 64 + MSYSTEM: MINGW64 + PATH: C:\msys64\mingw64\bin\;%PATH% + - GETH_ARCH: 386 + MSYS2_ARCH: i686 + MSYS2_BITS: 32 + MSYSTEM: MINGW32 + PATH: C:\msys64\mingw32\bin\;%PATH% install: - - "%GO% version" - - "%CC% --version" + - rmdir c:\go /s /q + - appveyor DownloadFile https://storage.googleapis.com/golang/go1.7.3.windows-amd64.zip + - 7z x go1.7.3.windows-amd64.zip -y -oC:\ > NUL + - go version + - gcc --version build_script: - - "%GO% run build\\ci.go install" - -test_script: - - "%GO% run build\\ci.go test -vet -coverage" + - go run build\\ci.go install -arch %GETH_ARCH% after_build: - - "%GO% run build\\ci.go archive -type zip" + - go run build\\ci.go archive -arch %GETH_ARCH% -type zip -signer WINDOWS_SIGNING_KEY -upload gethstore/builds -artifacts: - - path: geth-*.zip +test_script: + - set GOARCH=%GETH_ARCH% + - set CGO_ENABLED=1 + - go run build\\ci.go test -vet -coverage diff --git a/build/ci.go b/build/ci.go index c6c6f61c9..f3882a1e7 100644 --- a/build/ci.go +++ b/build/ci.go @@ -158,6 +158,13 @@ func doInstall(cmdline []string) { build.MustRun(goinstall) return } + // If we are cross compiling to ARMv5 ARMv6 or ARMv7, clean any prvious builds + if *arch == "arm" { + os.RemoveAll(filepath.Join(runtime.GOROOT(), "pkg", runtime.GOOS+"_arm")) + for _, path := range filepath.SplitList(build.GOPATH()) { + os.RemoveAll(filepath.Join(path, "pkg", runtime.GOOS+"_arm")) + } + } // Seems we are cross compiling, work around forbidden GOBIN goinstall := goToolArch(*arch, "install", buildFlags(env)...) goinstall.Args = append(goinstall.Args, "-v") @@ -318,6 +325,9 @@ func doArchive(cmdline []string) { func archiveBasename(arch string, env build.Environment) string { platform := runtime.GOOS + "-" + arch + if arch == "arm" { + platform += os.Getenv("GOARM") + } archive := platform + "-" + build.VERSION() if isUnstableBuild(env) { archive += "-unstable" |