|
15 | 15 | */
|
16 | 16 |
|
17 | 17 | import { expect } from 'chai';
|
| 18 | +import { CreateTransactionFromPayload } from '../../../src/infrastructure/transaction/CreateTransactionFromPayload'; |
18 | 19 | import { Account } from '../../../src/model/account/Account';
|
19 | 20 | import { Address } from '../../../src/model/account/Address';
|
20 | 21 | import { NetworkType } from '../../../src/model/blockchain/NetworkType';
|
21 | 22 | import { MessageType } from '../../../src/model/message/MessageType';
|
22 | 23 | import { PersistentHarvestingDelegationMessage } from '../../../src/model/message/PersistentHarvestingDelegationMessage';
|
23 | 24 | import { PlainMessage } from '../../../src/model/message/PlainMessage';
|
| 25 | +import { Mosaic } from '../../../src/model/mosaic/Mosaic'; |
| 26 | +import { MosaicId } from '../../../src/model/mosaic/MosaicId'; |
24 | 27 | import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrencyMosaic';
|
25 | 28 | import { NamespaceId } from '../../../src/model/namespace/NamespaceId';
|
26 | 29 | import { Deadline } from '../../../src/model/transaction/Deadline';
|
@@ -299,4 +302,61 @@ describe('TransferTransaction', () => {
|
299 | 302 | );
|
300 | 303 | }).to.throw();
|
301 | 304 | });
|
| 305 | + |
| 306 | + it('should sort the Mosaic array', () => { |
| 307 | + const mosaics = [ |
| 308 | + new Mosaic(new MosaicId(UInt64.fromUint(200).toDTO()), UInt64.fromUint(0)), |
| 309 | + new Mosaic(new MosaicId(UInt64.fromUint(100).toDTO()), UInt64.fromUint(0)), |
| 310 | + ]; |
| 311 | + |
| 312 | + const transferTransaction = TransferTransaction.create( |
| 313 | + Deadline.create(), |
| 314 | + Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), |
| 315 | + mosaics, |
| 316 | + PlainMessage.create('NEM'), |
| 317 | + NetworkType.MIJIN_TEST, |
| 318 | + ); |
| 319 | + |
| 320 | + expect(transferTransaction.mosaics[0].id.id.compact()).to.be.equal(200); |
| 321 | + expect(transferTransaction.mosaics[1].id.id.compact()).to.be.equal(100); |
| 322 | + |
| 323 | + const signedTransaction = transferTransaction.signWith(account, generationHash); |
| 324 | + |
| 325 | + expect(signedTransaction.payload.substring( |
| 326 | + 304, |
| 327 | + signedTransaction.payload.length, |
| 328 | + )).to.be.equal( |
| 329 | + '64000000000000000000000000000000C8000000000000000000000000000000'); |
| 330 | + |
| 331 | + const sorted = CreateTransactionFromPayload(signedTransaction.payload) as TransferTransaction; |
| 332 | + expect(sorted.mosaics[0].id.id.compact()).to.be.equal(100); |
| 333 | + expect(sorted.mosaics[1].id.id.compact()).to.be.equal(200); |
| 334 | + }); |
| 335 | + |
| 336 | + it('should sort the Mosaic array - using Hex MosaicId', () => { |
| 337 | + const mosaics = [ |
| 338 | + new Mosaic(new MosaicId('D525AD41D95FCF29'), UInt64.fromUint(5)), |
| 339 | + new Mosaic(new MosaicId('77A1969932D987D7'), UInt64.fromUint(6)), |
| 340 | + new Mosaic(new MosaicId('67F2B76F28BD36BA'), UInt64.fromUint(10)), |
| 341 | + ]; |
| 342 | + |
| 343 | + const transferTransaction = TransferTransaction.create( |
| 344 | + Deadline.create(), |
| 345 | + Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), |
| 346 | + mosaics, |
| 347 | + PlainMessage.create('NEM'), |
| 348 | + NetworkType.MIJIN_TEST, |
| 349 | + ); |
| 350 | + |
| 351 | + expect(transferTransaction.mosaics[0].id.toHex()).to.be.equal('D525AD41D95FCF29'); |
| 352 | + expect(transferTransaction.mosaics[1].id.toHex()).to.be.equal('77A1969932D987D7'); |
| 353 | + expect(transferTransaction.mosaics[2].id.toHex()).to.be.equal('67F2B76F28BD36BA'); |
| 354 | + |
| 355 | + const signedTransaction = transferTransaction.signWith(account, generationHash); |
| 356 | + const sorted = CreateTransactionFromPayload(signedTransaction.payload) as TransferTransaction; |
| 357 | + expect(sorted.mosaics[0].id.toHex()).to.be.equal('67F2B76F28BD36BA'); |
| 358 | + expect(sorted.mosaics[1].id.toHex()).to.be.equal('77A1969932D987D7'); |
| 359 | + expect(sorted.mosaics[2].id.toHex()).to.be.equal('D525AD41D95FCF29'); |
| 360 | + |
| 361 | + }); |
302 | 362 | });
|
0 commit comments