@@ -54,7 +54,7 @@ func TestNewPoolTier(t *testing.T) {
5454
5555func TestCacheReward(t *testing.T) {
5656 currentHeight := int64(250)
57- currentTime := int64(250000) // Arbitrary time for testing
57+ currentTime := int64(250000)
5858 // Simulate emission updates
5959 poolTier := NewPoolTier(NewPools(), currentHeight, currentTime, "testPool", func() int64 { return 1000 }, func(startHeight int64, endHeight int64) ([]int64, []int64) {
6060 return []int64{100, 150, 200}, []int64{1000, 500, 250}
@@ -78,3 +78,156 @@ func SetupPoolTier(t *testing.T) *PoolTier {
7878 poolTier.changeTier(1, int64(1000), pools, test_gnousdc, 1)
7979 return poolTier
8080}
81+
82+ func TestTierRatioGet(t *testing.T) {
83+ ratio := TierRatio{Tier1: 50, Tier2: 30, Tier3: 20}
84+
85+ tests := []struct {
86+ tier uint64
87+ expected uint64
88+ }{
89+ {1, 50},
90+ {2, 30},
91+ {3, 20},
92+ }
93+
94+ for _, tt := range tests {
95+ result := ratio.Get(tt.tier)
96+ if result != tt.expected {
97+ t.Errorf("Get(%d) = %d; want %d", tt.tier, result, tt.expected)
98+ }
99+ }
100+
101+ // Test panic for invalid tier
102+ defer func() {
103+ if r := recover(); r == nil {
104+ t.Errorf("Get(4) should panic for invalid tier")
105+ }
106+ }()
107+ ratio.Get(4)
108+ }
109+
110+ func TestPoolTierChangeTier(t *testing.T) {
111+ pools := NewPools()
112+ currentHeight := int64(100)
113+ currentTime := int64(100000)
114+ testPool1 := pl.GetPoolPath("gno.land/r/onbloc/bar", "gno.land/r/onbloc/baz", 3000)
115+ testPool2 := pl.GetPoolPath("gno.land/r/onbloc/foo", "gno.land/r/onbloc/qux", 3000)
116+
117+ poolTier := NewPoolTier(pools, currentHeight, currentTime, testPool1,
118+ func() int64 { return 1000000 },
119+ func(start, end int64) ([]int64, []int64) { return nil, nil })
120+
121+ // Add second pool to tier 2
122+ pools.set(testPool2, NewPool(testPool2, currentTime+1))
123+ poolTier.changeTier(currentHeight+1, currentTime+1, pools, testPool2, 2)
124+
125+ // Verify tier assignments
126+ if tier := poolTier.CurrentTier(testPool1); tier != 1 {
127+ t.Errorf("Expected pool1 to be in tier 1, got %d", tier)
128+ }
129+ if tier := poolTier.CurrentTier(testPool2); tier != 2 {
130+ t.Errorf("Expected pool2 to be in tier 2, got %d", tier)
131+ }
132+
133+ // Verify ratio changed to 70/30/0
134+ if poolTier.tierRatio.Tier1 != 70 || poolTier.tierRatio.Tier2 != 30 || poolTier.tierRatio.Tier3 != 0 {
135+ t.Errorf("Expected ratio 70/30/0, got %d/%d/%d",
136+ poolTier.tierRatio.Tier1, poolTier.tierRatio.Tier2, poolTier.tierRatio.Tier3)
137+ }
138+
139+ // Test removing pool from tier (tier 0)
140+ poolTier.changeTier(currentHeight+2, currentTime+2, pools, testPool2, 0)
141+ if tier := poolTier.CurrentTier(testPool2); tier != 0 {
142+ t.Errorf("Expected pool2 to be removed (tier 0), got %d", tier)
143+ }
144+ }
145+
146+ func TestCurrentAllTierCounts(t *testing.T) {
147+ pools := NewPools()
148+ currentHeight := int64(100)
149+ currentTime := int64(100000)
150+ testPool1 := pl.GetPoolPath("gno.land/r/onbloc/bar", "gno.land/r/onbloc/baz", 3000)
151+ testPool2 := pl.GetPoolPath("gno.land/r/onbloc/foo", "gno.land/r/onbloc/qux", 3000)
152+ testPool3 := pl.GetPoolPath("gno.land/r/demo/wugnot", "gno.land/r/onbloc/bar", 3000)
153+
154+ poolTier := NewPoolTier(pools, currentHeight, currentTime, testPool1,
155+ func() int64 { return 1000000 },
156+ func(start, end int64) ([]int64, []int64) { return nil, nil })
157+
158+ // Add pools to different tiers
159+ pools.set(testPool2, NewPool(testPool2, currentTime+1))
160+ poolTier.changeTier(currentHeight+1, currentTime+1, pools, testPool2, 2)
161+
162+ pools.set(testPool3, NewPool(testPool3, currentTime+2))
163+ poolTier.changeTier(currentHeight+2, currentTime+2, pools, testPool3, 3)
164+
165+ counts := poolTier.CurrentAllTierCounts()
166+
167+ // Should be [0, 1, 1, 1] for tiers 0, 1, 2, 3
168+ expected := []uint64{0, 1, 1, 1}
169+ for i, count := range counts {
170+ if count != expected[i] {
171+ t.Errorf("Tier %d count = %d; want %d", i, count, expected[i])
172+ }
173+ }
174+ }
175+
176+ func TestIsInternallyIncentivizedPool(t *testing.T) {
177+ pools := NewPools()
178+ currentHeight := int64(100)
179+ currentTime := int64(100000)
180+ testPool1 := pl.GetPoolPath("gno.land/r/onbloc/bar", "gno.land/r/onbloc/baz", 3000)
181+ testPool2 := pl.GetPoolPath("gno.land/r/onbloc/foo", "gno.land/r/onbloc/qux", 3000)
182+
183+ poolTier := NewPoolTier(pools, currentHeight, currentTime, testPool1,
184+ func() int64 { return 1000000 },
185+ func(start, end int64) ([]int64, []int64) { return nil, nil })
186+
187+ // testPool1 is in tier 1, should be incentivized
188+ if !poolTier.IsInternallyIncentivizedPool(testPool1) {
189+ t.Errorf("Expected pool1 to be internally incentivized")
190+ }
191+
192+ // testPool2 is not in any tier, should not be incentivized
193+ if poolTier.IsInternallyIncentivizedPool(testPool2) {
194+ t.Errorf("Expected pool2 to not be internally incentivized")
195+ }
196+ }
197+
198+ func TestCurrentRewardPerPool(t *testing.T) {
199+ pools := NewPools()
200+ currentHeight := int64(100)
201+ currentTime := int64(100000)
202+ emission := int64(1000000)
203+ testPool1 := pl.GetPoolPath("gno.land/r/onbloc/bar", "gno.land/r/onbloc/baz", 3000)
204+ testPool2 := pl.GetPoolPath("gno.land/r/onbloc/foo", "gno.land/r/onbloc/qux", 3000)
205+
206+ poolTier := NewPoolTier(pools, currentHeight, currentTime, testPool1,
207+ func() int64 { return emission },
208+ func(start, end int64) ([]int64, []int64) { return nil, nil })
209+
210+ // With only tier 1 pool, it should get 100% of emission
211+ reward1 := poolTier.CurrentRewardPerPool(testPool1)
212+ expectedReward1 := emission * 100 / 100 / 1 // 100% ratio, 1 pool
213+ if reward1 != expectedReward1 {
214+ t.Errorf("Expected reward %d, got %d", expectedReward1, reward1)
215+ }
216+
217+ // Add pool to tier 2
218+ pools.set(testPool2, NewPool(testPool2, currentTime+1))
219+ poolTier.changeTier(currentHeight+1, currentTime+1, pools, testPool2, 2)
220+
221+ // Now tier1 gets 70%, tier2 gets 30%
222+ reward1After := poolTier.CurrentRewardPerPool(testPool1)
223+ expectedReward1After := emission * 70 / 100 / 1 // 70% ratio, 1 pool
224+ if reward1After != expectedReward1After {
225+ t.Errorf("Expected tier1 reward %d, got %d", expectedReward1After, reward1After)
226+ }
227+
228+ reward2 := poolTier.CurrentRewardPerPool(testPool2)
229+ expectedReward2 := emission * 30 / 100 / 1 // 30% ratio, 1 pool
230+ if reward2 != expectedReward2 {
231+ t.Errorf("Expected tier2 reward %d, got %d", expectedReward2, reward2)
232+ }
233+ }
0 commit comments