psf-multisig-approval 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,290 @@
1
+ /*
2
+ Mock data for the main-index-unit.js unit test library.
3
+ */
4
+
5
+ const approvalTxDetails01 = {
6
+ txid: 'a63f9fbcc901316e6e89f5a8caaad6b2ab268278b29866c6c22088bd3ab93900',
7
+ hash: 'a63f9fbcc901316e6e89f5a8caaad6b2ab268278b29866c6c22088bd3ab93900',
8
+ version: 2,
9
+ size: 595,
10
+ locktime: 0,
11
+ vin: [
12
+ {
13
+ txid: 'f630f4db4b88c604e0670558782dfcfe7ad4b3d06c033dafa36f1505c3dbc58d',
14
+ vout: 0,
15
+ scriptSig: {
16
+ asm: '0 304402201474f95ab0e5fa3b5d6bd5f83d904c23a448f11c51a4b007b759663e76856e72022008b209df76b75e15422436f893b1b9f9f0671d65f41d0d419313f651e408c596[ALL|FORKID] 304402205ccff79c16a58da52ced457d6e898857df8fca650c7a4501406c95659c81f1e202201f79ab6615e75ae519ba8ee9d19718892dc07f3f307673149cafc5f487eb0ac0[ALL|FORKID] 3045022100dd9c0445509ada78622ae4551503c7bd84505bacfdb13994104e86e1c615a39f02205b895941fdd2a8082d27801904979992c4a6eaac3c85dd056c3c1b32865cff40[ALL|FORKID] 5321021ca211a04a1d489ae77e01c28c97b02e733893890fda00a359ca8956c2e0d25921024be54accec310c2636140336ae548d610ba9b7ce300b3f42494b4a6f2963731f21033c930d4cff4ba68a70f7a21443e20ad4176173380d21f8c3ce27f7ce947f3246210361fd21512b9072e8f6b984d9b04c57e5779867c2ad002999372268770fcb26742103b9bdc40c478ab0536be29c368b26c48a5e8d6867fc34b77c727ab690365aae9155ae',
17
+ hex: '0047304402201474f95ab0e5fa3b5d6bd5f83d904c23a448f11c51a4b007b759663e76856e72022008b209df76b75e15422436f893b1b9f9f0671d65f41d0d419313f651e408c5964147304402205ccff79c16a58da52ced457d6e898857df8fca650c7a4501406c95659c81f1e202201f79ab6615e75ae519ba8ee9d19718892dc07f3f307673149cafc5f487eb0ac041483045022100dd9c0445509ada78622ae4551503c7bd84505bacfdb13994104e86e1c615a39f02205b895941fdd2a8082d27801904979992c4a6eaac3c85dd056c3c1b32865cff40414cad5321021ca211a04a1d489ae77e01c28c97b02e733893890fda00a359ca8956c2e0d25921024be54accec310c2636140336ae548d610ba9b7ce300b3f42494b4a6f2963731f21033c930d4cff4ba68a70f7a21443e20ad4176173380d21f8c3ce27f7ce947f3246210361fd21512b9072e8f6b984d9b04c57e5779867c2ad002999372268770fcb26742103b9bdc40c478ab0536be29c368b26c48a5e8d6867fc34b77c727ab690365aae9155ae'
18
+ },
19
+ sequence: 4294967295,
20
+ address: 'bitcoincash:pqntzt6wcp38h8ud68wjnwh437uek76lhvhlwcm4fj',
21
+ value: 0.000756
22
+ }
23
+ ],
24
+ vout: [
25
+ {
26
+ value: 0,
27
+ n: 0,
28
+ scriptPubKey: {
29
+ asm: 'OP_RETURN 19516672076435521 66386561316663643434383161646664363263363235316336613466363366336435616333643566646363333862333530643332316439333235346466363566',
30
+ hex: '6a07415050524f56454066386561316663643434383161646664363263363235316336613466363366336435616333643566646363333862333530643332316439333235346466363566',
31
+ type: 'nulldata'
32
+ }
33
+ },
34
+ {
35
+ value: 0.00001,
36
+ n: 1,
37
+ scriptPubKey: {
38
+ asm: 'OP_DUP OP_HASH160 dd9d58d7672be6675262069534b173c113f59e85 OP_EQUALVERIFY OP_CHECKSIG',
39
+ hex: '76a914dd9d58d7672be6675262069534b173c113f59e8588ac',
40
+ reqSigs: 1,
41
+ type: 'pubkeyhash',
42
+ addresses: [
43
+ 'bitcoincash:qrwe6kxhvu47ve6jvgrf2d93w0q38av7s5xm9xfehr'
44
+ ]
45
+ }
46
+ },
47
+ {
48
+ value: 0.00072671,
49
+ n: 2,
50
+ scriptPubKey: {
51
+ asm: 'OP_HASH160 26b12f4ec0627b9f8dd1dd29baf58fb99b7b5fbb OP_EQUAL',
52
+ hex: 'a91426b12f4ec0627b9f8dd1dd29baf58fb99b7b5fbb87',
53
+ reqSigs: 1,
54
+ type: 'scripthash',
55
+ addresses: [
56
+ 'bitcoincash:pqntzt6wcp38h8ud68wjnwh437uek76lhvhlwcm4fj'
57
+ ]
58
+ }
59
+ }
60
+ ],
61
+ hex: '02000000018dc5dbc305156fa3af3d036cd0b3d47afefc2d78580567e004c6884bdbf430f600000000fd89010047304402201474f95ab0e5fa3b5d6bd5f83d904c23a448f11c51a4b007b759663e76856e72022008b209df76b75e15422436f893b1b9f9f0671d65f41d0d419313f651e408c5964147304402205ccff79c16a58da52ced457d6e898857df8fca650c7a4501406c95659c81f1e202201f79ab6615e75ae519ba8ee9d19718892dc07f3f307673149cafc5f487eb0ac041483045022100dd9c0445509ada78622ae4551503c7bd84505bacfdb13994104e86e1c615a39f02205b895941fdd2a8082d27801904979992c4a6eaac3c85dd056c3c1b32865cff40414cad5321021ca211a04a1d489ae77e01c28c97b02e733893890fda00a359ca8956c2e0d25921024be54accec310c2636140336ae548d610ba9b7ce300b3f42494b4a6f2963731f21033c930d4cff4ba68a70f7a21443e20ad4176173380d21f8c3ce27f7ce947f3246210361fd21512b9072e8f6b984d9b04c57e5779867c2ad002999372268770fcb26742103b9bdc40c478ab0536be29c368b26c48a5e8d6867fc34b77c727ab690365aae9155aeffffffff0300000000000000004a6a07415050524f56454066386561316663643434383161646664363263363235316336613466363366336435616333643566646363333862333530643332316439333235346466363566e8030000000000001976a914dd9d58d7672be6675262069534b173c113f59e8588acdf1b01000000000017a91426b12f4ec0627b9f8dd1dd29baf58fb99b7b5fbb8700000000',
62
+ blockhash: '000000000000000003e90bff17eeb147b0fb532abeddd5ba5a7ec23347e300ee',
63
+ confirmations: 6450,
64
+ time: 1677006961,
65
+ blocktime: 1677006961,
66
+ isValidSlp: false
67
+ }
68
+
69
+ const updateTxDetails01 = {
70
+ txid: 'f8ea1fcd4481adfd62c6251c6a4f63f3d5ac3d5fdcc38b350d321d93254df65f',
71
+ hash: 'f8ea1fcd4481adfd62c6251c6a4f63f3d5ac3d5fdcc38b350d321d93254df65f',
72
+ version: 2,
73
+ size: 361,
74
+ locktime: 0,
75
+ vin: [
76
+ {
77
+ txid: '2879a62158f0c3953750688e439d87737face939b5493b213f2e7d3bf505ddc4',
78
+ vout: 2,
79
+ scriptSig: {
80
+ asm: '3045022100919192436273a7b53994e151d6e2359934fcdb17f60f37954fab06f5012fccea02207c329deb48b0eaff25651360ac71d159b8b0bb49072aea3a6d4b657e61f24c30[ALL|FORKID] 02239ca86fcc2910aefb3bd06419c15bd542a7ce4e1c34c48ca9d398640cf94a3e',
81
+ hex: '483045022100919192436273a7b53994e151d6e2359934fcdb17f60f37954fab06f5012fccea02207c329deb48b0eaff25651360ac71d159b8b0bb49072aea3a6d4b657e61f24c30412102239ca86fcc2910aefb3bd06419c15bd542a7ce4e1c34c48ca9d398640cf94a3e'
82
+ },
83
+ sequence: 4294967295,
84
+ address: 'bitcoincash:qz4mn3ayguhyylz50zsg953yzs8ay3akrg3wle6qj6',
85
+ value: 0.00710985
86
+ }
87
+ ],
88
+ vout: [
89
+ {
90
+ value: 0,
91
+ n: 0,
92
+ scriptPubKey: {
93
+ asm: 'OP_RETURN 0 7b22636964223a226261667962656962356436733674337471346c687770326f63767a377932777334637a676b726d686c687635793561657968366271726d73787869222c227473223a313637363536303234373136387d',
94
+ hex: '6a004c587b22636964223a226261667962656962356436733674337471346c687770326f63767a377932777334637a676b726d686c687635793561657968366271726d73787869222c227473223a313637363536303234373136387d',
95
+ type: 'nulldata'
96
+ }
97
+ },
98
+ {
99
+ value: 0.00002,
100
+ n: 1,
101
+ scriptPubKey: {
102
+ asm: 'OP_DUP OP_HASH160 203b64bfbaa9e58333295b621159ddebc591ecb1 OP_EQUALVERIFY OP_CHECKSIG',
103
+ hex: '76a914203b64bfbaa9e58333295b621159ddebc591ecb188ac',
104
+ reqSigs: 1,
105
+ type: 'pubkeyhash',
106
+ addresses: [
107
+ 'bitcoincash:qqsrke9lh257tqen99dkyy2emh4uty0vky9y0z0lsr'
108
+ ]
109
+ }
110
+ },
111
+ {
112
+ value: 0.00708077,
113
+ n: 2,
114
+ scriptPubKey: {
115
+ asm: 'OP_DUP OP_HASH160 abb9c7a4472e427c5478a082d224140fd247b61a OP_EQUALVERIFY OP_CHECKSIG',
116
+ hex: '76a914abb9c7a4472e427c5478a082d224140fd247b61a88ac',
117
+ reqSigs: 1,
118
+ type: 'pubkeyhash',
119
+ addresses: [
120
+ 'bitcoincash:qz4mn3ayguhyylz50zsg953yzs8ay3akrg3wle6qj6'
121
+ ]
122
+ }
123
+ },
124
+ {
125
+ value: 0.00000546,
126
+ n: 3,
127
+ scriptPubKey: {
128
+ asm: 'OP_DUP OP_HASH160 dd9d58d7672be6675262069534b173c113f59e85 OP_EQUALVERIFY OP_CHECKSIG',
129
+ hex: '76a914dd9d58d7672be6675262069534b173c113f59e8588ac',
130
+ reqSigs: 1,
131
+ type: 'pubkeyhash',
132
+ addresses: [
133
+ 'bitcoincash:qrwe6kxhvu47ve6jvgrf2d93w0q38av7s5xm9xfehr'
134
+ ]
135
+ }
136
+ }
137
+ ],
138
+ hex: '0200000001c4dd05f53b7d2e3f213b49b539e9ac7f73879d438e68503795c3f05821a67928020000006b483045022100919192436273a7b53994e151d6e2359934fcdb17f60f37954fab06f5012fccea02207c329deb48b0eaff25651360ac71d159b8b0bb49072aea3a6d4b657e61f24c30412102239ca86fcc2910aefb3bd06419c15bd542a7ce4e1c34c48ca9d398640cf94a3effffffff0400000000000000005c6a004c587b22636964223a226261667962656962356436733674337471346c687770326f63767a377932777334637a676b726d686c687635793561657968366271726d73787869222c227473223a313637363536303234373136387dd0070000000000001976a914203b64bfbaa9e58333295b621159ddebc591ecb188acedcd0a00000000001976a914abb9c7a4472e427c5478a082d224140fd247b61a88ac22020000000000001976a914dd9d58d7672be6675262069534b173c113f59e8588ac00000000',
139
+ blockhash: '000000000000000001a1b31a8ec4a683a13fbe287209949e4dd54045860f776e',
140
+ confirmations: 7239,
141
+ time: 1676561115,
142
+ blocktime: 1676561115,
143
+ isValidSlp: false
144
+ }
145
+
146
+ const pubkeys01 = [
147
+ {
148
+ addr: 'bitcoincash:qz4zsa22glal5c4jqm748xge657gwuw2d5t9nvg64p',
149
+ pubKey: '021ca211a04a1d489ae77e01c28c97b02e733893890fda00a359ca8956c2e0d259',
150
+ nft: 'e86164aaa06efac1d6453951f67beafe042f0bceb9312845a95355b1e93aa846'
151
+ },
152
+ {
153
+ addr: 'bitcoincash:qpfvh07mdt7yq5czndaz5qq4g9q3m87qpspy7xaxgu',
154
+ pubKey: '0361fd21512b9072e8f6b984d9b04c57e5779867c2ad002999372268770fcb2674',
155
+ nft: 'da7ccbd5e24e468c9e7402489ca9148b5e76e588b73cc4aa4bbf1ca41d5808ab'
156
+ },
157
+ {
158
+ addr: 'bitcoincash:qpsxtzaa7rg677akcc2znpenpsy5jr2ygywmfd45p2',
159
+ pubKey: '03b9bdc40c478ab0536be29c368b26c48a5e8d6867fc34b77c727ab690365aae91',
160
+ nft: '0ec318bede8c2f229db840a24cb63d662ad91e8e6c840e46e6a8ff2d173049ce'
161
+ },
162
+ {
163
+ addr: 'bitcoincash:qqk3aczzggvxnfm7rwm0f9yz20yr00dmpv2f3tasdr',
164
+ pubKey: '033c930d4cff4ba68a70f7a21443e20ad4176173380d21f8c3ce27f7ce947f3246',
165
+ nft: '51624e772adafd7c6a9da38774e4f654282199bd5402e049ee087fc2bd900882'
166
+ },
167
+ {
168
+ addr: 'bitcoincash:qpszha37cjn6n83hpxn7zz5ndaa35vygtcgslxhpuc',
169
+ pubKey: '024be54accec310c2636140336ae548d610ba9b7ce300b3f42494b4a6f2963731f',
170
+ nft: 'e70cc72eeb15c82e96b1f8127d3b138b2fc8ea101fe9c62302ec641c05d4b97d'
171
+ }
172
+ ]
173
+
174
+ const txHistory01 = [{
175
+ height: 780917,
176
+ tx_hash: 'a63f9fbcc901316e6e89f5a8caaad6b2ab268278b29866c6c22088bd3ab93900'
177
+ }]
178
+
179
+ const txHistory02 = [
180
+ {
181
+ height: 781137,
182
+ tx_hash: '095b299da0be5bb2367e62a5628cef603c7d6e709dd72f532632e9c0acf665d3'
183
+ },
184
+ {
185
+ height: 780917,
186
+ tx_hash: 'a63f9fbcc901316e6e89f5a8caaad6b2ab268278b29866c6c22088bd3ab93900'
187
+ }
188
+ ]
189
+
190
+ const tokenHolderInfo01 = {
191
+ keys: [
192
+ {
193
+ addr: 'bitcoincash:qz4zsa22glal5c4jqm748xge657gwuw2d5t9nvg64p',
194
+ pubKey: '021ca211a04a1d489ae77e01c28c97b02e733893890fda00a359ca8956c2e0d259',
195
+ nft: 'e86164aaa06efac1d6453951f67beafe042f0bceb9312845a95355b1e93aa846'
196
+ },
197
+ {
198
+ addr: 'bitcoincash:qpfvh07mdt7yq5czndaz5qq4g9q3m87qpspy7xaxgu',
199
+ pubKey: '0361fd21512b9072e8f6b984d9b04c57e5779867c2ad002999372268770fcb2674',
200
+ nft: 'da7ccbd5e24e468c9e7402489ca9148b5e76e588b73cc4aa4bbf1ca41d5808ab'
201
+ },
202
+ {
203
+ addr: 'bitcoincash:qpsxtzaa7rg677akcc2znpenpsy5jr2ygywmfd45p2',
204
+ pubKey: '03b9bdc40c478ab0536be29c368b26c48a5e8d6867fc34b77c727ab690365aae91',
205
+ nft: '0ec318bede8c2f229db840a24cb63d662ad91e8e6c840e46e6a8ff2d173049ce'
206
+ },
207
+ {
208
+ addr: 'bitcoincash:qqk3aczzggvxnfm7rwm0f9yz20yr00dmpv2f3tasdr',
209
+ pubKey: '033c930d4cff4ba68a70f7a21443e20ad4176173380d21f8c3ce27f7ce947f3246',
210
+ nft: '51624e772adafd7c6a9da38774e4f654282199bd5402e049ee087fc2bd900882'
211
+ },
212
+ {
213
+ addr: 'bitcoincash:qpszha37cjn6n83hpxn7zz5ndaa35vygtcgslxhpuc',
214
+ pubKey: '024be54accec310c2636140336ae548d610ba9b7ce300b3f42494b4a6f2963731f',
215
+ nft: 'e70cc72eeb15c82e96b1f8127d3b138b2fc8ea101fe9c62302ec641c05d4b97d'
216
+ }
217
+ ],
218
+ keysNotFound: []
219
+ }
220
+
221
+ const updateData01 = {
222
+ groupId: '8e8d90ebdb1791d58eba7acd428ff3b1e21c47fb7aba2ba3b5b815aa0fe7d6d5',
223
+ keys: [
224
+ {
225
+ addr: 'bitcoincash:qz4zsa22glal5c4jqm748xge657gwuw2d5t9nvg64p',
226
+ pubKey: '021ca211a04a1d489ae77e01c28c97b02e733893890fda00a359ca8956c2e0d259',
227
+ nft: 'e86164aaa06efac1d6453951f67beafe042f0bceb9312845a95355b1e93aa846'
228
+ },
229
+ {
230
+ addr: 'bitcoincash:qpfvh07mdt7yq5czndaz5qq4g9q3m87qpspy7xaxgu',
231
+ pubKey: '0361fd21512b9072e8f6b984d9b04c57e5779867c2ad002999372268770fcb2674',
232
+ nft: 'da7ccbd5e24e468c9e7402489ca9148b5e76e588b73cc4aa4bbf1ca41d5808ab'
233
+ },
234
+ {
235
+ addr: 'bitcoincash:qpsxtzaa7rg677akcc2znpenpsy5jr2ygywmfd45p2',
236
+ pubKey: '03b9bdc40c478ab0536be29c368b26c48a5e8d6867fc34b77c727ab690365aae91',
237
+ nft: '0ec318bede8c2f229db840a24cb63d662ad91e8e6c840e46e6a8ff2d173049ce'
238
+ },
239
+ {
240
+ addr: 'bitcoincash:qqk3aczzggvxnfm7rwm0f9yz20yr00dmpv2f3tasdr',
241
+ pubKey: '033c930d4cff4ba68a70f7a21443e20ad4176173380d21f8c3ce27f7ce947f3246',
242
+ nft: '51624e772adafd7c6a9da38774e4f654282199bd5402e049ee087fc2bd900882'
243
+ },
244
+ {
245
+ addr: 'bitcoincash:qpszha37cjn6n83hpxn7zz5ndaa35vygtcgslxhpuc',
246
+ pubKey: '024be54accec310c2636140336ae548d610ba9b7ce300b3f42494b4a6f2963731f',
247
+ nft: 'e70cc72eeb15c82e96b1f8127d3b138b2fc8ea101fe9c62302ec641c05d4b97d'
248
+ }
249
+ ],
250
+ walletObj: {
251
+ address: 'bitcoincash:pqntzt6wcp38h8ud68wjnwh437uek76lhvhlwcm4fj',
252
+ scriptHex: 'a91426b12f4ec0627b9f8dd1dd29baf58fb99b7b5fbb87',
253
+ publicKeys: [
254
+ '021ca211a04a1d489ae77e01c28c97b02e733893890fda00a359ca8956c2e0d259',
255
+ '0361fd21512b9072e8f6b984d9b04c57e5779867c2ad002999372268770fcb2674',
256
+ '03b9bdc40c478ab0536be29c368b26c48a5e8d6867fc34b77c727ab690365aae91',
257
+ '033c930d4cff4ba68a70f7a21443e20ad4176173380d21f8c3ce27f7ce947f3246',
258
+ '024be54accec310c2636140336ae548d610ba9b7ce300b3f42494b4a6f2963731f'
259
+ ],
260
+ requiredSigners: 3
261
+ },
262
+ multisigAddr: 'bitcoincash:pqntzt6wcp38h8ud68wjnwh437uek76lhvhlwcm4fj',
263
+ p2wdbWritePrice: 0.08335233
264
+ }
265
+
266
+ const approvalObj01 = {
267
+ approvalTxid: 'a63f9fbcc901316e6e89f5a8caaad6b2ab268278b29866c6c22088bd3ab93900',
268
+ updateTxid: 'f8ea1fcd4481adfd62c6251c6a4f63f3d5ac3d5fdcc38b350d321d93254df65f',
269
+ approvalTxDetails: approvalTxDetails01,
270
+ opReturn: 'j\x07APPROVE@f8ea1fcd4481adfd62c6251c6a4f63f3d5ac3d5fdcc38b350d321d93254df65f'
271
+ }
272
+
273
+ const updateObj01 = {
274
+ cid: 'bafybeib5d6s6t3tq4lhwp2ocvz7y2ws4czgkrmhlhv5y5aeyh6bqrmsxxi',
275
+ ts: 1676560247168,
276
+ txid: 'f8ea1fcd4481adfd62c6251c6a4f63f3d5ac3d5fdcc38b350d321d93254df65f',
277
+ txDetails: updateTxDetails01
278
+ }
279
+
280
+ module.exports = {
281
+ pubkeys01,
282
+ txHistory01,
283
+ txHistory02,
284
+ approvalTxDetails01,
285
+ updateTxDetails01,
286
+ tokenHolderInfo01,
287
+ updateData01,
288
+ approvalObj01,
289
+ updateObj01
290
+ }
@@ -0,0 +1,173 @@
1
+ /*
2
+ Unit tests for the nfts.js utility library.
3
+ */
4
+
5
+ // npm libraries
6
+ const chai = require('chai')
7
+ const sinon = require('sinon')
8
+ // const cloneDeep = require('lodash.clonedeep')
9
+ const SlpWallet = require('minimal-slp-wallet')
10
+
11
+ // Locally global variables.
12
+ const assert = chai.assert
13
+
14
+ // Mocking data libraries.
15
+ // const mockDataLib = require('./mocks/util-mocks')
16
+
17
+ // Unit under test
18
+ const NftsLib = require('../../lib/nfts')
19
+
20
+ describe('#NFTs', () => {
21
+ let sandbox
22
+ // let mockData
23
+ let uut
24
+ let wallet
25
+
26
+ before(async () => {
27
+ wallet = new SlpWallet(undefined, { interface: 'consumer-api' })
28
+ await wallet.walletInfoPromise
29
+ })
30
+
31
+ beforeEach(() => {
32
+ // Restore the sandbox before each test.
33
+ sandbox = sinon.createSandbox()
34
+
35
+ // Clone the mock data.
36
+ // mockData = cloneDeep(mockDataLib)
37
+
38
+ uut = new NftsLib({ wallet })
39
+ })
40
+
41
+ afterEach(() => sandbox.restore())
42
+
43
+ describe('#constructor', () => {
44
+ it('should throw an error if wallet is not passed', () => {
45
+ try {
46
+ uut = new NftsLib()
47
+ console.log('uut: ', uut)
48
+
49
+ assert.fail('Unexpected result')
50
+ } catch (err) {
51
+ assert.include(err.message, 'Instance of minimal-slp-wallet must be passed in as a property called \'wallet\', when initializing the nfts.js library.')
52
+ }
53
+ })
54
+ })
55
+
56
+ describe('#getNftsFromGroup', () => {
57
+ it('should get NFT token IDs from a Group token', async () => {
58
+ // Mock dependencies and force desired code path
59
+ sandbox.stub(uut.wallet, 'getTokenData').resolves({
60
+ genesisData: {
61
+ nfts: ['a', 'b', 'c']
62
+ }
63
+ })
64
+
65
+ const result = await uut.getNftsFromGroup('fake-group-id')
66
+
67
+ assert.isArray(result)
68
+ })
69
+
70
+ it('should catch and throw errors', async () => {
71
+ try {
72
+ // Mock dependencies and force desired code path
73
+ sandbox.stub(uut.wallet, 'getTokenData').rejects(new Error('test error'))
74
+
75
+ await uut.getNftsFromGroup()
76
+
77
+ assert.fail('Unexpected code path')
78
+ } catch (err) {
79
+ assert.include(err.message, 'test error')
80
+ }
81
+ })
82
+ })
83
+
84
+ describe('#getAddrsFromNfts', () => {
85
+ it('should should return addresses associated with each NFT', async () => {
86
+ // Mock dependencies and force desired code path.
87
+ sandbox.stub(uut.wallet, 'getTokenData').resolves({
88
+ genesisData: {
89
+ nftHolder: 'sam'
90
+ }
91
+ })
92
+
93
+ const nfts = ['a']
94
+
95
+ const result = await uut.getAddrsFromNfts(nfts)
96
+
97
+ assert.isArray(result)
98
+ assert.equal(result[0], 'sam')
99
+ })
100
+
101
+ it('should catch and throw errors', async () => {
102
+ try {
103
+ // Force an error
104
+ sandbox.stub(uut.wallet, 'getTokenData').rejects(new Error('test error'))
105
+
106
+ const nfts = ['a']
107
+
108
+ await uut.getAddrsFromNfts(nfts)
109
+
110
+ assert.fail('Unexpected code path')
111
+ } catch (err) {
112
+ assert.include(err.message, 'test error')
113
+ }
114
+ })
115
+ })
116
+
117
+ describe('#findKeys', () => {
118
+ it('should collect public keys for an addresses', async () => {
119
+ const addrs = ['bitcoincash:qzwahhjldv0qsecfxlmcenzvkjv9rlv9au2hcfggl6']
120
+ const nfts = ['fb707a9d8a4d6ba47ef0c510714ca46d4523cd29c8f4e3fd6a63a85edb8b05d2']
121
+
122
+ // Mock dependencies and force desired code path.
123
+ sandbox.stub(uut.wallet, 'getPubKey').resolves('02055962631b236ddcd2c17cd0b711f12438b93bcf01b206cadb351cc3e6e3e269')
124
+
125
+ const result = await uut.findKeys(addrs, nfts)
126
+ // console.log('result: ', result)
127
+
128
+ // Assert expected properties exist
129
+ assert.property(result, 'keys')
130
+ assert.property(result, 'keysNotFound')
131
+
132
+ // Assert that each property is an array.
133
+ assert.isArray(result.keys)
134
+ assert.isArray(result.keysNotFound)
135
+
136
+ // Assert expected values exist
137
+ assert.equal(result.keys[0].addr, 'bitcoincash:qzwahhjldv0qsecfxlmcenzvkjv9rlv9au2hcfggl6')
138
+ assert.equal(result.keys[0].pubKey, '02055962631b236ddcd2c17cd0b711f12438b93bcf01b206cadb351cc3e6e3e269')
139
+ })
140
+
141
+ it('should handle address without a public key', async () => {
142
+ const addrs = ['bitcoincash:qzwahhjldv0qsecfxlmcenzvkjv9rlv9au2hcfggl6']
143
+ const nfts = ['fb707a9d8a4d6ba47ef0c510714ca46d4523cd29c8f4e3fd6a63a85edb8b05d2']
144
+
145
+ // Mock dependencies and force desired code path.
146
+ sandbox.stub(uut.wallet, 'getPubKey').resolves('not found')
147
+
148
+ const result = await uut.findKeys(addrs, nfts)
149
+ // console.log('result: ', result)
150
+
151
+ // Assert expected properties exist
152
+ assert.property(result, 'keys')
153
+ assert.property(result, 'keysNotFound')
154
+
155
+ // Assert that each property is an array.
156
+ assert.isArray(result.keys)
157
+ assert.isArray(result.keysNotFound)
158
+
159
+ // Assert expected values exist
160
+ assert.equal(result.keysNotFound[0], 'bitcoincash:qzwahhjldv0qsecfxlmcenzvkjv9rlv9au2hcfggl6')
161
+ })
162
+
163
+ it('should catch and throw errors', async () => {
164
+ try {
165
+ await uut.findKeys()
166
+
167
+ assert.fail('Unexpected code path')
168
+ } catch (err) {
169
+ assert.include(err.message, 'Cannot read')
170
+ }
171
+ })
172
+ })
173
+ })
@@ -3,68 +3,89 @@
3
3
  */
4
4
 
5
5
  // npm libraries
6
- const chai = require('chai')
6
+ const assert = require('chai').assert
7
7
  const sinon = require('sinon')
8
- const cloneDeep = require('lodash.clonedeep')
8
+ // const cloneDeep = require('lodash.clonedeep')
9
+ const SlpWallet = require('minimal-slp-wallet')
9
10
 
10
- // Locally global variables.
11
- const assert = chai.assert
12
-
13
- // Mocking data libraries.
14
- const mockDataLib = require('./mocks/util-mocks')
11
+ // Local libraries
12
+ // const mockDataLib = require('./mocks/util-mocks')
15
13
 
16
14
  // Unit under test
17
15
  const UtilLib = require('../../lib/util')
18
- const uut = new UtilLib()
19
16
 
20
- describe('#util.js', () => {
17
+ describe('#Util', () => {
21
18
  let sandbox
22
- let mockData
19
+ // let mockData
20
+ let uut
21
+ let wallet
22
+
23
+ before(async () => {
24
+ wallet = new SlpWallet(undefined, { interface: 'consumer-api' })
25
+ await wallet.walletInfoPromise
26
+ })
23
27
 
24
28
  beforeEach(() => {
25
29
  // Restore the sandbox before each test.
26
30
  sandbox = sinon.createSandbox()
27
31
 
28
32
  // Clone the mock data.
29
- mockData = cloneDeep(mockDataLib)
33
+ // mockData = cloneDeep(mockDataLib)
34
+
35
+ uut = new UtilLib({ wallet })
30
36
  })
31
37
 
32
38
  afterEach(() => sandbox.restore())
33
39
 
34
- describe('#getBchData', () => {
35
- it('should throw error if address is not a string', async () => {
40
+ describe('#constructor', () => {
41
+ it('should throw an error if wallet is not passed', () => {
36
42
  try {
37
- const addr = 1234
43
+ uut = new UtilLib()
44
+ console.log('uut: ', uut)
38
45
 
39
- await uut.getBchData(addr)
40
-
41
- assert.equal(true, false, 'unexpected result')
46
+ assert.fail('Unexpected result')
42
47
  } catch (err) {
43
- assert.include(err.message, 'Address must be a string')
48
+ assert.include(err.message, 'Instance of minimal-slp-wallet must be passed in as a property called \'wallet\', when initializing the util library.')
44
49
  }
45
50
  })
51
+ })
52
+
53
+ describe('#getTxData', () => {
54
+ it('should get TX data from the full node', async () => {
55
+ // Mock dependencies and force desired code path
56
+ sandbox.stub(uut.wallet, 'getTxData').resolves([{ txid: 'fake-txid' }])
57
+
58
+ const txid = 'fake-txid'
59
+
60
+ const result = await uut.getTxData(txid)
61
+ // console.log('result: ', result)
62
+
63
+ assert.equal(result.txid, 'fake-txid')
64
+ })
65
+
66
+ it('should get TX data from the cache', async () => {
67
+ // Mock dependencies and force desired code path
68
+ sandbox.stub(uut.wallet, 'getTxData').rejects(new Error('test error'))
69
+ uut.txCache['fake-txid'] = { txid: 'fake-txid' }
46
70
 
47
- it('should get BCH data on an address', async () => {
48
- // Mock external dependencies.
49
- sandbox
50
- .stub(uut.bchjs.Electrumx, 'balance')
51
- .resolves(mockData.mockBalance)
52
- sandbox.stub(uut.bchjs.Electrumx, 'utxo').resolves(mockData.mockUtxos)
71
+ const txid = 'fake-txid'
53
72
 
54
- const addr = 'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7'
73
+ const result = await uut.getTxData(txid)
74
+ // console.log('result: ', result)
55
75
 
56
- const bchData = await uut.getBchData(addr)
57
- // console.log(`bchData: ${JSON.stringify(bchData, null, 2)}`)
76
+ // Assert expected result
77
+ assert.equal(result.txid, 'fake-txid')
78
+ })
58
79
 
59
- // Assert that top-level properties exist.
60
- assert.property(bchData, 'balance')
61
- assert.property(bchData, 'utxos')
80
+ it('should catch, report, and throw an error', async () => {
81
+ try {
82
+ await uut.getTxData()
62
83
 
63
- // Assert essential UTXOs properties exist.
64
- assert.isArray(bchData.utxos)
65
- assert.property(bchData.utxos[0], 'tx_pos')
66
- assert.property(bchData.utxos[0], 'tx_hash')
67
- assert.property(bchData.utxos[0], 'value')
84
+ assert.fail('Unexpected result')
85
+ } catch (err) {
86
+ // console.log('err.message: ', err.message)
87
+ assert.include(err.message, 'txid (transactoin ID) required')
88
+ }
68
89
  })
69
90
  })
70
91
  })
@@ -1,33 +0,0 @@
1
- /*
2
- Integration tests for the util.js utility library.
3
- */
4
-
5
- // npm libraries
6
- const chai = require('chai')
7
-
8
- // Locally global variables.
9
- const assert = chai.assert
10
-
11
- // Unit under test
12
- const UtilLib = require('../../lib/util')
13
- const uut = new UtilLib()
14
-
15
- describe('#util.js', () => {
16
- describe('#getBchData', () => {
17
- it('should get BCH data on an address', async () => {
18
- const addr = 'bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7'
19
-
20
- const bchData = await uut.getBchData(addr)
21
-
22
- // Assert that top-level properties exist.
23
- assert.property(bchData, 'balance')
24
- assert.property(bchData, 'utxos')
25
-
26
- // Assert essential UTXOs properties exist.
27
- assert.isArray(bchData.utxos)
28
- assert.property(bchData.utxos[0], 'tx_pos')
29
- assert.property(bchData.utxos[0], 'tx_hash')
30
- assert.property(bchData.utxos[0], 'value')
31
- })
32
- })
33
- })