forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
change_trust_test.go
97 lines (83 loc) · 3.09 KB
/
change_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
package txnbuild
import (
"testing"
"github.com/stellar/go/network"
"github.com/stretchr/testify/assert"
)
func TestChangeTrustMaxLimit(t *testing.T) {
kp0 := newKeypair0()
txSourceAccount := NewSimpleAccount(kp0.Address(), int64(9605939170639898))
changeTrust := ChangeTrust{
Line: CreditAsset{"ABCD", kp0.Address()},
}
received, err := newSignedTransaction(
TransactionParams{
SourceAccount: &txSourceAccount,
IncrementSequenceNum: true,
Operations: []Operation{&changeTrust},
BaseFee: MinBaseFee,
Timebounds: NewInfiniteTimeout(),
},
network.TestNetworkPassphrase,
kp0,
)
assert.NoError(t, err)
expected := "AAAAAgAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAGQAIiCNAAAAGwAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAABgAAAAFBQkNEAAAAAODcbeFyXKxmUWK1L6znNbKKIkPkHRJNbLktcKPqLnLFf/////////8AAAAAAAAAAeoucsUAAABAXp/gGvNtaqn2/gEh4QoNO+LpT3AmyLFDb81INsfdkf70USiBheUc7bzxgZJLVpFy2qw3ucqpQQPi986XFbPsAQ=="
assert.Equal(t, expected, received, "Base 64 XDR should match")
}
func TestChangeTrustValidateInvalidAsset(t *testing.T) {
kp0 := newKeypair0()
txSourceAccount := NewSimpleAccount(kp0.Address(), int64(9605939170639898))
changeTrust := ChangeTrust{
Line: NativeAsset{},
}
_, err := NewTransaction(
TransactionParams{
SourceAccount: &txSourceAccount,
IncrementSequenceNum: true,
Operations: []Operation{&changeTrust},
BaseFee: MinBaseFee,
Timebounds: NewInfiniteTimeout(),
},
)
if assert.Error(t, err) {
expected := "validation failed for *txnbuild.ChangeTrust operation: Field: Line, Error: native (XLM) asset type is not allowed"
assert.Contains(t, err.Error(), expected)
}
}
func TestChangeTrustValidateInvalidLimit(t *testing.T) {
kp0 := newKeypair0()
txSourceAccount := NewSimpleAccount(kp0.Address(), int64(9605939170639898))
changeTrust := ChangeTrust{
Line: CreditAsset{"ABCD", kp0.Address()},
Limit: "-1",
}
_, err := NewTransaction(
TransactionParams{
SourceAccount: &txSourceAccount,
IncrementSequenceNum: true,
Operations: []Operation{&changeTrust},
BaseFee: MinBaseFee,
Timebounds: NewInfiniteTimeout(),
},
)
if assert.Error(t, err) {
expected := "validation failed for *txnbuild.ChangeTrust operation: Field: Limit, Error: amount can not be negative"
assert.Contains(t, err.Error(), expected)
}
}
func TestChangeTrustRoundtrip(t *testing.T) {
changeTrust := ChangeTrust{
SourceAccount: "GB7BDSZU2Y27LYNLALKKALB52WS2IZWYBDGY6EQBLEED3TJOCVMZRH7H",
Line: CreditAsset{"ABCD", "GB7BDSZU2Y27LYNLALKKALB52WS2IZWYBDGY6EQBLEED3TJOCVMZRH7H"},
Limit: "1.0000000",
}
testOperationsMarshallingRoundtrip(t, []Operation{&changeTrust}, false)
// with muxed accounts
changeTrust = ChangeTrust{
SourceAccount: "MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVAAAAAAAAAAAAAJLK",
Line: CreditAsset{"ABCD", "GB7BDSZU2Y27LYNLALKKALB52WS2IZWYBDGY6EQBLEED3TJOCVMZRH7H"},
Limit: "1.0000000",
}
testOperationsMarshallingRoundtrip(t, []Operation{&changeTrust}, true)
}