Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

kudos_test.gno

1.58 Kb · 64 lines
 1package kudos
 2
 3import (
 4	"strings"
 5	"testing"
 6
 7	"gno.land/p/nt/avl/v0"
 8	"gno.land/p/nt/testutils/v0"
 9	"gno.land/p/nt/uassert/v0"
10)
11
12func TestGiveAndLeaderboard(cur realm, t *testing.T) {
13	alice := testutils.TestAddress("alice")
14	bob := testutils.TestAddress("bob")
15	carol := testutils.TestAddress("carol")
16
17	// reset package state between test funcs
18	counts = avl.Tree{}
19	feed = nil
20
21	testing.SetRealm(testing.NewUserRealm(alice))
22	Give(cross(cur), bob, "great review")
23
24	testing.SetRealm(testing.NewUserRealm(carol))
25	Give(cross(cur), bob, "helpful pairing")
26	Give(cross(cur), alice, "nice docs")
27
28	lb := leaderboard()
29	uassert.Equal(t, 2, len(lb))
30	// bob has 2, alice has 1 -> bob first
31	uassert.Equal(t, bob.String(), lb[0].addr)
32	uassert.Equal(t, int64(2), lb[0].count)
33	uassert.Equal(t, alice.String(), lb[1].addr)
34	uassert.Equal(t, int64(1), lb[1].count)
35
36	out := Render("")
37	uassert.True(t, strings.Contains(out, "helpful pairing"))
38	uassert.True(t, strings.Contains(out, "Leaderboard"))
39}
40
41func TestCannotKudosSelf(cur realm, t *testing.T) {
42	dave := testutils.TestAddress("dave")
43
44	counts = avl.Tree{}
45	feed = nil
46
47	testing.SetRealm(testing.NewUserRealm(dave))
48	uassert.AbortsWithMessage(t, cur, "cannot give kudos to yourself", func() {
49		Give(cross(cur), dave, "self five")
50	})
51}
52
53func TestEmptyReasonAborts(cur realm, t *testing.T) {
54	eve := testutils.TestAddress("eve")
55	frank := testutils.TestAddress("frank")
56
57	counts = avl.Tree{}
58	feed = nil
59
60	testing.SetRealm(testing.NewUserRealm(eve))
61	uassert.AbortsWithMessage(t, cur, "reason must not be empty", func() {
62		Give(cross(cur), frank, "   ")
63	})
64}