package protocol import "testing" func TestKindNames(t *testing.T) { if n := KindName(KindTrack); n != "track" { t.Fatalf("KindName(32210) = %q", n) } if n := KindName(KindAccessFilter); n != "access-filter" { t.Fatalf("KindName(32217) = %q", n) } if n := KindName(12345); n != "unknown" { t.Fatalf("KindName(12345) = %q", n) } } func TestKindBlocks(t *testing.T) { addressable := []uint16{ KindTrack, KindAlbum, KindPlaylist, KindSetlist, KindReleaseCredits, KindTrackCredits, KindEdition, KindAccessFilter, } regular := []uint16{ KindPlayReport, KindPurchaseOrder, KindDeliveryReceipt, KindHostAggregate, KindPublisherRollup, } for _, k := range addressable { if !IsMusiquay(k) || !IsAddressable(k) || IsRegular(k) { t.Errorf("kind %d is not classified as addressable-only", k) } } for _, k := range regular { if !IsMusiquay(k) || !IsRegular(k) || IsAddressable(k) { t.Errorf("kind %d is not classified as regular-only", k) } } if IsMusiquay(KindCreditLabel) || IsMusiquay(KindStall) { t.Fatal("a reused NIP kind is reported as a Musiquay kind") } } func TestAddressableBlockIsContiguous(t *testing.T) { for k := uint16(32210); k <= 32217; k++ { if !IsAddressable(k) { t.Fatalf("kind %d in the addressable block is not addressable", k) } if !InReplaceableRange(k) { t.Fatalf("addressable kind %d is outside NIP-01's replaceable range", k) } } } // The registry puts three regular, counted kinds inside NIP-01's replaceable // range. That is a hazard, not a feature: a relay applying the range rule // without an exception would keep one receipt per host. This test pins the // exact set so a renumbering is visible, and so storage policy has a list. func TestRegularKindsInReplaceableRange(t *testing.T) { ks := RegularInReplaceableRange() want := []uint16{KindDeliveryReceipt, KindHostAggregate, KindPublisherRollup} if len(ks) != len(want) { t.Fatalf("RegularInReplaceableRange() = %v", ks) } for i, k := range ks { if k != want[i] { t.Fatalf("RegularInReplaceableRange()[%d] = %d, want %d", i, k, want[i]) } if !IsRegular(k) { t.Fatalf("kind %d listed as regular is not regular", k) } if !InReplaceableRange(k) { t.Fatalf("kind %d listed as in-range is not", k) } } // The counted kinds outside the range must not be listed. if InReplaceableRange(KindPlayReport) || InReplaceableRange(KindPurchaseOrder) { t.Fatal("a regular kind outside the replaceable range is reported inside it") } } func TestPrivateKinds(t *testing.T) { if !IsPrivate(KindPurchaseOrder) || !IsPrivate(KindDeliveryReceipt) { t.Fatal("the two wrapped kinds must be private") } if IsPrivate(KindPlayReport) || IsPrivate(KindHostAggregate) { t.Fatal("a public kind is reported as private") } } func TestKnownRole(t *testing.T) { if !KnownRole("sound-foh") { t.Fatal("roster role not known") } if !KnownRole("mastering-engineer") { t.Fatal("credit role not known") } // Instruments are open-ended inside the role token. if !KnownRole("performer-cello") { t.Fatal("performer- not accepted") } if KnownRole("wizard") { t.Fatal("an unknown role reported as known") } } func TestAccessTier(t *testing.T) { for _, s := range []string{TierFan, TierRetail, TierSub} { if !AccessTier(s) { t.Errorf("tier %q not accepted", s) } } if AccessTier("presale") { t.Fatal("presale is not an access-filter tier") } }