lock_test.gno
1.40 Kb · 43 lines
1package lock
2
3import (
4 "testing"
5
6 v0 "gno.land/r/moul/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/moul/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/moul/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/moul/x/upgrade/lock/v1)\n", v0.Render(""))
43}