forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransaction_test.go
186 lines (160 loc) · 5.39 KB
/
transaction_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
package build
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/stellar/go/xdr"
)
var _ = Describe("Transaction Mutators:", func() {
var (
subject *TransactionBuilder
mut TransactionMutator
err error
)
BeforeEach(func() { subject = &TransactionBuilder{} })
JustBeforeEach(func() { err = subject.Mutate(mut) })
Describe("Defaults", func() {
BeforeEach(func() {
subject.Mutate(Payment())
mut = Defaults{}
})
It("sets the fee", func() { Expect(subject.TX.Fee).To(BeEquivalentTo(DefaultBaseFee)) })
It("sets the network passphrase", func() { Expect(subject.NetworkPassphrase).To(Equal(DefaultNetwork.Passphrase)) })
Context("on a transaction with 2 operations", func() {
BeforeEach(func() { subject.Mutate(Payment()) })
It("sets the fee to 200", func() { Expect(subject.TX.Fee).To(BeEquivalentTo(200)) })
})
})
Describe("TransactionBuilder.BaseFee", func() {
BeforeEach(func() {
subject.Mutate(Payment())
mut = Defaults{}
})
It("sets the fee", func() { Expect(subject.TX.Fee).To(BeEquivalentTo(DefaultBaseFee)) })
Context("trying to change the base fee to 333", func() {
BeforeEach(func() {
subject.BaseFee = 333
subject.Mutate(Payment())
})
It(
"sets the fee to 333 * 2",
func() { Expect(subject.TX.Fee).To(BeEquivalentTo(333 * 2)) },
)
})
})
Describe("BaseFee Mutator", func() {
BeforeEach(func() {
subject.Mutate(BaseFee{Amount: 456}, Defaults{})
})
It(
"sets the base fee to 456",
func() { Expect(subject.BaseFee).To(BeEquivalentTo(456)) },
)
Context("on a transaction with 3 operations", func() {
BeforeEach(func() {
subject.Mutate(Payment())
subject.Mutate(Payment())
subject.Mutate(Payment())
})
It(
"sets the fee to 456 * 3",
func() { Expect(subject.TX.Fee).To(BeEquivalentTo(456 * 3)) },
)
})
})
Describe("MemoHash", func() {
BeforeEach(func() { mut = MemoHash{[32]byte{0x01}} })
It("sets a Hash memo on the transaction", func() {
Expect(subject.TX.Memo.Type).To(Equal(xdr.MemoTypeMemoHash))
Expect(subject.TX.Memo.MustHash()).To(Equal(xdr.Hash([32]byte{0x01})))
})
})
Describe("MemoID", func() {
BeforeEach(func() { mut = MemoID{123} })
It("sets an ID memo on the transaction", func() {
Expect(subject.TX.Memo.Type).To(Equal(xdr.MemoTypeMemoId))
Expect(subject.TX.Memo.MustId()).To(Equal(xdr.Uint64(123)))
})
})
Describe("MemoReturn", func() {
BeforeEach(func() { mut = MemoReturn{[32]byte{0x01}} })
It("sets a Hash memo on the transaction", func() {
Expect(subject.TX.Memo.Type).To(Equal(xdr.MemoTypeMemoReturn))
Expect(subject.TX.Memo.MustRetHash()).To(Equal(xdr.Hash([32]byte{0x01})))
})
})
Describe("MemoText", func() {
BeforeEach(func() { mut = MemoText{"hello"} })
It("sets a TEXT memo on the transaction", func() {
Expect(subject.TX.Memo.Type).To(Equal(xdr.MemoTypeMemoText))
Expect(subject.TX.Memo.MustText()).To(Equal("hello"))
})
Context("a string longer than 28 bytes", func() {
BeforeEach(func() { mut = MemoText{"12345678901234567890123456789"} })
It("sets an error", func() {
Expect(err).ToNot(BeNil())
})
})
})
Describe("Timebounds", func() {
BeforeEach(func() { mut = Timebounds{1521056118, 1521056298} })
It("succeeds", func() { Expect(err).NotTo(HaveOccurred()) })
It("sets an minimum and maximum timebound on the transaction", func() {
Expect(subject.TX.TimeBounds.MinTime).To(Equal(xdr.Uint64(1521056118)))
Expect(subject.TX.TimeBounds.MaxTime).To(Equal(xdr.Uint64(1521056298)))
})
})
Describe("AllowTrustBuilder", func() {
BeforeEach(func() { mut = AllowTrust() })
It("adds itself to the tx's operations", func() {
Expect(subject.TX.Operations).To(HaveLen(1))
})
})
Describe("PaymentBuilder", func() {
BeforeEach(func() { mut = Payment() })
It("adds itself to the tx's operations", func() {
Expect(subject.TX.Operations).To(HaveLen(1))
})
})
Describe("SourceAccount", func() {
Context("with a valid address", func() {
address := "GAXEMCEXBERNSRXOEKD4JAIKVECIXQCENHEBRVSPX2TTYZPMNEDSQCNQ"
BeforeEach(func() { mut = SourceAccount{address} })
It("sets the AccountId correctly", func() {
var aid xdr.AccountId
aid.SetAddress(address)
Expect(subject.TX.SourceAccount.MustEd25519()).To(Equal(aid.MustEd25519()))
})
})
Context("with bad address", func() {
BeforeEach(func() { mut = SourceAccount{"foo"} })
It("fails", func() { Expect(err).To(HaveOccurred()) })
})
})
Describe("Sequence", func() {
BeforeEach(func() { mut = Sequence{12345} })
It("succeeds", func() { Expect(err).NotTo(HaveOccurred()) })
It("sets the sequence", func() { Expect(subject.TX.SeqNum).To(BeEquivalentTo(12345)) })
})
Describe("AutoSequence", func() {
BeforeEach(func() {
mock := &MockSequenceProvider{
Data: map[string]xdr.SequenceNumber{
"GAXEMCEXBERNSRXOEKD4JAIKVECIXQCENHEBRVSPX2TTYZPMNEDSQCNQ": 2,
},
}
mut = AutoSequence{mock}
})
Context("with no source account set", func() {
It("fails", func() { Expect(err).To(HaveOccurred()) })
})
Context("with a source account set", func() {
BeforeEach(func() {
subject.Mutate(SourceAccount{
"GAXEMCEXBERNSRXOEKD4JAIKVECIXQCENHEBRVSPX2TTYZPMNEDSQCNQ",
})
})
It("succeeds", func() { Expect(err).NotTo(HaveOccurred()) })
It("sets the sequence", func() { Expect(subject.TX.SeqNum).To(BeEquivalentTo(3)) })
})
})
})