package nostr import ( "strings" "testing" ) func TestNormalizePubkey_Hex(t *testing.T) { hex := "0e8c41ebcd55a8d8db2e0a8c3a4b9c5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c" got, err := NormalizePubkey(hex) if err != nil { t.Fatalf("unexpected err: %v", err) } if got != strings.ToLower(hex) { t.Fatalf("got %q want %q", got, hex) } } func TestNormalizePubkey_BadInput(t *testing.T) { cases := []string{"", "abc", "not-an-npub", "npub1invalid", strings.Repeat("z", 64)} for _, c := range cases { if _, err := NormalizePubkey(c); err == nil { t.Errorf("expected error for %q", c) } } } func TestNormalizePubkey_NpubRoundtrip(t *testing.T) { hex := "0e8c41ebcd55a8d8db2e0a8c3a4b9c5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c" npub := HexToNpub(hex) if npub == "" || !strings.HasPrefix(npub, "npub1") { t.Fatalf("HexToNpub failed: %q", npub) } got, err := NormalizePubkey(npub) if err != nil { t.Fatalf("decode npub: %v", err) } if got != hex { t.Fatalf("roundtrip got %q want %q", got, hex) } }