forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
revoke_sponsorship_test.go
120 lines (114 loc) · 3.1 KB
/
revoke_sponsorship_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
package txnbuild
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stellar/go/xdr"
)
func TestRevokeSponsorship(t *testing.T) {
accountAddress := "GCCOBXW2XQNUSL467IEILE6MMCNRR66SSVL4YQADUNYYNUVREF3FIV2Z"
accountAddress2 := "GBUKBCG5VLRKAVYAIREJRUJHOKLIADZJOICRW43WVJCLES52BDOTCQZU"
claimableBalanceId, err := xdr.MarshalHex(xdr.ClaimableBalanceId{
Type: xdr.ClaimableBalanceIdTypeClaimableBalanceIdTypeV0,
V0: &xdr.Hash{0xca, 0xfe, 0xba, 0xbe, 0xde, 0xad, 0xbe, 0xef},
})
assert.NoError(t, err)
for _, testcase := range []struct {
name string
op RevokeSponsorship
}{
{
name: "Account",
op: RevokeSponsorship{
SponsorshipType: RevokeSponsorshipTypeAccount,
Account: &accountAddress,
},
},
{
name: "Account with source",
op: RevokeSponsorship{
SponsorshipType: RevokeSponsorshipTypeAccount,
Account: &accountAddress,
SourceAccount: accountAddress2,
},
},
{
name: "TrustLine",
op: RevokeSponsorship{
SponsorshipType: RevokeSponsorshipTypeTrustLine,
TrustLine: &TrustLineID{
Account: accountAddress,
Asset: CreditAsset{
Code: "USD",
Issuer: newKeypair0().Address(),
},
},
},
},
{
name: "Offer",
op: RevokeSponsorship{
SponsorshipType: RevokeSponsorshipTypeOffer,
Offer: &OfferID{
SellerAccountAddress: accountAddress,
OfferID: 0xdeadbeef,
},
},
},
{
name: "Data",
op: RevokeSponsorship{
SponsorshipType: RevokeSponsorshipTypeData,
Data: &DataID{
Account: accountAddress,
DataName: "foobar",
},
},
},
{
name: "Data",
op: RevokeSponsorship{
SponsorshipType: RevokeSponsorshipTypeClaimableBalance,
ClaimableBalance: &claimableBalanceId,
},
},
{
name: "Signer",
op: RevokeSponsorship{
SponsorshipType: RevokeSponsorshipTypeSigner,
Signer: &SignerID{
AccountID: accountAddress,
SignerAddress: "XBU2RRGLXH3E5CQHTD3ODLDF2BWDCYUSSBLLZ5GNW7JXHDIYKXZWGTOG",
},
},
},
} {
t.Run(testcase.name, func(t *testing.T) {
op := testcase.op
assert.NoError(t, op.Validate(false))
xdrOp, err := op.BuildXDR(false)
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 RevokeSponsorship
assert.NoError(t, op2.FromXDR(xdrOp2, false))
assert.Equal(t, op, op2)
testOperationsMarshallingRoundtrip(t, []Operation{&testcase.op}, false)
})
}
// without muxed accounts
revokeOp := RevokeSponsorship{
SourceAccount: "GB7BDSZU2Y27LYNLALKKALB52WS2IZWYBDGY6EQBLEED3TJOCVMZRH7H",
SponsorshipType: RevokeSponsorshipTypeAccount,
Account: &accountAddress,
}
testOperationsMarshallingRoundtrip(t, []Operation{&revokeOp}, false)
// with muxed accounts
revokeOp = RevokeSponsorship{
SourceAccount: "MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVAAAAAAAAAAAAAJLK",
SponsorshipType: RevokeSponsorshipTypeAccount,
Account: &accountAddress,
}
testOperationsMarshallingRoundtrip(t, []Operation{&revokeOp}, true)
}