guards_test.gno
1.50 Kb · 57 lines
1package bolo
2
3import (
4 "math"
5 "strings"
6 "testing"
7
8 "gno.land/p/nt/testutils/v0"
9)
10
11func TestCheckAddress(t *testing.T) {
12 good := testutils.TestAddress("beneficiary")
13 checkAddress(good, ErrBeneficiary)
14
15 bad := string(good)
16 last := "q"
17 if bad[39] == 'q' {
18 last = "p"
19 }
20 for name, a := range map[string]address{
21 "empty": "",
22 "39 chars": address(bad[:39]),
23 "41 chars": address(bad + "q"),
24 "bad checksum": address(bad[:39] + last),
25 "not bech32": address("0x00000000000000000000000000000000000000"),
26 // IsValid takes an address in capitals, as the same account; it must not
27 // pass as a second address (API C12). Mixed case is refused by IsValid.
28 "capitals": address(strings.ToUpper(bad)),
29 "mixed case": address(bad[:20] + strings.ToUpper(bad[20:])),
30 } {
31 if !panicsWith(func() { checkAddress(a, ErrBeneficiary) }, ErrBeneficiary) {
32 t.Errorf("%s: not refused", name)
33 }
34 }
35}
36
37func TestDaysToSeconds(t *testing.T) {
38 if got := daysToSeconds(0, ErrSetting); got != 0 {
39 t.Errorf("0 days = %d", got)
40 }
41 if got := daysToSeconds(3650, ErrSetting); got != 315360000 {
42 t.Errorf("3650 days = %d", got)
43 }
44 for _, days := range []int{-1, math.MaxInt64/secondsPerDay + 1, math.MaxInt64} {
45 if !panicsWith(func() { daysToSeconds(days, ErrSetting) }, ErrSetting) {
46 t.Errorf("%d days: not refused", days)
47 }
48 }
49}
50
51func TestNow(t *testing.T) {
52 start := now()
53 testing.SkipHeights(12)
54 if got := now() - start; got != 60 {
55 t.Errorf("12 heights moved now() by %d seconds, want 60", got)
56 }
57}