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

timelock_test.gno

1.38 Kb · 43 lines
 1package timelock
 2
 3import (
 4	"testing"
 5
 6	"gno.land/p/nt/uassert/v0"
 7)
 8
 9func TestStateOf(t *testing.T) {
10	base := &Operation{ID: 1, Action: "upgrade", ReadyHeight: 100}
11
12	// Before ready height -> Pending.
13	uassert.Equal(t, StatePending, StateOf(base, 50))
14	// At/after ready height -> Ready.
15	uassert.Equal(t, StateReady, StateOf(base, 100))
16	uassert.Equal(t, StateReady, StateOf(base, 150))
17
18	// Executed and cancelled are terminal regardless of height.
19	done := &Operation{ID: 2, ReadyHeight: 10, Done: true}
20	uassert.Equal(t, StateExecuted, StateOf(done, 5))
21	uassert.Equal(t, StateExecuted, StateOf(done, 999))
22
23	cancelled := &Operation{ID: 3, ReadyHeight: 10, Cancelled: true}
24	uassert.Equal(t, StateCancelled, StateOf(cancelled, 5))
25	uassert.Equal(t, StateCancelled, StateOf(cancelled, 999))
26}
27
28func TestBlocksRemaining(t *testing.T) {
29	op := &Operation{ID: 1, ReadyHeight: 100}
30
31	uassert.Equal(t, int64(100), BlocksRemaining(op, 0))
32	uassert.Equal(t, int64(40), BlocksRemaining(op, 60))
33	// At ready height and beyond -> 0.
34	uassert.Equal(t, int64(0), BlocksRemaining(op, 100))
35	uassert.Equal(t, int64(0), BlocksRemaining(op, 250))
36}
37
38func TestPaddedKeyOrdering(t *testing.T) {
39	// Keys must be fixed-width so lexical order matches numeric id order.
40	uassert.True(t, paddedKey(2) < paddedKey(10))
41	uassert.True(t, paddedKey(9) < paddedKey(100))
42	uassert.Equal(t, len(paddedKey(1)), len(paddedKey(123456)))
43}