-
Notifications
You must be signed in to change notification settings - Fork 2
/
wallets_test.go
120 lines (109 loc) · 4.55 KB
/
wallets_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 sila_test
import (
"testing"
uuid "github.com/satori/go.uuid"
. "github.com/smartystreets/goconvey/convey"
"github.com/bpancost/sila"
"github.com/bpancost/sila/domain"
)
func TestClient_Wallets(t *testing.T) {
Convey("Given the Sila client exists", t, func() {
testConfig, err := readTestConfig()
So(err, ShouldBeNil)
userHandle := testConfig.UserHandle
userWalletPrivateKey := testConfig.UserWalletPrivateKeyHex
userWalletAddress, err := sila.GetWalletAddress(userWalletPrivateKey)
So(err, ShouldBeNil)
silaClient, err := sila.NewClient(
testConfig.AuthPrivateKeyKex,
testConfig.AuthHandle,
sila.Sandbox)
So(err, ShouldBeNil)
Convey("And the specified integration user exists and has passed KYC", func() {
ensureIntegrationUserExists(silaClient, userHandle, userWalletAddress, userWalletPrivateKey)
Convey("A call to get a main wallet's balance should succeed", func() {
response, err := silaClient.GetWalletBalance(userWalletAddress).Do()
So(err, ShouldBeNil)
So(response.Success, ShouldBeTrue)
So(response.Status, ShouldEqual, "SUCCESS")
So(response.ValidationDetails, ShouldBeNil)
})
Convey("A call to get the main wallet should succeed", func() {
response, err := silaClient.GetWallet(userHandle).
SetRef("My Reference").
Do(userWalletPrivateKey)
So(err, ShouldBeNil)
So(response.Success, ShouldBeTrue)
So(response.Status, ShouldEqual, "SUCCESS")
So(response.ValidationDetails, ShouldBeNil)
So(response.Reference, ShouldEqual, "My Reference")
So(response.IsWhitelisted, ShouldBeTrue)
So(response.Wallet.BlockchainAddress, ShouldEqual, userWalletAddress)
})
Convey("A call to get a user's wallets should succeed", func() {
response, err := silaClient.GetWallets(userHandle).
SetSearchFilters(domain.WalletSearchFilters{
Page: 1,
PerPage: 5,
SortAscending: true,
}).
Do(userWalletPrivateKey)
So(err, ShouldBeNil)
So(response.Success, ShouldBeTrue)
So(response.Status, ShouldEqual, "SUCCESS")
So(response.ValidationDetails, ShouldBeNil)
So(response.Wallets, ShouldNotBeEmpty)
So(response.Page, ShouldEqual, 1)
So(response.ReturnedCount, ShouldBeGreaterThanOrEqualTo, 1)
So(response.TotalCount, ShouldBeGreaterThanOrEqualTo, 1)
So(response.TotalPageCount, ShouldBeGreaterThanOrEqualTo, 1)
})
Convey("A new wallet private key and address are generated for registration, along with a signature", func() {
newWalletPrivateKey, err := sila.GenerateNewPrivateKey()
So(err, ShouldBeNil)
newWalletAddress, err := sila.GetWalletAddress(newWalletPrivateKey)
So(err, ShouldBeNil)
signature, err := sila.GenerateWalletSignature([]byte(newWalletAddress), newWalletPrivateKey)
Convey("A call to register the wallet should succeed", func() {
response, err := silaClient.RegisterWallet(userHandle).
SetRef("My Reference").
SetWallet("My Integration Wallet", newWalletAddress, signature).
Do(userWalletPrivateKey)
So(err, ShouldBeNil)
So(response.Success, ShouldBeTrue)
So(response.Status, ShouldEqual, "SUCCESS")
So(response.ValidationDetails, ShouldBeNil)
So(response.Reference, ShouldEqual, "My Reference")
So(response.WalletNickname, ShouldStartWith, "My Integration Wallet")
Convey("A call to update the new wallet's nickname should succeed", func() {
updatedWalletNickname := uuid.NewV4().String()
response, err := silaClient.UpdateWallet(userHandle).
SetRef("My Reference").
SetNickname(updatedWalletNickname).
Do(newWalletPrivateKey)
So(err, ShouldBeNil)
So(response.Success, ShouldBeTrue)
So(response.Status, ShouldEqual, "SUCCESS")
So(response.Message, ShouldEqual, "Wallet updated.")
So(response.ValidationDetails, ShouldBeNil)
So(response.Reference, ShouldEqual, "My Reference")
So(response.Wallet.Nickname, ShouldEqual, updatedWalletNickname)
So(response.Wallet.Default, ShouldBeFalse)
So(response.Wallet.BlockchainAddress, ShouldEqual, newWalletAddress)
So(response.Changes, ShouldNotBeEmpty)
Convey("A call to delete the new wallet should succeed", func() {
response, err := silaClient.DeleteWallet(userHandle).
SetRef("My Reference").
Do(newWalletPrivateKey)
So(err, ShouldBeNil)
So(response.Success, ShouldBeTrue)
So(response.Status, ShouldEqual, "SUCCESS")
So(response.ValidationDetails, ShouldBeNil)
So(response.Reference, ShouldEqual, "My Reference")
})
})
})
})
})
})
}