init.gno
1.15 Kb · 48 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() {
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().DeleteAll()
17 dao.UpdateImpl(cross, dao.UpdateRequest{
18 DAO: impl.NewGovDAO(),
19 AllowedDAOs: []string{"gno.land/r/gov/dao/v3/impl"},
20 })
21}
22
23func InitWithUsers(addrs ...address) {
24 assertIsDevChain()
25
26 // This is needed because state is saved between unit tests,
27 // and we want to avoid having real members used on tests
28 memberstore.Get().DeleteAll()
29 memberstore.Get().SetTier(memberstore.T1)
30 for _, a := range addrs {
31 if !a.IsValid() {
32 panic("invalid address: " + a.String())
33 }
34 memberstore.Get().SetMember(memberstore.T1, a, &memberstore.Member{InvitationPoints: 3})
35 }
36
37 dao.UpdateImpl(cross, dao.UpdateRequest{
38 DAO: impl.NewGovDAO(),
39 AllowedDAOs: []string{"gno.land/r/gov/dao/v3/impl"},
40 })
41}
42
43func assertIsDevChain() {
44 chainID := runtime.ChainID()
45 if chainID != "dev" && chainID != "tendermint_test" {
46 panic("unauthorized")
47 }
48}