verifier_test.gno
1.31 Kb ยท 52 lines
1package names
2
3import (
4 "std"
5 "testing"
6
7 "gno.land/p/demo/ownable"
8 "gno.land/p/demo/testutils"
9 "gno.land/p/demo/uassert"
10 "gno.land/p/demo/urequire"
11
12 "gno.land/r/sys/users"
13)
14
15var alice = testutils.TestAddress("alice")
16
17func TestDefaultVerifier(t *testing.T) {
18 // Check disabled, any case is true
19 uassert.True(t, verifier(false, alice, alice.String()))
20 uassert.True(t, verifier(false, "", alice.String()))
21 uassert.True(t, verifier(false, alice, "somerandomusername"))
22
23 // Check enabled
24 // username + addr mismatch
25 uassert.False(t, verifier(true, alice, "notregistered"))
26 // PA namespace check
27 uassert.True(t, verifier(true, alice, alice.String()))
28
29 // Empty name/address
30 uassert.False(t, verifier(true, std.Address(""), ""))
31
32 // Register proper username
33 testing.SetRealm(std.NewCodeRealm("gno.land/r/gnoland/users/v1")) // authorized write
34 urequire.NoError(t, cross(users.RegisterUser)("alice", alice))
35
36 // Proper namespace
37 uassert.True(t, verifier(true, alice, "alice"))
38}
39
40func TestEnable(t *testing.T) {
41 testing.SetRealm(std.NewUserRealm("g1manfred47kzduec920z88wfr64ylksmdcedlf5"))
42
43 uassert.NotPanics(t, func() {
44 cross(Enable)()
45 })
46
47 // Confirm enable drops ownerships
48 uassert.Equal(t, Ownable.Owner().String(), "")
49 uassert.AbortsWithMessage(t, ownable.ErrUnauthorized.Error(), func() {
50 cross(Enable)()
51 })
52}