faucet_test.gno
1.42 Kb · 51 lines
1package faucet
2
3import (
4 "strings"
5 "testing"
6
7 "gno.land/p/nt/testutils/v0"
8 "gno.land/p/nt/uassert/v0"
9)
10
11func TestClaimGrantsPoints(cur realm, t *testing.T) {
12 alice := testutils.TestAddress("alice")
13 testing.SetRealm(testing.NewUserRealm(alice))
14
15 Claim(cross(cur))
16
17 uassert.Equal(t, int64(ClaimAmount), BalanceOf(alice.String()),
18 "first claim should grant ClaimAmount")
19 uassert.Equal(t, int64(ClaimAmount), totalDistributed,
20 "totalDistributed should reflect the single claim")
21 uassert.Equal(t, int64(1), totalClaims, "one claim recorded")
22}
23
24func TestClaimCooldownAborts(cur realm, t *testing.T) {
25 bob := testutils.TestAddress("bob")
26 testing.SetRealm(testing.NewUserRealm(bob))
27
28 // First claim succeeds at the current height.
29 Claim(cross(cur))
30
31 // Immediate second claim (same block) must abort due to cooldown.
32 uassert.AbortsWithMessage(t, cur,
33 "cooldown active: 100 block(s) remaining before you can claim again",
34 func() {
35 Claim(cross(cur))
36 },
37 "second immediate claim should abort on cooldown",
38 )
39}
40
41func TestRenderContainsStats(cur realm, t *testing.T) {
42 carol := testutils.TestAddress("carol")
43 testing.SetRealm(testing.NewUserRealm(carol))
44 Claim(cross(cur))
45
46 out := Render("")
47 uassert.True(t, strings.Contains(out, "# Token Faucet"), "has title")
48 uassert.True(t, strings.Contains(out, "Total distributed"), "has stats")
49 uassert.True(t, strings.Contains(out, carol.String()),
50 "claimer address listed in table")
51}