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

3.58 Kb · 104 lines
  1package game_vault
  2
  3import (
  4	"chain"
  5	"testing"
  6
  7	"gno.land/p/nt/testutils/v0"
  8	"gno.land/r/akkadia/beta/admin"
  9	gameworld "gno.land/r/akkadia/beta/game_world"
 10)
 11
 12var vaultTest = &vaultTestHelper{
 13	Admin:    testutils.TestAddress("vaultAdmin"),
 14	Operator: testutils.TestAddress("vaultOperator"),
 15	Owner:    testutils.TestAddress("vaultOwner"),
 16	Player1:  testutils.TestAddress("vaultPlayer1"),
 17	Player2:  testutils.TestAddress("vaultPlayer2"),
 18}
 19
 20type vaultTestHelper struct {
 21	Admin       address
 22	Operator    address
 23	Owner       address
 24	Player1     address
 25	Player2     address
 26	GameWorldID uint64
 27	setupDone   bool
 28}
 29
 30func (h *vaultTestHelper) Setup(cur realm, t *testing.T) {
 31	t.Helper()
 32	resetGameVaultState()
 33	testing.SetOriginSend(chain.Coins{})
 34	if h.setupDone {
 35		return
 36	}
 37
 38	originalAdmin := admin.GetAdmin()
 39	testing.SetOriginCaller(originalAdmin)
 40	testing.SetRealm(testing.NewUserRealm(originalAdmin))
 41	admin.TransferAdmin(cross(cur), h.Admin)
 42
 43	testing.SetOriginCaller(h.Admin)
 44	testing.SetRealm(testing.NewUserRealm(h.Admin))
 45	admin.AcceptAdmin(cross(cur))
 46	admin.SetOperator(cross(cur), h.Operator)
 47
 48	testing.SetOriginCaller(h.Operator)
 49	testing.SetRealm(testing.NewUserRealm(h.Operator))
 50	gameworld.SetGameTypePolicy(cross(cur), "vault_test", 0, gameworld.CreationModePublicCreator)
 51
 52	testing.SetOriginCaller(h.Owner)
 53	testing.SetRealm(testing.NewUserRealm(h.Owner))
 54	h.GameWorldID = gameworld.CreateGameWorld(cross(cur), "vault_test")
 55	h.setupDone = true
 56}
 57
 58func (h *vaultTestHelper) CreatePool(cur realm, key string) uint64 {
 59	testing.SetOriginCaller(h.Operator)
 60	testing.SetRealm(testing.NewUserRealm(h.Operator))
 61	testing.SetOriginSend(chain.Coins{})
 62	return CreateRewardPool(cross(cur), key, h.GameWorldID)
 63}
 64
 65func (h *vaultTestHelper) CreateParticipationProcess(cur realm, key, poolKey string, fee int64) uint64 {
 66	testing.SetOriginCaller(h.Operator)
 67	testing.SetRealm(testing.NewUserRealm(h.Operator))
 68	testing.SetOriginSend(chain.Coins{})
 69	return CreateParticipationProcess(cross(cur), key, h.GameWorldID, poolKey, fee)
 70}
 71
 72func (h *vaultTestHelper) CreateEntryProcess(cur realm, key string, fee int64) uint64 {
 73	testing.SetOriginCaller(h.Operator)
 74	testing.SetRealm(testing.NewUserRealm(h.Operator))
 75	testing.SetOriginSend(chain.Coins{})
 76	return CreateEntryProcess(cross(cur), key, h.GameWorldID, fee)
 77}
 78
 79func (h *vaultTestHelper) DepositParticipation(cur realm, owner address, processID uint64, participationKey, paymentKey string, amount int64) uint64 {
 80	testing.SetOriginCaller(owner)
 81	testing.SetRealm(testing.NewUserRealm(owner))
 82	coins := chain.Coins{{"ugnot", amount}}
 83	testing.IssueCoins(chain.PackageAddress("gno.land/r/akkadia/beta/game_vault"), coins)
 84	testing.SetOriginSend(coins)
 85	return DepositParticipation(cross(cur), processID, participationKey, paymentKey)
 86}
 87
 88func (h *vaultTestHelper) DepositEntry(cur realm, owner address, processID uint64, participationKey, entryKey string, amount int64) uint64 {
 89	testing.SetOriginCaller(owner)
 90	testing.SetRealm(testing.NewUserRealm(owner))
 91	coins := chain.Coins{{"ugnot", amount}}
 92	testing.IssueCoins(chain.PackageAddress("gno.land/r/akkadia/beta/game_vault"), coins)
 93	testing.SetOriginSend(coins)
 94	return DepositEntry(cross(cur), processID, participationKey, entryKey)
 95}
 96
 97func (h *vaultTestHelper) DepositSystemFunding(cur realm, poolID uint64, key string, amount int64) uint64 {
 98	testing.SetOriginCaller(h.Operator)
 99	testing.SetRealm(testing.NewUserRealm(h.Operator))
100	coins := chain.Coins{{"ugnot", amount}}
101	testing.IssueCoins(chain.PackageAddress("gno.land/r/akkadia/beta/game_vault"), coins)
102	testing.SetOriginSend(coins)
103	return DepositSystemFunding(cross(cur), poolID, key)
104}