Added support for more base encodings

License: MIT
Signed-off-by: Mateusz Naściszewski <matin1111@wp.pl>
This commit is contained in:
mateon1
2016-11-27 23:56:23 +01:00
parent 64b00b0f1a
commit 3d3cb9341e
3 changed files with 65 additions and 21 deletions

View File

@@ -6,29 +6,33 @@ import (
"testing"
)
func TestBase58RoundTrip(t *testing.T) {
func TestRoundTrip(t *testing.T) {
buf := make([]byte, 16)
rand.Read(buf)
enc, err := Encode(Base58BTC, buf)
if err != nil {
t.Fatal(err)
baseList := []int{ Base16, Base32, Base32hex, Base58BTC, Base58Flickr, Base64, Base64url }
for _, base := range baseList {
enc, err := Encode(base, buf)
if err != nil {
t.Fatal(err)
}
e, out, err := Decode(enc)
if err != nil {
t.Fatal(err)
}
if e != base {
t.Fatal("got wrong encoding out")
}
if !bytes.Equal(buf, out) {
t.Fatal("input wasnt the same as output", buf, out)
}
}
e, out, err := Decode(enc)
if err != nil {
t.Fatal(err)
}
if e != Base58BTC {
t.Fatal("got wrong encoding out")
}
if !bytes.Equal(buf, out) {
t.Fatal("input wasnt the same as output", buf, out)
}
_, _, err = Decode("")
_, _, err := Decode("")
if err == nil {
t.Fatal("shouldnt be able to decode empty string")
}