forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_trustline_flags_test.go
104 lines (99 loc) · 2.89 KB
/
set_trustline_flags_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
package txnbuild
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stellar/go/xdr"
)
func TestSetTrustLineFlags(t *testing.T) {
asset := CreditAsset{"ABCD", "GAEJJMDDCRYF752PKIJICUVL7MROJBNXDV2ZB455T7BAFHU2LCLSE2LW"}
source := "GBUKBCG5VLRKAVYAIREJRUJHOKLIADZJOICRW43WVJCLES52BDOTCQZU"
trustor := "GCCOBXW2XQNUSL467IEILE6MMCNRR66SSVL4YQADUNYYNUVREF3FIV2Z"
for _, testcase := range []struct {
name string
op SetTrustLineFlags
}{
{
name: "Both set and clear",
op: SetTrustLineFlags{
Trustor: trustor,
Asset: asset,
SetFlags: []TrustLineFlag{TrustLineClawbackEnabled},
ClearFlags: []TrustLineFlag{TrustLineAuthorized, TrustLineAuthorizedToMaintainLiabilities},
SourceAccount: source,
},
},
{
name: "Both set and clear 2",
op: SetTrustLineFlags{
Trustor: trustor,
Asset: asset,
SetFlags: []TrustLineFlag{TrustLineAuthorized, TrustLineAuthorizedToMaintainLiabilities},
ClearFlags: []TrustLineFlag{TrustLineClawbackEnabled},
SourceAccount: source,
},
},
{
name: "Only set",
op: SetTrustLineFlags{
Trustor: trustor,
Asset: asset,
SetFlags: []TrustLineFlag{TrustLineClawbackEnabled},
ClearFlags: nil,
SourceAccount: source,
},
},
{
name: "Only clear",
op: SetTrustLineFlags{
Trustor: trustor,
Asset: asset,
SetFlags: nil,
ClearFlags: []TrustLineFlag{TrustLineClawbackEnabled},
SourceAccount: source,
},
},
{
name: "No set nor clear",
op: SetTrustLineFlags{
Trustor: trustor,
Asset: asset,
SetFlags: nil,
ClearFlags: nil,
SourceAccount: source,
},
},
{
name: "No source",
op: SetTrustLineFlags{
Trustor: trustor,
Asset: asset,
SetFlags: []TrustLineFlag{TrustLineClawbackEnabled},
ClearFlags: []TrustLineFlag{TrustLineAuthorized, TrustLineAuthorizedToMaintainLiabilities},
},
},
} {
t.Run(testcase.name, func(t *testing.T) {
op := testcase.op
assert.NoError(t, op.Validate())
xdrOp, err := op.BuildXDR()
assert.NoError(t, err)
xdrBin, err := xdrOp.MarshalBinary()
assert.NoError(t, err)
var xdrOp2 xdr.Operation
assert.NoError(t, xdr.SafeUnmarshal(xdrBin, &xdrOp2))
var op2 SetTrustLineFlags
assert.NoError(t, op2.FromXDR(xdrOp2))
assert.Equal(t, op, op2)
testOperationsMarshalingRoundtrip(t, []Operation{&testcase.op}, false)
})
}
// with muxed accounts
setTrustLineFlags := SetTrustLineFlags{
Trustor: trustor,
Asset: asset,
SetFlags: []TrustLineFlag{TrustLineClawbackEnabled},
ClearFlags: []TrustLineFlag{TrustLineAuthorized, TrustLineAuthorizedToMaintainLiabilities},
SourceAccount: "MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVAAAAAAAAAAAAAJLK",
}
testOperationsMarshalingRoundtrip(t, []Operation{&setTrustLineFlags}, true)
}