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.

setup_test.gno

1.99 Kb · 70 lines
 1package game_world
 2
 3import (
 4	"chain"
 5	"chain/banker"
 6	"testing"
 7
 8	"gno.land/p/nt/testutils/v0"
 9	"gno.land/r/akkadia/beta/admin"
10)
11
12var (
13	testAdmin        = testutils.TestAddress("gwAdmin")
14	testOperator     = testutils.TestAddress("gwOperator")
15	testCreator      = testutils.TestAddress("gwCreator")
16	testOtherCreator = testutils.TestAddress("gwOtherCreator")
17	testRestricted   = testutils.TestAddress("gwRestricted")
18	testNoPersonal   = testutils.TestAddress("gwNoPersonal")
19	testFeeCollector = testutils.TestAddress("gwFeeCollector")
20	testPkgAddr      = chain.PackageAddress("gno.land/r/akkadia/beta/game_world")
21	setupDone        bool
22)
23
24const (
25	testGameTypeDungeon = "instance_dungeon"
26	testGameTypeJump    = "jump_map"
27	testGameTypeRace    = "race_map"
28	testGameTypeDrop    = "drop_map"
29)
30
31func setupGameWorld(cur realm, t *testing.T) {
32	t.Helper()
33	resetGameWorldState()
34	testing.SetOriginSend(chain.Coins{})
35
36	if setupDone {
37		return
38	}
39	originalAdmin := admin.GetAdmin()
40	testing.SetOriginCaller(originalAdmin)
41	testing.SetRealm(testing.NewUserRealm(originalAdmin))
42	admin.TransferAdmin(cross(cur), testAdmin)
43
44	testing.SetOriginCaller(testAdmin)
45	testing.SetRealm(testing.NewUserRealm(testAdmin))
46	admin.AcceptAdmin(cross(cur))
47	admin.SetOperator(cross(cur), testOperator)
48	admin.SetFeeCollector(cross(cur), testFeeCollector)
49	setupDone = true
50}
51
52func setPolicyForTest(cur realm, gameType string, cost int64, mode CreationMode) {
53	testing.SetOriginCaller(testOperator)
54	testing.SetRealm(testing.NewUserRealm(testOperator))
55	SetGameTypePolicy(cross(cur), gameType, cost, mode)
56}
57
58func createGameWorldForTest(cur realm, creator address, gameType string, coins chain.Coins) uint64 {
59	testing.SetOriginCaller(creator)
60	testing.SetRealm(testing.NewUserRealm(creator))
61	if len(coins) > 0 {
62		testing.IssueCoins(testPkgAddr, coins)
63	}
64	testing.SetOriginSend(coins)
65	return CreateGameWorld(cross(cur), gameType)
66}
67
68func ugnotBalanceForTest(addr address) int64 {
69	return banker.NewReadonlyBanker().GetCoins(addr).AmountOf("ugnot")
70}