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

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

lock_test.gno

1.45 Kb · 43 lines
 1package lock
 2
 3import (
 4	"testing"
 5
 6	v0 "gno.land/r/nym-moultest123/x/upgrade/lock/v0"
 7
 8	"gno.land/p/nt/uassert/v0"
 9)
10
11// TestHandover walks the whole one-writer-at-a-time sequence in order: only v0
12// writes, then the retirement flips it, then only v1 writes.
13func TestHandover(cur realm, t *testing.T) {
14	testing.SetRealm(testing.NewUserRealm(v0.Ownable.Owner()))
15
16	// Before the handover: v0 writes, v1 refuses.
17	v0.Inc(cross(cur), 10)
18	uassert.False(t, Live(), "v1 must not be live before the handover")
19	uassert.AbortsContains(t, cur, "not live yet", func() {
20		Inc(cross(cur), 1)
21	})
22	uassert.Equal(t, 10, Get(), "v1 already reports v0's running total")
23
24	// The handover itself.
25	v0.Retire(cross(cur), "gno.land/r/nym-moultest123/x/upgrade/lock/v1")
26	uassert.True(t, Live(), "v1 must be live once v0 names it")
27
28	// After: v0 refuses, v1 writes, the total is single-valued.
29	uassert.AbortsContains(t, cur, "is retired", func() {
30		v0.Inc(cross(cur), 1)
31	})
32	Inc(cross(cur), 100)
33	uassert.Equal(t, 110, Get(), "v1 folds v0's frozen total into its own")
34	uassert.Equal(t, 10, v0.Get(), "v0's total is frozen where it stopped")
35
36	// Retirement is one-way.
37	uassert.AbortsContains(t, cur, "already retired", func() {
38		v0.Retire(cross(cur), "gno.land/r/nym-moultest123/x/upgrade/lock/v2")
39	})
40
41	uassert.Equal(t, "lock/v1: 110 (own 100 + retired v0 10)\n", Render(""))
42	uassert.Equal(t, "lock/v0: 10 (retired, use gno.land/r/nym-moultest123/x/upgrade/lock/v1)\n", v0.Render(""))
43}