@@ -12,7 +12,13 @@ import dateFormatter from '../../src/date';
12
12
13
13
14
14
import { UnsupportedScriptError } from '../../src/errors' ;
15
- import { HATHOR_TOKEN_CONFIG , DEFAULT_TX_VERSION , TOKEN_AUTHORITY_MASK } from '../../src/constants' ;
15
+ import {
16
+ HATHOR_TOKEN_CONFIG ,
17
+ DEFAULT_TX_VERSION ,
18
+ TOKEN_AUTHORITY_MASK ,
19
+ TOKEN_MINT_MASK ,
20
+ TOKEN_MELT_MASK ,
21
+ } from '../../src/constants' ;
16
22
import helpers from '../../src/utils/helpers' ;
17
23
import txApi from '../../src/api/txApi' ;
18
24
import P2PKH from '../../src/models/p2pkh' ;
@@ -132,11 +138,11 @@ describe('PartialTx.isComplete', () => {
132
138
expect ( partialTx . isComplete ( ) ) . toBe ( false ) ;
133
139
134
140
// Outputs have less than inputs for 1 token
135
- partialTx . outputs . push ( new ProposalOutput ( 1 , Buffer . from ( [ ] ) , { token : '1' , tokenData : 1 } ) ) ;
141
+ partialTx . outputs . push ( new ProposalOutput ( 1 , Buffer . from ( [ ] ) , { token : '1' } ) ) ;
136
142
expect ( partialTx . isComplete ( ) ) . toBe ( false ) ;
137
143
138
144
// Outputs have more than inputs for 1 token
139
- partialTx . outputs . push ( new ProposalOutput ( 2 , Buffer . from ( [ ] ) , { token : '2' , tokenData : 2 } ) ) ;
145
+ partialTx . outputs . push ( new ProposalOutput ( 2 , Buffer . from ( [ ] ) , { token : '2' } ) ) ;
140
146
expect ( partialTx . isComplete ( ) ) . toBe ( false ) ;
141
147
142
148
// Missing token from inputs
@@ -178,7 +184,7 @@ describe('PartialTx.isComplete', () => {
178
184
new ProposalOutput ( 1 , Buffer . from ( [ ] ) ) ,
179
185
new ProposalOutput ( 1 , Buffer . from ( [ ] ) , { token : '2' } ) ,
180
186
// Add authority output for token 2
181
- new ProposalOutput ( 1 , Buffer . from ( [ ] ) , { token : '2' , tokenData : TOKEN_AUTHORITY_MASK | 1 } ) ,
187
+ new ProposalOutput ( 1 , Buffer . from ( [ ] ) , { token : '2' , authorities : TOKEN_MINT_MASK } ) ,
182
188
] ;
183
189
184
190
expect ( partialTx . isComplete ( ) ) . toBe ( true ) ;
@@ -192,16 +198,19 @@ describe('PartialTx.addInput', () => {
192
198
const partialTx = new PartialTx ( testnet ) ;
193
199
const expected = [ ]
194
200
195
- expected . push ( expect . objectContaining ( { hash : 'hash1' , index : 0 , token : '1' , tokenData : 1 , value : 1 , address : 'W123' } ) ) ;
196
- partialTx . addInput ( 'hash1' , 0 , 1 , 'W123' , { token : '1' , tokenData : 1 } ) ;
201
+ // Passing all optional arguments
202
+ expected . push ( expect . objectContaining ( { hash : 'hash1' , index : 0 , token : '1' , authorities : 0 , value : 1 , address : 'W123' } ) ) ;
203
+ partialTx . addInput ( 'hash1' , 0 , 1 , 'W123' , { token : '1' , authorities : 0 } ) ;
197
204
expect ( partialTx . inputs ) . toEqual ( expected ) ;
198
205
199
- expected . push ( expect . objectContaining ( { hash : 'hash2' , index : 1 , token : '00' , tokenData : 0 , value : 27 , address : 'Wabc' } ) ) ;
206
+ // Default options, HTR
207
+ expected . push ( expect . objectContaining ( { hash : 'hash2' , index : 1 , token : '00' , authorities : 0 , value : 27 , address : 'Wabc' } ) ) ;
200
208
partialTx . addInput ( 'hash2' , 1 , 27 , 'Wabc' ) ;
201
209
expect ( partialTx . inputs ) . toEqual ( expected ) ;
202
210
203
- expected . push ( expect . objectContaining ( { hash : 'hash3' , index : 10 , token : '1' , tokenData : TOKEN_AUTHORITY_MASK | 3 , value : 1056 , address : 'W1b3' } ) ) ;
204
- partialTx . addInput ( 'hash3' , 10 , 1056 , 'W1b3' , { token : '1' , tokenData : TOKEN_AUTHORITY_MASK | 3 } ) ;
211
+ // Authority input
212
+ expected . push ( expect . objectContaining ( { hash : 'hash3' , index : 10 , token : '1' , authorities : TOKEN_MINT_MASK | TOKEN_MELT_MASK , value : 1056 , address : 'W1b3' } ) ) ;
213
+ partialTx . addInput ( 'hash3' , 10 , 1056 , 'W1b3' , { token : '1' , authorities : TOKEN_MINT_MASK | TOKEN_MELT_MASK } ) ;
205
214
expect ( partialTx . inputs ) . toEqual ( expected ) ;
206
215
} ) ;
207
216
} ) ;
@@ -220,17 +229,17 @@ describe('PartialTx.addOutput', () => {
220
229
isChange : true ,
221
230
value : 27 ,
222
231
script : expect . toMatchBuffer ( Buffer . from ( [ 230 , 148 , 32 ] ) ) ,
223
- tokenData : 128 ,
232
+ authorities : TOKEN_MELT_MASK ,
224
233
} ) ) ;
225
- partialTx . addOutput ( 27 , Buffer . from ( [ 230 , 148 , 32 ] ) , { token : '1' , tokenData : 128 , isChange : true } ) ;
234
+ partialTx . addOutput ( 27 , Buffer . from ( [ 230 , 148 , 32 ] ) , { token : '1' , authorities : TOKEN_MELT_MASK , isChange : true } ) ;
226
235
expect ( partialTx . outputs ) . toEqual ( expected ) ;
227
236
228
237
expected . push ( expect . objectContaining ( {
229
238
token : '2' ,
230
239
isChange : false ,
231
240
value : 72 ,
232
241
script : expect . toMatchBuffer ( Buffer . from ( [ 1 , 2 , 3 ] ) ) ,
233
- tokenData : 0 ,
242
+ authorities : 0 ,
234
243
} ) ) ;
235
244
partialTx . addOutput ( 72 , Buffer . from ( [ 1 , 2 , 3 ] ) , { token : '2' } ) ;
236
245
expect ( partialTx . outputs ) . toEqual ( expected ) ;
@@ -272,14 +281,14 @@ describe('PartialTx serialization', () => {
272
281
} ;
273
282
274
283
it ( 'should serialize a transaction correctly' , async ( ) => {
275
- const expected = 'PartialTx|00010102030000389deaf5557642e5a8a26656dcf360b608160f43e7ef79b9bde8ab69a18c00000d906babfa76b092f0088530a85f4d6bae5437304820f4c7a39540d87dd00000000000584ed8ad32b00e79e1c5cf26b5969ca7cd4d93ae39b776e71cfecf7c8c780400000000000f00001976a914729181c0f3f2e3f589cc10facbb9332e0c309a7788ac0000000d01001976a9146861143f7dc6b2f9c8525315efe6fcda160a795c88ac0000000c00001976a914486bc4f1e70f242a737d3866147c7f8335c2995f88ac0000000000000000000000010000000000|WVGxdgZMHkWo2Hdrb1sEFedNdjTXzjvjPi,00,0,1b:WVGxdgZMHkWo2Hdrb1sEFedNdjTXzjvjPi,0000389deaf5557642e5a8a26656dcf360b608160f43e7ef79b9bde8ab69a18c,1 ,d|1:2' ;
284
+ const expected = 'PartialTx|00010102030000389deaf5557642e5a8a26656dcf360b608160f43e7ef79b9bde8ab69a18c00000d906babfa76b092f0088530a85f4d6bae5437304820f4c7a39540d87dd00000000000584ed8ad32b00e79e1c5cf26b5969ca7cd4d93ae39b776e71cfecf7c8c780400000000000f00001976a914729181c0f3f2e3f589cc10facbb9332e0c309a7788ac0000000d01001976a9146861143f7dc6b2f9c8525315efe6fcda160a795c88ac0000000c00001976a914486bc4f1e70f242a737d3866147c7f8335c2995f88ac0000000000000000000000010000000000|WVGxdgZMHkWo2Hdrb1sEFedNdjTXzjvjPi,00,0,1b:WVGxdgZMHkWo2Hdrb1sEFedNdjTXzjvjPi,0000389deaf5557642e5a8a26656dcf360b608160f43e7ef79b9bde8ab69a18c,0 ,d|1:2' ;
276
285
277
286
const partialTx = new PartialTx ( testnet ) ;
278
287
279
288
const address = 'WVGxdgZMHkWo2Hdrb1sEFedNdjTXzjvjPi' ;
280
289
partialTx . inputs = [
281
290
new ProposalInput ( txId1 , 0 , 27 , address , { token : HATHOR_TOKEN_CONFIG . uid } ) ,
282
- new ProposalInput ( txId2 , 4 , 13 , address , { token : testTokenConfig . uid , tokenData : 1 } ) ,
291
+ new ProposalInput ( txId2 , 4 , 13 , address , { token : testTokenConfig . uid } ) ,
283
292
] ;
284
293
partialTx . outputs = [
285
294
new ProposalOutput ( 15 , scriptFromAddressP2PKH ( 'WZ7pDnkPnxbs14GHdUFivFzPbzitwNtvZo' ) ) ,
@@ -292,7 +301,7 @@ describe('PartialTx serialization', () => {
292
301
} ) ;
293
302
294
303
it ( 'should deserialize a transaction correctly' , ( ) => {
295
- const serialized = 'PartialTx|00010102030000389deaf5557642e5a8a26656dcf360b608160f43e7ef79b9bde8ab69a18c00000d906babfa76b092f0088530a85f4d6bae5437304820f4c7a39540d87dd00000000000584ed8ad32b00e79e1c5cf26b5969ca7cd4d93ae39b776e71cfecf7c8c780400000000000f00001976a914729181c0f3f2e3f589cc10facbb9332e0c309a7788ac0000000d01001976a9146861143f7dc6b2f9c8525315efe6fcda160a795c88ac0000000c00001976a914486bc4f1e70f242a737d3866147c7f8335c2995f88ac0000000000000000000000010000000000|WVGxdgZMHkWo2Hdrb1sEFedNdjTXzjvjPi,00,0,1b:WVGxdgZMHkWo2Hdrb1sEFedNdjTXzjvjPi,0000389deaf5557642e5a8a26656dcf360b608160f43e7ef79b9bde8ab69a18c,1 ,d|1:2' ;
304
+ const serialized = 'PartialTx|00010102030000389deaf5557642e5a8a26656dcf360b608160f43e7ef79b9bde8ab69a18c00000d906babfa76b092f0088530a85f4d6bae5437304820f4c7a39540d87dd00000000000584ed8ad32b00e79e1c5cf26b5969ca7cd4d93ae39b776e71cfecf7c8c780400000000000f00001976a914729181c0f3f2e3f589cc10facbb9332e0c309a7788ac0000000d01001976a9146861143f7dc6b2f9c8525315efe6fcda160a795c88ac0000000c00001976a914486bc4f1e70f242a737d3866147c7f8335c2995f88ac0000000000000000000000010000000000|WVGxdgZMHkWo2Hdrb1sEFedNdjTXzjvjPi,00,0,1b:WVGxdgZMHkWo2Hdrb1sEFedNdjTXzjvjPi,0000389deaf5557642e5a8a26656dcf360b608160f43e7ef79b9bde8ab69a18c,0 ,d|1:2' ;
296
305
const partialTx = PartialTx . deserialize ( serialized , testnet ) ;
297
306
expect ( partialTx . serialize ( ) ) . toBe ( serialized ) ;
298
307
} ) ;
@@ -306,7 +315,7 @@ describe('PartialTx serialization', () => {
306
315
307
316
partialTx . inputs = [
308
317
new ProposalInput ( txId1 , 0 , 27 , address , { token : HATHOR_TOKEN_CONFIG . uid } ) ,
309
- new ProposalInput ( txId2 , 4 , 13 , address , { token : testTokenConfig . uid , tokenData : 1 } ) ,
318
+ new ProposalInput ( txId2 , 4 , 13 , address , { token : testTokenConfig . uid } ) ,
310
319
] ;
311
320
const partialOnlyInputs = PartialTx . deserialize ( partialTx . serialize ( ) , testnet ) ;
312
321
expect ( partialOnlyInputs . serialize ( ) ) . toEqual ( partialTx . serialize ( ) ) ;
@@ -322,7 +331,7 @@ describe('PartialTx serialization', () => {
322
331
323
332
partialTx . inputs = [
324
333
new ProposalInput ( txId1 , 0 , 27 , address , { token : HATHOR_TOKEN_CONFIG . uid } ) ,
325
- new ProposalInput ( txId2 , 4 , 13 , address , { token : testTokenConfig . uid , tokenData : 1 } ) ,
334
+ new ProposalInput ( txId2 , 4 , 13 , address , { token : testTokenConfig . uid } ) ,
326
335
] ;
327
336
const partialFull = PartialTx . deserialize ( partialTx . serialize ( ) , testnet ) ;
328
337
expect ( partialFull . serialize ( ) ) . toEqual ( partialTx . serialize ( ) ) ;
@@ -416,7 +425,7 @@ describe('PartialTx.validate', () => {
416
425
const partialTx = new PartialTx ( testnet ) ;
417
426
partialTx . inputs = [
418
427
new ProposalInput ( txId1 , 0 , 27 , addr1 ) ,
419
- new ProposalInput ( txId2 , 4 , 13 , addr2 , { token : testTokenConfig . uid , tokenData : 1 } ) ,
428
+ new ProposalInput ( txId2 , 4 , 13 , addr2 , { token : testTokenConfig . uid } ) ,
420
429
] ;
421
430
partialTx . outputs = [
422
431
new ProposalOutput ( 15 , scriptFromAddressP2PKH ( addr2 ) ) ,
@@ -427,7 +436,7 @@ describe('PartialTx.validate', () => {
427
436
await expect ( partialTx . validate ( ) ) . resolves . toEqual ( true ) ;
428
437
} ) ;
429
438
430
- it ( 'should return false if an address, value, token or tokenData is wrong' , async ( ) => {
439
+ it ( 'should return false if an address, value, token or authorities are wrong' , async ( ) => {
431
440
spy . mockImplementation ( async ( txId , cb ) => {
432
441
return new Promise ( resolve => {
433
442
process . nextTick ( ( ) => {
@@ -440,7 +449,7 @@ describe('PartialTx.validate', () => {
440
449
// Address of inputs[1] is wrong
441
450
partialTx . inputs = [
442
451
new ProposalInput ( txId1 , 0 , 27 , addr1 ) ,
443
- new ProposalInput ( txId2 , 4 , 13 , addr1 , { token : testTokenConfig . uid , tokenData : 1 } ) ,
452
+ new ProposalInput ( txId2 , 4 , 13 , addr1 , { token : testTokenConfig . uid } ) ,
444
453
] ;
445
454
partialTx . outputs = [
446
455
new ProposalOutput ( 15 , scriptFromAddressP2PKH ( addr2 ) ) ,
@@ -453,23 +462,23 @@ describe('PartialTx.validate', () => {
453
462
// Value of inputs[0] is wrong
454
463
partialTx . inputs = [
455
464
new ProposalInput ( txId1 , 0 , 28 , addr1 ) ,
456
- new ProposalInput ( txId2 , 4 , 13 , addr2 , { token : testTokenConfig . uid , tokenData : 1 } ) ,
465
+ new ProposalInput ( txId2 , 4 , 13 , addr2 , { token : testTokenConfig . uid } ) ,
457
466
] ;
458
467
459
468
await expect ( partialTx . validate ( ) ) . resolves . toEqual ( false ) ;
460
469
461
470
// TokenData of inputs[1] is wrong
462
471
partialTx . inputs = [
463
472
new ProposalInput ( txId1 , 0 , 27 , addr1 ) ,
464
- new ProposalInput ( txId2 , 4 , 13 , addr2 , { token : testTokenConfig . uid , tokenData : 2 } ) ,
473
+ new ProposalInput ( txId2 , 4 , 13 , addr2 , { token : testTokenConfig . uid , authorities : TOKEN_MELT_MASK } ) ,
465
474
] ;
466
475
467
476
await expect ( partialTx . validate ( ) ) . resolves . toEqual ( false ) ;
468
477
469
478
// Token of inputs[0] is wrong
470
479
partialTx . inputs = [
471
480
new ProposalInput ( txId1 , 0 , 27 , addr1 , { token : testTokenConfig } ) ,
472
- new ProposalInput ( txId2 , 4 , 13 , addr2 , { token : testTokenConfig . uid , tokenData : 1 } ) ,
481
+ new ProposalInput ( txId2 , 4 , 13 , addr2 , { token : testTokenConfig . uid } ) ,
473
482
] ;
474
483
475
484
await expect ( partialTx . validate ( ) ) . resolves . toEqual ( false ) ;
0 commit comments