Search Apps Documentation Source Content File Folder Download Copy Actions Download

init.gno

1.13 Kb · 42 lines
 1package init
 2
 3import (
 4	"chain/runtime"
 5
 6	"gno.land/r/gov/dao"
 7	"gno.land/r/gov/dao/v3/impl"
 8	"gno.land/r/gov/dao/v3/memberstore"
 9)
10
11func Init(cur realm) {
12	assertIsDevChain()
13
14	// This is needed because state is saved between unit tests,
15	// and we want to avoid having real members used on tests
16	memberstore.Get(0, cur).DeleteAll()
17	dao.UpdateImpl(cross(cur), dao.NewUpdateRequest(impl.NewGovDAO(), []string{"gno.land/r/gov/dao/v3/impl"}))
18}
19
20func InitWithUsers(cur realm, addrs ...address) {
21	assertIsDevChain()
22
23	// This is needed because state is saved between unit tests,
24	// and we want to avoid having real members used on tests
25	memberstore.Get(0, cur).DeleteAll()
26	memberstore.Get(0, cur).SetTier(memberstore.T1)
27	for _, a := range addrs {
28		if !a.IsValid() {
29			panic("invalid address: " + a.String())
30		}
31		memberstore.Get(0, cur).SetMember(memberstore.T1, a, memberstore.NewMember(3))
32	}
33
34	dao.UpdateImpl(cross(cur), dao.NewUpdateRequest(impl.NewGovDAO(), []string{"gno.land/r/gov/dao/v3/impl"}))
35}
36
37func assertIsDevChain() {
38	chainID := runtime.ChainID()
39	if chainID != "dev" && chainID != "tendermint_test" {
40		panic("unauthorized")
41	}
42}