package base58 import ( "bytes" "encoding/hex" "testing" ) func TestRoundTrip(t *testing.T) { cases := [][]byte{ {0x00}, {0x00, 0x00, 0x01}, bytes.Repeat([]byte{0xff}, 32), []byte("hello world"), {}, } for _, in := range cases { enc := Encode(in) got, err := Decode(enc) if err != nil { t.Fatalf("Decode(%q): %v", enc, err) } if !bytes.Equal(got, in) { t.Fatalf("round trip mismatch: in=%x enc=%q got=%x", in, enc, got) } } } func TestCheckEncodeKnownAddress(t *testing.T) { raw, err := hex.DecodeString("4143d75ee7cdcd7f2fcd4fc3b4eb574b6bdc2a3fcb") if err != nil { t.Fatalf("decode raw: %v", err) } if got := CheckEncode(raw); got != "TG9vH8c2jBWq2wSnksrq5mVyq2wjhG4A1n" { t.Fatalf("CheckEncode = %s", got) } payload, err := CheckDecode("TG9vH8c2jBWq2wSnksrq5mVyq2wjhG4A1n") if err != nil { t.Fatalf("CheckDecode: %v", err) } if !bytes.Equal(payload, raw) { t.Fatalf("CheckDecode = %x, want %x", payload, raw) } } func TestCheckDecodeRejectsBadChecksum(t *testing.T) { if _, err := CheckDecode("TG9vH8c2jBWq2wSnksrq5mVyq2wjhG4A1m"); err == nil { t.Fatalf("expected checksum error") } } func TestDecodeRejectsInvalidByte(t *testing.T) { if _, err := Decode("0OIl"); err == nil { t.Fatalf("expected invalid byte error") } }