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

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

englishauction_test.gno

0.95 Kb · 34 lines
 1package englishauction
 2
 3import (
 4	"testing"
 5
 6	"gno.land/p/nt/uassert/v0"
 7)
 8
 9func TestKeyAndPendKey(t *testing.T) {
10	uassert.Equal(t, "000000000001", key(1))
11	uassert.Equal(t, "000000000042", key(42))
12	uassert.Equal(t, "000000123456", key(123456))
13
14	addr := address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
15	uassert.Equal(t, "000000000007:"+addr.String(), pendKey(7, addr))
16}
17
18func TestBlocksLeftAndWinner(t *testing.T) {
19	a := &Auction{ID: 1, Item: "vase", EndHeight: 100}
20
21	// before the deadline, blocks remain and there is no winner yet.
22	uassert.Equal(t, int64(40), blocksLeft(a, 60))
23	uassert.Equal(t, int64(1), blocksLeft(a, 99))
24	uassert.False(t, hasWinner(a))
25
26	// at/after the deadline, no blocks remain.
27	uassert.Equal(t, int64(0), blocksLeft(a, 100))
28	uassert.Equal(t, int64(0), blocksLeft(a, 150))
29
30	// a recorded bid makes it a winner.
31	a.HighestBid = 500
32	a.HighestBidder = address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
33	uassert.True(t, hasWinner(a))
34}