10 Commits

Author SHA1 Message Date
Marten Seemann
ecc3acc587 checkout recursively 2021-05-21 10:47:20 -07:00
web3-bot
4c4da582c9 add .github/workflows/go-check.yml 2021-05-21 17:37:42 +00:00
web3-bot
7a4928f460 add .github/workflows/go-test.yml 2021-05-21 17:37:42 +00:00
web3-bot
dc8f758855 add .github/workflows/automerge.yml 2021-05-21 17:37:42 +00:00
web3-bot
5dd3f1a01a set Go version to 1.15 and run go mod tidy 2021-05-21 17:37:42 +00:00
web3-bot
2c89197b5a disable Travis 2021-05-21 17:37:41 +00:00
Marten Seemann
f68598dd02 Merge pull request #41 from multiformats/fix-staticcheck
fix staticcheck
2021-05-05 20:16:15 +07:00
Marten Seemann
daffaef0db fix staticcheck 2021-05-05 20:13:06 +07:00
Steven Allen
95cb7074c4 Merge pull request #39 from gammazero/fix-vet-warnings
Fix vet warnings about conversion of int to string
2021-02-26 15:53:14 -08:00
gammazero
2985033078 Fix vet warnings about conversion of int to string
Fixes issue #38
2020-11-19 17:38:08 -08:00
8 changed files with 121 additions and 41 deletions

27
.github/workflows/automerge.yml vendored Normal file
View File

@@ -0,0 +1,27 @@
# File managed by web3-bot. DO NOT EDIT.
# See https://github.com/protocol/.github/ for details.
# Automatically merge pull requests opened by web3-bot, as soon as (and only if) all tests pass.
# This reduces the friction associated with updating with our workflows.
on: [ pull_request ]
jobs:
automerge:
if: github.event.pull_request.user.login == 'web3-bot'
runs-on: ubuntu-latest
steps:
- name: Wait on tests
uses: lewagon/wait-on-check-action@bafe56a6863672c681c3cf671f5e10b20abf2eaa # v0.2
with:
ref: ${{ github.event.pull_request.head.sha }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
wait-interval: 10
running-workflow-name: 'automerge' # the name of this job
- name: Merge PR
uses: pascalgn/automerge-action@741c311a47881be9625932b0a0de1b0937aab1ae # v0.13.1
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
MERGE_LABELS: ""
MERGE_METHOD: "squash"
MERGE_DELETE_BRANCH: true

43
.github/workflows/go-check.yml vendored Normal file
View File

@@ -0,0 +1,43 @@
# File managed by web3-bot. DO NOT EDIT.
# See https://github.com/protocol/.github/ for details.
on: [push, pull_request]
jobs:
unit:
runs-on: ubuntu-latest
name: Go checks
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: actions/setup-go@v2
with:
go-version: "1.16.x"
- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@be534f007836a777104a15f2456cd1fffd3ddee8 # v2020.2.2
- name: Check that go.mod is tidy
run: |
go mod tidy
if [[ -n $(git ls-files --other --exclude-standard --directory -- go.sum) ]]; then
echo "go.sum was added by go mod tidy"
exit 1
fi
git diff --exit-code -- go.sum go.mod
- name: gofmt
if: ${{ success() || failure() }} # run this step even if the previous one failed
run: |
out=$(gofmt -s -l .)
if [[ -n "$out" ]]; then
echo $out | awk '{print "::error file=" $0 ",line=0,col=0::File is not gofmt-ed."}'
exit 1
fi
- name: go vet
if: ${{ success() || failure() }} # run this step even if the previous one failed
run: go vet ./...
- name: staticcheck
if: ${{ success() || failure() }} # run this step even if the previous one failed
run: |
set -o pipefail
staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g'

40
.github/workflows/go-test.yml vendored Normal file
View File

@@ -0,0 +1,40 @@
# File managed by web3-bot. DO NOT EDIT.
# See https://github.com/protocol/.github/ for details.
on: [push, pull_request]
jobs:
unit:
strategy:
fail-fast: false
matrix:
os: [ "ubuntu", "windows", "macos" ]
go: [ "1.15.x", "1.16.x" ]
runs-on: ${{ matrix.os }}-latest
name: Unit tests (${{ matrix.os}}, Go ${{ matrix.go }})
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- name: Go information
run: |
go version
go env
- name: Run tests
run: go test -v -coverprofile coverage.txt ./...
- name: Run tests (32 bit)
if: ${{ matrix.os != 'macos' }} # can't run 32 bit tests on OSX.
env:
GOARCH: 386
run: go test -v ./...
- name: Run tests with race detector
if: ${{ matrix.os == 'ubuntu' }} # speed things up. Windows and OSX VMs are slow
run: go test -v -race ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@967e2b38a85a62bd61be5529ada27ebc109948c2 # v1.4.1
with:
file: coverage.txt
env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }}

View File

@@ -1,30 +0,0 @@
os:
- linux
language: go
go:
- 1.11.x
env:
global:
- GOTFLAGS="-race"
matrix:
- BUILD_DEPTYPE=gomod
# disable travis install
install:
- true
script:
- bash <(curl -s https://raw.githubusercontent.com/ipfs/ci-helpers/master/travis-ci/run-standard-tests.sh)
cache:
directories:
- $GOPATH/pkg/mod
- /home/travis/.cache/go-build
notifications:
email: false

View File

@@ -14,7 +14,7 @@ type Encoder struct {
func NewEncoder(base Encoding) (Encoder, error) { func NewEncoder(base Encoding) (Encoder, error) {
_, ok := EncodingToStr[base] _, ok := EncodingToStr[base]
if !ok { if !ok {
return Encoder{-1}, fmt.Errorf("Unsupported multibase encoding: %d", base) return Encoder{-1}, fmt.Errorf("unsupported multibase encoding: %d", base)
} }
return Encoder{base}, nil return Encoder{base}, nil
} }
@@ -33,9 +33,9 @@ func MustNewEncoder(base Encoding) Encoder {
// either be the multibase name or single character multibase prefix // either be the multibase name or single character multibase prefix
func EncoderByName(str string) (Encoder, error) { func EncoderByName(str string) (Encoder, error) {
var base Encoding var base Encoding
ok := true var ok bool
if len(str) == 0 { if len(str) == 0 {
return Encoder{-1}, fmt.Errorf("Empty multibase encoding") return Encoder{-1}, fmt.Errorf("empty multibase encoding")
} else if len(str) == 1 { } else if len(str) == 1 {
base = Encoding(str[0]) base = Encoding(str[0])
_, ok = EncodingToStr[base] _, ok = EncodingToStr[base]
@@ -43,7 +43,7 @@ func EncoderByName(str string) (Encoder, error) {
base, ok = Encodings[str] base, ok = Encodings[str]
} }
if !ok { if !ok {
return Encoder{-1}, fmt.Errorf("Unsupported multibase encoding: %s", str) return Encoder{-1}, fmt.Errorf("unsupported multibase encoding: %s", str)
} }
return Encoder{base}, nil return Encoder{base}, nil
} }

2
go.mod
View File

@@ -1,6 +1,6 @@
module github.com/multiformats/go-multibase module github.com/multiformats/go-multibase
go 1.11 go 1.15
require ( require (
github.com/mr-tron/base58 v1.1.0 github.com/mr-tron/base58 v1.1.0

View File

@@ -84,7 +84,7 @@ func Encode(base Encoding, data []byte) (string, error) {
switch base { switch base {
case Identity: case Identity:
// 0x00 inside a string is OK in golang and causes no problems with the length calculation. // 0x00 inside a string is OK in golang and causes no problems with the length calculation.
return string(Identity) + string(data), nil return string(rune(Identity)) + string(data), nil
case Base2: case Base2:
return string(Base2) + binaryEncodeToString(data), nil return string(Base2) + binaryEncodeToString(data), nil
case Base16: case Base16:

View File

@@ -24,7 +24,7 @@ func TestMap(t *testing.T) {
var sampleBytes = []byte("Decentralize everything!!!") var sampleBytes = []byte("Decentralize everything!!!")
var encodedSamples = map[Encoding]string{ var encodedSamples = map[Encoding]string{
Identity: string(0x00) + "Decentralize everything!!!", Identity: string(rune(0x00)) + "Decentralize everything!!!",
Base2: "00100010001100101011000110110010101101110011101000111001001100001011011000110100101111010011001010010000001100101011101100110010101110010011110010111010001101000011010010110111001100111001000010010000100100001", Base2: "00100010001100101011000110110010101101110011101000111001001100001011011000110100101111010011001010010000001100101011101100110010101110010011110010111010001101000011010010110111001100111001000010010000100100001",
Base16: "f446563656e7472616c697a652065766572797468696e67212121", Base16: "f446563656e7472616c697a652065766572797468696e67212121",
Base16Upper: "F446563656E7472616C697A652065766572797468696E67212121", Base16Upper: "F446563656E7472616C697A652065766572797468696E67212121",
@@ -91,22 +91,22 @@ func TestRoundTrip(t *testing.T) {
continue continue
} }
_, _, err := Decode(string(base) + "\u00A0") _, _, err := Decode(string(rune(base)) + "\u00A0")
if err == nil { if err == nil {
t.Fatal(EncodingToStr[base] + " decode should fail on low-unicode") t.Fatal(EncodingToStr[base] + " decode should fail on low-unicode")
} }
_, _, err = Decode(string(base) + "\u1F4A8") _, _, err = Decode(string(rune(base)) + "\u1F4A8")
if err == nil { if err == nil {
t.Fatal(EncodingToStr[base] + " decode should fail on emoji") t.Fatal(EncodingToStr[base] + " decode should fail on emoji")
} }
_, _, err = Decode(string(base) + "!") _, _, err = Decode(string(rune(base)) + "!")
if err == nil { if err == nil {
t.Fatal(EncodingToStr[base] + " decode should fail on punctuation") t.Fatal(EncodingToStr[base] + " decode should fail on punctuation")
} }
_, _, err = Decode(string(base) + "\xA0") _, _, err = Decode(string(rune(base)) + "\xA0")
if err == nil { if err == nil {
t.Fatal(EncodingToStr[base] + " decode should fail on high-latin1") t.Fatal(EncodingToStr[base] + " decode should fail on high-latin1")
} }