From 89c2754439feffc7e65a89c333acba2872780b3c Mon Sep 17 00:00:00 2001 From: Greg S Date: Sun, 24 Feb 2019 13:35:16 +0100 Subject: [PATCH] added tests for idGenerator ; removed debug log --- test/coders/idGenerator.spec.js | 41 +++++++++++++++++++ .../AddressAliasTransaction.spec.js | 1 - 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/test/coders/idGenerator.spec.js b/test/coders/idGenerator.spec.js index 51a0238..3f0e98d 100644 --- a/test/coders/idGenerator.spec.js +++ b/test/coders/idGenerator.spec.js @@ -17,6 +17,8 @@ import { expect } from 'chai'; import { sha3_256 } from 'js-sha3'; import idGenerator from '../../src/coders/idGenerator'; +import convert from '../../src/coders/convert'; +import uint64 from '../../src/coders/uint64'; const constants = { nem_id: [0x375FFA4B, 0x84B3552D], @@ -33,6 +35,31 @@ const basicMosaicInfo = { id: [0xC0AFC518, 0x3AD842A8] }; +const mosaicTestVector = { + rows: [ + { publicKey: '4AFF7B4BA8C1C26A7917575993346627CB6C80DE62CD92F7F9AEDB7064A3DE62', nonce: 'B76FE378', expectedMosaicId: '3AD842A8C0AFC518' }, + { publicKey: '3811EDF245F1D30171FF1474B24C4366FECA365A8457AAFA084F3DE4AEA0BA60', nonce: '21832A2A', expectedMosaicId: '24C54740A9F3893F' }, + { publicKey: '3104D468D20491EC12C988C50CAD9282256052907415359201C46CBD7A0BCD75', nonce: '2ADBB332', expectedMosaicId: '43908F2DEEA04245' }, + { publicKey: '6648E16513F351E9907B0EA34377E25F579BE640D4698B28E06585A21E94CFE2', nonce: 'B9175E0F', expectedMosaicId: '183172772BD29E78' }, + { publicKey: '1C05C40D38463FE725CF0584A3A69E3B0D6B780196A88C50624E49B921EE1404', nonce: 'F6077DDD', expectedMosaicId: '423DB0B12F787422' }, + { publicKey: '37926B3509987093C776C8EA3E7F978E3A78142B5C96B9434C3376177DC65EFD', nonce: '08190C6D', expectedMosaicId: '1F07D26B6CD352D5' }, + { publicKey: 'FDC6B0D415D90536263431F05C46AC492D0BD9B3CFA1B79D5A35E0F371655C0C', nonce: '81662AA5', expectedMosaicId: '74511F54940729CB' }, + { publicKey: '2D4EA99965477AEB3BC162C09C24C8DA4DABE408956C2F69642554EA48AAE1B2', nonce: 'EA16BF58', expectedMosaicId: '4C55843B6EB4A5BD' }, + { publicKey: '68EB2F91E74D005A7C22D6132926AEF9BFD90A3ACA3C7F989E579A93EFF24D51', nonce: 'E5F87A8B', expectedMosaicId: '4D89DE2B6967666A' }, + { publicKey: '3B082C0074F65D1E205643CDE72C6B0A3D0579C7ACC4D6A7E23A6EC46363B90F', nonce: '1E6BB49F', expectedMosaicId: '0A96B3A44615B62F' }, + { publicKey: '81245CA233B729FAD1752662EADFD73C5033E3B918CE854E01F6EB51E98CD9F1', nonce: 'B82965E3', expectedMosaicId: '1D6D8E655A77C4E6' }, + { publicKey: 'D3A2C1BFD5D48239001174BFF62A83A52BC9A535B8CDBDF289203146661D8AC4', nonce: 'F37FB460', expectedMosaicId: '268A3CC23ADCDA2D' }, + { publicKey: '4C4CA89B7A31C42A7AB963B8AB9D85628BBB94735C999B2BD462001A002DBDF3', nonce: 'FF6323B0', expectedMosaicId: '51202B5C51F6A5A9' }, + { publicKey: '2F95D9DCD4F18206A54FA95BD138DA1C038CA82546525A8FCC330185DA0647DC', nonce: '99674492', expectedMosaicId: '5CE4E38B09F1423D' }, + { publicKey: 'A7892491F714B8A7469F763F695BDB0B3BF28D1CC6831D17E91F550A2D48BD12', nonce: '55141880', expectedMosaicId: '5EFD001B3350C9CB' }, + { publicKey: '68BBDDF5C08F54278DA516F0E4A5CCF795C10E2DE26CAF127FF4357DA7ACF686', nonce: '11FA5BAF', expectedMosaicId: '179F0CDD6D2CCA7B' }, + { publicKey: '014F6EF90792F814F6830D64017107534F5B718E2DD43C25ACAABBE347DEC81E', nonce: '6CFBF7B3', expectedMosaicId: '53095813DEB3D108' }, + { publicKey: '95A6344597E0412C51B3559F58F564F9C2DE3101E5CC1DD8B115A93CE7040A71', nonce: '905EADFE', expectedMosaicId: '3551C4B12DDF067D' }, + { publicKey: '0D7DDFEB652E8B65915EA734420A1233A233119BF1B0D41E1D5118CDD44447EE', nonce: '61F5B671', expectedMosaicId: '696E2FB0682D3199' }, + { publicKey: 'FFD781A20B01D0C999AABC337B8BAE82D1E7929A9DD77CC1A71E4B99C0749684', nonce: 'D8542F1A', expectedMosaicId: '6C55E05D11D19FBD' } + ] +}; + describe('id generator', () => { function generateNamespaceId(parentId, name) { const hash = sha3_256.create(); @@ -80,6 +107,20 @@ describe('id generator', () => { expect(idGenerator.generateMosaicId(basicMosaicInfo.nonce, basicMosaicInfo.publicId)) .to.deep.equal(basicMosaicInfo.id); }); + + // @dataProvider mosaicTestVector + it('generates correct mosaicId given nonce and public key', () => { + mosaicTestVector.rows.map((row, i) => { + const pubKey = convert.hexToUint8(row.publicKey); + const nonce = convert.hexToUint8(row.nonce).reverse(); // Little-Endianness! + const mosaicId = idGenerator.generateMosaicId(nonce, pubKey); + const expectedId = uint64.fromHex(row.expectedMosaicId); + + // Assert: + expect(mosaicId) + .to.deep.equal(expectedId); + }); + }); }); describe('generate namespace paths', () => { diff --git a/test/transactions/AddressAliasTransaction.spec.js b/test/transactions/AddressAliasTransaction.spec.js index 467de7f..43f094d 100644 --- a/test/transactions/AddressAliasTransaction.spec.js +++ b/test/transactions/AddressAliasTransaction.spec.js @@ -41,7 +41,6 @@ describe('AddressAliasTransaction', () => { .build(); const transactionPayload = transaction.signTransaction(keyPair); - console.log(transactionPayload); expect(transactionPayload.payload.substring(240, transactionPayload.payload.length)) .to.be.equal('004F1B65BA5F7F49B1907D96D592DE9CB19B6C60905DFA7A5B8B231C9A71323EAF6E'); });