@wishknish/knishio-client-js 0.5.2 → 0.6.1

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.
Files changed (133) hide show
  1. package/README.md +207 -274
  2. package/dist/client.iife.js +533 -0
  3. package/package.json +37 -79
  4. package/src/.babelrc +0 -22
  5. package/src/Atom.js +171 -132
  6. package/src/AtomMeta.js +76 -50
  7. package/src/AuthToken.js +38 -47
  8. package/src/KnishIOClient.js +934 -987
  9. package/src/Meta.js +15 -17
  10. package/src/Molecule.js +423 -494
  11. package/src/PolicyMeta.js +32 -41
  12. package/src/TokenUnit.js +30 -32
  13. package/src/Wallet.js +275 -265
  14. package/src/exception/AtomIndexException.js +4 -8
  15. package/src/exception/AtomsMissingException.js +4 -6
  16. package/src/exception/AuthorizationRejectedException.js +4 -5
  17. package/src/exception/BalanceInsufficientException.js +4 -8
  18. package/src/exception/BaseException.js +6 -8
  19. package/src/exception/BatchIdException.js +5 -7
  20. package/src/exception/CodeException.js +4 -8
  21. package/src/{libraries/ApolloLink/HttpLink.js → exception/DecryptionKeyException.js} +12 -15
  22. package/src/exception/InvalidResponseException.js +4 -5
  23. package/src/exception/MetaMissingException.js +4 -6
  24. package/src/exception/MolecularHashMismatchException.js +4 -6
  25. package/src/exception/MolecularHashMissingException.js +4 -5
  26. package/src/exception/NegativeAmountException.js +4 -5
  27. package/src/exception/PolicyInvalidException.js +4 -4
  28. package/src/exception/SignatureMalformedException.js +4 -5
  29. package/src/exception/SignatureMismatchException.js +4 -5
  30. package/src/exception/StackableUnitAmountException.js +4 -5
  31. package/src/exception/StackableUnitDecimalsException.js +4 -5
  32. package/src/exception/TransferBalanceException.js +4 -5
  33. package/src/exception/TransferMalformedException.js +4 -5
  34. package/src/exception/TransferMismatchedException.js +4 -5
  35. package/src/exception/TransferRemainderException.js +4 -5
  36. package/src/exception/TransferToSelfException.js +4 -5
  37. package/src/exception/TransferUnbalancedException.js +4 -5
  38. package/src/exception/UnauthenticatedException.js +4 -5
  39. package/src/{libraries/ApolloLink/AuthLink.js → exception/WalletCredentialException.js} +12 -40
  40. package/src/exception/WalletShadowException.js +4 -5
  41. package/src/exception/WrongTokenTypeException.js +4 -5
  42. package/src/exception/index.js +26 -26
  43. package/src/index.js +8 -10
  44. package/src/instance/Rules/Callback.js +91 -93
  45. package/src/instance/Rules/Condition.js +21 -23
  46. package/src/instance/Rules/Meta.js +13 -14
  47. package/src/instance/Rules/Rule.js +39 -43
  48. package/src/instance/Rules/exception/RuleArgumentException.js +4 -4
  49. package/src/libraries/CheckMolecule.js +253 -232
  50. package/src/libraries/Decimal.js +13 -17
  51. package/src/libraries/Dot.js +74 -48
  52. package/src/libraries/Hex.js +49 -54
  53. package/src/libraries/array.js +50 -41
  54. package/src/libraries/crypto.js +20 -27
  55. package/src/libraries/strings.js +58 -91
  56. package/src/libraries/urql/UrqlClientWrapper.js +166 -0
  57. package/src/mutation/Mutation.js +44 -25
  58. package/src/mutation/MutationActiveSession.js +12 -12
  59. package/src/mutation/MutationClaimShadowWallet.js +15 -17
  60. package/src/mutation/MutationCreateIdentifier.js +11 -12
  61. package/src/mutation/MutationCreateMeta.js +11 -12
  62. package/src/mutation/MutationCreateRule.js +11 -12
  63. package/src/mutation/MutationCreateToken.js +18 -13
  64. package/src/mutation/MutationCreateWallet.js +9 -11
  65. package/src/mutation/MutationDepositBufferToken.js +7 -9
  66. package/src/mutation/MutationLinkIdentifier.js +12 -14
  67. package/src/mutation/MutationProposeMolecule.js +24 -25
  68. package/src/mutation/MutationRequestAuthorization.js +9 -10
  69. package/src/mutation/MutationRequestAuthorizationGuest.js +12 -15
  70. package/src/mutation/MutationRequestTokens.js +11 -14
  71. package/src/mutation/MutationTransferTokens.js +11 -14
  72. package/src/mutation/MutationWithdrawBufferToken.js +7 -10
  73. package/src/query/Query.js +62 -36
  74. package/src/query/QueryActiveSession.js +11 -13
  75. package/src/query/QueryAtom.js +75 -76
  76. package/src/query/QueryBalance.js +11 -12
  77. package/src/query/QueryBatch.js +17 -14
  78. package/src/query/QueryBatchHistory.js +16 -13
  79. package/src/query/QueryContinuId.js +13 -10
  80. package/src/query/QueryMetaType.js +45 -57
  81. package/src/query/QueryMetaTypeViaAtom.js +49 -57
  82. package/src/query/QueryPolicy.js +11 -12
  83. package/src/query/QueryToken.js +11 -13
  84. package/src/query/QueryUserActivity.js +11 -13
  85. package/src/query/QueryWalletBundle.js +15 -47
  86. package/src/query/QueryWalletList.js +15 -16
  87. package/src/response/Response.js +29 -34
  88. package/src/response/ResponseActiveSession.js +6 -6
  89. package/src/response/ResponseAtom.js +29 -30
  90. package/src/response/ResponseAuthorizationGuest.js +17 -18
  91. package/src/response/ResponseBalance.js +12 -13
  92. package/src/response/ResponseClaimShadowWallet.js +1 -1
  93. package/src/response/ResponseContinuId.js +21 -22
  94. package/src/response/ResponseCreateIdentifier.js +1 -1
  95. package/src/response/ResponseCreateMeta.js +1 -1
  96. package/src/response/ResponseCreateRule.js +1 -1
  97. package/src/response/ResponseCreateToken.js +1 -1
  98. package/src/response/ResponseCreateWallet.js +1 -1
  99. package/src/response/ResponseLinkIdentifier.js +9 -10
  100. package/src/response/ResponseMetaBatch.js +6 -8
  101. package/src/response/ResponseMetaType.js +19 -20
  102. package/src/response/ResponseMetaTypeViaAtom.js +19 -19
  103. package/src/response/ResponsePolicy.js +14 -15
  104. package/src/response/ResponseProposeMolecule.js +27 -30
  105. package/src/response/ResponseQueryActiveSession.js +20 -23
  106. package/src/response/ResponseQueryUserActivity.js +11 -12
  107. package/src/response/ResponseRequestAuthorization.js +11 -16
  108. package/src/response/ResponseRequestAuthorizationGuest.js +18 -21
  109. package/src/response/ResponseRequestTokens.js +1 -1
  110. package/src/response/ResponseTransferTokens.js +8 -9
  111. package/src/response/ResponseWalletBundle.js +16 -17
  112. package/src/response/ResponseWalletList.js +44 -47
  113. package/src/subscribe/ActiveSessionSubscribe.js +5 -6
  114. package/src/subscribe/ActiveWalletSubscribe.js +5 -6
  115. package/src/subscribe/CreateMoleculeSubscribe.js +5 -5
  116. package/src/subscribe/Subscribe.js +26 -26
  117. package/src/subscribe/WalletStatusSubscribe.js +5 -6
  118. package/src/versions/HashAtom.js +78 -0
  119. package/src/versions/Version4.js +34 -0
  120. package/src/versions/index.js +5 -0
  121. package/dist/client.umd.js +0 -453
  122. package/src/httpClient/ApolloClient.js +0 -245
  123. package/src/libraries/ApolloLink/CipherLink.js +0 -117
  124. package/src/libraries/ApolloLink/Client.js +0 -231
  125. package/src/libraries/ApolloLink/PusherLink.js +0 -234
  126. package/src/libraries/ApolloLink/handler.js +0 -106
  127. package/src/libraries/Base58.js +0 -71
  128. package/src/libraries/Base64.js +0 -40
  129. package/src/libraries/BaseX.js +0 -91
  130. package/src/libraries/Soda.js +0 -93
  131. package/src/query/QueryMetaInstance.js +0 -99
  132. package/src/test/Test.js +0 -670
  133. package/src/test/TestTokenUnit.js +0 -340
package/src/test/Test.js DELETED
@@ -1,670 +0,0 @@
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
- Powered by Knish.IO: Connecting a Decentralized World
43
-
44
- Please visit https://github.com/WishKnish/KnishIO-Client-JS for information.
45
-
46
- License: https://github.com/WishKnish/KnishIO-Client-JS/blob/master/LICENSE
47
- */
48
- import KnishIOClient from '../KnishIOClient';
49
- import Dot from '../libraries/Dot';
50
- import {
51
- generateBundleHash,
52
- generateSecret
53
- } from '../libraries/crypto';
54
- import ResponseMolecule from '../response/ResponseProposeMolecule';
55
- import TokenUnit from '../TokenUnit';
56
-
57
- /*
58
-
59
- import Test from '@wishknish/knishio-client-js/src/test/Test';
60
- import { KNISHIO_SETTINGS, } from 'src/libraries/constants/knishio';
61
-
62
- // Run all test
63
- await Test.run( KNISHIO_SETTINGS.serverUriConfig );
64
-
65
- */
66
-
67
- export default class Test {
68
-
69
- /**
70
- * Run all
71
- */
72
- static async run ( uris ) {
73
- for ( let uriIndex in uris ) {
74
- let test = new Test( uris[ uriIndex ] );
75
- await test.testAll();
76
- }
77
- }
78
-
79
- /**
80
- *
81
- * @param graphqlUrl
82
- * @param encrypt
83
- */
84
- constructor ( graphqlUrl, encrypt = false ) {
85
- this.encrypt = encrypt;
86
- this.secrets = [ generateSecret(), generateSecret() ];
87
- this.tokenSlugs = [ 'TESTTOKEN', 'UTENVSTACKABLE', 'UTSTACKUNIT', 'UTENVSTACKUNIT', 'UTSTACKUNITZONES', 'UTSLUG0', 'UTSLUG1' ];
88
- this.graphqlUrl = graphqlUrl;
89
- console.log( `---------- GraphQL URI: ${ this.graphqlUrl }` );
90
-
91
- this.clients = {};
92
- this.tokenUnits = [
93
- [ 'unit_id_1', 'unit_name_1' ],
94
- [ 'unit_id_2', 'unit_name_2' ],
95
- [ 'unit_id_3', 'unit_name_3' ],
96
- [ 'unit_id_4', 'unit_name_4' ],
97
- [ 'unit_id_5', 'unit_name_5' ],
98
- [ 'unit_id_6', 'unit_name_6' ],
99
- [ 'unit_id_7', 'unit_name_7' ],
100
- [ 'unit_id_8', 'unit_name_8' ],
101
- [ 'unit_id_9', 'unit_name_9' ],
102
- [ 'unit_id_10', 'unit_name_10' ],
103
- [ 'unit_id_11', 'unit_name_11' ]
104
- ];
105
- this.replenishTokenUnits = [
106
- [ 'unit_id_12', 'unit_id_12' ],
107
- [ 'unit_id_13', 'unit_id_13' ],
108
- [ 'unit_id_14', 'unit_id_14' ],
109
- [ 'unit_id_15', 'unit_id_15' ]
110
- ];
111
-
112
- // Generate token units with fragment zones
113
- let getTokenUnitsFZ = ( tokenUnits, from = 0 ) => {
114
- let result = [];
115
- tokenUnits.forEach( ( tokenUnit, key ) => {
116
- let tokenUnitFZ = Array.from( tokenUnit );
117
- tokenUnitFZ.push( { fragmentZone: from + key } );
118
- result.push( tokenUnitFZ );
119
- } );
120
- return result;
121
- };
122
- this.tokenUnitsFZ = getTokenUnitsFZ( this.tokenUnits );
123
- this.replenishTokenUnitsFZ = getTokenUnitsFZ( Array.from( this.replenishTokenUnits ), this.tokenUnits.length );
124
- this.fragmentZones = this.tokenUnitsFZ.length + this.replenishTokenUnitsFZ.length;
125
-
126
- // Init fused token unit IDs
127
- this.fusedTokenUnitIds = [];
128
- this.tokenUnitsFZ.slice( 0, 5 ).forEach( ( tokenUnitData ) => {
129
- this.fusedTokenUnitIds.push( tokenUnitData[ 0 ] );
130
- } );
131
- }
132
-
133
-
134
- /**
135
- * Test all KnishIOClient functions
136
- */
137
- async testAll () {
138
- console.info( `Executing test for: ${ this.graphqlUrl }...` );
139
-
140
- await this.client( this.secrets[ 0 ] );
141
- await this.client( this.secrets[ 1 ] );
142
-
143
- await this.testCreateToken();
144
- await this.testFuseToken();
145
- await this.testCreateWallet();
146
- await this.testCreateMeta();
147
- await this.testCreateIdentifier();
148
- await this.testRequestTokens();
149
- await this.testTransferToken();
150
- await this.testBurnToken();
151
- await this.testReplenishToken();
152
- await this.testClaimShadowWallet();
153
- await this.testWalletBufferTransactions();
154
- await this.testQueryMeta();
155
- await this.testQueryWallets();
156
- await this.testQueryShadowWallets();
157
- await this.testQueryBundle();
158
- await this.testQueryBalance();
159
- }
160
-
161
-
162
- /**
163
- *
164
- * @returns {Promise<void>}
165
- */
166
- async testTokenExpiration () {
167
- const client = await this.client( this.secrets[ 0 ] );
168
- const fnTimeout = ( timeout ) => {
169
- setTimeout( client => {
170
- console.warn( `setTimeout ${ timeout }` );
171
- client.queryMeta( {
172
- metaType: 'metaType',
173
- metaId: 'metaId'
174
- } );
175
- }, timeout, client, timeout );
176
- };
177
- fnTimeout( 3000 );
178
- fnTimeout( 30000 );
179
- fnTimeout( 61000 );
180
- fnTimeout( 64000 );
181
- }
182
-
183
- /**
184
- * @throws \Exception
185
- */
186
- async testCreateToken () {
187
-
188
- let responses = {};
189
-
190
- // Regular stackable token
191
- let client = await this.client( this.secrets[ 0 ] );
192
- responses[ 0 ] = await client.createToken( {
193
- token: this.tokenSlugs[ 0 ],
194
- amount: 1000.000000000000,
195
- meta: {
196
- name: this.tokenSlugs[ 0 ],
197
- fungibility: 'stackable',
198
- supply: 'replenishable',
199
- decimals: 0,
200
- icon: 'icon'
201
- },
202
- batchId: 'batch_0'
203
- } );
204
- this.checkResponse( responses[ 0 ], 'testCreateToken.0' );
205
-
206
- // Server stackable token
207
- let serverClient = await this.client( process.env.SECRET_TOKEN_KNISH );
208
- responses[ 1 ] = await serverClient.createToken( {
209
- token: this.tokenSlugs[ 1 ],
210
- amount: 1000.000000000000,
211
- meta: {
212
- name: this.tokenSlugs[ 1 ],
213
- fungibility: 'stackable',
214
- supply: 'limited',
215
- decimals: 0,
216
- icon: 'icon'
217
- },
218
- batchId: 'server_batch_0'
219
- } );
220
- this.checkResponse( responses[ 1 ], 'testCreateToken.1' );
221
-
222
-
223
- // --------- UNITABLE TOKENS ----------
224
-
225
- // Create stackable unit token
226
- responses[ 2 ] = await client.createToken( {
227
- token: this.tokenSlugs[ 2 ],
228
- units: this.tokenUnits,
229
- meta: {
230
- name: this.tokenSlugs[ 2 ],
231
- supply: 'replenishable',
232
- fungibility: 'stackable'
233
- },
234
- batchId: 'unit_batch_0'
235
- } );
236
- this.checkResponse( responses[ 2 ], 'testCreateToken.2' );
237
-
238
-
239
- // --- SERVER CLIENT (used only for the testing - SECRET_TOKEN_KNISH is server var only!)
240
-
241
- // Create server stackable unit token
242
- responses[ 3 ] = await serverClient.createToken( {
243
- token: this.tokenSlugs[ 3 ],
244
- units: this.tokenUnits,
245
- meta: {
246
- name: this.tokenSlugs[ 3 ],
247
- supply: 'limited',
248
- fungibility: 'stackable'
249
- },
250
- batchId: 'server_unit_batch_0'
251
- } );
252
- this.checkResponse( responses[ 3 ], 'testCreateToken.3' );
253
-
254
-
255
- // Create stackable unit token
256
- responses[ 4 ] = await client.createToken( {
257
- token: this.tokenSlugs[ 4 ],
258
- units: this.tokenUnitsFZ,
259
- meta: {
260
- name: this.tokenSlugs[ 4 ],
261
- supply: 'replenishable',
262
- fungibility: 'stackable',
263
- fragmentZones: this.fragmentZones
264
- },
265
- batchId: 'unit_fz_batch_0'
266
- } );
267
- this.checkResponse( responses[ 4 ], 'testCreateToken.4' );
268
-
269
- // --- Tokens for trading
270
- client = await this.client( this.secrets[ 0 ] );
271
- for ( const tokenSlug of [ this.tokenSlugs[ 5 ], this.tokenSlugs[ 6 ] ] ) {
272
- responses[ 0 ] = await client.createToken( {
273
- token: tokenSlug,
274
- amount: 1000.000000000000,
275
- meta: {
276
- name: tokenSlug,
277
- fungibility: 'fungible',
278
- supply: 'limited',
279
- decimals: 0,
280
- icon: 'icon'
281
- }
282
- } );
283
- this.checkResponse( responses[ 0 ], `testCreateToken.${ tokenSlug }` );
284
- }
285
- }
286
-
287
- /**
288
- *
289
- */
290
- async testCreateWallet () {
291
- let client = await this.client( this.secrets[ 0 ] );
292
- let response = await client.createWallet( {
293
- token: this.tokenSlugs[ 1 ]
294
- } );
295
- this.checkResponse( response, 'testCreateWallet' );
296
- }
297
-
298
- /**
299
- *
300
- */
301
- async testCreateMeta () {
302
- let client = await this.client( this.secrets[ 0 ] );
303
- let response = await client.createMeta( {
304
- metaType: 'metaType',
305
- metaId: 'metaId',
306
- meta: {
307
- key1: 'value1',
308
- key2: 'value2'
309
- }
310
- } );
311
- this.checkResponse( response, 'testCreateMeta' );
312
- }
313
-
314
-
315
- /**
316
- *
317
- */
318
- async testCreateIdentifier () {
319
- let client = await this.client( this.secrets[ 0 ] );
320
- let response = await client.createIdentifier( {
321
- type: 'email',
322
- contact: 'test@test.com',
323
- code: '1234'
324
- } );
325
-
326
- console.log( ' ############### testCreateIdentifier ###############' );
327
- if ( response.reason() !== 'Outdated code' ) {
328
- console.error( 'Error with response.' );
329
- }
330
- this.debug( response );
331
- }
332
-
333
- /**
334
- *
335
- */
336
- async testRequestTokens () {
337
- let client = await this.client( this.secrets[ 0 ] );
338
- let response = await client.requestTokens( {
339
- token: this.tokenSlugs[ 1 ],
340
- amount: 10,
341
- to: this.secrets[ 0 ],
342
- batchId: 'batch_5'
343
- } );
344
- this.checkResponse( response, 'testRequestTokens.1' );
345
-
346
- response = await client.requestTokens( {
347
- token: this.tokenSlugs[ 3 ],
348
- units: [ 'unit_id_10', 'unit_id_11' ],
349
- to: this.secrets[ 0 ],
350
- batchId: 'batch_6'
351
- } );
352
- this.checkResponse( response, 'testRequestTokens.2' );
353
- }
354
-
355
-
356
- /**
357
- *
358
- * @return {Promise<void>}
359
- */
360
- async testTransferToken () {
361
-
362
- let bundleHash = generateBundleHash( this.secrets[ 1 ] );
363
- let response;
364
-
365
- let client = await this.client( this.secrets[ 0 ] );
366
- response = await client.transferToken( {
367
- bundleHash,
368
- token: this.tokenSlugs[ 0 ],
369
- amount: 10,
370
- batchId: 'batch_1'
371
- } );
372
- this.checkResponse( response, 'testTransferToken' );
373
-
374
- response = await client.transferToken( {
375
- bundleHash,
376
- token: this.tokenSlugs[ 2 ],
377
- units: [ 'unit_id_1', 'unit_id_2' ],
378
- batchId: 'batch_2'
379
- } );
380
- this.checkResponse( response, 'testTransferUnitToken' );
381
- }
382
-
383
-
384
- /**
385
- *
386
- */
387
- async testBurnToken () {
388
- let response;
389
-
390
- let client = await this.client( this.secrets[ 0 ] );
391
- response = await client.burnTokens( {
392
- token: this.tokenSlugs[ 0 ],
393
- amount: 10
394
- } );
395
- this.checkResponse( response, 'testBurnToken' );
396
-
397
- response = await client.burnTokens( {
398
- token: this.tokenSlugs[ 2 ],
399
- units: [ 'unit_id_3', 'unit_id_4' ]
400
- } );
401
- this.checkResponse( response, 'testBurnUnitToken' );
402
- }
403
-
404
-
405
- /**
406
- *
407
- */
408
- async testReplenishToken () {
409
-
410
- let response;
411
-
412
- let client = await this.client( this.secrets[ 0 ] );
413
- response = await client.replenishToken( {
414
- token: this.tokenSlugs[ 0 ],
415
- amount: 25
416
- } );
417
- this.checkResponse( response, 'testReplenishToken' );
418
-
419
- response = await client.replenishToken( {
420
- token: this.tokenSlugs[ 2 ],
421
- amount: 0,
422
- units: this.replenishTokenUnits
423
- } );
424
- this.checkResponse( response, 'testReplenishUnitToken' );
425
- }
426
-
427
-
428
- /**
429
- *
430
- * @returns {Promise<void>}
431
- */
432
- async testFuseToken () {
433
-
434
- let tokenSlug = this.tokenSlugs[ 4 ];
435
-
436
- let recipientSecret = generateSecret();
437
- let recipientClient = await this.client( recipientSecret );
438
-
439
- let fusedTokenUnit = new TokenUnit( 'fusedTokenUnitId' );
440
-
441
- let client = await this.client( this.secrets[ 0 ] );
442
- let response = await client.fuseToken( {
443
- bundleHash: recipientClient.getBundle(),
444
- tokenSlug,
445
- newTokenUnit: fusedTokenUnit,
446
- fusedTokenUnitIds: this.fusedTokenUnitIds
447
- } );
448
- this.checkResponse( response, 'testFuseToken' );
449
-
450
- let walletRecipient = ( await recipientClient.queryBalance( { token: tokenSlug } ) ).payload();
451
- let walletRemainder = ( await client.queryBalance( { token: tokenSlug } ) ).payload();
452
-
453
- // Check recipient wallet
454
- console.assert( walletRecipient.tokenUnits.length, 1 );
455
- console.assert( walletRecipient.tokenUnits[ 0 ].id, 'fusedTokenUnitId' );
456
-
457
-
458
- // --- Check fused token units in the recipient wallet
459
- let fusedTokenUnits = walletRecipient.tokenUnits[ 0 ].getFusedTokenUnits();
460
- console.assert( fusedTokenUnits.length, this.fusedTokenUnitIds.length );
461
-
462
- // Get token unit IDs from the fused metadata of the fused token unit
463
- let dbFusedTokenUnitIds = [];
464
- fusedTokenUnits.forEach( ( tokenUnit ) => {
465
- dbFusedTokenUnitIds.push( tokenUnit[ 0 ] );
466
- } );
467
- // ---
468
-
469
- // --- Check remainder token units
470
- console.assert( walletRemainder.tokenUnits.length, 6 );
471
- let remainderTokenUnitIds = [];
472
- walletRemainder.tokenUnits.forEach( ( tokenUnit ) => {
473
- remainderTokenUnitIds.push( tokenUnit.id );
474
- } );
475
- console.assert(
476
- remainderTokenUnitIds,
477
- [ 'unit_id_6', 'unit_id_7', 'unit_id_8', 'unit_id_9', 'unit_id_10', 'unit_id_11' ]
478
- );
479
- }
480
-
481
- /**
482
- *
483
- */
484
- async testClaimShadowWallet () {
485
- let client = await this.client( this.secrets[ 1 ] );
486
-
487
- /**
488
- * @type {ResponseBalance}
489
- */
490
- let balanceResponse = await client.queryBalance( {
491
- token: this.tokenSlugs[ 0 ]
492
- } );
493
-
494
- let response = await client.claimShadowWallet( {
495
- token: this.tokenSlugs[ 0 ],
496
- batchId: balanceResponse.payload().batchId
497
- } );
498
- this.checkResponse( response, 'testClaimShadowWallet' );
499
- }
500
-
501
-
502
- /**
503
- *
504
- * @returns {Promise<void>}
505
- */
506
- async testWalletBufferTransactions () {
507
- let client = await this.client( this.secrets[ 0 ] );
508
-
509
- // Deposit buffer
510
- let tradeRates = {};
511
- tradeRates[ this.tokenSlugs[ 1 ] ] = 200 / 100;
512
- tradeRates[ this.tokenSlugs[ 3 ] ] = 200 / 200;
513
- let response = await client.depositBufferToken( {
514
- tokenSlug: this.tokenSlugs[ 5 ],
515
- amount: 200,
516
- tradeRates
517
- } );
518
- this.checkResponse( response, 'testWalletBufferTransactions: depositBufferToken' );
519
-
520
- // Withdraw buffer
521
- await client.withdrawBufferToken( {
522
- tokenSlug: this.tokenSlugs[ 5 ],
523
- amount: 100
524
- } );
525
- this.checkResponse( response, 'testWalletBufferTransactions: withdrawBufferToken' );
526
-
527
- }
528
-
529
- /**
530
- *
531
- */
532
- async testQueryMeta () {
533
- let client = await this.client( this.secrets[ 0 ] );
534
- let response = await client.queryMeta( {
535
- metaType: 'metaType',
536
- metaId: 'metaId'
537
- } );
538
- this.checkResponse( response, 'testQueryMeta' );
539
- }
540
-
541
- /**
542
- *
543
- */
544
- async testQueryWallets () {
545
- let client = await this.client( this.secrets[ 0 ] );
546
- let response = await client.queryWallets( {} );
547
- this.checkResponse( response, 'testQueryWallets' );
548
- }
549
-
550
- /**
551
- *
552
- */
553
- async testQueryShadowWallets () {
554
- let client = await this.client( this.secrets[ 1 ] );
555
- let response = await client.queryShadowWallets( {
556
- token: this.tokenSlugs[ 0 ]
557
- } );
558
- this.checkResponse( response, 'testQueryShadowWallets' );
559
- }
560
-
561
- /**
562
- *
563
- */
564
- async testQueryBundle () {
565
- let client = await this.client( this.secrets[ 0 ] );
566
- let response = await client.queryBundle( {} );
567
- this.checkResponse( response, 'testQueryBundle' );
568
- }
569
-
570
- /**
571
- *
572
- */
573
- async testQueryContinuId () {
574
- let bundleHash = generateBundleHash( this.secrets[ 0 ] );
575
-
576
- let client = await this.client( this.secrets[ 0 ] );
577
- let response = await client.queryContinuId( {
578
- bundle: bundleHash
579
- } );
580
- this.checkResponse( response, 'testQueryContinuId' );
581
- }
582
-
583
- /**
584
- * @throws \Exception
585
- */
586
- async testQueryBalance () {
587
- let client = await this.client( this.secrets[ 0 ] );
588
- let response = await client.queryBalance( {
589
- token: this.tokenSlugs[ 0 ]
590
- } );
591
- this.checkResponse( response, 'testQueryBalance' );
592
- }
593
-
594
-
595
- /**
596
- * Get a client for each secret
597
- *
598
- * @param secret
599
- * @param cellSlug
600
- * @returns {Promise<*>}
601
- */
602
- async client ( secret, cellSlug = 'unit_test' ) {
603
-
604
- // Create new client
605
- if ( !this.clients[ secret ] ) {
606
-
607
- // Create a client
608
- this.clients[ secret ] = new KnishIOClient( {
609
- uri: this.graphqlUrl,
610
- logging: true
611
- } );
612
-
613
- // Auth the client
614
- await this.clients[ secret ]
615
- .requestAuthToken( {
616
- secret,
617
- encrypt: this.encrypt,
618
- cellSlug
619
- } );
620
- if ( !this.clients[ secret ].getAuthToken() ) {
621
- console.log( 'Error with authorize - get an empty response.' );
622
- }
623
- }
624
-
625
- // Return the client by secret
626
- return this.clients[ secret ];
627
- }
628
-
629
-
630
- /**
631
- * Check a response
632
- * @param response
633
- * @param key
634
- */
635
- checkResponse ( response, key ) {
636
-
637
- console.log( ` ############### ${ key } ###############` );
638
- console.log( response );
639
-
640
- // Check molecule response
641
- if ( response instanceof ResponseMolecule ) {
642
- if ( !response.success() ) {
643
- this.debug( response );
644
- }
645
- console.assert( response.success(), response );
646
- }
647
-
648
- // Default response
649
- else {
650
- this.debug( response );
651
- }
652
- }
653
-
654
-
655
- /**
656
- * Debug output
657
- * @param response
658
- */
659
- debug ( response ) {
660
-
661
- // Reason data on the top of the output
662
- if ( response.data && Dot.get( response.data() || {}, 'reason' ) ) {
663
- console.log( response.data().reason );
664
- } else {
665
- console.log( response );
666
- }
667
-
668
- }
669
-
670
- }