@@ -10,16 +10,37 @@ import (
10
10
"github.com/stellar/go/txnbuild"
11
11
"github.com/stretchr/testify/assert"
12
12
"github.com/stretchr/testify/mock"
13
+ "github.com/stretchr/testify/require"
13
14
15
+ "github.com/stellar/wallet-backend/internal/db"
16
+ "github.com/stellar/wallet-backend/internal/db/dbtest"
14
17
"github.com/stellar/wallet-backend/internal/services"
15
18
"github.com/stellar/wallet-backend/internal/signing"
16
19
"github.com/stellar/wallet-backend/internal/signing/store"
17
20
"github.com/stellar/wallet-backend/internal/tss/utils"
18
21
)
19
22
20
23
func TestValidateOptions (t * testing.T ) {
24
+ dbt := dbtest .Open (t )
25
+ defer dbt .Close ()
26
+ dbConnectionPool , err := db .OpenDBConnectionPool (dbt .DSN )
27
+ require .NoError (t , err )
28
+ defer dbConnectionPool .Close ()
29
+ t .Run ("return_error_when_db_nil" , func (t * testing.T ) {
30
+ opts := TransactionServiceOptions {
31
+ DistributionAccountSignatureClient : nil ,
32
+ ChannelAccountSignatureClient : & signing.SignatureClientMock {},
33
+ ChannelAccountStore : & store.ChannelAccountStoreMock {},
34
+ RPCService : & services.RPCServiceMock {},
35
+ BaseFee : 114 ,
36
+ }
37
+ err := opts .ValidateOptions ()
38
+ assert .Equal (t , "DB cannot be nil" , err .Error ())
39
+
40
+ })
21
41
t .Run ("return_error_when_distribution_signature_client_nil" , func (t * testing.T ) {
22
42
opts := TransactionServiceOptions {
43
+ DB : dbConnectionPool ,
23
44
DistributionAccountSignatureClient : nil ,
24
45
ChannelAccountSignatureClient : & signing.SignatureClientMock {},
25
46
ChannelAccountStore : & store.ChannelAccountStoreMock {},
@@ -33,6 +54,7 @@ func TestValidateOptions(t *testing.T) {
33
54
34
55
t .Run ("return_error_when_channel_signature_client_nil" , func (t * testing.T ) {
35
56
opts := TransactionServiceOptions {
57
+ DB : dbConnectionPool ,
36
58
DistributionAccountSignatureClient : & signing.SignatureClientMock {},
37
59
ChannelAccountSignatureClient : nil ,
38
60
ChannelAccountStore : & store.ChannelAccountStoreMock {},
@@ -45,6 +67,7 @@ func TestValidateOptions(t *testing.T) {
45
67
46
68
t .Run ("return_error_when_channel_account_store_nil" , func (t * testing.T ) {
47
69
opts := TransactionServiceOptions {
70
+ DB : dbConnectionPool ,
48
71
DistributionAccountSignatureClient : & signing.SignatureClientMock {},
49
72
ChannelAccountSignatureClient : & signing.SignatureClientMock {},
50
73
ChannelAccountStore : nil ,
@@ -57,6 +80,7 @@ func TestValidateOptions(t *testing.T) {
57
80
58
81
t .Run ("return_error_when_rpc_client_nil" , func (t * testing.T ) {
59
82
opts := TransactionServiceOptions {
83
+ DB : dbConnectionPool ,
60
84
DistributionAccountSignatureClient : & signing.SignatureClientMock {},
61
85
ChannelAccountSignatureClient : & signing.SignatureClientMock {},
62
86
ChannelAccountStore : & store.ChannelAccountStoreMock {},
@@ -69,6 +93,7 @@ func TestValidateOptions(t *testing.T) {
69
93
70
94
t .Run ("return_error_when_base_fee_too_low" , func (t * testing.T ) {
71
95
opts := TransactionServiceOptions {
96
+ DB : dbConnectionPool ,
72
97
DistributionAccountSignatureClient : & signing.SignatureClientMock {},
73
98
ChannelAccountSignatureClient : & signing.SignatureClientMock {},
74
99
ChannelAccountStore : & store.ChannelAccountStoreMock {},
@@ -81,18 +106,24 @@ func TestValidateOptions(t *testing.T) {
81
106
}
82
107
83
108
func TestBuildAndSignTransactionWithChannelAccount (t * testing.T ) {
109
+ dbt := dbtest .Open (t )
110
+ defer dbt .Close ()
111
+ dbConnectionPool , err := db .OpenDBConnectionPool (dbt .DSN )
112
+ require .NoError (t , err )
113
+ defer dbConnectionPool .Close ()
84
114
distributionAccountSignatureClient := signing.SignatureClientMock {}
85
115
channelAccountSignatureClient := signing.SignatureClientMock {}
86
116
channelAccountStore := store.ChannelAccountStoreMock {}
87
117
mockRPCService := & services.RPCServiceMock {}
88
118
txService , _ := NewTransactionService (TransactionServiceOptions {
119
+ DB : dbConnectionPool ,
89
120
DistributionAccountSignatureClient : & distributionAccountSignatureClient ,
90
121
ChannelAccountSignatureClient : & channelAccountSignatureClient ,
91
122
ChannelAccountStore : & channelAccountStore ,
92
123
RPCService : mockRPCService ,
93
124
BaseFee : 114 ,
94
125
})
95
-
126
+ atomicTxErrorPrefix := "running atomic function in RunInTransactionWithResult: "
96
127
t .Run ("channel_account_signature_client_get_account_public_key_err" , func (t * testing.T ) {
97
128
channelAccountSignatureClient .
98
129
On ("GetAccountPublicKey" , context .Background ()).
@@ -103,7 +134,7 @@ func TestBuildAndSignTransactionWithChannelAccount(t *testing.T) {
103
134
104
135
channelAccountSignatureClient .AssertExpectations (t )
105
136
assert .Empty (t , tx )
106
- assert .Equal (t , "getting channel account public key: channel accounts unavailable" , err .Error ())
137
+ assert .Equal (t , atomicTxErrorPrefix + "getting channel account public key: channel accounts unavailable" , err .Error ())
107
138
})
108
139
109
140
t .Run ("rpc_client_get_account_seq_err" , func (t * testing.T ) {
@@ -124,7 +155,7 @@ func TestBuildAndSignTransactionWithChannelAccount(t *testing.T) {
124
155
channelAccountSignatureClient .AssertExpectations (t )
125
156
assert .Empty (t , tx )
126
157
expectedErr := fmt .Errorf ("getting ledger sequence for channel account public key: %s: rpc service down" , channelAccount .Address ())
127
- assert .Equal (t , expectedErr .Error (), err .Error ())
158
+ assert .Equal (t , atomicTxErrorPrefix + expectedErr .Error (), err .Error ())
128
159
})
129
160
130
161
t .Run ("build_tx_fails" , func (t * testing.T ) {
@@ -144,7 +175,7 @@ func TestBuildAndSignTransactionWithChannelAccount(t *testing.T) {
144
175
145
176
channelAccountSignatureClient .AssertExpectations (t )
146
177
assert .Empty (t , tx )
147
- assert .Equal (t , "building transaction: transaction has no operations" , err .Error ())
178
+ assert .Equal (t , atomicTxErrorPrefix + "building transaction: transaction has no operations" , err .Error ())
148
179
149
180
})
150
181
@@ -180,7 +211,7 @@ func TestBuildAndSignTransactionWithChannelAccount(t *testing.T) {
180
211
channelAccountSignatureClient .AssertExpectations (t )
181
212
channelAccountStore .AssertExpectations (t )
182
213
assert .Empty (t , tx )
183
- assert .Equal (t , "assigning channel account to tx: unable to assign channel account to tx" , err .Error ())
214
+ assert .Equal (t , atomicTxErrorPrefix + "assigning channel account to tx: unable to assign channel account to tx" , err .Error ())
184
215
})
185
216
186
217
t .Run ("sign_stellar_transaction_w_channel_account_err" , func (t * testing.T ) {
@@ -261,11 +292,17 @@ func TestBuildAndSignTransactionWithChannelAccount(t *testing.T) {
261
292
}
262
293
263
294
func TestBuildFeeBumpTransaction (t * testing.T ) {
295
+ dbt := dbtest .Open (t )
296
+ defer dbt .Close ()
297
+ dbConnectionPool , err := db .OpenDBConnectionPool (dbt .DSN )
298
+ require .NoError (t , err )
299
+ defer dbConnectionPool .Close ()
264
300
distributionAccountSignatureClient := signing.SignatureClientMock {}
265
301
channelAccountSignatureClient := signing.SignatureClientMock {}
266
302
channelAccountStore := store.ChannelAccountStoreMock {}
267
303
mockRPCService := & services.RPCServiceMock {}
268
304
txService , _ := NewTransactionService (TransactionServiceOptions {
305
+ DB : dbConnectionPool ,
269
306
DistributionAccountSignatureClient : & distributionAccountSignatureClient ,
270
307
ChannelAccountSignatureClient : & channelAccountSignatureClient ,
271
308
ChannelAccountStore : & channelAccountStore ,
0 commit comments