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