forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
payment_test.go
101 lines (88 loc) · 2.92 KB
/
payment_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
package txnbuild
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestPaymentValidateDestination(t *testing.T) {
kp0 := newKeypair0()
sourceAccount := NewSimpleAccount(kp0.Address(), int64(9605939170639898))
payment := Payment{
Destination: "",
Amount: "10",
Asset: NativeAsset{},
}
_, err := NewTransaction(
TransactionParams{
SourceAccount: &sourceAccount,
IncrementSequenceNum: false,
Operations: []Operation{&payment},
BaseFee: MinBaseFee,
Timebounds: NewInfiniteTimeout(),
},
)
if assert.Error(t, err) {
expected := "validation failed for *txnbuild.Payment operation: Field: Destination"
assert.Contains(t, err.Error(), expected)
}
}
func TestPaymentValidateAmount(t *testing.T) {
kp0 := newKeypair0()
sourceAccount := NewSimpleAccount(kp0.Address(), int64(9605939170639898))
payment := Payment{
Destination: "GB7BDSZU2Y27LYNLALKKALB52WS2IZWYBDGY6EQBLEED3TJOCVMZRH7H",
Amount: "ten",
Asset: NativeAsset{},
}
_, err := NewTransaction(
TransactionParams{
SourceAccount: &sourceAccount,
IncrementSequenceNum: false,
Operations: []Operation{&payment},
BaseFee: MinBaseFee,
Timebounds: NewInfiniteTimeout(),
},
)
if assert.Error(t, err) {
expected := "validation failed for *txnbuild.Payment operation: Field: Amount, Error: invalid amount format: ten"
assert.Contains(t, err.Error(), expected)
}
}
func TestPaymentValidateAsset(t *testing.T) {
kp0 := newKeypair0()
sourceAccount := NewSimpleAccount(kp0.Address(), int64(9605939170639898))
payment := Payment{
Destination: "GB7BDSZU2Y27LYNLALKKALB52WS2IZWYBDGY6EQBLEED3TJOCVMZRH7H",
Amount: "10",
Asset: CreditAsset{},
}
_, err := NewTransaction(
TransactionParams{
SourceAccount: &sourceAccount,
IncrementSequenceNum: false,
Operations: []Operation{&payment},
BaseFee: MinBaseFee,
Timebounds: NewInfiniteTimeout(),
},
)
if assert.Error(t, err) {
expected := "validation failed for *txnbuild.Payment operation: Field: Asset, Error: asset code length must be between 1 and 12 characters"
assert.Contains(t, err.Error(), expected)
}
}
func TestPaymentRoundtrip(t *testing.T) {
payment := Payment{
SourceAccount: "GB7BDSZU2Y27LYNLALKKALB52WS2IZWYBDGY6EQBLEED3TJOCVMZRH7H",
Destination: "GB7BDSZU2Y27LYNLALKKALB52WS2IZWYBDGY6EQBLEED3TJOCVMZRH7H",
Amount: "10.0000000",
Asset: NativeAsset{},
}
testOperationsMarshallingRoundtrip(t, []Operation{&payment}, false)
// with muxed accounts
payment = Payment{
SourceAccount: "MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVAAAAAAAAAAAAAJLK",
Destination: "MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVAAAAAAAAAAAAAJLK",
Amount: "10.0000000",
Asset: NativeAsset{},
}
testOperationsMarshallingRoundtrip(t, []Operation{&payment}, true)
}