This repository has been archived by the owner on May 14, 2021. It is now read-only.
forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 3
/
set_options_test.go
209 lines (174 loc) · 5.06 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package build
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/kinecosystem/go/xdr"
"github.com/stretchr/testify/assert"
)
func TestSetOptions_Signer(t *testing.T) {
cases := []struct {
Name string
Address string
Weight uint32
Error string
}{
{
Name: "AccountID",
Address: "GAXEMCEXBERNSRXOEKD4JAIKVECIXQCENHEBRVSPX2TTYZPMNEDSQCNQ",
Weight: 1,
},
{
Name: "hash(x)",
Address: "XBU2RRGLXH3E5CQHTD3ODLDF2BWDCYUSSBLLZ5GNW7JXHDIYKXZWGTOG",
Weight: 2,
},
{
Name: "hash(tx)",
Address: "TBU2RRGLXH3E5CQHTD3ODLDF2BWDCYUSSBLLZ5GNW7JXHDIYKXZWHXL7",
Weight: 3,
},
{
Name: "Bad",
Address: "foo",
Weight: 1,
Error: "base32 decode failed",
},
}
for _, kase := range cases {
var m SetOptionsBuilder
m.Mutate(Signer{
Address: kase.Address,
Weight: kase.Weight,
})
if kase.Error == "" {
if assert.NoError(t, m.Err, "Unexpected error on case %s", kase.Name) {
assert.Equal(t, kase.Address, m.SO.Signer.Key.Address())
assert.Equal(t, kase.Weight, uint32(m.SO.Signer.Weight))
}
} else {
assert.Contains(t, m.Err.Error(), kase.Error,
"Expected an error on case %s", kase.Name)
}
}
}
var _ = Describe("SetOptionsBuilder Mutators", func() {
var (
subject SetOptionsBuilder
mut interface{}
address = "GAXEMCEXBERNSRXOEKD4JAIKVECIXQCENHEBRVSPX2TTYZPMNEDSQCNQ"
bad = "foo"
)
JustBeforeEach(func() {
subject = SetOptionsBuilder{}
subject.Mutate(mut)
})
Describe("InflationDest", func() {
Context("using a valid stellar address", func() {
BeforeEach(func() { mut = InflationDest(address) })
It("succeeds", func() {
Expect(subject.Err).NotTo(HaveOccurred())
})
It("sets the destination to the correct xdr.AccountId", func() {
var aid xdr.AccountId
aid.SetAddress(address)
Expect(subject.SO.InflationDest.MustEd25519()).To(Equal(aid.MustEd25519()))
})
})
Context("using an invalid value", func() {
BeforeEach(func() { mut = InflationDest(bad) })
It("failed", func() { Expect(subject.Err).To(HaveOccurred()) })
})
})
Describe("HomeDomain", func() {
Context("using a valid value", func() {
BeforeEach(func() { mut = HomeDomain("stellar.org") })
It("succeeds", func() {
Expect(subject.Err).NotTo(HaveOccurred())
})
It("sets the HomeDomain to correct value", func() {
Expect(*subject.SO.HomeDomain).To(Equal(xdr.String32("stellar.org")))
})
})
Context("value too long", func() {
BeforeEach(func() { mut = HomeDomain("123456789012345678901234567890123") })
It("failed", func() { Expect(subject.Err).To(HaveOccurred()) })
})
})
Describe("SetFlag", func() {
Context("using a valid account flag", func() {
BeforeEach(func() { mut = SetFlag(1) })
It("succeeds", func() {
Expect(subject.Err).NotTo(HaveOccurred())
})
It("sets the flag to the correct value", func() {
Expect(*subject.SO.SetFlags).To(Equal(xdr.Uint32(1)))
})
})
Context("using an invalid value", func() {
BeforeEach(func() { mut = SetFlag(3) })
It("failed", func() { Expect(subject.Err).To(HaveOccurred()) })
})
})
Describe("ClearFlag", func() {
Context("using a valid account flag", func() {
BeforeEach(func() { mut = ClearFlag(1) })
It("succeeds", func() {
Expect(subject.Err).NotTo(HaveOccurred())
})
It("sets the flag to the correct value", func() {
Expect(*subject.SO.ClearFlags).To(Equal(xdr.Uint32(1)))
})
})
Context("using an invalid value", func() {
BeforeEach(func() { mut = ClearFlag(3) })
It("failed", func() { Expect(subject.Err).To(HaveOccurred()) })
})
})
Describe("MasterWeight", func() {
Context("using a valid weight", func() {
BeforeEach(func() { mut = MasterWeight(1) })
It("succeeds", func() {
Expect(subject.Err).NotTo(HaveOccurred())
})
It("sets the weight to the correct value", func() {
Expect(*subject.SO.MasterWeight).To(Equal(xdr.Uint32(1)))
})
})
})
Describe("Thresholds", func() {
Context("using a valid weight", func() {
BeforeEach(func() {
low := uint32(1)
med := uint32(2)
high := uint32(3)
mut = Thresholds{&low, &med, &high}
})
It("succeeds", func() {
Expect(subject.Err).NotTo(HaveOccurred())
})
It("sets the thresholds to the correct value", func() {
Expect(*subject.SO.LowThreshold).To(Equal(xdr.Uint32(1)))
Expect(*subject.SO.MedThreshold).To(Equal(xdr.Uint32(2)))
Expect(*subject.SO.HighThreshold).To(Equal(xdr.Uint32(3)))
})
})
})
Describe("SourceAccount", func() {
Context("using a valid stellar address", func() {
BeforeEach(func() { mut = SourceAccount{address} })
It("succeeds", func() {
Expect(subject.Err).NotTo(HaveOccurred())
})
It("sets the destination to the correct xdr.AccountId", func() {
var aid xdr.AccountId
aid.SetAddress(address)
Expect(subject.O.SourceAccount.MustEd25519()).To(Equal(aid.MustEd25519()))
})
})
Context("using an invalid value", func() {
BeforeEach(func() { mut = SourceAccount{bad} })
It("failed", func() { Expect(subject.Err).To(HaveOccurred()) })
})
})
})