Kind Realm (renderable)
Name game_world
Namespace akkadia / beta
Exported functions 18
Module gno.land/r/akkadia/beta/game_world
gno 0.9 game_world_test.gno gno
⧉
1 package game_world 2 3 import ( 4 "chain" 5 "testing" 6 7 "gno.land/p/nt/uassert/v0" 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
10 func TestCreateGameWorldUsesCallerAsOwnerAndChargesExactCost(cur realm, t *testing.T) {
11 setupGameWorld(cross(cur), t)
12 setPolicyForTest(cross(cur), testGameTypeJump, 25 , CreationModePublicCreator)
13 collectorBefore := ugnotBalanceForTest(testFeeCollector)
14
15 id := createGameWorldForTest(cross(cur), testCreator, testGameTypeJump, chain.Coins{{ "ugnot" , 25 }})
16
17 uassert.Equal(t, uint64 ( 1 ), id)
18 uassert.Equal(t, uint64 ( 1 ), GetLatestGameWorldID())
19 world := GetGameWorld(id)
20 uassert.Equal(t, testCreator.String(), world.Owner.String())
21 uassert.Equal(t, testGameTypeJump, world.GameType)
22 uassert.Equal(t, int64 ( 25 ), ugnotBalanceForTest(testFeeCollector)-collectorBefore)
23 uassert.Equal(t, int64 ( 0 ), ugnotBalanceForTest(testPkgAddr))
24 }
25
26 func TestCreateGameWorldDoesNotRequirePersonalWorld(cur realm, t *testing.T) {
27 setupGameWorld(cross(cur), t)
28 setPolicyForTest(cross(cur), testGameTypeJump, 0 , CreationModePublicCreator)
29
30 uassert.True(t, HasGameWorld(createGameWorldForTest(cross(cur), testNoPersonal, testGameTypeJump, chain.Coins{})))
31 }
32
33 func TestOperatorOnlyCreationAllowsOperator(cur realm, t *testing.T) {
34 setupGameWorld(cross(cur), t)
35 setPolicyForTest(cross(cur), testGameTypeJump, 0 , CreationModeOperatorOnly)
36
37 uassert.True(t, HasGameWorld(createGameWorldForTest(cross(cur), testOperator, testGameTypeJump, chain.Coins{})))
38 }
39
40 func TestApprovedCreatorFlowAndRevocation(cur realm, t *testing.T) {
41 setupGameWorld(cross(cur), t)
42 setPolicyForTest(cross(cur), testGameTypeRace, 0 , CreationModeApprovedCreator)
43
44 uassert.AbortsWithMessage(t, cur, "creator is not approved for game type" , func () {
45 createGameWorldForTest(cross(cur), testCreator, testGameTypeRace, chain.Coins{})
46 })
47
48 testing.SetOriginCaller(testOperator)
49 testing.SetRealm(testing.NewUserRealm(testOperator))
50 AddApprovedCreator(cross(cur), testGameTypeRace, testCreator)
51 id := createGameWorldForTest(cross(cur), testCreator, testGameTypeRace, chain.Coins{})
52 uassert.True(t, HasGameWorld(id))
53
54 testing.SetOriginCaller(testOperator)
55 testing.SetRealm(testing.NewUserRealm(testOperator))
56 RemoveApprovedCreator(cross(cur), testGameTypeRace, testCreator)
57 uassert.True(t, HasGameWorld(id))
58 uassert.AbortsWithMessage(t, cur, "creator is not approved for game type" , func () {
59 createGameWorldForTest(cross(cur), testCreator, testGameTypeRace, chain.Coins{})
60 })
61 }
62
63 func TestCreateGameWorldRejectsInexactPayment(cur realm, t *testing.T) {
64 setupGameWorld(cross(cur), t)
65 setPolicyForTest(cross(cur), testGameTypeDrop, 25 , CreationModePublicCreator)
66
67 uassert.AbortsWithMessage(t, cur, "exact payment required: expected 25ugnot, got 24ugnot" , func () {
68 createGameWorldForTest(cross(cur), testCreator, testGameTypeDrop, chain.Coins{{ "ugnot" , 24 }})
69 })
70 uassert.Equal(t, uint64 ( 0 ), GetLatestGameWorldID())
71
72 uassert.AbortsWithMessage(t, cur, "exact payment required: expected 25ugnot, got 25ugnot,1foo" , func () {
73 createGameWorldForTest(cross(cur), testCreator, testGameTypeDrop, chain.Coins{{ "ugnot" , 25 }, { "foo" , 1 }})
74 })
75 uassert.Equal(t, uint64 ( 0 ), GetLatestGameWorldID())
76 }
77
78 func TestApprovedCreatorModeDoesNotImplicitlyApproveOperator(cur realm, t *testing.T) {
79 setupGameWorld(cross(cur), t)
80 setPolicyForTest(cross(cur), testGameTypeRace, 0 , CreationModeApprovedCreator)
81
82 uassert.AbortsWithMessage(t, cur, "creator is not approved for game type" , func () {
83 createGameWorldForTest(cross(cur), testOperator, testGameTypeRace, chain.Coins{})
84 })
85 }
86
87 func TestCreateGameWorldRejectsIDOverflow(cur realm, t *testing.T) {
88 setupGameWorld(cross(cur), t)
89 setPolicyForTest(cross(cur), testGameTypeJump, 0 , CreationModePublicCreator)
90 latestGameWorldID = uint64 ( 18446744073709551615 )
91
92 uassert.AbortsWithMessage(t, cur, "game world id exhausted" , func () {
93 createGameWorldForTest(cross(cur), testCreator, testGameTypeJump, chain.Coins{})
94 })
95 }
96
97 func TestListLatestGameWorldsByOwner(cur realm, t *testing.T) {
98 setupGameWorld(cross(cur), t)
99 setPolicyForTest(cross(cur), testGameTypeJump, 0 , CreationModePublicCreator)
100 firstID := createGameWorldForTest(cross(cur), testCreator, testGameTypeJump, chain.Coins{})
101 createGameWorldForTest(cross(cur), testOtherCreator, testGameTypeJump, chain.Coins{})
102 for i := 1 ; i <= gameWorldListLimit; i++ {
103 createGameWorldForTest(cross(cur), testCreator, testGameTypeJump, chain.Coins{})
104 }
105
106 worlds := ListLatestGameWorldsByOwner(testCreator)
107 uassert.Equal(t, gameWorldListLimit, len(worlds))
108 uassert.Equal(t, firstID+ 2 , worlds[ 0 ].ID)
109 uassert.Equal(t, firstID+ uint64 (gameWorldListLimit+ 1 ), worlds[len(worlds)- 1 ].ID)
110 uassert.Equal(t, testGameTypeJump, worlds[ 0 ].GameType)
111 uassert.Equal(t, 0 , len(ListLatestGameWorldsByOwner(address( "g1missing" ))))
112 }
113