logic_test.gno
1.25 Kb · 37 lines
1package logic
2
3import (
4 "testing"
5
6 logicv0 "gno.land/r/moul/x/upgrade/store/logic/v0"
7 root "gno.land/r/moul/x/upgrade/store/root/v0"
8
9 "gno.land/p/nt/uassert/v0"
10)
11
12// TestSwapLogic shows the upgrade: the counter survives it untouched, and only
13// the realm root currently points at may write.
14func TestSwapLogic(cur realm, t *testing.T) {
15 testing.SetRealm(testing.NewUserRealm(root.Ownable.Owner()))
16
17 // v0 is live out of the box.
18 uassert.Equal(t, 1, logicv0.Inc(cross(cur)))
19 uassert.Equal(t, 2, logicv0.Inc(cross(cur)))
20 uassert.AbortsContains(t, cur, "is not the live logic realm", func() {
21 Inc(cross(cur))
22 })
23
24 // The upgrade: one call, no migration.
25 root.SetLive(cross(cur), "gno.land/r/moul/x/upgrade/store/logic/v1")
26
27 // v1 writes on top of the data v0 left; v0 is locked out by the same gate.
28 uassert.Equal(t, 1002, Inc(cross(cur)), "v1 adds its own step to v0's data")
29 uassert.AbortsContains(t, cur, "is not the live logic realm", func() {
30 logicv0.Inc(cross(cur))
31 })
32
33 // Reads stay open to every version, live or not.
34 uassert.Equal(t, 1002, logicv0.Get(), "a retired version still reads the truth")
35 uassert.Equal(t, "store/logic/v1: counter=1002 step=1000\n", Render(""))
36 uassert.Equal(t, "store/logic/v0: counter=1002 step=1\n", logicv0.Render(""))
37}