Skip to content Search Apps Documentation Source Content Run Reset Eval Playground 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.

owner_test.gno

3.49 Kb · 92 lines
 1package arena
 2
 3import (
 4	"testing"
 5
 6	"gno.land/p/nt/ownable/v0"
 7	"gno.land/p/nt/uassert/v0"
 8	"gno.land/r/nym-gfanton001/gnomepit/standings/v0"
 9)
10
11// Under gno test, init's deployer address is empty, so each test sets the owner itself.
12
13func TestRetireIsOwnerOnly(cur realm, t *testing.T) {
14	reset()
15	owner = ownable.NewWithAddress(alice)
16
17	testing.SetRealm(testing.NewUserRealm(bob))
18	uassert.AbortsWithMessage(t, cur, "ownable: caller is not owner", func() { Retire(cross(cur)) })
19	uassert.AbortsWithMessage(t, cur, "ownable: caller is not owner", func() { TransferOwnership(cross(cur), bob) })
20	uassert.False(t, Retired())
21	uassert.Equal(t, alice, Owner())
22
23	testing.SetRealm(testing.NewUserRealm(alice))
24	Retire(cross(cur))
25	uassert.True(t, Retired())
26	TransferOwnership(cross(cur), bob)
27	uassert.Equal(t, bob, Owner())
28}
29
30func TestRetiredArenaRefusesNewMatches(cur realm, t *testing.T) {
31	reset()
32	owner = ownable.NewWithAddress(alice)
33	testing.SetRealm(testing.NewUserRealm(alice))
34	id := Challenge(cross(cur), "Pickers", sealOf(saltA, deckA), sealOf(salt1, picks), boxOf("box1"), "")
35	Retire(cross(cur))
36
37	uassert.AbortsWithMessage(t, cur, "arena retired", func() {
38		Challenge(cross(cur), "Pickers", sealOf(saltA, deckA), sealOf(salt1, picks), boxOf("box1"), "")
39	})
40	testing.SetRealm(testing.NewUserRealm(bob))
41	uassert.AbortsWithMessage(t, cur, "arena retired", func() { Accept(cross(cur), id, "Ironhide", deckB, braces) })
42}
43
44func TestRetiredArenaFinishesItsMatches(cur realm, t *testing.T) {
45	reset()
46	owner = ownable.NewWithAddress(alice)
47	a1, b1 := "Chalk Dust,Double Tap", "Hammer Blow,Spiked Shield"
48	testing.SetRealm(testing.NewUserRealm(alice))
49	open := Challenge(cross(cur), "Pickers", sealOf(saltA, deckA), sealOf(salt1, picks), boxOf("box1"), "")
50	running := Challenge(cross(cur), "Pickers", sealOf(saltA, deckA), sealOf(salt1, a1), boxOf("box1"), "")
51	stalled := Challenge(cross(cur), "Pickers", sealOf(saltA, deckA), sealOf(salt1, picks), boxOf("box1"), "")
52	testing.SetRealm(testing.NewUserRealm(bob))
53	Accept(cross(cur), running, "Ironhide", deckB, b1)
54	Accept(cross(cur), stalled, "Ironhide", deckB, braces)
55	testing.SetRealm(testing.NewUserRealm(alice))
56	Reveal(cross(cur), running, deckA, saltA, a1, salt1, sealOf(salt2, picks), boxOf("box2"))
57	Retire(cross(cur))
58
59	testing.SetRealm(testing.NewUserRealm(bob))
60	Play(cross(cur), running, braces)
61	testing.SetRealm(testing.NewUserRealm(alice))
62	Reveal(cross(cur), running, "", "", picks, salt2, sealOf(salt3, picks), boxOf("box3"))
63	uassert.Equal(t, "play", Match(running).Phase)
64	testing.SetRealm(testing.NewUserRealm(bob))
65	Resign(cross(cur), running)
66	uassert.Equal(t, "resign", Match(running).Reason)
67
68	testing.SkipHeights(day + 1)
69	testing.SetRealm(testing.NewUserRealm(carol))
70	ClaimForfeit(cross(cur), stalled)
71	uassert.Equal(t, "forfeit", Match(stalled).Reason)
72
73	testing.SetRealm(testing.NewUserRealm(alice))
74	Resign(cross(cur), open)
75	uassert.Equal(t, 0, len(Open(0, 50)), "the open challenge is withdrawn")
76}
77
78func TestRetiredArenaStillRates(cur realm, t *testing.T) {
79	reset()
80	owner = ownable.NewWithAddress(alice)
81	testing.SetRealm(testing.NewUserRealm(alice))
82	id := Challenge(cross(cur), "Pickers", sealOf(saltA, deckA), sealOf(salt1, picks), boxOf("box1"), "")
83	testing.SetRealm(testing.NewUserRealm(bob))
84	Accept(cross(cur), id, "Ironhide", deckB, braces)
85	testing.SetRealm(testing.NewUserRealm(alice))
86	Retire(cross(cur))
87
88	before := standings.ResultCount()
89	testing.SetRealm(testing.NewUserRealm(bob))
90	Resign(cross(cur), id)
91	uassert.Equal(t, before+1, standings.ResultCount())
92}