z_2_prop3_filetest.gno
1.87 Kb · 62 lines
1package main
2
3import (
4 "chain"
5 "chain/runtime"
6 "testing"
7
8 "gno.land/p/nt/testutils/v0"
9 "gno.land/r/gov/dao"
10 daov3init "gno.land/r/gov/dao/v3/init"
11 users "gno.land/r/sys/namereg/v1"
12 susers "gno.land/r/sys/users"
13)
14
15// Test the full governance-driven registerPrice flow:
16// 1. propose a new price via users.ProposeNewRegisterPrice
17// 2. DAO accepts the proposal (vote YES, execute)
18// 3. verify the executed callback updated registerPrice by exercising
19// Register with the new amount and watching it succeed (registration
20// under the old default of 0 ugnot would now panic with the new
21// price in the error message).
22var c address = runtime.OriginCaller()
23
24func init() {
25 // Whitelist this realm as a controller so its Register() can reach r/sys/users.
26 testing.SetHeight(0)
27 susers.AddControllerAtGenesis(cross, chain.PackageAddress("gno.land/r/sys/namereg/v1"))
28 testing.SetHeight(123)
29
30 daov3init.InitWithUsers(c)
31
32 // Propose raising the price from 0 to 20 GNOT.
33 testing.SetOriginCaller(c)
34 testing.SetRealm(testing.NewUserRealm(c))
35 pr := users.ProposeNewRegisterPrice(20_000_000)
36 dao.MustCreateProposal(cross, pr)
37}
38
39func main() {
40 testing.SetOriginCaller(c)
41
42 // Vote and execute.
43 dao.MustVoteOnProposal(cross, dao.VoteRequest{
44 Option: dao.YesVote,
45 ProposalID: dao.ProposalID(0),
46 })
47 dao.ExecuteProposal(cross, dao.ProposalID(0))
48
49 // New price should be active. Register a user with the new amount;
50 // registration with the old default (0 ugnot) would panic.
51 alice := testutils.TestAddress("alice")
52 testing.SetOriginCaller(alice)
53 testing.SetRealm(testing.NewUserRealm(alice))
54 testing.SetOriginSend(chain.Coins{{Denom: "ugnot", Amount: 20_000_000}})
55 users.Register(cross, "nym-alice123")
56
57 data, _ := susers.ResolveName("nym-alice123")
58 println("registered alice at:", data.Addr())
59}
60
61// Output:
62// registered alice at: g1v9kxjcm9ta047h6lta047h6lta047h6lzd40gh