englishauction_test.gno
1.22 Kb · 38 lines
1package englishauction
2
3import (
4 "testing"
5
6 "gno.land/p/moul/kit/store/v0"
7 "gno.land/p/nt/uassert/v0"
8)
9
10// v0 asserted that its own key() padded to width 12, and built pendKey on top
11// of it. The auction key is now the store's, which has no width to outgrow;
12// pending is only point-read, so its key is the plain decimal id.
13func TestKeyAndPendKey(t *testing.T) {
14 uassert.True(t, store.ID(2).Key() < store.ID(10).Key())
15 uassert.True(t, store.ID(999999999999).Key() < store.ID(1000000000000).Key(),
16 "one past v0's width-12 ceiling")
17
18 addr := address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
19 uassert.Equal(t, "7:"+addr.String(), pendKey(7, addr))
20}
21
22func TestBlocksLeftAndWinner(t *testing.T) {
23 a := &Auction{Item: "vase", EndHeight: 100}
24
25 // before the deadline, blocks remain and there is no winner yet.
26 uassert.Equal(t, int64(40), blocksLeft(a, 60))
27 uassert.Equal(t, int64(1), blocksLeft(a, 99))
28 uassert.False(t, hasWinner(a))
29
30 // at/after the deadline, no blocks remain.
31 uassert.Equal(t, int64(0), blocksLeft(a, 100))
32 uassert.Equal(t, int64(0), blocksLeft(a, 150))
33
34 // a recorded bid makes it a winner.
35 a.HighestBid = 500
36 a.HighestBidder = address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
37 uassert.True(t, hasWinner(a))
38}