summaryrefslogtreecommitdiffstats
path: root/kinds_test.go
blob: 2bf013df7d26b1d5b372056d4326e5ad21c2eadf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package nostr

import (
	"testing"
)

func TestKindConstants(t *testing.T) {
	// Verify constants match NIP-01 spec
	tests := []struct {
		name  string
		kind  int
		value int
	}{
		{"Metadata", KindMetadata, 0},
		{"TextNote", KindTextNote, 1},
		{"ContactList", KindContactList, 3},
		{"EncryptedDM", KindEncryptedDM, 4},
		{"Deletion", KindDeletion, 5},
		{"Repost", KindRepost, 6},
		{"Reaction", KindReaction, 7},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if tt.kind != tt.value {
				t.Errorf("Kind%s = %d, want %d", tt.name, tt.kind, tt.value)
			}
		})
	}
}

func TestIsRegular(t *testing.T) {
	tests := []struct {
		kind int
		want bool
	}{
		{0, false},  // Metadata - replaceable
		{1, true},   // TextNote - regular
		{3, false},  // ContactList - replaceable
		{4, true},   // EncryptedDM - regular
		{5, true},   // Deletion - regular
		{1000, true}, // Regular range
		{9999, true}, // Regular range
		{10000, false}, // Replaceable range
		{19999, false}, // Replaceable range
		{20000, false}, // Ephemeral range
		{29999, false}, // Ephemeral range
		{30000, false}, // Addressable range
		{39999, false}, // Addressable range
		{40000, true},  // Back to regular
	}

	for _, tt := range tests {
		t.Run("kind_"+string(rune(tt.kind)), func(t *testing.T) {
			if got := IsRegular(tt.kind); got != tt.want {
				t.Errorf("IsRegular(%d) = %v, want %v", tt.kind, got, tt.want)
			}
		})
	}
}

func TestIsReplaceable(t *testing.T) {
	tests := []struct {
		kind int
		want bool
	}{
		{0, true},      // Metadata
		{1, false},     // TextNote
		{3, true},      // ContactList
		{10000, true},  // Replaceable range start
		{15000, true},  // Replaceable range middle
		{19999, true},  // Replaceable range end
		{20000, false}, // Ephemeral range
		{30000, false}, // Addressable range
	}

	for _, tt := range tests {
		t.Run("kind_"+string(rune(tt.kind)), func(t *testing.T) {
			if got := IsReplaceable(tt.kind); got != tt.want {
				t.Errorf("IsReplaceable(%d) = %v, want %v", tt.kind, got, tt.want)
			}
		})
	}
}

func TestIsEphemeral(t *testing.T) {
	tests := []struct {
		kind int
		want bool
	}{
		{1, false},     // TextNote
		{19999, false}, // Replaceable range
		{20000, true},  // Ephemeral range start
		{25000, true},  // Ephemeral range middle
		{29999, true},  // Ephemeral range end
		{30000, false}, // Addressable range
	}

	for _, tt := range tests {
		t.Run("kind_"+string(rune(tt.kind)), func(t *testing.T) {
			if got := IsEphemeral(tt.kind); got != tt.want {
				t.Errorf("IsEphemeral(%d) = %v, want %v", tt.kind, got, tt.want)
			}
		})
	}
}

func TestIsAddressable(t *testing.T) {
	tests := []struct {
		kind int
		want bool
	}{
		{1, false},     // TextNote
		{29999, false}, // Ephemeral range
		{30000, true},  // Addressable range start
		{35000, true},  // Addressable range middle
		{39999, true},  // Addressable range end
		{40000, false}, // Beyond addressable range
	}

	for _, tt := range tests {
		t.Run("kind_"+string(rune(tt.kind)), func(t *testing.T) {
			if got := IsAddressable(tt.kind); got != tt.want {
				t.Errorf("IsAddressable(%d) = %v, want %v", tt.kind, got, tt.want)
			}
		})
	}
}