forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clawback_test.go
101 lines (88 loc) · 3.04 KB
/
clawback_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 TestClawbackValidateFrom(t *testing.T) {
kp0 := newKeypair0()
sourceAccount := NewSimpleAccount(kp0.Address(), int64(9605939170639898))
clawback := Clawback{
From: "",
Amount: "10",
Asset: CreditAsset{"", kp0.Address()},
}
_, err := NewTransaction(
TransactionParams{
SourceAccount: &sourceAccount,
IncrementSequenceNum: false,
Operations: []Operation{&clawback},
BaseFee: MinBaseFee,
Timebounds: NewInfiniteTimeout(),
},
)
if assert.Error(t, err) {
expected := "validation failed for *txnbuild.Clawback operation: Field: From"
assert.Contains(t, err.Error(), expected)
}
}
func TestClawbackValidateAmount(t *testing.T) {
kp0 := newKeypair0()
sourceAccount := NewSimpleAccount(kp0.Address(), int64(9605939170639898))
clawback := Clawback{
From: "GB7BDSZU2Y27LYNLALKKALB52WS2IZWYBDGY6EQBLEED3TJOCVMZRH7H",
Amount: "ten",
Asset: CreditAsset{"", kp0.Address()},
}
_, err := NewTransaction(
TransactionParams{
SourceAccount: &sourceAccount,
IncrementSequenceNum: false,
Operations: []Operation{&clawback},
BaseFee: MinBaseFee,
Timebounds: NewInfiniteTimeout(),
},
)
if assert.Error(t, err) {
expected := "validation failed for *txnbuild.Clawback operation: Field: Amount, Error: invalid amount format: ten"
assert.Contains(t, err.Error(), expected)
}
}
func TestClawbackValidateAsset(t *testing.T) {
kp0 := newKeypair0()
sourceAccount := NewSimpleAccount(kp0.Address(), int64(9605939170639898))
clawback := Clawback{
From: "GB7BDSZU2Y27LYNLALKKALB52WS2IZWYBDGY6EQBLEED3TJOCVMZRH7H",
Amount: "10",
Asset: CreditAsset{},
}
_, err := NewTransaction(
TransactionParams{
SourceAccount: &sourceAccount,
IncrementSequenceNum: false,
Operations: []Operation{&clawback},
BaseFee: MinBaseFee,
Timebounds: NewInfiniteTimeout(),
},
)
if assert.Error(t, err) {
expected := "validation failed for *txnbuild.Clawback operation: Field: Asset, Error: asset code length must be between 1 and 12 characters"
assert.Contains(t, err.Error(), expected)
}
}
func TestClawbackRoundTrip(t *testing.T) {
clawback := Clawback{
SourceAccount: "GB7BDSZU2Y27LYNLALKKALB52WS2IZWYBDGY6EQBLEED3TJOCVMZRH7H",
From: "GB7BDSZU2Y27LYNLALKKALB52WS2IZWYBDGY6EQBLEED3TJOCVMZRH7H",
Amount: "10.0000000",
Asset: CreditAsset{"USD", "GCXKG6RN4ONIEPCMNFB732A436Z5PNDSRLGWK7GBLCMQLIFO4S7EYWVU"},
}
testOperationsMarshallingRoundtrip(t, []Operation{&clawback}, false)
// with muxed accounts
clawback = Clawback{
SourceAccount: "MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVAAAAAAAAAAAAAJLK",
From: "MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVAAAAAAAAAAAAAJLK",
Amount: "10.0000000",
Asset: CreditAsset{"USD", "GCXKG6RN4ONIEPCMNFB732A436Z5PNDSRLGWK7GBLCMQLIFO4S7EYWVU"},
}
testOperationsMarshallingRoundtrip(t, []Operation{&clawback}, true)
}