Kind Realm (renderable)
Name game_world
Namespace akkadia / beta
Exported functions 18
Module gno.land/r/akkadia/beta/game_world
gno 0.9 policy_test.gno gno
⧉
1 package game_world 2 3 import ( 4 "testing" 5 6 "gno.land/p/nt/uassert/v0" 7 ) 8 AddApprovedCreator (cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, gameType string, creator string)
CreateGameWorld (cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, gameType string) uint64
GetApprovedCreatorCount (gameType string) int
GetGameTypePolicy (gameType string) struct{CreationCost int64; CreationMode gno.land/r/akkadia/beta/game_world.CreationMode}
GetGameWorld (gameWorldID uint64) struct{ID uint64; Owner .uverse.address; GameType string; Status gno.land/r/akkadia/beta/game_world.GameWorldStatus; CreatedHeight int64; RestrictedHeight int64}
GetLatestGameWorldID () uint64
GetListLimit () int
GetRestrictedGameWorldCount () int
HasGameTypePolicy (gameType string) bool
HasGameWorld (gameWorldID uint64) bool
IsApprovedCreator (gameType string, creator string) bool
ListApprovedCreators (gameType string, offset int, count int) [].uverse.address
ListLatestGameWorldsByOwner (owner string) []gno.land/r/akkadia/beta/game_world.GameWorld
ListRestrictedGameWorldIDs (page int, count int) []uint64
RemoveApprovedCreator (cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, gameType string, creator string)
RestrictGameWorld (cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, gameWorldID uint64)
SetApprovedCreators (cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, gameType string, creatorsCSV string, approved bool)
SetGameTypePolicy (cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, gameType string, creationCost int64, mode int)
Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.
Render unavailable
rate limit exceeded — the render query is served by the Gnoland archive RPC.
vm/qrender output, sanitized (docs/render-security.md) and displayed in an empty-sandbox iframe — scripts, forms and popups cannot run. Links stay inert in-preview; right-click to open.
9 func TestGameTypePoliciesStartEmptyAndAdminRegistersOpaqueKey(cur realm, t *testing.T) {
10 setupGameWorld(cross(cur), t)
11 uassert.False(t, HasGameTypePolicy(testGameTypeDungeon))
12 uassert.False(t, HasGameTypePolicy(testGameTypeJump))
13
14 testing.SetOriginCaller(testOperator)
15 testing.SetRealm(testing.NewUserRealm(testOperator))
16 SetGameTypePolicy(cross(cur), "custom_type_alpha" , 17 , CreationModeApprovedCreator)
17
18 uassert.True(t, HasGameTypePolicy( "custom_type_alpha" ))
19 policy := GetGameTypePolicy( "custom_type_alpha" )
20 uassert.Equal(t, int64 ( 17 ), policy.CreationCost)
21 uassert.Equal(t, int (CreationModeApprovedCreator), int (policy.CreationMode))
22 }
23
24 func TestApprovedCreatorIsManagedPerOpaqueKey(cur realm, t *testing.T) {
25 setupGameWorld(cross(cur), t)
26 setPolicyForTest(cross(cur), testGameTypeJump, 0 , CreationModeApprovedCreator)
27 setPolicyForTest(cross(cur), testGameTypeRace, 0 , CreationModeApprovedCreator)
28 testing.SetOriginCaller(testOperator)
29 testing.SetRealm(testing.NewUserRealm(testOperator))
30
31 AddApprovedCreator(cross(cur), testGameTypeJump, testCreator)
32 uassert.True(t, IsApprovedCreator(testGameTypeJump, testCreator))
33 uassert.False(t, IsApprovedCreator(testGameTypeRace, testCreator))
34
35 RemoveApprovedCreator(cross(cur), testGameTypeJump, testCreator)
36 uassert.False(t, IsApprovedCreator(testGameTypeJump, testCreator))
37 }
38
39 func TestAddAndRemoveApprovedCreator(cur realm, t *testing.T) {
40 setupGameWorld(cross(cur), t)
41 setPolicyForTest(cross(cur), testGameTypeJump, 0 , CreationModeApprovedCreator)
42 testing.SetOriginCaller(testOperator)
43 testing.SetRealm(testing.NewUserRealm(testOperator))
44
45 AddApprovedCreator(cross(cur), testGameTypeJump, testCreator)
46 uassert.True(t, IsApprovedCreator(testGameTypeJump, testCreator))
47
48 RemoveApprovedCreator(cross(cur), testGameTypeJump, testCreator)
49 uassert.False(t, IsApprovedCreator(testGameTypeJump, testCreator))
50 }
51
52 func TestSetApprovedCreatorsBulk(cur realm, t *testing.T) {
53 setupGameWorld(cross(cur), t)
54 setPolicyForTest(cross(cur), testGameTypeJump, 0 , CreationModeApprovedCreator)
55 testing.SetOriginCaller(testOperator)
56 testing.SetRealm(testing.NewUserRealm(testOperator))
57 creatorsCSV := testCreator.String() + "," + testOtherCreator.String()
58
59 SetApprovedCreators(cross(cur), testGameTypeJump, creatorsCSV, true )
60 uassert.True(t, IsApprovedCreator(testGameTypeJump, testCreator))
61 uassert.True(t, IsApprovedCreator(testGameTypeJump, testOtherCreator))
62
63 SetApprovedCreators(cross(cur), testGameTypeJump, creatorsCSV, false )
64 uassert.False(t, IsApprovedCreator(testGameTypeJump, testCreator))
65 uassert.False(t, IsApprovedCreator(testGameTypeJump, testOtherCreator))
66 }
67
68 func TestSetApprovedCreatorsRejectsInvalidAndEmptyCSV(cur realm, t *testing.T) {
69 setupGameWorld(cross(cur), t)
70 setPolicyForTest(cross(cur), testGameTypeJump, 0 , CreationModeApprovedCreator)
71 testing.SetOriginCaller(testOperator)
72 testing.SetRealm(testing.NewUserRealm(testOperator))
73
74 uassert.AbortsWithMessage(t, cur, "invalid creator address" , func () {
75 SetApprovedCreators(cross(cur), testGameTypeJump, testCreator.String()+ ",invalid" , true )
76 })
77
78 setupGameWorld(cross(cur), t)
79 setPolicyForTest(cross(cur), testGameTypeJump, 0 , CreationModeApprovedCreator)
80 testing.SetOriginCaller(testOperator)
81 testing.SetRealm(testing.NewUserRealm(testOperator))
82 uassert.AbortsWithMessage(t, cur, "creator list must not be empty" , func () {
83 SetApprovedCreators(cross(cur), testGameTypeJump, "" , true )
84 })
85 }
86
87 func TestSetApprovedCreatorsAllowsDuplicateAddresses(cur realm, t *testing.T) {
88 setupGameWorld(cross(cur), t)
89 setPolicyForTest(cross(cur), testGameTypeJump, 0 , CreationModeApprovedCreator)
90 testing.SetOriginCaller(testOperator)
91 testing.SetRealm(testing.NewUserRealm(testOperator))
92 creatorsCSV := testCreator.String() + "," + testCreator.String()
93
94 SetApprovedCreators(cross(cur), testGameTypeJump, creatorsCSV, true )
95 uassert.True(t, IsApprovedCreator(testGameTypeJump, testCreator))
96 uassert.Equal(t, 1 , GetApprovedCreatorCount(testGameTypeJump))
97
98 SetApprovedCreators(cross(cur), testGameTypeJump, creatorsCSV, false )
99 uassert.False(t, IsApprovedCreator(testGameTypeJump, testCreator))
100 }
101
102 func TestSetApprovedCreatorsRejectsEmptyEntryAndOversizedBatch(cur realm, t *testing.T) {
103 setupGameWorld(cross(cur), t)
104 setPolicyForTest(cross(cur), testGameTypeJump, 0 , CreationModeApprovedCreator)
105 testing.SetOriginCaller(testOperator)
106 testing.SetRealm(testing.NewUserRealm(testOperator))
107
108 uassert.AbortsWithMessage(t, cur, "invalid creator address" , func () {
109 SetApprovedCreators(cross(cur), testGameTypeJump, testCreator.String()+ "," , true )
110 })
111
112 setupGameWorld(cross(cur), t)
113 setPolicyForTest(cross(cur), testGameTypeJump, 0 , CreationModeApprovedCreator)
114 testing.SetOriginCaller(testOperator)
115 testing.SetRealm(testing.NewUserRealm(testOperator))
116 creatorsCSV := testCreator.String()
117 for i := 1 ; i < 101 ; i++ {
118 creatorsCSV += "," + testCreator.String()
119 }
120 uassert.AbortsWithMessage(t, cur, "creator list exceeds limit" , func () {
121 SetApprovedCreators(cross(cur), testGameTypeJump, creatorsCSV, true )
122 })
123 }
124
125 func TestListApprovedCreatorsSupportsManagementProjection(cur realm, t *testing.T) {
126 setupGameWorld(cross(cur), t)
127 setPolicyForTest(cross(cur), testGameTypeDrop, 0 , CreationModeApprovedCreator)
128 testing.SetOriginCaller(testOperator)
129 testing.SetRealm(testing.NewUserRealm(testOperator))
130 AddApprovedCreator(cross(cur), testGameTypeDrop, testCreator)
131 AddApprovedCreator(cross(cur), testGameTypeDrop, testOtherCreator)
132
133 uassert.Equal(t, 2 , GetApprovedCreatorCount(testGameTypeDrop))
134 listed := ListApprovedCreators(testGameTypeDrop, 0 , 100 )
135 uassert.Equal(t, 2 , len(listed))
136 uassert.True(t, containsApprovedCreator(listed, testCreator))
137 uassert.True(t, containsApprovedCreator(listed, testOtherCreator))
138 }
139
140 func containsApprovedCreator(creators []address, target address) bool {
141 for _, creator := range creators {
142 if creator == target {
143 return true
144 }
145 }
146 return false
147 }
148
149 func TestSetGameTypePolicyRejectsUnauthorizedCaller(cur realm, t *testing.T) {
150 setupGameWorld(cross(cur), t)
151 testing.SetOriginCaller(testCreator)
152 testing.SetRealm(testing.NewUserRealm(testCreator))
153
154 uassert.AbortsWithMessage(t, cur, "admin or operator access required" , func () {
155 SetGameTypePolicy(cross(cur), testGameTypeJump, 10 , CreationModeApprovedCreator)
156 })
157 }
158
159 func TestSetGameTypePolicyValidatesOpaqueKeyAndPolicy(cur realm, t *testing.T) {
160 setupGameWorld(cross(cur), t)
161 testing.SetOriginCaller(testOperator)
162 testing.SetRealm(testing.NewUserRealm(testOperator))
163
164 uassert.AbortsWithMessage(t, cur, "game type key length must be between 1 and 64" , func () {
165 SetGameTypePolicy(cross(cur), "" , 0 , CreationModeOperatorOnly)
166 })
167 uassert.AbortsWithMessage(t, cur, "game type key length must be between 1 and 64" , func () {
168 SetGameTypePolicy(cross(cur), "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" , 0 , CreationModeOperatorOnly)
169 })
170 uassert.AbortsWithMessage(t, cur, "invalid game type key" , func () {
171 SetGameTypePolicy(cross(cur), "Jump Map" , 0 , CreationModeOperatorOnly)
172 })
173 uassert.AbortsWithMessage(t, cur, "creation cost must not be negative" , func () {
174 SetGameTypePolicy(cross(cur), testGameTypeJump, - 1 , CreationModeOperatorOnly)
175 })
176 uassert.AbortsWithMessage(t, cur, "invalid creation mode" , func () {
177 SetGameTypePolicy(cross(cur), testGameTypeJump, 0 , CreationModeInvalid)
178 })
179 }
180
181 func TestUnregisteredGameTypeIsRejected(cur realm, t *testing.T) {
182 setupGameWorld(cross(cur), t)
183 testing.SetOriginCaller(testCreator)
184 testing.SetRealm(testing.NewUserRealm(testCreator))
185
186 uassert.AbortsWithMessage(t, cur, "game type policy not found: unknown_type" , func () {
187 CreateGameWorld(cross(cur), "unknown_type" )
188 })
189
190 testing.SetOriginCaller(testOperator)
191 testing.SetRealm(testing.NewUserRealm(testOperator))
192 uassert.AbortsWithMessage(t, cur, "game type policy not found: unknown_type" , func () {
193 AddApprovedCreator(cross(cur), "unknown_type" , testCreator)
194 })
195 }
196