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.

lazy_test.gno

1.57 Kb · 44 lines
 1package lazy
 2
 3import (
 4	"testing"
 5
 6	v0 "gno.land/r/nym-moultest123/x/upgrade/lazy/v0"
 7
 8	"gno.land/p/nt/uassert/v0"
 9)
10
11// TestLazyMigration walks a record from v0 into v1 on first touch and checks
12// what the two halves of the read path report on either side of it.
13func TestLazyMigration(cur realm, t *testing.T) {
14	uassert.Equal(t, 1, Migrated(), "only v1's own seed has moved")
15	uassert.Equal(t, 2, Pending(), "both v0 records are untouched")
16
17	// Peek converts without storing: the answer is right, the state is not moved.
18	uassert.Equal(t, "v1{ada-migrated 1000 true}", Peek("ada").String())
19	uassert.Equal(t, 1, Migrated(), "Peek must not migrate")
20
21	// Get migrates.
22	uassert.Equal(t, "v1{ada-migrated 1000 true}", Get(cross(cur), "ada").String())
23	uassert.Equal(t, 2, Migrated(), "ada has moved over")
24	uassert.Equal(t, 1, Pending())
25
26	// Migrating COPIES: v0 still holds (and still pays for) the original.
27	uassert.Equal(t, 2, v0.Size(), "v0 never shrinks")
28	uassert.Equal(t, "v0{ada 1}", v0.Get("ada").String())
29
30	// A second Get is a plain hit, not a second migration.
31	uassert.Equal(t, "v1{ada-migrated 1000 true}", Get(cross(cur), "ada").String())
32	uassert.Equal(t, 2, Migrated())
33
34	// A key in neither version is nil in both halves.
35	uassert.True(t, Get(cross(cur), "zoe") == nil)
36	uassert.True(t, Peek("zoe") == nil)
37
38	// v1's own records are untouched by any of this.
39	uassert.Equal(t, "v1{cyd 3000 true}", Get(cross(cur), "cyd").String())
40
41	uassert.Equal(t, "lazy/v1: 2 migrated, 1 pending in v0\n"+
42		"- ada: v1{ada-migrated 1000 true}\n"+
43		"- cyd: v1{cyd 3000 true}\n", Render(""))
44}