Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

staking_test.gno

1.00 Kb · 32 lines
 1package staking
 2
 3import (
 4	"testing"
 5
 6	"gno.land/p/nt/uassert/v0"
 7)
 8
 9func TestComputeRewardPerToken(t *testing.T) {
10	// No stakers: accumulator is frozen at its stored value.
11	uassert.Equal(t, uint64(42), computeRewardPerToken(42, 100, 10, 0))
12
13	// rate=100, elapsed=2, total=200, precision=1e6 => 100*2*1e6/200 = 1e6.
14	uassert.Equal(t, precision, computeRewardPerToken(0, 100, 2, 200))
15
16	// Accumulation builds on the stored value.
17	uassert.Equal(t, 2*precision, computeRewardPerToken(precision, 100, 2, 200))
18}
19
20func TestComputeEarned(t *testing.T) {
21	// balance=50, delta=precision => 50*1e6/1e6 = 50.
22	uassert.Equal(t, uint64(50), computeEarned(50, precision, 0, 0))
23
24	// Prior accrual is added on top.
25	uassert.Equal(t, uint64(57), computeEarned(50, precision, 0, 7))
26
27	// Only the un-paid portion of the accumulator counts.
28	uassert.Equal(t, uint64(50), computeEarned(50, 3*precision, 2*precision, 0))
29
30	// Zero stake earns only what was already accrued.
31	uassert.Equal(t, uint64(9), computeEarned(0, 5*precision, 0, 9))
32}