-
Notifications
You must be signed in to change notification settings - Fork 499
/
create_claimable_balance_test.go
92 lines (78 loc) · 2.87 KB
/
create_claimable_balance_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
package txnbuild
import (
"testing"
"time"
"github.com/stellar/go/keypair"
"github.com/stellar/go/network"
"github.com/stretchr/testify/assert"
)
func TestCreateClaimableBalanceRoundTrip(t *testing.T) {
and := AndPredicate(BeforeAbsoluteTimePredicate(100), BeforeRelativeTimePredicate(10))
createNativeBalance := &CreateClaimableBalance{
Amount: "1234.0000000",
Asset: NativeAsset{},
Destinations: []Claimant{
NewClaimant(newKeypair1().Address(), &UnconditionalPredicate),
NewClaimant(newKeypair1().Address(), &and),
},
}
not := NotPredicate(UnconditionalPredicate)
or := OrPredicate(BeforeAbsoluteTimePredicate(100), BeforeRelativeTimePredicate(10))
createAssetBalance := &CreateClaimableBalance{
Amount: "99.0000000",
Asset: CreditAsset{
Code: "COP",
Issuer: "GB56OJGSA6VHEUFZDX6AL2YDVG2TS5JDZYQJHDYHBDH7PCD5NIQKLSDO",
},
Destinations: []Claimant{
NewClaimant(newKeypair1().Address(), ¬),
NewClaimant(newKeypair1().Address(), &or),
},
}
testOperationsMarshalingRoundtrip(t, []Operation{createNativeBalance, createAssetBalance}, false)
createNativeBalanceWithMuxedAcounts := &CreateClaimableBalance{
SourceAccount: "MA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVAAAAAAAAAAAAAJLK",
Amount: "1234.0000000",
Asset: NativeAsset{},
Destinations: []Claimant{
NewClaimant(newKeypair1().Address(), &UnconditionalPredicate),
NewClaimant(newKeypair1().Address(), &and),
},
}
testOperationsMarshalingRoundtrip(t, []Operation{createNativeBalanceWithMuxedAcounts}, true)
}
func TestClaimableBalanceID(t *testing.T) {
A := "SCZANGBA5YHTNYVVV4C3U252E2B6P6F5T3U6MM63WBSBZATAQI3EBTQ4"
B := "GA2C5RFPE6GCKMY3US5PAB6UZLKIGSPIUKSLRB6Q723BM2OARMDUYEJ5"
aKeys := keypair.MustParseFull(A)
aAccount := SimpleAccount{AccountID: aKeys.Address(), Sequence: 123}
soon := time.Now().Add(time.Second * 60)
bCanClaim := BeforeRelativeTimePredicate(60)
aCanReclaim := NotPredicate(BeforeAbsoluteTimePredicate(soon.Unix()))
claimants := []Claimant{
NewClaimant(B, &bCanClaim),
NewClaimant(aKeys.Address(), &aCanReclaim),
}
claimableBalanceEntry := CreateClaimableBalance{
Destinations: claimants,
Asset: NativeAsset{},
Amount: "420",
SourceAccount: "GB56OJGSA6VHEUFZDX6AL2YDVG2TS5JDZYQJHDYHBDH7PCD5NIQKLSDO",
}
// Build and sign the transaction
tx, err := NewTransaction(
TransactionParams{
SourceAccount: &aAccount,
IncrementSequenceNum: true,
BaseFee: MinBaseFee,
Preconditions: Preconditions{TimeBounds: NewInfiniteTimeout()},
Operations: []Operation{&claimableBalanceEntry},
},
)
assert.NoError(t, err)
tx, err = tx.Sign(network.TestNetworkPassphrase, aKeys)
assert.NoError(t, err)
balanceId, err := tx.ClaimableBalanceID(0)
assert.NoError(t, err)
assert.Equal(t, "0000000095001252ab3b4d16adbfa5364ce526dfcda03cb2258b827edbb2e0450087be51", balanceId)
}