forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
allow_trust_test.go
78 lines (68 loc) · 2.25 KB
/
allow_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
package txnbuild
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestAllowTrustValidateAsset(t *testing.T) {
kp0 := newKeypair0()
kp1 := newKeypair1()
sourceAccount := NewSimpleAccount(kp0.Address(), int64(40385577484366))
issuedAsset := CreditAsset{"", kp1.Address()}
allowTrust := AllowTrust{
Trustor: kp1.Address(),
Type: issuedAsset,
Authorize: true,
}
_, err := NewTransaction(
TransactionParams{
SourceAccount: &sourceAccount,
Operations: []Operation{&allowTrust},
Preconditions: Preconditions{TimeBounds: NewInfiniteTimeout()},
BaseFee: MinBaseFee,
},
)
if assert.Error(t, err) {
expected := "validation failed for *txnbuild.AllowTrust operation: Field: Type, Error: asset code length must be between 1 and 12 characters"
assert.Contains(t, err.Error(), expected)
}
}
func TestAllowTrustValidateTrustor(t *testing.T) {
kp0 := newKeypair0()
kp1 := newKeypair1()
sourceAccount := NewSimpleAccount(kp0.Address(), int64(40385577484366))
issuedAsset := CreditAsset{"ABCD", kp1.Address()}
allowTrust := AllowTrust{
Trustor: "",
Type: issuedAsset,
Authorize: true,
}
_, err := NewTransaction(
TransactionParams{
SourceAccount: &sourceAccount,
Operations: []Operation{&allowTrust},
Preconditions: Preconditions{TimeBounds: NewInfiniteTimeout()},
BaseFee: MinBaseFee,
},
)
if assert.Error(t, err) {
expected := "validation failed for *txnbuild.AllowTrust operation: Field: Trustor, Error: public key is undefined"
assert.Contains(t, err.Error(), expected)
}
}
func TestAllowTrustRoundtrip(t *testing.T) {
allowTrust := AllowTrust{
SourceAccount: "GB7BDSZU2Y27LYNLALKKALB52WS2IZWYBDGY6EQBLEED3TJOCVMZRH7H",
Trustor: "GB7BDSZU2Y27LYNLALKKALB52WS2IZWYBDGY6EQBLEED3TJOCVMZRH7H",
Type: CreditAsset{"USD", ""},
Authorize: true,
}
testOperationsMarshalingRoundtrip(t, []Operation{&allowTrust}, false)
// with muxed accounts
allowTrust = AllowTrust{
SourceAccount: "MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVAAAAAAAAAAAAAJLK",
Trustor: "GB7BDSZU2Y27LYNLALKKALB52WS2IZWYBDGY6EQBLEED3TJOCVMZRH7H",
Type: CreditAsset{"USD", ""},
Authorize: true,
}
testOperationsMarshalingRoundtrip(t, []Operation{&allowTrust}, true)
}