bech32_test.go raw
1 package helpers
2
3 import "testing"
4
5 func TestBech32RoundTrip(t *testing.T) {
6 data := HexDecode("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798")
7 encoded := EncodeNpub(data)
8 t.Logf("npub: %s", encoded)
9
10 decoded := DecodeNpub(encoded)
11 if decoded == nil {
12 t.Fatal("DecodeNpub returned nil")
13 }
14 got := HexEncode(decoded)
15 want := "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"
16 if got != want {
17 t.Errorf("round-trip failed:\ngot %s\nwant %s", got, want)
18 }
19 }
20
21 func TestNpubKnown(t *testing.T) {
22 // Decode a known npub.
23 npub := "npub1fjqqy4a93z5zsjwsfxqhc2764kvykfdyttvldkkkdera8dr78vhsmmleku"
24 data := DecodeNpub(npub)
25 if data == nil {
26 t.Fatal("failed to decode npub")
27 }
28 hex := HexEncode(data)
29 t.Logf("pubkey hex: %s", hex)
30 if len(hex) != 64 {
31 t.Errorf("expected 64 hex chars, got %d", len(hex))
32 }
33 }
34