Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: sync base58 with upstream #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
name: Build and Test
on: [push, pull_request]
on:
pull_request:
push:
jobs:
build:
name: Go CI
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Check out source
Expand Down
3 changes: 1 addition & 2 deletions base58/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
base58
==========

[![Build Status](http://img.shields.io/travis/cosmos/btcutil.svg)](https://travis-ci.org/cosmos/btcutil)
[![ISC License](http://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org)
[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)](http://godoc.org/github.com/cosmos/btcutil/base58)

Expand All @@ -14,7 +13,7 @@ A comprehensive suite of tests is provided to ensure proper functionality.
## Installation and Updating

```bash
$ go get -u github.com/cosmos/btcutil/base58
go get -u github.com/cosmos/btcutil/base58
```

## Examples
Expand Down
4 changes: 4 additions & 0 deletions base58/base58.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func Decode(b string) []byte {

total := uint64(0)
for _, v := range t[:n] {
if v > 255 {
return []byte("")
}

tmp := b58[v]
if tmp == 255 {
return []byte("")
Expand Down
2 changes: 2 additions & 0 deletions base58/base58_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ var invalidStringTests = []struct {
{"4kl8", ""},
{"0OIl", ""},
{"!@#$%^&*()-_=+~`", ""},
{"abcd\xd80", ""},
{"abcd\U000020BF", ""},
}

var hexTests = []struct {
Expand Down
2 changes: 1 addition & 1 deletion base58/base58check.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func checksum(input []byte) (cksum [4]byte) {
func CheckEncode(input []byte, version byte) string {
b := make([]byte, 0, 1+len(input)+4)
b = append(b, version)
b = append(b, input[:]...)
b = append(b, input...)
cksum := checksum(b)
b = append(b, cksum[:]...)
return Encode(b)
Expand Down
11 changes: 7 additions & 4 deletions base58/base58check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ func TestBase58Check(t *testing.T) {

// test decoding
res, version, err := base58.CheckDecode(test.out)
if err != nil {
switch {
case err != nil:
t.Errorf("CheckDecode test #%d failed with err: %v", x, err)
} else if version != test.version {

case version != test.version:
t.Errorf("CheckDecode test #%d failed: got version: %d want: %d", x, version, test.version)
} else if string(res) != test.in {

case string(res) != test.in:
t.Errorf("CheckDecode test #%d failed: got: %s want: %s", x, res, test.in)
}
}
Expand All @@ -56,7 +59,7 @@ func TestBase58Check(t *testing.T) {
// bytes are missing).
testString := ""
for len := 0; len < 4; len++ {
testString = testString + "x"
testString += "x"
_, _, err = base58.CheckDecode(testString)
if err != base58.ErrInvalidFormat {
t.Error("Checkdecode test failed, expected ErrInvalidFormat")
Expand Down