forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
119 lines (112 loc) · 3.7 KB
/
config_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package genesis
import (
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/ava-labs/avalanchego/ids"
)
func TestAllocationCompare(t *testing.T) {
type test struct {
name string
alloc1 Allocation
alloc2 Allocation
expected int
}
tests := []test{
{
name: "equal",
alloc1: Allocation{},
alloc2: Allocation{},
expected: 0,
},
{
name: "initial amount smaller",
alloc1: Allocation{},
alloc2: Allocation{
InitialAmount: 1,
},
expected: -1,
},
{
name: "bytes smaller",
alloc1: Allocation{},
alloc2: Allocation{
AVAXAddr: ids.ShortID{1},
},
expected: -1,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
require := require.New(t)
require.Equal(tt.expected, tt.alloc1.Compare(tt.alloc2))
require.Equal(-tt.expected, tt.alloc2.Compare(tt.alloc1))
})
}
}
func TestGetRecentStartTime(t *testing.T) {
type test struct {
name string
defined time.Time
now time.Time
expected time.Time
}
tests := []test{
{
name: "before 1 period and 1 second",
defined: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
now: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC).Add(-localNetworkUpdateStartTimePeriod - time.Second),
expected: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
},
{
name: "before 1 second",
defined: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
now: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC).Add(-time.Second),
expected: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
},
{
name: "equal",
defined: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
now: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
expected: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
},
{
name: "after 1 second",
defined: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
now: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC).Add(time.Second),
expected: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
},
{
name: "after 1 period",
defined: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
now: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC).Add(localNetworkUpdateStartTimePeriod),
expected: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC).Add(localNetworkUpdateStartTimePeriod),
},
{
name: "after 1 period and 1 second",
defined: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
now: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC).Add(localNetworkUpdateStartTimePeriod + time.Second),
expected: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC).Add(localNetworkUpdateStartTimePeriod),
},
{
name: "after 2 periods",
defined: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
now: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC).Add(2 * localNetworkUpdateStartTimePeriod),
expected: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC).Add(2 * localNetworkUpdateStartTimePeriod),
},
{
name: "after 2 periods and 1 second",
defined: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC),
now: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC).Add(2*localNetworkUpdateStartTimePeriod + time.Second),
expected: time.Date(2024, time.July, 15, 4, 0, 0, 0, time.UTC).Add(2 * localNetworkUpdateStartTimePeriod),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := getRecentStartTime(tt.defined, tt.now, localNetworkUpdateStartTimePeriod)
require.Equal(t, tt.expected, actual)
})
}
}