forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
timebounds_test.go
51 lines (40 loc) · 1.38 KB
/
timebounds_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
package txnbuild
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestTimeboundsRequireConstructor(t *testing.T) {
tb := TimeBounds{MinTime: -1, MaxTime: 300}
err := tb.Validate()
expectedErrMsg := "timebounds must be constructed using NewTimebounds(), NewTimeout(), or NewInfiniteTimeout()"
require.EqualError(t, err, expectedErrMsg, "Default timebounds not allowed")
}
func TestSetTimeboundsNegativeMinTime(t *testing.T) {
tb := NewTimebounds(-1, 300)
err := tb.Validate()
expectedErrMsg := "invalid timebound: minTime cannot be negative"
require.EqualError(t, err, expectedErrMsg, "No negative minTime allowed")
}
func TestSetTimeboundsNegativeMaxTime(t *testing.T) {
tb := NewTimebounds(1, -300)
err := tb.Validate()
expectedErrMsg := "invalid timebound: maxTime cannot be negative"
require.EqualError(t, err, expectedErrMsg, "No negative maxTime allowed")
}
func TestSetTimeoutNegativeWidth(t *testing.T) {
tb := NewTimeout(300)
tb.MinTime = 5555624032 // Sometime in 2146
err := tb.Validate()
expectedErrMsg := "invalid timebound: maxTime < minTime"
require.EqualError(t, err, expectedErrMsg, "No negative width windows")
}
func TestSetTimeout(t *testing.T) {
tb := NewTimeout(300)
tb.MinTime = 1
err := tb.Validate()
if assert.NoError(t, err) {
assert.Equal(t, int64(1), tb.MinTime)
assert.NotNil(t, tb.MaxTime)
}
}