forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_options_test.go
138 lines (97 loc) · 3.51 KB
/
set_options_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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package txnbuild
import (
"testing"
"github.com/stellar/go/xdr"
"github.com/stretchr/testify/assert"
)
func TestHandleSetFlagsThreeDifferent(t *testing.T) {
options := SetOptions{}
options.SetFlags = []AccountFlag{1, 2, 4}
options.handleSetFlags()
expected := xdr.Uint32(7)
assert.Equal(t, expected, *options.xdrOp.SetFlags, "three different valid flags are ok")
}
func TestHandleSetFlagsThreeSame(t *testing.T) {
options := SetOptions{}
options.SetFlags = []AccountFlag{1, 1, 1}
options.handleSetFlags()
expected := xdr.Uint32(1)
assert.Equal(t, expected, *options.xdrOp.SetFlags, "three of the same valid flags are ok")
}
func TestHandleSetFlagsRedundantFlagsAllowed(t *testing.T) {
options := SetOptions{}
options.SetFlags = []AccountFlag{1, 2, 4, 2, 4, 1}
options.handleSetFlags()
expected := xdr.Uint32(7)
assert.Equal(t, expected, *options.xdrOp.SetFlags, "additional redundant flags are allowed")
}
func TestHandleSetFlagsLessThanThreeAreOK(t *testing.T) {
options := SetOptions{}
options.SetFlags = []AccountFlag{1, 2}
options.handleSetFlags()
expected := xdr.Uint32(3)
assert.Equal(t, expected, *options.xdrOp.SetFlags, "less than three flags are ok")
}
func TestHandleSetFlagsInvalidFlagsAllowed(t *testing.T) {
options := SetOptions{}
options.SetFlags = []AccountFlag{3, 3, 3}
options.handleSetFlags()
expected := xdr.Uint32(3)
assert.Equal(t, expected, *options.xdrOp.SetFlags, "invalid flags are allowed")
}
func TestHandleSetFlagsZeroFlagsAreOK(t *testing.T) {
options := SetOptions{}
options.SetFlags = []AccountFlag{0, 2, 0}
options.handleSetFlags()
expected := xdr.Uint32(2)
assert.Equal(t, expected, *options.xdrOp.SetFlags, "zero flags are ok")
}
func TestHandleClearFlagsThreeDifferent(t *testing.T) {
options := SetOptions{}
options.ClearFlags = []AccountFlag{1, 2, 4}
options.handleClearFlags()
expected := xdr.Uint32(7)
assert.Equal(t, expected, *options.xdrOp.ClearFlags, "three different valid flags are ok")
}
func TestHandleClearFlagsThreeSame(t *testing.T) {
options := SetOptions{}
options.ClearFlags = []AccountFlag{1, 1, 1}
options.handleClearFlags()
expected := xdr.Uint32(1)
assert.Equal(t, expected, *options.xdrOp.ClearFlags, "three of the same valid flags are ok")
}
func TestHandleClearFlagsRedundantFlagsAllowed(t *testing.T) {
options := SetOptions{}
options.ClearFlags = []AccountFlag{1, 2, 4, 2, 4, 1}
options.handleClearFlags()
expected := xdr.Uint32(7)
assert.Equal(t, expected, *options.xdrOp.ClearFlags, "additional redundant flags are allowed")
}
func TestHandleClearFlagsLessThanThreeAreOK(t *testing.T) {
options := SetOptions{}
options.ClearFlags = []AccountFlag{1, 2}
options.handleClearFlags()
expected := xdr.Uint32(3)
assert.Equal(t, expected, *options.xdrOp.ClearFlags, "less than three flags are ok")
}
func TestHandleClearFlagsInvalidFlagsAllowed(t *testing.T) {
options := SetOptions{}
options.ClearFlags = []AccountFlag{3, 3, 3}
options.handleClearFlags()
expected := xdr.Uint32(3)
assert.Equal(t, expected, *options.xdrOp.ClearFlags, "invalid flags are allowed")
}
func TestHandleClearFlagsZeroFlagsAreOK(t *testing.T) {
options := SetOptions{}
options.ClearFlags = []AccountFlag{0, 2, 0}
options.handleClearFlags()
expected := xdr.Uint32(2)
assert.Equal(t, expected, *options.xdrOp.ClearFlags, "zero flags are ok")
}
func TestEmptyHomeDomainOK(t *testing.T) {
options := SetOptions{
HomeDomain: NewHomeDomain(""),
}
options.BuildXDR()
assert.Equal(t, string(*options.xdrOp.HomeDomain), "", "empty string home domain is set")
}