forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathallow_trust_test.go
136 lines (111 loc) · 3.33 KB
/
allow_trust_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
package build
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/stellar/go/xdr"
)
var _ = Describe("AllowTrustBuilder Mutators", func() {
var (
subject AllowTrustBuilder
mut interface{}
address = "GAXEMCEXBERNSRXOEKD4JAIKVECIXQCENHEBRVSPX2TTYZPMNEDSQCNQ"
bad = "foo"
)
JustBeforeEach(func() {
subject = AllowTrustBuilder{}
subject.Mutate(mut)
})
Describe("Trustor", func() {
Context("using a valid stellar address", func() {
BeforeEach(func() { mut = Trustor{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.AT.Trustor.MustEd25519()).To(Equal(aid.MustEd25519()))
})
})
Context("using an invalid value", func() {
BeforeEach(func() { mut = Trustor{bad} })
It("failed", func() { Expect(subject.Err).To(HaveOccurred()) })
})
})
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()) })
})
})
Describe("AllowTrustAsset", func() {
Context("AssetTypeCreditAlphanum4", func() {
BeforeEach(func() {
mut = AllowTrustAsset{"USD"}
})
It("sets Asset properly", func() {
Expect(subject.AT.Asset.Type).To(Equal(xdr.AssetTypeAssetTypeCreditAlphanum4))
Expect(*subject.AT.Asset.AssetCode4).To(Equal([4]byte{'U', 'S', 'D', 0}))
Expect(subject.AT.Asset.AssetCode12).To(BeNil())
})
})
Context("AssetTypeCreditAlphanum12", func() {
BeforeEach(func() {
mut = AllowTrustAsset{"ABCDEF"}
})
It("sets Asset properly", func() {
Expect(subject.AT.Asset.Type).To(Equal(xdr.AssetTypeAssetTypeCreditAlphanum12))
Expect(subject.AT.Asset.AssetCode4).To(BeNil())
Expect(*subject.AT.Asset.AssetCode12).To(Equal([12]byte{'A', 'B', 'C', 'D', 'E', 'F', 0, 0, 0, 0, 0, 0}))
})
})
Context("asset code length invalid", func() {
Context("empty", func() {
BeforeEach(func() {
mut = AllowTrustAsset{""}
})
It("failed", func() {
Expect(subject.Err.Error()).To(ContainSubstring("Asset code length is invalid"))
})
})
Context("too long", func() {
BeforeEach(func() {
mut = AllowTrustAsset{"1234567890123"}
})
It("failed", func() {
Expect(subject.Err.Error()).To(ContainSubstring("Asset code length is invalid"))
})
})
})
})
Describe("Authorize", func() {
Context("when equal true", func() {
BeforeEach(func() {
mut = Authorize{true}
})
It("sets authorize flag properly", func() {
Expect(subject.AT.Authorize).To(Equal(true))
})
})
Context("when equal false", func() {
BeforeEach(func() {
subject.AT.Authorize = true
mut = Authorize{false}
})
It("sets authorize flag properly", func() {
Expect(subject.AT.Authorize).To(Equal(false))
})
})
})
})