Added support for more base encodings
License: MIT Signed-off-by: Mateusz Naściszewski <matin1111@wp.pl>
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user