From ed1690952a5156d89f03bee1b6d3d0996ab050ab Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 4 Jun 2020 18:31:01 +0100 Subject: [PATCH 01/22] Updated address (25 bytes => 24 bytes) --- package-lock.json | 2 +- src/core/format/RawAddress.ts | 13 +++-- src/model/account/Address.ts | 4 +- test/core/format/RawAddress.spec.ts | 91 ++++++++++++++++------------- 4 files changed, 62 insertions(+), 48 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9d084e70ea..56c923b728 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4792,7 +4792,7 @@ }, "which-module": { "version": "2.0.0", - "resolved": false, + "resolved": "", "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", "dev": true }, diff --git a/src/core/format/RawAddress.ts b/src/core/format/RawAddress.ts index fc5fc6f524..8d701872a3 100644 --- a/src/core/format/RawAddress.ts +++ b/src/core/format/RawAddress.ts @@ -25,10 +25,10 @@ export class RawAddress { static readonly constants = { sizes: { ripemd160: 20, - addressDecoded: 25, - addressEncoded: 40, + addressDecoded: 24, + addressEncoded: 39, key: 32, - checksum: 4, + checksum: 3, }, }; /** @@ -40,8 +40,7 @@ export class RawAddress { if (RawAddress.constants.sizes.addressEncoded !== encoded.length) { throw Error(`${encoded} does not represent a valid encoded address`); } - - return Base32.Base32Decode(encoded); + return Base32.Base32Decode(`${encoded}A`).subarray(0, RawAddress.constants.sizes.addressDecoded); }; /** @@ -68,7 +67,9 @@ export class RawAddress { if (RawAddress.constants.sizes.addressDecoded !== decoded.length) { throw Error(`${Convert.uint8ToHex(decoded)} does not represent a valid decoded address`); } - return Base32.Base32Encode(decoded); + const padded = new Uint8Array(RawAddress.constants.sizes.addressDecoded + 1); + padded.set(decoded); + return Base32.Base32Encode(padded).slice(0, -1); }; /** diff --git a/src/model/account/Address.ts b/src/model/account/Address.ts index 654eb51df8..678857128d 100644 --- a/src/model/account/Address.ts +++ b/src/model/account/Address.ts @@ -41,8 +41,8 @@ export class Address { public static createFromRawAddress(rawAddress: string): Address { let networkType: NetworkType; const addressTrimAndUpperCase: string = rawAddress.trim().toUpperCase().replace(/-/g, ''); - if (addressTrimAndUpperCase.length !== 40) { - throw new Error('Address ' + addressTrimAndUpperCase + ' has to be 40 characters long'); + if (addressTrimAndUpperCase.length !== 39) { + throw new Error('Address ' + addressTrimAndUpperCase + ' has to be 39 characters long'); } if (addressTrimAndUpperCase.charAt(0) === 'S') { networkType = NetworkType.MIJIN_TEST; diff --git a/test/core/format/RawAddress.spec.ts b/test/core/format/RawAddress.spec.ts index 6c521ede23..392b9b17ef 100644 --- a/test/core/format/RawAddress.spec.ts +++ b/test/core/format/RawAddress.spec.ts @@ -17,7 +17,7 @@ import { expect } from 'chai'; import { Convert as convert, RawAddress as address } from '../../../src/core/format'; import { NetworkType } from '../../../src/model/model'; -const Address_Decoded_Size = 25; +const Address_Decoded_Size = 24; describe('address', () => { describe('stringToAddress', () => { @@ -30,8 +30,21 @@ describe('address', () => { it('can create address from valid encoded address', () => { // Arrange: - const encoded = 'NAR3W7B4BCOZSZMFIZRYB3N5YGOUSWIYJCJ6HDFG'; - const expectedHex = '6823BB7C3C089D996585466380EDBDC19D4959184893E38CA6'; + const encoded = 'NAR3W7B4BCOZSZMFIZRYB3N5YGOUSWIYJCJ6HDA'; + const expectedHex = '6823BB7C3C089D996585466380EDBDC19D4959184893E38C'; + + // Act: + const decoded = address.stringToAddress(encoded); + + // Assert: + expect(address.isValidAddress(decoded)).to.equal(true); + expect(convert.uint8ToHex(decoded)).to.equal(expectedHex); + }); + + it('can create address from valid encoded address', () => { + // Arrange: + const encoded = 'NATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34SQ33Y'; + const expectedHex = '6826D27E1D0A26CA4E316F901E23E55C8711DB20DF250DEF'; // Act: const decoded = address.stringToAddress(encoded); @@ -51,17 +64,17 @@ describe('address', () => { it('cannot create address from invalid encoded string', () => { // Assert: - assertCannotCreateAddress('NC5(5DI2URIC4H3T3IMXQS25PWQWZIPEV6EV7LAS', 'illegal base32 character ('); - assertCannotCreateAddress('NC5J1DI2URIC4H3T3IMXQS25PWQWZIPEV6EV7LAS', 'illegal base32 character 1'); - assertCannotCreateAddress('NC5J5?I2URIC4H3T3IMXQS25PWQWZIPEV6EV7LAS', 'illegal base32 character ?'); + assertCannotCreateAddress('NC5(5DI2URIC4H3T3IMXQS25PWQWZIPEV6EV7LA', 'illegal base32 character ('); + assertCannotCreateAddress('NC5J1DI2URIC4H3T3IMXQS25PWQWZIPEV6EV7LA', 'illegal base32 character 1'); + assertCannotCreateAddress('NC5J5?I2URIC4H3T3IMXQS25PWQWZIPEV6EV7LA', 'illegal base32 character ?'); }); }); describe('addressToString', () => { it('can create encoded address from address', () => { // Arrange: - const decodedHex = '6823BB7C3C089D996585466380EDBDC19D4959184893E38CA6'; - const expected = 'NAR3W7B4BCOZSZMFIZRYB3N5YGOUSWIYJCJ6HDFG'; + const decodedHex = '6823BB7C3C089D996585466380EDBDC19D4959184893E38C'; + const expected = 'NAR3W7B4BCOZSZMFIZRYB3N5YGOUSWIYJCJ6HDA'; // Act: const encoded = address.addressToString(convert.hexToUint8(decodedHex)); @@ -81,8 +94,8 @@ describe('address', () => { describe('publicKeyToAddress', () => { it('can create address from public key for well known network', () => { // Arrange: - const expectedHex = '6023BB7C3C089D996585466380EDBDC19D49591848B3727714'; - const publicKey = convert.hexToUint8('3485D98EFD7EB07ADAFCFD1A157D89DE2796A95E780813C0258AF3F5F84ED8CB'); + const expectedHex = '6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144'; + const publicKey = convert.hexToUint8('2E834140FD66CF87B254A693A2C7862C819217B676D3943267156625E816EC6F'); // Act: const decoded = address.publicKeyToAddress(publicKey, NetworkType.MIJIN); @@ -95,8 +108,8 @@ describe('address', () => { it('can create address from public key for custom network', () => { // Arrange: - const expectedHex = '9023BB7C3C089D996585466380EDBDC19D495918486F4F86A7'; - const publicKey = convert.hexToUint8('3485D98EFD7EB07ADAFCFD1A157D89DE2796A95E780813C0258AF3F5F84ED8CB'); + const expectedHex = '9026D27E1D0A26CA4E316F901E23E55C8711DB20DF11A7B2'; + const publicKey = convert.hexToUint8('2E834140FD66CF87B254A693A2C7862C819217B676D3943267156625E816EC6F'); // Act: const decoded = address.publicKeyToAddress(publicKey, NetworkType.MIJIN_TEST); @@ -109,7 +122,7 @@ describe('address', () => { it('address calculation is deterministic', () => { // Arrange: - const publicKey = convert.hexToUint8('3485D98EFD7EB07ADAFCFD1A157D89DE2796A95E780813C0258AF3F5F84ED8CB'); + const publicKey = convert.hexToUint8('2E834140FD66CF87B254A693A2C7862C819217B676D3943267156625E816EC6F'); // Act: const decoded1 = address.publicKeyToAddress(publicKey, NetworkType.MIJIN_TEST); @@ -122,8 +135,8 @@ describe('address', () => { it('different public keys result in different addresses', () => { // Arrange: - const publicKey1 = convert.hexToUint8('1464953393CE96A08ABA6184601FD08864E910696B060FF7064474726E666CA8'); - const publicKey2 = convert.hexToUint8('b4f12e7c9f6946091e2cb8b6d3a12b50d17ccbbf646386ea27ce2946a7423dcf'); + const publicKey1 = convert.hexToUint8('2E834140FD66CF87B254A693A2C7862C819217B676D3943267156625E816EC6F'); + const publicKey2 = convert.hexToUint8('4875FD2E32875D1BC6567745F1509F0F890A1BF8EE59FA74452FA4183A270E03'); // Act: const decoded1 = address.publicKeyToAddress(publicKey1, NetworkType.MIJIN_TEST); @@ -137,7 +150,7 @@ describe('address', () => { it('different networks result in different addresses', () => { // Arrange: - const publicKey = convert.hexToUint8('b4f12e7c9f6946091e2cb8b6d3a12b50d17ccbbf646386ea27ce2946a7423dcf'); + const publicKey = convert.hexToUint8('4875FD2E32875D1BC6567745F1509F0F890A1BF8EE59FA74452FA4183A270E03'); // Act: const decoded1 = address.publicKeyToAddress(publicKey, NetworkType.MIJIN_TEST); @@ -153,7 +166,7 @@ describe('address', () => { describe('isValidAddress', () => { it('returns true for valid address', () => { // Arrange: - const validHex = '6823BB7C3C089D996585466380EDBDC19D4959184893E38CA6'; + const validHex = '6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144'; const decoded = convert.hexToUint8(validHex); // Assert: @@ -162,7 +175,7 @@ describe('address', () => { it('returns false for address with invalid checksum', () => { // Arrange: - const validHex = '6823BB7C3C089D996585466380EDBDC19D4959184893E38CA6'; + const validHex = '6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144'; const decoded = convert.hexToUint8(validHex); decoded[Address_Decoded_Size - 1] ^= 0xff; // ruin checksum @@ -172,7 +185,7 @@ describe('address', () => { it('returns false for address with invalid hash', () => { // Arrange: - const validHex = '6823BB7C3C089D996585466380EDBDC19D4959184893E38CA6'; + const validHex = '6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144'; const decoded = convert.hexToUint8(validHex); decoded[5] ^= 0xff; // ruin ripemd160 hash @@ -204,11 +217,11 @@ describe('address', () => { ]; const Addresses = [ - 'NATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34SQ3365', - 'NDR6EW2WBHJQDYMNGFX2UBZHMMZC5PGL2YCZOQR4', - 'NCOXVZMAZJTT4I3F7EAZYGNGR77D6WPTRH6SYIUT', - 'NDZ4373ASEGJ7S7GQTKF26TIIMC7HK5EWFDDCHAF', - 'NDI5I7Z3BRBAAHTZHGONGOXX742CW4W5QAZ4BMVY', + 'NATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34SQ33Y', + 'NDR6EW2WBHJQDYMNGFX2UBZHMMZC5PGL2YCZOQQ', + 'NCOXVZMAZJTT4I3F7EAZYGNGR77D6WPTRH6SYIQ', + 'NDZ4373ASEGJ7S7GQTKF26TIIMC7HK5EWFDDCHA', + 'NDI5I7Z3BRBAAHTZHGONGOXX742CW4W5QAZ4BMQ', ]; // Sanity: @@ -244,11 +257,11 @@ describe('address', () => { ]; const Addresses = [ - 'TATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA37JGO5UW', - 'TDR6EW2WBHJQDYMNGFX2UBZHMMZC5PGL2YBO3KHD', - 'TCOXVZMAZJTT4I3F7EAZYGNGR77D6WPTRE3VIBRU', - 'TDZ4373ASEGJ7S7GQTKF26TIIMC7HK5EWEPHRSM7', - 'TDI5I7Z3BRBAAHTZHGONGOXX742CW4W5QCY5ZUBR', + 'TATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA37JGO5Q', + 'TDR6EW2WBHJQDYMNGFX2UBZHMMZC5PGL2YBO3KA', + 'TCOXVZMAZJTT4I3F7EAZYGNGR77D6WPTRE3VIBQ', + 'TDZ4373ASEGJ7S7GQTKF26TIIMC7HK5EWEPHRSI', + 'TDI5I7Z3BRBAAHTZHGONGOXX742CW4W5QCY5ZUA', ]; // Sanity: @@ -284,11 +297,11 @@ describe('address', () => { ]; const Addresses = [ - 'MATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34YACREP', - 'MDR6EW2WBHJQDYMNGFX2UBZHMMZC5PGL22B27FN3', - 'MCOXVZMAZJTT4I3F7EAZYGNGR77D6WPTRFDHL7JO', - 'MDZ4373ASEGJ7S7GQTKF26TIIMC7HK5EWFN3NK2Z', - 'MDI5I7Z3BRBAAHTZHGONGOXX742CW4W5QCLCVED4', + 'MATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34YACRA', + 'MDR6EW2WBHJQDYMNGFX2UBZHMMZC5PGL22B27FI', + 'MCOXVZMAZJTT4I3F7EAZYGNGR77D6WPTRFDHL7I', + 'MDZ4373ASEGJ7S7GQTKF26TIIMC7HK5EWFN3NKY', + 'MDI5I7Z3BRBAAHTZHGONGOXX742CW4W5QCLCVEA', ]; // Sanity: @@ -324,11 +337,11 @@ describe('address', () => { ]; const Addresses = [ - 'SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMUQ', - 'SDR6EW2WBHJQDYMNGFX2UBZHMMZC5PGL2Z5UYY4U', - 'SCOXVZMAZJTT4I3F7EAZYGNGR77D6WPTRFENHXSH', - 'SDZ4373ASEGJ7S7GQTKF26TIIMC7HK5EWH6N46CD', - 'SDI5I7Z3BRBAAHTZHGONGOXX742CW4W5QDVZG2PO', + 'SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ', + 'SDR6EW2WBHJQDYMNGFX2UBZHMMZC5PGL2Z5UYYY', + 'SCOXVZMAZJTT4I3F7EAZYGNGR77D6WPTRFENHXQ', + 'SDZ4373ASEGJ7S7GQTKF26TIIMC7HK5EWH6N46A', + 'SDI5I7Z3BRBAAHTZHGONGOXX742CW4W5QDVZG2I', ]; // Sanity: From cfed5650cc8958a8ede5e99d776a7fd81aed46b6 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 4 Jun 2020 22:05:58 +0100 Subject: [PATCH 02/22] 961 patch changes applied --- e2e/infrastructure/AccountHttp.spec.ts | 12 +- e2e/infrastructure/BlockHttp.spec.ts | 2 +- e2e/infrastructure/Listener.spec.ts | 15 +- e2e/infrastructure/MetadataHttp.spec.ts | 48 +++--- e2e/infrastructure/MosaicHttp.spec.ts | 4 +- e2e/infrastructure/NamespaceHttp.spec.ts | 4 +- e2e/infrastructure/RestrictionHttp.spec.ts | 2 +- e2e/infrastructure/TransactionHttp.spec.ts | 16 +- e2e/infrastructure/UnresolvedMapping.spec.ts | 2 +- .../MetadataTransactionService.spec.ts | 34 ++--- e2e/service/TransactionService.spec.ts | 2 +- ...TransactionService_AggregateBonded.spec.ts | 8 +- package-lock.json | 12 +- package.json | 4 +- src/core/format/RawAddress.ts | 6 +- src/infrastructure/BlockHttp.ts | 5 +- src/infrastructure/Listener.ts | 2 +- src/infrastructure/MetadataHttp.ts | 25 +-- src/infrastructure/MetadataRepository.ts | 12 +- src/infrastructure/MosaicHttp.ts | 18 +-- src/infrastructure/MultisigHttp.ts | 59 +++----- src/infrastructure/NamespaceHttp.ts | 38 ++--- src/infrastructure/ReceiptHttp.ts | 12 +- src/infrastructure/RepositoryFactoryHttp.ts | 2 +- .../receipt/CreateReceiptFromDTO.ts | 28 ++-- .../searchCriteria/BlockSearchCriteria.ts | 2 +- .../transaction/CreateTransactionFromDTO.ts | 15 +- .../CreateTransactionFromPayload.ts | 2 +- .../transaction/SerializeTransactionToJSON.ts | 14 +- src/model/account/Address.ts | 21 ++- src/model/account/MultisigAccountGraphInfo.ts | 4 +- src/model/account/MultisigAccountInfo.ts | 28 ++-- src/model/account/UnresolvedAddress.ts | 7 + src/model/blockchain/BlockInfo.ts | 7 +- src/model/blockchain/NewBlock.ts | 7 +- src/model/metadata/MetadataEntry.ts | 13 +- src/model/model.ts | 1 + src/model/mosaic/MosaicInfo.ts | 12 +- src/model/namespace/NamespaceId.ts | 11 +- src/model/namespace/NamespaceInfo.ts | 8 +- src/model/receipt/BalanceChangeReceipt.ts | 13 +- src/model/receipt/BalanceTransferReceipt.ts | 26 +--- .../AccountAddressRestrictionTransaction.ts | 23 ++- .../transaction/AccountMetadataTransaction.ts | 35 +++-- .../transaction/AddressAliasTransaction.ts | 2 +- src/model/transaction/AggregateTransaction.ts | 9 +- .../AggregateTransactionCosignature.ts | 7 + .../MosaicAddressRestrictionTransaction.ts | 2 +- .../transaction/MosaicMetadataTransaction.ts | 33 ++-- .../MultisigAccountModificationTransaction.ts | 67 ++++---- .../NamespaceMetadataTransaction.ts | 34 +++-- .../transaction/SecretLockTransaction.ts | 2 +- .../transaction/SecretProofTransaction.ts | 2 +- src/model/transaction/TransferTransaction.ts | 6 +- src/service/AggregateTransactionService.ts | 30 ++-- src/service/MetadataTransactionService.ts | 119 ++++++--------- src/service/MosaicService.ts | 2 +- test/core/format/RawAddress.spec.ts | 2 +- test/core/utils/TransactionMapping.spec.ts | 89 ++++++----- .../TransactionMappingWithSignatures.spec.ts | 49 +++--- test/core/utils/UnresolvedMapping.spec.ts | 6 +- test/infrastructure/AccountHttp.spec.ts | 2 +- test/infrastructure/BlockHttp.spec.ts | 10 +- test/infrastructure/Listener.spec.ts | 15 +- test/infrastructure/MetadataHttp.spec.ts | 29 ++-- test/infrastructure/MosaicHttp.spec.ts | 10 +- test/infrastructure/MultisigHttp.spec.ts | 23 +-- test/infrastructure/Page.spec.ts | 3 +- .../SerializeTransactionToJSON.spec.ts | 19 +-- test/infrastructure/TransactionHttp.spec.ts | 6 +- .../TransactionSearchCriteria.spec.ts | 6 +- .../receipt/CreateReceiptFromDTO.spec.ts | 15 +- .../CreateTransactionFromDTO.spec.ts | 20 ++- .../transaction/ValidateTransaction.ts | 4 +- test/model/account/Account.spec.ts | 2 +- test/model/account/AccountInfo.spec.ts | 8 +- test/model/account/Address.spec.ts | 70 ++++----- .../account/MultisigAccountGraphInfo.spec.ts | 42 ++--- .../model/account/MultisigAccountInfo.spec.ts | 102 +++++-------- test/model/account/PublicAccount.spec.ts | 2 +- test/model/blockchain/BlockInfo.spec.ts | 7 +- test/model/blockchain/NewBlock.spec.ts | 11 +- test/model/message/EncryptedMessage.spec.ts | 5 +- test/model/metadata/Metadata.spec.ts | 12 +- test/model/metadata/MetadataEntry.spec.ts | 39 ++--- test/model/mosaic/MosaicAmountView.spec.ts | 6 +- test/model/mosaic/MosaicInfo.spec.ts | 46 +++--- test/model/mosaic/MosaicView.spec.ts | 3 +- test/model/namespace/Alias.spec.ts | 4 +- test/model/namespace/NamespaceInfo.spec.ts | 18 ++- test/model/receipt/Receipt.spec.ts | 60 ++++---- .../model/receipt/ResolutionStatement.spec.ts | 23 +-- test/model/receipt/Statement.spec.ts | 26 ++-- .../restriction/AccountRestriction.spec.ts | 4 +- .../restriction/AccountRestrictions.spec.ts | 6 +- .../AccountRestrictionsInfo.spec.ts | 6 +- .../restriction/MosaicRestriction.spec.ts | 4 +- .../AccountKeyLinkTransaction.spec.ts | 2 +- .../AccountMetadataTransaction.spec.ts | 49 ++++-- .../AccountRestrictionTransaction.spec.ts | 49 +++--- .../AddressAliasTransaction.spec.ts | 24 +-- .../transaction/AggregateTransaction.spec.ts | 49 +++--- .../CosignatureTransaction.spec.ts | 3 +- ...osaicAddressRestrictionTransaction.spec.ts | 8 +- .../MosaicMetadataTransaction.spec.ts | 61 +++++--- ...isigAccountModificationTransaction.spec.ts | 143 ++++++++---------- .../NamespaceMetadataTransaction.spec.ts | 53 +++++-- .../NodeKeyLinkTransaction.spec.ts | 2 +- ...istentDelegationRequestTransaction.spec.ts | 2 +- .../transaction/SecretLockTransaction.spec.ts | 36 ++--- .../SecretProofTransaction.spec.ts | 12 +- test/model/transaction/Transaction.spec.ts | 8 +- .../TransactionStatusError.spec.ts | 2 +- .../transaction/TransferTransaction.spec.ts | 69 +++++---- .../VotingKeyLinkTransaction.spec.ts | 2 +- .../transaction/VrfKeyLinkTransaction.spec.ts | 2 +- test/service/AccountService.spec.ts | 6 +- .../AggregateTransactionService.spec.ts | 46 +++--- .../MetadataTransactionservice.spec.ts | 44 +++--- test/service/MosaicService.spec.ts | 6 +- test/service/NamespaceService.spec.ts | 6 +- test/service/TransactionService.spec.ts | 2 +- 122 files changed, 1251 insertions(+), 1185 deletions(-) create mode 100644 src/model/account/UnresolvedAddress.ts diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index f328edb52e..f1802fab40 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -134,7 +134,7 @@ describe('AccountHttp', () => { Deadline.create(), 2, 1, - [cosignAccount1.publicAccount, cosignAccount2.publicAccount, cosignAccount3.publicAccount], + [cosignAccount1.address, cosignAccount2.address, cosignAccount3.address], [], networkType, helper.maxFee, @@ -182,13 +182,13 @@ describe('AccountHttp', () => { const multisigAccountGraphInfo = await multisigRepository .getMultisigAccountGraphInfo(multisigAccount.publicAccount.address) .toPromise(); - expect(multisigAccountGraphInfo.multisigAccounts.get(0)![0].account.publicKey).to.be.equal(multisigAccount.publicKey); + expect(multisigAccountGraphInfo.multisigEntries.get(0)![0].accountAddress.plain()).to.be.equal(multisigAccount.address.plain()); }); }); describe('getMultisigAccountInfo', () => { it('should call getMultisigAccountInfo successfully', async () => { const multisigAccountInfo = await multisigRepository.getMultisigAccountInfo(multisigAccount.publicAccount.address).toPromise(); - expect(multisigAccountInfo.account.publicKey).to.be.equal(multisigAccount.publicKey); + expect(multisigAccountInfo.accountAddress.plain()).to.be.equal(multisigAccount.address.plain()); }); }); @@ -245,7 +245,7 @@ describe('AccountHttp', () => { -1, 0, [], - [cosignAccount1.publicAccount], + [cosignAccount1.address], networkType, helper.maxFee, ); @@ -254,7 +254,7 @@ describe('AccountHttp', () => { 0, 0, [], - [cosignAccount2.publicAccount], + [cosignAccount2.address], networkType, helper.maxFee, ); @@ -264,7 +264,7 @@ describe('AccountHttp', () => { -1, -1, [], - [cosignAccount3.publicAccount], + [cosignAccount3.address], networkType, helper.maxFee, ); diff --git a/e2e/infrastructure/BlockHttp.spec.ts b/e2e/infrastructure/BlockHttp.spec.ts index 9de3ff22e7..e0a744b058 100644 --- a/e2e/infrastructure/BlockHttp.spec.ts +++ b/e2e/infrastructure/BlockHttp.spec.ts @@ -91,7 +91,7 @@ describe('BlockHttp', () => { expect(blockInfo.height.higher).to.be.equal(0); expect(blockInfo.timestamp.lower).to.be.equal(0); expect(blockInfo.timestamp.higher).to.be.equal(0); - expect(blockInfo.beneficiaryPublicKey).not.to.be.undefined; + expect(blockInfo.beneficiaryAddress).not.to.be.undefined; expect(blockInfo.numStatements).not.to.be.undefined; }); }); diff --git a/e2e/infrastructure/Listener.spec.ts b/e2e/infrastructure/Listener.spec.ts index 75e28c2ba2..0efcee0500 100644 --- a/e2e/infrastructure/Listener.spec.ts +++ b/e2e/infrastructure/Listener.spec.ts @@ -19,7 +19,6 @@ import { filter } from 'rxjs/operators'; import { TransactionRepository } from '../../src/infrastructure/TransactionRepository'; import { Account } from '../../src/model/account/Account'; import { PlainMessage } from '../../src/model/message/PlainMessage'; -import { Address, CosignatureTransaction, LockFundsTransaction, Mosaic, SignedTransaction, UInt64 } from '../../src/model/model'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { NetworkType } from '../../src/model/network/NetworkType'; @@ -30,6 +29,12 @@ import { TransferTransaction } from '../../src/model/transaction/TransferTransac import { IntegrationTestHelper } from './IntegrationTestHelper'; import { TransactionSearchCriteria } from '../../src/infrastructure/searchCriteria/TransactionSearchCriteria'; import { TransactionGroupSubsetEnum } from 'symbol-openapi-typescript-node-client'; +import { Address } from '../../src/model/account/Address'; +import { SignedTransaction } from '../../src/model/transaction/SignedTransaction'; +import { LockFundsTransaction } from '../../src/model/transaction/LockFundsTransaction'; +import { UInt64 } from '../../src/model/UInt64'; +import { Mosaic } from '../../src/model/mosaic/Mosaic'; +import { CosignatureTransaction } from '../../src/model/transaction/CosignatureTransaction'; describe('Listener', () => { const helper = new IntegrationTestHelper(); @@ -199,7 +204,7 @@ describe('Listener', () => { Deadline.create(), 2, 1, - [cosignAccount1.publicAccount, cosignAccount2.publicAccount, cosignAccount3.publicAccount], + [cosignAccount1.address, cosignAccount2.address, cosignAccount3.address], [], networkType, helper.maxFee, @@ -313,7 +318,7 @@ describe('Listener', () => { -1, 0, [], - [cosignAccount1.publicAccount], + [cosignAccount1.address], networkType, ); const removeCosigner2 = MultisigAccountModificationTransaction.create( @@ -321,7 +326,7 @@ describe('Listener', () => { 0, 0, [], - [cosignAccount2.publicAccount], + [cosignAccount2.address], networkType, ); @@ -330,7 +335,7 @@ describe('Listener', () => { -1, -1, [], - [cosignAccount3.publicAccount], + [cosignAccount3.address], networkType, ); diff --git a/e2e/infrastructure/MetadataHttp.spec.ts b/e2e/infrastructure/MetadataHttp.spec.ts index a0b3d5eec8..af918e5ab1 100644 --- a/e2e/infrastructure/MetadataHttp.spec.ts +++ b/e2e/infrastructure/MetadataHttp.spec.ts @@ -106,7 +106,7 @@ describe('MetadataHttp', () => { it('aggregate', () => { const accountMetadataTransaction = AccountMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(5), 23, `Test account meta value`, @@ -129,7 +129,7 @@ describe('MetadataHttp', () => { it('aggregate', () => { const mosaicMetadataTransaction = MosaicMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(5), mosaicId, 22, @@ -154,7 +154,7 @@ describe('MetadataHttp', () => { it('aggregate', () => { const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(5), namespaceId, 25, @@ -186,8 +186,8 @@ describe('MetadataHttp', () => { const metadata = await metadataRepository.getAccountMetadata(accountAddress).toPromise(); expect(metadata.length).to.be.greaterThan(0); expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); - expect(metadata[0].metadataEntry.senderPublicKey).to.be.equal(account.publicKey); - expect(metadata[0].metadataEntry.targetPublicKey).to.be.equal(account.publicKey); + expect(metadata[0].metadataEntry.sourceAddress).to.be.deep.equal(account.address); + expect(metadata[0].metadataEntry.targetAddress).to.be.deep.equal(account.address); expect(metadata[0].metadataEntry.targetId).to.be.undefined; expect(metadata[0].metadataEntry.value).to.be.equal('Test account meta value'); expect(metadata[0].metadataEntry.value.length).to.be.equal(23); @@ -199,8 +199,8 @@ describe('MetadataHttp', () => { const metadata = await metadataRepository.getAccountMetadataByKey(accountAddress, UInt64.fromUint(5).toHex()).toPromise(); expect(metadata.length).to.be.greaterThan(0); expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); - expect(metadata[0].metadataEntry.senderPublicKey).to.be.equal(account.publicKey); - expect(metadata[0].metadataEntry.targetPublicKey).to.be.equal(account.publicKey); + expect(metadata[0].metadataEntry.sourceAddress).to.be.deep.equal(account.address); + expect(metadata[0].metadataEntry.targetAddress).to.be.deep.equal(account.address); expect(metadata[0].metadataEntry.targetId).to.be.undefined; expect(metadata[0].metadataEntry.value).to.be.equal('Test account meta value'); expect(metadata[0].metadataEntry.value.length).to.be.equal(23); @@ -210,11 +210,11 @@ describe('MetadataHttp', () => { describe('getAccountMetadataByKeyAndSender', () => { it('should return metadata given a NEM Address and metadata key and sender public key', async () => { const metadata = await metadataRepository - .getAccountMetadataByKeyAndSender(accountAddress, UInt64.fromUint(5).toHex(), account.publicKey) + .getAccountMetadataByKeyAndSender(accountAddress, UInt64.fromUint(5).toHex(), account.address) .toPromise(); expect(metadata.metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); - expect(metadata.metadataEntry.senderPublicKey).to.be.equal(account.publicKey); - expect(metadata.metadataEntry.targetPublicKey).to.be.equal(account.publicKey); + expect(metadata.metadataEntry.sourceAddress).to.be.deep.equal(account.address); + expect(metadata.metadataEntry.targetAddress).to.be.deep.equal(account.address); expect(metadata.metadataEntry.targetId).to.be.undefined; expect(metadata.metadataEntry.value).to.be.equal('Test account meta value'); expect(metadata.metadataEntry.value.length).to.be.equal(23); @@ -226,8 +226,8 @@ describe('MetadataHttp', () => { const metadata = await metadataRepository.getMosaicMetadata(mosaicId).toPromise(); expect(metadata.length).to.be.greaterThan(0); expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); - expect(metadata[0].metadataEntry.senderPublicKey).to.be.equal(account.publicKey); - expect(metadata[0].metadataEntry.targetPublicKey).to.be.equal(account.publicKey); + expect(metadata[0].metadataEntry.sourceAddress).to.be.deep.equal(account.address); + expect(metadata[0].metadataEntry.targetAddress).to.be.deep.equal(account.address); expect((metadata[0].metadataEntry.targetId as MosaicId).toHex()).to.be.equal(mosaicId.toHex()); expect(metadata[0].metadataEntry.value).to.be.equal('Test mosaic meta value'); expect(metadata[0].metadataEntry.value.length).to.be.equal(22); @@ -239,8 +239,8 @@ describe('MetadataHttp', () => { const metadata = await metadataRepository.getMosaicMetadataByKey(mosaicId, UInt64.fromUint(5).toHex()).toPromise(); expect(metadata.length).to.be.greaterThan(0); expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); - expect(metadata[0].metadataEntry.senderPublicKey).to.be.equal(account.publicKey); - expect(metadata[0].metadataEntry.targetPublicKey).to.be.equal(account.publicKey); + expect(metadata[0].metadataEntry.sourceAddress).to.be.deep.equal(account.address); + expect(metadata[0].metadataEntry.targetAddress).to.be.deep.equal(account.address); expect((metadata[0].metadataEntry.targetId as MosaicId).toHex()).to.be.equal(mosaicId.toHex()); expect(metadata[0].metadataEntry.value).to.be.equal('Test mosaic meta value'); expect(metadata[0].metadataEntry.value.length).to.be.equal(22); @@ -250,11 +250,11 @@ describe('MetadataHttp', () => { describe('getMosaicMetadataByKeyAndSender', () => { it('should return metadata given a mosaicId and metadata key and sender public key', async () => { const metadata = await metadataRepository - .getMosaicMetadataByKeyAndSender(mosaicId, UInt64.fromUint(5).toHex(), account.publicKey) + .getMosaicMetadataByKeyAndSender(mosaicId, UInt64.fromUint(5).toHex(), account.address) .toPromise(); expect(metadata.metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); - expect(metadata.metadataEntry.senderPublicKey).to.be.equal(account.publicKey); - expect(metadata.metadataEntry.targetPublicKey).to.be.equal(account.publicKey); + expect(metadata.metadataEntry.sourceAddress).to.be.deep.equal(account.address); + expect(metadata.metadataEntry.targetAddress).to.be.deep.equal(account.address); expect((metadata.metadataEntry.targetId as MosaicId).toHex()).to.be.equal(mosaicId.toHex()); expect(metadata.metadataEntry.value).to.be.equal('Test mosaic meta value'); expect(metadata.metadataEntry.value.length).to.be.equal(22); @@ -266,8 +266,8 @@ describe('MetadataHttp', () => { const metadata = await metadataRepository.getNamespaceMetadata(namespaceId).toPromise(); expect(metadata.length).to.be.greaterThan(0); expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); - expect(metadata[0].metadataEntry.senderPublicKey).to.be.equal(account.publicKey); - expect(metadata[0].metadataEntry.targetPublicKey).to.be.equal(account.publicKey); + expect(metadata[0].metadataEntry.sourceAddress).to.be.deep.equal(account.address); + expect(metadata[0].metadataEntry.targetAddress).to.be.deep.equal(account.address); expect((metadata[0].metadataEntry.targetId as NamespaceId).toHex()).to.be.equal(namespaceId.toHex()); expect(metadata[0].metadataEntry.value).to.be.equal('Test namespace meta value'); expect(metadata[0].metadataEntry.value.length).to.be.equal(25); @@ -279,8 +279,8 @@ describe('MetadataHttp', () => { const metadata = await metadataRepository.getNamespaceMetadataByKey(namespaceId, UInt64.fromUint(5).toHex()).toPromise(); expect(metadata.length).to.be.greaterThan(0); expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); - expect(metadata[0].metadataEntry.senderPublicKey).to.be.equal(account.publicKey); - expect(metadata[0].metadataEntry.targetPublicKey).to.be.equal(account.publicKey); + expect(metadata[0].metadataEntry.sourceAddress).to.be.deep.equal(account.address); + expect(metadata[0].metadataEntry.targetAddress).to.be.deep.equal(account.address); expect((metadata[0].metadataEntry.targetId as NamespaceId).toHex()).to.be.equal(namespaceId.toHex()); expect(metadata[0].metadataEntry.value).to.be.equal('Test namespace meta value'); expect(metadata[0].metadataEntry.value.length).to.be.equal(25); @@ -290,11 +290,11 @@ describe('MetadataHttp', () => { describe('getNamespaceMetadataByKeyAndSender', () => { it('should return metadata given a namespaceId and metadata key and sender public key', async () => { const metadata = await metadataRepository - .getNamespaceMetadataByKeyAndSender(namespaceId, UInt64.fromUint(5).toHex(), account.publicKey) + .getNamespaceMetadataByKeyAndSender(namespaceId, UInt64.fromUint(5).toHex(), account.address) .toPromise(); expect(metadata.metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); - expect(metadata.metadataEntry.senderPublicKey).to.be.equal(account.publicKey); - expect(metadata.metadataEntry.targetPublicKey).to.be.equal(account.publicKey); + expect(metadata.metadataEntry.sourceAddress).to.be.deep.equal(account.address); + expect(metadata.metadataEntry.targetAddress).to.be.deep.equal(account.address); expect((metadata.metadataEntry.targetId as NamespaceId).toHex()).to.be.equal(namespaceId.toHex()); expect(metadata.metadataEntry.value).to.be.equal('Test namespace meta value'); expect(metadata.metadataEntry.value.length).to.be.equal(25); diff --git a/e2e/infrastructure/MosaicHttp.spec.ts b/e2e/infrastructure/MosaicHttp.spec.ts index af1bde6bfb..1a3a68ac58 100644 --- a/e2e/infrastructure/MosaicHttp.spec.ts +++ b/e2e/infrastructure/MosaicHttp.spec.ts @@ -137,7 +137,7 @@ describe('MosaicHttp', () => { describe('getMosaic', () => { it('should return mosaic given mosaicId', async () => { const mosaicInfo = await mosaicRepository.getMosaic(mosaicId).toPromise(); - expect(mosaicInfo.height.lower).not.to.be.null; + expect(mosaicInfo.startHeight.lower).not.to.be.null; expect(mosaicInfo.divisibility).to.be.equal(3); expect(mosaicInfo.isSupplyMutable()).to.be.equal(true); expect(mosaicInfo.isTransferable()).to.be.equal(true); @@ -147,7 +147,7 @@ describe('MosaicHttp', () => { describe('getMosaics', () => { it('should return mosaics given array of mosaicIds', async () => { const mosaicInfos = await mosaicRepository.getMosaics([mosaicId]).toPromise(); - expect(mosaicInfos[0].height.lower).not.to.be.null; + expect(mosaicInfos[0].startHeight.lower).not.to.be.null; expect(mosaicInfos[0].divisibility).to.be.equal(3); expect(mosaicInfos[0].isSupplyMutable()).to.be.equal(true); expect(mosaicInfos[0].isTransferable()).to.be.equal(true); diff --git a/e2e/infrastructure/NamespaceHttp.spec.ts b/e2e/infrastructure/NamespaceHttp.spec.ts index 35a6735b39..3651621c22 100644 --- a/e2e/infrastructure/NamespaceHttp.spec.ts +++ b/e2e/infrastructure/NamespaceHttp.spec.ts @@ -93,14 +93,14 @@ describe('NamespaceHttp', () => { describe('getNamespacesFromAccount', () => { it('should return namespace data given publicKeyNemesis', async () => { const namespaces = await namespaceRepository.getNamespacesFromAccount(account.address).toPromise(); - deepEqual(namespaces[0].owner, account.publicAccount); + deepEqual(namespaces[0].ownerAddress, account.address); }); }); describe('getNamespacesFromAccounts', () => { it('should return namespaces data given publicKeyNemesis', async () => { const namespaces = await namespaceRepository.getNamespacesFromAccounts([account.address]).toPromise(); - deepEqual(namespaces[0].owner, account.publicAccount); + deepEqual(namespaces[0].ownerAddress, account.address); }); }); diff --git a/e2e/infrastructure/RestrictionHttp.spec.ts b/e2e/infrastructure/RestrictionHttp.spec.ts index a3492b960d..e53a239481 100644 --- a/e2e/infrastructure/RestrictionHttp.spec.ts +++ b/e2e/infrastructure/RestrictionHttp.spec.ts @@ -34,7 +34,7 @@ import { MosaicDefinitionTransaction } from '../../src/model/transaction/MosaicD import { MosaicGlobalRestrictionTransaction } from '../../src/model/transaction/MosaicGlobalRestrictionTransaction'; import { UInt64 } from '../../src/model/UInt64'; import { IntegrationTestHelper } from './IntegrationTestHelper'; -import { AddressRestrictionFlag } from '../../src/model/model'; +import { AddressRestrictionFlag } from '../../src/model/restriction/AddressRestrictionFlag'; describe('RestrictionHttp', () => { const helper = new IntegrationTestHelper(); diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 398109e38b..62c1911808 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -68,10 +68,12 @@ import { TransactionSearchCriteria } from '../../src/infrastructure/infrastructu import { VrfKeyLinkTransaction } from '../../src/model/transaction/VrfKeyLinkTransaction'; import { VotingKeyLinkTransaction } from '../../src/model/transaction/VotingKeyLinkTransaction'; import { NodeKeyLinkTransaction } from '../../src/model/transaction/NodeKeyLinkTransaction'; -import { AddressRestrictionFlag, MosaicRestrictionFlag, OperationRestrictionFlag } from '../../src/model/model'; import { TransactionPaginationStreamer } from '../../src/infrastructure/paginationStreamer/TransactionPaginationStreamer'; import { toArray, take } from 'rxjs/operators'; import { deepEqual } from 'assert'; +import { AddressRestrictionFlag } from '../../src/model/restriction/AddressRestrictionFlag'; +import { MosaicRestrictionFlag } from '../../src/model/restriction/MosaicRestrictionFlag'; +import { OperationRestrictionFlag } from '../../src/model/restriction/OperationRestrictionFlag'; // eslint-disable-next-line @typescript-eslint/no-var-requires const CryptoJS = require('crypto-js'); @@ -188,7 +190,7 @@ describe('TransactionHttp', () => { it('aggregate', () => { const accountMetadataTransaction = AccountMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(5), 10, Convert.uint8ToUtf8(new Uint8Array(10)), @@ -207,7 +209,7 @@ describe('TransactionHttp', () => { const signedTransaction = aggregateTransaction.signWith(account, generationHash); return helper.announce(signedTransaction).then((transaction: AggregateTransaction) => { transaction.innerTransactions.forEach((innerTx) => { - expect((innerTx as AccountMetadataTransaction).targetPublicKey, 'TargetPublicKey').not.to.be.undefined; + expect((innerTx as AccountMetadataTransaction).targetAddress, 'TargetAddress').not.to.be.undefined; expect((innerTx as AccountMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; expect((innerTx as AccountMetadataTransaction).valueSizeDelta, 'ValueSizeDelta').not.to.be.undefined; expect((innerTx as AccountMetadataTransaction).value, 'Value').not.to.be.undefined; @@ -220,7 +222,7 @@ describe('TransactionHttp', () => { it('aggregate', () => { const mosaicMetadataTransaction = MosaicMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(5), mosaicId, 10, @@ -239,7 +241,7 @@ describe('TransactionHttp', () => { const signedTransaction = aggregateTransaction.signWith(account, generationHash); return helper.announce(signedTransaction).then((transaction: AggregateTransaction) => { transaction.innerTransactions.forEach((innerTx) => { - expect((innerTx as MosaicMetadataTransaction).targetPublicKey, 'TargetPublicKey').not.to.be.undefined; + expect((innerTx as MosaicMetadataTransaction).targetAddress, 'TargetAddress').not.to.be.undefined; expect((innerTx as MosaicMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; expect((innerTx as MosaicMetadataTransaction).valueSizeDelta, 'ValueSizeDelta').not.to.be.undefined; expect((innerTx as MosaicMetadataTransaction).value, 'Value').not.to.be.undefined; @@ -294,7 +296,7 @@ describe('TransactionHttp', () => { it('aggregate', () => { const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(5), namespaceId, 10, @@ -313,7 +315,7 @@ describe('TransactionHttp', () => { const signedTransaction = aggregateTransaction.signWith(account, generationHash); return helper.announce(signedTransaction).then((transaction: AggregateTransaction) => { transaction.innerTransactions.forEach((innerTx) => { - expect((innerTx as NamespaceMetadataTransaction).targetPublicKey, 'TargetPublicKey').not.to.be.undefined; + expect((innerTx as NamespaceMetadataTransaction).targetAddress, 'TargetAddress').not.to.be.undefined; expect((innerTx as NamespaceMetadataTransaction).scopedMetadataKey, 'ScopedMetadataKey').not.to.be.undefined; expect((innerTx as NamespaceMetadataTransaction).valueSizeDelta, 'ValueSizeDelta').not.to.be.undefined; expect((innerTx as NamespaceMetadataTransaction).value, 'Value').not.to.be.undefined; diff --git a/e2e/infrastructure/UnresolvedMapping.spec.ts b/e2e/infrastructure/UnresolvedMapping.spec.ts index 3d47651421..7b61be1a73 100644 --- a/e2e/infrastructure/UnresolvedMapping.spec.ts +++ b/e2e/infrastructure/UnresolvedMapping.spec.ts @@ -168,7 +168,7 @@ describe('Unresolved Mapping', () => { it('aggregate', () => { const mosaicMetadataTransaction = MosaicMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(5), namespaceIdMosaic, 10, diff --git a/e2e/service/MetadataTransactionService.spec.ts b/e2e/service/MetadataTransactionService.spec.ts index 3fe8be134a..16fa62c13c 100644 --- a/e2e/service/MetadataTransactionService.spec.ts +++ b/e2e/service/MetadataTransactionService.spec.ts @@ -96,7 +96,7 @@ describe('MetadataTransactionService', () => { it('aggregate', () => { const mosaicMetadataTransaction = MosaicMetadataTransaction.create( Deadline.create(), - targetAccount.publicKey, + targetAccount.address, key, mosaicId, newValue.length, @@ -122,7 +122,7 @@ describe('MetadataTransactionService', () => { it('aggregate', () => { const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( Deadline.create(), - targetAccount.publicKey, + targetAccount.address, key, namespaceId, newValue.length, @@ -156,17 +156,17 @@ describe('MetadataTransactionService', () => { deadline, networkType, MetadataType.Account, - targetAccount.publicAccount, + targetAccount.address, key, newValue, - targetAccount.publicAccount, + targetAccount.address, ) .toPromise(); expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_METADATA); expect(transaction.scopedMetadataKey.toHex()).to.be.equal(key.toHex()); expect(transaction.value).to.be.equal(newValue); - expect(transaction.targetPublicKey).to.be.equal(targetAccount.publicKey); + expect(transaction.targetAddress).to.be.deep.equal(targetAccount.address); }); it('should create MosaicMetadataTransaction', async () => { @@ -177,10 +177,10 @@ describe('MetadataTransactionService', () => { deadline, networkType, MetadataType.Mosaic, - targetAccount.publicAccount, + targetAccount.address, key, updateValue, - targetAccount.publicAccount, + targetAccount.address, mosaicId, ) .toPromise()) as MosaicMetadataTransaction; @@ -190,7 +190,7 @@ describe('MetadataTransactionService', () => { expect(transaction.value).to.be.equals( Convert.decodeHex(Convert.xor(Convert.utf8ToUint8(newValue), Convert.utf8ToUint8(updateValue))), ); - expect(transaction.targetPublicKey).to.be.equal(targetAccount.publicKey); + expect(transaction.targetAddress).to.be.deep.equal(targetAccount.address); expect(transaction.targetMosaicId.toHex()).to.be.equal(mosaicId.toHex()); }); @@ -203,10 +203,10 @@ describe('MetadataTransactionService', () => { deadline, networkType, MetadataType.Namespace, - targetAccount.publicAccount, + targetAccount.address, key, updateValue, - targetAccount.publicAccount, + targetAccount.address, namespaceId, ) .toPromise()) as NamespaceMetadataTransaction; @@ -217,7 +217,7 @@ describe('MetadataTransactionService', () => { expect(transaction.value).to.be.equals( Convert.decodeHex(Convert.xor(Convert.utf8ToUint8(newValue), Convert.utf8ToUint8(updateValue))), ); - expect(transaction.targetPublicKey).to.be.equal(targetAccount.publicKey); + expect(transaction.targetAddress).to.be.deep.equal(targetAccount.address); expect(transaction.targetNamespaceId.toHex()).to.be.equal(namespaceId.toHex()); }); }); @@ -231,10 +231,10 @@ describe('MetadataTransactionService', () => { deadline, networkType, MetadataType.Mosaic, - targetAccount.publicAccount, + targetAccount.address, key, newValue + 'delta', - targetAccount.publicAccount, + targetAccount.address, mosaicId, helper.maxFee, ) @@ -260,10 +260,10 @@ describe('MetadataTransactionService', () => { deadline, networkType, MetadataType.Mosaic, - targetAccount.publicAccount, + targetAccount.address, key, newValue + 'delta' + 'extra delta', - targetAccount.publicAccount, + targetAccount.address, mosaicId, helper.maxFee, ) @@ -291,10 +291,10 @@ describe('MetadataTransactionService', () => { deadline, networkType, MetadataType.Mosaic, - targetAccount.publicAccount, + targetAccount.address, key, newValue, - targetAccount.publicAccount, + targetAccount.address, mosaicId, ) .toPromise() diff --git a/e2e/service/TransactionService.spec.ts b/e2e/service/TransactionService.spec.ts index bb3c1220c4..5cd81f506f 100644 --- a/e2e/service/TransactionService.spec.ts +++ b/e2e/service/TransactionService.spec.ts @@ -131,7 +131,7 @@ describe('TransactionService', () => { // Use new mosaicAlias in metadata const mosaicMetadataTransaction = MosaicMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(5), mosaicAlias, 10, diff --git a/e2e/service/TransactionService_AggregateBonded.spec.ts b/e2e/service/TransactionService_AggregateBonded.spec.ts index 7e4c3ec7a6..969717e3f9 100644 --- a/e2e/service/TransactionService_AggregateBonded.spec.ts +++ b/e2e/service/TransactionService_AggregateBonded.spec.ts @@ -117,7 +117,7 @@ describe('TransactionService', () => { Deadline.create(), 2, 1, - [cosignAccount1.publicAccount, cosignAccount2.publicAccount, cosignAccount3.publicAccount], + [cosignAccount1.address, cosignAccount2.address, cosignAccount3.address], [], networkType, helper.maxFee, @@ -223,7 +223,7 @@ describe('TransactionService', () => { -1, 0, [], - [cosignAccount1.publicAccount], + [cosignAccount1.address], networkType, helper.maxFee, ); @@ -232,7 +232,7 @@ describe('TransactionService', () => { 0, 0, [], - [cosignAccount2.publicAccount], + [cosignAccount2.address], networkType, helper.maxFee, ); @@ -242,7 +242,7 @@ describe('TransactionService', () => { -1, -1, [], - [cosignAccount3.publicAccount], + [cosignAccount3.address], networkType, helper.maxFee, ); diff --git a/package-lock.json b/package-lock.json index 56c923b728..776e914b13 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1307,9 +1307,9 @@ "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, "catbuffer-typescript": { - "version": "0.0.19", - "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.19.tgz", - "integrity": "sha512-EE5zoQxoSEAXDo7X7WgQWduUwoppFk1RhJvvNGNwwTeKYzB3MO+6v9vFG9jGjZSTXMV3pezVgOsqMk47nif2XQ==" + "version": "0.0.20-alpha-202006031138", + "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.20-alpha-202006031138.tgz", + "integrity": "sha512-vXyKWhirl/CyLdf2NwqFFl1p/0c3E9VQL81Hr7acr0aiKeECao/V/HKY2b33VnlxVc07f0GBC+NpAhEPX8WVXg==" }, "chai": { "version": "4.1.2", @@ -6252,9 +6252,9 @@ } }, "symbol-openapi-typescript-node-client": { - "version": "0.8.12-SNAPSHOT.202005221525", - "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-node-client/-/symbol-openapi-typescript-node-client-0.8.12-SNAPSHOT.202005221525.tgz", - "integrity": "sha512-4hoG73GnNQwznjLXrCvkZmgMcOLB+9FhT5RJ5GLH2KIfoRiqSd59MrlJ47ruNa1GHWGzAC2jsu/IWZkCh0CU0w==", + "version": "0.8.13-SNAPSHOT.202006040918", + "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-node-client/-/symbol-openapi-typescript-node-client-0.8.13-SNAPSHOT.202006040918.tgz", + "integrity": "sha512-tyPmzLkWVoRPeewgyddnjipOBLS+LDi3RpGJ4WMuthJy8iQjnv/FOqUD7lQwdagVxjfuUsrpM2vw8E0Q5pmVww==", "requires": { "@types/bluebird": "*", "@types/request": "*", diff --git a/package.json b/package.json index fe7b4c4080..231206a90c 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ }, "dependencies": { "bluebird": "^3.7.2", - "catbuffer-typescript": "0.0.19", + "catbuffer-typescript": "0.0.20-alpha-202006031138", "crypto-js": "^4.0.0", "diff": "^4.0.2", "futoin-hkdf": "^1.3.1", @@ -89,7 +89,7 @@ "ripemd160": "^2.0.2", "rxjs": "^6.5.3", "rxjs-compat": "^6.5.3", - "symbol-openapi-typescript-node-client": "0.8.12-SNAPSHOT.202005221525", + "symbol-openapi-typescript-node-client": "0.8.13-SNAPSHOT.202006040918", "tweetnacl": "^1.0.3", "utf8": "^3.0.0", "ws": "^7.2.3" diff --git a/src/core/format/RawAddress.ts b/src/core/format/RawAddress.ts index 8d701872a3..65b2586634 100644 --- a/src/core/format/RawAddress.ts +++ b/src/core/format/RawAddress.ts @@ -50,11 +50,11 @@ export class RawAddress { * @returns {Uint8Array} The padded notation of the alias */ public static aliasToRecipient = (namespaceId: Uint8Array, networkType: NetworkType): Uint8Array => { - // 0x91 | namespaceId on 8 bytes | 16 bytes 0-pad = 25 bytes - const padded = new Uint8Array(1 + 8 + 16); + // 0x91 | namespaceId on 8 bytes | 15 bytes 0-pad = 24 bytes + const padded = new Uint8Array(1 + 8 + 15); padded.set([networkType.valueOf() | 0x01], 0); padded.set(namespaceId.reverse(), 1); - padded.set(Convert.hexToUint8('00'.repeat(16)), 9); + padded.set(Convert.hexToUint8('00'.repeat(15)), 9); return padded; }; diff --git a/src/infrastructure/BlockHttp.ts b/src/infrastructure/BlockHttp.ts index e9a6cd9cb5..705cd48a68 100644 --- a/src/infrastructure/BlockHttp.ts +++ b/src/infrastructure/BlockHttp.ts @@ -25,6 +25,7 @@ import { BlockRepository } from './BlockRepository'; import { Http } from './Http'; import { BlockSearchCriteria } from './searchCriteria/BlockSearchCriteria'; import { Page } from './Page'; +import { Address } from '../model/account/Address'; /** * Blockchain http repository. @@ -66,7 +67,7 @@ export class BlockHttp extends Http implements BlockRepository { return this.call( this.blockRoutesApi.searchBlocks( criteria.signerPublicKey, - criteria.beneficiaryPublicKey, + criteria.beneficiaryAddress, criteria.pageSize, criteria.pageNumber, criteria.offset, @@ -109,7 +110,7 @@ export class BlockHttp extends Http implements BlockRepository { dto.block.proofGamma, dto.block.proofScalar, dto.block.proofVerificationHash, - dto.block.beneficiaryPublicKey ? PublicAccount.createFromPublicKey(dto.block.beneficiaryPublicKey, networkType) : undefined, + dto.block.beneficiaryAddress ? Address.createFromEncoded(dto.block.beneficiaryAddress) : undefined, dto.meta.numStatements, ); } diff --git a/src/infrastructure/Listener.ts b/src/infrastructure/Listener.ts index 06396bea58..bb34121903 100644 --- a/src/infrastructure/Listener.ts +++ b/src/infrastructure/Listener.ts @@ -436,7 +436,7 @@ export class Listener implements IListener { dto.block.proofGamma, dto.block.proofScalar, dto.block.proofVerificationHash, - dto.block.beneficiaryPublicKey ? PublicAccount.createFromPublicKey(dto.block.beneficiaryPublicKey, networkType) : undefined, + dto.block.beneficiaryAddress ? Address.createFromEncoded(dto.block.beneficiaryAddress) : undefined, ); } } diff --git a/src/infrastructure/MetadataHttp.ts b/src/infrastructure/MetadataHttp.ts index 1d01cb60e0..b169afdafa 100644 --- a/src/infrastructure/MetadataHttp.ts +++ b/src/infrastructure/MetadataHttp.ts @@ -84,11 +84,11 @@ export class MetadataHttp extends Http implements MetadataRepository { * Returns the account metadata given an account id and a key * @param address - Account address to be created from PublicKey or RawAddress * @param key - Metadata key - * @param publicKey - Sender public key + * @param sourceAddress - Sender address * @returns Observable */ - getAccountMetadataByKeyAndSender(address: Address, key: string, publicKey: string): Observable { - return this.call(this.metadataRoutesApi.getAccountMetadataByKeyAndSender(address.plain(), key, publicKey), (body) => + getAccountMetadataByKeyAndSender(address: Address, key: string, sourceAddress: Address): Observable { + return this.call(this.metadataRoutesApi.getAccountMetadataByKeyAndSender(address.plain(), key, sourceAddress.plain()), (body) => this.buildMetadata(body), ); } @@ -127,11 +127,14 @@ export class MetadataHttp extends Http implements MetadataRepository { * Returns the mosaic metadata given a mosaic id and metadata key. * @param mosaicId - Mosaic identifier. * @param key - Metadata key. - * @param publicKey - Sender public key + * @param sourceAddress - Sender address * @returns Observable */ - getMosaicMetadataByKeyAndSender(mosaicId: MosaicId, key: string, publicKey: string): Observable { - return this.call(this.metadataRoutesApi.getMosaicMetadataByKeyAndSender(mosaicId.toHex(), key, publicKey), this.buildMetadata); + getMosaicMetadataByKeyAndSender(mosaicId: MosaicId, key: string, sourceAddress: Address): Observable { + return this.call( + this.metadataRoutesApi.getMosaicMetadataByKeyAndSender(mosaicId.toHex(), key, sourceAddress.plain()), + this.buildMetadata, + ); } /** @@ -168,12 +171,12 @@ export class MetadataHttp extends Http implements MetadataRepository { * Returns the namespace metadata given a mosaic id and metadata key. * @param namespaceId - Namespace identifier. * @param key - Metadata key. - * @param publicKey - Sender public key + * @param sourceAddress - Sender address * @returns Observable */ - public getNamespaceMetadataByKeyAndSender(namespaceId: NamespaceId, key: string, publicKey: string): Observable { + public getNamespaceMetadataByKeyAndSender(namespaceId: NamespaceId, key: string, sourceAddress: Address): Observable { return this.call( - this.metadataRoutesApi.getNamespaceMetadataByKeyAndSender(namespaceId.toHex(), key, publicKey), + this.metadataRoutesApi.getNamespaceMetadataByKeyAndSender(namespaceId.toHex(), key, sourceAddress.plain()), this.buildMetadata, ); } @@ -201,8 +204,8 @@ export class MetadataHttp extends Http implements MetadataRepository { metadata.id, new MetadataEntry( metadataEntry.compositeHash, - metadataEntry.senderPublicKey, - metadataEntry.targetPublicKey, + Address.createFromEncoded(metadataEntry.sourceAddress), + Address.createFromEncoded(metadataEntry.targetAddress), UInt64.fromHex(metadataEntry.scopedMetadataKey), metadataEntry.metadataType.valueOf(), Convert.decodeHex(metadataEntry.value), diff --git a/src/infrastructure/MetadataRepository.ts b/src/infrastructure/MetadataRepository.ts index 734f9f187b..06cdb740b6 100644 --- a/src/infrastructure/MetadataRepository.ts +++ b/src/infrastructure/MetadataRepository.ts @@ -47,10 +47,10 @@ export interface MetadataRepository { * Returns the account metadata given an account id and a key * @param address - Account address to be created from PublicKey or RawAddress * @param key - Metadata key - * @param publicKey - Sender public key + * @param sourceAddress - Sender address * @returns Observable */ - getAccountMetadataByKeyAndSender(address: Address, key: string, publicKey: string): Observable; + getAccountMetadataByKeyAndSender(address: Address, key: string, sourceAddress: Address): Observable; /** * Returns the mosaic metadata given a mosaic id. @@ -72,10 +72,10 @@ export interface MetadataRepository { * Returns the mosaic metadata given a mosaic id and metadata key. * @param mosaicId - Mosaic identifier. * @param key - Metadata key. - * @param publicKey - Sender public key + * @param sourceAddress - Sender address * @returns Observable */ - getMosaicMetadataByKeyAndSender(mosaicId: MosaicId, key: string, publicKey: string): Observable; + getMosaicMetadataByKeyAndSender(mosaicId: MosaicId, key: string, sourceAddress: Address): Observable; /** * Returns the mosaic metadata given a mosaic id. @@ -97,8 +97,8 @@ export interface MetadataRepository { * Returns the namespace metadata given a mosaic id and metadata key. * @param namespaceId - Namespace identifier. * @param key - Metadata key. - * @param publicKey - Sender public key + * @param sourceAddress - Sender address * @returns Observable */ - getNamespaceMetadataByKeyAndSender(namespaceId: NamespaceId, key: string, publicKey: string): Observable; + getNamespaceMetadataByKeyAndSender(namespaceId: NamespaceId, key: string, sourceAddress: Address): Observable; } diff --git a/src/infrastructure/MosaicHttp.ts b/src/infrastructure/MosaicHttp.ts index cf6b668d14..c973bd6c3e 100644 --- a/src/infrastructure/MosaicHttp.ts +++ b/src/infrastructure/MosaicHttp.ts @@ -16,7 +16,6 @@ import { Observable } from 'rxjs'; import { mergeMap } from 'rxjs/operators'; -import { PublicAccount } from '../model/account/PublicAccount'; import { MosaicFlags } from '../model/mosaic/MosaicFlags'; import { MosaicId } from '../model/mosaic/MosaicId'; import { MosaicInfo } from '../model/mosaic/MosaicInfo'; @@ -27,6 +26,7 @@ import { MosaicRepository } from './MosaicRepository'; import { MosaicSearchCriteria } from './searchCriteria/MosaicSearchCriteria'; import { Page } from './Page'; import { MosaicRoutesApi, MosaicIds, MosaicInfoDTO } from 'symbol-openapi-typescript-node-client'; +import { Address } from '../model/account/Address'; /** * Mosaic http repository. @@ -63,11 +63,7 @@ export class MosaicHttp extends Http implements MosaicRepository { * @returns Observable */ public getMosaic(mosaicId: MosaicId): Observable { - return this.networkTypeObservable.pipe( - mergeMap((networkType) => - this.call(this.mosaicRoutesApi.getMosaic(mosaicId.toHex()), (body) => this.toMosaicInfo(body, networkType)), - ), - ); + return this.call(this.mosaicRoutesApi.getMosaic(mosaicId.toHex()), (body) => this.toMosaicInfo(body)); } /** @@ -78,11 +74,7 @@ export class MosaicHttp extends Http implements MosaicRepository { public getMosaics(mosaicIds: MosaicId[]): Observable { const ids = new MosaicIds(); ids.mosaicIds = mosaicIds.map((id) => id.toHex()); - return this.networkTypeObservable.pipe( - mergeMap((networkType) => - this.call(this.mosaicRoutesApi.getMosaics(ids), (body) => body.map((b) => this.toMosaicInfo(b, networkType))), - ), - ); + return this.call(this.mosaicRoutesApi.getMosaics(ids), (body) => body.map((b) => this.toMosaicInfo(b))); } /** @@ -114,13 +106,13 @@ export class MosaicHttp extends Http implements MosaicRepository { * @param mosaicInfo the dto object. * @returns the model object */ - private toMosaicInfo(mosaicInfo: MosaicInfoDTO, networkType: NetworkType): MosaicInfo { + private toMosaicInfo(mosaicInfo: MosaicInfoDTO): MosaicInfo { return new MosaicInfo( mosaicInfo.id, new MosaicId(mosaicInfo.mosaic.id), UInt64.fromNumericString(mosaicInfo.mosaic.supply), UInt64.fromNumericString(mosaicInfo.mosaic.startHeight), - PublicAccount.createFromPublicKey(mosaicInfo.mosaic.ownerPublicKey, networkType), + Address.createFromEncoded(mosaicInfo.mosaic.ownerAddress), mosaicInfo.mosaic.revision, new MosaicFlags(mosaicInfo.mosaic.flags), mosaicInfo.mosaic.divisibility, diff --git a/src/infrastructure/MultisigHttp.ts b/src/infrastructure/MultisigHttp.ts index c08ed01981..063efa824f 100644 --- a/src/infrastructure/MultisigHttp.ts +++ b/src/infrastructure/MultisigHttp.ts @@ -15,13 +15,10 @@ */ import { Observable } from 'rxjs'; -import { mergeMap } from 'rxjs/operators'; import { MultisigAccountInfoDTO, MultisigRoutesApi } from 'symbol-openapi-typescript-node-client'; import { Address } from '../model/account/Address'; import { MultisigAccountGraphInfo } from '../model/account/MultisigAccountGraphInfo'; import { MultisigAccountInfo } from '../model/account/MultisigAccountInfo'; -import { PublicAccount } from '../model/account/PublicAccount'; -import { NetworkType } from '../model/network/NetworkType'; import { Http } from './Http'; import { MultisigRepository } from './MultisigRepository'; @@ -36,21 +33,14 @@ export class MultisigHttp extends Http implements MultisigRepository { * Symbol openapi typescript-node client account routes api */ private readonly multisigRoutesApi: MultisigRoutesApi; - /** - * @internal - * network type for the mappings. - */ - private readonly networkTypeObservable: Observable; /** * Constructor * @param url - * @param networkType */ - constructor(url: string, networkType?: NetworkType | Observable) { + constructor(url: string) { super(url); this.multisigRoutesApi = new MultisigRoutesApi(url); - this.networkTypeObservable = this.createNetworkTypeObservable(networkType); this.multisigRoutesApi.useQuerystring = true; } @@ -60,13 +50,7 @@ export class MultisigHttp extends Http implements MultisigRepository { * @returns Observable */ public getMultisigAccountInfo(address: Address): Observable { - return this.networkTypeObservable.pipe( - mergeMap((networkType) => - this.call(this.multisigRoutesApi.getAccountMultisig(address.plain()), (body) => - this.toMultisigAccountInfo(body, networkType), - ), - ), - ); + return this.call(this.multisigRoutesApi.getAccountMultisig(address.plain()), (body) => this.toMultisigAccountInfo(body)); } /** @@ -75,37 +59,32 @@ export class MultisigHttp extends Http implements MultisigRepository { * @returns Observable */ public getMultisigAccountGraphInfo(address: Address): Observable { - return this.networkTypeObservable.pipe( - mergeMap((networkType) => - this.call(this.multisigRoutesApi.getAccountMultisigGraph(address.plain()), (body) => { - const multisigAccountGraphInfosDTO = body; - const multisigAccounts = new Map(); - multisigAccountGraphInfosDTO.map((multisigAccountGraphInfoDTO) => { - multisigAccounts.set( - multisigAccountGraphInfoDTO.level, - multisigAccountGraphInfoDTO.multisigEntries.map((multisigAccountInfoDTO) => { - return this.toMultisigAccountInfo(multisigAccountInfoDTO, networkType); - }), - ); - }); - return new MultisigAccountGraphInfo(multisigAccounts); - }), - ), - ); + return this.call(this.multisigRoutesApi.getAccountMultisigGraph(address.plain()), (body) => { + const multisigAccountGraphInfosDTO = body; + const multisigAccounts = new Map(); + multisigAccountGraphInfosDTO.map((multisigAccountGraphInfoDTO) => { + multisigAccounts.set( + multisigAccountGraphInfoDTO.level, + multisigAccountGraphInfoDTO.multisigEntries.map((multisigAccountInfoDTO) => { + return this.toMultisigAccountInfo(multisigAccountInfoDTO); + }), + ); + }); + return new MultisigAccountGraphInfo(multisigAccounts); + }); } /** * It maps from MultisigAccountInfoDTO to MultisigAccountInfo * @param dto the DTO - * @param networkType the network type */ - private toMultisigAccountInfo(dto: MultisigAccountInfoDTO, networkType: NetworkType): MultisigAccountInfo { + private toMultisigAccountInfo(dto: MultisigAccountInfoDTO): MultisigAccountInfo { return new MultisigAccountInfo( - PublicAccount.createFromPublicKey(dto.multisig.accountPublicKey, networkType), + Address.createFromEncoded(dto.multisig.accountAddress), dto.multisig.minApproval, dto.multisig.minRemoval, - dto.multisig.cosignatoryPublicKeys.map((cosigner) => PublicAccount.createFromPublicKey(cosigner, networkType)), - dto.multisig.multisigPublicKeys.map((multisigAccount) => PublicAccount.createFromPublicKey(multisigAccount, networkType)), + dto.multisig.cosignatoryAddresses.map((cosigner) => Address.createFromEncoded(cosigner)), + dto.multisig.multisigAddresses.map((multisig) => Address.createFromEncoded(multisig)), ); } } diff --git a/src/infrastructure/NamespaceHttp.ts b/src/infrastructure/NamespaceHttp.ts index 288ef9cd01..4e854689dc 100644 --- a/src/infrastructure/NamespaceHttp.ts +++ b/src/infrastructure/NamespaceHttp.ts @@ -19,7 +19,6 @@ import { NamespaceDTO, NamespaceInfoDTO, NamespaceRoutesApi } from 'symbol-opena import { Convert as convert, RawAddress as AddressLibrary } from '../core/format'; import { AccountNames } from '../model/account/AccountNames'; import { Address } from '../model/account/Address'; -import { PublicAccount } from '../model/account/PublicAccount'; import { MosaicId } from '../model/mosaic/MosaicId'; import { MosaicNames } from '../model/mosaic/MosaicNames'; import { AddressAlias } from '../model/namespace/AddressAlias'; @@ -117,11 +116,7 @@ export class NamespaceHttp extends Http implements NamespaceRepository { * @returns Observable */ public getNamespace(namespaceId: NamespaceId): Observable { - return this.networkTypeObservable.pipe( - mergeMap((networkType) => - this.call(this.namespaceRoutesApi.getNamespace(namespaceId.toHex()), (body) => this.toNamespaceInfo(body, networkType)), - ), - ); + return this.call(this.namespaceRoutesApi.getNamespace(namespaceId.toHex()), (body) => this.toNamespaceInfo(body)); } /** @@ -131,18 +126,14 @@ export class NamespaceHttp extends Http implements NamespaceRepository { * @returns Observable */ public getNamespacesFromAccount(address: Address, queryParams?: QueryParams): Observable { - return this.networkTypeObservable.pipe( - mergeMap((networkType) => - this.call( - this.namespaceRoutesApi.getNamespacesFromAccount( - address.plain(), - this.queryParams(queryParams).pageSize, - this.queryParams(queryParams).id, - this.queryParams(queryParams).ordering, - ), - (body) => body.namespaces.map((namespaceInfoDTO) => this.toNamespaceInfo(namespaceInfoDTO, networkType)), - ), + return this.call( + this.namespaceRoutesApi.getNamespacesFromAccount( + address.plain(), + this.queryParams(queryParams).pageSize, + this.queryParams(queryParams).id, + this.queryParams(queryParams).ordering, ), + (body) => body.namespaces.map((namespaceInfoDTO) => this.toNamespaceInfo(namespaceInfoDTO)), ); } @@ -156,12 +147,8 @@ export class NamespaceHttp extends Http implements NamespaceRepository { const publicKeysBody = { addresses: addresses.map((address) => address.plain()), }; - return this.networkTypeObservable.pipe( - mergeMap((networkType) => - this.call(this.namespaceRoutesApi.getNamespacesFromAccounts(publicKeysBody), (body) => - body.namespaces.map((namespaceInfoDTO) => this.toNamespaceInfo(namespaceInfoDTO, networkType)), - ), - ), + return this.call(this.namespaceRoutesApi.getNamespacesFromAccounts(publicKeysBody), (body) => + body.namespaces.map((namespaceInfoDTO) => this.toNamespaceInfo(namespaceInfoDTO)), ); } @@ -245,9 +232,8 @@ export class NamespaceHttp extends Http implements NamespaceRepository { /** * It maps from a NamespaceInfoDTO to NamespaceInfo * @param dto the dto - * @param networkType the network type */ - private toNamespaceInfo(dto: NamespaceInfoDTO, networkType: NetworkType): NamespaceInfo { + private toNamespaceInfo(dto: NamespaceInfoDTO): NamespaceInfo { return new NamespaceInfo( dto.meta.active, dto.meta.index, @@ -256,7 +242,7 @@ export class NamespaceHttp extends Http implements NamespaceRepository { dto.namespace.depth, this.extractLevels(dto.namespace), NamespaceId.createFromEncoded(dto.namespace.parentId), - PublicAccount.createFromPublicKey(dto.namespace.ownerPublicKey, networkType), + Address.createFromEncoded(dto.namespace.ownerAddress), UInt64.fromNumericString(dto.namespace.startHeight), UInt64.fromNumericString(dto.namespace.endHeight), this.extractAlias(dto.namespace), diff --git a/src/infrastructure/ReceiptHttp.ts b/src/infrastructure/ReceiptHttp.ts index 837850ed8b..7ad45680b3 100644 --- a/src/infrastructure/ReceiptHttp.ts +++ b/src/infrastructure/ReceiptHttp.ts @@ -15,7 +15,7 @@ */ import { from as observableFrom, Observable, throwError } from 'rxjs'; -import { catchError, map, mergeMap } from 'rxjs/operators'; +import { catchError, map } from 'rxjs/operators'; import { ReceiptRoutesApi } from 'symbol-openapi-typescript-node-client'; import { MerklePathItem } from '../model/blockchain/MerklePathItem'; import { MerkleProofInfo } from '../model/blockchain/MerkleProofInfo'; @@ -80,13 +80,9 @@ export class ReceiptHttp extends Http implements ReceiptRepository { * @returns Observable */ public getBlockReceipts(height: UInt64): Observable { - return this.networkTypeObservable.pipe( - mergeMap((networkType) => - observableFrom(this.receiptRoutesApi.getBlockReceipts(height.toString())).pipe( - map(({ body }) => CreateStatementFromDTO(body, networkType)), - catchError((error) => throwError(this.errorHandling(error))), - ), - ), + return observableFrom(this.receiptRoutesApi.getBlockReceipts(height.toString())).pipe( + map(({ body }) => CreateStatementFromDTO(body)), + catchError((error) => throwError(this.errorHandling(error))), ); } } diff --git a/src/infrastructure/RepositoryFactoryHttp.ts b/src/infrastructure/RepositoryFactoryHttp.ts index d90bd48100..1dca30a4bb 100644 --- a/src/infrastructure/RepositoryFactoryHttp.ts +++ b/src/infrastructure/RepositoryFactoryHttp.ts @@ -100,7 +100,7 @@ export class RepositoryFactoryHttp implements RepositoryFactory { } createMultisigRepository(): MultisigRepository { - return new MultisigHttp(this.url, this.networkType); + return new MultisigHttp(this.url); } createNamespaceRepository(): NamespaceRepository { diff --git a/src/infrastructure/receipt/CreateReceiptFromDTO.ts b/src/infrastructure/receipt/CreateReceiptFromDTO.ts index 0129f6e026..395144c492 100644 --- a/src/infrastructure/receipt/CreateReceiptFromDTO.ts +++ b/src/infrastructure/receipt/CreateReceiptFromDTO.ts @@ -16,7 +16,6 @@ import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping'; import { Address } from '../../model/account/Address'; -import { PublicAccount } from '../../model/account/PublicAccount'; import { MosaicId } from '../../model/mosaic/MosaicId'; import { NamespaceId } from '../../model/namespace/NamespaceId'; import { ArtifactExpiryReceipt } from '../../model/receipt/ArtifactExpiryReceipt'; @@ -93,13 +92,12 @@ const createResolutionStatement = (statementDTO, resolutionType): ResolutionStat /** * @internal * @param receiptDTO - * @param networkType * @returns {BalanceChangeReceipt} * @constructor */ -const createBalanceChangeReceipt = (receiptDTO, networkType): Receipt => { +const createBalanceChangeReceipt = (receiptDTO): Receipt => { return new BalanceChangeReceipt( - PublicAccount.createFromPublicKey(receiptDTO.targetPublicKey, networkType), + Address.createFromEncoded(receiptDTO.targetAddress), new MosaicId(receiptDTO.mosaicId), UInt64.fromNumericString(receiptDTO.amount), receiptDTO.version, @@ -110,13 +108,12 @@ const createBalanceChangeReceipt = (receiptDTO, networkType): Receipt => { /** * @internal * @param receiptDTO - * @param networkType * @returns {BalanceTransferReceipt} * @constructor */ -const createBalanceTransferReceipt = (receiptDTO, networkType): Receipt => { +const createBalanceTransferReceipt = (receiptDTO): Receipt => { return new BalanceTransferReceipt( - PublicAccount.createFromPublicKey(receiptDTO.senderPublicKey, networkType), + Address.createFromEncoded(receiptDTO.senderAddress), Address.createFromEncoded(receiptDTO.recipientAddress), new MosaicId(receiptDTO.mosaicId), UInt64.fromNumericString(receiptDTO.amount), @@ -170,11 +167,10 @@ const createInflationReceipt = (receiptDTO): Receipt => { /** * @param receiptDTO - * @param networkType * @returns {Receipt} * @constructor */ -export const CreateReceiptFromDTO = (receiptDTO, networkType): Receipt => { +export const CreateReceiptFromDTO = (receiptDTO): Receipt => { switch (receiptDTO.type) { case ReceiptType.Harvest_Fee: case ReceiptType.LockHash_Created: @@ -183,11 +179,11 @@ export const CreateReceiptFromDTO = (receiptDTO, networkType): Receipt => { case ReceiptType.LockSecret_Created: case ReceiptType.LockSecret_Completed: case ReceiptType.LockSecret_Expired: - return createBalanceChangeReceipt(receiptDTO, networkType); + return createBalanceChangeReceipt(receiptDTO); case ReceiptType.Mosaic_Levy: case ReceiptType.Mosaic_Rental_Fee: case ReceiptType.Namespace_Rental_Fee: - return createBalanceTransferReceipt(receiptDTO, networkType); + return createBalanceTransferReceipt(receiptDTO); case ReceiptType.Mosaic_Expired: case ReceiptType.Namespace_Expired: case ReceiptType.Namespace_Deleted: @@ -202,31 +198,29 @@ export const CreateReceiptFromDTO = (receiptDTO, networkType): Receipt => { /** * @internal * @param statementDTO - * @param networkType * @returns {TransactionStatement} * @constructor */ -const createTransactionStatement = (statementDTO, networkType): TransactionStatement => { +const createTransactionStatement = (statementDTO): TransactionStatement => { return new TransactionStatement( UInt64.fromNumericString(statementDTO.height), new ReceiptSource(statementDTO.source.primaryId, statementDTO.source.secondaryId), statementDTO.receipts.map((receipt) => { - return CreateReceiptFromDTO(receipt, networkType); + return CreateReceiptFromDTO(receipt); }), ); }; /** * @param receiptDTO - * @param networkType * @returns {Statement} * @see https://github.com/nemtech/catapult-server/blob/master/src/catapult/model/ReceiptType.h * @see https://github.com/nemtech/catapult-server/blob/master/src/catapult/model/ReceiptType.cpp * @constructor */ -export const CreateStatementFromDTO = (receiptDTO, networkType): Statement => { +export const CreateStatementFromDTO = (receiptDTO): Statement => { return new Statement( - receiptDTO.transactionStatements.map((statement) => createTransactionStatement(statement.statement, networkType)), + receiptDTO.transactionStatements.map((statement) => createTransactionStatement(statement.statement)), receiptDTO.addressResolutionStatements.map((statement) => createResolutionStatement(statement.statement, ResolutionType.Address)), receiptDTO.mosaicResolutionStatements.map((statement) => createResolutionStatement(statement.statement, ResolutionType.Mosaic)), ); diff --git a/src/infrastructure/searchCriteria/BlockSearchCriteria.ts b/src/infrastructure/searchCriteria/BlockSearchCriteria.ts index 1148ad6fc3..ee7945235a 100644 --- a/src/infrastructure/searchCriteria/BlockSearchCriteria.ts +++ b/src/infrastructure/searchCriteria/BlockSearchCriteria.ts @@ -30,7 +30,7 @@ export interface BlockSearchCriteria extends SearchCriteria { /** * beneficiary public key. (optional) */ - beneficiaryPublicKey?: string; + beneficiaryAddress?: string; /** * Order by block id or height. (optional) diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index 8830b63a2d..eecd9adeba 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -225,12 +225,8 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr UInt64.fromNumericString(transactionDTO.maxFee || '0'), transactionDTO.minApprovalDelta, transactionDTO.minRemovalDelta, - transactionDTO.publicKeyAdditions - ? transactionDTO.publicKeyAdditions.map((addition) => PublicAccount.createFromPublicKey(addition, transactionDTO.network)) - : [], - transactionDTO.publicKeyDeletions - ? transactionDTO.publicKeyDeletions.map((deletion) => PublicAccount.createFromPublicKey(deletion, transactionDTO.network)) - : [], + transactionDTO.addressAdditions ? transactionDTO.addressAdditions.map((addition) => extractRecipient(addition)) : [], + transactionDTO.addressDeletions ? transactionDTO.addressDeletions.map((deletion) => extractRecipient(deletion)) : [], transactionDTO.signature, transactionDTO.signerPublicKey ? PublicAccount.createFromPublicKey(transactionDTO.signerPublicKey, transactionDTO.network) @@ -422,7 +418,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr transactionDTO.version, Deadline.createFromDTO(transactionDTO.deadline), UInt64.fromNumericString(transactionDTO.maxFee || '0'), - transactionDTO.targetPublicKey, + extractRecipient(transactionDTO.targetAddress), UInt64.fromHex(transactionDTO.scopedMetadataKey), transactionDTO.valueSizeDelta, convert.decodeHex(transactionDTO.value), @@ -438,7 +434,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr transactionDTO.version, Deadline.createFromDTO(transactionDTO.deadline), UInt64.fromNumericString(transactionDTO.maxFee || '0'), - transactionDTO.targetPublicKey, + extractRecipient(transactionDTO.targetAddress), UInt64.fromHex(transactionDTO.scopedMetadataKey), UnresolvedMapping.toUnresolvedMosaic(transactionDTO.targetMosaicId), transactionDTO.valueSizeDelta, @@ -455,7 +451,7 @@ const CreateStandaloneTransactionFromDTO = (transactionDTO, transactionInfo): Tr transactionDTO.version, Deadline.createFromDTO(transactionDTO.deadline), UInt64.fromNumericString(transactionDTO.maxFee || '0'), - transactionDTO.targetPublicKey, + extractRecipient(transactionDTO.targetAddress), UInt64.fromHex(transactionDTO.scopedMetadataKey), NamespaceId.createFromEncoded(transactionDTO.targetNamespaceId), transactionDTO.valueSizeDelta, @@ -542,6 +538,7 @@ export const CreateTransactionFromDTO = (transactionDTO): Transaction => { transactionDTO.transaction.cosignatures ? transactionDTO.transaction.cosignatures.map((aggregateCosignatureDTO) => { return new AggregateTransactionCosignature( + UInt64.fromNumericString(aggregateCosignatureDTO.version), aggregateCosignatureDTO.signature, PublicAccount.createFromPublicKey(aggregateCosignatureDTO.signerPublicKey, transactionDTO.transaction.network), ); diff --git a/src/infrastructure/transaction/CreateTransactionFromPayload.ts b/src/infrastructure/transaction/CreateTransactionFromPayload.ts index e3dcbc0069..603b8332a9 100644 --- a/src/infrastructure/transaction/CreateTransactionFromPayload.ts +++ b/src/infrastructure/transaction/CreateTransactionFromPayload.ts @@ -16,7 +16,6 @@ import { EmbeddedTransactionBuilder, TransactionBuilder } from 'catbuffer-typescript'; import { Convert as convert } from '../../core/format'; -import { InnerTransaction } from '../../model/model'; import { AccountAddressRestrictionTransaction } from '../../model/transaction/AccountAddressRestrictionTransaction'; import { AccountKeyLinkTransaction } from '../../model/transaction/AccountKeyLinkTransaction'; import { AccountMetadataTransaction } from '../../model/transaction/AccountMetadataTransaction'; @@ -42,6 +41,7 @@ import { TransferTransaction } from '../../model/transaction/TransferTransaction import { VrfKeyLinkTransaction } from '../../model/transaction/VrfKeyLinkTransaction'; import { VotingKeyLinkTransaction } from '../../model/transaction/VotingKeyLinkTransaction'; import { NodeKeyLinkTransaction } from '../../model/transaction/NodeKeyLinkTransaction'; +import { InnerTransaction } from '../../model/transaction/InnerTransaction'; /** * @internal diff --git a/src/infrastructure/transaction/SerializeTransactionToJSON.ts b/src/infrastructure/transaction/SerializeTransactionToJSON.ts index a93d797f1a..a824417044 100644 --- a/src/infrastructure/transaction/SerializeTransactionToJSON.ts +++ b/src/infrastructure/transaction/SerializeTransactionToJSON.ts @@ -125,11 +125,11 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => { return { minApprovalDelta: multisigTx.minApprovalDelta, minRemovalDelta: multisigTx.minRemovalDelta, - publicKeyAdditions: multisigTx.publicKeyAdditions.map((addition) => { - return addition.publicKey; + addressAdditions: multisigTx.addressAdditions.map((addition) => { + return addition.toDTO(); }), - publicKeyDeletions: multisigTx.publicKeyDeletions.map((deletion) => { - return deletion.publicKey; + addressDeletions: multisigTx.addressDeletions.map((deletion) => { + return deletion.toDTO(); }), }; case TransactionType.MOSAIC_ALIAS: @@ -227,7 +227,7 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => { case TransactionType.ACCOUNT_METADATA: const accountMetadataTx = transaction as AccountMetadataTransaction; return { - targetPublicKey: accountMetadataTx.targetPublicKey, + targetAddress: accountMetadataTx.targetAddress, scopedMetadataKey: accountMetadataTx.scopedMetadataKey.toHex(), valueSizeDelta: accountMetadataTx.valueSizeDelta, valueSize: accountMetadataTx.value.length, @@ -236,7 +236,7 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => { case TransactionType.MOSAIC_METADATA: const mosaicMetadataTx = transaction as MosaicMetadataTransaction; return { - targetPublicKey: mosaicMetadataTx.targetPublicKey, + targetAddress: mosaicMetadataTx.targetAddress, scopedMetadataKey: mosaicMetadataTx.scopedMetadataKey.toHex(), valueSizeDelta: mosaicMetadataTx.valueSizeDelta, targetMosaicId: mosaicMetadataTx.targetMosaicId.id.toHex(), @@ -246,7 +246,7 @@ export const SerializeTransactionToJSON = (transaction: Transaction): any => { case TransactionType.NAMESPACE_METADATA: const namespaceMetaTx = transaction as NamespaceMetadataTransaction; return { - targetPublicKey: namespaceMetaTx.targetPublicKey, + targetAddress: namespaceMetaTx.targetAddress, scopedMetadataKey: namespaceMetaTx.scopedMetadataKey.toHex(), valueSizeDelta: namespaceMetaTx.valueSizeDelta, targetNamespaceId: namespaceMetaTx.targetNamespaceId.id.toHex(), diff --git a/src/model/account/Address.ts b/src/model/account/Address.ts index 678857128d..9a318495b0 100644 --- a/src/model/account/Address.ts +++ b/src/model/account/Address.ts @@ -82,7 +82,7 @@ export class Address { /** * Determines the validity of an encoded address string. - * @param {string} encoded The encoded address string. Expected format: 9085215E4620D383C2DF70235B9EF7607F6A28EF6D16FD7B9C + * @param {string} encoded The encoded address string. Expected format: 6823BB7C3C089D996585466380EDBDC19D4959184893E38C * @returns {boolean} true if the encoded address string is valid, false otherwise. */ public static isValidEncodedAddress = (encoded: string): boolean => { @@ -135,11 +135,14 @@ export class Address { /** * Compares addresses for equality - * @param address - Address + * @param address - Address to compare * @returns {boolean} */ - public equals(address: Address): boolean { - return this.plain() === address.plain() && this.networkType === address.networkType; + public equals(address: any): boolean { + if (address instanceof Address) { + return this.plain() === address.plain() && this.networkType === address.networkType; + } + return false; } /** @@ -151,4 +154,14 @@ export class Address { networkType: this.networkType, }; } + + /** + * Encoded address or namespace id. Note that namespace id get the hex reversed and + * zero padded. + * @returns {Uint8Array} + */ + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public encodeUnresolvedAddress(networkType: NetworkType): Uint8Array { + return Convert.hexToUint8(this.encoded()); + } } diff --git a/src/model/account/MultisigAccountGraphInfo.ts b/src/model/account/MultisigAccountGraphInfo.ts index 89b596bdf7..52d7bbd1e0 100644 --- a/src/model/account/MultisigAccountGraphInfo.ts +++ b/src/model/account/MultisigAccountGraphInfo.ts @@ -21,12 +21,12 @@ import { MultisigAccountInfo } from './MultisigAccountInfo'; */ export class MultisigAccountGraphInfo { /** - * @param multisigAccounts + * @param multisigEntries */ constructor( /** * The multisig accounts. */ - public readonly multisigAccounts: Map, + public readonly multisigEntries: Map, ) {} } diff --git a/src/model/account/MultisigAccountInfo.ts b/src/model/account/MultisigAccountInfo.ts index 9847fbc822..2e20041fc6 100644 --- a/src/model/account/MultisigAccountInfo.ts +++ b/src/model/account/MultisigAccountInfo.ts @@ -14,24 +14,24 @@ * limitations under the License. */ -import { PublicAccount } from './PublicAccount'; +import { Address } from './Address'; /** * The multisig account graph info structure describes the information of all the mutlisig levels an account is involved in. */ export class MultisigAccountInfo { /** - * @param account + * @param accountAddress * @param minApproval * @param minRemoval - * @param cosignatories - * @param multisigAccounts + * @param cosignatoryAddresses + * @param multisigAddresses */ constructor( /** - * The account multisig public account. + * The account multisig address. */ - public readonly account: PublicAccount, + public readonly accountAddress: Address, /** * The number of signatures needed to approve a transaction. */ @@ -43,11 +43,11 @@ export class MultisigAccountInfo { /** * The multisig account cosignatories. */ - public readonly cosignatories: PublicAccount[], + public readonly cosignatoryAddresses: Address[], /** * The multisig accounts this account is cosigner of. */ - public readonly multisigAccounts: PublicAccount[], + public readonly multisigAddresses: Address[], ) {} /** @@ -60,19 +60,19 @@ export class MultisigAccountInfo { /** * Checks if an account is cosignatory of the multisig account. - * @param account + * @param address * @returns {boolean} */ - public hasCosigner(account: PublicAccount): boolean { - return this.cosignatories.find((cosigner) => cosigner.equals(account)) !== undefined; + public hasCosigner(address: Address): boolean { + return this.cosignatoryAddresses.find((cosigner) => cosigner.equals(address)) !== undefined; } /** * Checks if the multisig account is cosignatory of an account. - * @param account + * @param address * @returns {boolean} */ - public isCosignerOfMultisigAccount(account: PublicAccount): boolean { - return this.multisigAccounts.find((multisigAccount) => multisigAccount.equals(account)) !== undefined; + public isCosignerOfMultisigAccount(address: Address): boolean { + return this.multisigAddresses.find((multisig) => multisig.equals(address)) !== undefined; } } diff --git a/src/model/account/UnresolvedAddress.ts b/src/model/account/UnresolvedAddress.ts new file mode 100644 index 0000000000..6f77639d46 --- /dev/null +++ b/src/model/account/UnresolvedAddress.ts @@ -0,0 +1,7 @@ +import { Address } from './Address'; +import { NamespaceId } from '../namespace/NamespaceId'; + +/** + * Custom type for unresolved address + */ +export type UnresolvedAddress = Address | NamespaceId; diff --git a/src/model/blockchain/BlockInfo.ts b/src/model/blockchain/BlockInfo.ts index 709e69d4d1..955f5b810c 100644 --- a/src/model/blockchain/BlockInfo.ts +++ b/src/model/blockchain/BlockInfo.ts @@ -17,6 +17,7 @@ import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../network/NetworkType'; import { UInt64 } from '../UInt64'; +import { Address } from '../account/Address'; /** * The block info structure describes basic information of a block. @@ -45,7 +46,7 @@ export class BlockInfo { * @param blockTransactionsHash * @param blockReceiptsHash * @param blockStateHash - * @param beneficiaryPublicKey + * @param beneficiaryAddress * @param numStatements */ constructor( @@ -141,9 +142,9 @@ export class BlockInfo { */ public readonly proofVerificationHash: string, /** - * The beneficiary public key. + * The beneficiary address. */ - public readonly beneficiaryPublicKey?: PublicAccount | undefined, + public readonly beneficiaryAddress?: Address | undefined, /** * The number of statements included. */ diff --git a/src/model/blockchain/NewBlock.ts b/src/model/blockchain/NewBlock.ts index 179f2c4590..dc7d230566 100644 --- a/src/model/blockchain/NewBlock.ts +++ b/src/model/blockchain/NewBlock.ts @@ -17,6 +17,7 @@ import { PublicAccount } from '../account/PublicAccount'; import { NetworkType } from '../network/NetworkType'; import { UInt64 } from '../UInt64'; +import { Address } from '../account/Address'; /** * The block info structure describes basic information of a new gernated block (Websocket payload). @@ -41,7 +42,7 @@ export class NewBlock { * @param blockTransactionsHash * @param blockReceiptsHash * @param blockStateHash - * @param beneficiaryPublicKey + * @param beneficiaryAddress */ constructor( /** @@ -120,8 +121,8 @@ export class NewBlock { */ public readonly proofVerificationHash: string, /** - * The beneficiary public key. + * The beneficiary address. */ - public readonly beneficiaryPublicKey?: PublicAccount, + public readonly beneficiaryAddress?: Address, ) {} } diff --git a/src/model/metadata/MetadataEntry.ts b/src/model/metadata/MetadataEntry.ts index eccdcb2187..6105a3d9cf 100644 --- a/src/model/metadata/MetadataEntry.ts +++ b/src/model/metadata/MetadataEntry.ts @@ -18,6 +18,7 @@ import { MosaicId } from '../mosaic/MosaicId'; import { NamespaceId } from '../namespace/NamespaceId'; import { UInt64 } from '../UInt64'; import { MetadataType } from './MetadataType'; +import { Address } from '../account/Address'; /** * A mosaic describes an instance of a mosaic definition. @@ -27,8 +28,8 @@ export class MetadataEntry { /** * Constructor * @param {string} compositeHash - The composite hash - * @param {string} senderPublicKey - The metadata sender's public key - * @param {string} targetPublicKey - The metadata target public key + * @param {string} sourceAddress - The metadata source address (provider) + * @param {string} targetAddress - The metadata target address * @param {UInt64} scopedMetadataKey - The key scoped to source, target and type * @param {MetadatType} metadataType - The metadata type (Account | Mosaic | Namespace) * @param {string} value - The metadata value @@ -40,13 +41,13 @@ export class MetadataEntry { */ public readonly compositeHash: string, /** - * The metadata sender's public key + * The metadata source address (provider) */ - public readonly senderPublicKey: string, + public readonly sourceAddress: Address, /** - * The metadata target public key + * The metadata target address */ - public readonly targetPublicKey: string, + public readonly targetAddress: Address, /** * The key scoped to source, target and type */ diff --git a/src/model/model.ts b/src/model/model.ts index 4ef664baa5..2a323554ef 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -30,6 +30,7 @@ export * from './account/AccountNames'; export * from './account/AccountInfoResolvedMosaic'; export * from './account/AccountKeyType'; export * from './account/AccountKey'; +export * from './account/UnresolvedAddress'; // Blockchain export * from './blockchain/BlockchainScore'; diff --git a/src/model/mosaic/MosaicInfo.ts b/src/model/mosaic/MosaicInfo.ts index baed9c0f8f..512f4fa93e 100644 --- a/src/model/mosaic/MosaicInfo.ts +++ b/src/model/mosaic/MosaicInfo.ts @@ -14,10 +14,10 @@ * limitations under the License. */ -import { PublicAccount } from '../account/PublicAccount'; import { UInt64 } from '../UInt64'; import { MosaicFlags } from './MosaicFlags'; import { MosaicId } from './MosaicId'; +import { Address } from '../account/Address'; /** * The mosaic info structure describes a mosaic. @@ -27,8 +27,8 @@ export class MosaicInfo { * @param recordId * @param id * @param supply - * @param height - * @param owner + * @param startHeight + * @param ownerAddress * @param revision * @param flags * @param divisibility @@ -50,11 +50,11 @@ export class MosaicInfo { /** * The block height were mosaic was created. */ - public readonly height: UInt64, + public readonly startHeight: UInt64, /** - * The public key of the mosaic creator. + * The mosaic owner address. */ - public readonly owner: PublicAccount, + public readonly ownerAddress: Address, /** * The mosaic revision */ diff --git a/src/model/namespace/NamespaceId.ts b/src/model/namespace/NamespaceId.ts index 3d12529cd6..66a1e050c7 100644 --- a/src/model/namespace/NamespaceId.ts +++ b/src/model/namespace/NamespaceId.ts @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Convert as convert } from '../../core/format'; +import { Convert as convert, RawAddress, Convert } from '../../core/format'; import { NamespaceMosaicIdGenerator } from '../../infrastructure/transaction/NamespaceMosaicIdGenerator'; import { Id } from '../Id'; +import { NetworkType } from '../network/NetworkType'; /** * The namespace id structure describes namespace id @@ -89,4 +90,12 @@ export class NamespaceId { fullName: this.fullName ? this.fullName : '', }; } + + /** + * Encoded unresolved address + * @returns {Uint8Array} + */ + public encodeUnresolvedAddress(networkType: NetworkType): Uint8Array { + return RawAddress.aliasToRecipient(Convert.hexToUint8(this.toHex()), networkType); + } } diff --git a/src/model/namespace/NamespaceInfo.ts b/src/model/namespace/NamespaceInfo.ts index 6d6a96b416..b5ff1b0b94 100644 --- a/src/model/namespace/NamespaceInfo.ts +++ b/src/model/namespace/NamespaceInfo.ts @@ -14,10 +14,10 @@ * limitations under the License. */ -import { PublicAccount } from '../account/PublicAccount'; import { UInt64 } from '../UInt64'; import { Alias } from './Alias'; import { NamespaceId } from './NamespaceId'; +import { Address } from '../account/Address'; /** * Object containing information of a namespace. @@ -31,7 +31,7 @@ export class NamespaceInfo { * @param depth * @param levels * @param parentId - * @param owner + * @param ownerAddress * @param startHeight * @param endHeight */ @@ -65,9 +65,9 @@ export class NamespaceInfo { */ private readonly parentId: NamespaceId, /** - * The owner of the namespace. + * The namespace owner's address. */ - public readonly owner: PublicAccount, + public readonly ownerAddress: Address, /** * The height at which the ownership begins. */ diff --git a/src/model/receipt/BalanceChangeReceipt.ts b/src/model/receipt/BalanceChangeReceipt.ts index 3a5587a7b6..6eeb24a384 100644 --- a/src/model/receipt/BalanceChangeReceipt.ts +++ b/src/model/receipt/BalanceChangeReceipt.ts @@ -14,14 +14,15 @@ * limitations under the License. */ -import { AmountDto, BalanceChangeReceiptBuilder, KeyDto, MosaicBuilder, MosaicIdDto } from 'catbuffer-typescript'; +import { AmountDto, BalanceChangeReceiptBuilder, MosaicBuilder, MosaicIdDto } from 'catbuffer-typescript'; import { Convert } from '../../core/format/Convert'; -import { PublicAccount } from '../account/PublicAccount'; import { MosaicId } from '../mosaic/MosaicId'; import { UInt64 } from '../UInt64'; import { Receipt } from './Receipt'; import { ReceiptType } from './ReceiptType'; import { ReceiptVersion } from './ReceiptVersion'; +import { Address } from '../account/Address'; +import { AddressDto } from 'catbuffer-typescript'; /** * Balance Change: A mosaic credit or debit was triggered. @@ -29,7 +30,7 @@ import { ReceiptVersion } from './ReceiptVersion'; export class BalanceChangeReceipt extends Receipt { /** * Balance change expiry receipt - * @param targetPublicAccount - The target account public account. + * @param targetAddress - The target account address. * @param mosaicId - The mosaic id. * @param amount - The amount of mosaic. * @param version - The receipt version @@ -38,9 +39,9 @@ export class BalanceChangeReceipt extends Receipt { */ constructor( /** - * The target targetPublicKey public account. + * The target account address. */ - public readonly targetPublicAccount: PublicAccount, + public readonly targetAddress: Address, /** * The mosaic id. */ @@ -66,7 +67,7 @@ export class BalanceChangeReceipt extends Receipt { ReceiptVersion.BALANCE_CHANGE, this.type.valueOf(), new MosaicBuilder(new MosaicIdDto(this.mosaicId.toDTO()), new AmountDto(this.amount.toDTO())), - new KeyDto(Convert.hexToUint8(this.targetPublicAccount.publicKey)), + new AddressDto(Convert.hexToUint8(this.targetAddress.encoded())), ).serialize(); } } diff --git a/src/model/receipt/BalanceTransferReceipt.ts b/src/model/receipt/BalanceTransferReceipt.ts index 9082a50511..3fdfc9c59b 100644 --- a/src/model/receipt/BalanceTransferReceipt.ts +++ b/src/model/receipt/BalanceTransferReceipt.ts @@ -14,13 +14,10 @@ * limitations under the License. */ -import { AddressDto, AmountDto, BalanceTransferReceiptBuilder, KeyDto, MosaicBuilder, MosaicIdDto } from 'catbuffer-typescript'; +import { AddressDto, AmountDto, BalanceTransferReceiptBuilder, MosaicBuilder, MosaicIdDto } from 'catbuffer-typescript'; import { Convert } from '../../core/format/Convert'; -import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping'; import { Address } from '../account/Address'; -import { PublicAccount } from '../account/PublicAccount'; import { MosaicId } from '../mosaic/MosaicId'; -import { NamespaceId } from '../namespace/NamespaceId'; import { UInt64 } from '../UInt64'; import { Receipt } from './Receipt'; import { ReceiptType } from './ReceiptType'; @@ -32,7 +29,7 @@ import { ReceiptVersion } from './ReceiptVersion'; export class BalanceTransferReceipt extends Receipt { /** * Balance transfer expiry receipt - * @param sender - The public account of the sender. + * @param senderAddress - The sender address. * @param recipientAddress - The mosaic recipient address. * @param mosaicId - The mosaic id. * @param amount - The amount of mosaic. @@ -42,13 +39,13 @@ export class BalanceTransferReceipt extends Receipt { */ constructor( /** - * The public account of the sender. + * The sender address. */ - public readonly sender: PublicAccount, + public readonly senderAddress: Address, /** * The mosaic recipient address. */ - public readonly recipientAddress: Address | NamespaceId, + public readonly recipientAddress: Address, /** * The mosaic id. */ @@ -74,17 +71,8 @@ export class BalanceTransferReceipt extends Receipt { ReceiptVersion.BALANCE_TRANSFER, this.type.valueOf(), new MosaicBuilder(new MosaicIdDto(this.mosaicId.toDTO()), new AmountDto(this.amount.toDTO())), - new KeyDto(Convert.hexToUint8(this.sender.publicKey)), - new AddressDto(this.getRecipientBytes()), + new AddressDto(Convert.hexToUint8(this.senderAddress.encoded())), + new AddressDto(Convert.hexToUint8(this.recipientAddress.encoded())), ).serialize(); } - - /** - * @internal - * Generate buffer for recipientAddress - * @return {Uint8Array} - */ - private getRecipientBytes(): Uint8Array { - return UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress, this.sender.address.networkType); - } } diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index 3396af4bc8..684905ad59 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -40,6 +40,7 @@ import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; import { AddressRestrictionFlag } from '../restriction/AddressRestrictionFlag'; +import { UnresolvedAddress } from '../account/UnresolvedAddress'; export class AccountAddressRestrictionTransaction extends Transaction { /** @@ -57,8 +58,8 @@ export class AccountAddressRestrictionTransaction extends Transaction { public static create( deadline: Deadline, restrictionFlags: AddressRestrictionFlag, - restrictionAdditions: (Address | NamespaceId)[], - restrictionDeletions: (Address | NamespaceId)[], + restrictionAdditions: UnresolvedAddress[], + restrictionDeletions: UnresolvedAddress[], networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), signature?: string, @@ -150,8 +151,8 @@ export class AccountAddressRestrictionTransaction extends Transaction { const byteAdditionCount = 1; const byteDeletionCount = 1; const byteAccountRestrictionTransactionBody_Reserved1 = 4; - const byteRestrictionAdditions = 25 * this.restrictionAdditions.length; - const byteRestrictionDeletions = 25 * this.restrictionDeletions.length; + const byteRestrictionAdditions = 24 * this.restrictionAdditions.length; + const byteRestrictionDeletions = 24 * this.restrictionDeletions.length; return ( byteSize + @@ -182,10 +183,10 @@ export class AccountAddressRestrictionTransaction extends Transaction { new TimestampDto(this.deadline.toDTO()), this.restrictionFlags.valueOf(), this.restrictionAdditions.map((addition) => { - return new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(addition, this.networkType)); + return new UnresolvedAddressDto(addition.encodeUnresolvedAddress(this.networkType)); }), this.restrictionDeletions.map((deletion) => { - return new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(deletion, this.networkType)); + return new UnresolvedAddressDto(deletion.encodeUnresolvedAddress(this.networkType)); }), ); return transactionBuilder.serialize(); @@ -203,10 +204,10 @@ export class AccountAddressRestrictionTransaction extends Transaction { TransactionType.ACCOUNT_ADDRESS_RESTRICTION.valueOf(), this.restrictionFlags.valueOf(), this.restrictionAdditions.map((addition) => { - return new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(addition, this.networkType)); + return new UnresolvedAddressDto(addition.encodeUnresolvedAddress(this.networkType)); }), this.restrictionDeletions.map((deletion) => { - return new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(deletion, this.networkType)); + return new UnresolvedAddressDto(deletion.encodeUnresolvedAddress(this.networkType)); }), ); } @@ -239,10 +240,8 @@ export class AccountAddressRestrictionTransaction extends Transaction { public shouldNotifyAccount(address: Address, alias: NamespaceId[]): boolean { return ( super.isSigned(address) || - this.restrictionAdditions.find((_) => _.equals(address)) !== undefined || - this.restrictionDeletions.find((_) => _.equals(address)) !== undefined || - this.restrictionAdditions.find((_: NamespaceId) => alias.find((name) => name.equals(_) !== undefined)) !== undefined || - this.restrictionDeletions.find((_: NamespaceId) => alias.find((name) => name.equals(_) !== undefined)) !== undefined + this.restrictionAdditions.find((_) => _.equals(address) || alias.find((a) => _.equals(a)) !== undefined) !== undefined || + this.restrictionDeletions.find((_) => _.equals(address) || alias.find((a) => _.equals(a)) !== undefined) !== undefined ); } } diff --git a/src/model/transaction/AccountMetadataTransaction.ts b/src/model/transaction/AccountMetadataTransaction.ts index be437aaac4..30757c0962 100644 --- a/src/model/transaction/AccountMetadataTransaction.ts +++ b/src/model/transaction/AccountMetadataTransaction.ts @@ -22,6 +22,7 @@ import { KeyDto, SignatureDto, TimestampDto, + UnresolvedAddressDto, } from 'catbuffer-typescript'; import { Convert } from '../../core/format'; import { PublicAccount } from '../account/PublicAccount'; @@ -34,6 +35,9 @@ import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; import { Address } from '../account/Address'; +import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping'; +import { NamespaceId } from '../namespace/NamespaceId'; +import { UnresolvedAddress } from '../account/UnresolvedAddress'; /** * Announce an account metadata transaction to associate a key-value state to an account. @@ -42,7 +46,7 @@ export class AccountMetadataTransaction extends Transaction { /** * Create a account meta data transaction object * @param deadline - transaction deadline - * @param targetPublicKey - Public key of the target account. + * @param targetAddress - target account address. * @param scopedMetadataKey - Metadata key scoped to source, target and type. * @param valueSizeDelta - Change in value size in bytes. * @param value - String value with UTF-8 encoding @@ -56,7 +60,7 @@ export class AccountMetadataTransaction extends Transaction { */ public static create( deadline: Deadline, - targetPublicKey: string, + targetAddress: UnresolvedAddress, scopedMetadataKey: UInt64, valueSizeDelta: number, value: string, @@ -70,7 +74,7 @@ export class AccountMetadataTransaction extends Transaction { TransactionVersion.ACCOUNT_METADATA, deadline, maxFee, - targetPublicKey, + targetAddress, scopedMetadataKey, valueSizeDelta, value, @@ -84,7 +88,7 @@ export class AccountMetadataTransaction extends Transaction { * @param version * @param deadline * @param maxFee - * @param targetPublicKey + * @param targetAddress * @param scopedMetadataKey * @param valueSizeDelta * @param value @@ -98,9 +102,9 @@ export class AccountMetadataTransaction extends Transaction { deadline: Deadline, maxFee: UInt64, /** - * Public key of the target account. + * target account address. */ - public readonly targetPublicKey: string, + public readonly targetAddress: UnresolvedAddress, /** * Metadata key scoped to source, target and type. */ @@ -136,7 +140,7 @@ export class AccountMetadataTransaction extends Transaction { const signature = payload.substring(16, 144); const transaction = AccountMetadataTransaction.create( isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as AccountMetadataTransactionBuilder).getDeadline().timestamp), - Convert.uint8ToHex(builder.getTargetPublicKey().key), + UnresolvedMapping.toUnresolvedAddress(Convert.uint8ToHex(builder.getTargetAddress().unresolvedAddress)), new UInt64(builder.getScopedMetadataKey()), builder.getValueSizeDelta(), Convert.uint8ToUtf8(builder.getValue()), @@ -158,12 +162,12 @@ export class AccountMetadataTransaction extends Transaction { const byteSize = super.size; // set static byte size fields - const targetPublicKey = 32; + const targetAddress = 24; const byteScopedMetadataKey = 8; const byteValueSizeDelta = 2; const valueSize = 2; - return byteSize + targetPublicKey + byteScopedMetadataKey + byteValueSizeDelta + valueSize + this.value.length; + return byteSize + targetAddress + byteScopedMetadataKey + byteValueSizeDelta + valueSize + this.value.length; } /** @@ -182,7 +186,7 @@ export class AccountMetadataTransaction extends Transaction { TransactionType.ACCOUNT_METADATA.valueOf(), new AmountDto(this.maxFee.toDTO()), new TimestampDto(this.deadline.toDTO()), - new KeyDto(Convert.hexToUint8(this.targetPublicKey)), + new UnresolvedAddressDto(this.targetAddress.encodeUnresolvedAddress(this.networkType)), this.scopedMetadataKey.toDTO(), this.valueSizeDelta, Convert.utf8ToUint8(this.value), @@ -200,7 +204,7 @@ export class AccountMetadataTransaction extends Transaction { this.versionToDTO(), this.networkType.valueOf(), TransactionType.ACCOUNT_METADATA.valueOf(), - new KeyDto(Convert.hexToUint8(this.targetPublicKey)), + new UnresolvedAddressDto(this.targetAddress.encodeUnresolvedAddress(this.networkType)), this.scopedMetadataKey.toDTO(), this.valueSizeDelta, Convert.utf8ToUint8(this.value), @@ -219,9 +223,14 @@ export class AccountMetadataTransaction extends Transaction { * @internal * Check a given address should be notified in websocket channels * @param address address to be notified + * @param alias address alias (names) * @returns {boolean} */ - public shouldNotifyAccount(address: Address): boolean { - return super.isSigned(address) || Address.createFromPublicKey(this.targetPublicKey, this.networkType).equals(address); + public shouldNotifyAccount(address: Address, alias: NamespaceId[]): boolean { + return ( + super.isSigned(address) || + this.targetAddress.equals(address) || + alias.find((name) => this.targetAddress.equals(name)) !== undefined + ); } } diff --git a/src/model/transaction/AddressAliasTransaction.ts b/src/model/transaction/AddressAliasTransaction.ts index b634fa0871..fda383607f 100644 --- a/src/model/transaction/AddressAliasTransaction.ts +++ b/src/model/transaction/AddressAliasTransaction.ts @@ -153,7 +153,7 @@ export class AddressAliasTransaction extends Transaction { // set static byte size fields const byteActionType = 1; const byteNamespaceId = 8; - const byteAddress = 25; + const byteAddress = 24; return byteSize + byteActionType + byteNamespaceId + byteAddress; } diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index d1c936e9db..f7b7a6c1c2 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -172,6 +172,7 @@ export class AggregateTransaction extends Transaction { const signature = payload.substring(16, 144); const consignatures = builder.getCosignatures().map((cosig) => { return new AggregateTransactionCosignature( + new UInt64(cosig.version), Convert.uint8ToHex(cosig.signature.signature), PublicAccount.createFromPublicKey(Convert.uint8ToHex(cosig.signerPublicKey.key), networkType), ); @@ -243,7 +244,7 @@ export class AggregateTransaction extends Transaction { cosignatories.forEach((cosigner) => { const keyPairEncoded = KeyPair.createKeyPairFromPrivateKeyString(cosigner.privateKey); const signature = KeyPair.sign(keyPairEncoded, transactionHashBytes); - signedPayload += cosigner.publicKey + Convert.uint8ToHex(signature); + signedPayload += UInt64.fromUint(0).toHex() + cosigner.publicKey + Convert.uint8ToHex(signature); }); // Calculate new size @@ -273,7 +274,7 @@ export class AggregateTransaction extends Transaction { const signedTransaction = this.signWith(initiatorAccount, generationHash); let signedPayload = signedTransaction.payload; cosignatureSignedTransactions.forEach((cosignedTransaction) => { - signedPayload += cosignedTransaction.signerPublicKey + cosignedTransaction.signature; + signedPayload += UInt64.fromUint(0).toHex() + cosignedTransaction.signerPublicKey + cosignedTransaction.signature; }); // Calculate new size @@ -321,7 +322,7 @@ export class AggregateTransaction extends Transaction { byteTransactions += paddedTransactionByte.length; }); - const byteCosignatures = this.cosignatures.length * 96; + const byteCosignatures = this.cosignatures.length * 104; return byteSize + byteTransactionHash + bytePayloadSize + byteHeader_Reserved1 + byteTransactions + byteCosignatures; } @@ -336,7 +337,7 @@ export class AggregateTransaction extends Transaction { const cosignatures = this.cosignatures.map((cosignature) => { const signerBytes = Convert.hexToUint8(cosignature.signer.publicKey); const signatureBytes = Convert.hexToUint8(cosignature.signature); - return new CosignatureBuilder(new KeyDto(signerBytes), new SignatureDto(signatureBytes)); + return new CosignatureBuilder(cosignature.version.toDTO(), new KeyDto(signerBytes), new SignatureDto(signatureBytes)); }); const transactionBuilder = diff --git a/src/model/transaction/AggregateTransactionCosignature.ts b/src/model/transaction/AggregateTransactionCosignature.ts index d9ae9a5afe..12f7cf9ae1 100644 --- a/src/model/transaction/AggregateTransactionCosignature.ts +++ b/src/model/transaction/AggregateTransactionCosignature.ts @@ -15,15 +15,21 @@ */ import { PublicAccount } from '../account/PublicAccount'; +import { UInt64 } from '../UInt64'; /** * Model representing cosignature of an aggregate transaction. */ export class AggregateTransactionCosignature { /** + * @param version * @param signature * @param signer */ constructor( + /** + * Version + */ + public readonly version: UInt64, /** * The signature of aggregate transaction done by the cosigner. */ @@ -39,6 +45,7 @@ export class AggregateTransactionCosignature { */ public toDTO(): any { return { + version: this.version.toDTO(), signature: this.signature, signerPublicKey: this.signer.toDTO(), }; diff --git a/src/model/transaction/MosaicAddressRestrictionTransaction.ts b/src/model/transaction/MosaicAddressRestrictionTransaction.ts index 81563110e7..593768da3c 100644 --- a/src/model/transaction/MosaicAddressRestrictionTransaction.ts +++ b/src/model/transaction/MosaicAddressRestrictionTransaction.ts @@ -184,7 +184,7 @@ export class MosaicAddressRestrictionTransaction extends Transaction { const byteRestrictionKey = 8; const bytePreviousRestrictionValue = 8; const byteNewRestrictionValue = 8; - const byteTargetAddress = 25; + const byteTargetAddress = 24; return byteSize + byteMosaicId + byteRestrictionKey + byteTargetAddress + bytePreviousRestrictionValue + byteNewRestrictionValue; } diff --git a/src/model/transaction/MosaicMetadataTransaction.ts b/src/model/transaction/MosaicMetadataTransaction.ts index 3b24340ee7..0a641d3727 100644 --- a/src/model/transaction/MosaicMetadataTransaction.ts +++ b/src/model/transaction/MosaicMetadataTransaction.ts @@ -23,6 +23,7 @@ import { SignatureDto, TimestampDto, UnresolvedMosaicIdDto, + UnresolvedAddressDto, } from 'catbuffer-typescript'; import { Convert } from '../../core/format'; import { DtoMapping } from '../../core/utils/DtoMapping'; @@ -40,6 +41,7 @@ import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; import { Address } from '../account/Address'; +import { UnresolvedAddress } from '../account/UnresolvedAddress'; /** * Announce an mosaic metadata transaction to associate a key-value state to an account. @@ -48,7 +50,7 @@ export class MosaicMetadataTransaction extends Transaction { /** * Create a mosaic meta data transaction object * @param deadline - transaction deadline - * @param targetPublicKey - Public key of the target account. + * @param targetAddress - target account address. * @param scopedMetadataKey - Metadata key scoped to source, target and type. * @param targetMosaicId - Target unresolved mosaic identifier. * @param valueSizeDelta - Change in value size in bytes. @@ -63,7 +65,7 @@ export class MosaicMetadataTransaction extends Transaction { */ public static create( deadline: Deadline, - targetPublicKey: string, + targetAddress: UnresolvedAddress, scopedMetadataKey: UInt64, targetMosaicId: MosaicId | NamespaceId, valueSizeDelta: number, @@ -78,7 +80,7 @@ export class MosaicMetadataTransaction extends Transaction { TransactionVersion.MOSAIC_METADATA, deadline, maxFee, - targetPublicKey, + targetAddress, scopedMetadataKey, targetMosaicId, valueSizeDelta, @@ -93,7 +95,7 @@ export class MosaicMetadataTransaction extends Transaction { * @param version * @param deadline * @param maxFee - * @param targetPublicKey + * @param targetAddress * @param scopedMetadataKey * @param targetMosaicId * @param valueSizeDelta @@ -108,9 +110,9 @@ export class MosaicMetadataTransaction extends Transaction { deadline: Deadline, maxFee: UInt64, /** - * Public key of the target account. + * target account address. */ - public readonly targetPublicKey: string, + public readonly targetAddress: UnresolvedAddress, /** * Metadata key scoped to source, target and type. */ @@ -150,7 +152,7 @@ export class MosaicMetadataTransaction extends Transaction { const signature = payload.substring(16, 144); const transaction = MosaicMetadataTransaction.create( isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as MosaicMetadataTransactionBuilder).getDeadline().timestamp), - Convert.uint8ToHex(builder.getTargetPublicKey().key), + UnresolvedMapping.toUnresolvedAddress(Convert.uint8ToHex(builder.getTargetAddress().unresolvedAddress)), new UInt64(builder.getScopedMetadataKey()), UnresolvedMapping.toUnresolvedMosaic(new UInt64(builder.getTargetMosaicId().unresolvedMosaicId).toHex()), builder.getValueSizeDelta(), @@ -173,13 +175,13 @@ export class MosaicMetadataTransaction extends Transaction { const byteSize = super.size; // set static byte size fields - const targetPublicKey = 32; + const targetAddress = 24; const byteScopedMetadataKey = 8; const byteTargetMosaicId = 8; const byteValueSizeDelta = 2; const valueSize = 2; - return byteSize + targetPublicKey + byteScopedMetadataKey + byteTargetMosaicId + byteValueSizeDelta + valueSize + this.value.length; + return byteSize + targetAddress + byteScopedMetadataKey + byteTargetMosaicId + byteValueSizeDelta + valueSize + this.value.length; } /** @@ -198,7 +200,7 @@ export class MosaicMetadataTransaction extends Transaction { TransactionType.MOSAIC_METADATA.valueOf(), new AmountDto(this.maxFee.toDTO()), new TimestampDto(this.deadline.toDTO()), - new KeyDto(Convert.hexToUint8(this.targetPublicKey)), + new UnresolvedAddressDto(this.targetAddress.encodeUnresolvedAddress(this.networkType)), this.scopedMetadataKey.toDTO(), new UnresolvedMosaicIdDto(this.targetMosaicId.id.toDTO()), this.valueSizeDelta, @@ -217,7 +219,7 @@ export class MosaicMetadataTransaction extends Transaction { this.versionToDTO(), this.networkType.valueOf(), TransactionType.MOSAIC_METADATA.valueOf(), - new KeyDto(Convert.hexToUint8(this.targetPublicKey)), + new UnresolvedAddressDto(this.targetAddress.encodeUnresolvedAddress(this.networkType)), this.scopedMetadataKey.toDTO(), new UnresolvedMosaicIdDto(this.targetMosaicId.id.toDTO()), this.valueSizeDelta, @@ -247,9 +249,14 @@ export class MosaicMetadataTransaction extends Transaction { * @internal * Check a given address should be notified in websocket channels * @param address address to be notified + * @param alias address alias (names) * @returns {boolean} */ - public shouldNotifyAccount(address: Address): boolean { - return super.isSigned(address) || Address.createFromPublicKey(this.targetPublicKey, this.networkType).equals(address); + public shouldNotifyAccount(address: Address, alias: NamespaceId[]): boolean { + return ( + super.isSigned(address) || + this.targetAddress.equals(address) || + alias.find((name) => this.targetAddress.equals(name)) !== undefined + ); } } diff --git a/src/model/transaction/MultisigAccountModificationTransaction.ts b/src/model/transaction/MultisigAccountModificationTransaction.ts index 88c4538c2f..bb1e4aeede 100644 --- a/src/model/transaction/MultisigAccountModificationTransaction.ts +++ b/src/model/transaction/MultisigAccountModificationTransaction.ts @@ -22,6 +22,7 @@ import { MultisigAccountModificationTransactionBuilder, SignatureDto, TimestampDto, + UnresolvedAddressDto, } from 'catbuffer-typescript'; import { Convert } from '../../core/format'; import { PublicAccount } from '../account/PublicAccount'; @@ -34,6 +35,9 @@ import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; import { Address } from '../account/Address'; +import { UnresolvedAddress } from '../account/UnresolvedAddress'; +import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping'; +import { NamespaceId } from '../namespace/NamespaceId'; /** * Modify multisig account transactions are part of the NEM's multisig account system. @@ -47,8 +51,8 @@ export class MultisigAccountModificationTransaction extends Transaction { * @param deadline - The deadline to include the transaction. * @param minApprovalDelta - The min approval relative change. * @param minRemovalDelta - The min removal relative change. - * @param publicKeyAdditions - Cosignatory public key additions. - * @param publicKeyDeletions - Cosignatory public key deletions. + * @param addressAdditions - Cosignatory address additions. + * @param addressDeletions - Cosignatory address deletions. * @param networkType - The network type. * @param maxFee - (Optional) Max fee defined by the sender * @param signature - (Optional) Transaction signature @@ -59,8 +63,8 @@ export class MultisigAccountModificationTransaction extends Transaction { deadline: Deadline, minApprovalDelta: number, minRemovalDelta: number, - publicKeyAdditions: PublicAccount[], - publicKeyDeletions: PublicAccount[], + addressAdditions: UnresolvedAddress[], + addressDeletions: UnresolvedAddress[], networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), signature?: string, @@ -73,8 +77,8 @@ export class MultisigAccountModificationTransaction extends Transaction { maxFee, minApprovalDelta, minRemovalDelta, - publicKeyAdditions, - publicKeyDeletions, + addressAdditions, + addressDeletions, signature, signer, ); @@ -87,8 +91,8 @@ export class MultisigAccountModificationTransaction extends Transaction { * @param maxFee * @param minApprovalDelta * @param minRemovalDelta - * @param publicKeyAdditions - * @param publicKeyDeletions + * @param addressAdditions + * @param addressDeletions * @param signature * @param signer * @param transactionInfo @@ -109,13 +113,13 @@ export class MultisigAccountModificationTransaction extends Transaction { */ public readonly minRemovalDelta: number, /** - * The Cosignatory public key additions. + * The Cosignatory address additions. */ - public readonly publicKeyAdditions: PublicAccount[], + public readonly addressAdditions: UnresolvedAddress[], /** - * The Cosignatory public key deletion. + * The Cosignatory address deletion. */ - public readonly publicKeyDeletions: PublicAccount[], + public readonly addressDeletions: UnresolvedAddress[], signature?: string, signer?: PublicAccount, transactionInfo?: TransactionInfo, @@ -142,11 +146,11 @@ export class MultisigAccountModificationTransaction extends Transaction { : Deadline.createFromDTO((builder as MultisigAccountModificationTransactionBuilder).getDeadline().timestamp), builder.getMinApprovalDelta(), builder.getMinRemovalDelta(), - builder.getPublicKeyAdditions().map((addition) => { - return PublicAccount.createFromPublicKey(Convert.uint8ToHex(addition.getKey()), networkType); + builder.getAddressAdditions().map((addition) => { + return UnresolvedMapping.toUnresolvedAddress(Convert.uint8ToHex(addition.unresolvedAddress)); }), - builder.getPublicKeyDeletions().map((deletion) => { - return PublicAccount.createFromPublicKey(Convert.uint8ToHex(deletion.getKey()), networkType); + builder.getAddressDeletions().map((deletion) => { + return UnresolvedMapping.toUnresolvedAddress(Convert.uint8ToHex(deletion.unresolvedAddress)); }), networkType, isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as MultisigAccountModificationTransactionBuilder).fee.amount), @@ -170,8 +174,8 @@ export class MultisigAccountModificationTransaction extends Transaction { const byteApprovalDelta = 1; const byteAdditionCount = 1; const byteDeletionCount = 1; - const bytePublicKeyAdditions = 32 * this.publicKeyAdditions.length; - const bytePublicKeyDeletions = 32 * this.publicKeyDeletions.length; + const byteAddressAdditions = 24 * this.addressAdditions.length; + const byteAddressyDeletions = 24 * this.addressDeletions.length; const byteReserved1 = 4; return ( @@ -180,8 +184,8 @@ export class MultisigAccountModificationTransaction extends Transaction { byteApprovalDelta + byteAdditionCount + byteDeletionCount + - bytePublicKeyAdditions + - bytePublicKeyDeletions + + byteAddressAdditions + + byteAddressyDeletions + byteReserved1 ); } @@ -204,11 +208,11 @@ export class MultisigAccountModificationTransaction extends Transaction { new TimestampDto(this.deadline.toDTO()), this.minRemovalDelta, this.minApprovalDelta, - this.publicKeyAdditions.map((addition) => { - return new KeyDto(Convert.hexToUint8(addition.publicKey)); + this.addressAdditions.map((addition) => { + return new UnresolvedAddressDto(addition.encodeUnresolvedAddress(this.networkType)); }), - this.publicKeyDeletions.map((deletion) => { - return new KeyDto(Convert.hexToUint8(deletion.publicKey)); + this.addressDeletions.map((deletion) => { + return new UnresolvedAddressDto(deletion.encodeUnresolvedAddress(this.networkType)); }), ); return transactionBuilder.serialize(); @@ -226,11 +230,11 @@ export class MultisigAccountModificationTransaction extends Transaction { TransactionType.MULTISIG_ACCOUNT_MODIFICATION.valueOf(), this.minRemovalDelta, this.minApprovalDelta, - this.publicKeyAdditions.map((addition) => { - return new KeyDto(Convert.hexToUint8(addition.publicKey)); + this.addressAdditions.map((addition) => { + return new UnresolvedAddressDto(addition.encodeUnresolvedAddress(this.networkType)); }), - this.publicKeyDeletions.map((deletion) => { - return new KeyDto(Convert.hexToUint8(deletion.publicKey)); + this.addressDeletions.map((deletion) => { + return new UnresolvedAddressDto(deletion.encodeUnresolvedAddress(this.networkType)); }), ); } @@ -247,13 +251,14 @@ export class MultisigAccountModificationTransaction extends Transaction { * @internal * Check a given address should be notified in websocket channels * @param address address to be notified + * @param alias address alias (names) * @returns {boolean} */ - public shouldNotifyAccount(address: Address): boolean { + public shouldNotifyAccount(address: Address, alias: NamespaceId[]): boolean { return ( super.isSigned(address) || - this.publicKeyAdditions.find((_: PublicAccount) => _.address.equals(address)) !== undefined || - this.publicKeyDeletions.find((_: PublicAccount) => _.address.equals(address)) !== undefined + this.addressAdditions.find((_) => _.equals(address) || alias.find((a) => _.equals(a)) !== undefined) !== undefined || + this.addressDeletions.find((_) => _.equals(address) || alias.find((a) => _.equals(a)) !== undefined) !== undefined ); } } diff --git a/src/model/transaction/NamespaceMetadataTransaction.ts b/src/model/transaction/NamespaceMetadataTransaction.ts index e01e0137d3..14e7fae8d4 100644 --- a/src/model/transaction/NamespaceMetadataTransaction.ts +++ b/src/model/transaction/NamespaceMetadataTransaction.ts @@ -23,6 +23,7 @@ import { NamespaceMetadataTransactionBuilder, SignatureDto, TimestampDto, + UnresolvedAddressDto, } from 'catbuffer-typescript'; import { Convert } from '../../core/format'; import { PublicAccount } from '../account/PublicAccount'; @@ -36,6 +37,8 @@ import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; import { Address } from '../account/Address'; +import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping'; +import { UnresolvedAddress } from '../account/UnresolvedAddress'; /** * Announce an namespace metadata transaction to associate a key-value state to an account. @@ -44,7 +47,7 @@ export class NamespaceMetadataTransaction extends Transaction { /** * Create a mosaic meta data transaction object * @param deadline - transaction deadline - * @param targetPublicKey - Public key of the target account. + * @param targetAddress - target account address. * @param scopedMetadataKey - Metadata key scoped to source, target and type. * @param targetNamespaceId - Target namespace identifier. * @param valueSizeDelta - Change in value size in bytes. @@ -59,7 +62,7 @@ export class NamespaceMetadataTransaction extends Transaction { */ public static create( deadline: Deadline, - targetPublicKey: string, + targetAddress: UnresolvedAddress, scopedMetadataKey: UInt64, targetNamespaceId: NamespaceId, valueSizeDelta: number, @@ -74,7 +77,7 @@ export class NamespaceMetadataTransaction extends Transaction { TransactionVersion.NAMESPACE_METADATA, deadline, maxFee, - targetPublicKey, + targetAddress, scopedMetadataKey, targetNamespaceId, valueSizeDelta, @@ -89,7 +92,7 @@ export class NamespaceMetadataTransaction extends Transaction { * @param version * @param deadline * @param maxFee - * @param targetPublicKey + * @param targetAddress * @param scopedMetadataKey * @param targetNamespaceId * @param valueSizeDelta @@ -104,9 +107,9 @@ export class NamespaceMetadataTransaction extends Transaction { deadline: Deadline, maxFee: UInt64, /** - * Public key of the target account. + * target account address. */ - public readonly targetPublicKey: string, + public readonly targetAddress: UnresolvedAddress, /** * Metadata key scoped to source, target and type. */ @@ -148,7 +151,7 @@ export class NamespaceMetadataTransaction extends Transaction { isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as NamespaceMetadataTransactionBuilder).getDeadline().timestamp), - Convert.uint8ToHex(builder.getTargetPublicKey().key), + UnresolvedMapping.toUnresolvedAddress(Convert.uint8ToHex(builder.getTargetAddress().unresolvedAddress)), new UInt64(builder.getScopedMetadataKey()), new NamespaceId(builder.getTargetNamespaceId().namespaceId), builder.getValueSizeDelta(), @@ -171,7 +174,7 @@ export class NamespaceMetadataTransaction extends Transaction { const byteSize = super.size; // set static byte size fields - const targetPublicKey = 32; + const targetAddress = 24; const byteScopedMetadataKey = 8; const byteTargetNamespaceId = 8; const byteValueSizeDelta = 2; @@ -179,7 +182,7 @@ export class NamespaceMetadataTransaction extends Transaction { return ( byteSize + - targetPublicKey + + targetAddress + byteScopedMetadataKey + byteTargetNamespaceId + byteValueSizeDelta + @@ -204,7 +207,7 @@ export class NamespaceMetadataTransaction extends Transaction { TransactionType.NAMESPACE_METADATA.valueOf(), new AmountDto(this.maxFee.toDTO()), new TimestampDto(this.deadline.toDTO()), - new KeyDto(Convert.hexToUint8(this.targetPublicKey)), + new UnresolvedAddressDto(this.targetAddress.encodeUnresolvedAddress(this.networkType)), this.scopedMetadataKey.toDTO(), new NamespaceIdDto(this.targetNamespaceId.id.toDTO()), this.valueSizeDelta, @@ -223,7 +226,7 @@ export class NamespaceMetadataTransaction extends Transaction { this.versionToDTO(), this.networkType.valueOf(), TransactionType.NAMESPACE_METADATA.valueOf(), - new KeyDto(Convert.hexToUint8(this.targetPublicKey)), + new UnresolvedAddressDto(this.targetAddress.encodeUnresolvedAddress(this.networkType)), this.scopedMetadataKey.toDTO(), new NamespaceIdDto(this.targetNamespaceId.id.toDTO()), this.valueSizeDelta, @@ -243,9 +246,14 @@ export class NamespaceMetadataTransaction extends Transaction { * @internal * Check a given address should be notified in websocket channels * @param address address to be notified + * @param alias address alias (names) * @returns {boolean} */ - public shouldNotifyAccount(address: Address): boolean { - return super.isSigned(address) || Address.createFromPublicKey(this.targetPublicKey, this.networkType).equals(address); + public shouldNotifyAccount(address: Address, alias: NamespaceId[]): boolean { + return ( + super.isSigned(address) || + this.targetAddress.equals(address) || + alias.find((name) => this.targetAddress.equals(name)) !== undefined + ); } } diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index 7bbd5991b6..c95fc858d2 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -182,7 +182,7 @@ export class SecretLockTransaction extends Transaction { const byteAmount = 8; const byteDuration = 8; const byteAlgorithm = 1; - const byteRecipient = 25; + const byteRecipient = 24; // convert secret to uint8 const byteSecret = convert.hexToUint8(this.secret).length; diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index 99d6bb567f..501dd85f8b 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -153,7 +153,7 @@ export class SecretProofTransaction extends Transaction { // hash algorithm and proof size static byte size const byteAlgorithm = 1; const byteProofSize = 2; - const byteRecipient = 25; + const byteRecipient = 24; // convert secret and proof to uint8 const byteSecret = convert.hexToUint8(this.secret).length; diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index fcc951ff76..166539ce60 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -230,10 +230,11 @@ export class TransferTransaction extends Transaction { const byteSize = super.size; // recipient and number of mosaics are static byte size - const byteRecipientAddress = 25; + const byteRecipientAddress = 24; const byteMosaicsCount = 1; const byteMessageSize = 2; const byteTransferTransactionBody_Reserved1 = 4; + const byteTransferTransactionBody_Reserved2 = 1; // read message payload size const bytePayload = this.getMessageBuffer().length; @@ -245,7 +246,8 @@ export class TransferTransaction extends Transaction { byteSize + byteMosaicsCount + byteRecipientAddress + - +byteTransferTransactionBody_Reserved1 + + byteTransferTransactionBody_Reserved1 + + byteTransferTransactionBody_Reserved2 + byteMessageSize + bytePayload + byteMosaics diff --git a/src/service/AggregateTransactionService.ts b/src/service/AggregateTransactionService.ts index c5b288e28b..0b11ef1625 100644 --- a/src/service/AggregateTransactionService.ts +++ b/src/service/AggregateTransactionService.ts @@ -54,9 +54,9 @@ export class AggregateTransactionService { /** * Include both initiator & cosigners */ - const signers = aggregateTransaction.cosignatures.map((cosigner) => cosigner.signer.publicKey); + const signers = aggregateTransaction.cosignatures.map((cosigner) => cosigner.signer.address); if (signedTransaction.signerPublicKey) { - signers.push(signedTransaction.signerPublicKey); + signers.push(Address.createFromPublicKey(signedTransaction.signerPublicKey, aggregateTransaction.networkType)); } return observableFrom(aggregateTransaction.innerTransactions) .pipe( @@ -68,9 +68,9 @@ export class AggregateTransactionService { mergeMap((_) => _.minApproval !== 0 && _.minRemoval !== 0 ? this.multisigRepository - .getMultisigAccountGraphInfo(_.account.address) + .getMultisigAccountGraphInfo(_.accountAddress) .pipe(map((graphInfo) => this.validateCosignatories(graphInfo, signers, innerTransaction))) - : observableOf(signers.find((s) => s === _.account.publicKey) !== undefined), + : observableOf(signers.find((s) => s.equals(_.accountAddress)) !== undefined), ), ), ), @@ -92,9 +92,9 @@ export class AggregateTransactionService { return this.multisigRepository.getMultisigAccountGraphInfo(address).pipe( map((graph) => { const cosignatures = ([] as MultisigAccountInfo[]) - .concat(...Array.from(graph.multisigAccounts.values())) - .map((info) => info.cosignatories.map((cosig) => cosig.publicKey)); - return new Set(([] as string[]).concat(...cosignatures)).size; + .concat(...Array.from(graph.multisigEntries.values())) + .map((info) => info.cosignatoryAddresses.map((cosig) => cosig)); + return new Set(([] as Address[]).concat(...cosignatures)).size; }), ); } @@ -123,14 +123,14 @@ export class AggregateTransactionService { */ private validateCosignatories( graphInfo: MultisigAccountGraphInfo, - cosignatories: string[], + cosignatories: Address[], innerTransaction: InnerTransaction, ): boolean { /** * Validate cosignatories from bottom level to top */ - const sortedKeys = Array.from(graphInfo.multisigAccounts.keys()).sort((a, b) => b - a); - const cosignatoriesReceived = cosignatories; + const sortedKeys = Array.from(graphInfo.multisigEntries.keys()).sort((a, b) => b - a); + const cosignatoriesReceived = cosignatories.map((cosig) => cosig.plain()); let validationResult = false; let isMultisigRemoval = false; @@ -140,20 +140,20 @@ export class AggregateTransactionService { * use minRemoval instead of minApproval for cosignatories validation. */ if (innerTransaction.type === TransactionType.MULTISIG_ACCOUNT_MODIFICATION) { - if ((innerTransaction as MultisigAccountModificationTransaction).publicKeyDeletions.length) { + if ((innerTransaction as MultisigAccountModificationTransaction).addressDeletions.length) { isMultisigRemoval = true; } } sortedKeys.forEach((key) => { - const multisigInfo = graphInfo.multisigAccounts.get(key); + const multisigInfo = graphInfo.multisigEntries.get(key); if (multisigInfo && !validationResult) { multisigInfo.forEach((multisig) => { if (multisig.minApproval >= 1 && multisig.minRemoval) { // To make sure it is multisig account const matchedCosignatories = this.compareArrays( cosignatoriesReceived, - multisig.cosignatories.map((cosig) => cosig.publicKey), + multisig.cosignatoryAddresses.map((cosig) => cosig.plain()), ); /** @@ -165,8 +165,8 @@ export class AggregateTransactionService { (matchedCosignatories.length >= multisig.minApproval && !isMultisigRemoval) || (matchedCosignatories.length >= multisig.minRemoval && isMultisigRemoval) ) { - if (cosignatoriesReceived.indexOf(multisig.account.publicKey) === -1) { - cosignatoriesReceived.push(multisig.account.publicKey); + if (cosignatoriesReceived.indexOf(multisig.accountAddress.plain()) === -1) { + cosignatoriesReceived.push(multisig.accountAddress.plain()); } validationResult = true; } else { diff --git a/src/service/MetadataTransactionService.ts b/src/service/MetadataTransactionService.ts index 817e1c16b6..b77fcb475f 100644 --- a/src/service/MetadataTransactionService.ts +++ b/src/service/MetadataTransactionService.ts @@ -19,7 +19,6 @@ import { catchError, map } from 'rxjs/operators'; import { Convert } from '../core/format/Convert'; import { MetadataRepository } from '../infrastructure/MetadataRepository'; import { Address } from '../model/account/Address'; -import { PublicAccount } from '../model/account/PublicAccount'; import { Metadata } from '../model/metadata/Metadata'; import { MetadataType } from '../model/metadata/MetadataType'; import { MosaicId } from '../model/mosaic/MosaicId'; @@ -46,10 +45,10 @@ export class MetadataTransactionService { * @param deadline - Deadline * @param networkType - Network identifier * @param metadataType - Matadata type - * @param targetPublicAccount - Target public account + * @param targetAddress - Target address * @param key - Metadata scoped key * @param value - New metadata value - * @param senderPublicAccount - sender (signer) public account + * @param sourceAddress - sender (signer) address * @param targetId - Target Id (MosaicId | NamespaceId) * @param maxFee - Max fee * @return {AccountMetadataTransaction | MosaicMetadataTransaction | NamespaceMetadataTransaction} @@ -58,24 +57,16 @@ export class MetadataTransactionService { deadline: Deadline, networkType: NetworkType, metadataType: MetadataType, - targetPublicAccount: PublicAccount, + targetAddress: Address, key: UInt64, value: string, - senderPublicAccount: PublicAccount, + sourceAddress: Address, targetId?: MosaicId | NamespaceId, maxFee: UInt64 = new UInt64([0, 0]), ): Observable { switch (metadataType) { case MetadataType.Account: - return this.createAccountMetadataTransaction( - deadline, - networkType, - targetPublicAccount.publicKey, - key, - value, - senderPublicAccount.publicKey, - maxFee, - ); + return this.createAccountMetadataTransaction(deadline, networkType, targetAddress, key, value, sourceAddress, maxFee); case MetadataType.Mosaic: if (!targetId || !(targetId instanceof MosaicId)) { throw Error('TargetId for MosaicMetadataTransaction is invalid'); @@ -83,11 +74,11 @@ export class MetadataTransactionService { return this.createMosaicMetadataTransaction( deadline, networkType, - targetPublicAccount.publicKey, + targetAddress, targetId as MosaicId, key, value, - senderPublicAccount.publicKey, + sourceAddress, maxFee, ); case MetadataType.Namespace: @@ -97,11 +88,11 @@ export class MetadataTransactionService { return this.createNamespaceMetadataTransaction( deadline, networkType, - targetPublicAccount.publicKey, + targetAddress, targetId as NamespaceId, key, value, - senderPublicAccount.publicKey, + sourceAddress, maxFee, ); default: @@ -113,88 +104,78 @@ export class MetadataTransactionService { * @internal * @param deadline - Deadline * @param networkType - Network identifier - * @param targetPublicKey - Target public key + * @param targetAddress - Target address * @param key - Metadata key * @param value - New metadata value - * @param senderPublicKey - sender (signer) public key + * @param sourceAddress - sender (signer) address * @param maxFee - max fee * @returns {Observable} */ private createAccountMetadataTransaction( deadline: Deadline, networkType: NetworkType, - targetPublicKey: string, + targetAddress: Address, key: UInt64, value: string, - senderPublicKey: string, + sourceAddress: Address, maxFee: UInt64, ): Observable { - return this.metadataRepository - .getAccountMetadataByKeyAndSender(Address.createFromPublicKey(targetPublicKey, networkType), key.toHex(), senderPublicKey) - .pipe( - map((metadata: Metadata) => { - const currentValueByte = Convert.utf8ToUint8(metadata.metadataEntry.value); + return this.metadataRepository.getAccountMetadataByKeyAndSender(targetAddress, key.toHex(), sourceAddress).pipe( + map((metadata: Metadata) => { + const currentValueByte = Convert.utf8ToUint8(metadata.metadataEntry.value); + const newValueBytes = Convert.utf8ToUint8(value); + return AccountMetadataTransaction.create( + deadline, + targetAddress, + key, + newValueBytes.length - currentValueByte.length, + Convert.decodeHex(Convert.xor(currentValueByte, newValueBytes)), + networkType, + maxFee, + ); + }), + catchError((err: Error) => { + const error = JSON.parse(err.message); + if (error && error.statusCode && error.statusCode === 404) { const newValueBytes = Convert.utf8ToUint8(value); - return AccountMetadataTransaction.create( - deadline, - targetPublicKey, - key, - newValueBytes.length - currentValueByte.length, - Convert.decodeHex(Convert.xor(currentValueByte, newValueBytes)), - networkType, - maxFee, + return of( + AccountMetadataTransaction.create(deadline, targetAddress, key, newValueBytes.length, value, networkType, maxFee), ); - }), - catchError((err: Error) => { - const error = JSON.parse(err.message); - if (error && error.statusCode && error.statusCode === 404) { - const newValueBytes = Convert.utf8ToUint8(value); - return of( - AccountMetadataTransaction.create( - deadline, - targetPublicKey, - key, - newValueBytes.length, - value, - networkType, - maxFee, - ), - ); - } - throw Error(err.message); - }), - ); + } + throw Error(err.message); + }), + ); } /** * @internal * @param deadline - Deadline * @param networkType - Network identifier - * @param targetPublicKey - Target public key + * @param targetAddress - Target Address * @param mosaicId - Mosaic Id * @param key - Metadata key * @param value - New metadata value - * @param senderPublicKey - sender (signer) public key + * @param sourceAddress - sender (signer) address * @param maxFee - max fee * @returns {Observable} */ private createMosaicMetadataTransaction( deadline: Deadline, networkType: NetworkType, - targetPublicKey: string, + targetAddress: Address, mosaicId: MosaicId, key: UInt64, value: string, - senderPublicKey: string, + sourceAddress: Address, maxFee: UInt64, ): Observable { - return this.metadataRepository.getMosaicMetadataByKeyAndSender(mosaicId, key.toHex(), senderPublicKey).pipe( + return this.metadataRepository.getMosaicMetadataByKeyAndSender(mosaicId, key.toHex(), sourceAddress).pipe( map((metadata: Metadata) => { const currentValueByte = Convert.utf8ToUint8(metadata.metadataEntry.value); const newValueBytes = Convert.utf8ToUint8(value); return MosaicMetadataTransaction.create( deadline, - targetPublicKey, + targetAddress, key, mosaicId, newValueBytes.length - currentValueByte.length, @@ -210,7 +191,7 @@ export class MetadataTransactionService { return of( MosaicMetadataTransaction.create( deadline, - targetPublicKey, + targetAddress, key, mosaicId, newValueBytes.length, @@ -229,31 +210,31 @@ export class MetadataTransactionService { * @internal * @param deadline - Deadline * @param networkType - Network identifier - * @param targetPublicKey - Target public key + * @param targetAddress - Target address * @param namespaceId - Namespace Id * @param key - Metadata key * @param value - New metadata value - * @param senderPublicKey - sender (signer) public key + * @param sourceAddress - sender (signer) address * @param maxFee - max fee * @returns {Observable} */ private createNamespaceMetadataTransaction( deadline: Deadline, networkType: NetworkType, - targetPublicKey: string, + targetAddress: Address, namespaceId: NamespaceId, key: UInt64, value: string, - senderPublicKey: string, + sourceAddress: Address, maxFee: UInt64, ): Observable { - return this.metadataRepository.getNamespaceMetadataByKeyAndSender(namespaceId, key.toHex(), senderPublicKey).pipe( + return this.metadataRepository.getNamespaceMetadataByKeyAndSender(namespaceId, key.toHex(), sourceAddress).pipe( map((metadata: Metadata) => { const currentValueByte = Convert.utf8ToUint8(metadata.metadataEntry.value); const newValueBytes = Convert.utf8ToUint8(value); return NamespaceMetadataTransaction.create( deadline, - targetPublicKey, + targetAddress, key, namespaceId, newValueBytes.length - currentValueByte.length, @@ -269,7 +250,7 @@ export class MetadataTransactionService { return of( NamespaceMetadataTransaction.create( deadline, - targetPublicKey, + targetAddress, key, namespaceId, newValueBytes.length, diff --git a/src/service/MosaicService.ts b/src/service/MosaicService.ts index c3b140eacd..02a543af47 100644 --- a/src/service/MosaicService.ts +++ b/src/service/MosaicService.ts @@ -19,11 +19,11 @@ import { map, mergeMap, toArray } from 'rxjs/operators'; import { AccountRepository } from '../infrastructure/AccountRepository'; import { MosaicRepository } from '../infrastructure/MosaicRepository'; import { Address } from '../model/account/Address'; -import { MosaicInfo } from '../model/model'; import { Mosaic } from '../model/mosaic/Mosaic'; import { MosaicId } from '../model/mosaic/MosaicId'; import { MosaicAmountView } from './MosaicAmountView'; import { MosaicView } from './MosaicView'; +import { MosaicInfo } from '../model/mosaic/MosaicInfo'; /** * Mosaic service diff --git a/test/core/format/RawAddress.spec.ts b/test/core/format/RawAddress.spec.ts index 392b9b17ef..a7d98455af 100644 --- a/test/core/format/RawAddress.spec.ts +++ b/test/core/format/RawAddress.spec.ts @@ -15,7 +15,7 @@ */ import { expect } from 'chai'; import { Convert as convert, RawAddress as address } from '../../../src/core/format'; -import { NetworkType } from '../../../src/model/model'; +import { NetworkType } from '../../../src/model/network/NetworkType'; const Address_Decoded_Size = 24; diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index 3749593cf8..d9d2dbe3da 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -21,7 +21,6 @@ import { Convert } from '../../../src/core/format'; import { TransactionMapping } from '../../../src/core/utils/TransactionMapping'; import { Account } from '../../../src/model/account/Account'; import { Address } from '../../../src/model/account/Address'; -import { PublicAccount } from '../../../src/model/account/PublicAccount'; import { EncryptedMessage } from '../../../src/model/message/EncryptedMessage'; import { MessageType } from '../../../src/model/message/MessageType'; import { PlainMessage } from '../../../src/model/message/PlainMessage'; @@ -67,7 +66,9 @@ import { VrfKeyLinkTransaction } from '../../../src/model/transaction/VrfKeyLink import { VotingKeyLinkTransaction } from '../../../src/model/transaction/VotingKeyLinkTransaction'; import { Crypto } from '../../../src/core/crypto'; import { NodeKeyLinkTransaction } from '../../../src/model/transaction/NodeKeyLinkTransaction'; -import { AddressRestrictionFlag, MosaicRestrictionFlag, OperationRestrictionFlag } from '../../../src/model/model'; +import { AddressRestrictionFlag } from '../../../src/model/restriction/AddressRestrictionFlag'; +import { OperationRestrictionFlag } from '../../../src/model/restriction/OperationRestrictionFlag'; +import { MosaicRestrictionFlag } from '../../../src/model/restriction/MosaicRestrictionFlag'; describe('TransactionMapping - createFromPayload', () => { let account: Account; @@ -77,7 +78,7 @@ describe('TransactionMapping - createFromPayload', () => { }); it('should create AccountRestrictionAddressTransaction', () => { - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), AddressRestrictionFlag.AllowIncomingAddress, @@ -91,7 +92,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping.createFromPayload(signedTransaction.payload) as AccountAddressRestrictionTransaction; expect(transaction.restrictionFlags).to.be.equal(AddressRestrictionFlag.AllowIncomingAddress); - expect((transaction.restrictionAdditions[0] as Address).plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + expect((transaction.restrictionAdditions[0] as Address).plain()).to.be.equal('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); expect(transaction.restrictionDeletions.length).to.be.equal(0); }); @@ -133,7 +134,7 @@ describe('TransactionMapping - createFromPayload', () => { it('should create AddressAliasTransaction', () => { const namespaceId = new NamespaceId([33347626, 3779697293]); - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), AliasAction.Link, @@ -149,7 +150,7 @@ describe('TransactionMapping - createFromPayload', () => { expect(transaction.aliasAction).to.be.equal(AliasAction.Link); expect(transaction.namespaceId.id.lower).to.be.equal(33347626); expect(transaction.namespaceId.id.higher).to.be.equal(3779697293); - expect(transaction.address.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + expect(transaction.address.plain()).to.be.equal('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); }); it('should create MosaicAliasTransaction', () => { @@ -304,7 +305,7 @@ describe('TransactionMapping - createFromPayload', () => { it('should create TransferTransaction', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [NetworkCurrencyLocal.createRelative(100)], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -316,12 +317,12 @@ describe('TransactionMapping - createFromPayload', () => { expect(transaction.message.payload).to.be.equal('test-message'); expect(transaction.mosaics.length).to.be.equal(1); - expect(transaction.recipientToString()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + expect(transaction.recipientToString()).to.be.equal('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); }); it('should create SecretLockTransaction', () => { const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; - const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); + const recipientAddress = Address.createFromRawAddress('SCOXVZMAZJTT4I3F7EAZYGNGR77D6WPTRFENHXQ'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), NetworkCurrencyLocal.createAbsolute(10), @@ -368,7 +369,7 @@ describe('TransactionMapping - createFromPayload', () => { Deadline.create(), 2, 1, - [PublicAccount.createFromPublicKey('B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24', NetworkType.MIJIN_TEST)], + [Address.createFromPublicKey('B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24', NetworkType.MIJIN_TEST)], [], NetworkType.MIJIN_TEST, ); @@ -379,14 +380,18 @@ describe('TransactionMapping - createFromPayload', () => { expect(transaction.minApprovalDelta).to.be.equal(2); expect(transaction.minRemovalDelta).to.be.equal(1); - expect(transaction.publicKeyAdditions[0].publicKey).to.be.equal('B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24'); - expect(transaction.publicKeyDeletions.length).to.be.equal(0); + expect( + transaction.addressAdditions[0].equals( + Address.createFromPublicKey('B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24', NetworkType.MIJIN_TEST), + ), + ).to.be.true; + expect(transaction.addressDeletions.length).to.be.equal(0); }); it('should create AggregatedTransaction - Complete', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -443,7 +448,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const accountMetadataTransaction = AccountMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), 1, Convert.uint8ToUtf8(new Uint8Array(10)), @@ -451,7 +456,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const mosaicMetadataTransaction = MosaicMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new MosaicId([2262289484, 3405110546]), 1, @@ -460,7 +465,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new NamespaceId([2262289484, 3405110546]), 1, @@ -518,7 +523,7 @@ describe('TransactionMapping - createFromPayload', () => { it('should create AggregatedTransaction - Bonded', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -723,7 +728,7 @@ describe('TransactionMapping - createFromPayload', () => { it('should create AddressMetadataTransaction', () => { const accountMetadataTransaction = AccountMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), 1, Convert.uint8ToUtf8(new Uint8Array(10)), @@ -734,7 +739,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping.createFromPayload(signedTx.payload) as AccountMetadataTransaction; expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_METADATA); - expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.targetAddress.equals(account.address)).to.be.true; expect(transaction.scopedMetadataKey.toHex()).to.be.equal(UInt64.fromUint(1000).toHex()); expect(transaction.valueSizeDelta).to.be.equal(1); expect(Convert.uint8ToHex(transaction.value)).to.be.equal(Convert.uint8ToHex(new Uint8Array(10))); @@ -743,7 +748,7 @@ describe('TransactionMapping - createFromPayload', () => { it('should create MosaicMetadataTransaction', () => { const mosaicMetadataTransaction = MosaicMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new MosaicId([2262289484, 3405110546]), 1, @@ -756,7 +761,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping.createFromPayload(signedTx.payload) as MosaicMetadataTransaction; expect(transaction.type).to.be.equal(TransactionType.MOSAIC_METADATA); - expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.targetAddress.equals(account.address)).to.be.true; expect(transaction.scopedMetadataKey.toHex()).to.be.equal(UInt64.fromUint(1000).toHex()); expect(transaction.valueSizeDelta).to.be.equal(1); expect(transaction.targetMosaicId.toHex()).to.be.equal(new MosaicId([2262289484, 3405110546]).toHex()); @@ -766,7 +771,7 @@ describe('TransactionMapping - createFromPayload', () => { it('should create NamespaceMetadataTransaction', () => { const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new NamespaceId([2262289484, 3405110546]), 1, @@ -779,7 +784,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping.createFromPayload(signedTx.payload) as NamespaceMetadataTransaction; expect(transaction.type).to.be.equal(TransactionType.NAMESPACE_METADATA); - expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.targetAddress.equals(account.address)).to.be.true; expect(transaction.scopedMetadataKey.toHex()).to.be.equal(UInt64.fromUint(1000).toHex()); expect(transaction.valueSizeDelta).to.be.equal(1); expect(transaction.targetNamespaceId.toHex()).to.be.equal(new NamespaceId([2262289484, 3405110546]).toHex()); @@ -789,7 +794,7 @@ describe('TransactionMapping - createFromPayload', () => { it('should throw error with invalid type', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [NetworkCurrencyLocal.createRelative(100)], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -814,7 +819,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => it('should create TransferTransaction - Address', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [NetworkCurrencyLocal.createRelative(100)], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -822,7 +827,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => const transaction = TransactionMapping.createFromDTO(transferTransaction.toJSON()) as TransferTransaction; - expect((transaction.recipientAddress as Address).plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + expect((transaction.recipientAddress as Address).plain()).to.be.equal('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); expect(transaction.message.payload).to.be.equal('test-message'); }); @@ -845,7 +850,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => it('should create TransferTransaction - Encrypted Message', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [NetworkCurrencyLocal.createRelative(100)], new EncryptedMessage('12324556'), NetworkType.MIJIN_TEST, @@ -853,7 +858,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => const transaction = TransactionMapping.createFromDTO(transferTransaction.toJSON()) as TransferTransaction; - expect((transaction.recipientAddress as Address).plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + expect((transaction.recipientAddress as Address).plain()).to.be.equal('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); expect(transaction.message.type).to.be.equal(MessageType.EncryptedMessage); }); @@ -909,7 +914,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => expect(transaction.linkAction).to.be.equal(LinkAction.Link); }); it('should create AccountRestrictionAddressTransaction', () => { - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), AddressRestrictionFlag.AllowIncomingAddress, @@ -922,7 +927,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => addressRestrictionTransaction.toJSON(), ) as AccountAddressRestrictionTransaction; - expect((transaction.restrictionAdditions[0] as Address).plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + expect((transaction.restrictionAdditions[0] as Address).plain()).to.be.equal('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); expect(transaction.restrictionFlags).to.be.equal(AddressRestrictionFlag.AllowIncomingAddress); expect(transaction.restrictionDeletions.length).to.be.equal(0); }); @@ -965,7 +970,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => it('should create AddressAliasTransaction', () => { const namespaceId = new NamespaceId([33347626, 3779697293]); - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), AliasAction.Link, @@ -1034,7 +1039,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => it('should create SecretLockTransaction', () => { const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; - const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); + const recipientAddress = Address.createFromRawAddress('SCOXVZMAZJTT4I3F7EAZYGNGR77D6WPTRFENHXQ'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), NetworkCurrencyLocal.createAbsolute(10), @@ -1073,7 +1078,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => it('should create SecretLockTransaction - resolved Mosaic', () => { const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; - const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); + const recipientAddress = Address.createFromRawAddress('SCOXVZMAZJTT4I3F7EAZYGNGR77D6WPTRFENHXQ'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), new Mosaic(new MosaicId([1, 1]), UInt64.fromUint(10)), @@ -1137,7 +1142,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => Deadline.create(), 2, 1, - [PublicAccount.createFromPublicKey('B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24', NetworkType.MIJIN_TEST)], + [Address.createFromPublicKey('B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24', NetworkType.MIJIN_TEST)], [], NetworkType.MIJIN_TEST, ); @@ -1154,7 +1159,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => it('should create AggregatedTransaction - Complete', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -1176,7 +1181,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => it('should create AggregatedTransaction - Bonded', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -1289,7 +1294,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => it('should create AddressMetadataTransaction', () => { const accountMetadataTransaction = AccountMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), 1, 'Test Value', @@ -1299,7 +1304,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => const transaction = TransactionMapping.createFromDTO(accountMetadataTransaction.toJSON()) as AccountMetadataTransaction; expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_METADATA); - expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.targetAddress.equals(account.address)).to.be.true; expect(transaction.scopedMetadataKey.toHex()).to.be.equal(UInt64.fromUint(1000).toHex()); expect(transaction.valueSizeDelta).to.be.equal(1); expect(transaction.value).to.be.equal('Test Value'); @@ -1308,7 +1313,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => it('should create MosaicMetadataTransaction', () => { const mosaicMetadataTransaction = MosaicMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new MosaicId([2262289484, 3405110546]), 1, @@ -1319,7 +1324,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => const transaction = TransactionMapping.createFromDTO(mosaicMetadataTransaction.toJSON()) as MosaicMetadataTransaction; expect(transaction.type).to.be.equal(TransactionType.MOSAIC_METADATA); - expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.targetAddress.equals(account.address)).to.be.true; expect(transaction.scopedMetadataKey.toHex()).to.be.equal(UInt64.fromUint(1000).toHex()); expect(transaction.valueSizeDelta).to.be.equal(1); expect(transaction.targetMosaicId.toHex()).to.be.equal(new MosaicId([2262289484, 3405110546]).toHex()); @@ -1329,7 +1334,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => it('should create NamespaceMetadataTransaction', () => { const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new NamespaceId([2262289484, 3405110546]), 1, @@ -1340,7 +1345,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => const transaction = TransactionMapping.createFromDTO(namespaceMetadataTransaction.toJSON()) as NamespaceMetadataTransaction; expect(transaction.type).to.be.equal(TransactionType.NAMESPACE_METADATA); - expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.targetAddress.equals(account.address)).to.be.true; expect(transaction.scopedMetadataKey.toString()).to.be.equal(UInt64.fromUint(1000).toString()); expect(transaction.valueSizeDelta).to.be.equal(1); expect(transaction.targetNamespaceId.toHex()).to.be.equal(new NamespaceId([2262289484, 3405110546]).toHex()); diff --git a/test/core/utils/TransactionMappingWithSignatures.spec.ts b/test/core/utils/TransactionMappingWithSignatures.spec.ts index e402d56838..d720ff08fd 100644 --- a/test/core/utils/TransactionMappingWithSignatures.spec.ts +++ b/test/core/utils/TransactionMappingWithSignatures.spec.ts @@ -21,7 +21,6 @@ import { Convert } from '../../../src/core/format'; import { TransactionMapping } from '../../../src/core/utils/TransactionMapping'; import { Account } from '../../../src/model/account/Account'; import { Address } from '../../../src/model/account/Address'; -import { PublicAccount } from '../../../src/model/account/PublicAccount'; import { PlainMessage } from '../../../src/model/message/PlainMessage'; import { MosaicFlags } from '../../../src/model/mosaic/MosaicFlags'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; @@ -79,7 +78,7 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign }); it('should create AccountRestrictionAddressTransaction', () => { - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), AddressRestrictionFlag.AllowIncomingAddress, @@ -95,7 +94,7 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign let transaction = TransactionMapping.createFromPayload(signedTransaction) as AccountAddressRestrictionTransaction; expect(transaction.restrictionFlags).to.be.equal(AddressRestrictionFlag.AllowIncomingAddress); - expect((transaction.restrictionAdditions[0] as Address).plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + expect((transaction.restrictionAdditions[0] as Address).plain()).to.be.equal('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); expect(transaction.restrictionDeletions.length).to.be.equal(0); expect(transaction.signature).to.be.equal(testSignature); expect(transaction.signer?.publicKey).to.be.equal(account.publicKey); @@ -171,7 +170,7 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign it('should create AddressAliasTransaction', () => { const namespaceId = new NamespaceId([33347626, 3779697293]); - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), AliasAction.Link, @@ -190,7 +189,7 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign expect(transaction.aliasAction).to.be.equal(AliasAction.Link); expect(transaction.namespaceId.id.lower).to.be.equal(33347626); expect(transaction.namespaceId.id.higher).to.be.equal(3779697293); - expect(transaction.address.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + expect(transaction.address.plain()).to.be.equal('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); expect(transaction.signature).to.be.equal(testSignature); expect(transaction.signer?.publicKey).to.be.equal(account.publicKey); @@ -339,7 +338,7 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign it('should create TransferTransaction', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [NetworkCurrencyLocal.createRelative(100)], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -354,7 +353,7 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign expect(transaction.message.payload).to.be.equal('test-message'); expect(transaction.mosaics.length).to.be.equal(1); - expect(transaction.recipientToString()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + expect(transaction.recipientToString()).to.be.equal('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); expect(transaction.signature).to.be.equal(testSignature); expect(transaction.signer?.publicKey).to.be.equal(account.publicKey); @@ -368,7 +367,7 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign it('should create SecretLockTransaction', () => { const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; - const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); + const recipientAddress = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), NetworkCurrencyLocal.createAbsolute(10), @@ -439,7 +438,7 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign Deadline.create(), 2, 1, - [PublicAccount.createFromPublicKey('B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24', NetworkType.MIJIN_TEST)], + [Address.createFromPublicKey('B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24', NetworkType.MIJIN_TEST)], [], NetworkType.MIJIN_TEST, undefined, @@ -453,8 +452,12 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign expect(transaction.minApprovalDelta).to.be.equal(2); expect(transaction.minRemovalDelta).to.be.equal(1); - expect(transaction.publicKeyAdditions[0].publicKey).to.be.equal('B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24'); - expect(transaction.publicKeyDeletions.length).to.be.equal(0); + expect( + transaction.addressAdditions[0].equals( + Address.createFromPublicKey('B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24', NetworkType.MIJIN_TEST), + ), + ).to.be.true; + expect(transaction.addressDeletions.length).to.be.equal(0); expect(transaction.signature).to.be.equal(testSignature); expect(transaction.signer?.publicKey).to.be.equal(account.publicKey); @@ -469,7 +472,7 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign it('should create AggregatedTransaction - Complete', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -526,7 +529,7 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign ); const accountMetadataTransaction = AccountMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), 1, Convert.uint8ToUtf8(new Uint8Array(10)), @@ -534,7 +537,7 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign ); const mosaicMetadataTransaction = MosaicMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new MosaicId([2262289484, 3405110546]), 1, @@ -543,7 +546,7 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign ); const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new NamespaceId([2262289484, 3405110546]), 1, @@ -613,7 +616,7 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign it('should create AggregatedTransaction - Bonded', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -956,7 +959,7 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign it('should create AddressMetadataTransaction', () => { const accountMetadataTransaction = AccountMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), 1, Convert.uint8ToUtf8(new Uint8Array(10)), @@ -970,7 +973,7 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign let transaction = TransactionMapping.createFromPayload(signedTransaction) as AccountMetadataTransaction; expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_METADATA); - expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.targetAddress.equals(account.address)).to.be.true; expect(transaction.scopedMetadataKey.toHex()).to.be.equal(UInt64.fromUint(1000).toHex()); expect(transaction.valueSizeDelta).to.be.equal(1); expect(Convert.uint8ToHex(transaction.value)).to.be.equal(Convert.uint8ToHex(new Uint8Array(10))); @@ -988,7 +991,7 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign it('should create MosaicMetadataTransaction', () => { const mosaicMetadataTransaction = MosaicMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new MosaicId([2262289484, 3405110546]), 1, @@ -1004,7 +1007,7 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign let transaction = TransactionMapping.createFromPayload(signedTransaction) as MosaicMetadataTransaction; expect(transaction.type).to.be.equal(TransactionType.MOSAIC_METADATA); - expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.targetAddress.equals(account.address)).to.be.true; expect(transaction.scopedMetadataKey.toHex()).to.be.equal(UInt64.fromUint(1000).toHex()); expect(transaction.valueSizeDelta).to.be.equal(1); expect(transaction.targetMosaicId.toHex()).to.be.equal(new MosaicId([2262289484, 3405110546]).toHex()); @@ -1023,7 +1026,7 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign it('should create NamespaceMetadataTransaction', () => { const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new NamespaceId([2262289484, 3405110546]), 1, @@ -1039,7 +1042,7 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign let transaction = TransactionMapping.createFromPayload(signedTransaction) as NamespaceMetadataTransaction; expect(transaction.type).to.be.equal(TransactionType.NAMESPACE_METADATA); - expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.targetAddress.equals(account.address)).to.be.true; expect(transaction.scopedMetadataKey.toHex()).to.be.equal(UInt64.fromUint(1000).toHex()); expect(transaction.valueSizeDelta).to.be.equal(1); expect(transaction.targetNamespaceId.toHex()).to.be.equal(new NamespaceId([2262289484, 3405110546]).toHex()); @@ -1058,7 +1061,7 @@ describe('TransactionMapping - createFromPayload with optional sigature and sign it('should throw error with invalid type', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [NetworkCurrencyLocal.createRelative(100)], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, diff --git a/test/core/utils/UnresolvedMapping.spec.ts b/test/core/utils/UnresolvedMapping.spec.ts index 5831b190e3..dcbf7daea5 100644 --- a/test/core/utils/UnresolvedMapping.spec.ts +++ b/test/core/utils/UnresolvedMapping.spec.ts @@ -29,7 +29,7 @@ describe('UnresolvedMapping', () => { before(() => { mosaicId = new MosaicId('11F4B1B3AC033DB5'); namespacId = NamespaceId.createFromEncoded('9550CA3FC9B41FC5'); - address = Address.createFromRawAddress('MCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPR72DYSX'); + address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); }); describe('toUnresolvedMosaic', () => { @@ -83,14 +83,14 @@ describe('UnresolvedMapping', () => { const buffer = UnresolvedMapping.toUnresolvedAddressBytes(namespacId, NetworkType.MIJIN_TEST); expect(buffer instanceof Uint8Array).to.be.true; expect(buffer[0]).to.be.equal(NetworkType.MIJIN_TEST | 1); - expect(Convert.uint8ToHex(buffer)).to.be.equal('91C51FB4C93FCA509500000000000000000000000000000000'); + expect(Convert.uint8ToHex(buffer)).to.be.equal('91C51FB4C93FCA5095000000000000000000000000000000'); }); it('can map hex string to NamespaceId using MAIN_NET', () => { const buffer = UnresolvedMapping.toUnresolvedAddressBytes(namespacId, NetworkType.MAIN_NET); expect(buffer instanceof Uint8Array).to.be.true; expect(buffer[0]).to.be.equal(NetworkType.MAIN_NET | 1); - expect(Convert.uint8ToHex(buffer)).to.be.equal('69C51FB4C93FCA509500000000000000000000000000000000'); + expect(Convert.uint8ToHex(buffer)).to.be.equal('69C51FB4C93FCA5095000000000000000000000000000000'); }); }); }); diff --git a/test/infrastructure/AccountHttp.spec.ts b/test/infrastructure/AccountHttp.spec.ts index 42fbfa5181..e68155a347 100644 --- a/test/infrastructure/AccountHttp.spec.ts +++ b/test/infrastructure/AccountHttp.spec.ts @@ -34,7 +34,7 @@ import { Address } from '../../src/model/account/Address'; import { AccountKeyDTO } from 'symbol-openapi-typescript-node-client/dist/model/accountKeyDTO'; describe('AccountHttp', () => { - const address = Address.createFromRawAddress('MCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPR72DYSX'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const mosaic = new Mosaic(); mosaic.amount = '777'; diff --git a/test/infrastructure/BlockHttp.spec.ts b/test/infrastructure/BlockHttp.spec.ts index 59f55027be..cb30d4f340 100644 --- a/test/infrastructure/BlockHttp.spec.ts +++ b/test/infrastructure/BlockHttp.spec.ts @@ -34,12 +34,13 @@ import { BlockRepository } from '../../src/infrastructure/BlockRepository'; import { BlockInfo } from '../../src/model/blockchain/BlockInfo'; import { MerklePathItem } from '../../src/model/blockchain/MerklePathItem'; import { UInt64 } from '../../src/model/UInt64'; +import { Address } from '../../src/model/account/Address'; +import { NetworkType } from '../../src/model/network/NetworkType'; describe('BlockHttp', () => { const blockDTO = new BlockDTO(); blockDTO.version = 1; blockDTO.network = NetworkTypeEnum.NUMBER_152; - blockDTO.beneficiaryPublicKey = 'a'; blockDTO.difficulty = '2'; blockDTO.feeMultiplier = 3; blockDTO.height = '4'; @@ -47,7 +48,10 @@ describe('BlockHttp', () => { blockDTO.type = 6; blockDTO.signerPublicKey = '81E5E7AE49998802DABC816EC10158D3A7879702FF29084C2C992CD1289877A7'; blockDTO.timestamp = '7'; - blockDTO.beneficiaryPublicKey = '81E5E7AE49998802DABC816EC10158D3A7879702FF29084C2C992CD1289877A8'; + blockDTO.beneficiaryAddress = Address.createFromPublicKey( + '81E5E7AE49998802DABC816EC10158D3A7879702FF29084C2C992CD1289877A8', + NetworkType.MIJIN_TEST, + ).encoded(); const blockMetaDTO = new BlockMetaDTO(); blockMetaDTO.generationHash = 'abc'; @@ -81,7 +85,7 @@ describe('BlockHttp', () => { expect(blockInfo.feeMultiplier).to.be.equals(blockInfoDto.block.feeMultiplier); expect(blockInfo.networkType).to.be.equals(blockInfoDto.block.network); expect(blockInfo.version).to.be.equals(blockInfoDto.block.version); - expect(blockInfo.beneficiaryPublicKey!.publicKey).to.be.equals(blockInfoDto.block.beneficiaryPublicKey); + expect(blockInfo.beneficiaryAddress?.encoded()).to.be.equals(blockInfoDto.block.beneficiaryAddress); expect(blockInfo.difficulty.toString()).to.be.equals(blockInfoDto.block.difficulty); expect(blockInfo.feeMultiplier).to.be.equals(blockInfoDto.block.feeMultiplier); expect(blockInfo.signer!.publicKey).to.be.equals(blockInfoDto.block.signerPublicKey); diff --git a/test/infrastructure/Listener.spec.ts b/test/infrastructure/Listener.spec.ts index a856f5a819..a1e6556df3 100644 --- a/test/infrastructure/Listener.spec.ts +++ b/test/infrastructure/Listener.spec.ts @@ -23,11 +23,16 @@ import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepositor import { Account } from '../../src/model/account/Account'; import { AccountNames } from '../../src/model/account/AccountNames'; import { Address } from '../../src/model/account/Address'; -import { Deadline, NamespaceId, NamespaceName, PlainMessage, Transaction, TransferTransaction, PublicAccount } from '../../src/model/model'; import { NetworkType } from '../../src/model/network/NetworkType'; import { TransactionStatusError } from '../../src/model/transaction/TransactionStatusError'; import { UInt64 } from '../../src/model/UInt64'; import { NewBlock } from '../../src/model/blockchain/NewBlock'; +import { Transaction } from '../../src/model/transaction/Transaction'; +import { PlainMessage } from '../../src/model/message/PlainMessage'; +import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; +import { NamespaceName } from '../../src/model/namespace/NamespaceName'; +import { NamespaceId } from '../../src/model/namespace/NamespaceId'; +import { Deadline } from '../../src/model/transaction/Deadline'; describe('Listener', () => { const account = Account.createFromPrivateKey( @@ -58,7 +63,7 @@ describe('Listener', () => { describe('onStatusWhenAddressIsTheSame', () => { it('Should forward status', () => { - const errorEncodedAddress = '906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB'; + const errorEncodedAddress = '6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144'; const errorAddress = Address.createFromEncoded(errorEncodedAddress); @@ -100,7 +105,7 @@ describe('Listener', () => { describe('onConfirmed', () => { it('Should forward status', () => { - const errorEncodedAddress = '906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB'; + const errorEncodedAddress = '6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144'; const errorAddress = Address.createFromEncoded(errorEncodedAddress); @@ -448,7 +453,7 @@ describe('Listener', () => { '37351C8244AC166BE6664E3FA954E99A3239AC46E51E2B32CEA1C72DD0851100A7731868' + 'E932E1A9BEF8A27D48E1FFEE401E933EB801824373E7537E51733E0F', signerPublicKey: 'B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF', - beneficiaryPublicKey: 'B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF', + beneficiaryAddress: '6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144', timestamp: '0', type: 32768, version: 1, @@ -490,7 +495,7 @@ describe('Listener', () => { expect(reportedStatus[0].blockTransactionsHash).to.be.equal(blockDTO.block.transactionsHash); expect(reportedStatus[0].blockReceiptsHash).to.be.equal(blockDTO.block.receiptsHash); expect(reportedStatus[0].stateHash).to.be.equal(blockDTO.block.stateHash); - expect((reportedStatus[0].beneficiaryPublicKey as PublicAccount).publicKey).to.be.equal(blockDTO.block.beneficiaryPublicKey); + expect(reportedStatus[0].beneficiaryAddress?.encoded()).to.be.equal(blockDTO.block.beneficiaryAddress); expect(reportedStatus[0].proofGamma).to.be.equal(blockDTO.block.proofGamma); expect(reportedStatus[0].proofScalar).to.be.equal(blockDTO.block.proofScalar); expect(reportedStatus[0].proofVerificationHash).to.be.equal(blockDTO.block.proofVerificationHash); diff --git a/test/infrastructure/MetadataHttp.spec.ts b/test/infrastructure/MetadataHttp.spec.ts index 135559538e..2f44178516 100644 --- a/test/infrastructure/MetadataHttp.spec.ts +++ b/test/infrastructure/MetadataHttp.spec.ts @@ -35,7 +35,7 @@ import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { Order } from 'symbol-openapi-typescript-node-client/dist/model/order'; describe('MetadataHttp', () => { - const address = Address.createFromRawAddress('MCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPR72DYSX'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const mosaicId = new MosaicId('941299B2B7E1291C'); const namespaceId = new NamespaceId('some.address'); @@ -46,8 +46,8 @@ describe('MetadataHttp', () => { metadataEntryDtoMosaic.compositeHash = '1'; metadataEntryDtoMosaic.metadataType = MetadataTypeEnum.NUMBER_1; metadataEntryDtoMosaic.scopedMetadataKey = '123451234512345A'; - metadataEntryDtoMosaic.senderPublicKey = 'aSenderPublicKey1'; - metadataEntryDtoMosaic.targetPublicKey = 'aTargetPublicKey1'; + metadataEntryDtoMosaic.sourceAddress = address.encoded(); + metadataEntryDtoMosaic.targetAddress = address.encoded(); metadataEntryDtoMosaic.value = 'value1'; metadataEntryDtoMosaic.targetId = '941299B2B7E1291C' as any; metadataDTOMosaic.metadataEntry = metadataEntryDtoMosaic; @@ -59,8 +59,8 @@ describe('MetadataHttp', () => { metadataEntryDtoAddress.compositeHash = '2'; metadataEntryDtoAddress.metadataType = MetadataTypeEnum.NUMBER_0; metadataEntryDtoAddress.scopedMetadataKey = '123451234512345B'; - metadataEntryDtoAddress.senderPublicKey = 'aSenderPublicKey2'; - metadataEntryDtoAddress.targetPublicKey = 'aTargetPublicKey2'; + metadataEntryDtoAddress.sourceAddress = address.encoded(); + metadataEntryDtoAddress.targetAddress = address.encoded(); metadataEntryDtoAddress.value = 'value1'; metadataEntryDtoAddress.targetId = '941299B2B7E1291D' as any; metadataDTOAddress.metadataEntry = metadataEntryDtoAddress; @@ -72,8 +72,8 @@ describe('MetadataHttp', () => { metadataEntryDtoNamespace.compositeHash = '3'; metadataEntryDtoNamespace.metadataType = MetadataTypeEnum.NUMBER_2; metadataEntryDtoNamespace.scopedMetadataKey = '123451234512345C'; - metadataEntryDtoNamespace.senderPublicKey = 'aSenderPublicKey3'; - metadataEntryDtoNamespace.targetPublicKey = 'aTargetPublicKey3'; + metadataEntryDtoNamespace.sourceAddress = address.encoded(); + metadataEntryDtoNamespace.targetAddress = address.encoded(); metadataEntryDtoNamespace.value = 'value1'; metadataEntryDtoNamespace.targetId = '941299B2B7E1291E' as any; metadataDTONamespace.metadataEntry = metadataEntryDtoNamespace; @@ -104,7 +104,8 @@ describe('MetadataHttp', () => { if (metadataInfo.metadataEntry.metadataType === MetadataType.Namespace) { expect(metadataInfo.metadataEntry.targetId!.toHex()).to.be.equals(dto.metadataEntry.targetId); } - expect(metadataInfo.metadataEntry.targetPublicKey).to.be.equals(dto.metadataEntry.targetPublicKey); + expect(metadataInfo.metadataEntry.sourceAddress.encoded()).to.be.equals(dto.metadataEntry.sourceAddress); + expect(metadataInfo.metadataEntry.targetAddress.encoded()).to.be.equals(dto.metadataEntry.targetAddress); expect(metadataInfo.metadataEntry.scopedMetadataKey.toHex()).to.be.equals(dto.metadataEntry.scopedMetadataKey); expect(metadataInfo.metadataEntry.compositeHash).to.be.equals(dto.metadataEntry.compositeHash); } @@ -145,13 +146,13 @@ describe('MetadataHttp', () => { }); it('getAccountMetadataByKeyAndSender', async () => { - when(metadataRoutesApi.getAccountMetadataByKeyAndSender(address.plain(), 'aaa', 'sender')).thenReturn( + when(metadataRoutesApi.getAccountMetadataByKeyAndSender(address.plain(), 'aaa', address.plain())).thenReturn( Promise.resolve({ response, body: metadataDTOMosaic, }), ); - const metadata = await metadataRepository.getAccountMetadataByKeyAndSender(address, 'aaa', 'sender').toPromise(); + const metadata = await metadataRepository.getAccountMetadataByKeyAndSender(address, 'aaa', address).toPromise(); assertMetadataInfo(metadata, metadataDTOMosaic); }); @@ -191,13 +192,13 @@ describe('MetadataHttp', () => { }); it('getMosaicMetadataByKeyAndSender', async () => { - when(metadataRoutesApi.getMosaicMetadataByKeyAndSender(mosaicId.toHex(), 'aaa', 'sender')).thenReturn( + when(metadataRoutesApi.getMosaicMetadataByKeyAndSender(mosaicId.toHex(), 'aaa', address.plain())).thenReturn( Promise.resolve({ response, body: metadataDTOMosaic, }), ); - const metadata = await metadataRepository.getMosaicMetadataByKeyAndSender(mosaicId, 'aaa', 'sender').toPromise(); + const metadata = await metadataRepository.getMosaicMetadataByKeyAndSender(mosaicId, 'aaa', address).toPromise(); assertMetadataInfo(metadata, metadataDTOMosaic); }); @@ -237,13 +238,13 @@ describe('MetadataHttp', () => { }); it('getNamespaceMetadataByKeyAndSender', async () => { - when(metadataRoutesApi.getNamespaceMetadataByKeyAndSender(namespaceId.toHex(), 'cccc', 'sender1')).thenReturn( + when(metadataRoutesApi.getNamespaceMetadataByKeyAndSender(namespaceId.toHex(), 'cccc', address.plain())).thenReturn( Promise.resolve({ response, body: metadataDTOMosaic, }), ); - const metadata = await metadataRepository.getNamespaceMetadataByKeyAndSender(namespaceId, 'cccc', 'sender1').toPromise(); + const metadata = await metadataRepository.getNamespaceMetadataByKeyAndSender(namespaceId, 'cccc', address).toPromise(); assertMetadataInfo(metadata, metadataDTOMosaic); }); }); diff --git a/test/infrastructure/MosaicHttp.spec.ts b/test/infrastructure/MosaicHttp.spec.ts index 12525de051..bc14a75efb 100644 --- a/test/infrastructure/MosaicHttp.spec.ts +++ b/test/infrastructure/MosaicHttp.spec.ts @@ -43,7 +43,6 @@ describe('MosaicHttp', () => { mosaicDto.flags = 1; mosaicDto.id = mosaicId.toHex(); mosaicDto.ownerAddress = address.encoded(); - mosaicDto.ownerPublicKey = publicAccount.publicKey; mosaicDto.revision = 0; mosaicDto.startHeight = '1'; mosaicDto.supply = '100'; @@ -68,10 +67,9 @@ describe('MosaicHttp', () => { expect(mosaicInfo.divisibility).to.be.equals(6); expect(mosaicInfo.duration.toString()).to.be.equals(mosaicDto.duration); expect(mosaicInfo.flags.getValue()).to.be.equals(mosaicDto.flags); - expect(mosaicInfo.height.toString()).to.be.equals(mosaicDto.startHeight); + expect(mosaicInfo.startHeight.toString()).to.be.equals(mosaicDto.startHeight); expect(mosaicInfo.supply.toString()).to.be.equals(mosaicDto.supply); - expect(mosaicInfo.owner.publicKey).to.be.equals(mosaicDto.ownerPublicKey); - expect(mosaicInfo.owner.address.encoded()).to.be.equals(mosaicDto.ownerAddress); + expect(mosaicInfo.ownerAddress.encoded()).to.be.equals(mosaicDto.ownerAddress); expect(mosaicInfo.revision).to.be.equals(mosaicDto.revision); expect(mosaicInfo.id.toHex()).to.be.equals(mosaicId.toHex()); } @@ -109,7 +107,7 @@ describe('MosaicHttp', () => { }); it('getMosaic - Error', async () => { - when(mosaicRoutesApi.getMosaic(mosaicId.toHex())).thenThrow(new Error('Mocked Error')); + when(mosaicRoutesApi.getMosaic(mosaicId.toHex())).thenReject(new Error('Mocked Error')); await mosaicRepository .getMosaic(mosaicId) .toPromise() @@ -119,7 +117,7 @@ describe('MosaicHttp', () => { it('getMosaics - Error', async () => { const mosaicIds = new MosaicIds(); mosaicIds.mosaicIds = [mosaicId.toHex()]; - when(mosaicRoutesApi.getMosaics(deepEqual(mosaicIds))).thenThrow(new Error('Mocked Error')); + when(mosaicRoutesApi.getMosaics(deepEqual(mosaicIds))).thenReject(new Error('Mocked Error')); await mosaicRepository .getMosaics([mosaicId]) .toPromise() diff --git a/test/infrastructure/MultisigHttp.spec.ts b/test/infrastructure/MultisigHttp.spec.ts index 35ef5f9637..2124f5bcee 100644 --- a/test/infrastructure/MultisigHttp.spec.ts +++ b/test/infrastructure/MultisigHttp.spec.ts @@ -23,6 +23,7 @@ import { MultisigRepository } from '../../src/infrastructure/MultisigRepository' import { Account } from '../../src/model/account/Account'; import { MultisigAccountInfo } from '../../src/model/account/MultisigAccountInfo'; import { NetworkType } from '../../src/model/network/NetworkType'; +import { deepEqual } from 'assert'; describe('MultisigHttp', () => { const networkType = NetworkType.MIJIN_TEST; @@ -36,19 +37,19 @@ describe('MultisigHttp', () => { const account3 = Account.generateNewAccount(networkType); const account4 = Account.generateNewAccount(networkType); - multisigDTO.accountAddress = account.address.plain(); - multisigDTO.accountPublicKey = account.publicKey; - multisigDTO.cosignatoryPublicKeys = [account1.publicKey, account2.publicKey]; + multisigDTO.accountAddress = account.address.encoded(); + multisigDTO.accountAddress = account.address.encoded(); + multisigDTO.cosignatoryAddresses = [account1.address.encoded(), account2.address.encoded()]; multisigDTO.minApproval = 2; multisigDTO.minRemoval = 3; - multisigDTO.multisigPublicKeys = [account3.publicKey, account4.publicKey]; + multisigDTO.multisigAddresses = [account3.address.encoded(), account4.address.encoded()]; accountInfoDto.multisig = multisigDTO; const url = 'http://someHost'; const response: http.IncomingMessage = mock(); const multisigRoutesApi: MultisigRoutesApi = mock(); - const accountRepository: MultisigRepository = DtoMapping.assign(new MultisigHttp(url, networkType), { + const accountRepository: MultisigRepository = DtoMapping.assign(new MultisigHttp(url), { multisigRoutesApi: instance(multisigRoutesApi), }); @@ -60,11 +61,11 @@ describe('MultisigHttp', () => { function assertMultisigInfo(accountInfo: MultisigAccountInfo): void { expect(accountInfo).to.be.not.null; expect(accountInfo.isMultisig()).to.be.equals(true); - expect(accountInfo.account).to.be.deep.equals(account.publicAccount); - expect(accountInfo.cosignatories).to.deep.equals([account1.publicAccount, account2.publicAccount]); + deepEqual(accountInfo.accountAddress, account.address); + expect(accountInfo.cosignatoryAddresses).to.deep.equals([account1.address, account2.address]); expect(accountInfo.minApproval).to.be.equals(multisigDTO.minApproval); expect(accountInfo.minRemoval).to.be.equals(multisigDTO.minRemoval); - expect(accountInfo.multisigAccounts).to.deep.equals([account3.publicAccount, account4.publicAccount]); + expect(accountInfo.multisigAddresses).to.deep.equals([account3.address, account4.address]); } it('getMultisigAccountInfo', async () => { @@ -83,14 +84,14 @@ describe('MultisigHttp', () => { body2.multisigEntries = [accountInfoDto, accountInfoDto]; when(multisigRoutesApi.getAccountMultisigGraph(address.plain())).thenReturn(Promise.resolve({ response, body: [body, body2] })); const graphInfo = await accountRepository.getMultisigAccountGraphInfo(address).toPromise(); - expect(graphInfo.multisigAccounts.size).to.be.eq(2); - const list10: MultisigAccountInfo[] = graphInfo.multisigAccounts.get(10) as MultisigAccountInfo[]; + expect(graphInfo.multisigEntries.size).to.be.eq(2); + const list10: MultisigAccountInfo[] = graphInfo.multisigEntries.get(10) as MultisigAccountInfo[]; expect(list10.length).to.be.eq(3); assertMultisigInfo(list10[0]); assertMultisigInfo(list10[1]); assertMultisigInfo(list10[2]); - const list20: MultisigAccountInfo[] = graphInfo.multisigAccounts.get(20) as MultisigAccountInfo[]; + const list20: MultisigAccountInfo[] = graphInfo.multisigEntries.get(20) as MultisigAccountInfo[]; expect(list20.length).to.be.eq(2); assertMultisigInfo(list20[0]); assertMultisigInfo(list20[1]); diff --git a/test/infrastructure/Page.spec.ts b/test/infrastructure/Page.spec.ts index c2680bd424..44bd4ae5f1 100644 --- a/test/infrastructure/Page.spec.ts +++ b/test/infrastructure/Page.spec.ts @@ -18,9 +18,10 @@ import { expect } from 'chai'; import { Page } from '../../src/infrastructure/infrastructure'; import { Transaction } from '../../src/model/transaction/Transaction'; import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; -import { Deadline, NetworkType } from '../../src/model/model'; import { TestingAccount } from '../conf/conf.spec'; import { PlainMessage } from '../../src/model/message/PlainMessage'; +import { Deadline } from '../../src/model/transaction/Deadline'; +import { NetworkType } from '../../src/model/network/NetworkType'; describe('Page', () => { it('should create Page', () => { diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index 69bc9d2ecb..2f9b5e9416 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -19,7 +19,6 @@ import { sha3_256 } from 'js-sha3'; import { Convert as convert, Convert } from '../../src/core/format'; import { Account } from '../../src/model/account/Account'; import { Address } from '../../src/model/account/Address'; -import { PublicAccount } from '../../src/model/account/PublicAccount'; import { PlainMessage } from '../../src/model/message/PlainMessage'; import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; @@ -52,7 +51,9 @@ import { Crypto } from '../../src/core/crypto'; import { VotingKeyLinkTransaction } from '../../src/model/transaction/VotingKeyLinkTransaction'; import { VrfKeyLinkTransaction } from '../../src/model/transaction/VrfKeyLinkTransaction'; import { NodeKeyLinkTransaction } from '../../src/model/transaction/NodeKeyLinkTransaction'; -import { AddressRestrictionFlag, MosaicRestrictionFlag, OperationRestrictionFlag } from '../../src/model/model'; +import { AddressRestrictionFlag } from '../../src/model/restriction/AddressRestrictionFlag'; +import { MosaicRestrictionFlag } from '../../src/model/restriction/MosaicRestrictionFlag'; +import { OperationRestrictionFlag } from '../../src/model/restriction/OperationRestrictionFlag'; describe('SerializeTransactionToJSON', () => { let account: Account; @@ -76,7 +77,7 @@ describe('SerializeTransactionToJSON', () => { }); it('should create AccountRestrictionAddressTransaction', () => { - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), AddressRestrictionFlag.AllowIncomingAddress, @@ -128,7 +129,7 @@ describe('SerializeTransactionToJSON', () => { it('should create AddressAliasTransaction', () => { const namespaceId = new NamespaceId([33347626, 3779697293]); - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), AliasAction.Link, @@ -215,7 +216,7 @@ describe('SerializeTransactionToJSON', () => { it('should create TransferTransaction', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [NetworkCurrencyLocal.createRelative(100)], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -230,7 +231,7 @@ describe('SerializeTransactionToJSON', () => { it('should create SecretLockTransaction', () => { const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; - const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); + const recipientAddress = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), NetworkCurrencyLocal.createAbsolute(10), @@ -271,7 +272,7 @@ describe('SerializeTransactionToJSON', () => { Deadline.create(), 2, 1, - [PublicAccount.createFromPublicKey('B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24', NetworkType.MIJIN_TEST)], + [Address.createFromPublicKey('B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24', NetworkType.MIJIN_TEST)], [], NetworkType.MIJIN_TEST, ); @@ -286,7 +287,7 @@ describe('SerializeTransactionToJSON', () => { it('should create AggregatedTransaction - Complete', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -308,7 +309,7 @@ describe('SerializeTransactionToJSON', () => { it('should create AggregatedTransaction - Bonded', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, diff --git a/test/infrastructure/TransactionHttp.spec.ts b/test/infrastructure/TransactionHttp.spec.ts index d2cc73f564..1079f85737 100644 --- a/test/infrastructure/TransactionHttp.spec.ts +++ b/test/infrastructure/TransactionHttp.spec.ts @@ -47,7 +47,7 @@ describe('TransactionHttp', () => { it('should return an error when a non aggregate transaction bonded is announced via announceAggregateBonded method', () => { const tx = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SAGY2PTFX4T2XYKYXTJXYCTQRP3FESQH5MEQI2RQ'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('Hi'), NetworkType.MIJIN_TEST, @@ -143,7 +143,7 @@ describe('TransactionHttp', () => { transactionDto.maxFee = '1'; transactionDto.mosaics = []; transactionDto.network = NetworkTypeEnum.NUMBER_104; - transactionDto.recipientAddress = '906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB'; + transactionDto.recipientAddress = '6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144'; transactionDto.type = TransactionType.TRANSFER.valueOf(); transactionDto.version = 1; @@ -175,7 +175,7 @@ describe('TransactionHttp', () => { expect(transactions.data.length).to.be.equal(1); expect(transactions.data[0].type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf()); expect(((transactions.data[0] as TransferTransaction).recipientAddress as Address).plain()).to.be.equal( - Address.createFromEncoded('906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB').plain(), + Address.createFromEncoded('6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144').plain(), ); expect(transactions.data[0].transactionInfo?.id).to.be.equal('id'); expect(transactions.data[0].transactionInfo?.hash).to.be.equal('hash'); diff --git a/test/infrastructure/TransactionSearchCriteria.spec.ts b/test/infrastructure/TransactionSearchCriteria.spec.ts index 4df653c6cc..6c30f06985 100644 --- a/test/infrastructure/TransactionSearchCriteria.spec.ts +++ b/test/infrastructure/TransactionSearchCriteria.spec.ts @@ -18,8 +18,10 @@ import { expect } from 'chai'; import { Order, TransactionGroupSubsetEnum } from 'symbol-openapi-typescript-node-client'; import { TransactionSearchCriteria } from '../../src/infrastructure/searchCriteria/TransactionSearchCriteria'; import { TestingAccount } from '../conf/conf.spec'; -import { UInt64, TransactionType, Address } from '../../src/model/model'; import { deepEqual } from 'assert'; +import { TransactionType } from '../../src/model/transaction/TransactionType'; +import { UInt64 } from '../../src/model/UInt64'; +import { Address } from '../../src/model/account/Address'; describe('TransactionSearchCriteria', () => { const account = TestingAccount; @@ -53,7 +55,7 @@ describe('TransactionSearchCriteria', () => { expect(criteria.signerPublicKey).to.be.equal(account.publicKey); deepEqual(criteria.transactionTypes, [TransactionType.ACCOUNT_ADDRESS_RESTRICTION]); - const address = Address.createFromRawAddress('MCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPR72DYSX'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); criteria = { order: Order.Desc, pageNumber: 2, diff --git a/test/infrastructure/receipt/CreateReceiptFromDTO.spec.ts b/test/infrastructure/receipt/CreateReceiptFromDTO.spec.ts index 8158349ee5..7dba1fd1cb 100644 --- a/test/infrastructure/receipt/CreateReceiptFromDTO.spec.ts +++ b/test/infrastructure/receipt/CreateReceiptFromDTO.spec.ts @@ -28,7 +28,6 @@ import { UInt64 } from '../../../src/model/UInt64'; describe('Receipt - CreateStatementFromDTO', () => { let account: Account; let statementDto; - const netWorkType = NetworkType.MIJIN_TEST; before(() => { account = Account.createFromPrivateKey('D242FB34C2C4DD36E995B9C865F93940065E326661BA5A4A247331D211FE3A3D', NetworkType.MIJIN_TEST); @@ -45,7 +44,7 @@ describe('Receipt - CreateStatementFromDTO', () => { { version: 1, type: 8515, - targetPublicKey: account.publicKey, + targetAddress: account.address.encoded(), mosaicId: '85BBEA6CC462B244', amount: '1000', }, @@ -57,14 +56,14 @@ describe('Receipt - CreateStatementFromDTO', () => { { statement: { height: '1488', - unresolved: '9103B60AAF2762688300000000000000000000000000000000', + unresolved: '9103B60AAF27626883000000000000000000000000000000', resolutionEntries: [ { source: { primaryId: 4, secondaryId: 0, }, - resolved: '917E7E29A01014C2F300000000000000000000000000000000', + resolved: '917E7E29A01014C2F3000000000000000000000000000000', }, ], }, @@ -72,14 +71,14 @@ describe('Receipt - CreateStatementFromDTO', () => { { statement: { height: '1488', - unresolved: '917E7E29A01014C2F300000000000000000000000000000000', + unresolved: '917E7E29A01014C2F3000000000000000000000000000000', resolutionEntries: [ { source: { primaryId: 2, secondaryId: 0, }, - resolved: '9103B60AAF2762688300000000000000000000000000000000', + resolved: '9103B60AAF27626883000000000000000000000000000000', }, ], }, @@ -120,7 +119,7 @@ describe('Receipt - CreateStatementFromDTO', () => { }; }); it('should create Statement', () => { - const statement = CreateStatementFromDTO(statementDto, netWorkType); + const statement = CreateStatementFromDTO(statementDto); const unresolvedAddress = statement.addressResolutionStatements[0].unresolved as NamespaceId; const unresolvedMosaicId = statement.mosaicResolutionStatements[0].unresolved as NamespaceId; @@ -138,7 +137,7 @@ describe('Receipt - CreateStatementFromDTO', () => { deepEqual(unresolvedAddress.toHex(), '83686227AF0AB603'); expect(statement.addressResolutionStatements[0].resolutionEntries.length).to.be.equal(1); expect((statement.addressResolutionStatements[0].resolutionEntries[0].resolved as Address).plain()).to.be.equal( - Address.createFromEncoded('917E7E29A01014C2F300000000000000000000000000000000').plain(), + Address.createFromEncoded('917E7E29A01014C2F3000000000000000000000000000000').plain(), ); deepEqual(statement.mosaicResolutionStatements[0].height, UInt64.fromNumericString('1506')); diff --git a/test/infrastructure/transaction/CreateTransactionFromDTO.spec.ts b/test/infrastructure/transaction/CreateTransactionFromDTO.spec.ts index 838200881d..9987da9874 100644 --- a/test/infrastructure/transaction/CreateTransactionFromDTO.spec.ts +++ b/test/infrastructure/transaction/CreateTransactionFromDTO.spec.ts @@ -40,7 +40,7 @@ describe('CreateTransactionFromDTO', () => { type: 16724, maxFee: '0', deadline: '1000', - recipientAddress: '906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB', + recipientAddress: '6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144', message: { payload: '746573742D6D657373616765', type: 0, @@ -77,7 +77,7 @@ describe('CreateTransactionFromDTO', () => { type: 16724, maxFee: '0', deadline: '1000', - recipientAddress: '906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB', + recipientAddress: '6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144', mosaics: [ { id: '85BBEA6CC462B244', @@ -104,6 +104,7 @@ describe('CreateTransactionFromDTO', () => { transaction: { cosignatures: [ { + version: '0', signature: '5780C8DF9D46BA2BCF029DCC5D3BF55FE1CB5BE7ABCF30387C4637DD' + 'EDFC2152703CA0AD95F21BB9B942F3CC52FCFC2064C7B84CF60D1A9E69195F1943156C07', @@ -136,7 +137,7 @@ describe('CreateTransactionFromDTO', () => { id: '85BBEA6CC462B244', }, ], - recipientAddress: '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142', + recipientAddress: '6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144', signerPublicKey: 'B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF', type: 16724, version: 1, @@ -201,6 +202,7 @@ describe('CreateTransactionFromDTO', () => { transaction: { cosignatures: [ { + version: '0', signature: '5780C8DF9D46BA2BCF029DCC5D3BF55FE1CB5BE7ABCF30387C4637DD' + 'EDFC2152703CA0AD95F21BB9B942F3CC52FCFC2064C7B84CF60D1A9E69195F1943156C07', @@ -292,6 +294,7 @@ describe('CreateTransactionFromDTO', () => { transaction: { cosignatures: [ { + version: '0', signature: '5780C8DF9D46BA2BCF029DCC5D3BF55FE1CB5BE7ABCF30387C4637DD' + 'EDFC2152703CA0AD95F21BB9B942F3CC52FCFC2064C7B84CF60D1A9E69195F1943156C07', @@ -386,6 +389,7 @@ describe('CreateTransactionFromDTO', () => { transaction: { cosignatures: [ { + version: '0', signature: '5780C8DF9D46BA2BCF029DCC5D3BF55FE1CB5BE7ABCF30387C4637DD' + 'EDFC2152703CA0AD95F21BB9B942F3CC52FCFC2064C7B84CF60D1A9E69195F1943156C07', @@ -475,6 +479,7 @@ describe('CreateTransactionFromDTO', () => { transaction: { cosignatures: [ { + version: '0', signature: '5780C8DF9D46BA2BCF029DCC5D3BF55FE1CB5BE7ABCF30387C4637DD' + 'EDFC2152703CA0AD95F21BB9B942F3CC52FCFC2064C7B84CF60D1A9E69195F1943156C07', @@ -534,8 +539,8 @@ describe('CreateTransactionFromDTO', () => { maxFee: '0', minApprovalDelta: 1, minRemovalDelta: 1, - publicKeyAdditions: ['76C1622C7FB58986E500228E8FFB30C606CAAFC1CD78E770E82C73DAB7BD7C9F'], - publicKeyDeletions: [], + addressAdditions: ['6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144'], + addressDeletions: [], signature: '553E696EB4A54E43A11D180EBA57E4B89D0048C9DD2604A9E0608120018B9E0' + '2F6EE63025FEEBCED3293B622AF8581334D0BDAB7541A9E7411E7EE4EF0BC5D0E', @@ -563,6 +568,7 @@ describe('CreateTransactionFromDTO', () => { transaction: { cosignatures: [ { + version: '0', signature: '5780C8DF9D46BA2BCF029DCC5D3BF55FE1CB5BE7ABCF30387C4637DD' + 'EDFC2152703CA0AD95F21BB9B942F3CC52FCFC2064C7B84CF60D1A9E69195F1943156C07', @@ -587,8 +593,8 @@ describe('CreateTransactionFromDTO', () => { transaction: { minApprovalDelta: 1, minRemovalDelta: 1, - publicKeyAdditions: ['589B73FBC22063E9AE6FBAC67CB9C6EA865EF556E5FB8B7310D45F77C1250B97'], - publicKeyDeletions: [], + addressAdditions: ['6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144'], + addressDeletions: [], signerPublicKey: 'B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF', type: 16725, version: 1, diff --git a/test/infrastructure/transaction/ValidateTransaction.ts b/test/infrastructure/transaction/ValidateTransaction.ts index 401a64a24d..1a6c41525d 100644 --- a/test/infrastructure/transaction/ValidateTransaction.ts +++ b/test/infrastructure/transaction/ValidateTransaction.ts @@ -90,8 +90,8 @@ const ValidateTransaction = { expect(modifyMultisigAccountTransaction.minRemovalDelta).to.be.equal( modifyMultisigAccountTransactionDTO.transaction.minRemovalDelta, ); - expect(modifyMultisigAccountTransaction.publicKeyAdditions.length).to.be.equal(1); - expect(modifyMultisigAccountTransaction.publicKeyDeletions.length).to.be.equal(0); + expect(modifyMultisigAccountTransaction.addressAdditions.length).to.be.equal(1); + expect(modifyMultisigAccountTransaction.addressDeletions.length).to.be.equal(0); }, validateNamespaceCreationTx: (registerNamespaceTransaction: any, registerNamespaceTransactionDTO: any): void => { expect(registerNamespaceTransaction.registrationType).to.be.equal(registerNamespaceTransactionDTO.transaction.registrationType); diff --git a/test/model/account/Account.spec.ts b/test/model/account/Account.spec.ts index 7cd414ac86..5041c6bf36 100644 --- a/test/model/account/Account.spec.ts +++ b/test/model/account/Account.spec.ts @@ -28,7 +28,7 @@ import { TransactionMapping } from '../../../src/core/utils/TransactionMapping'; describe('Account', () => { const accountInformation = { - address: 'SDLGYM2CBZKBDGK3VT6KFMUM6HE7LXL2WEQE5JCR', + address: 'SDLGYM2CBZKBDGK3VT6KFMUM6HE7LXL2WEQE5JA', privateKey: '26b64cb10f005e5988a36744ca19e20d835ccc7c105aaa5f3b212da593180930'.toUpperCase(), publicKey: '9801508C58666C746F471538E43002B85B1CD542F9874B2861183919BA8787B6'.toUpperCase(), }; diff --git a/test/model/account/AccountInfo.spec.ts b/test/model/account/AccountInfo.spec.ts index 4a13b54f37..c6e33458b1 100644 --- a/test/model/account/AccountInfo.spec.ts +++ b/test/model/account/AccountInfo.spec.ts @@ -30,12 +30,12 @@ describe('AccountInfo', () => { it('should createComplete an AccountInfo object', () => { const accountInfoDTO = { account: { - address: Address.createFromEncoded('9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'), + address: Address.createFromEncoded('6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144'), addressHeight: new UInt64([1, 0]), importance: new UInt64([405653170, 0]), importanceHeight: new UInt64([6462, 0]), accountType: 0, - supplementalAccountKeys: [{ keyType: 1, key: '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142' }], + supplementalAccountKeys: [{ keyType: 1, key: '6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144' }], activityBucket: [ { startHeight: '1000', @@ -50,7 +50,7 @@ describe('AccountInfo', () => { id: new MosaicId([3646934825, 3576016193]), }, ], - publicKey: '846B4439154579A5903B1459C9CF69CB8153F6D0110A7A0ED61DE29AE4810BF2', + publicKey: '2E834140FD66CF87B254A693A2C7862C819217B676D3943267156625E816EC6F', publicKeyHeight: new UInt64([13, 0]), }, }; @@ -81,6 +81,6 @@ describe('AccountInfo', () => { deepEqual(accountInfo.publicKeyHeight, accountInfoDTO.account.publicKeyHeight); deepEqual(accountInfo.importance, accountInfoDTO.account.importance); deepEqual(accountInfo.importanceHeight, accountInfoDTO.account.importanceHeight); - deepEqual(accountInfo.publicAccount, PublicAccount.createFromPublicKey(accountInfoDTO.account.publicKey, NetworkType.MIJIN_TEST)); + deepEqual(accountInfo.publicAccount, PublicAccount.createFromPublicKey(accountInfoDTO.account.publicKey, NetworkType.MIJIN)); }); }); diff --git a/test/model/account/Address.spec.ts b/test/model/account/Address.spec.ts index 19e49a43d7..b92513d706 100644 --- a/test/model/account/Address.spec.ts +++ b/test/model/account/Address.spec.ts @@ -20,93 +20,93 @@ import { Address } from '../../../src/model/account/Address'; import { NetworkType } from '../../../src/model/network/NetworkType'; describe('Address', () => { - const publicKey = 'c2f93346e27ce6ad1a9f8f5e3066f8326593a406bdf357acb041e2f9ab402efe'.toUpperCase(); + const publicKey = '2E834140FD66CF87B254A693A2C7862C819217B676D3943267156625E816EC6F'; it('createComplete an address given publicKey + NetworkType.MIJIN_TEST', () => { const address = Address.createFromPublicKey(publicKey, NetworkType.MIJIN_TEST); - expect(address.plain()).to.be.equal('SCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPRLIKCF2'); + expect(address.plain()).to.be.equal('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); expect(address.networkType).to.be.equal(NetworkType.MIJIN_TEST); }); it('print the address in pretty format', () => { const address = Address.createFromPublicKey(publicKey, NetworkType.MIJIN_TEST); - expect(address.pretty()).to.be.equal('SCTVW2-3D2MN5-VE4AQ4-TZIDZE-NGNOZX-PRPRLI-KCF2'); + expect(address.pretty()).to.be.equal('SATNE7-Q5BITM-UTRRN6-IB4I7F-LSDRDW-ZA34I2-PMQ'); }); it('createComplete an address given publicKey + NetworkType.MIJIN', () => { const address = Address.createFromPublicKey(publicKey, NetworkType.MIJIN); - expect(address.plain()).to.be.equal('MCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPR72DYSX'); + expect(address.plain()).to.be.equal('MATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34YACRA'); expect(address.networkType).to.be.equal(NetworkType.MIJIN); }); it('createComplete an address given publicKey + NetworkType.MAIN_NET', () => { const address = Address.createFromPublicKey(publicKey, NetworkType.MAIN_NET); - expect(address.plain()).not.to.be.equal('NDD2CT6LQLIYQ56KIXI3ENTM6EK3D44P5JFXJ4R4'); + expect(address.plain()).to.be.equal('NATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34SQ33Y'); expect(address.networkType).to.be.equal(NetworkType.MAIN_NET); }); it('createComplete an address given publicKey + NetworkType.TEST_NET', () => { const address = Address.createFromPublicKey(publicKey, NetworkType.TEST_NET); - expect(address.plain()).not.to.be.equal('TDD2CT6LQLIYQ56KIXI3ENTM6EK3D44P5KZPFMK2'); + expect(address.plain()).to.be.equal('TATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA37JGO5Q'); expect(address.networkType).to.be.equal(NetworkType.TEST_NET); }); - it('createComplete an address given SCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPRLIKCF2', () => { - const address = Address.createFromRawAddress('SCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPRLIKCF2'); + it('createComplete an address given SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ', () => { + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); expect(address.networkType).to.be.equal(NetworkType.MIJIN_TEST); }); - it('createComplete an address given MCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPR72DYSX', () => { - const address = Address.createFromRawAddress('MCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPR72DYSX'); + it('createComplete an address given MATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34YACRA', () => { + const address = Address.createFromRawAddress('MATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34YACRA'); expect(address.networkType).to.be.equal(NetworkType.MIJIN); }); - it('createComplete an address given TCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPSDRSFRF', () => { - const address = Address.createFromRawAddress('NCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPQUJ2ZML'); + it('createComplete an address given NATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34SQ33Y', () => { + const address = Address.createFromRawAddress('NATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34SQ33Y'); expect(address.networkType).to.be.equal(NetworkType.MAIN_NET); }); - it('createComplete an address given TCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPSDRSFRF', () => { - const address = Address.createFromRawAddress('TCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPSDRSFRF'); + it('createComplete an address given TATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA37JGO5Q', () => { + const address = Address.createFromRawAddress('TATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA37JGO5Q'); expect(address.networkType).to.be.equal(NetworkType.TEST_NET); }); - it('createComplete an address given SDRDGF-TDLLCB-67D4HP-GIMIHP-NSRYRJ-RT7DOB-GWZY', () => { - const address = Address.createFromRawAddress('SDRDGF-TDLLCB-67D4HP-GIMIHP-NSRYRJ-RT7DOB-GWZY'); + it('createComplete an address given SATNE7-Q5BITM-UTRRN6-IB4I7F-LSDRDW-ZA34I2-PMQ', () => { + const address = Address.createFromRawAddress('SATNE7-Q5BITM-UTRRN6-IB4I7F-LSDRDW-ZA34I2-PMQ'); expect(address.networkType).to.be.equal(NetworkType.MIJIN_TEST); - expect(address.pretty()).to.be.equal('SDRDGF-TDLLCB-67D4HP-GIMIHP-NSRYRJ-RT7DOB-GWZY'); + expect(address.pretty()).to.be.equal('SATNE7-Q5BITM-UTRRN6-IB4I7F-LSDRDW-ZA34I2-PMQ'); }); it('should throw Error when the address contain an invalid network identifier', () => { expect(() => { - Address.createFromRawAddress('ZCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPSDRSFRF'); + Address.createFromRawAddress('ZCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPSDRSFR'); }).to.throw('Address Network unsupported'); }); it('should throw Error when the address is not valid in length', () => { expect(() => { Address.createFromRawAddress('ZCTVW234AQ4TZIDZENGNOZXPRPSDRSFRF'); - }).to.throw('Address ZCTVW234AQ4TZIDZENGNOZXPRPSDRSFRF has to be 40 characters long'); + }).to.throw('Address ZCTVW234AQ4TZIDZENGNOZXPRPSDRSFRF has to be 39 characters long'); }); it('should turn a lowercase address to uppercase', () => { - const address = Address.createFromRawAddress('tctvw23d2mn5ve4aq4tzidzengnozxprpsdrsfrf'); - expect(address.plain()).to.be.equal('TCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPSDRSFRF'); + const address = Address.createFromRawAddress('tatne7q5bitmutrrn6ib4i7flsdrdwza37jgo5q'); + expect(address.plain()).to.be.equal('TATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA37JGO5Q'); }); it('should equal addresses', () => { - const address = Address.createFromRawAddress('TCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPSDRSFRF'); - const compareAddress = Address.createFromRawAddress('TCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPSDRSFRF'); + const address = Address.createFromRawAddress('TATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA37JGO5Q'); + const compareAddress = Address.createFromRawAddress('TATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA37JGO5Q'); expect(address.equals(compareAddress)).to.be.equal(true); }); it('should not equal addresses', () => { - const address = Address.createFromRawAddress('TCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPSDRSFRF'); - const compareAddress = Address.createFromRawAddress('TCTMW23D2MN5VE4AQ4TZIDZENGNOZXPRPSDRSFRF'); + const address = Address.createFromRawAddress('TATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA37JGO5Q'); + const compareAddress = Address.createFromRawAddress('TDR6EW2WBHJQDYMNGFX2UBZHMMZC5PGL2YBO3KA'); expect(address.equals(compareAddress)).to.be.equal(false); }); it('It creates the address from an encoded value', () => { - const encoded = '917E7E29A01014C2F300000000000000000000000000000000'; + const encoded = '917E7E29A01014C2F3000000000000000000000000000000'; const address = Address.createFromEncoded(encoded); expect(address.encoded()).to.be.equal(encoded); }); @@ -122,7 +122,7 @@ describe('Address', () => { it('returns true for valid address', () => { // Arrange: - const rawAddress = 'SCHCZBZ6QVJAHGJTKYVPW5FBSO2IXXJQBPV5XE6P'; + const rawAddress = 'SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'; // Assert: expect(Address.isValidRawAddress(rawAddress)).to.equal(true); @@ -130,7 +130,7 @@ describe('Address', () => { it('returns false for address with invalid checksum', () => { // Arrange: - const rawAddress = 'SCHCZBZ6QVJAHGJTKYAPW5FBSO2IXXJQBPV5XE6P'; + const rawAddress = 'SATNE7Q5BITMUTRRN6YB4I7FLSDRDWZA34I2PMQ'; // Assert: expect(Address.isValidRawAddress(rawAddress)).to.equal(false); @@ -138,7 +138,7 @@ describe('Address', () => { it('returns false for address with invalid hash', () => { // Arrange: - const rawAddress = 'SCHCZBZ6QVJAHGJTKYVPW5FBSO2IXXJQBPV5XE7P'; + const rawAddress = 'SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PQQ'; // Assert: expect(Address.isValidRawAddress(rawAddress)).to.equal(false); @@ -146,7 +146,7 @@ describe('Address', () => { it('returns false for address with invalid prefix', () => { // Arrange: - const rawAddress = 'ACHCZBZ6QVJAHGJTKYVPW5FBSO2IXXJQBPV5XE6P'; + const rawAddress = 'AATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'; // Assert: expect(Address.isValidRawAddress(rawAddress)).to.equal(false); @@ -164,7 +164,7 @@ describe('Address', () => { it('returns true for valid encoded address', () => { // Arrange: - const encoded = '9085215E4620D383C2DF70235B9EF7507F6A28EF6D16FD7B9C'; + const encoded = '6823BB7C3C089D996585466380EDBDC19D4959184893E38C'; // Assert: expect(Address.isValidEncodedAddress(encoded)).to.equal(true); @@ -172,7 +172,7 @@ describe('Address', () => { it('returns false for invalid hex encoded address', () => { // Arrange: - const encoded = 'Z085215E4620D383C2DF70235B9EF7507F6A28EF6D16FD7B9C'; + const encoded = 'Z823BB7C3C089D996585466380EDBDC19D4959184893E38C'; // Assert: expect(Address.isValidEncodedAddress(encoded)).to.equal(false); @@ -180,7 +180,7 @@ describe('Address', () => { it('returns false for invalid encoded address', () => { // Arrange: changed last char - const encoded = '9085215E4620D383C2DF70235B9EF7507F6A28EF6D16FD7B9D'; + const encoded = '6823BB7C3C089D996585466380EDBDC19D4959184893E38D'; // Assert: expect(Address.isValidEncodedAddress(encoded)).to.equal(false); @@ -188,7 +188,7 @@ describe('Address', () => { it('returns false for encoded address with wrong length', () => { // Arrange: added ABC - const encoded = '9085215E4620D383C2DF70235B9EF7607F6A28EF6D16FD7B9C'; + const encoded = '6823BB7C3C089D996585466380EDBDC19D4959184893E38CEE'; // Assert: expect(Address.isValidEncodedAddress(encoded)).to.equal(false); @@ -196,7 +196,7 @@ describe('Address', () => { it('adding leading or trailing white space invalidates encoded address', () => { // Arrange: - const encoded = '9085215E4620D383C2DF70235B9EF7507F6A28EF6D16FD7B9C'; + const encoded = '6823BB7C3C089D996585466380EDBDC19D4959184893E38C'; // Assert: expect(Address.isValidEncodedAddress(` \t ${encoded}`)).to.equal(false); diff --git a/test/model/account/MultisigAccountGraphInfo.spec.ts b/test/model/account/MultisigAccountGraphInfo.spec.ts index 754e1df419..5733a14aa1 100644 --- a/test/model/account/MultisigAccountGraphInfo.spec.ts +++ b/test/model/account/MultisigAccountGraphInfo.spec.ts @@ -18,8 +18,8 @@ import { deepEqual } from 'assert'; import { expect } from 'chai'; import { MultisigAccountGraphInfo } from '../../../src/model/account/MultisigAccountGraphInfo'; import { MultisigAccountInfo } from '../../../src/model/account/MultisigAccountInfo'; -import { PublicAccount } from '../../../src/model/account/PublicAccount'; import { NetworkType } from '../../../src/model/network/NetworkType'; +import { Address } from '../../../src/model/account/Address'; describe('MultisigAccountGraphInfo', () => { it('should createComplete an MultisigAccountGraphInfo object', () => { @@ -28,28 +28,28 @@ describe('MultisigAccountGraphInfo', () => { multisigEntries: [ { multisig: { - account: PublicAccount.createFromPublicKey( + accountAddress: Address.createFromPublicKey( 'B694186EE4AB0558CA4AFCFDD43B42114AE71094F5A1FC4A913FE9971CACD21D', NetworkType.MIJIN_TEST, ), - cosignatories: [ - PublicAccount.createFromPublicKey( + cosignatoryAddresses: [ + Address.createFromPublicKey( 'CF893FFCC47C33E7F68AB1DB56365C156B0736824A0C1E273F9E00B8DF8F01EB', NetworkType.MIJIN_TEST, ), - PublicAccount.createFromPublicKey( + Address.createFromPublicKey( '68B3FBB18729C1FDE225C57F8CE080FA828F0067E451A3FD81FA628842B0B763', NetworkType.MIJIN_TEST, ), - PublicAccount.createFromPublicKey( + Address.createFromPublicKey( 'DAB1C38C3E1642494FCCB33138B95E81867B5FB59FC4277A1D53761C8B9F6D14', NetworkType.MIJIN_TEST, ), ], minApproval: 3, minRemoval: 3, - multisigAccounts: [ - PublicAccount.createFromPublicKey( + multisigAddresses: [ + Address.createFromPublicKey( '1674016C27FE2C2EB5DFA73996FA54A183B38AED0AA64F756A3918BAF08E061B', NetworkType.MIJIN_TEST, ), @@ -64,35 +64,35 @@ describe('MultisigAccountGraphInfo', () => { multisigAccountGraphInfoDTO.level, multisigAccountGraphInfoDTO.multisigEntries.map((multisigAccountInfoDTO) => { return new MultisigAccountInfo( - multisigAccountInfoDTO.multisig.account, + multisigAccountInfoDTO.multisig.accountAddress, multisigAccountInfoDTO.multisig.minApproval, multisigAccountInfoDTO.multisig.minRemoval, - multisigAccountInfoDTO.multisig.cosignatories, - multisigAccountInfoDTO.multisig.multisigAccounts, + multisigAccountInfoDTO.multisig.cosignatoryAddresses, + multisigAccountInfoDTO.multisig.multisigAddresses, ); }), ); const multisigAccountInfoGraph = new MultisigAccountGraphInfo(multisigAccounts); - expect(multisigAccountInfoGraph.multisigAccounts.get(2)).to.not.be.equal(undefined); - expect(multisigAccountInfoGraph.multisigAccounts.get(1)).to.be.equal(undefined); - expect(multisigAccountInfoGraph.multisigAccounts.get(2)![0].account).to.be.equal( - multisigAccountGraphInfoDTO.multisigEntries[0].multisig.account, + expect(multisigAccountInfoGraph.multisigEntries.get(2)).to.not.be.equal(undefined); + expect(multisigAccountInfoGraph.multisigEntries.get(1)).to.be.equal(undefined); + expect(multisigAccountInfoGraph.multisigEntries.get(2)![0].accountAddress.plain()).to.be.equal( + multisigAccountGraphInfoDTO.multisigEntries[0].multisig.accountAddress.plain(), ); - expect(multisigAccountInfoGraph.multisigAccounts.get(2)![0].minApproval).to.be.equal( + expect(multisigAccountInfoGraph.multisigEntries.get(2)![0].minApproval).to.be.equal( multisigAccountGraphInfoDTO.multisigEntries[0].multisig.minApproval, ); - expect(multisigAccountInfoGraph.multisigAccounts.get(2)![0].minRemoval).to.be.equal( + expect(multisigAccountInfoGraph.multisigEntries.get(2)![0].minRemoval).to.be.equal( multisigAccountGraphInfoDTO.multisigEntries[0].multisig.minRemoval, ); deepEqual( - multisigAccountInfoGraph.multisigAccounts.get(2)![0].cosignatories, - multisigAccountGraphInfoDTO.multisigEntries[0].multisig.cosignatories, + multisigAccountInfoGraph.multisigEntries.get(2)![0].cosignatoryAddresses, + multisigAccountGraphInfoDTO.multisigEntries[0].multisig.cosignatoryAddresses, ); deepEqual( - multisigAccountInfoGraph.multisigAccounts.get(2)![0].multisigAccounts, - multisigAccountGraphInfoDTO.multisigEntries[0].multisig.multisigAccounts, + multisigAccountInfoGraph.multisigEntries.get(2)![0].multisigAddresses, + multisigAccountGraphInfoDTO.multisigEntries[0].multisig.multisigAddresses, ); }); diff --git a/test/model/account/MultisigAccountInfo.spec.ts b/test/model/account/MultisigAccountInfo.spec.ts index 06231d57ca..a32cf7b80d 100644 --- a/test/model/account/MultisigAccountInfo.spec.ts +++ b/test/model/account/MultisigAccountInfo.spec.ts @@ -16,87 +16,75 @@ import { expect } from 'chai'; import { MultisigAccountInfo } from '../../../src/model/account/MultisigAccountInfo'; -import { PublicAccount } from '../../../src/model/account/PublicAccount'; import { NetworkType } from '../../../src/model/network/NetworkType'; +import { Address } from '../../../src/model/account/Address'; describe('MultisigAccountInfo', () => { const multisigAccountInfoDTO = { multisig: { - account: PublicAccount.createFromPublicKey( + accountAddress: Address.createFromPublicKey( 'B694186EE4AB0558CA4AFCFDD43B42114AE71094F5A1FC4A913FE9971CACD21D', NetworkType.MIJIN_TEST, ), - cosignatories: [ - PublicAccount.createFromPublicKey( - 'CF893FFCC47C33E7F68AB1DB56365C156B0736824A0C1E273F9E00B8DF8F01EB', - NetworkType.MIJIN_TEST, - ), - PublicAccount.createFromPublicKey( - '68B3FBB18729C1FDE225C57F8CE080FA828F0067E451A3FD81FA628842B0B763', - NetworkType.MIJIN_TEST, - ), - PublicAccount.createFromPublicKey( - 'DAB1C38C3E1642494FCCB33138B95E81867B5FB59FC4277A1D53761C8B9F6D14', - NetworkType.MIJIN_TEST, - ), + cosignatoryAddresses: [ + Address.createFromPublicKey('CF893FFCC47C33E7F68AB1DB56365C156B0736824A0C1E273F9E00B8DF8F01EB', NetworkType.MIJIN_TEST), + Address.createFromPublicKey('68B3FBB18729C1FDE225C57F8CE080FA828F0067E451A3FD81FA628842B0B763', NetworkType.MIJIN_TEST), + Address.createFromPublicKey('DAB1C38C3E1642494FCCB33138B95E81867B5FB59FC4277A1D53761C8B9F6D14', NetworkType.MIJIN_TEST), ], minApproval: 3, minRemoval: 3, - multisigAccounts: [ - PublicAccount.createFromPublicKey( - '1674016C27FE2C2EB5DFA73996FA54A183B38AED0AA64F756A3918BAF08E061B', - NetworkType.MIJIN_TEST, - ), + multisigAddresses: [ + Address.createFromPublicKey('1674016C27FE2C2EB5DFA73996FA54A183B38AED0AA64F756A3918BAF08E061B', NetworkType.MIJIN_TEST), ], }, }; it('should createComplete an MultisigAccountInfo object', () => { const multisigAccountInfo = new MultisigAccountInfo( - multisigAccountInfoDTO.multisig.account, + multisigAccountInfoDTO.multisig.accountAddress, multisigAccountInfoDTO.multisig.minApproval, multisigAccountInfoDTO.multisig.minRemoval, - multisigAccountInfoDTO.multisig.cosignatories, - multisigAccountInfoDTO.multisig.multisigAccounts, + multisigAccountInfoDTO.multisig.cosignatoryAddresses, + multisigAccountInfoDTO.multisig.multisigAddresses, ); - expect(multisigAccountInfo.account).to.be.equal(multisigAccountInfoDTO.multisig.account); + expect(multisigAccountInfo.accountAddress).to.be.equal(multisigAccountInfoDTO.multisig.accountAddress); expect(multisigAccountInfo.minApproval).to.be.equal(multisigAccountInfoDTO.multisig.minApproval); expect(multisigAccountInfo.minRemoval).to.be.equal(multisigAccountInfoDTO.multisig.minRemoval); - expect(multisigAccountInfo.cosignatories).to.be.equal(multisigAccountInfoDTO.multisig.cosignatories); - expect(multisigAccountInfo.multisigAccounts).to.be.equal(multisigAccountInfoDTO.multisig.multisigAccounts); + expect(multisigAccountInfo.cosignatoryAddresses).to.be.equal(multisigAccountInfoDTO.multisig.cosignatoryAddresses); + expect(multisigAccountInfo.multisigAddresses).to.be.equal(multisigAccountInfoDTO.multisig.multisigAddresses); }); describe('isMultisig', () => { it('should return true when it has minApproval different to 0', () => { const multisigAccountInfo = new MultisigAccountInfo( - multisigAccountInfoDTO.multisig.account, + multisigAccountInfoDTO.multisig.accountAddress, 1, multisigAccountInfoDTO.multisig.minRemoval, - multisigAccountInfoDTO.multisig.cosignatories, - multisigAccountInfoDTO.multisig.multisigAccounts, + multisigAccountInfoDTO.multisig.cosignatoryAddresses, + multisigAccountInfoDTO.multisig.multisigAddresses, ); expect(multisigAccountInfo.isMultisig()).to.be.equal(true); }); it('should return true when it has minRemoval different to 0', () => { const multisigAccountInfo = new MultisigAccountInfo( - multisigAccountInfoDTO.multisig.account, + multisigAccountInfoDTO.multisig.accountAddress, multisigAccountInfoDTO.multisig.minApproval, 1, - multisigAccountInfoDTO.multisig.cosignatories, - multisigAccountInfoDTO.multisig.multisigAccounts, + multisigAccountInfoDTO.multisig.cosignatoryAddresses, + multisigAccountInfoDTO.multisig.multisigAddresses, ); expect(multisigAccountInfo.isMultisig()).to.be.equal(true); }); it('should return false when it has minRemoval and minApproval equals to 0', () => { const multisigAccountInfo = new MultisigAccountInfo( - multisigAccountInfoDTO.multisig.account, + multisigAccountInfoDTO.multisig.accountAddress, 0, 0, - multisigAccountInfoDTO.multisig.cosignatories, - multisigAccountInfoDTO.multisig.multisigAccounts, + multisigAccountInfoDTO.multisig.cosignatoryAddresses, + multisigAccountInfoDTO.multisig.multisigAddresses, ); expect(multisigAccountInfo.isMultisig()).to.be.equal(false); }); @@ -105,38 +93,32 @@ describe('MultisigAccountInfo', () => { describe('hasCosigner', () => { it('should return true when account is in the cosignatories list', () => { const multisigAccountInfo = new MultisigAccountInfo( - multisigAccountInfoDTO.multisig.account, + multisigAccountInfoDTO.multisig.accountAddress, multisigAccountInfoDTO.multisig.minApproval, multisigAccountInfoDTO.multisig.minRemoval, - multisigAccountInfoDTO.multisig.cosignatories, - multisigAccountInfoDTO.multisig.multisigAccounts, + multisigAccountInfoDTO.multisig.cosignatoryAddresses, + multisigAccountInfoDTO.multisig.multisigAddresses, ); expect( multisigAccountInfo.hasCosigner( - PublicAccount.createFromPublicKey( - 'CF893FFCC47C33E7F68AB1DB56365C156B0736824A0C1E273F9E00B8DF8F01EB', - NetworkType.MIJIN_TEST, - ), + Address.createFromPublicKey('CF893FFCC47C33E7F68AB1DB56365C156B0736824A0C1E273F9E00B8DF8F01EB', NetworkType.MIJIN_TEST), ), ).to.be.equal(true); }); it('should return false when account is not in the cosignatories list', () => { const multisigAccountInfo = new MultisigAccountInfo( - multisigAccountInfoDTO.multisig.account, + multisigAccountInfoDTO.multisig.accountAddress, multisigAccountInfoDTO.multisig.minApproval, multisigAccountInfoDTO.multisig.minRemoval, - multisigAccountInfoDTO.multisig.cosignatories, - multisigAccountInfoDTO.multisig.multisigAccounts, + multisigAccountInfoDTO.multisig.cosignatoryAddresses, + multisigAccountInfoDTO.multisig.multisigAddresses, ); expect( multisigAccountInfo.hasCosigner( - PublicAccount.createFromPublicKey( - 'B694186EE4AB0558CA4AFCFDD43B42114AE71094F5A1FC4A913FE9971CACD21D', - NetworkType.MIJIN_TEST, - ), + Address.createFromPublicKey('B694186EE4AB0558CA4AFCFDD43B42114AE71094F5A1FC4A913FE9971CACD21D', NetworkType.MIJIN_TEST), ), ).to.be.equal(false); }); @@ -145,38 +127,32 @@ describe('MultisigAccountInfo', () => { describe('isCosignerOfMultisigAccount', () => { it('should return true when account is in the multisig account list', () => { const multisigAccountInfo = new MultisigAccountInfo( - multisigAccountInfoDTO.multisig.account, + multisigAccountInfoDTO.multisig.accountAddress, multisigAccountInfoDTO.multisig.minApproval, multisigAccountInfoDTO.multisig.minRemoval, - multisigAccountInfoDTO.multisig.cosignatories, - multisigAccountInfoDTO.multisig.multisigAccounts, + multisigAccountInfoDTO.multisig.cosignatoryAddresses, + multisigAccountInfoDTO.multisig.multisigAddresses, ); expect( multisigAccountInfo.isCosignerOfMultisigAccount( - PublicAccount.createFromPublicKey( - '1674016C27FE2C2EB5DFA73996FA54A183B38AED0AA64F756A3918BAF08E061B', - NetworkType.MIJIN_TEST, - ), + Address.createFromPublicKey('1674016C27FE2C2EB5DFA73996FA54A183B38AED0AA64F756A3918BAF08E061B', NetworkType.MIJIN_TEST), ), ).to.be.equal(true); }); it('should return false when account is not in the multisig account list', () => { const multisigAccountInfo = new MultisigAccountInfo( - multisigAccountInfoDTO.multisig.account, + multisigAccountInfoDTO.multisig.accountAddress, multisigAccountInfoDTO.multisig.minApproval, multisigAccountInfoDTO.multisig.minRemoval, - multisigAccountInfoDTO.multisig.cosignatories, - multisigAccountInfoDTO.multisig.multisigAccounts, + multisigAccountInfoDTO.multisig.cosignatoryAddresses, + multisigAccountInfoDTO.multisig.multisigAddresses, ); expect( multisigAccountInfo.isCosignerOfMultisigAccount( - PublicAccount.createFromPublicKey( - 'B694186EE4AB0558CA4AFCFDD43B42114AE71094F5A1FC4A913FE9971CACD21D', - NetworkType.MIJIN_TEST, - ), + Address.createFromPublicKey('B694186EE4AB0558CA4AFCFDD43B42114AE71094F5A1FC4A913FE9971CACD21D', NetworkType.MIJIN_TEST), ), ).to.be.equal(false); }); diff --git a/test/model/account/PublicAccount.spec.ts b/test/model/account/PublicAccount.spec.ts index 8f94f31066..559e1efb2b 100644 --- a/test/model/account/PublicAccount.spec.ts +++ b/test/model/account/PublicAccount.spec.ts @@ -25,7 +25,7 @@ describe('PublicAccount', () => { it('should createComplete a public account from public key', () => { const publicAccount = PublicAccount.createFromPublicKey(publicKey, NetworkType.MIJIN_TEST); expect(publicAccount.publicKey).to.be.equal(publicKey); - expect(publicAccount.address.plain()).to.be.equal('SARNASAS2BIAB6LMFA3FPMGBPGIJGK6IJETM3ZSP'); + expect(publicAccount.address.plain()).to.be.equal('SARNASAS2BIAB6LMFA3FPMGBPGIJGK6IJETM3ZQ'); }); }); diff --git a/test/model/blockchain/BlockInfo.spec.ts b/test/model/blockchain/BlockInfo.spec.ts index 0e69727a35..08a5cb53f1 100644 --- a/test/model/blockchain/BlockInfo.spec.ts +++ b/test/model/blockchain/BlockInfo.spec.ts @@ -19,6 +19,7 @@ import { expect } from 'chai'; import { PublicAccount } from '../../../src/model/account/PublicAccount'; import { BlockInfo } from '../../../src/model/blockchain/BlockInfo'; import { UInt64 } from '../../../src/model/UInt64'; +import { Address } from '../../../src/model/account/Address'; describe('BlockInfo', () => { it('should createComplete an BlockInfo object', () => { @@ -39,7 +40,7 @@ describe('BlockInfo', () => { '37351C8244AC166BE6664E3FA954E99A3239AC46E51E2B32CEA1C72DD0851100A7731868' + 'E932E1A9BEF8A27D48E1FFEE401E933EB801824373E7537E51733E0F', signerPublicKey: 'B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF', - beneficiaryPublicKey: 'B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF', + beneficiaryAddress: '6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144', timestamp: new UInt64([0, 0]), type: 32768, version: 1, @@ -78,7 +79,7 @@ describe('BlockInfo', () => { blockDTO.block.proofGamma, blockDTO.block.proofScalar, blockDTO.block.proofVerificationHash, - PublicAccount.createFromPublicKey(blockDTO.block.beneficiaryPublicKey, blockDTO.block.network), + Address.createFromEncoded(blockDTO.block.beneficiaryAddress), blockDTO.meta.numStatements, ); @@ -100,7 +101,7 @@ describe('BlockInfo', () => { expect(blockInfo.blockTransactionsHash).to.be.equal(blockDTO.block.blockTransactionsHash); expect(blockInfo.blockReceiptsHash).to.be.equal(blockDTO.block.blockReceiptsHash); expect(blockInfo.stateHash).to.be.equal(blockDTO.block.stateHash); - expect((blockInfo.beneficiaryPublicKey as PublicAccount).publicKey).to.be.equal(blockDTO.block.beneficiaryPublicKey); + expect(blockInfo.beneficiaryAddress?.plain()).to.be.equal(Address.createFromEncoded(blockDTO.block.beneficiaryAddress).plain()); expect(blockInfo.numStatements).to.be.equal(blockDTO.meta.numStatements); expect(blockInfo.proofGamma).to.be.equal(blockDTO.block.proofGamma); expect(blockInfo.proofScalar).to.be.equal(blockDTO.block.proofScalar); diff --git a/test/model/blockchain/NewBlock.spec.ts b/test/model/blockchain/NewBlock.spec.ts index 630cde69e0..42752bf736 100644 --- a/test/model/blockchain/NewBlock.spec.ts +++ b/test/model/blockchain/NewBlock.spec.ts @@ -19,6 +19,8 @@ import { expect } from 'chai'; import { PublicAccount } from '../../../src/model/account/PublicAccount'; import { UInt64 } from '../../../src/model/UInt64'; import { NewBlock } from '../../../src/model/blockchain/NewBlock'; +import { Address } from '../../../src/model/account/Address'; +import { NetworkType } from '../../../src/model/network/NetworkType'; describe('NewBlock', () => { it('should createComplete an NewBlock object', () => { @@ -38,7 +40,10 @@ describe('NewBlock', () => { '37351C8244AC166BE6664E3FA954E99A3239AC46E51E2B32CEA1C72DD0851100A7731868' + 'E932E1A9BEF8A27D48E1FFEE401E933EB801824373E7537E51733E0F', signerPublicKey: 'B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF', - beneficiaryPublicKey: 'B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF', + beneficiaryAddress: Address.createFromPublicKey( + 'B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF', + NetworkType.MIJIN_TEST, + ).encoded(), timestamp: new UInt64([0, 0]), type: 32768, version: 1, @@ -69,7 +74,7 @@ describe('NewBlock', () => { blockDTO.block.proofGamma, blockDTO.block.proofScalar, blockDTO.block.proofVerificationHash, - PublicAccount.createFromPublicKey(blockDTO.block.beneficiaryPublicKey, blockDTO.block.network), + Address.createFromEncoded(blockDTO.block.beneficiaryAddress), ); expect(blockInfo.hash).to.be.equal(blockDTO.meta.hash); @@ -87,7 +92,7 @@ describe('NewBlock', () => { expect(blockInfo.blockTransactionsHash).to.be.equal(blockDTO.block.blockTransactionsHash); expect(blockInfo.blockReceiptsHash).to.be.equal(blockDTO.block.blockReceiptsHash); expect(blockInfo.stateHash).to.be.equal(blockDTO.block.stateHash); - expect((blockInfo.beneficiaryPublicKey as PublicAccount).publicKey).to.be.equal(blockDTO.block.beneficiaryPublicKey); + expect(blockInfo.beneficiaryAddress?.encoded()).to.be.equal(blockDTO.block.beneficiaryAddress); expect(blockInfo.proofGamma).to.be.equal(blockDTO.block.proofGamma); expect(blockInfo.proofScalar).to.be.equal(blockDTO.block.proofScalar); expect(blockInfo.proofVerificationHash).to.be.equal(blockDTO.block.proofVerificationHash); diff --git a/test/model/message/EncryptedMessage.spec.ts b/test/model/message/EncryptedMessage.spec.ts index 76a5ca57ab..d4057da366 100644 --- a/test/model/message/EncryptedMessage.spec.ts +++ b/test/model/message/EncryptedMessage.spec.ts @@ -17,7 +17,10 @@ import { expect } from 'chai'; import { Account } from '../../../src/model/account/Account'; import { EncryptedMessage } from '../../../src/model/message/EncryptedMessage'; -import { Deadline, NetworkCurrencyLocal, NetworkType, TransferTransaction } from '../../../src/model/model'; +import { NetworkType } from '../../../src/model/network/NetworkType'; +import { Deadline } from '../../../src/model/transaction/Deadline'; +import { TransferTransaction } from '../../../src/model/transaction/TransferTransaction'; +import { NetworkCurrencyLocal } from '../../../src/model/mosaic/NetworkCurrencyLocal'; describe('EncryptedMessage', () => { let sender: Account; diff --git a/test/model/metadata/Metadata.spec.ts b/test/model/metadata/Metadata.spec.ts index ed05e85113..7d7c14203f 100644 --- a/test/model/metadata/Metadata.spec.ts +++ b/test/model/metadata/Metadata.spec.ts @@ -32,8 +32,8 @@ describe('Metadata', () => { it('should createComplete an Metadata object', () => { const metadataEntryDTO = { compositeHash: hash, - senderPublicKey: account.publicKey, - targetPublicKey: account.publicKey, + sourceAddress: account.address, + targetAddress: account.address, scopedMetadataKey: '85BBEA6CC462B244', targetId: undefined, metadataType: 0, @@ -50,8 +50,8 @@ describe('Metadata', () => { metadataDTO.meta.id, new MetadataEntry( metadataDTO.metadataEntry.compositeHash, - metadataDTO.metadataEntry.senderPublicKey, - metadataDTO.metadataEntry.targetPublicKey, + metadataDTO.metadataEntry.sourceAddress, + metadataDTO.metadataEntry.targetAddress, UInt64.fromHex(metadataDTO.metadataEntry.scopedMetadataKey), metadataDTO.metadataEntry.metadataType, metadataDTO.metadataEntry.value, @@ -59,9 +59,9 @@ describe('Metadata', () => { ); deepEqual(metadata.id, '9999'); - deepEqual(metadata.metadataEntry.senderPublicKey, account.publicKey); + deepEqual(metadata.metadataEntry.sourceAddress, account.address); deepEqual(metadata.metadataEntry.compositeHash, hash); - deepEqual(metadata.metadataEntry.targetPublicKey, account.publicKey); + deepEqual(metadata.metadataEntry.targetAddress, account.address); deepEqual(metadata.metadataEntry.scopedMetadataKey, UInt64.fromHex('85BBEA6CC462B244')); deepEqual(metadata.metadataEntry.targetId, undefined); deepEqual(metadata.metadataEntry.metadataType, MetadataType.Account); diff --git a/test/model/metadata/MetadataEntry.spec.ts b/test/model/metadata/MetadataEntry.spec.ts index 26c319f6e3..03ee584462 100644 --- a/test/model/metadata/MetadataEntry.spec.ts +++ b/test/model/metadata/MetadataEntry.spec.ts @@ -18,9 +18,10 @@ import { deepEqual } from 'assert'; import { Account } from '../../../src/model/account/Account'; import { MetadataEntry } from '../../../src/model/metadata/MetadataEntry'; import { MetadataType } from '../../../src/model/metadata/MetadataType'; -import { MosaicId, NamespaceId } from '../../../src/model/model'; import { UInt64 } from '../../../src/model/UInt64'; import { TestingAccount } from '../../conf/conf.spec'; +import { MosaicId } from '../../../src/model/mosaic/MosaicId'; +import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; describe('MetadataEntry', () => { let account: Account; @@ -32,8 +33,8 @@ describe('MetadataEntry', () => { it('should createComplete an Account Metadata object', () => { const metadataEntryDTO = { compositeHash: hash, - senderPublicKey: account.publicKey, - targetPublicKey: account.publicKey, + sourceAddress: account.address, + targetAddress: account.address, scopedMetadataKey: '85BBEA6CC462B244', targetId: undefined, metadataType: 0, @@ -42,16 +43,16 @@ describe('MetadataEntry', () => { const metadata = new MetadataEntry( metadataEntryDTO.compositeHash, - metadataEntryDTO.senderPublicKey, - metadataEntryDTO.targetPublicKey, + metadataEntryDTO.sourceAddress, + metadataEntryDTO.targetAddress, UInt64.fromHex(metadataEntryDTO.scopedMetadataKey), metadataEntryDTO.metadataType, metadataEntryDTO.value, ); - deepEqual(metadata.senderPublicKey, account.publicKey); + deepEqual(metadata.sourceAddress, account.address); deepEqual(metadata.compositeHash, hash); - deepEqual(metadata.targetPublicKey, account.publicKey); + deepEqual(metadata.targetAddress, account.address); deepEqual(metadata.scopedMetadataKey, UInt64.fromHex('85BBEA6CC462B244')); deepEqual(metadata.targetId, undefined); deepEqual(metadata.metadataType, MetadataType.Account); @@ -61,8 +62,8 @@ describe('MetadataEntry', () => { it('should createComplete an Mosaic Metadata object', () => { const metadataEntryDTO = { compositeHash: hash, - senderPublicKey: account.publicKey, - targetPublicKey: account.publicKey, + sourceAddress: account.address, + targetAddress: account.address, scopedMetadataKey: '85BBEA6CC462B244', targetId: '85BBEA6CC462B244', metadataType: 1, @@ -72,17 +73,17 @@ describe('MetadataEntry', () => { const metadata = new MetadataEntry( metadataEntryDTO.compositeHash, - metadataEntryDTO.senderPublicKey, - metadataEntryDTO.targetPublicKey, + metadataEntryDTO.sourceAddress, + metadataEntryDTO.targetAddress, UInt64.fromHex(metadataEntryDTO.scopedMetadataKey), metadataEntryDTO.metadataType, metadataEntryDTO.value, new MosaicId(metadataEntryDTO.targetId), ); - deepEqual(metadata.senderPublicKey, account.publicKey); + deepEqual(metadata.sourceAddress, account.address); deepEqual(metadata.compositeHash, hash); - deepEqual(metadata.targetPublicKey, account.publicKey); + deepEqual(metadata.targetAddress, account.address); deepEqual(metadata.scopedMetadataKey, UInt64.fromHex('85BBEA6CC462B244')); deepEqual((metadata.targetId as MosaicId).toHex(), '85BBEA6CC462B244'); deepEqual(metadata.metadataType, MetadataType.Mosaic); @@ -92,8 +93,8 @@ describe('MetadataEntry', () => { it('should createComplete an Namespace Metadata object', () => { const metadataEntryDTO = { compositeHash: hash, - senderPublicKey: account.publicKey, - targetPublicKey: account.publicKey, + sourceAddress: account.address, + targetAddress: account.address, scopedMetadataKey: '85BBEA6CC462B244', targetId: '85BBEA6CC462B244', metadataType: 2, @@ -102,17 +103,17 @@ describe('MetadataEntry', () => { const metadata = new MetadataEntry( metadataEntryDTO.compositeHash, - metadataEntryDTO.senderPublicKey, - metadataEntryDTO.targetPublicKey, + metadataEntryDTO.sourceAddress, + metadataEntryDTO.targetAddress, UInt64.fromHex(metadataEntryDTO.scopedMetadataKey), metadataEntryDTO.metadataType, metadataEntryDTO.value, NamespaceId.createFromEncoded(metadataEntryDTO.targetId), ); - deepEqual(metadata.senderPublicKey, account.publicKey); + deepEqual(metadata.sourceAddress, account.address); deepEqual(metadata.compositeHash, hash); - deepEqual(metadata.targetPublicKey, account.publicKey); + deepEqual(metadata.targetAddress, account.address); deepEqual(metadata.scopedMetadataKey, UInt64.fromHex('85BBEA6CC462B244')); deepEqual((metadata.targetId as NamespaceId).toHex(), '85BBEA6CC462B244'); deepEqual(metadata.metadataType, MetadataType.Namespace); diff --git a/test/model/mosaic/MosaicAmountView.spec.ts b/test/model/mosaic/MosaicAmountView.spec.ts index 998787ec3e..942a8fa27c 100644 --- a/test/model/mosaic/MosaicAmountView.spec.ts +++ b/test/model/mosaic/MosaicAmountView.spec.ts @@ -15,13 +15,13 @@ */ import { expect } from 'chai'; -import { PublicAccount } from '../../../src/model/account/PublicAccount'; import { MosaicFlags } from '../../../src/model/mosaic/MosaicFlags'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; import { MosaicInfo } from '../../../src/model/mosaic/MosaicInfo'; import { NetworkType } from '../../../src/model/network/NetworkType'; import { UInt64 } from '../../../src/model/UInt64'; import { MosaicAmountView } from '../../../src/service/MosaicAmountView'; +import { Address } from '../../../src/model/account/Address'; describe('MosaicAmountView', () => { let mosaicInfo: MosaicInfo; @@ -32,7 +32,7 @@ describe('MosaicAmountView', () => { new MosaicId([3294802500, 2243684972]), // mosaicId new UInt64([3403414400, 2095475]), // supply new UInt64([1, 0]), // height - PublicAccount.createFromPublicKey('B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF', NetworkType.MIJIN_TEST), + Address.createFromPublicKey('B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF', NetworkType.MIJIN_TEST), 1, // revision MosaicFlags.create(true, true, true), 3, @@ -64,7 +64,7 @@ describe('MosaicAmountView', () => { new MosaicId([3294802500, 2243684972]), // mosaicId new UInt64([3403414400, 2095475]), // supply new UInt64([1, 0]), // height - PublicAccount.createFromPublicKey('B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF', NetworkType.MIJIN_TEST), + Address.createFromPublicKey('B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF', NetworkType.MIJIN_TEST), 1, // revision MosaicFlags.create(true, true, true), 0, diff --git a/test/model/mosaic/MosaicInfo.spec.ts b/test/model/mosaic/MosaicInfo.spec.ts index 10d2e6c7b3..7bbe750b27 100644 --- a/test/model/mosaic/MosaicInfo.spec.ts +++ b/test/model/mosaic/MosaicInfo.spec.ts @@ -16,12 +16,12 @@ import { deepEqual } from 'assert'; import { expect } from 'chai'; -import { PublicAccount } from '../../../src/model/account/PublicAccount'; import { MosaicFlags } from '../../../src/model/mosaic/MosaicFlags'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; import { MosaicInfo } from '../../../src/model/mosaic/MosaicInfo'; import { NetworkType } from '../../../src/model/network/NetworkType'; import { UInt64 } from '../../../src/model/UInt64'; +import { Address } from '../../../src/model/account/Address'; describe('MosaicInfo', () => { const mosaicInfoDTO = { @@ -29,8 +29,8 @@ describe('MosaicInfo', () => { mosaic: { id: new MosaicId([3646934825, 3576016193]), supply: new UInt64([3403414400, 2095475]), - height: new UInt64([1, 0]), - owner: PublicAccount.createFromPublicKey( + startHeight: new UInt64([1, 0]), + ownerAddress: Address.createFromPublicKey( 'B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF', NetworkType.MIJIN_TEST, ), @@ -46,8 +46,8 @@ describe('MosaicInfo', () => { mosaicInfoDTO.id, mosaicInfoDTO.mosaic.id, mosaicInfoDTO.mosaic.supply, - mosaicInfoDTO.mosaic.height, - mosaicInfoDTO.mosaic.owner, + mosaicInfoDTO.mosaic.startHeight, + mosaicInfoDTO.mosaic.ownerAddress, mosaicInfoDTO.mosaic.revision, new MosaicFlags(mosaicInfoDTO.mosaic.flags), mosaicInfoDTO.mosaic.divisibility, @@ -57,8 +57,8 @@ describe('MosaicInfo', () => { deepEqual(mosaicInfo.recordId, mosaicInfoDTO.id); deepEqual(mosaicInfo.id, mosaicInfoDTO.mosaic.id); deepEqual(mosaicInfo.supply, mosaicInfoDTO.mosaic.supply); - deepEqual(mosaicInfo.height, mosaicInfoDTO.mosaic.height); - expect(mosaicInfo.owner).to.be.equal(mosaicInfoDTO.mosaic.owner); + deepEqual(mosaicInfo.startHeight, mosaicInfoDTO.mosaic.startHeight); + expect(mosaicInfo.ownerAddress.equals(mosaicInfoDTO.mosaic.ownerAddress)).to.be.true; deepEqual(mosaicInfo.revision, mosaicInfoDTO.mosaic.revision); expect(mosaicInfo.divisibility).to.be.equal(mosaicInfoDTO.mosaic.divisibility); @@ -71,8 +71,8 @@ describe('MosaicInfo', () => { mosaicInfoDTO.id, mosaicInfoDTO.mosaic.id, mosaicInfoDTO.mosaic.supply, - mosaicInfoDTO.mosaic.height, - mosaicInfoDTO.mosaic.owner, + mosaicInfoDTO.mosaic.startHeight, + mosaicInfoDTO.mosaic.ownerAddress, mosaicInfoDTO.mosaic.revision, new MosaicFlags(mosaicInfoDTO.mosaic.flags), mosaicInfoDTO.mosaic.divisibility, @@ -82,8 +82,8 @@ describe('MosaicInfo', () => { deepEqual(mosaicInfo.recordId, mosaicInfoDTO.id); deepEqual(mosaicInfo.id, mosaicInfoDTO.mosaic.id); deepEqual(mosaicInfo.supply, mosaicInfoDTO.mosaic.supply); - deepEqual(mosaicInfo.height, mosaicInfoDTO.mosaic.height); - expect(mosaicInfo.owner).to.be.equal(mosaicInfoDTO.mosaic.owner); + deepEqual(mosaicInfo.startHeight, mosaicInfoDTO.mosaic.startHeight); + expect(mosaicInfo.ownerAddress.equals(mosaicInfoDTO.mosaic.ownerAddress)).to.be.true; deepEqual(mosaicInfo.revision, mosaicInfoDTO.mosaic.revision); expect(mosaicInfo.divisibility).to.be.equal(mosaicInfoDTO.mosaic.divisibility); @@ -96,8 +96,8 @@ describe('MosaicInfo', () => { mosaicInfoDTO.id, mosaicInfoDTO.mosaic.id, mosaicInfoDTO.mosaic.supply, - mosaicInfoDTO.mosaic.height, - mosaicInfoDTO.mosaic.owner, + mosaicInfoDTO.mosaic.startHeight, + mosaicInfoDTO.mosaic.ownerAddress, mosaicInfoDTO.mosaic.revision, MosaicFlags.create(true, false, false), mosaicInfoDTO.mosaic.divisibility, @@ -111,8 +111,8 @@ describe('MosaicInfo', () => { mosaicInfoDTO.id, mosaicInfoDTO.mosaic.id, mosaicInfoDTO.mosaic.supply, - mosaicInfoDTO.mosaic.height, - mosaicInfoDTO.mosaic.owner, + mosaicInfoDTO.mosaic.startHeight, + mosaicInfoDTO.mosaic.ownerAddress, mosaicInfoDTO.mosaic.revision, MosaicFlags.create(false, false, false), mosaicInfoDTO.mosaic.divisibility, @@ -128,8 +128,8 @@ describe('MosaicInfo', () => { mosaicInfoDTO.id, mosaicInfoDTO.mosaic.id, mosaicInfoDTO.mosaic.supply, - mosaicInfoDTO.mosaic.height, - mosaicInfoDTO.mosaic.owner, + mosaicInfoDTO.mosaic.startHeight, + mosaicInfoDTO.mosaic.ownerAddress, mosaicInfoDTO.mosaic.revision, MosaicFlags.create(false, true, false), mosaicInfoDTO.mosaic.divisibility, @@ -143,8 +143,8 @@ describe('MosaicInfo', () => { mosaicInfoDTO.id, mosaicInfoDTO.mosaic.id, mosaicInfoDTO.mosaic.supply, - mosaicInfoDTO.mosaic.height, - mosaicInfoDTO.mosaic.owner, + mosaicInfoDTO.mosaic.startHeight, + mosaicInfoDTO.mosaic.ownerAddress, mosaicInfoDTO.mosaic.revision, MosaicFlags.create(false, false, false), mosaicInfoDTO.mosaic.divisibility, @@ -160,8 +160,8 @@ describe('MosaicInfo', () => { mosaicInfoDTO.id, mosaicInfoDTO.mosaic.id, mosaicInfoDTO.mosaic.supply, - mosaicInfoDTO.mosaic.height, - mosaicInfoDTO.mosaic.owner, + mosaicInfoDTO.mosaic.startHeight, + mosaicInfoDTO.mosaic.ownerAddress, mosaicInfoDTO.mosaic.revision, MosaicFlags.create(false, false, true), mosaicInfoDTO.mosaic.divisibility, @@ -175,8 +175,8 @@ describe('MosaicInfo', () => { mosaicInfoDTO.id, mosaicInfoDTO.mosaic.id, mosaicInfoDTO.mosaic.supply, - mosaicInfoDTO.mosaic.height, - mosaicInfoDTO.mosaic.owner, + mosaicInfoDTO.mosaic.startHeight, + mosaicInfoDTO.mosaic.ownerAddress, mosaicInfoDTO.mosaic.revision, MosaicFlags.create(false, false, false), mosaicInfoDTO.mosaic.divisibility, diff --git a/test/model/mosaic/MosaicView.spec.ts b/test/model/mosaic/MosaicView.spec.ts index c0b95fb421..89c8e93675 100644 --- a/test/model/mosaic/MosaicView.spec.ts +++ b/test/model/mosaic/MosaicView.spec.ts @@ -22,6 +22,7 @@ import { MosaicInfo } from '../../../src/model/mosaic/MosaicInfo'; import { NetworkType } from '../../../src/model/network/NetworkType'; import { UInt64 } from '../../../src/model/UInt64'; import { MosaicView } from '../../../src/service/MosaicView'; +import { Address } from '../../../src/model/account/Address'; describe('MosaicView', () => { let mosaicInfo: MosaicInfo; @@ -32,7 +33,7 @@ describe('MosaicView', () => { new MosaicId([3294802500, 2243684972]), new UInt64([3403414400, 2095475]), // supply new UInt64([1, 0]), // height - PublicAccount.createFromPublicKey('B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF', NetworkType.MIJIN_TEST), + Address.createFromPublicKey('B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF', NetworkType.MIJIN_TEST), 1, // revision MosaicFlags.create(true, true, true), 2, diff --git a/test/model/namespace/Alias.spec.ts b/test/model/namespace/Alias.spec.ts index 362cb21708..b76e9fe23d 100644 --- a/test/model/namespace/Alias.spec.ts +++ b/test/model/namespace/Alias.spec.ts @@ -29,8 +29,8 @@ describe('Alias', () => { let address2; before(() => { - address = Address.createFromRawAddress('SCTVW23D2MN5VE4AQ4TZIDZENGNOZXPRPRLIKCF2'); - address2 = Address.createFromRawAddress('SARNASAS2BIAB6LMFA3FPMGBPGIJGK6IJETM3ZSP'); + address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); + address2 = Address.createFromRawAddress('SDR6EW2WBHJQDYMNGFX2UBZHMMZC5PGL2Z5UYYY'); mosaicAliasDTO = { type: AliasType.Mosaic, mosaicId: new MosaicId([481110499, 231112638]), diff --git a/test/model/namespace/NamespaceInfo.spec.ts b/test/model/namespace/NamespaceInfo.spec.ts index 7d7a35f793..f9c964538d 100644 --- a/test/model/namespace/NamespaceInfo.spec.ts +++ b/test/model/namespace/NamespaceInfo.spec.ts @@ -16,12 +16,12 @@ import { deepEqual } from 'assert'; import { expect } from 'chai'; -import { PublicAccount } from '../../../src/model/account/PublicAccount'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { NamespaceInfo } from '../../../src/model/namespace/NamespaceInfo'; import { NetworkType } from '../../../src/model/network/NetworkType'; import { UInt64 } from '../../../src/model/UInt64'; +import { Address } from '../../../src/model/account/Address'; describe('NamespaceInfo', () => { let rootNamespaceDTO; @@ -35,7 +35,7 @@ describe('NamespaceInfo', () => { dto.namespace.depth, [dto.namespace.level0], dto.namespace.parentId, - PublicAccount.createFromPublicKey(dto.namespace.owner, NetworkType.MIJIN_TEST), + Address.createFromEncoded(dto.namespace.ownerAddress), dto.namespace.startHeight, dto.namespace.endHeight, dto.namespace.alias, @@ -51,7 +51,7 @@ describe('NamespaceInfo', () => { dto.namespace.depth, [dto.namespace.level0, dto.namespace.level1], dto.namespace.parentId, - PublicAccount.createFromPublicKey(dto.namespace.owner, NetworkType.MIJIN_TEST), + Address.createFromEncoded(dto.namespace.ownerAddress), dto.namespace.startHeight, dto.namespace.endHeight, dto.namespace.alias, @@ -69,7 +69,10 @@ describe('NamespaceInfo', () => { depth: 1, endHeight: new UInt64([4294967295, 4294967295]), level0: new NamespaceId([929036875, 2226345261]), - owner: 'B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF', + ownerAddress: Address.createFromPublicKey( + 'B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF', + NetworkType.MIJIN_TEST, + ).encoded(), parentId: new NamespaceId([0, 0]), startHeight: new UInt64([1, 0]), type: 0, @@ -88,7 +91,10 @@ describe('NamespaceInfo', () => { level0: new NamespaceId([3316183705, 3829351378]), level1: new NamespaceId([1781696705, 4157485863]), parentId: new NamespaceId([3316183705, 3829351378]), - owner: '846B4439154579A5903B1459C9CF69CB8153F6D0110A7A0ED61DE29AE4810BF2', + ownerAddress: Address.createFromPublicKey( + '846B4439154579A5903B1459C9CF69CB8153F6D0110A7A0ED61DE29AE4810BF2', + NetworkType.MIJIN_TEST, + ).encoded(), startHeight: [795, 0], endHeight: [50795, 0], alias: { type: 0 }, @@ -104,7 +110,7 @@ describe('NamespaceInfo', () => { expect(namespaceInfo.metaId).to.be.equal(rootNamespaceDTO.meta.id); expect(namespaceInfo.depth).to.be.equal(rootNamespaceDTO.namespace.depth); deepEqual(namespaceInfo.levels[0], rootNamespaceDTO.namespace.level0); - expect(namespaceInfo.owner.publicKey).to.be.equal(rootNamespaceDTO.namespace.owner); + expect(namespaceInfo.ownerAddress.encoded()).to.be.equal(rootNamespaceDTO.namespace.ownerAddress); deepEqual(namespaceInfo.startHeight, rootNamespaceDTO.namespace.startHeight); deepEqual(namespaceInfo.endHeight, rootNamespaceDTO.namespace.endHeight); expect(namespaceInfo.alias.type).to.be.equal(rootNamespaceDTO.namespace.alias.type); diff --git a/test/model/receipt/Receipt.spec.ts b/test/model/receipt/Receipt.spec.ts index 1f877ccb74..53071c2265 100644 --- a/test/model/receipt/Receipt.spec.ts +++ b/test/model/receipt/Receipt.spec.ts @@ -19,7 +19,6 @@ import { expect } from 'chai'; import { CreateReceiptFromDTO, CreateStatementFromDTO } from '../../../src/infrastructure/receipt/CreateReceiptFromDTO'; import { Account } from '../../../src/model/account/Account'; import { Address } from '../../../src/model/account/Address'; -import { PublicAccount } from '../../../src/model/account/PublicAccount'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { NetworkType } from '../../../src/model/network/NetworkType'; @@ -42,7 +41,6 @@ describe('Receipt', () => { let addressResolutionStatementsDTO; let mosaicResolutionStatementsDTO; let statementDTO; - const netWorkType = NetworkType.MIJIN_TEST; before(() => { account = Account.createFromPrivateKey('D242FB34C2C4DD36E995B9C865F93940065E326661BA5A4A247331D211FE3A3D', NetworkType.MIJIN_TEST); @@ -58,7 +56,7 @@ describe('Receipt', () => { { version: 1, type: 8515, - targetPublicKey: account.publicKey, + targetAddress: account.address.encoded(), mosaicId: '85BBEA6CC462B244', amount: '1000', }, @@ -70,14 +68,14 @@ describe('Receipt', () => { { statement: { height: '1488', - unresolved: '9103B60AAF2762688300000000000000000000000000000000', + unresolved: '9103B60AAF27626883000000000000000000000000000000', resolutionEntries: [ { source: { primaryId: 4, secondaryId: 0, }, - resolved: '917E7E29A01014C2F300000000000000000000000000000000', + resolved: '917E7E29A01014C2F3000000000000000000000000000000', }, ], }, @@ -85,14 +83,14 @@ describe('Receipt', () => { { statement: { height: '1488', - unresolved: '917E7E29A01014C2F300000000000000000000000000000000', + unresolved: '917E7E29A01014C2F3000000000000000000000000000000', resolutionEntries: [ { source: { primaryId: 2, secondaryId: 0, }, - resolved: '9103B60AAF2762688300000000000000000000000000000000', + resolved: '9103B60AAF27626883000000000000000000000000000000', }, ], }, @@ -142,13 +140,13 @@ describe('Receipt', () => { const receiptDTO = { version: 1, type: 4685, - senderPublicKey: account.publicKey, - recipientAddress: '9103B60AAF2762688300000000000000000000000000000000', + senderAddress: account.address.encoded(), + recipientAddress: '9103B60AAF27626883000000000000000000000000000000', mosaicId: '941299B2B7E1291C', amount: '1000', }; const receipt = new BalanceTransferReceipt( - PublicAccount.createFromPublicKey(receiptDTO.senderPublicKey, netWorkType), + Address.createFromEncoded(receiptDTO.senderAddress), Address.createFromEncoded(receiptDTO.recipientAddress), new MosaicId(receiptDTO.mosaicId), UInt64.fromNumericString(receiptDTO.amount), @@ -156,25 +154,26 @@ describe('Receipt', () => { receiptDTO.type, ); + deepEqual(receipt.senderAddress.encoded(), receiptDTO.senderAddress); deepEqual(receipt.amount.toString(), receiptDTO.amount); deepEqual(receipt.mosaicId.toHex(), receiptDTO.mosaicId); deepEqual(receipt.type, ReceiptType.Mosaic_Levy); deepEqual(receipt.version, ReceiptVersion.BALANCE_TRANSFER); - deepEqual(receipt.recipientAddress, Address.createFromEncoded('9103B60AAF2762688300000000000000000000000000000000')); + deepEqual(receipt.recipientAddress, Address.createFromEncoded('9103B60AAF27626883000000000000000000000000000000')); }); it('should createComplete a balance transfer receipt - Mosaic Rental Fee', () => { const receiptDTO = { version: 1, type: 4685, - senderPublicKey: account.publicKey, - recipientAddress: '9103B60AAF2762688300000000000000000000000000000000', + senderAddress: account.address.encoded(), + recipientAddress: '9103B60AAF27626883000000000000000000000000000000', mosaicId: '941299B2B7E1291C', amount: '1000', }; const receipt = new BalanceTransferReceipt( - PublicAccount.createFromPublicKey(receiptDTO.senderPublicKey, netWorkType), + Address.createFromEncoded(receiptDTO.senderAddress), Address.createFromEncoded(receiptDTO.recipientAddress), new MosaicId(receiptDTO.mosaicId), UInt64.fromNumericString(receiptDTO.amount), @@ -182,8 +181,9 @@ describe('Receipt', () => { receiptDTO.type, ); + deepEqual(receipt.senderAddress.encoded(), receiptDTO.senderAddress); deepEqual(receipt.amount.toString(), receiptDTO.amount); - deepEqual(receipt.recipientAddress, Address.createFromEncoded('9103B60AAF2762688300000000000000000000000000000000')); + deepEqual(receipt.recipientAddress, Address.createFromEncoded('9103B60AAF27626883000000000000000000000000000000')); deepEqual(receipt.mosaicId.toHex(), receiptDTO.mosaicId); deepEqual(receipt.type, ReceiptType.Mosaic_Rental_Fee); deepEqual(receipt.version, ReceiptVersion.BALANCE_TRANSFER); @@ -193,20 +193,20 @@ describe('Receipt', () => { const receiptDTO = { version: 1, type: 8515, - targetPublicKey: account.publicKey, + targetAddress: account.address.encoded(), mosaicId: '941299B2B7E1291C', amount: '1000', }; const receipt = new BalanceChangeReceipt( - PublicAccount.createFromPublicKey(receiptDTO.targetPublicKey, netWorkType), + Address.createFromEncoded(receiptDTO.targetAddress), new MosaicId(receiptDTO.mosaicId), UInt64.fromNumericString(receiptDTO.amount), receiptDTO.version, receiptDTO.type, ); - deepEqual(receipt.targetPublicAccount.publicKey, receiptDTO.targetPublicKey); + deepEqual(receipt.targetAddress.encoded(), receiptDTO.targetAddress); deepEqual(receipt.amount.toString(), receiptDTO.amount); deepEqual(receipt.mosaicId.toHex(), receiptDTO.mosaicId); deepEqual(receipt.type, ReceiptType.Harvest_Fee); @@ -217,20 +217,20 @@ describe('Receipt', () => { const receiptDTO = { version: 1, type: 12616, - targetPublicKey: account.publicKey, + targetAddress: account.address.encoded(), mosaicId: '941299B2B7E1291C', amount: '1000', }; const receipt = new BalanceChangeReceipt( - PublicAccount.createFromPublicKey(receiptDTO.targetPublicKey, netWorkType), + Address.createFromEncoded(receiptDTO.targetAddress), new MosaicId(receiptDTO.mosaicId), UInt64.fromNumericString(receiptDTO.amount), receiptDTO.version, receiptDTO.type, ); - deepEqual(receipt.targetPublicAccount.publicKey, receiptDTO.targetPublicKey); + deepEqual(receipt.targetAddress.encoded(), receiptDTO.targetAddress); deepEqual(receipt.amount.toString(), receiptDTO.amount); deepEqual(receipt.mosaicId.toHex().toUpperCase(), receiptDTO.mosaicId); deepEqual(receipt.type, ReceiptType.LockHash_Created); @@ -269,11 +269,11 @@ describe('Receipt', () => { const statement = new TransactionStatement( statementDto.statement.height, new ReceiptSource(statementDto.statement.source.primaryId, statementDto.statement.source.secondaryId), - statementDto.statement.receipts.map((receipt) => CreateReceiptFromDTO(receipt, netWorkType)), + statementDto.statement.receipts.map((receipt) => CreateReceiptFromDTO(receipt)), ); deepEqual(statement.source.primaryId, statementDto.statement.source.primaryId); deepEqual(statement.source.secondaryId, statementDto.statement.source.secondaryId); - deepEqual((statement.receipts[0] as BalanceChangeReceipt).targetPublicAccount.publicKey, account.publicKey); + deepEqual((statement.receipts[0] as BalanceChangeReceipt).targetAddress, account.address); }); it('should createComplete resolution statement - mosaic', () => { @@ -308,11 +308,11 @@ describe('Receipt', () => { ); deepEqual( (statement.unresolved as Address).plain(), - Address.createFromEncoded('9103B60AAF2762688300000000000000000000000000000000').plain(), + Address.createFromEncoded('9103B60AAF27626883000000000000000000000000000000').plain(), ); deepEqual( (statement.resolutionEntries[0].resolved as Address).plain(), - Address.createFromEncoded('917E7E29A01014C2F300000000000000000000000000000000').plain(), + Address.createFromEncoded('917E7E29A01014C2F3000000000000000000000000000000').plain(), ); }); @@ -338,23 +338,23 @@ describe('Receipt', () => { }); it('should generate hash for MosaicResolutionStatement', () => { - const statement = CreateStatementFromDTO(statementDTO, netWorkType); + const statement = CreateStatementFromDTO(statementDTO); const receipt = statement.mosaicResolutionStatements[0]; const hash = receipt.generateHash(NetworkType.MAIN_NET); expect(hash).to.be.equal('DE29FB6356530E5D1FBEE0A84202520C155D882C46EA74456752D6C75F0707B3'); }); it('should generate hash for AddressResolutionStatement', () => { - const statement = CreateStatementFromDTO(statementDTO, netWorkType); + const statement = CreateStatementFromDTO(statementDTO); const receipt = statement.addressResolutionStatements[0]; const hash = receipt.generateHash(NetworkType.MAIN_NET); - expect(hash).to.be.equal('EFE3D51BF14E861E6E219D1ADB5715D132D6AB7481B29726104933E517F7FBCC'); + expect(hash).to.be.equal('AA9B667C37C8A19902F3E1098FCEE681318455551CC2FBE9B81E8FA47007CA79'); }); it('should generate hash for TransactionStatement', () => { - const statement = CreateStatementFromDTO(statementDTO, netWorkType); + const statement = CreateStatementFromDTO(statementDTO); const receipt = statement.transactionStatements[0]; const hash = receipt.generateHash(); - expect(hash).to.be.equal('D84F5C2E4CBFC645FFAEC92A32AEEB22969C3C48296CF77BCD86BE79A300D0CF'); + expect(hash).to.be.equal('E73E67382162C38AED77D5D5D67F96AA590DC12FF13AE263AA50932896AC4801'); }); }); diff --git a/test/model/receipt/ResolutionStatement.spec.ts b/test/model/receipt/ResolutionStatement.spec.ts index 9ddb63b24d..84c9a8becf 100644 --- a/test/model/receipt/ResolutionStatement.spec.ts +++ b/test/model/receipt/ResolutionStatement.spec.ts @@ -17,8 +17,9 @@ import { expect } from 'chai'; import { CreateStatementFromDTO } from '../../../src/infrastructure/receipt/CreateReceiptFromDTO'; import { Account } from '../../../src/model/account/Account'; -import { Address, MosaicId } from '../../../src/model/model'; import { NetworkType } from '../../../src/model/network/NetworkType'; +import { Address } from '../../../src/model/account/Address'; +import { MosaicId } from '../../../src/model/mosaic/MosaicId'; describe('ResolutionStatement', () => { let account: Account; @@ -41,7 +42,7 @@ describe('ResolutionStatement', () => { { version: 1, type: 8515, - targetPublicKey: 'B2708D49C46F8AB5CDBD7A09C959EEA12E4A782592F3D1D3D17D54622E655D7F', + targetAddress: account.address.encoded(), mosaicId: '504677C3281108DB', amount: '0', }, @@ -53,14 +54,14 @@ describe('ResolutionStatement', () => { { statement: { height: '1473', - unresolved: '9156258DE356F030A500000000000000000000000000000000', + unresolved: '9156258DE356F030A5000000000000000000000000000000', resolutionEntries: [ { source: { primaryId: 1, secondaryId: 0, }, - resolved: '90AB9480887275E559F3BCA87E6158AA7AFF339BE85E77A0F3', + resolved: account.address.encoded(), }, ], }, @@ -150,7 +151,7 @@ describe('ResolutionStatement', () => { }); it('should get resolve entry when both primaryId and secondaryId matched', () => { - const statement = CreateStatementFromDTO(statementDTO, NetworkType.MIJIN_TEST); + const statement = CreateStatementFromDTO(statementDTO); const entry = statement.addressResolutionStatements[0].getResolutionEntryById(1, 0); expect(entry!.resolved instanceof Address).to.be.true; @@ -158,7 +159,7 @@ describe('ResolutionStatement', () => { }); it('should get resolved entry when primaryId is greater than max', () => { - const statement = CreateStatementFromDTO(statementDTO, NetworkType.MIJIN_TEST); + const statement = CreateStatementFromDTO(statementDTO); const entry = statement.mosaicResolutionStatements[0].getResolutionEntryById(4, 0); expect(entry!.source.primaryId).to.be.equal(3); expect(entry!.source.secondaryId).to.be.equal(5); @@ -167,7 +168,7 @@ describe('ResolutionStatement', () => { }); it('should get resolved entry when primaryId is in middle of 2 pirmaryIds', () => { - const statement = CreateStatementFromDTO(statementDTO, NetworkType.MIJIN_TEST); + const statement = CreateStatementFromDTO(statementDTO); const entry = statement.mosaicResolutionStatements[0].getResolutionEntryById(2, 1); expect(entry!.source.primaryId).to.be.equal(1); expect(entry!.source.secondaryId).to.be.equal(0); @@ -176,7 +177,7 @@ describe('ResolutionStatement', () => { }); it('should get resolved entry when primaryId matches but not secondaryId', () => { - const statement = CreateStatementFromDTO(statementDTO, NetworkType.MIJIN_TEST); + const statement = CreateStatementFromDTO(statementDTO); const entry = statement.mosaicResolutionStatements[0].getResolutionEntryById(3, 6); expect(entry!.source.primaryId).to.be.equal(3); expect(entry!.source.secondaryId).to.be.equal(5); @@ -185,7 +186,7 @@ describe('ResolutionStatement', () => { }); it('should get resolved entry when primaryId matches but secondaryId less than minimum', () => { - const statement = CreateStatementFromDTO(statementDTO, NetworkType.MIJIN_TEST); + const statement = CreateStatementFromDTO(statementDTO); const entry = statement.mosaicResolutionStatements[0].getResolutionEntryById(3, 1); expect(entry!.source.primaryId).to.be.equal(1); expect(entry!.source.secondaryId).to.be.equal(0); @@ -194,13 +195,13 @@ describe('ResolutionStatement', () => { }); it('should return undefined', () => { - const statement = CreateStatementFromDTO(statementDTO, NetworkType.MIJIN_TEST); + const statement = CreateStatementFromDTO(statementDTO); const entry = statement.addressResolutionStatements[0].getResolutionEntryById(0, 0); expect(entry).to.be.undefined; }); it('resolution change in the block (more than one AGGREGATE)', () => { - const statement = CreateStatementFromDTO(statementDTO, NetworkType.MIJIN_TEST); + const statement = CreateStatementFromDTO(statementDTO); const resolution = statement.mosaicResolutionStatements[2]; expect((resolution.getResolutionEntryById(1, 1)!.resolved as MosaicId).toHex()).to.be.equal('0DC67FBE1CAD29E5'); expect((resolution.getResolutionEntryById(1, 4)!.resolved as MosaicId).toHex()).to.be.equal('7CDF3B117A3C40CC'); diff --git a/test/model/receipt/Statement.spec.ts b/test/model/receipt/Statement.spec.ts index 4969d482fe..45098016c9 100644 --- a/test/model/receipt/Statement.spec.ts +++ b/test/model/receipt/Statement.spec.ts @@ -18,8 +18,10 @@ import { expect } from 'chai'; import { UnresolvedMapping } from '../../../src/core/utils/UnresolvedMapping'; import { CreateStatementFromDTO } from '../../../src/infrastructure/receipt/CreateReceiptFromDTO'; import { Account } from '../../../src/model/account/Account'; -import { Address, MosaicId, NamespaceId } from '../../../src/model/model'; import { NetworkType } from '../../../src/model/network/NetworkType'; +import { Address } from '../../../src/model/account/Address'; +import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; +import { MosaicId } from '../../../src/model/mosaic/MosaicId'; describe('Statement', () => { let account: Account; @@ -42,7 +44,7 @@ describe('Statement', () => { { version: 1, type: 8515, - targetPublicKey: 'B2708D49C46F8AB5CDBD7A09C959EEA12E4A782592F3D1D3D17D54622E655D7F', + targetAddress: '6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144', mosaicId: '504677C3281108DB', amount: '0', }, @@ -54,14 +56,14 @@ describe('Statement', () => { { statement: { height: '1473', - unresolved: '9156258DE356F030A500000000000000000000000000000000', + unresolved: '9156258DE356F030A5000000000000000000000000000000', resolutionEntries: [ { source: { primaryId: 1, secondaryId: 0, }, - resolved: '90AB9480887275E559F3BCA87E6158AA7AFF339BE85E77A0F3', + resolved: account.address.encoded(), }, ], }, @@ -108,8 +110,8 @@ describe('Statement', () => { }); it('should get resolved address from receipt', () => { - const unresolvedAddress = UnresolvedMapping.toUnresolvedAddress('9156258DE356F030A500000000000000000000000000000000'); - const statement = CreateStatementFromDTO(statementDTO, NetworkType.MIJIN_TEST); + const unresolvedAddress = UnresolvedMapping.toUnresolvedAddress('9156258DE356F030A5000000000000000000000000000000'); + const statement = CreateStatementFromDTO(statementDTO); const resolved = statement.resolveAddress(unresolvedAddress as NamespaceId, '1473', 0); expect(resolved instanceof Address).to.be.true; @@ -123,14 +125,14 @@ describe('Statement', () => { { statement: { height: '1473', - unresolved: '9156258DE356F030A500000000000000000000000000000000', + unresolved: '9156258DE356F030A5000000000000000000000000000000', resolutionEntries: [ { source: { primaryId: 1, secondaryId: 0, }, - resolved: '90AB9480887275E559F3BCA87E6158AA7AFF339BE85E77A0F3', + resolved: account.address.encoded(), }, ], }, @@ -138,8 +140,8 @@ describe('Statement', () => { ], mosaicResolutionStatements: [], }; - const unresolvedAddress = UnresolvedMapping.toUnresolvedAddress('9156258DE356F030A500000000000000000000000000000000'); - const statement = CreateStatementFromDTO(statementWithoutHarvesting, NetworkType.MIJIN_TEST); + const unresolvedAddress = UnresolvedMapping.toUnresolvedAddress('9156258DE356F030A5000000000000000000000000000000'); + const statement = CreateStatementFromDTO(statementWithoutHarvesting); const resolved = statement.resolveAddress(unresolvedAddress as NamespaceId, '1473', 0); expect(resolved instanceof Address).to.be.true; @@ -148,7 +150,7 @@ describe('Statement', () => { it('should get resolved mosaic from receipt', () => { const unresolvedMosaic = UnresolvedMapping.toUnresolvedMosaic('E81F622A5B11A340'); - const statement = CreateStatementFromDTO(statementDTO, NetworkType.MIJIN_TEST); + const statement = CreateStatementFromDTO(statementDTO); const resolved = statement.resolveMosaicId(unresolvedMosaic as NamespaceId, '1473', 0); expect(resolved instanceof MosaicId).to.be.true; @@ -193,7 +195,7 @@ describe('Statement', () => { ], }; const unresolvedMosaic = UnresolvedMapping.toUnresolvedMosaic('E81F622A5B11A340'); - const statement = CreateStatementFromDTO(statementWithoutHarvesting, NetworkType.MIJIN_TEST); + const statement = CreateStatementFromDTO(statementWithoutHarvesting); const resolved = statement.resolveMosaicId(unresolvedMosaic as NamespaceId, '1473', 0); expect(resolved instanceof MosaicId).to.be.true; diff --git a/test/model/restriction/AccountRestriction.spec.ts b/test/model/restriction/AccountRestriction.spec.ts index 910cca61a7..03ed8bd806 100644 --- a/test/model/restriction/AccountRestriction.spec.ts +++ b/test/model/restriction/AccountRestriction.spec.ts @@ -18,12 +18,12 @@ import { deepEqual } from 'assert'; import { expect } from 'chai'; import { Address } from '../../../src/model/account/Address'; import { AccountRestriction } from '../../../src/model/restriction/AccountRestriction'; -import { AddressRestrictionFlag } from '../../../src/model/model'; +import { AddressRestrictionFlag } from '../../../src/model/restriction/AddressRestrictionFlag'; describe('AccountRestriction', () => { it('should createComplete an AccountRestriction object', () => { const accountRestrictionDTO = { restrictionFlags: AddressRestrictionFlag.AllowIncomingAddress, - values: ['906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB'], + values: ['6826D27E1D0A26CA4E316F901E23E55C8711DB20DF250DEF'], }; const accountRestriction = new AccountRestriction( diff --git a/test/model/restriction/AccountRestrictions.spec.ts b/test/model/restriction/AccountRestrictions.spec.ts index 0fc5c9f8fd..249a1e276c 100644 --- a/test/model/restriction/AccountRestrictions.spec.ts +++ b/test/model/restriction/AccountRestrictions.spec.ts @@ -20,19 +20,19 @@ import { Address } from '../../../src/model/account/Address'; import { AccountRestriction } from '../../../src/model/restriction/AccountRestriction'; import { AccountRestrictionModificationAction } from '../../../src/model/restriction/AccountRestrictionModificationAction'; import { AccountRestrictions } from '../../../src/model/restriction/AccountRestrictions'; -import { AddressRestrictionFlag } from '../../../src/model/model'; +import { AddressRestrictionFlag } from '../../../src/model/restriction/AddressRestrictionFlag'; describe('AccountRestrictions', () => { it('should createComplete an AccountRestrictions object', () => { const accountRestrictionsDTO = { - address: Address.createFromEncoded('9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'), + address: Address.createFromEncoded('6826D27E1D0A26CA4E316F901E23E55C8711DB20DF250DEF'), restrictions: [ { restrictionFlags: AddressRestrictionFlag.AllowIncomingAddress, values: [ { modificationAction: AccountRestrictionModificationAction.Add, - value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', + value: 'SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ', }, ], }, diff --git a/test/model/restriction/AccountRestrictionsInfo.spec.ts b/test/model/restriction/AccountRestrictionsInfo.spec.ts index eba41e521b..6270752a92 100644 --- a/test/model/restriction/AccountRestrictionsInfo.spec.ts +++ b/test/model/restriction/AccountRestrictionsInfo.spec.ts @@ -20,21 +20,21 @@ import { AccountRestriction } from '../../../src/model/restriction/AccountRestri import { AccountRestrictionModificationAction } from '../../../src/model/restriction/AccountRestrictionModificationAction'; import { AccountRestrictions } from '../../../src/model/restriction/AccountRestrictions'; import { AccountRestrictionsInfo } from '../../../src/model/restriction/AccountRestrictionsInfo'; -import { AddressRestrictionFlag } from '../../../src/model/model'; +import { AddressRestrictionFlag } from '../../../src/model/restriction/AddressRestrictionFlag'; describe('AccountRestrictionsInfo', () => { it('should createComplete an AccountRestrictionsInfo object', () => { const accountRestrictionsInfoDTO = { meta: { id: '12345' }, accountRestrictions: { - address: '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142', + address: '6826D27E1D0A26CA4E316F901E23E55C8711DB20DF250DEF', restrictions: [ { restrictionFlags: AddressRestrictionFlag.AllowIncomingAddress, values: [ { modificationAction: AccountRestrictionModificationAction.Add, - value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM', + value: 'SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ', }, ], }, diff --git a/test/model/restriction/MosaicRestriction.spec.ts b/test/model/restriction/MosaicRestriction.spec.ts index f07864e240..2448aa1f13 100644 --- a/test/model/restriction/MosaicRestriction.spec.ts +++ b/test/model/restriction/MosaicRestriction.spec.ts @@ -31,7 +31,7 @@ describe('MosaicRestrictions', () => { compositeHash: hash, entryType: 0, mosaicId: '85BBEA6CC462B244', - targetAddress: '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142', + targetAddress: '6826D27E1D0A26CA4E316F901E23E55C8711DB20DF250DEF', restrictions: [ { key: 'testKey', @@ -54,7 +54,7 @@ describe('MosaicRestrictions', () => { expect(mosaicAddressRestriction.compositeHash).to.be.equal(hash); expect(mosaicAddressRestriction.entryType).to.be.equal(MosaicRestrictionEntryType.ADDRESS); expect(mosaicAddressRestriction.targetAddress.plain()).to.be.equal( - Address.createFromEncoded('9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142').plain(), + Address.createFromEncoded('6826D27E1D0A26CA4E316F901E23E55C8711DB20DF250DEF').plain(), ); expect(mosaicAddressRestriction.restrictions.size).to.be.equal(1); expect(mosaicAddressRestriction.restrictions.get('testKey')).to.not.be.equal(undefined); diff --git a/test/model/transaction/AccountKeyLinkTransaction.spec.ts b/test/model/transaction/AccountKeyLinkTransaction.spec.ts index f82427a38c..8fd7474d57 100644 --- a/test/model/transaction/AccountKeyLinkTransaction.spec.ts +++ b/test/model/transaction/AccountKeyLinkTransaction.spec.ts @@ -124,7 +124,7 @@ describe('AccountKeyLinkTransaction', () => { let canNotify = tx.shouldNotifyAccount(account.address); expect(canNotify).to.be.true; - canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKB')); + canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ')); expect(canNotify).to.be.false; Object.assign(tx, { signer: account.publicAccount }); diff --git a/test/model/transaction/AccountMetadataTransaction.spec.ts b/test/model/transaction/AccountMetadataTransaction.spec.ts index d3ae7ddf9e..2e67a3b67e 100644 --- a/test/model/transaction/AccountMetadataTransaction.spec.ts +++ b/test/model/transaction/AccountMetadataTransaction.spec.ts @@ -26,6 +26,7 @@ import { EmbeddedTransactionBuilder } from 'catbuffer-typescript/dist/EmbeddedTr import { TransactionType } from '../../../src/model/transaction/TransactionType'; import { deepEqual } from 'assert'; import { Address } from '../../../src/model/account/Address'; +import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; describe('AccountMetadataTransaction', () => { let account: Account; @@ -37,7 +38,7 @@ describe('AccountMetadataTransaction', () => { it('should default maxFee field be set to 0', () => { const accountMetadataTransaction = AccountMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), 1, Convert.uint8ToUtf8(new Uint8Array(10)), @@ -51,7 +52,7 @@ describe('AccountMetadataTransaction', () => { it('should filled maxFee override transaction maxFee', () => { const accountMetadataTransaction = AccountMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), 1, Convert.uint8ToUtf8(new Uint8Array(10)), @@ -66,7 +67,7 @@ describe('AccountMetadataTransaction', () => { it('should create and sign an AccountMetadataTransaction object', () => { const accountMetadataTransaction = AccountMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), 1, Convert.uint8ToUtf8(new Uint8Array(10)), @@ -76,15 +77,15 @@ describe('AccountMetadataTransaction', () => { const signedTransaction = accountMetadataTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '9801508C58666C746F471538E43002B85B1CD542F9874B2861183919BA8787B6E80300000000000001000A0000000000000000000000', + '90D66C33420E5411995BACFCA2B28CF1C9F5DD7AB1204EA4E80300000000000001000A0000000000000000000000', ); }); describe('size', () => { - it('should return 182 for AccountMetadataTransaction byte size', () => { + it('should return 174 for AccountMetadataTransaction byte size', () => { const accountMetadataTransaction = AccountMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), 1, Convert.uint8ToUtf8(new Uint8Array(10)), @@ -92,7 +93,7 @@ describe('AccountMetadataTransaction', () => { ); expect(Convert.hexToUint8(accountMetadataTransaction.serialize()).length).to.be.equal(accountMetadataTransaction.size); - expect(accountMetadataTransaction.size).to.be.equal(182); + expect(accountMetadataTransaction.size).to.be.equal(174); const signedTransaction = accountMetadataTransaction.signWith(account, generationHash); expect(signedTransaction.hash).not.to.be.undefined; @@ -102,7 +103,7 @@ describe('AccountMetadataTransaction', () => { it('should create EmbeddedTransactionBuilder', () => { const accountMetadataTransaction = AccountMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), 1, Convert.uint8ToUtf8(new Uint8Array(10)), @@ -121,7 +122,7 @@ describe('AccountMetadataTransaction', () => { it('should resolve alias', () => { const accountMetadataTransaction = AccountMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), 1, Convert.uint8ToUtf8(new Uint8Array(10)), @@ -137,20 +138,42 @@ describe('AccountMetadataTransaction', () => { it('Notify Account', () => { const tx = AccountMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), 1, Convert.uint8ToUtf8(new Uint8Array(10)), NetworkType.MIJIN_TEST, ); - let canNotify = tx.shouldNotifyAccount(account.address); + let canNotify = tx.shouldNotifyAccount(account.address, []); expect(canNotify).to.be.true; - canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKB')); + canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), []); expect(canNotify).to.be.false; Object.assign(tx, { signer: account.publicAccount }); - expect(tx.shouldNotifyAccount(account.address)).to.be.true; + expect(tx.shouldNotifyAccount(account.address, [])).to.be.true; + }); + + it('Notify Account with alias', () => { + const alias = new NamespaceId('test'); + const wrongAlias = new NamespaceId('wrong'); + const tx = AccountMetadataTransaction.create( + Deadline.create(), + account.address, + UInt64.fromUint(1000), + 1, + Convert.uint8ToUtf8(new Uint8Array(10)), + NetworkType.MIJIN_TEST, + ); + + let canNotify = tx.shouldNotifyAccount(account.address, [alias]); + expect(canNotify).to.be.true; + + canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [wrongAlias]); + expect(canNotify).to.be.false; + + Object.assign(tx, { signer: account.publicAccount }); + expect(tx.shouldNotifyAccount(account.address, [])).to.be.true; }); }); diff --git a/test/model/transaction/AccountRestrictionTransaction.spec.ts b/test/model/transaction/AccountRestrictionTransaction.spec.ts index 2cbe20c443..ceab6751b8 100644 --- a/test/model/transaction/AccountRestrictionTransaction.spec.ts +++ b/test/model/transaction/AccountRestrictionTransaction.spec.ts @@ -28,7 +28,9 @@ import { TransactionType } from '../../../src/model/transaction/TransactionType' import { UInt64 } from '../../../src/model/UInt64'; import { TestingAccount } from '../../conf/conf.spec'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; -import { AddressRestrictionFlag, OperationRestrictionFlag, MosaicRestrictionFlag } from '../../../src/model/model'; +import { AddressRestrictionFlag } from '../../../src/model/restriction/AddressRestrictionFlag'; +import { OperationRestrictionFlag } from '../../../src/model/restriction/OperationRestrictionFlag'; +import { MosaicRestrictionFlag } from '../../../src/model/restriction/MosaicRestrictionFlag'; describe('AccountRestrictionTransaction', () => { let account: Account; @@ -37,7 +39,7 @@ describe('AccountRestrictionTransaction', () => { account = TestingAccount; }); it('should create address restriction filter', () => { - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const addressRestrictionFilter = AccountRestrictionModification.createForAddress(AccountRestrictionModificationAction.Add, address); expect(addressRestrictionFilter.modificationAction).to.be.equal(AccountRestrictionModificationAction.Add); expect(addressRestrictionFilter.value).to.be.equal(address.plain()); @@ -62,8 +64,8 @@ describe('AccountRestrictionTransaction', () => { }); describe('size', () => { - it('should return 161 for AccountAddressRestrictionTransaction transaction byte size with 1 modification', () => { - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + it('should return 160 for AccountAddressRestrictionTransaction transaction byte size with 1 modification', () => { + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), AddressRestrictionFlag.AllowIncomingAddress, @@ -73,7 +75,7 @@ describe('AccountRestrictionTransaction', () => { ); expect(Convert.hexToUint8(addressRestrictionTransaction.serialize()).length).to.be.equal(addressRestrictionTransaction.size); - expect(addressRestrictionTransaction.size).to.be.equal(161); + expect(addressRestrictionTransaction.size).to.be.equal(160); }); it('should return 144 for AccountMosaicRestrictionTransaction transaction byte size with 1 modification', () => { @@ -102,7 +104,7 @@ describe('AccountRestrictionTransaction', () => { }); it('should default maxFee field be set to 0', () => { - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), AddressRestrictionFlag.AllowIncomingAddress, @@ -116,7 +118,7 @@ describe('AccountRestrictionTransaction', () => { }); it('should filled maxFee override transaction maxFee', () => { - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), AddressRestrictionFlag.AllowIncomingAddress, @@ -131,7 +133,7 @@ describe('AccountRestrictionTransaction', () => { }); it('should create allow incmoing address restriction transaction', () => { - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), AddressRestrictionFlag.AllowIncomingAddress, @@ -143,7 +145,7 @@ describe('AccountRestrictionTransaction', () => { const signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '01000100000000009050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142', + '01000100000000009026D27E1D0A26CA4E316F901E23E55C8711DB20DF11A7B2', ); }); @@ -178,7 +180,7 @@ describe('AccountRestrictionTransaction', () => { }); it('should create outgoing address restriction transaction', () => { - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); let addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), AddressRestrictionFlag.AllowOutgoingAddress, @@ -190,7 +192,7 @@ describe('AccountRestrictionTransaction', () => { let signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '01400100000000009050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142', + '01400100000000009026D27E1D0A26CA4E316F901E23E55C8711DB20DF11A7B2', ); addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( @@ -204,7 +206,7 @@ describe('AccountRestrictionTransaction', () => { signedTransaction = addressRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '01C00100000000009050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142', + '01C00100000000009026D27E1D0A26CA4E316F901E23E55C8711DB20DF11A7B2', ); }); @@ -236,7 +238,7 @@ describe('AccountRestrictionTransaction', () => { }); it('Notify Account', () => { - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const tx = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), AddressRestrictionFlag.AllowOutgoingAddress, @@ -247,7 +249,7 @@ describe('AccountRestrictionTransaction', () => { let canNotify = tx.shouldNotifyAccount(address, []); expect(canNotify).to.be.true; - canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKB'), []); + canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SDR6EW2WBHJQDYMNGFX2UBZHMMZC5PGL2Z5UYYY'), []); expect(canNotify).to.be.false; Object.assign(tx, { signer: account.publicAccount }); @@ -263,7 +265,7 @@ describe('AccountRestrictionTransaction', () => { let canNotifyDeletion = txDeletion.shouldNotifyAccount(address, []); expect(canNotifyDeletion).to.be.true; - canNotifyDeletion = txDeletion.shouldNotifyAccount(Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKB'), []); + canNotifyDeletion = txDeletion.shouldNotifyAccount(Address.createFromRawAddress('SDR6EW2WBHJQDYMNGFX2UBZHMMZC5PGL2Z5UYYY'), []); expect(canNotifyDeletion).to.be.false; Object.assign(txDeletion, { signer: account.publicAccount }); @@ -271,18 +273,19 @@ describe('AccountRestrictionTransaction', () => { }); it('Notify Account with alias', () => { - const address = new NamespaceId('test'); + const alias = new NamespaceId('test'); + const wrongAlias = new NamespaceId('wrong'); const tx = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction( Deadline.create(), AddressRestrictionFlag.AllowOutgoingAddress, - [address], + [alias], [], NetworkType.MIJIN_TEST, ); - let canNotify = tx.shouldNotifyAccount(account.address, [address]); + let canNotify = tx.shouldNotifyAccount(account.address, [alias]); expect(canNotify).to.be.true; - canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKB'), []); + canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [wrongAlias]); expect(canNotify).to.be.false; Object.assign(tx, { signer: account.publicAccount }); @@ -292,13 +295,15 @@ describe('AccountRestrictionTransaction', () => { Deadline.create(), AddressRestrictionFlag.AllowOutgoingAddress, [], - [address], + [alias], NetworkType.MIJIN_TEST, ); - let canNotifyDeletion = txDeletion.shouldNotifyAccount(account.address, [address]); + let canNotifyDeletion = txDeletion.shouldNotifyAccount(account.address, [alias]); expect(canNotifyDeletion).to.be.true; - canNotifyDeletion = txDeletion.shouldNotifyAccount(Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKB'), []); + canNotifyDeletion = txDeletion.shouldNotifyAccount(Address.createFromRawAddress('SDR6EW2WBHJQDYMNGFX2UBZHMMZC5PGL2Z5UYYY'), [ + wrongAlias, + ]); expect(canNotifyDeletion).to.be.false; Object.assign(txDeletion, { signer: account.publicAccount }); diff --git a/test/model/transaction/AddressAliasTransaction.spec.ts b/test/model/transaction/AddressAliasTransaction.spec.ts index 9310250550..1a57b96b4d 100644 --- a/test/model/transaction/AddressAliasTransaction.spec.ts +++ b/test/model/transaction/AddressAliasTransaction.spec.ts @@ -35,7 +35,7 @@ describe('AddressAliasTransaction', () => { it('should default maxFee field be set to 0', () => { const namespaceId = new NamespaceId([33347626, 3779697293]); - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), AliasAction.Link, @@ -50,7 +50,7 @@ describe('AddressAliasTransaction', () => { it('should filled maxFee override transaction maxFee', () => { const namespaceId = new NamespaceId([33347626, 3779697293]); - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), AliasAction.Link, @@ -66,7 +66,7 @@ describe('AddressAliasTransaction', () => { it('should createComplete an AddressAliasTransaction object and sign it', () => { const namespaceId = new NamespaceId([33347626, 3779697293]); - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), AliasAction.Link, @@ -78,19 +78,19 @@ describe('AddressAliasTransaction', () => { expect(addressAliasTransaction.aliasAction).to.be.equal(AliasAction.Link); expect(addressAliasTransaction.namespaceId.id.lower).to.be.equal(33347626); expect(addressAliasTransaction.namespaceId.id.higher).to.be.equal(3779697293); - expect(addressAliasTransaction.address.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + expect(addressAliasTransaction.address.plain()).to.be.equal('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const signedTransaction = addressAliasTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '2AD8FC018D9A49E19050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E14201', + '2AD8FC018D9A49E19026D27E1D0A26CA4E316F901E23E55C8711DB20DF11A7B201', ); }); describe('size', () => { - it('should return 162 for AggregateTransaction byte size with TransferTransaction with 1 mosaic and message NEM', () => { + it('should return 161 for AggregateTransaction byte size with TransferTransaction with 1 mosaic and message NEM', () => { const namespaceId = new NamespaceId([33347626, 3779697293]); - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), AliasAction.Link, @@ -99,13 +99,13 @@ describe('AddressAliasTransaction', () => { NetworkType.MIJIN_TEST, ); expect(Convert.hexToUint8(addressAliasTransaction.serialize()).length).to.be.equal(addressAliasTransaction.size); - expect(addressAliasTransaction.size).to.be.equal(162); + expect(addressAliasTransaction.size).to.be.equal(161); }); }); it('Test set maxFee using multiplier', () => { const namespaceId = new NamespaceId([33347626, 3779697293]); - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), AliasAction.Link, @@ -113,18 +113,18 @@ describe('AddressAliasTransaction', () => { address, NetworkType.MIJIN_TEST, ).setMaxFee(2); - expect(addressAliasTransaction.maxFee.compact()).to.be.equal(324); + expect(addressAliasTransaction.maxFee.compact()).to.be.equal(322); }); it('Notify Account', () => { const namespaceId = new NamespaceId([33347626, 3779697293]); - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const tx = AddressAliasTransaction.create(Deadline.create(), AliasAction.Link, namespaceId, address, NetworkType.MIJIN_TEST); let canNotify = tx.shouldNotifyAccount(address); expect(canNotify).to.be.true; - canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKB')); + canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SDR6EW2WBHJQDYMNGFX2UBZHMMZC5PGL2Z5UYYY')); expect(canNotify).to.be.false; Object.assign(tx, { signer: account.publicAccount }); diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index 9b2ddbfe2c..2ef2511f20 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -81,7 +81,7 @@ describe('AggregateTransaction', () => { it('should default maxFee field be set to 0', () => { const transferTransaction = TransferTransaction.create( Deadline.create(1, ChronoUnit.HOURS), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -101,7 +101,7 @@ describe('AggregateTransaction', () => { it('should filled maxFee override transaction maxFee', () => { const transferTransaction = TransferTransaction.create( Deadline.create(1, ChronoUnit.HOURS), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -122,7 +122,7 @@ describe('AggregateTransaction', () => { it('should createComplete an AggregateTransaction object with TransferTransaction', () => { const transferTransaction = TransferTransaction.create( Deadline.create(1, ChronoUnit.HOURS), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -138,7 +138,7 @@ describe('AggregateTransaction', () => { const signedTransaction = aggregateTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(0, 8)).to.be.equal('08010000'); expect(signedTransaction.payload.substring(424, signedTransaction.payload.length)).to.be.equal( - '019054419050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142000D000000000000746573742D6D657373616765000000', + '019054419026D27E1D0A26CA4E316F901E23E55C8711DB20DF11A7B20D0000000000000000746573742D6D657373616765000000', ); }); @@ -225,14 +225,8 @@ describe('AggregateTransaction', () => { 2, 1, [ - PublicAccount.createFromPublicKey( - 'B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24', - NetworkType.MIJIN_TEST, - ), - PublicAccount.createFromPublicKey( - 'B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4', - NetworkType.MIJIN_TEST, - ), + Address.createFromPublicKey('B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24', NetworkType.MIJIN_TEST), + Address.createFromPublicKey('B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4', NetworkType.MIJIN_TEST), ], [], NetworkType.MIJIN_TEST, @@ -246,18 +240,17 @@ describe('AggregateTransaction', () => { const signedTransaction = aggregateTransaction.signWith(account, generationHash); - expect(signedTransaction.payload.substring(0, 8)).to.be.equal('20010000'); - expect(signedTransaction.payload.substring(320, 352)).to.be.equal('78000000000000007800000000000000'); + expect(signedTransaction.payload.substring(0, 8)).to.be.equal('10010000'); + expect(signedTransaction.payload.substring(320, 352)).to.be.equal('68000000000000006800000000000000'); expect(signedTransaction.payload.substring(424, signedTransaction.payload.length)).to.be.equal( - '019055410102020000000000B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6' + - 'EC24B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4', + '019055410102020000000000909FC4844A5206CFA44603EFA1FFC76FE9B0564D967FFE0D906B4CB49ECF224FC4F0F4FCA2F6034305B3A47B0BB90303', ); }); it('should createComplete an AggregateTransaction object with different cosignatories', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -274,18 +267,18 @@ describe('AggregateTransaction', () => { generationHash, ); - expect(signedTransaction.payload.substring(0, 8)).to.be.equal('68010000'); + expect(signedTransaction.payload.substring(0, 8)).to.be.equal('70010000'); expect(signedTransaction.payload.substring(320, 352)).to.be.equal('60000000000000005D00000000000000'); expect(signedTransaction.payload.substring(424, 424 + 162)).to.be.equal( - '019054419050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142000D000000000000746573' + - '742D6D657373616765000000F9D6329A1A927F5D8918D3D313524CF179DE126AF8F0E83F0FBF2782B5', + '019054419026D27E1D0A26CA4E316F901E23E55C8711DB20DF11A7B20D0000000000000000746573742D6D657373616' + + '7650000000000000000000000F9D6329A1A927F5D8918D3D313524CF179DE126AF8', ); }); it('should createBonded an AggregateTransaction object with TransferTransaction', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -304,7 +297,7 @@ describe('AggregateTransaction', () => { expect(signedTransaction.payload.substring(320, 352)).to.be.equal('60000000000000005D00000000000000'); expect(signedTransaction.payload.substring(220, 224)).to.be.equal('4142'); expect(signedTransaction.payload.substring(424, signedTransaction.payload.length)).to.be.equal( - '019054419050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142000D000000000000746573742D6D657373616765000000', + '019054419026D27E1D0A26CA4E316F901E23E55C8711DB20DF11A7B20D0000000000000000746573742D6D657373616765000000', ); }); @@ -320,6 +313,7 @@ describe('AggregateTransaction', () => { transaction: { cosignatures: [ { + version: '0', signature: '5780C8DF9D46BA2BCF029DCC5D3BF55FE1CB5BE7ABCF30387C4637DD' + 'EDFC2152703CA0AD95F21BB9B942F3CC52FCFC2064C7B84CF60D1A9E69195F1943156C07', @@ -411,7 +405,7 @@ describe('AggregateTransaction', () => { it('should throw exception when adding an aggregated transaction as inner transaction', () => { const transferTransaction = TransferTransaction.create( Deadline.create(1, ChronoUnit.HOURS), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -563,6 +557,7 @@ describe('AggregateTransaction', () => { // add cosignature after creation const signedTransaction = aggregateTransaction.signWith(account, generationHash); const cosignature = new AggregateTransactionCosignature( + UInt64.fromUint(0), signedTransaction.payload, PublicAccount.createFromPublicKey(signedTransaction.signerPublicKey, NetworkType.MIJIN_TEST), ); @@ -577,7 +572,7 @@ describe('AggregateTransaction', () => { it('should return 268 for AggregateTransaction byte size with TransferTransaction with 1 mosaic and message NEM', () => { const transaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [NetworkCurrencyLocal.createRelative(100)], PlainMessage.create('NEM'), NetworkType.MIJIN_TEST, @@ -686,7 +681,7 @@ describe('AggregateTransaction', () => { let canNotify = tx.shouldNotifyAccount(account.address, []); expect(canNotify).to.be.true; - canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKB'), []); + canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), []); expect(canNotify).to.be.false; Object.assign(tx, { signer: account.publicAccount }); @@ -707,12 +702,12 @@ describe('AggregateTransaction', () => { NetworkType.MIJIN_TEST, [], ); - let canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKB'), [ + let canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [ unresolvedAddress, ]); expect(canNotify).to.be.true; - canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKB'), []); + canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), []); expect(canNotify).to.be.false; Object.assign(tx, { signer: account.publicAccount }); diff --git a/test/model/transaction/CosignatureTransaction.spec.ts b/test/model/transaction/CosignatureTransaction.spec.ts index 5dcdc6f501..7d097895b8 100644 --- a/test/model/transaction/CosignatureTransaction.spec.ts +++ b/test/model/transaction/CosignatureTransaction.spec.ts @@ -44,6 +44,7 @@ describe('CosignatureTransaction', () => { transaction: { cosignatures: [ { + version: '0', signature: '5780C8DF9D46BA2BCF029DCC5D3BF55FE1CB5BE7ABCF30387C4637DD' + 'EDFC2152703CA0AD95F21BB9B942F3CC52FCFC2064C7B84CF60D1A9E69195F1943156C07', @@ -76,7 +77,7 @@ describe('CosignatureTransaction', () => { id: '85BBEA6CC462B244', }, ], - recipientAddress: '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142', + recipientAddress: '6823BB7C3C089D996585466380EDBDC19D4959184893E38C', signerPublicKey: 'B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF', type: 16724, version: 36865, diff --git a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts index 3bca4254f6..0c97a7a916 100644 --- a/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts +++ b/test/model/transaction/MosaicAddressRestrictionTransaction.spec.ts @@ -76,7 +76,7 @@ describe('MosaicAddressRestrictionTransaction', () => { const signedTransaction = mosaicAddressRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '010000000000000001000000000000000900000000000000080' + '000000000000090D66C33420E5411995BACFCA2B28CF1C9F5DD7AB1204EA451', + '010000000000000001000000000000000900000000000000080000000000000090D66C33420E5411995BACFCA2B28CF1C9F5DD7AB1204EA4', ); }); @@ -100,7 +100,7 @@ describe('MosaicAddressRestrictionTransaction', () => { const signedTransaction = mosaicAddressRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - 'C51FB4C93FCA509501000000000000000900000000000000080000000000' + '000090D66C33420E5411995BACFCA2B28CF1C9F5DD7AB1204EA451', + 'C51FB4C93FCA509501000000000000000900000000000000080000000000000090D66C33420E5411995BACFCA2B28CF1C9F5DD7AB1204EA4', ); }); @@ -125,7 +125,7 @@ describe('MosaicAddressRestrictionTransaction', () => { const signedTransaction = mosaicAddressRestrictionTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '01000000000000000100000000000000090000000000000008000000000' + '0000091C51FB4C93FCA509500000000000000000000000000000000', + '010000000000000001000000000000000900000000000000080000000000000091C51FB4C93FCA5095000000000000000000000000000000', ); }); @@ -160,7 +160,7 @@ describe('MosaicAddressRestrictionTransaction', () => { NetworkType.MIJIN_TEST, UInt64.fromUint(9), ).setMaxFee(2); - expect(transaction.maxFee.compact()).to.be.equal(370); + expect(transaction.maxFee.compact()).to.be.equal(368); const signedTransaction = transaction.signWith(account, generationHash); expect(signedTransaction.hash).not.to.be.undefined; diff --git a/test/model/transaction/MosaicMetadataTransaction.spec.ts b/test/model/transaction/MosaicMetadataTransaction.spec.ts index 966300059e..0c638a02f3 100644 --- a/test/model/transaction/MosaicMetadataTransaction.spec.ts +++ b/test/model/transaction/MosaicMetadataTransaction.spec.ts @@ -31,7 +31,8 @@ import { TransactionInfo } from '../../../src/model/transaction/TransactionInfo' import { UInt64 } from '../../../src/model/UInt64'; import { TestingAccount } from '../../conf/conf.spec'; import { EmbeddedTransactionBuilder } from 'catbuffer-typescript'; -import { TransactionType, Address } from '../../../src/model/model'; +import { Address } from '../../../src/model/account/Address'; +import { TransactionType } from '../../../src/model/transaction/TransactionType'; describe('MosaicMetadataTransaction', () => { let account: Account; @@ -55,7 +56,7 @@ describe('MosaicMetadataTransaction', () => { it('should default maxFee field be set to 0', () => { const mosaicMetadataTransaction = MosaicMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new MosaicId([2262289484, 3405110546]), 1, @@ -70,7 +71,7 @@ describe('MosaicMetadataTransaction', () => { it('should filled maxFee override transaction maxFee', () => { const mosaicMetadataTransaction = MosaicMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new MosaicId([2262289484, 3405110546]), 1, @@ -86,7 +87,7 @@ describe('MosaicMetadataTransaction', () => { it('should create and sign an MosaicMetadataTransaction object', () => { const mosaicMetadataTransaction = MosaicMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new MosaicId([2262289484, 3405110546]), 1, @@ -97,8 +98,7 @@ describe('MosaicMetadataTransaction', () => { const signedTransaction = mosaicMetadataTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '9801508C58666C746F471538E43002B85B1CD542F9874B2861183919BA8' + - '787B6E8030000000000004CCCD78612DDF5CA01000A0000000000000000000000', + '90D66C33420E5411995BACFCA2B28CF1C9F5DD7AB1204EA4E8030000000000004CCCD78612DDF5CA01000A0000000000000000000000', ); }); @@ -106,7 +106,7 @@ describe('MosaicMetadataTransaction', () => { const namespacId = NamespaceId.createFromEncoded('9550CA3FC9B41FC5'); const mosaicMetadataTransaction = MosaicMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), namespacId, 1, @@ -117,23 +117,22 @@ describe('MosaicMetadataTransaction', () => { const signedTransaction = mosaicMetadataTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '9801508C58666C746F471538E43002B85B1CD542F9874B2861183919BA878' + - '7B6E803000000000000C51FB4C93FCA509501000A0000000000000000000000', + '90D66C33420E5411995BACFCA2B28CF1C9F5DD7AB1204EA4E803000000000000C51FB4C93FCA509501000A0000000000000000000000', ); }); describe('size', () => { - it('should return 190 for MosaicMetadataTransaction byte size', () => { + it('should return 182 for MosaicMetadataTransaction byte size', () => { const mosaicMetadataTransaction = MosaicMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new MosaicId([2262289484, 3405110546]), 1, Convert.uint8ToUtf8(new Uint8Array(10)), NetworkType.MIJIN_TEST, ); - expect(mosaicMetadataTransaction.size).to.be.equal(190); + expect(mosaicMetadataTransaction.size).to.be.equal(182); expect(Convert.hexToUint8(mosaicMetadataTransaction.serialize()).length).to.be.equal(mosaicMetadataTransaction.size); }); }); @@ -141,14 +140,14 @@ describe('MosaicMetadataTransaction', () => { it('Test set maxFee using multiplier', () => { const mosaicMetadataTransaction = MosaicMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new MosaicId([2262289484, 3405110546]), 1, Convert.uint8ToUtf8(new Uint8Array(10)), NetworkType.MIJIN_TEST, ).setMaxFee(2); - expect(mosaicMetadataTransaction.maxFee.compact()).to.be.equal(380); + expect(mosaicMetadataTransaction.maxFee.compact()).to.be.equal(364); const signedTransaction = mosaicMetadataTransaction.signWith(account, generationHash); expect(signedTransaction.hash).not.to.be.undefined; @@ -160,7 +159,7 @@ describe('MosaicMetadataTransaction', () => { 1, Deadline.createFromDTO('1'), UInt64.fromUint(0), - account.publicKey, + account.address, UInt64.fromUint(1000), unresolvedMosaicId, 10, @@ -179,7 +178,7 @@ describe('MosaicMetadataTransaction', () => { it('should create EmbeddedTransactionBuilder', () => { const mosaicMetadataTransaction = MosaicMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new MosaicId([2262289484, 3405110546]), 1, @@ -199,20 +198,42 @@ describe('MosaicMetadataTransaction', () => { it('Notify Account', () => { const tx = MosaicMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new MosaicId([2262289484, 3405110546]), 1, Convert.uint8ToUtf8(new Uint8Array(10)), NetworkType.MIJIN_TEST, ); - let canNotify = tx.shouldNotifyAccount(account.address); + let canNotify = tx.shouldNotifyAccount(account.address, []); expect(canNotify).to.be.true; - canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKB')); + canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), []); expect(canNotify).to.be.false; Object.assign(tx, { signer: account.publicAccount }); - expect(tx.shouldNotifyAccount(account.address)).to.be.true; + expect(tx.shouldNotifyAccount(account.address, [])).to.be.true; + }); + + it('Notify Account with alias', () => { + const alias = new NamespaceId('test'); + const wrongAlias = new NamespaceId('wrong'); + const tx = MosaicMetadataTransaction.create( + Deadline.create(), + alias, + UInt64.fromUint(1000), + new MosaicId([2262289484, 3405110546]), + 1, + Convert.uint8ToUtf8(new Uint8Array(10)), + NetworkType.MIJIN_TEST, + ); + let canNotify = tx.shouldNotifyAccount(account.address, [alias]); + expect(canNotify).to.be.true; + + canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [wrongAlias]); + expect(canNotify).to.be.false; + + Object.assign(tx, { signer: account.publicAccount }); + expect(tx.shouldNotifyAccount(account.address, [])).to.be.true; }); }); diff --git a/test/model/transaction/MultisigAccountModificationTransaction.spec.ts b/test/model/transaction/MultisigAccountModificationTransaction.spec.ts index a8cb4885bd..f888410f31 100644 --- a/test/model/transaction/MultisigAccountModificationTransaction.spec.ts +++ b/test/model/transaction/MultisigAccountModificationTransaction.spec.ts @@ -17,17 +17,25 @@ import { expect } from 'chai'; import { Convert } from '../../../src/core/format'; import { Account } from '../../../src/model/account/Account'; -import { PublicAccount } from '../../../src/model/account/PublicAccount'; import { NetworkType } from '../../../src/model/network/NetworkType'; import { Deadline } from '../../../src/model/transaction/Deadline'; import { MultisigAccountModificationTransaction } from '../../../src/model/transaction/MultisigAccountModificationTransaction'; import { UInt64 } from '../../../src/model/UInt64'; import { TestingAccount } from '../../conf/conf.spec'; import { Address } from '../../../src/model/account/Address'; +import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; describe('MultisigAccountModificationTransaction', () => { let account: Account; const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; + const address1 = Address.createFromPublicKey( + 'B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24', + NetworkType.MIJIN_TEST, + ); + const address2 = Address.createFromPublicKey( + 'B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4', + NetworkType.MIJIN_TEST, + ); before(() => { account = TestingAccount; }); @@ -37,16 +45,7 @@ describe('MultisigAccountModificationTransaction', () => { Deadline.create(), 2, 1, - [ - PublicAccount.createFromPublicKey( - 'B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24', - NetworkType.MIJIN_TEST, - ), - PublicAccount.createFromPublicKey( - 'B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4', - NetworkType.MIJIN_TEST, - ), - ], + [address1, address2], [], NetworkType.MIJIN_TEST, ); @@ -60,16 +59,7 @@ describe('MultisigAccountModificationTransaction', () => { Deadline.create(), 2, 1, - [ - PublicAccount.createFromPublicKey( - 'B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24', - NetworkType.MIJIN_TEST, - ), - PublicAccount.createFromPublicKey( - 'B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4', - NetworkType.MIJIN_TEST, - ), - ], + [address1, address2], [], NetworkType.MIJIN_TEST, new UInt64([1, 0]), @@ -84,55 +74,36 @@ describe('MultisigAccountModificationTransaction', () => { Deadline.create(), 2, 1, - [ - PublicAccount.createFromPublicKey( - 'B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24', - NetworkType.MIJIN_TEST, - ), - PublicAccount.createFromPublicKey( - 'B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4', - NetworkType.MIJIN_TEST, - ), - ], + [address1, address2], [], NetworkType.MIJIN_TEST, ); expect(modifyMultisigAccountTransaction.minApprovalDelta).to.be.equal(2); expect(modifyMultisigAccountTransaction.minRemovalDelta).to.be.equal(1); - expect(modifyMultisigAccountTransaction.publicKeyAdditions.length).to.be.equal(2); - expect(modifyMultisigAccountTransaction.publicKeyAdditions[0].publicKey).to.be.equal( - 'B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24', - ); - expect(modifyMultisigAccountTransaction.publicKeyAdditions[1].publicKey).to.be.equal( - 'B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4', - ); - expect(modifyMultisigAccountTransaction.publicKeyDeletions.length).to.be.equal(0); + expect(modifyMultisigAccountTransaction.addressAdditions.length).to.be.equal(2); + expect(modifyMultisigAccountTransaction.addressAdditions[0].equals(address1)).to.be.true; + expect(modifyMultisigAccountTransaction.addressAdditions[1].equals(address2)).to.be.true; + expect(modifyMultisigAccountTransaction.addressDeletions.length).to.be.equal(0); const signedTransaction = modifyMultisigAccountTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '0102020000000000B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC' + - '6EC24B1B5581FC81A6970DEE418D2C2978F2724228B7B36C5C6DF71B0162BB04778B4', + '0102020000000000909FC4844A5206CFA44603EFA1FFC76FE9B0564D967FFE0D906B4CB49ECF224FC4F0F4FCA2F6034305B3A47B0BB90303', ); }); describe('size', () => { - it('should return 168 for MultisigAccountModificationTransaction transaction byte size with 1 modification', () => { + it('should return 160 for MultisigAccountModificationTransaction transaction byte size with 1 modification', () => { const modifyMultisigAccountTransaction = MultisigAccountModificationTransaction.create( Deadline.create(), 1, 1, - [ - PublicAccount.createFromPublicKey( - 'B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24', - NetworkType.MIJIN_TEST, - ), - ], + [address1], [], NetworkType.MIJIN_TEST, ); - expect(modifyMultisigAccountTransaction.size).to.be.equal(168); + expect(modifyMultisigAccountTransaction.size).to.be.equal(160); expect(Convert.hexToUint8(modifyMultisigAccountTransaction.serialize()).length).to.be.equal( modifyMultisigAccountTransaction.size, ); @@ -144,55 +115,73 @@ describe('MultisigAccountModificationTransaction', () => { Deadline.create(), 1, 1, - [PublicAccount.createFromPublicKey('B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24', NetworkType.MIJIN_TEST)], + [address1], [], NetworkType.MIJIN_TEST, ).setMaxFee(2); - expect(modifyMultisigAccountTransaction.maxFee.compact()).to.be.equal(336); + expect(modifyMultisigAccountTransaction.maxFee.compact()).to.be.equal(320); const signedTransaction = modifyMultisigAccountTransaction.signWith(account, generationHash); expect(signedTransaction.hash).not.to.be.undefined; }); it('Notify Account', () => { - const publicAccount = PublicAccount.createFromPublicKey( - 'B0F93CBEE49EEB9953C6F3985B15A4F238E205584D8F924C621CBE4D7AC6EC24', - NetworkType.MIJIN_TEST, - ); - const txAddition = MultisigAccountModificationTransaction.create( - Deadline.create(), - 1, - 1, - [publicAccount], - [], - NetworkType.MIJIN_TEST, - ); + const txAddition = MultisigAccountModificationTransaction.create(Deadline.create(), 1, 1, [address1], [], NetworkType.MIJIN_TEST); - let canNotify = txAddition.shouldNotifyAccount(publicAccount.address); + let canNotify = txAddition.shouldNotifyAccount(address1, []); expect(canNotify).to.be.true; - canNotify = txAddition.shouldNotifyAccount(Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKB')); + canNotify = txAddition.shouldNotifyAccount(Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), []); expect(canNotify).to.be.false; Object.assign(txAddition, { signer: account.publicAccount }); - expect(txAddition.shouldNotifyAccount(account.address)).to.be.true; + expect(txAddition.shouldNotifyAccount(account.address, [])).to.be.true; - const txDeletion = MultisigAccountModificationTransaction.create( - Deadline.create(), - 1, - 1, - [], - [publicAccount], - NetworkType.MIJIN_TEST, - ); + const txDeletion = MultisigAccountModificationTransaction.create(Deadline.create(), 1, 1, [], [address1], NetworkType.MIJIN_TEST); - let canNotifyDeletion = txDeletion.shouldNotifyAccount(publicAccount.address); + let canNotifyDeletion = txDeletion.shouldNotifyAccount(address1, []); expect(canNotifyDeletion).to.be.true; - canNotifyDeletion = txDeletion.shouldNotifyAccount(Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKB')); + canNotifyDeletion = txDeletion.shouldNotifyAccount(Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), []); expect(canNotifyDeletion).to.be.false; Object.assign(txDeletion, { signer: account.publicAccount }); - expect(txDeletion.shouldNotifyAccount(account.address)).to.be.true; + expect(txDeletion.shouldNotifyAccount(account.address, [])).to.be.true; + }); + + it('Notify Account with alias', () => { + const alias = new NamespaceId('test'); + const wrongAlias = new NamespaceId('wrong'); + const txAddition = MultisigAccountModificationTransaction.create(Deadline.create(), 1, 1, [alias], [], NetworkType.MIJIN_TEST); + + let canNotify = txAddition.shouldNotifyAccount(address1, [alias]); + expect(canNotify).to.be.true; + + canNotify = txAddition.shouldNotifyAccount(Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [wrongAlias]); + expect(canNotify).to.be.false; + + canNotify = txAddition.shouldNotifyAccount(Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [alias]); + expect(canNotify).to.be.true; + + Object.assign(txAddition, { signer: account.publicAccount }); + expect(txAddition.shouldNotifyAccount(account.address, [])).to.be.true; + + const txDeletion = MultisigAccountModificationTransaction.create(Deadline.create(), 1, 1, [], [alias], NetworkType.MIJIN_TEST); + + let canNotifyDeletion = txDeletion.shouldNotifyAccount(address1, [alias]); + expect(canNotifyDeletion).to.be.true; + + canNotifyDeletion = txDeletion.shouldNotifyAccount(Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [ + wrongAlias, + ]); + expect(canNotifyDeletion).to.be.false; + + canNotifyDeletion = txDeletion.shouldNotifyAccount(Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [ + alias, + ]); + expect(canNotifyDeletion).to.be.true; + + Object.assign(txDeletion, { signer: account.publicAccount }); + expect(txDeletion.shouldNotifyAccount(account.address, [])).to.be.true; }); }); diff --git a/test/model/transaction/NamespaceMetadataTransaction.spec.ts b/test/model/transaction/NamespaceMetadataTransaction.spec.ts index d62ae23ec8..e5e79ddd1f 100644 --- a/test/model/transaction/NamespaceMetadataTransaction.spec.ts +++ b/test/model/transaction/NamespaceMetadataTransaction.spec.ts @@ -38,7 +38,7 @@ describe('NamespaceMetadataTransaction', () => { it('should default maxFee field be set to 0', () => { const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new NamespaceId([2262289484, 3405110546]), 1, @@ -53,7 +53,7 @@ describe('NamespaceMetadataTransaction', () => { it('should filled maxFee override transaction maxFee', () => { const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new NamespaceId([2262289484, 3405110546]), 1, @@ -69,7 +69,7 @@ describe('NamespaceMetadataTransaction', () => { it('should create and sign an NamespaceMetadataTransaction object', () => { const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new NamespaceId([2262289484, 3405110546]), 1, @@ -80,23 +80,22 @@ describe('NamespaceMetadataTransaction', () => { const signedTransaction = namespaceMetadataTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '9801508C58666C746F471538E43002B85B1CD542F9874B2861183919B' + - 'A8787B6E8030000000000004CCCD78612DDF5CA01000A0000000000000000000000', + '90D66C33420E5411995BACFCA2B28CF1C9F5DD7AB1204EA4E8030000000000004CCCD78612DDF5CA01000A0000000000000000000000', ); }); describe('size', () => { - it('should return 190 for NamespaceMetadataTransaction byte size', () => { + it('should return 182 for NamespaceMetadataTransaction byte size', () => { const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new NamespaceId([2262289484, 3405110546]), 1, Convert.uint8ToUtf8(new Uint8Array(10)), NetworkType.MIJIN_TEST, ); - expect(namespaceMetadataTransaction.size).to.be.equal(190); + expect(namespaceMetadataTransaction.size).to.be.equal(182); expect(Convert.hexToUint8(namespaceMetadataTransaction.serialize()).length).to.be.equal(namespaceMetadataTransaction.size); }); }); @@ -104,14 +103,14 @@ describe('NamespaceMetadataTransaction', () => { it('Test set maxFee using multiplier', () => { const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new NamespaceId([2262289484, 3405110546]), 1, Convert.uint8ToUtf8(new Uint8Array(10)), NetworkType.MIJIN_TEST, ).setMaxFee(2); - expect(namespaceMetadataTransaction.maxFee.compact()).to.be.equal(380); + expect(namespaceMetadataTransaction.maxFee.compact()).to.be.equal(364); const signedTransaction = namespaceMetadataTransaction.signWith(account, generationHash); expect(signedTransaction.hash).not.to.be.undefined; @@ -120,7 +119,7 @@ describe('NamespaceMetadataTransaction', () => { it('should create EmbeddedTransactionBuilder', () => { const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new NamespaceId([2262289484, 3405110546]), 1, @@ -140,7 +139,7 @@ describe('NamespaceMetadataTransaction', () => { it('should resolve alias', () => { const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new NamespaceId([2262289484, 3405110546]), 1, @@ -156,20 +155,42 @@ describe('NamespaceMetadataTransaction', () => { it('Notify Account', () => { const tx = NamespaceMetadataTransaction.create( Deadline.create(), - account.publicKey, + account.address, UInt64.fromUint(1000), new NamespaceId([2262289484, 3405110546]), 1, Convert.uint8ToUtf8(new Uint8Array(10)), NetworkType.MIJIN_TEST, ); - let canNotify = tx.shouldNotifyAccount(account.address); + let canNotify = tx.shouldNotifyAccount(account.address, []); expect(canNotify).to.be.true; - canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKB')); + canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), []); expect(canNotify).to.be.false; Object.assign(tx, { signer: account.publicAccount }); - expect(tx.shouldNotifyAccount(account.address)).to.be.true; + expect(tx.shouldNotifyAccount(account.address, [])).to.be.true; + }); + + it('Notify Account with alias', () => { + const alias = new NamespaceId('test'); + const wrongAlias = new NamespaceId('wrong'); + const tx = NamespaceMetadataTransaction.create( + Deadline.create(), + alias, + UInt64.fromUint(1000), + new NamespaceId([2262289484, 3405110546]), + 1, + Convert.uint8ToUtf8(new Uint8Array(10)), + NetworkType.MIJIN_TEST, + ); + let canNotify = tx.shouldNotifyAccount(account.address, [alias]); + expect(canNotify).to.be.true; + + canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [wrongAlias]); + expect(canNotify).to.be.false; + + Object.assign(tx, { signer: account.publicAccount }); + expect(tx.shouldNotifyAccount(account.address, [wrongAlias])).to.be.true; }); }); diff --git a/test/model/transaction/NodeKeyLinkTransaction.spec.ts b/test/model/transaction/NodeKeyLinkTransaction.spec.ts index 8b37bc690b..372eafb0ef 100644 --- a/test/model/transaction/NodeKeyLinkTransaction.spec.ts +++ b/test/model/transaction/NodeKeyLinkTransaction.spec.ts @@ -124,7 +124,7 @@ describe('NodeKeyLinkTransaction', () => { let canNotify = tx.shouldNotifyAccount(account.address); expect(canNotify).to.be.true; - canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKB')); + canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ')); expect(canNotify).to.be.false; Object.assign(tx, { signer: account.publicAccount }); diff --git a/test/model/transaction/PersistentDelegationRequestTransaction.spec.ts b/test/model/transaction/PersistentDelegationRequestTransaction.spec.ts index 6c76fe503c..f6783eeecb 100644 --- a/test/model/transaction/PersistentDelegationRequestTransaction.spec.ts +++ b/test/model/transaction/PersistentDelegationRequestTransaction.spec.ts @@ -73,7 +73,7 @@ describe('PersistentDelegationRequestTransaction', () => { expect(persistentDelegationRequestTransaction.mosaics.length).to.be.equal(0); expect(persistentDelegationRequestTransaction.recipientAddress).to.be.instanceof(Address); expect((persistentDelegationRequestTransaction.recipientAddress as Address).plain()).to.be.equal( - 'SDBC4JE7GTJAKN2XJCQWWRJMYA35AFOYQBATXOUA', + 'SDBC4JE7GTJAKN2XJCQWWRJMYA35AFOYQBATXOQ', ); const signedTransaction = persistentDelegationRequestTransaction.signWith(account, generationHash); diff --git a/test/model/transaction/SecretLockTransaction.spec.ts b/test/model/transaction/SecretLockTransaction.spec.ts index 5d51ab7ae3..b58fe67047 100644 --- a/test/model/transaction/SecretLockTransaction.spec.ts +++ b/test/model/transaction/SecretLockTransaction.spec.ts @@ -65,7 +65,7 @@ describe('SecretLockTransaction', () => { it('should default maxFee field be set to 0', () => { const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; - const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); + const recipientAddress = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), NetworkCurrencyLocal.createAbsolute(10), @@ -82,7 +82,7 @@ describe('SecretLockTransaction', () => { it('should filled maxFee override transaction maxFee', () => { const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; - const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); + const recipientAddress = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), NetworkCurrencyLocal.createAbsolute(10), @@ -100,7 +100,7 @@ describe('SecretLockTransaction', () => { it('should be created with LockHashAlgorithm: Op_Sha3_256 secret', () => { const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; - const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); + const recipientAddress = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), NetworkCurrencyLocal.createAbsolute(10), @@ -120,7 +120,7 @@ describe('SecretLockTransaction', () => { it('should be created and sign SecretLock Transaction', () => { const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; - const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); + const recipientAddress = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), NetworkCurrencyLocal.createAbsolute(10), @@ -132,14 +132,14 @@ describe('SecretLockTransaction', () => { ); const signedTx = secretLockTransaction.signWith(account, generationHash); expect(signedTx.payload.substring(256, signedTx.payload.length)).to.be.equal( - '9B3155B37159DA50AA52D5967C509B410F5A36A3B1E31ECB5AC76675D79B4A5E44B262C46CEABB850A' + - '0000000000000064000000000000000090C2337113E6D8F15B56E0821149299F340C01706FC1CAD6CB', + '9B3155B37159DA50AA52D5967C509B410F5A36A3B1E31ECB5AC76675D79B4A5E44B262C46CEABB850' + + 'A000000000000006400000000000000009026D27E1D0A26CA4E316F901E23E55C8711DB20DF11A7B2', ); }); it('should throw exception when the input is not related to HashTyp: Op_Sha3_256', () => { expect(() => { - const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); + const recipientAddress = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); SecretLockTransaction.create( Deadline.create(), NetworkCurrencyLocal.createAbsolute(10), @@ -154,7 +154,7 @@ describe('SecretLockTransaction', () => { it('should be created with LockHashAlgorithm: Op_Hash_160 secret', () => { const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9'; - const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); + const recipientAddress = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), NetworkCurrencyLocal.createAbsolute(10), @@ -174,7 +174,7 @@ describe('SecretLockTransaction', () => { it('should throw exception when the input is not related to HashTyp: Op_Hash_160', () => { expect(() => { - const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); + const recipientAddress = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); SecretLockTransaction.create( Deadline.create(), NetworkCurrencyLocal.createAbsolute(10), @@ -188,7 +188,7 @@ describe('SecretLockTransaction', () => { }); it('should be created with LockHashAlgorithm: Op_Hash_256 secret', () => { const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; - const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); + const recipientAddress = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), NetworkCurrencyLocal.createAbsolute(10), @@ -208,7 +208,7 @@ describe('SecretLockTransaction', () => { it('should throw exception when the input is not related to HashTyp: Op_Hash_256', () => { expect(() => { - const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); + const recipientAddress = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); SecretLockTransaction.create( Deadline.create(), NetworkCurrencyLocal.createAbsolute(10), @@ -222,9 +222,9 @@ describe('SecretLockTransaction', () => { }); describe('size', () => { - it('should return 210 for SecretLockTransaction with proof of 32 bytes', () => { + it('should return 209 for SecretLockTransaction with proof of 32 bytes', () => { const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; - const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); + const recipientAddress = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), NetworkCurrencyLocal.createAbsolute(10), @@ -234,7 +234,7 @@ describe('SecretLockTransaction', () => { recipientAddress, NetworkType.MIJIN_TEST, ); - expect(secretLockTransaction.size).to.be.equal(210); + expect(secretLockTransaction.size).to.be.equal(209); expect(Convert.hexToUint8(secretLockTransaction.serialize()).length).to.be.equal(secretLockTransaction.size); }); }); @@ -261,7 +261,7 @@ describe('SecretLockTransaction', () => { it('Test set maxFee using multiplier', () => { const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; - const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); + const recipientAddress = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), NetworkCurrencyLocal.createAbsolute(10), @@ -271,7 +271,7 @@ describe('SecretLockTransaction', () => { recipientAddress, NetworkType.MIJIN_TEST, ).setMaxFee(2); - expect(secretLockTransaction.maxFee.compact()).to.be.equal(420); + expect(secretLockTransaction.maxFee.compact()).to.be.equal(418); const signedTransaction = secretLockTransaction.signWith(account, generationHash); expect(signedTransaction.hash).not.to.be.undefined; }); @@ -303,7 +303,7 @@ describe('SecretLockTransaction', () => { it('Notify Account', () => { const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; - const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); + const recipientAddress = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const tx = SecretLockTransaction.create( Deadline.create(), NetworkCurrencyLocal.createAbsolute(10), @@ -316,7 +316,7 @@ describe('SecretLockTransaction', () => { let canNotify = tx.shouldNotifyAccount(recipientAddress, []); expect(canNotify).to.be.true; - canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKB'), []); + canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SDR6EW2WBHJQDYMNGFX2UBZHMMZC5PGL2Z5UYYY'), []); expect(canNotify).to.be.false; Object.assign(tx, { signer: account.publicAccount }); diff --git a/test/model/transaction/SecretProofTransaction.spec.ts b/test/model/transaction/SecretProofTransaction.spec.ts index 66f69d03fd..589ae0d030 100644 --- a/test/model/transaction/SecretProofTransaction.spec.ts +++ b/test/model/transaction/SecretProofTransaction.spec.ts @@ -174,7 +174,7 @@ describe('SecretProofTransaction', () => { }); describe('size', () => { - it('should return 220 for SecretProofTransaction with proof and secret both 32 bytes', () => { + it('should return 219 for SecretProofTransaction with proof and secret both 32 bytes', () => { const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7'; const secretProofTransaction = SecretProofTransaction.create( Deadline.create(), @@ -184,7 +184,7 @@ describe('SecretProofTransaction', () => { proof, NetworkType.MIJIN_TEST, ); - expect(secretProofTransaction.size).to.be.equal(220); + expect(secretProofTransaction.size).to.be.equal(219); expect(Convert.hexToUint8(secretProofTransaction.serialize()).length).to.be.equal(secretProofTransaction.size); }); }); @@ -202,8 +202,8 @@ describe('SecretProofTransaction', () => { const signedTx = secretProofTransaction.signWith(account, generationHash); expect(signedTx.payload.substring(256, signedTx.payload.length)).to.be.equal( - '9B3155B37159DA50AA52D5967C509B410F5A36A3B1E31ECB5AC76675D79B4A5E20000090D66C33420E5411995BA' + - 'CFCA2B28CF1C9F5DD7AB1204EA451B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7', + '9B3155B37159DA50AA52D5967C509B410F5A36A3B1E31ECB5AC76675D79B4A5E20000090D66C33420E5411995BACFCA2' + + 'B28CF1C9F5DD7AB1204EA4B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7', ); }); @@ -234,7 +234,7 @@ describe('SecretProofTransaction', () => { proof, NetworkType.MIJIN_TEST, ).setMaxFee(2); - expect(secretProofTransaction.maxFee.compact()).to.be.equal(440); + expect(secretProofTransaction.maxFee.compact()).to.be.equal(438); const signedTransaction = secretProofTransaction.signWith(account, generationHash); expect(signedTransaction.hash).not.to.be.undefined; }); @@ -313,7 +313,7 @@ describe('SecretProofTransaction', () => { let canNotify = tx.shouldNotifyAccount(account.address, []); expect(canNotify).to.be.true; - canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKB'), []); + canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), []); expect(canNotify).to.be.false; Object.assign(tx, { signer: account.publicAccount }); diff --git a/test/model/transaction/Transaction.spec.ts b/test/model/transaction/Transaction.spec.ts index a92e1e6acc..ff70e3f526 100644 --- a/test/model/transaction/Transaction.spec.ts +++ b/test/model/transaction/Transaction.spec.ts @@ -224,7 +224,7 @@ describe('Transaction', () => { it('Should return serialized payload', () => { const transaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -232,7 +232,7 @@ describe('Transaction', () => { const serialized = transaction.serialize(); expect(serialized.substring(256, serialized.length)).to.be.equal( - '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142000D000000000000746573742D6D657373616765', + '9026D27E1D0A26CA4E316F901E23E55C8711DB20DF11A7B20D0000000000000000746573742D6D657373616765', ); }); }); @@ -391,7 +391,7 @@ describe('Transaction', () => { it('is signed', () => { let tx = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -401,6 +401,6 @@ describe('Transaction', () => { const signed = tx.signWith(account, '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'); tx = TransactionMapping.createFromPayload(signed.payload) as Transaction; expect((tx as Transaction).isSigned(account.address)).to.be.true; - expect((tx as Transaction).isSigned(Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYZC'))).to.be.false; + expect((tx as Transaction).isSigned(Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'))).to.be.false; }); }); diff --git a/test/model/transaction/TransactionStatusError.spec.ts b/test/model/transaction/TransactionStatusError.spec.ts index ea62bcb62b..62f4daa941 100644 --- a/test/model/transaction/TransactionStatusError.spec.ts +++ b/test/model/transaction/TransactionStatusError.spec.ts @@ -24,7 +24,7 @@ import { UInt64 } from '../../../src/model/UInt64'; describe('TransactionStatusError', () => { it('should createComplete an TransactionStatusError object', () => { const statusInfoErrorDTO = { - address: Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + address: Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), deadline: '1010', hash: 'transaction-hash', code: 'error-message', diff --git a/test/model/transaction/TransferTransaction.spec.ts b/test/model/transaction/TransferTransaction.spec.ts index dff9769b21..8d3e5816e0 100644 --- a/test/model/transaction/TransferTransaction.spec.ts +++ b/test/model/transaction/TransferTransaction.spec.ts @@ -23,7 +23,6 @@ import { MessageMarker } from '../../../src/model/message/MessageMarker'; import { MessageType } from '../../../src/model/message/MessageType'; import { PersistentHarvestingDelegationMessage } from '../../../src/model/message/PersistentHarvestingDelegationMessage'; import { PlainMessage } from '../../../src/model/message/PlainMessage'; -import { ReceiptSource, ResolutionEntry, ResolutionType, TransactionInfo } from '../../../src/model/model'; import { Mosaic } from '../../../src/model/mosaic/Mosaic'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; import { NetworkCurrencyLocal } from '../../../src/model/mosaic/NetworkCurrencyLocal'; @@ -36,6 +35,10 @@ import { TransferTransaction } from '../../../src/model/transaction/TransferTran import { UInt64 } from '../../../src/model/UInt64'; import { TestingAccount } from '../../conf/conf.spec'; import { AggregateTransaction } from '../../../src/model/transaction/AggregateTransaction'; +import { ResolutionType } from '../../../src/model/receipt/ResolutionType'; +import { ReceiptSource } from '../../../src/model/receipt/ReceiptSource'; +import { ResolutionEntry } from '../../../src/model/receipt/ResolutionEntry'; +import { TransactionInfo } from '../../../src/model/transaction/TransactionInfo'; describe('TransferTransaction', () => { let account: Account; @@ -70,7 +73,7 @@ describe('TransferTransaction', () => { it('should default maxFee field be set to 0', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -83,7 +86,7 @@ describe('TransferTransaction', () => { it('should filled maxFee override transaction maxFee', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -97,7 +100,7 @@ describe('TransferTransaction', () => { it('should createComplete an TransferTransaction object and sign it without mosaics', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -106,19 +109,19 @@ describe('TransferTransaction', () => { expect(transferTransaction.message.payload).to.be.equal('test-message'); expect(transferTransaction.mosaics.length).to.be.equal(0); expect(transferTransaction.recipientAddress).to.be.instanceof(Address); - expect((transferTransaction.recipientAddress as Address).plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + expect((transferTransaction.recipientAddress as Address).plain()).to.be.equal('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const signedTransaction = transferTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142000D000000000000746573742D6D657373616765', + '9026D27E1D0A26CA4E316F901E23E55C8711DB20DF11A7B20D0000000000000000746573742D6D657373616765', ); }); it('should createComplete an TransferTransaction object and sign it with mosaics', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [NetworkCurrencyLocal.createRelative(100)], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -127,12 +130,12 @@ describe('TransferTransaction', () => { expect(transferTransaction.message.payload).to.be.equal('test-message'); expect(transferTransaction.mosaics.length).to.be.equal(1); expect(transferTransaction.recipientAddress).to.be.instanceof(Address); - expect((transferTransaction.recipientAddress as Address).plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + expect((transferTransaction.recipientAddress as Address).plain()).to.be.equal('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const signedTransaction = transferTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142010D000000000044B262C46CEABB8500E1F' + + '9026D27E1D0A26CA4E316F901E23E55C8711DB20DF11A7B20D0001000000000044B262C46CEABB8500E1F' + '5050000000000746573742D6D657373616765', ); }); @@ -156,26 +159,26 @@ describe('TransferTransaction', () => { const signedTransaction = transferTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '9151776168D24257D800000000000000000000000000000000010D000000000044B262C46CEABB8500E1F' + - '5050000000000746573742D6D657373616765', + '9151776168D24257D80000000000000000000000000000000D0001000000000044B262C46CEABB8500E1' + + 'F5050000000000746573742D6D657373616765', ); }); - it('should format TransferTransaction payload with 25 bytes binary address', () => { + it('should format TransferTransaction payload with 24 bytes binary address', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [NetworkCurrencyLocal.createRelative(100)], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, ); // test recipientToString with Address recipient - expect(transferTransaction.recipientToString()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + expect(transferTransaction.recipientToString()).to.be.equal('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const signedTransaction = transferTransaction.signWith(account, generationHash); - expect(signedTransaction.payload.substring(256, 306)).to.be.equal('9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'); + expect(signedTransaction.payload.substring(256, 306)).to.be.equal('9026D27E1D0A26CA4E316F901E23E55C8711DB20DF11A7B20D'); }); it('should format TransferTransaction payload with 8 bytes binary namespaceId', () => { @@ -192,14 +195,14 @@ describe('TransferTransaction', () => { const signedTransaction = transferTransaction.signWith(account, generationHash); - expect(signedTransaction.payload.substring(256, 306)).to.be.equal('9151776168D24257D800000000000000000000000000000000'); + expect(signedTransaction.payload.substring(256, 306)).to.be.equal('9151776168D24257D80000000000000000000000000000000D'); }); describe('size', () => { it('should return 180 for TransferTransaction with 1 mosaic and message NEM', () => { const transaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [NetworkCurrencyLocal.createRelative(100)], PlainMessage.create('NEM'), NetworkType.MIJIN_TEST, @@ -212,7 +215,7 @@ describe('TransferTransaction', () => { it('should create TransferTransaction and sign using catbuffer-typescript', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [NetworkCurrencyLocal.createRelative(100)], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -221,12 +224,12 @@ describe('TransferTransaction', () => { expect(transferTransaction.message.payload).to.be.equal('test-message'); expect(transferTransaction.mosaics.length).to.be.equal(1); expect(transferTransaction.recipientAddress).to.be.instanceof(Address); - expect((transferTransaction.recipientAddress as Address).plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + expect((transferTransaction.recipientAddress as Address).plain()).to.be.equal('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const signedTransaction = transferTransaction.signWith(account, generationHash); expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( - '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142010D000000000044B262C46CEABB8500E1F' + + '9026D27E1D0A26CA4E316F901E23E55C8711DB20DF11A7B20D0001000000000044B262C46CEABB8500E1F' + '5050000000000746573742D6D657373616765', ); }); @@ -234,7 +237,7 @@ describe('TransferTransaction', () => { it('should create Transafer transaction for persistent harvesting delegation request transaction', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PersistentHarvestingDelegationMessage.create(delegatedPrivateKey, recipientPublicKey, NetworkType.MIJIN_TEST), NetworkType.MIJIN_TEST, @@ -246,7 +249,7 @@ describe('TransferTransaction', () => { it('should createComplete an persistentDelegationRequestTransaction object and sign it', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PersistentHarvestingDelegationMessage.create(delegatedPrivateKey, recipientPublicKey, NetworkType.MIJIN_TEST), NetworkType.MIJIN_TEST, @@ -255,7 +258,7 @@ describe('TransferTransaction', () => { expect(transferTransaction.message.payload.includes(messageMarker)).to.be.true; expect(transferTransaction.mosaics.length).to.be.equal(0); expect(transferTransaction.recipientAddress).to.be.instanceof(Address); - expect((transferTransaction.recipientAddress as Address).plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + expect((transferTransaction.recipientAddress as Address).plain()).to.be.equal('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const signedTransaction = transferTransaction.signWith(account, generationHash); @@ -267,7 +270,7 @@ describe('TransferTransaction', () => { expect(() => { TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [NetworkCurrencyLocal.createRelative(100)], PersistentHarvestingDelegationMessage.create(delegatedPrivateKey, recipientPublicKey, NetworkType.MIJIN_TEST), NetworkType.MIJIN_TEST, @@ -279,7 +282,7 @@ describe('TransferTransaction', () => { expect(() => { TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [NetworkCurrencyLocal.createRelative(100)], PersistentHarvestingDelegationMessage.create('abc', recipientPublicKey, NetworkType.MIJIN_TEST), NetworkType.MIJIN_TEST, @@ -291,7 +294,7 @@ describe('TransferTransaction', () => { expect(() => { TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [NetworkCurrencyLocal.createRelative(100)], PersistentHarvestingDelegationMessage.create(delegatedPrivateKey, recipientPublicKey, NetworkType.MIJIN_TEST), NetworkType.MIJIN_TEST, @@ -307,7 +310,7 @@ describe('TransferTransaction', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), mosaics, PlainMessage.create('NEM'), NetworkType.MIJIN_TEST, @@ -336,7 +339,7 @@ describe('TransferTransaction', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), mosaics, PlainMessage.create('NEM'), NetworkType.MIJIN_TEST, @@ -372,7 +375,7 @@ describe('TransferTransaction', () => { it('Test set maxFee using multiplier', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -386,7 +389,7 @@ describe('TransferTransaction', () => { it('Test set maxFee using multiplier to throw', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -425,7 +428,7 @@ describe('TransferTransaction', () => { }); it('Notify Account', () => { - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const tx = TransferTransaction.create( Deadline.create(), address, @@ -436,7 +439,7 @@ describe('TransferTransaction', () => { let canNotify = tx.shouldNotifyAccount(address, []); expect(canNotify).to.be.true; - canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKB'), []); + canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SDR6EW2WBHJQDYMNGFX2UBZHMMZC5PGL2Z5UYYY'), []); expect(canNotify).to.be.false; Object.assign(tx, { signer: account.publicAccount }); @@ -444,7 +447,7 @@ describe('TransferTransaction', () => { }); it('Notify Account with alias', () => { - const address = Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); const namespaceId = new NamespaceId('test'); const canNotify = TransferTransaction.create( Deadline.create(), diff --git a/test/model/transaction/VotingKeyLinkTransaction.spec.ts b/test/model/transaction/VotingKeyLinkTransaction.spec.ts index 06927abff0..7cc9755aa9 100644 --- a/test/model/transaction/VotingKeyLinkTransaction.spec.ts +++ b/test/model/transaction/VotingKeyLinkTransaction.spec.ts @@ -126,7 +126,7 @@ describe('VotingKeyLinkTransaction', () => { let canNotify = tx.shouldNotifyAccount(account.address); expect(canNotify).to.be.true; - canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKB')); + canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SDR6EW2WBHJQDYMNGFX2UBZHMMZC5PGL2Z5UYYY')); expect(canNotify).to.be.false; Object.assign(tx, { signer: account.publicAccount }); diff --git a/test/model/transaction/VrfKeyLinkTransaction.spec.ts b/test/model/transaction/VrfKeyLinkTransaction.spec.ts index 6839d0c82f..d84b338420 100644 --- a/test/model/transaction/VrfKeyLinkTransaction.spec.ts +++ b/test/model/transaction/VrfKeyLinkTransaction.spec.ts @@ -124,7 +124,7 @@ describe('VrfKeyLinkTransaction', () => { let canNotify = tx.shouldNotifyAccount(account.address); expect(canNotify).to.be.true; - canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKB')); + canNotify = tx.shouldNotifyAccount(Address.createFromRawAddress('SDR6EW2WBHJQDYMNGFX2UBZHMMZC5PGL2Z5UYYY')); expect(canNotify).to.be.false; Object.assign(tx, { signer: account.publicAccount }); diff --git a/test/service/AccountService.spec.ts b/test/service/AccountService.spec.ts index 11b8c927a7..f8cef47ab7 100644 --- a/test/service/AccountService.spec.ts +++ b/test/service/AccountService.spec.ts @@ -78,7 +78,7 @@ describe('AccountService', () => { 1, [NetworkCurrencyLocal.NAMESPACE_ID], NamespaceId.createFromEncoded('0000000000000000'), - account.publicAccount, + account.address, UInt64.fromUint(10), UInt64.fromUint(20), new MosaicAlias(new MosaicId('30BBEA6CC462B244')), @@ -91,7 +91,7 @@ describe('AccountService', () => { 1, [NetworkCurrencyPublic.NAMESPACE_ID], NamespaceId.createFromEncoded('0000000000000000'), - account.publicAccount, + account.address, UInt64.fromUint(10), UInt64.fromUint(20), new MosaicAlias(new MosaicId('31BBEA6CC462B244')), @@ -104,7 +104,7 @@ describe('AccountService', () => { 1, [NetworkHarvestLocal.NAMESPACE_ID], NamespaceId.createFromEncoded('0000000000000000'), - account.publicAccount, + account.address, UInt64.fromUint(10), UInt64.fromUint(20), new MosaicAlias(new MosaicId('32BBEA6CC462B244')), diff --git a/test/service/AggregateTransactionService.spec.ts b/test/service/AggregateTransactionService.spec.ts index 1dcbed2ee0..46674dfc73 100644 --- a/test/service/AggregateTransactionService.spec.ts +++ b/test/service/AggregateTransactionService.spec.ts @@ -93,35 +93,29 @@ describe('AggregateTransactionService', () => { const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; function givenMultisig2AccountInfo(): MultisigAccountInfo { - return new MultisigAccountInfo(multisig2.publicAccount, 2, 1, [multisig1.publicAccount, account1.publicAccount], []); + return new MultisigAccountInfo(multisig2.address, 2, 1, [multisig1.address, account1.address], []); } function givenMultisig3AccountInfo(): MultisigAccountInfo { - return new MultisigAccountInfo(multisig3.publicAccount, 2, 2, [account2.publicAccount, account3.publicAccount], []); + return new MultisigAccountInfo(multisig3.address, 2, 2, [account2.address, account3.address], []); } function givenAccount1Info(): MultisigAccountInfo { - return new MultisigAccountInfo(account1.publicAccount, 0, 0, [], [multisig2.publicAccount]); + return new MultisigAccountInfo(account1.address, 0, 0, [], [multisig2.address]); } function givenAccount2Info(): MultisigAccountInfo { - return new MultisigAccountInfo(account2.publicAccount, 0, 0, [], [multisig2.publicAccount, multisig3.publicAccount]); + return new MultisigAccountInfo(account2.address, 0, 0, [], [multisig2.address, multisig3.address]); } function givenAccount3Info(): MultisigAccountInfo { - return new MultisigAccountInfo(account3.publicAccount, 0, 0, [], [multisig2.publicAccount, multisig3.publicAccount]); + return new MultisigAccountInfo(account3.address, 0, 0, [], [multisig2.address, multisig3.address]); } function givenAccount4Info(): MultisigAccountInfo { - return new MultisigAccountInfo(account4.publicAccount, 0, 0, [], []); + return new MultisigAccountInfo(account4.address, 0, 0, [], []); } function givenMultisig2AccountGraphInfo(): MultisigAccountGraphInfo { const map = new Map(); - map.set(0, [new MultisigAccountInfo(multisig2.publicAccount, 2, 1, [multisig1.publicAccount, account1.publicAccount], [])]).set(1, [ - new MultisigAccountInfo( - multisig1.publicAccount, - 1, - 1, - [account2.publicAccount, account3.publicAccount], - [multisig2.publicAccount], - ), + map.set(0, [new MultisigAccountInfo(multisig2.address, 2, 1, [multisig1.address, account1.address], [])]).set(1, [ + new MultisigAccountInfo(multisig1.address, 1, 1, [account2.address, account3.address], [multisig2.address]), ]); return new MultisigAccountGraphInfo(map); @@ -129,14 +123,8 @@ describe('AggregateTransactionService', () => { function givenMultisig2AccountGraphInfoDuplicated(): MultisigAccountGraphInfo { const map = new Map(); - map.set(0, [new MultisigAccountInfo(multisig2.publicAccount, 2, 1, [multisig1.publicAccount, account1.publicAccount], [])]).set(1, [ - new MultisigAccountInfo( - multisig1.publicAccount, - 1, - 1, - [account1.publicAccount, account2.publicAccount, account3.publicAccount], - [multisig2.publicAccount], - ), + map.set(0, [new MultisigAccountInfo(multisig2.address, 2, 1, [multisig1.address, account1.address], [])]).set(1, [ + new MultisigAccountInfo(multisig1.address, 1, 1, [account1.address, account2.address, account3.address], [multisig2.address]), ]); return new MultisigAccountGraphInfo(map); @@ -144,7 +132,7 @@ describe('AggregateTransactionService', () => { function givenMultisig3AccountGraphInfo(): MultisigAccountGraphInfo { const map = new Map(); - map.set(0, [new MultisigAccountInfo(multisig3.publicAccount, 2, 2, [account2.publicAccount, account3.publicAccount], [])]); + map.set(0, [new MultisigAccountInfo(multisig3.address, 2, 2, [account2.address, account3.address], [])]); return new MultisigAccountGraphInfo(map); } @@ -201,7 +189,7 @@ describe('AggregateTransactionService', () => { */ const transferTransaction = TransferTransaction.create( Deadline.create(1, ChronoUnit.HOURS), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -234,7 +222,7 @@ describe('AggregateTransactionService', () => { */ const transferTransaction = TransferTransaction.create( Deadline.create(1, ChronoUnit.HOURS), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -267,7 +255,7 @@ describe('AggregateTransactionService', () => { */ const transferTransaction = TransferTransaction.create( Deadline.create(1, ChronoUnit.HOURS), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -383,7 +371,7 @@ describe('AggregateTransactionService', () => { 1, 1, [], - [account1.publicAccount], + [account1.address], NetworkType.MIJIN_TEST, ); @@ -411,7 +399,7 @@ describe('AggregateTransactionService', () => { */ const transferTransaction = TransferTransaction.create( Deadline.create(1, ChronoUnit.HOURS), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -443,7 +431,7 @@ describe('AggregateTransactionService', () => { */ const transferTransaction = TransferTransaction.create( Deadline.create(1, ChronoUnit.HOURS), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, diff --git a/test/service/MetadataTransactionservice.spec.ts b/test/service/MetadataTransactionservice.spec.ts index a1f3c55a6d..137f3d3703 100644 --- a/test/service/MetadataTransactionservice.spec.ts +++ b/test/service/MetadataTransactionservice.spec.ts @@ -56,8 +56,8 @@ describe('MetadataTransactionService', () => { '59DFBA84B2E9E7000135E80C', new MetadataEntry( '5E628EA59818D97AA4118780D9A88C5512FCE7A21C195E1574727EFCE5DF7C0D', - account.publicKey, - account.publicKey, + account.address, + account.address, key, MetadataType.Account, value, @@ -70,17 +70,17 @@ describe('MetadataTransactionService', () => { account = TestingAccount; const mockMetadataRepository: MetadataRepository = mock(); + when(mockMetadataRepository.getAccountMetadataByKeyAndSender(deepEqual(account.address), key.toHex(), account.address)).thenReturn( + observableOf(mockMetadata(MetadataType.Account)), + ); when( - mockMetadataRepository.getAccountMetadataByKeyAndSender(deepEqual(account.address), key.toHex(), account.publicKey), - ).thenReturn(observableOf(mockMetadata(MetadataType.Account))); - when( - mockMetadataRepository.getMosaicMetadataByKeyAndSender(deepEqual(new MosaicId(targetIdHex)), key.toHex(), account.publicKey), + mockMetadataRepository.getMosaicMetadataByKeyAndSender(deepEqual(new MosaicId(targetIdHex)), key.toHex(), account.address), ).thenReturn(observableOf(mockMetadata(MetadataType.Mosaic))); when( mockMetadataRepository.getNamespaceMetadataByKeyAndSender( deepEqual(NamespaceId.createFromEncoded(targetIdHex)), key.toHex(), - account.publicKey, + account.address, ), ).thenReturn(observableOf(mockMetadata(MetadataType.Namespace))); const metadataRepository = instance(mockMetadataRepository); @@ -93,10 +93,10 @@ describe('MetadataTransactionService', () => { Deadline.create(), NetworkType.MIJIN_TEST, MetadataType.Account, - account.publicAccount, + account.address, key, value + deltaValue, - account.publicAccount, + account.address, ) .subscribe((transaction: AccountMetadataTransaction) => { expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_METADATA); @@ -105,7 +105,7 @@ describe('MetadataTransactionService', () => { Convert.xor(Convert.utf8ToUint8(value), Convert.utf8ToUint8(value + deltaValue)), ); expect(transaction.valueSizeDelta).to.be.equal(deltaValue.length); - expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.targetAddress.equals(account.address)).to.be.true; done(); }); }); @@ -116,10 +116,10 @@ describe('MetadataTransactionService', () => { Deadline.create(), NetworkType.MIJIN_TEST, MetadataType.Mosaic, - account.publicAccount, + account.address, key, value + deltaValue, - account.publicAccount, + account.address, new MosaicId(targetIdHex), ) .subscribe((transaction: MosaicMetadataTransaction) => { @@ -130,7 +130,7 @@ describe('MetadataTransactionService', () => { ); expect(transaction.targetMosaicId.toHex()).to.be.equal(targetIdHex); expect(transaction.valueSizeDelta).to.be.equal(deltaValue.length); - expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.targetAddress.equals(account.address)).to.be.true; done(); }); }); @@ -141,10 +141,10 @@ describe('MetadataTransactionService', () => { Deadline.create(), NetworkType.MIJIN_TEST, MetadataType.Namespace, - account.publicAccount, + account.address, key, value + deltaValue, - account.publicAccount, + account.address, NamespaceId.createFromEncoded(targetIdHex), ) .subscribe((transaction: NamespaceMetadataTransaction) => { @@ -155,7 +155,7 @@ describe('MetadataTransactionService', () => { ); expect(transaction.targetNamespaceId.toHex()).to.be.equal(targetIdHex); expect(transaction.valueSizeDelta).to.be.equal(deltaValue.length); - expect(transaction.targetPublicKey).to.be.equal(account.publicKey); + expect(transaction.targetAddress.equals(account.address)).to.be.true; done(); }); }); @@ -166,10 +166,10 @@ describe('MetadataTransactionService', () => { Deadline.create(), NetworkType.MIJIN_TEST, 99, - account.publicAccount, + account.address, key, value + deltaValue, - account.publicAccount, + account.address, ); }).to.throw(Error, 'Metadata type invalid'); }); @@ -180,10 +180,10 @@ describe('MetadataTransactionService', () => { Deadline.create(), NetworkType.MIJIN_TEST, MetadataType.Mosaic, - account.publicAccount, + account.address, key, value + deltaValue, - account.publicAccount, + account.address, ); }).to.throw(Error, 'TargetId for MosaicMetadataTransaction is invalid'); }); @@ -194,10 +194,10 @@ describe('MetadataTransactionService', () => { Deadline.create(), NetworkType.MIJIN_TEST, MetadataType.Namespace, - account.publicAccount, + account.address, key, value + deltaValue, - account.publicAccount, + account.address, ); }).to.throw(Error, 'TargetId for NamespaceMetadataTransaction is invalid'); }); diff --git a/test/service/MosaicService.spec.ts b/test/service/MosaicService.spec.ts index 98008174ca..e18c6ef709 100644 --- a/test/service/MosaicService.spec.ts +++ b/test/service/MosaicService.spec.ts @@ -15,7 +15,6 @@ */ import { expect } from 'chai'; -import { MosaicFlags, AccountInfo, AccountType } from '../../src/model/model'; import { Mosaic } from '../../src/model/mosaic/Mosaic'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { MosaicInfo } from '../../src/model/mosaic/MosaicInfo'; @@ -29,6 +28,9 @@ import { MosaicRepository } from '../../src/infrastructure/MosaicRepository'; import { of as observableOf } from 'rxjs'; import { PublicAccount } from '../../src/model/account/PublicAccount'; import { TestingAccount } from '../conf/conf.spec'; +import { AccountType } from '../../src/model/account/AccountType'; +import { AccountInfo } from '../../src/model/account/AccountInfo'; +import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags'; describe('MosaicService', () => { const accountRepositoryMock = mock(); @@ -40,7 +42,7 @@ describe('MosaicService', () => { mosaicId, UInt64.fromUint(10), UInt64.fromUint(1), - publicAccount, + publicAccount.address, 0, new MosaicFlags(1), 6, diff --git a/test/service/NamespaceService.spec.ts b/test/service/NamespaceService.spec.ts index 1888f274bb..c104d19b13 100644 --- a/test/service/NamespaceService.spec.ts +++ b/test/service/NamespaceService.spec.ts @@ -18,7 +18,6 @@ import { expect } from 'chai'; import { of as observableOf } from 'rxjs'; import { deepEqual, instance, mock, when } from 'ts-mockito'; import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; -import { PublicAccount } from '../../src/model/account/PublicAccount'; import { EmptyAlias } from '../../src/model/namespace/EmptyAlias'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { NamespaceInfo } from '../../src/model/namespace/NamespaceInfo'; @@ -26,6 +25,7 @@ import { NamespaceName } from '../../src/model/namespace/NamespaceName'; import { NetworkType } from '../../src/model/network/NetworkType'; import { UInt64 } from '../../src/model/UInt64'; import { NamespaceService } from '../../src/service/NamespaceService'; +import { Address } from '../../src/model/account/Address'; describe('NamespaceService', () => { function givenRootNamespace(): NamespaceInfo { @@ -37,7 +37,7 @@ describe('NamespaceService', () => { 1, [new NamespaceId([3316183705, 3829351378])], new NamespaceId([0, 0]), - PublicAccount.createFromPublicKey('1026D70E1954775749C6811084D6450A3184D977383F0E4282CD47118AF37755', NetworkType.MIJIN_TEST), + Address.createFromPublicKey('1026D70E1954775749C6811084D6450A3184D977383F0E4282CD47118AF37755', NetworkType.MIJIN_TEST), new UInt64([795, 0]), new UInt64([50795, 0]), new EmptyAlias(), @@ -53,7 +53,7 @@ describe('NamespaceService', () => { 2, [new NamespaceId([3316183705, 3829351378]), new NamespaceId([1781696705, 4157485863])], new NamespaceId([3316183705, 3829351378]), - PublicAccount.createFromPublicKey('1026D70E1954775749C6811084D6450A3184D977383F0E4282CD47118AF37755', NetworkType.MIJIN_TEST), + Address.createFromPublicKey('1026D70E1954775749C6811084D6450A3184D977383F0E4282CD47118AF37755', NetworkType.MIJIN_TEST), new UInt64([795, 0]), new UInt64([50795, 0]), new EmptyAlias(), diff --git a/test/service/TransactionService.spec.ts b/test/service/TransactionService.spec.ts index 1ee6f186da..27f210e168 100644 --- a/test/service/TransactionService.spec.ts +++ b/test/service/TransactionService.spec.ts @@ -46,7 +46,7 @@ describe('TransactionService', () => { const account = Account.generateNewAccount(NetworkType.MIJIN_TEST); const transferTransaction = TransferTransaction.create( Deadline.create(1, ChronoUnit.HOURS), - Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), [], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, From f174b5c2b0020fd67f84377485d0a89e1a11b1d0 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 4 Jun 2020 22:38:27 +0100 Subject: [PATCH 03/22] Added UnresolvedMosaicId --- e2e/infrastructure/Listener.spec.ts | 4 ++-- src/core/utils/UnresolvedMapping.ts | 14 ++++++----- .../receipt/CreateReceiptFromDTO.ts | 8 ++++--- src/model/account/ActivityBucket.ts | 1 - src/model/account/UnresolvedAddress.ts | 16 +++++++++++++ src/model/metadata/MetadataEntry.ts | 6 ++--- src/model/model.ts | 1 + src/model/mosaic/Mosaic.ts | 5 ++-- src/model/mosaic/UnresolvedMosaicId.ts | 23 +++++++++++++++++++ src/model/receipt/ArtifactExpiryReceipt.ts | 4 ++-- src/model/receipt/ResolutionStatement.ts | 9 ++++---- src/model/receipt/Statement.ts | 6 +++-- .../AccountAddressRestrictionTransaction.ts | 4 ++-- .../AccountMosaicRestrictionTransaction.ts | 11 ++++----- .../AccountRestrictionTransaction.ts | 13 +++++------ .../MosaicAddressRestrictionTransaction.ts | 19 +++++++-------- .../MosaicGlobalRestrictionTransaction.ts | 11 ++++----- .../transaction/MosaicMetadataTransaction.ts | 6 ++--- .../MosaicSupplyChangeTransaction.ts | 7 +++--- .../transaction/SecretLockTransaction.ts | 13 ++++++----- .../transaction/SecretProofTransaction.ts | 13 ++++++----- src/model/transaction/TransferTransaction.ts | 13 ++++++----- src/service/MetadataTransactionService.ts | 5 ++-- .../MosaicRestrictionTransactionService.ts | 15 ++++++------ 24 files changed, 137 insertions(+), 90 deletions(-) create mode 100644 src/model/mosaic/UnresolvedMosaicId.ts diff --git a/e2e/infrastructure/Listener.spec.ts b/e2e/infrastructure/Listener.spec.ts index 0efcee0500..807960c7a7 100644 --- a/e2e/infrastructure/Listener.spec.ts +++ b/e2e/infrastructure/Listener.spec.ts @@ -19,7 +19,6 @@ import { filter } from 'rxjs/operators'; import { TransactionRepository } from '../../src/infrastructure/TransactionRepository'; import { Account } from '../../src/model/account/Account'; import { PlainMessage } from '../../src/model/message/PlainMessage'; -import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { NetworkType } from '../../src/model/network/NetworkType'; import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction'; @@ -35,6 +34,7 @@ import { LockFundsTransaction } from '../../src/model/transaction/LockFundsTrans import { UInt64 } from '../../src/model/UInt64'; import { Mosaic } from '../../src/model/mosaic/Mosaic'; import { CosignatureTransaction } from '../../src/model/transaction/CosignatureTransaction'; +import { UnresolvedMosaicId } from '../../src/model/mosaic/UnresolvedMosaicId'; describe('Listener', () => { const helper = new IntegrationTestHelper(); @@ -97,7 +97,7 @@ describe('Listener', () => { const createHashLockTransactionAndAnnounce = ( signedAggregatedTransaction: SignedTransaction, signer: Account, - mosaicId: MosaicId | NamespaceId, + mosaicId: UnresolvedMosaicId, ): void => { const lockFundsTransaction = LockFundsTransaction.create( Deadline.create(), diff --git a/src/core/utils/UnresolvedMapping.ts b/src/core/utils/UnresolvedMapping.ts index b1bc089a4a..9fe416f59c 100644 --- a/src/core/utils/UnresolvedMapping.ts +++ b/src/core/utils/UnresolvedMapping.ts @@ -19,6 +19,8 @@ import { NamespaceId } from '../../model/namespace/NamespaceId'; import { NetworkType } from '../../model/network/NetworkType'; import { Convert } from '../format/Convert'; import { RawAddress } from '../format/RawAddress'; +import { UnresolvedAddress } from '../../model/account/UnresolvedAddress'; +import { UnresolvedMosaicId } from '../../model/mosaic/UnresolvedMosaicId'; /** * @internal @@ -28,9 +30,9 @@ export class UnresolvedMapping { * @internal * Map unresolved mosaic string to MosaicId or NamespaceId * @param {string} mosaicId The unresolvedMosaic id in hex. - * @returns {MosaicId | NamespaceId} + * @returns {UnresolvedMosaicId} */ - public static toUnresolvedMosaic(mosaicId: string): MosaicId | NamespaceId { + public static toUnresolvedMosaic(mosaicId: string): UnresolvedMosaicId { if (!Convert.isHexString(mosaicId)) { throw new Error('Input string is not in valid hexadecimal notation.'); } @@ -48,9 +50,9 @@ export class UnresolvedMapping { /** * Map unresolved address string to Address or NamespaceId * @param {string} address The unresolved address in hex - * @returns {Address | NamespaceId} + * @returns {UnresolvedAddress} */ - public static toUnresolvedAddress(address: string): Address | NamespaceId { + public static toUnresolvedAddress(address: string): UnresolvedAddress { if (!Convert.isHexString(address)) { throw new Error('Input string is not in valid hexadecimal notation.'); } @@ -71,11 +73,11 @@ export class UnresolvedMapping { /** * Return unresolved address bytes of the unresolved address * @internal - * @param {Address | NamespaceId} unresolvedAddress The unresolved address + * @param {UnresolvedAddress} unresolvedAddress The unresolved address * @param {networkType} the network type serialized in the output. * @return {Uint8Array} */ - public static toUnresolvedAddressBytes(unresolvedAddress: Address | NamespaceId, networkType: NetworkType): Uint8Array { + public static toUnresolvedAddressBytes(unresolvedAddress: UnresolvedAddress, networkType: NetworkType): Uint8Array { if (unresolvedAddress instanceof NamespaceId) { // received hexadecimal notation of namespaceId (alias) return RawAddress.aliasToRecipient(Convert.hexToUint8((unresolvedAddress as NamespaceId).toHex()), networkType); diff --git a/src/infrastructure/receipt/CreateReceiptFromDTO.ts b/src/infrastructure/receipt/CreateReceiptFromDTO.ts index 395144c492..9340e15f2b 100644 --- a/src/infrastructure/receipt/CreateReceiptFromDTO.ts +++ b/src/infrastructure/receipt/CreateReceiptFromDTO.ts @@ -31,13 +31,15 @@ import { ResolutionType } from '../../model/receipt/ResolutionType'; import { Statement } from '../../model/receipt/Statement'; import { TransactionStatement } from '../../model/receipt/TransactionStatement'; import { UInt64 } from '../../model/UInt64'; +import { UnresolvedAddress } from '../../model/account/UnresolvedAddress'; +import { UnresolvedMosaicId } from '../../model/mosaic/UnresolvedMosaicId'; /** * @interal * @param unresolvedAddress unresolved address * @returns {Address | NamespaceId} */ -const extractUnresolvedAddress = (unresolvedAddress: any): Address | NamespaceId => { +const extractUnresolvedAddress = (unresolvedAddress: any): UnresolvedAddress => { if (typeof unresolvedAddress === 'string') { return UnresolvedMapping.toUnresolvedAddress(unresolvedAddress); } else if (typeof unresolvedAddress === 'object') { @@ -126,9 +128,9 @@ const createBalanceTransferReceipt = (receiptDTO): Receipt => { * @internal * @param receiptType receipt type * @param id Artifact id - * @returns {MosaicId | NamespaceId} + * @returns {UnresolvedMosaicId} */ -const extractArtifactId = (receiptType: ReceiptType, id: string): MosaicId | NamespaceId => { +const extractArtifactId = (receiptType: ReceiptType, id: string): UnresolvedMosaicId => { switch (receiptType) { case ReceiptType.Mosaic_Expired: return new MosaicId(id); diff --git a/src/model/account/ActivityBucket.ts b/src/model/account/ActivityBucket.ts index 5ad6c86865..88df6e63d4 100644 --- a/src/model/account/ActivityBucket.ts +++ b/src/model/account/ActivityBucket.ts @@ -1,5 +1,4 @@ /* -import { UInt64 } from '../UInt64'; * Copyright 2019 NEM * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/src/model/account/UnresolvedAddress.ts b/src/model/account/UnresolvedAddress.ts index 6f77639d46..6b8367966b 100644 --- a/src/model/account/UnresolvedAddress.ts +++ b/src/model/account/UnresolvedAddress.ts @@ -1,3 +1,19 @@ +/* + * Copyright 2020 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"), + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import { Address } from './Address'; import { NamespaceId } from '../namespace/NamespaceId'; diff --git a/src/model/metadata/MetadataEntry.ts b/src/model/metadata/MetadataEntry.ts index 6105a3d9cf..988c711048 100644 --- a/src/model/metadata/MetadataEntry.ts +++ b/src/model/metadata/MetadataEntry.ts @@ -14,11 +14,11 @@ * limitations under the License. */ -import { MosaicId } from '../mosaic/MosaicId'; -import { NamespaceId } from '../namespace/NamespaceId'; import { UInt64 } from '../UInt64'; import { MetadataType } from './MetadataType'; import { Address } from '../account/Address'; +import { MosaicId } from '../mosaic/MosaicId'; +import { NamespaceId } from '../namespace/NamespaceId'; /** * A mosaic describes an instance of a mosaic definition. @@ -33,7 +33,7 @@ export class MetadataEntry { * @param {UInt64} scopedMetadataKey - The key scoped to source, target and type * @param {MetadatType} metadataType - The metadata type (Account | Mosaic | Namespace) * @param {string} value - The metadata value - * @param {MosaicId | NamespaceId | undefined} targetId - The target mosaic or namespace identifier + * @param {UnresolvedMosaicId | undefined} targetId - The target mosaic or namespace identifier */ constructor( /** diff --git a/src/model/model.ts b/src/model/model.ts index 2a323554ef..c48d9e9094 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -57,6 +57,7 @@ export * from './mosaic/NetworkCurrencyPublic'; export * from './mosaic/NetworkHarvestLocal'; export * from './mosaic/MosaicNames'; export * from './mosaic/ResolvedMosaic'; +export * from './mosaic/UnresolvedMosaicId'; // Mosaic export * from './metadata/Metadata'; diff --git a/src/model/mosaic/Mosaic.ts b/src/model/mosaic/Mosaic.ts index a94145ec2f..9abd84518b 100644 --- a/src/model/mosaic/Mosaic.ts +++ b/src/model/mosaic/Mosaic.ts @@ -14,9 +14,8 @@ * limitations under the License. */ -import { NamespaceId } from '../namespace/NamespaceId'; import { UInt64 } from '../UInt64'; -import { MosaicId } from './MosaicId'; +import { UnresolvedMosaicId } from './UnresolvedMosaicId'; /** * A mosaic describes an instance of a mosaic definition. @@ -32,7 +31,7 @@ export class Mosaic { /** * The mosaic id */ - public readonly id: MosaicId | NamespaceId, + public readonly id: UnresolvedMosaicId, /** * The mosaic amount. The quantity is always given in smallest units for the mosaic * i.e. if it has a divisibility of 3 the quantity is given in millis. diff --git a/src/model/mosaic/UnresolvedMosaicId.ts b/src/model/mosaic/UnresolvedMosaicId.ts new file mode 100644 index 0000000000..f1c9dc2477 --- /dev/null +++ b/src/model/mosaic/UnresolvedMosaicId.ts @@ -0,0 +1,23 @@ +/* + * Copyright 2020 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"), + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { NamespaceId } from '../namespace/NamespaceId'; +import { MosaicId } from './MosaicId'; + +/** + * Custom type for unresolved mosaicId + */ +export type UnresolvedMosaicId = MosaicId | NamespaceId; diff --git a/src/model/receipt/ArtifactExpiryReceipt.ts b/src/model/receipt/ArtifactExpiryReceipt.ts index a83c752a81..7aa8d69fa2 100644 --- a/src/model/receipt/ArtifactExpiryReceipt.ts +++ b/src/model/receipt/ArtifactExpiryReceipt.ts @@ -16,10 +16,10 @@ import { MosaicExpiryReceiptBuilder, MosaicIdDto, NamespaceExpiryReceiptBuilder, NamespaceIdDto } from 'catbuffer-typescript'; import { MosaicId } from '../mosaic/MosaicId'; -import { NamespaceId } from '../namespace/NamespaceId'; import { Receipt } from './Receipt'; import { ReceiptType } from './ReceiptType'; import { ReceiptVersion } from './ReceiptVersion'; +import { UnresolvedMosaicId } from '../mosaic/UnresolvedMosaicId'; /** * Artifact Expiry: An artifact (e.g. namespace, mosaic) expired. @@ -32,7 +32,7 @@ export class ArtifactExpiryReceipt extends Receipt { * @param type - The receipt type * @param size - the receipt size */ - constructor(public readonly artifactId: MosaicId | NamespaceId, version: ReceiptVersion, type: ReceiptType, size?: number) { + constructor(public readonly artifactId: UnresolvedMosaicId, version: ReceiptVersion, type: ReceiptType, size?: number) { super(version, type, size); } diff --git a/src/model/receipt/ResolutionStatement.ts b/src/model/receipt/ResolutionStatement.ts index 790bd3b2e0..cce29d0c66 100644 --- a/src/model/receipt/ResolutionStatement.ts +++ b/src/model/receipt/ResolutionStatement.ts @@ -30,13 +30,14 @@ import { RawAddress } from '../../core/format/RawAddress'; import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping'; import { Address } from '../account/Address'; import { MosaicId } from '../mosaic/MosaicId'; -import { NamespaceId } from '../namespace/NamespaceId'; import { NetworkType } from '../network/NetworkType'; import { UInt64 } from '../UInt64'; import { ReceiptType } from './ReceiptType'; import { ReceiptVersion } from './ReceiptVersion'; import { ResolutionEntry } from './ResolutionEntry'; import { ResolutionType } from './ResolutionType'; +import { UnresolvedAddress } from '../account/UnresolvedAddress'; +import { UnresolvedMosaicId } from '../mosaic/UnresolvedMosaicId'; /** * When a transaction includes an alias, a so called resolution statement reflects the resolved value for that block: @@ -63,7 +64,7 @@ export class ResolutionStatement { /** * An unresolved address or unresolved mosaicId. */ - public readonly unresolved: Address | MosaicId | NamespaceId, + public readonly unresolved: UnresolvedAddress | UnresolvedMosaicId, /** * The array of resolution entries. */ @@ -84,7 +85,7 @@ export class ResolutionStatement { ReceiptVersion.RESOLUTION_STATEMENT, type.valueOf(), new UnresolvedAddressDto( - UnresolvedMapping.toUnresolvedAddressBytes(this.unresolved as Address | NamespaceId, networkType), + UnresolvedMapping.toUnresolvedAddressBytes(this.unresolved as UnresolvedAddress, networkType), ), this.resolutionEntries.map( (entry) => @@ -97,7 +98,7 @@ export class ResolutionStatement { : new MosaicResolutionStatementBuilder( ReceiptVersion.RESOLUTION_STATEMENT, type.valueOf(), - new UnresolvedMosaicIdDto(UInt64.fromHex((this.unresolved as MosaicId | NamespaceId).toHex()).toDTO()), + new UnresolvedMosaicIdDto(UInt64.fromHex((this.unresolved as UnresolvedMosaicId).toHex()).toDTO()), this.resolutionEntries.map( (entry) => new MosaicResolutionEntryBuilder( diff --git a/src/model/receipt/Statement.ts b/src/model/receipt/Statement.ts index a681976906..f801da3a96 100644 --- a/src/model/receipt/Statement.ts +++ b/src/model/receipt/Statement.ts @@ -21,6 +21,8 @@ import { NamespaceId } from '../namespace/NamespaceId'; import { ResolutionStatement } from './ResolutionStatement'; import { ResolutionType } from './ResolutionType'; import { TransactionStatement } from './TransactionStatement'; +import { UnresolvedAddress } from '../account/UnresolvedAddress'; +import { UnresolvedMosaicId } from '../mosaic/UnresolvedMosaicId'; export class Statement { /** @@ -53,7 +55,7 @@ export class Statement { * @returns {Address} */ public resolveAddress( - unresolvedAddress: Address | NamespaceId, + unresolvedAddress: UnresolvedAddress, height: string, transactionIndex: number, aggregateTransactionIndex = 0, @@ -78,7 +80,7 @@ export class Statement { * @returns {MosaicId} */ public resolveMosaicId( - unresolvedMosaicId: MosaicId | NamespaceId, + unresolvedMosaicId: UnresolvedMosaicId, height: string, transactionIndex: number, aggregateTransactionIndex = 0, diff --git a/src/model/transaction/AccountAddressRestrictionTransaction.ts b/src/model/transaction/AccountAddressRestrictionTransaction.ts index 684905ad59..27667aa715 100644 --- a/src/model/transaction/AccountAddressRestrictionTransaction.ts +++ b/src/model/transaction/AccountAddressRestrictionTransaction.ts @@ -96,8 +96,8 @@ export class AccountAddressRestrictionTransaction extends Transaction { deadline: Deadline, maxFee: UInt64, public readonly restrictionFlags: AddressRestrictionFlag, - public readonly restrictionAdditions: (Address | NamespaceId)[], - public readonly restrictionDeletions: (Address | NamespaceId)[], + public readonly restrictionAdditions: UnresolvedAddress[], + public readonly restrictionDeletions: UnresolvedAddress[], signature?: string, signer?: PublicAccount, transactionInfo?: TransactionInfo, diff --git a/src/model/transaction/AccountMosaicRestrictionTransaction.ts b/src/model/transaction/AccountMosaicRestrictionTransaction.ts index a19ad08bf1..f5e0076ff1 100644 --- a/src/model/transaction/AccountMosaicRestrictionTransaction.ts +++ b/src/model/transaction/AccountMosaicRestrictionTransaction.ts @@ -28,8 +28,6 @@ import { Convert } from '../../core/format'; import { DtoMapping } from '../../core/utils/DtoMapping'; import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping'; import { PublicAccount } from '../account/PublicAccount'; -import { MosaicId } from '../mosaic/MosaicId'; -import { NamespaceId } from '../namespace/NamespaceId'; import { NetworkType } from '../network/NetworkType'; import { Statement } from '../receipt/Statement'; import { UInt64 } from '../UInt64'; @@ -41,6 +39,7 @@ import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; import { Address } from '../account/Address'; import { MosaicRestrictionFlag } from '../restriction/MosaicRestrictionFlag'; +import { UnresolvedMosaicId } from '../mosaic/UnresolvedMosaicId'; export class AccountMosaicRestrictionTransaction extends Transaction { /** @@ -58,8 +57,8 @@ export class AccountMosaicRestrictionTransaction extends Transaction { public static create( deadline: Deadline, restrictionFlags: MosaicRestrictionFlag, - restrictionAdditions: (MosaicId | NamespaceId)[], - restrictionDeletions: (MosaicId | NamespaceId)[], + restrictionAdditions: UnresolvedMosaicId[], + restrictionDeletions: UnresolvedMosaicId[], networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), signature?: string, @@ -96,8 +95,8 @@ export class AccountMosaicRestrictionTransaction extends Transaction { deadline: Deadline, maxFee: UInt64, public readonly restrictionFlags: MosaicRestrictionFlag, - public readonly restrictionAdditions: (MosaicId | NamespaceId)[], - public readonly restrictionDeletions: (MosaicId | NamespaceId)[], + public readonly restrictionAdditions: UnresolvedMosaicId[], + public readonly restrictionDeletions: UnresolvedMosaicId[], signature?: string, signer?: PublicAccount, transactionInfo?: TransactionInfo, diff --git a/src/model/transaction/AccountRestrictionTransaction.ts b/src/model/transaction/AccountRestrictionTransaction.ts index bc8dadac0c..3bb6bec660 100644 --- a/src/model/transaction/AccountRestrictionTransaction.ts +++ b/src/model/transaction/AccountRestrictionTransaction.ts @@ -14,9 +14,6 @@ * limitations under the License. */ -import { Address } from '../account/Address'; -import { MosaicId } from '../mosaic/MosaicId'; -import { NamespaceId } from '../namespace/NamespaceId'; import { NetworkType } from '../network/NetworkType'; import { UInt64 } from '../UInt64'; import { AccountAddressRestrictionTransaction } from './AccountAddressRestrictionTransaction'; @@ -28,6 +25,8 @@ import { PublicAccount } from '../account/PublicAccount'; import { AddressRestrictionFlag } from '../restriction/AddressRestrictionFlag'; import { MosaicRestrictionFlag } from '../restriction/MosaicRestrictionFlag'; import { OperationRestrictionFlag } from '../restriction/OperationRestrictionFlag'; +import { UnresolvedAddress } from '../account/UnresolvedAddress'; +import { UnresolvedMosaicId } from '../mosaic/UnresolvedMosaicId'; export class AccountRestrictionTransaction { /** @@ -45,8 +44,8 @@ export class AccountRestrictionTransaction { public static createAddressRestrictionModificationTransaction( deadline: Deadline, restrictionFlags: AddressRestrictionFlag, - restrictionAdditions: (Address | NamespaceId)[], - restrictionDeletions: (Address | NamespaceId)[], + restrictionAdditions: UnresolvedAddress[], + restrictionDeletions: UnresolvedAddress[], networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), signature?: string, @@ -79,8 +78,8 @@ export class AccountRestrictionTransaction { public static createMosaicRestrictionModificationTransaction( deadline: Deadline, restrictionFlags: MosaicRestrictionFlag, - restrictionAdditions: (MosaicId | NamespaceId)[], - restrictionDeletions: (MosaicId | NamespaceId)[], + restrictionAdditions: UnresolvedMosaicId[], + restrictionDeletions: UnresolvedMosaicId[], networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), signature?: string, diff --git a/src/model/transaction/MosaicAddressRestrictionTransaction.ts b/src/model/transaction/MosaicAddressRestrictionTransaction.ts index 593768da3c..45b51597ac 100644 --- a/src/model/transaction/MosaicAddressRestrictionTransaction.ts +++ b/src/model/transaction/MosaicAddressRestrictionTransaction.ts @@ -30,7 +30,6 @@ import { DtoMapping } from '../../core/utils/DtoMapping'; import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping'; import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; -import { MosaicId } from '../mosaic/MosaicId'; import { NamespaceId } from '../namespace/NamespaceId'; import { NetworkType } from '../network/NetworkType'; import { Statement } from '../receipt/Statement'; @@ -41,6 +40,8 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { UnresolvedAddress } from '../account/UnresolvedAddress'; +import { UnresolvedMosaicId } from '../mosaic/UnresolvedMosaicId'; export class MosaicAddressRestrictionTransaction extends Transaction { /** @@ -68,9 +69,9 @@ export class MosaicAddressRestrictionTransaction extends Transaction { */ public static create( deadline: Deadline, - mosaicId: MosaicId | NamespaceId, + mosaicId: UnresolvedMosaicId, restrictionKey: UInt64, - targetAddress: Address | NamespaceId, + targetAddress: UnresolvedAddress, newRestrictionValue: UInt64, networkType: NetworkType, previousRestrictionValue: UInt64 = UInt64.fromHex('FFFFFFFFFFFFFFFF'), @@ -116,7 +117,7 @@ export class MosaicAddressRestrictionTransaction extends Transaction { /** * The mosaic id. */ - public readonly mosaicId: MosaicId | NamespaceId, + public readonly mosaicId: UnresolvedMosaicId, /** * The restriction key. */ @@ -124,7 +125,7 @@ export class MosaicAddressRestrictionTransaction extends Transaction { /** * The affected unresolved address. */ - public readonly targetAddress: Address | NamespaceId, + public readonly targetAddress: UnresolvedAddress, /** * The previous restriction value. */ @@ -224,7 +225,7 @@ export class MosaicAddressRestrictionTransaction extends Transaction { this.restrictionKey.toDTO(), this.previousRestrictionValue.toDTO(), this.newRestrictionValue.toDTO(), - new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.targetAddress, this.networkType)), + new UnresolvedAddressDto(this.targetAddress.encodeUnresolvedAddress(this.networkType)), ); return transactionBuilder.serialize(); } @@ -243,7 +244,7 @@ export class MosaicAddressRestrictionTransaction extends Transaction { this.restrictionKey.toDTO(), this.previousRestrictionValue.toDTO(), this.newRestrictionValue.toDTO(), - new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.targetAddress, this.networkType)), + new UnresolvedAddressDto(this.targetAddress.encodeUnresolvedAddress(this.networkType)), ); } @@ -281,8 +282,8 @@ export class MosaicAddressRestrictionTransaction extends Transaction { public shouldNotifyAccount(address: Address, alias: NamespaceId[]): boolean { return ( super.isSigned(address) || - (this.targetAddress as Address).equals(address) || - alias.find((name) => (this.targetAddress as NamespaceId).equals(name)) !== undefined + this.targetAddress.equals(address) || + alias.find((name) => this.targetAddress.equals(name)) !== undefined ); } } diff --git a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts index b0e2132cc7..3d6ad34a96 100644 --- a/src/model/transaction/MosaicGlobalRestrictionTransaction.ts +++ b/src/model/transaction/MosaicGlobalRestrictionTransaction.ts @@ -28,8 +28,6 @@ import { Convert } from '../../core/format'; import { DtoMapping } from '../../core/utils/DtoMapping'; import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping'; import { PublicAccount } from '../account/PublicAccount'; -import { MosaicId } from '../mosaic/MosaicId'; -import { NamespaceId } from '../namespace/NamespaceId'; import { NetworkType } from '../network/NetworkType'; import { Statement } from '../receipt/Statement'; import { MosaicRestrictionType } from '../restriction/MosaicRestrictionType'; @@ -41,6 +39,7 @@ import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; import { Address } from '../account/Address'; +import { UnresolvedMosaicId } from '../mosaic/UnresolvedMosaicId'; export class MosaicGlobalRestrictionTransaction extends Transaction { /** @@ -73,14 +72,14 @@ export class MosaicGlobalRestrictionTransaction extends Transaction { */ public static create( deadline: Deadline, - mosaicId: MosaicId | NamespaceId, + mosaicId: UnresolvedMosaicId, restrictionKey: UInt64, previousRestrictionValue: UInt64, previousRestrictionType: MosaicRestrictionType, newRestrictionValue: UInt64, newRestrictionType: MosaicRestrictionType, networkType: NetworkType, - referenceMosaicId: MosaicId | NamespaceId = UnresolvedMapping.toUnresolvedMosaic(UInt64.fromUint(0).toHex()), + referenceMosaicId: UnresolvedMosaicId = UnresolvedMapping.toUnresolvedMosaic(UInt64.fromUint(0).toHex()), maxFee: UInt64 = new UInt64([0, 0]), signature?: string, signer?: PublicAccount, @@ -126,11 +125,11 @@ export class MosaicGlobalRestrictionTransaction extends Transaction { /** * The mosaic id. */ - public readonly mosaicId: MosaicId | NamespaceId, + public readonly mosaicId: UnresolvedMosaicId, /** * The refrence mosaic id. */ - public readonly referenceMosaicId: MosaicId | NamespaceId, + public readonly referenceMosaicId: UnresolvedMosaicId, /** * The restriction key. */ diff --git a/src/model/transaction/MosaicMetadataTransaction.ts b/src/model/transaction/MosaicMetadataTransaction.ts index 0a641d3727..e8045a0a69 100644 --- a/src/model/transaction/MosaicMetadataTransaction.ts +++ b/src/model/transaction/MosaicMetadataTransaction.ts @@ -29,7 +29,6 @@ import { Convert } from '../../core/format'; import { DtoMapping } from '../../core/utils/DtoMapping'; import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping'; import { PublicAccount } from '../account/PublicAccount'; -import { MosaicId } from '../mosaic/MosaicId'; import { NamespaceId } from '../namespace/NamespaceId'; import { NetworkType } from '../network/NetworkType'; import { Statement } from '../receipt/Statement'; @@ -42,6 +41,7 @@ import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; import { Address } from '../account/Address'; import { UnresolvedAddress } from '../account/UnresolvedAddress'; +import { UnresolvedMosaicId } from '../mosaic/UnresolvedMosaicId'; /** * Announce an mosaic metadata transaction to associate a key-value state to an account. @@ -67,7 +67,7 @@ export class MosaicMetadataTransaction extends Transaction { deadline: Deadline, targetAddress: UnresolvedAddress, scopedMetadataKey: UInt64, - targetMosaicId: MosaicId | NamespaceId, + targetMosaicId: UnresolvedMosaicId, valueSizeDelta: number, value: string, networkType: NetworkType, @@ -120,7 +120,7 @@ export class MosaicMetadataTransaction extends Transaction { /** * Target mosaic identifier. */ - public readonly targetMosaicId: MosaicId | NamespaceId, + public readonly targetMosaicId: UnresolvedMosaicId, /** * Change in value size in bytes. */ diff --git a/src/model/transaction/MosaicSupplyChangeTransaction.ts b/src/model/transaction/MosaicSupplyChangeTransaction.ts index 56e243eeb4..9d478577f6 100644 --- a/src/model/transaction/MosaicSupplyChangeTransaction.ts +++ b/src/model/transaction/MosaicSupplyChangeTransaction.ts @@ -28,9 +28,7 @@ import { Convert } from '../../core/format'; import { DtoMapping } from '../../core/utils/DtoMapping'; import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping'; import { PublicAccount } from '../account/PublicAccount'; -import { MosaicId } from '../mosaic/MosaicId'; import { MosaicSupplyChangeAction } from '../mosaic/MosaicSupplyChangeAction'; -import { NamespaceId } from '../namespace/NamespaceId'; import { NetworkType } from '../network/NetworkType'; import { Statement } from '../receipt/Statement'; import { UInt64 } from '../UInt64'; @@ -41,6 +39,7 @@ import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; import { Address } from '../account/Address'; +import { UnresolvedMosaicId } from '../mosaic/UnresolvedMosaicId'; /** * In case a mosaic has the flag 'supplyMutable' set to true, the creator of the mosaic can change the supply, @@ -61,7 +60,7 @@ export class MosaicSupplyChangeTransaction extends Transaction { */ public static create( deadline: Deadline, - mosaicId: MosaicId | NamespaceId, + mosaicId: UnresolvedMosaicId, action: MosaicSupplyChangeAction, delta: UInt64, networkType: NetworkType, @@ -102,7 +101,7 @@ export class MosaicSupplyChangeTransaction extends Transaction { /** * The unresolved mosaic id. */ - public readonly mosaicId: MosaicId | NamespaceId, + public readonly mosaicId: UnresolvedMosaicId, /** * The supply type. */ diff --git a/src/model/transaction/SecretLockTransaction.ts b/src/model/transaction/SecretLockTransaction.ts index c95fc858d2..a9ea47b783 100644 --- a/src/model/transaction/SecretLockTransaction.ts +++ b/src/model/transaction/SecretLockTransaction.ts @@ -44,6 +44,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { UnresolvedAddress } from '../account/UnresolvedAddress'; export class SecretLockTransaction extends Transaction { /** @@ -67,7 +68,7 @@ export class SecretLockTransaction extends Transaction { duration: UInt64, hashAlgorithm: LockHashAlgorithm, secret: string, - recipientAddress: Address | NamespaceId, + recipientAddress: UnresolvedAddress, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), signature?: string, @@ -126,7 +127,7 @@ export class SecretLockTransaction extends Transaction { /** * The unresolved recipientAddress of the funds. */ - public readonly recipientAddress: Address | NamespaceId, + public readonly recipientAddress: UnresolvedAddress, signature?: string, signer?: PublicAccount, transactionInfo?: TransactionInfo, @@ -219,7 +220,7 @@ export class SecretLockTransaction extends Transaction { new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), new AmountDto(this.mosaic.amount.toDTO())), new BlockDurationDto(this.duration.toDTO()), this.hashAlgorithm.valueOf(), - new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress, this.networkType)), + new UnresolvedAddressDto(this.recipientAddress.encodeUnresolvedAddress(this.networkType)), ); return transactionBuilder.serialize(); } @@ -238,7 +239,7 @@ export class SecretLockTransaction extends Transaction { new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(this.mosaic.id.id.toDTO()), new AmountDto(this.mosaic.amount.toDTO())), new BlockDurationDto(this.duration.toDTO()), this.hashAlgorithm.valueOf(), - new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress, this.networkType)), + new UnresolvedAddressDto(this.recipientAddress.encodeUnresolvedAddress(this.networkType)), ); } @@ -276,8 +277,8 @@ export class SecretLockTransaction extends Transaction { public shouldNotifyAccount(address: Address, alias: NamespaceId[]): boolean { return ( super.isSigned(address) || - (this.recipientAddress as Address).equals(address) || - alias.find((name) => (this.recipientAddress as NamespaceId).equals(name)) !== undefined + this.recipientAddress.equals(address) || + alias.find((name) => this.recipientAddress.equals(name)) !== undefined ); } } diff --git a/src/model/transaction/SecretProofTransaction.ts b/src/model/transaction/SecretProofTransaction.ts index 501dd85f8b..19a19c7e46 100644 --- a/src/model/transaction/SecretProofTransaction.ts +++ b/src/model/transaction/SecretProofTransaction.ts @@ -41,6 +41,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { UnresolvedAddress } from '../account/UnresolvedAddress'; export class SecretProofTransaction extends Transaction { /** @@ -61,7 +62,7 @@ export class SecretProofTransaction extends Transaction { deadline: Deadline, hashAlgorithm: LockHashAlgorithm, secret: string, - recipientAddress: Address | NamespaceId, + recipientAddress: UnresolvedAddress, proof: string, networkType: NetworkType, maxFee: UInt64 = new UInt64([0, 0]), @@ -102,7 +103,7 @@ export class SecretProofTransaction extends Transaction { maxFee: UInt64, public readonly hashAlgorithm: LockHashAlgorithm, public readonly secret: string, - public readonly recipientAddress: Address | NamespaceId, + public readonly recipientAddress: UnresolvedAddress, public readonly proof: string, signature?: string, signer?: PublicAccount, @@ -198,7 +199,7 @@ export class SecretProofTransaction extends Transaction { new TimestampDto(this.deadline.toDTO()), new Hash256Dto(this.getSecretByte()), this.hashAlgorithm.valueOf(), - new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress, this.networkType)), + new UnresolvedAddressDto(this.recipientAddress.encodeUnresolvedAddress(this.networkType)), this.getProofByte(), ); return transactionBuilder.serialize(); @@ -216,7 +217,7 @@ export class SecretProofTransaction extends Transaction { TransactionType.SECRET_PROOF.valueOf(), new Hash256Dto(this.getSecretByte()), this.hashAlgorithm.valueOf(), - new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress, this.networkType)), + new UnresolvedAddressDto(this.recipientAddress.encodeUnresolvedAddress(this.networkType)), this.getProofByte(), ); } @@ -249,8 +250,8 @@ export class SecretProofTransaction extends Transaction { public shouldNotifyAccount(address: Address, alias: NamespaceId[]): boolean { return ( super.isSigned(address) || - (this.recipientAddress as Address).equals(address) || - alias.find((name) => (this.recipientAddress as NamespaceId).equals(name)) !== undefined + this.recipientAddress.equals(address) || + alias.find((name) => this.recipientAddress.equals(name)) !== undefined ); } } diff --git a/src/model/transaction/TransferTransaction.ts b/src/model/transaction/TransferTransaction.ts index 166539ce60..e066b3e4c9 100644 --- a/src/model/transaction/TransferTransaction.ts +++ b/src/model/transaction/TransferTransaction.ts @@ -48,6 +48,7 @@ import { Transaction } from './Transaction'; import { TransactionInfo } from './TransactionInfo'; import { TransactionType } from './TransactionType'; import { TransactionVersion } from './TransactionVersion'; +import { UnresolvedAddress } from '../account/UnresolvedAddress'; /** * Transfer transactions contain data about transfers of mosaics and message to another account. @@ -70,7 +71,7 @@ export class TransferTransaction extends Transaction { */ public static create( deadline: Deadline, - recipientAddress: Address | NamespaceId, + recipientAddress: UnresolvedAddress, mosaics: Mosaic[], message: Message, networkType: NetworkType, @@ -111,7 +112,7 @@ export class TransferTransaction extends Transaction { /** * The address of the recipient address. */ - public readonly recipientAddress: Address | NamespaceId, + public readonly recipientAddress: UnresolvedAddress, /** * The array of Mosaic objects. */ @@ -270,7 +271,7 @@ export class TransferTransaction extends Transaction { TransactionType.TRANSFER.valueOf(), new AmountDto(this.maxFee.toDTO()), new TimestampDto(this.deadline.toDTO()), - new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress, this.networkType)), + new UnresolvedAddressDto(this.recipientAddress.encodeUnresolvedAddress(this.networkType)), this.sortMosaics().map((mosaic) => { return new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(mosaic.id.id.toDTO()), new AmountDto(mosaic.amount.toDTO())); }), @@ -289,7 +290,7 @@ export class TransferTransaction extends Transaction { this.versionToDTO(), this.networkType.valueOf(), TransactionType.TRANSFER.valueOf(), - new UnresolvedAddressDto(UnresolvedMapping.toUnresolvedAddressBytes(this.recipientAddress, this.networkType)), + new UnresolvedAddressDto(this.recipientAddress.encodeUnresolvedAddress(this.networkType)), this.sortMosaics().map((mosaic) => { return new UnresolvedMosaicBuilder(new UnresolvedMosaicIdDto(mosaic.id.id.toDTO()), new AmountDto(mosaic.amount.toDTO())); }), @@ -328,8 +329,8 @@ export class TransferTransaction extends Transaction { public shouldNotifyAccount(address: Address, alias: NamespaceId[]): boolean { return ( super.isSigned(address) || - (this.recipientAddress as Address).equals(address) || - alias.find((name) => (this.recipientAddress as NamespaceId).equals(name)) !== undefined + this.recipientAddress.equals(address) || + alias.find((name) => this.recipientAddress.equals(name)) !== undefined ); } } diff --git a/src/service/MetadataTransactionService.ts b/src/service/MetadataTransactionService.ts index b77fcb475f..f90d9e8363 100644 --- a/src/service/MetadataTransactionService.ts +++ b/src/service/MetadataTransactionService.ts @@ -29,6 +29,7 @@ import { Deadline } from '../model/transaction/Deadline'; import { MosaicMetadataTransaction } from '../model/transaction/MosaicMetadataTransaction'; import { NamespaceMetadataTransaction } from '../model/transaction/NamespaceMetadataTransaction'; import { UInt64 } from '../model/UInt64'; +import { UnresolvedMosaicId } from '../model/mosaic/UnresolvedMosaicId'; /** * MetadataTransaction service @@ -49,7 +50,7 @@ export class MetadataTransactionService { * @param key - Metadata scoped key * @param value - New metadata value * @param sourceAddress - sender (signer) address - * @param targetId - Target Id (MosaicId | NamespaceId) + * @param targetId - Target Id (UnresolvedMosaicId) * @param maxFee - Max fee * @return {AccountMetadataTransaction | MosaicMetadataTransaction | NamespaceMetadataTransaction} */ @@ -61,7 +62,7 @@ export class MetadataTransactionService { key: UInt64, value: string, sourceAddress: Address, - targetId?: MosaicId | NamespaceId, + targetId?: UnresolvedMosaicId, maxFee: UInt64 = new UInt64([0, 0]), ): Observable { switch (metadataType) { diff --git a/src/service/MosaicRestrictionTransactionService.ts b/src/service/MosaicRestrictionTransactionService.ts index f8cfe3f44a..00e32cd27b 100644 --- a/src/service/MosaicRestrictionTransactionService.ts +++ b/src/service/MosaicRestrictionTransactionService.ts @@ -20,7 +20,6 @@ import { NamespaceRepository } from '../infrastructure/NamespaceRepository'; import { RestrictionMosaicRepository } from '../infrastructure/RestrictionMosaicRepository'; import { Address } from '../model/account/Address'; import { MosaicId } from '../model/mosaic/MosaicId'; -import { NamespaceId } from '../model/namespace/NamespaceId'; import { NetworkType } from '../model/network/NetworkType'; import { MosaicGlobalRestriction } from '../model/restriction/MosaicGlobalRestriction'; import { MosaicGlobalRestrictionItem } from '../model/restriction/MosaicGlobalRestrictionItem'; @@ -30,6 +29,8 @@ import { MosaicAddressRestrictionTransaction } from '../model/transaction/Mosaic import { MosaicGlobalRestrictionTransaction } from '../model/transaction/MosaicGlobalRestrictionTransaction'; import { Transaction } from '../model/transaction/Transaction'; import { UInt64 } from '../model/UInt64'; +import { UnresolvedAddress } from '../model/account/UnresolvedAddress'; +import { UnresolvedMosaicId } from '../model/mosaic/UnresolvedMosaicId'; /** * MosaicRestrictionTransactionService service @@ -62,11 +63,11 @@ export class MosaicRestrictionTransactionService { public createMosaicGlobalRestrictionTransaction( deadline: Deadline, networkType: NetworkType, - mosaicId: MosaicId | NamespaceId, + mosaicId: UnresolvedMosaicId, restrictionKey: UInt64, restrictionValue: string, restrictionType: MosaicRestrictionType, - referenceMosaicId: MosaicId | NamespaceId = new MosaicId(UInt64.fromUint(0).toDTO()), + referenceMosaicId: UnresolvedMosaicId = new MosaicId(UInt64.fromUint(0).toDTO()), maxFee: UInt64 = new UInt64([0, 0]), ): Observable { this.validateInput(restrictionValue); @@ -109,9 +110,9 @@ export class MosaicRestrictionTransactionService { public createMosaicAddressRestrictionTransaction( deadline: Deadline, networkType: NetworkType, - mosaicId: MosaicId | NamespaceId, + mosaicId: UnresolvedMosaicId, restrictionKey: UInt64, - targetAddress: Address | NamespaceId, + targetAddress: UnresolvedAddress, restrictionValue: string, maxFee: UInt64 = new UInt64([0, 0]), ): Observable { @@ -206,7 +207,7 @@ export class MosaicRestrictionTransactionService { * @param unresolvedMosaicId unresolved mosaicId * @returns {MosaicId} */ - private getResolvedMosaicId(unresolvedMosaicId: MosaicId | NamespaceId): Observable { + private getResolvedMosaicId(unresolvedMosaicId: UnresolvedMosaicId): Observable { if (unresolvedMosaicId instanceof MosaicId) { return of(unresolvedMosaicId); } @@ -230,7 +231,7 @@ export class MosaicRestrictionTransactionService { * @param unresolvedAddress unresolved address * @returns {Address} */ - private getResolvedAddress(unresolvedAddress: Address | NamespaceId): Observable
{ + private getResolvedAddress(unresolvedAddress: UnresolvedAddress): Observable
{ if (unresolvedAddress instanceof Address) { return of(unresolvedAddress); } From b960051b494a589dcbe0454595e67a0f21eb2805 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Fri, 5 Jun 2020 11:24:05 +0100 Subject: [PATCH 04/22] Added A, I, Q, Y check on address --- src/model/account/Address.ts | 5 ++++- test/model/account/Address.spec.ts | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/model/account/Address.ts b/src/model/account/Address.ts index 9a318495b0..a219d4ca61 100644 --- a/src/model/account/Address.ts +++ b/src/model/account/Address.ts @@ -69,10 +69,13 @@ export class Address { /** * Determines the validity of an raw address string. - * @param {string} rawAddress The raw address string. Expected format SCHCZBZ6QVJAHGJTKYVPW5FBSO2IXXJQBPV5XE6P + * @param {string} rawAddress The raw address string. Expected format SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ * @returns {boolean} true if the raw address string is valid, false otherwise. */ public static isValidRawAddress = (rawAddress: string): boolean => { + if (!['A', 'I', 'Q', 'Y'].includes(rawAddress.slice(-1).toUpperCase())) { + return false; + } try { return RawAddress.isValidAddress(RawAddress.stringToAddress(rawAddress)); } catch (err) { diff --git a/test/model/account/Address.spec.ts b/test/model/account/Address.spec.ts index b92513d706..56f84fb4c1 100644 --- a/test/model/account/Address.spec.ts +++ b/test/model/account/Address.spec.ts @@ -151,6 +151,29 @@ describe('Address', () => { // Assert: expect(Address.isValidRawAddress(rawAddress)).to.equal(false); }); + + it('returns false if last char not in A, I, Q, Y', () => { + // Arrange: + const rawAddress = 'NAR3W7B4BCOZSZMFIZRYB3N5YGOUSWIYJCJ6HDF'; + + // Assert: + expect(Address.isValidRawAddress(rawAddress)).to.equal(false); + }); + + it('returns true if last char in A, I, Q, Y', () => { + // Arrange: + const rawAddress = [ + 'NAR3W7B4BCOZSZMFIZRYB3N5YGOUSWIYJCJ6HDA', + 'TDZ4373ASEGJ7S7GQTKF26TIIMC7HK5EWEPHRSI', + 'MDZ4373ASEGJ7S7GQTKF26TIIMC7HK5EWFN3NKY', + 'MCOVTFVVDZGNURZFU4IJLJR37X5TXNWMTTARXZQ', + ]; + + // Assert: + rawAddress.forEach((address) => { + expect(Address.isValidRawAddress(address)).to.equal(true); + }); + }); }); describe('isValidEncodedAddress', () => { From 4da790877eeea473e0aafdd06714cb5adaf59039 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 9 Jun 2020 21:05:50 +0100 Subject: [PATCH 05/22] Gernate MosaicId by address now --- src/core/format/IdGenerator.ts | 8 ++-- .../transaction/NamespaceMosaicIdGenerator.ts | 6 +-- src/model/mosaic/MosaicId.ts | 2 +- test/core/format/IdGenerator.spec.ts | 39 ++----------------- test/model/mosaic/MosaicId.spec.ts | 2 +- 5 files changed, 12 insertions(+), 45 deletions(-) diff --git a/src/core/format/IdGenerator.ts b/src/core/format/IdGenerator.ts index f0052d95a6..166202b14d 100644 --- a/src/core/format/IdGenerator.ts +++ b/src/core/format/IdGenerator.ts @@ -18,15 +18,15 @@ import * as utilities from './Utilities'; export class IdGenerator { /** - * Generates a mosaic id given a nonce and a public id. + * Generates a mosaic id given a nonce and a address. * @param {object} nonce The mosaic nonce. - * @param {object} ownerPublicId The public id. + * @param {object} ownerAddress The address. * @returns {module:coders/uint64~uint64} The mosaic id. */ - public static generateMosaicId = (nonce: any, ownerPublicId: any): number[] => { + public static generateMosaicId = (nonce: any, ownerAddress: any): number[] => { const hash = sha3_256.create(); hash.update(nonce); - hash.update(ownerPublicId); + hash.update(ownerAddress); const result = new Uint32Array(hash.arrayBuffer()); return [result[0], result[1] & 0x7fffffff]; }; diff --git a/src/infrastructure/transaction/NamespaceMosaicIdGenerator.ts b/src/infrastructure/transaction/NamespaceMosaicIdGenerator.ts index c70bc0fc7f..583b4b27f3 100644 --- a/src/infrastructure/transaction/NamespaceMosaicIdGenerator.ts +++ b/src/infrastructure/transaction/NamespaceMosaicIdGenerator.ts @@ -20,11 +20,11 @@ import { IdGenerator } from '../../core/format'; export class NamespaceMosaicIdGenerator { /** * @param {Uint8Array} nonce Mosaic nonce - * @param {Uint8Array} ownerPublicId Public key + * @param {Uint8Array} ownerAddress Address * @returns {number[]} mosaic Id */ - public static mosaicId = (nonce: Uint8Array, ownerPublicId: Uint8Array): number[] => { - return IdGenerator.generateMosaicId(nonce, ownerPublicId); + public static mosaicId = (nonce: Uint8Array, ownerAddress: Uint8Array): number[] => { + return IdGenerator.generateMosaicId(nonce, ownerAddress); }; /** diff --git a/src/model/mosaic/MosaicId.ts b/src/model/mosaic/MosaicId.ts index 4cf900e263..603d7b6017 100644 --- a/src/model/mosaic/MosaicId.ts +++ b/src/model/mosaic/MosaicId.ts @@ -38,7 +38,7 @@ export class MosaicId { * @return {MosaicId} */ public static createFromNonce(nonce: MosaicNonce, owner: PublicAccount): MosaicId { - const mosaicId = NamespaceMosaicIdGenerator.mosaicId(nonce.toUint8Array(), convert.hexToUint8(owner.publicKey)); + const mosaicId = NamespaceMosaicIdGenerator.mosaicId(nonce.toUint8Array(), convert.hexToUint8(owner.address.encoded())); return new MosaicId(mosaicId); } diff --git a/test/core/format/IdGenerator.spec.ts b/test/core/format/IdGenerator.spec.ts index 88f3607e8d..351f0ea661 100644 --- a/test/core/format/IdGenerator.spec.ts +++ b/test/core/format/IdGenerator.spec.ts @@ -25,41 +25,8 @@ const constants = { const basicMosaicInfo = { nonce: [0x78, 0xe3, 0x6f, 0xb7], - publicId: [ - 0x4a, - 0xff, - 0x7b, - 0x4b, - 0xa8, - 0xc1, - 0xc2, - 0x6a, - 0x79, - 0x17, - 0x57, - 0x59, - 0x93, - 0x34, - 0x66, - 0x27, - 0xcb, - 0x6c, - 0x80, - 0xde, - 0x62, - 0xcd, - 0x92, - 0xf7, - 0xf9, - 0xae, - 0xdb, - 0x70, - 0x64, - 0xa3, - 0xde, - 0x62, - ], - id: [0xc0afc518, 0x3ad842a8], + address: [144, 43, 151, 19, 142, 202, 193, 168, 140, 158, 106, 98, 111, 47, 199, 100, 233, 98, 104, 137, 71, 177, 230, 122], + id: [339608571, 538088181], }; const mosaicTestVector = { @@ -215,7 +182,7 @@ describe('id generator', () => { describe('generate mosaic id', () => { it('generates correct well known id', () => { // Assert: - expect(idGenerator.generateMosaicId(basicMosaicInfo.nonce, basicMosaicInfo.publicId)).to.deep.equal(basicMosaicInfo.id); + expect(idGenerator.generateMosaicId(basicMosaicInfo.nonce, basicMosaicInfo.address)).to.deep.equal(basicMosaicInfo.id); }); // @dataProvider mosaicTestVector diff --git a/test/model/mosaic/MosaicId.spec.ts b/test/model/mosaic/MosaicId.spec.ts index cc4fdfa9dc..eec5a8d949 100644 --- a/test/model/mosaic/MosaicId.spec.ts +++ b/test/model/mosaic/MosaicId.spec.ts @@ -37,7 +37,7 @@ describe('MosaicId', () => { it('should create id given nonce and owner', () => { const owner = PublicAccount.createFromPublicKey(publicKey, NetworkType.MIJIN_TEST); const id = MosaicId.createFromNonce(MosaicNonce.createFromNumber(0), owner); - deepEqual(id.id, new Id([481110499, 231112638])); + deepEqual(id.id, new Id([3526830425, 1241357627])); }); it('should create id twice the same given nonce and owner', () => { From 97d0e3fab12f57274506fd2316d5a838bfbbaf5b Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 11 Jun 2020 15:16:33 +0100 Subject: [PATCH 06/22] - A few issues fixed. - Integration tests fixed - updated openAPI and catbuffer lib version --- e2e/infrastructure/AccountHttp.spec.ts | 30 ++++----- e2e/infrastructure/IntegrationTestHelper.ts | 4 +- e2e/infrastructure/Listener.spec.ts | 17 +++-- e2e/infrastructure/MetadataHttp.spec.ts | 37 +++++------ e2e/infrastructure/MosaicHttp.spec.ts | 6 +- e2e/infrastructure/TransactionHttp.spec.ts | 63 +++++++++++++------ package-lock.json | 12 ++-- package.json | 4 +- src/infrastructure/TransactionHttp.ts | 2 +- .../TransactionSearchCriteria.ts | 7 +-- test/infrastructure/TransactionHttp.spec.ts | 4 +- .../TransactionSearchCriteria.spec.ts | 15 ++--- 12 files changed, 109 insertions(+), 92 deletions(-) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index f1802fab40..9462daa1fc 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -177,21 +177,6 @@ describe('AccountHttp', () => { }); }); - describe('getMultisigAccountGraphInfo', () => { - it('should call getMultisigAccountGraphInfo successfully', async () => { - const multisigAccountGraphInfo = await multisigRepository - .getMultisigAccountGraphInfo(multisigAccount.publicAccount.address) - .toPromise(); - expect(multisigAccountGraphInfo.multisigEntries.get(0)![0].accountAddress.plain()).to.be.equal(multisigAccount.address.plain()); - }); - }); - describe('getMultisigAccountInfo', () => { - it('should call getMultisigAccountInfo successfully', async () => { - const multisigAccountInfo = await multisigRepository.getMultisigAccountInfo(multisigAccount.publicAccount.address).toPromise(); - expect(multisigAccountInfo.accountAddress.plain()).to.be.equal(multisigAccount.address.plain()); - }); - }); - describe('transactions', () => { it('should not return accounts when account does not exist', () => { return accountRepository @@ -218,6 +203,21 @@ describe('AccountHttp', () => { }); }); + describe('getMultisigAccountGraphInfo', () => { + it('should call getMultisigAccountGraphInfo successfully', async () => { + await new Promise((resolve) => setTimeout(resolve, 3000)); + const multisigAccountGraphInfo = await multisigRepository + .getMultisigAccountGraphInfo(multisigAccount.publicAccount.address) + .toPromise(); + expect(multisigAccountGraphInfo.multisigEntries.get(0)![0].accountAddress.plain()).to.be.equal(multisigAccount.address.plain()); + }); + }); + describe('getMultisigAccountInfo', () => { + it('should call getMultisigAccountInfo successfully', async () => { + const multisigAccountInfo = await multisigRepository.getMultisigAccountInfo(multisigAccount.publicAccount.address).toPromise(); + expect(multisigAccountInfo.accountAddress.plain()).to.be.equal(multisigAccount.address.plain()); + }); + }); /** * ========================= * House Keeping diff --git a/e2e/infrastructure/IntegrationTestHelper.ts b/e2e/infrastructure/IntegrationTestHelper.ts index 50cd9ac7c3..f13403bcfb 100644 --- a/e2e/infrastructure/IntegrationTestHelper.ts +++ b/e2e/infrastructure/IntegrationTestHelper.ts @@ -108,7 +108,9 @@ export class IntegrationTestHelper { this.account3 = this.createAccount(parsedYaml.nemesis_addresses[2]); this.multisigAccount = this.createAccount(parsedYaml.nemesis_addresses[3]); this.cosignAccount1 = this.createAccount(parsedYaml.nemesis_addresses[4]); - this.cosignAccount4 = this.createAccount(parsedYaml.nemesis_addresses[5]); + this.cosignAccount2 = this.createAccount(parsedYaml.nemesis_addresses[5]); + this.cosignAccount3 = this.createAccount(parsedYaml.nemesis_addresses[6]); + this.cosignAccount4 = this.createAccount(parsedYaml.nemesis_addresses[7]); this.harvestingAccount = this.createAccount(parsedYaml.nemesis_addresses_harvesting[0]); return resolve(this); } diff --git a/e2e/infrastructure/Listener.spec.ts b/e2e/infrastructure/Listener.spec.ts index 807960c7a7..6be1e8fef9 100644 --- a/e2e/infrastructure/Listener.spec.ts +++ b/e2e/infrastructure/Listener.spec.ts @@ -19,7 +19,6 @@ import { filter } from 'rxjs/operators'; import { TransactionRepository } from '../../src/infrastructure/TransactionRepository'; import { Account } from '../../src/model/account/Account'; import { PlainMessage } from '../../src/model/message/PlainMessage'; -import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { NetworkType } from '../../src/model/network/NetworkType'; import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction'; import { Deadline } from '../../src/model/transaction/Deadline'; @@ -46,7 +45,6 @@ describe('Listener', () => { let cosignAccount3: Account; let generationHash: string; let networkType: NetworkType; - const NetworkCurrencyLocalId: NamespaceId = helper.networkCurrencyNamespaceId; let transactionRepository: TransactionRepository; before(() => { @@ -187,7 +185,7 @@ describe('Listener', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), cosignAccount1.address, - [new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, helper.networkCurrencyDivisibility)))], + [helper.createNetworkCurrency(10, true)], PlainMessage.create('test-message'), networkType, helper.maxFee, @@ -230,7 +228,7 @@ describe('Listener', () => { describe('Aggregate Bonded Transactions', () => { it('aggregateBondedTransactionsAdded', (done) => { const signedAggregatedTx = createSignedAggregatedBondTransaction(multisigAccount, account, account2.address); - createHashLockTransactionAndAnnounce(signedAggregatedTx, account, NetworkCurrencyLocalId); + createHashLockTransactionAndAnnounce(signedAggregatedTx, account, helper.networkCurrencyNamespaceId); helper.listener.aggregateBondedAdded(account.address).subscribe(() => { done(); }); @@ -248,18 +246,19 @@ describe('Listener', () => { it('aggregateBondedTransactionsRemoved', (done) => { const signedAggregatedTx = createSignedAggregatedBondTransaction(multisigAccount, cosignAccount1, account2.address); - createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, NetworkCurrencyLocalId); + createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, helper.networkCurrencyNamespaceId); helper.listener.confirmed(cosignAccount1.address).subscribe(() => { helper.listener.aggregateBondedRemoved(cosignAccount1.address).subscribe(() => { done(); }); helper.listener.aggregateBondedAdded(cosignAccount1.address).subscribe(() => { const criteria: TransactionSearchCriteria = { - address: cosignAccount1.publicAccount.address, + address: cosignAccount1.address, group: TransactionGroupSubsetEnum.Partial, }; transactionRepository.search(criteria).subscribe((transactions) => { - const transactionToCosign = transactions[0]; + console.log('Partial', transactions.data); + const transactionToCosign = transactions.data[0] as AggregateTransaction; const cosignatureTransaction = CosignatureTransaction.create(transactionToCosign); const cosignatureSignedTransaction = cosignAccount2.signCosignatureTransaction(cosignatureTransaction); transactionRepository.announceAggregateBondedCosignature(cosignatureSignedTransaction); @@ -284,7 +283,7 @@ describe('Listener', () => { it('cosignatureAdded', (done) => { const signedAggregatedTx = createSignedAggregatedBondTransaction(multisigAccount, cosignAccount1, account2.address); - createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, NetworkCurrencyLocalId); + createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, helper.networkCurrencyNamespaceId); helper.listener.cosignatureAdded(cosignAccount1.address).subscribe(() => { done(); }); @@ -294,7 +293,7 @@ describe('Listener', () => { group: TransactionGroupSubsetEnum.Partial, }; transactionRepository.search(criteria).subscribe((transactions) => { - const transactionToCosign = transactions[0]; + const transactionToCosign = transactions.data[0] as AggregateTransaction; const cosignatureTransaction = CosignatureTransaction.create(transactionToCosign); const cosignatureSignedTransaction = cosignAccount2.signCosignatureTransaction(cosignatureTransaction); transactionRepository.announceAggregateBondedCosignature(cosignatureSignedTransaction); diff --git a/e2e/infrastructure/MetadataHttp.spec.ts b/e2e/infrastructure/MetadataHttp.spec.ts index af918e5ab1..cd25ce585c 100644 --- a/e2e/infrastructure/MetadataHttp.spec.ts +++ b/e2e/infrastructure/MetadataHttp.spec.ts @@ -107,7 +107,7 @@ describe('MetadataHttp', () => { const accountMetadataTransaction = AccountMetadataTransaction.create( Deadline.create(), account.address, - UInt64.fromUint(5), + UInt64.fromUint(6), 23, `Test account meta value`, networkType, @@ -119,6 +119,7 @@ describe('MetadataHttp', () => { [accountMetadataTransaction.toAggregate(account.publicAccount)], networkType, [], + helper.maxFee, ); const signedTransaction = aggregateTransaction.signWith(account, generationHash); return helper.announce(signedTransaction); @@ -130,7 +131,7 @@ describe('MetadataHttp', () => { const mosaicMetadataTransaction = MosaicMetadataTransaction.create( Deadline.create(), account.address, - UInt64.fromUint(5), + UInt64.fromUint(6), mosaicId, 22, `Test mosaic meta value`, @@ -155,7 +156,7 @@ describe('MetadataHttp', () => { const namespaceMetadataTransaction = NamespaceMetadataTransaction.create( Deadline.create(), account.address, - UInt64.fromUint(5), + UInt64.fromUint(6), namespaceId, 25, `Test namespace meta value`, @@ -185,7 +186,7 @@ describe('MetadataHttp', () => { it('should return metadata given a NEM Address', async () => { const metadata = await metadataRepository.getAccountMetadata(accountAddress).toPromise(); expect(metadata.length).to.be.greaterThan(0); - expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); + expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('6'); expect(metadata[0].metadataEntry.sourceAddress).to.be.deep.equal(account.address); expect(metadata[0].metadataEntry.targetAddress).to.be.deep.equal(account.address); expect(metadata[0].metadataEntry.targetId).to.be.undefined; @@ -196,9 +197,9 @@ describe('MetadataHttp', () => { describe('getAccountMetadataByKey', () => { it('should return metadata given a NEM Address and metadata key', async () => { - const metadata = await metadataRepository.getAccountMetadataByKey(accountAddress, UInt64.fromUint(5).toHex()).toPromise(); + const metadata = await metadataRepository.getAccountMetadataByKey(accountAddress, UInt64.fromUint(6).toHex()).toPromise(); expect(metadata.length).to.be.greaterThan(0); - expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); + expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('6'); expect(metadata[0].metadataEntry.sourceAddress).to.be.deep.equal(account.address); expect(metadata[0].metadataEntry.targetAddress).to.be.deep.equal(account.address); expect(metadata[0].metadataEntry.targetId).to.be.undefined; @@ -210,9 +211,9 @@ describe('MetadataHttp', () => { describe('getAccountMetadataByKeyAndSender', () => { it('should return metadata given a NEM Address and metadata key and sender public key', async () => { const metadata = await metadataRepository - .getAccountMetadataByKeyAndSender(accountAddress, UInt64.fromUint(5).toHex(), account.address) + .getAccountMetadataByKeyAndSender(accountAddress, UInt64.fromUint(6).toHex(), account.address) .toPromise(); - expect(metadata.metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); + expect(metadata.metadataEntry.scopedMetadataKey.toString()).to.be.equal('6'); expect(metadata.metadataEntry.sourceAddress).to.be.deep.equal(account.address); expect(metadata.metadataEntry.targetAddress).to.be.deep.equal(account.address); expect(metadata.metadataEntry.targetId).to.be.undefined; @@ -225,7 +226,7 @@ describe('MetadataHttp', () => { it('should return metadata given a mosaicId', async () => { const metadata = await metadataRepository.getMosaicMetadata(mosaicId).toPromise(); expect(metadata.length).to.be.greaterThan(0); - expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); + expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('6'); expect(metadata[0].metadataEntry.sourceAddress).to.be.deep.equal(account.address); expect(metadata[0].metadataEntry.targetAddress).to.be.deep.equal(account.address); expect((metadata[0].metadataEntry.targetId as MosaicId).toHex()).to.be.equal(mosaicId.toHex()); @@ -236,9 +237,9 @@ describe('MetadataHttp', () => { describe('getMosaicMetadataByKey', () => { it('should return metadata given a mosaicId and metadata key', async () => { - const metadata = await metadataRepository.getMosaicMetadataByKey(mosaicId, UInt64.fromUint(5).toHex()).toPromise(); + const metadata = await metadataRepository.getMosaicMetadataByKey(mosaicId, UInt64.fromUint(6).toHex()).toPromise(); expect(metadata.length).to.be.greaterThan(0); - expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); + expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('6'); expect(metadata[0].metadataEntry.sourceAddress).to.be.deep.equal(account.address); expect(metadata[0].metadataEntry.targetAddress).to.be.deep.equal(account.address); expect((metadata[0].metadataEntry.targetId as MosaicId).toHex()).to.be.equal(mosaicId.toHex()); @@ -250,9 +251,9 @@ describe('MetadataHttp', () => { describe('getMosaicMetadataByKeyAndSender', () => { it('should return metadata given a mosaicId and metadata key and sender public key', async () => { const metadata = await metadataRepository - .getMosaicMetadataByKeyAndSender(mosaicId, UInt64.fromUint(5).toHex(), account.address) + .getMosaicMetadataByKeyAndSender(mosaicId, UInt64.fromUint(6).toHex(), account.address) .toPromise(); - expect(metadata.metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); + expect(metadata.metadataEntry.scopedMetadataKey.toString()).to.be.equal('6'); expect(metadata.metadataEntry.sourceAddress).to.be.deep.equal(account.address); expect(metadata.metadataEntry.targetAddress).to.be.deep.equal(account.address); expect((metadata.metadataEntry.targetId as MosaicId).toHex()).to.be.equal(mosaicId.toHex()); @@ -265,7 +266,7 @@ describe('MetadataHttp', () => { it('should return metadata given a namespaceId', async () => { const metadata = await metadataRepository.getNamespaceMetadata(namespaceId).toPromise(); expect(metadata.length).to.be.greaterThan(0); - expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); + expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('6'); expect(metadata[0].metadataEntry.sourceAddress).to.be.deep.equal(account.address); expect(metadata[0].metadataEntry.targetAddress).to.be.deep.equal(account.address); expect((metadata[0].metadataEntry.targetId as NamespaceId).toHex()).to.be.equal(namespaceId.toHex()); @@ -276,9 +277,9 @@ describe('MetadataHttp', () => { describe('getNamespaceMetadataByKey', () => { it('should return metadata given a namespaceId and metadata key', async () => { - const metadata = await metadataRepository.getNamespaceMetadataByKey(namespaceId, UInt64.fromUint(5).toHex()).toPromise(); + const metadata = await metadataRepository.getNamespaceMetadataByKey(namespaceId, UInt64.fromUint(6).toHex()).toPromise(); expect(metadata.length).to.be.greaterThan(0); - expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); + expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('6'); expect(metadata[0].metadataEntry.sourceAddress).to.be.deep.equal(account.address); expect(metadata[0].metadataEntry.targetAddress).to.be.deep.equal(account.address); expect((metadata[0].metadataEntry.targetId as NamespaceId).toHex()).to.be.equal(namespaceId.toHex()); @@ -290,9 +291,9 @@ describe('MetadataHttp', () => { describe('getNamespaceMetadataByKeyAndSender', () => { it('should return metadata given a namespaceId and metadata key and sender public key', async () => { const metadata = await metadataRepository - .getNamespaceMetadataByKeyAndSender(namespaceId, UInt64.fromUint(5).toHex(), account.address) + .getNamespaceMetadataByKeyAndSender(namespaceId, UInt64.fromUint(6).toHex(), account.address) .toPromise(); - expect(metadata.metadataEntry.scopedMetadataKey.toString()).to.be.equal('5'); + expect(metadata.metadataEntry.scopedMetadataKey.toString()).to.be.equal('6'); expect(metadata.metadataEntry.sourceAddress).to.be.deep.equal(account.address); expect(metadata.metadataEntry.targetAddress).to.be.deep.equal(account.address); expect((metadata.metadataEntry.targetId as NamespaceId).toHex()).to.be.equal(namespaceId.toHex()); diff --git a/e2e/infrastructure/MosaicHttp.spec.ts b/e2e/infrastructure/MosaicHttp.spec.ts index 1a3a68ac58..3d7cf3a870 100644 --- a/e2e/infrastructure/MosaicHttp.spec.ts +++ b/e2e/infrastructure/MosaicHttp.spec.ts @@ -173,10 +173,10 @@ describe('MosaicHttp', () => { it('should call searchMosaics successfully', async () => { const streamer = new MosaicPaginationStreamer(mosaicRepository); const mosaicsStreamer = await streamer - .search({ ownerAddress: account.address, pageSize: 3 }) - .pipe(take(3), toArray()) + .search({ ownerAddress: account.address, pageSize: 100 }) + .pipe(take(100), toArray()) .toPromise(); - const mosaics = await mosaicRepository.search({ ownerAddress: account.address, pageSize: 3 }).toPromise(); + const mosaics = await mosaicRepository.search({ ownerAddress: account.address, pageSize: 100 }).toPromise(); expect(mosaicsStreamer.length).to.be.greaterThan(0); expect(mosaicsStreamer.find((m) => m.id.toHex() === mosaicId.toHex()) !== undefined).to.be.true; deepEqual(mosaics.data, mosaicsStreamer); diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 62c1911808..43af66d394 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -79,8 +79,8 @@ import { OperationRestrictionFlag } from '../../src/model/restriction/OperationR const CryptoJS = require('crypto-js'); describe('TransactionHttp', () => { - let transactionHash; - let transactionId; + let transactionHash: string; + let transactionId: string; const helper = new IntegrationTestHelper(); let account: Account; @@ -93,7 +93,8 @@ describe('TransactionHttp', () => { let networkType: NetworkType; let mosaicId: MosaicId; let NetworkCurrencyLocalId: MosaicId; - let namespaceId: NamespaceId; + let addressAlias: NamespaceId; + let mosaicAlias: NamespaceId; let harvestingAccount: Account; let transactionRepository: TransactionRepository; let votingKey: string; @@ -104,6 +105,8 @@ describe('TransactionHttp', () => { // eslint-disable-next-line @typescript-eslint/no-var-requires const ripemd160 = require('ripemd160'); + const remoteAccount = Account.generateNewAccount(helper.networkType); + before(() => { return helper.start().then(() => { account = helper.account; @@ -148,6 +151,7 @@ describe('TransactionHttp', () => { helper.maxFee, ); const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash); + transactionHash = signedTransaction.hash; return helper.announce(signedTransaction).then((transaction: MosaicDefinitionTransaction) => { expect(transaction.mosaicId, 'MosaicId').not.to.be.undefined; @@ -257,11 +261,31 @@ describe('TransactionHttp', () => { const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( Deadline.create(), namespaceName, - UInt64.fromUint(10), + UInt64.fromUint(50), networkType, helper.maxFee, ); - namespaceId = new NamespaceId(namespaceName); + addressAlias = new NamespaceId(namespaceName); + const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); + return helper.announce(signedTransaction).then((transaction: NamespaceRegistrationTransaction) => { + expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; + expect(transaction.namespaceName, 'NamespaceName').not.to.be.undefined; + expect(transaction.registrationType, 'RegistrationType').not.to.be.undefined; + }); + }); + }); + + describe('NamespaceRegistrationTransaction', () => { + it('standalone', () => { + const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000); + const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace( + Deadline.create(), + namespaceName, + UInt64.fromUint(50), + networkType, + helper.maxFee, + ); + mosaicAlias = new NamespaceId(namespaceName); const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash); return helper.announce(signedTransaction).then((transaction: NamespaceRegistrationTransaction) => { expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined; @@ -298,7 +322,7 @@ describe('TransactionHttp', () => { Deadline.create(), account.address, UInt64.fromUint(5), - namespaceId, + addressAlias, 10, Convert.uint8ToUtf8(new Uint8Array(10)), networkType, @@ -591,7 +615,7 @@ describe('TransactionHttp', () => { it('standalone', () => { const accountLinkTransaction = AccountKeyLinkTransaction.create( Deadline.create(), - account3.publicKey, + remoteAccount.publicKey, LinkAction.Link, networkType, helper.maxFee, @@ -609,7 +633,7 @@ describe('TransactionHttp', () => { it('aggregate', () => { const accountLinkTransaction = AccountKeyLinkTransaction.create( Deadline.create(), - account3.publicKey, + remoteAccount.publicKey, LinkAction.Unlink, networkType, helper.maxFee, @@ -748,7 +772,7 @@ describe('TransactionHttp', () => { const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), AliasAction.Link, - namespaceId, + addressAlias, account.address, networkType, helper.maxFee, @@ -767,7 +791,7 @@ describe('TransactionHttp', () => { it('Announce TransferTransaction', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), - namespaceId, + addressAlias, [helper.createNetworkCurrency(1, false)], PlainMessage.create('test-message'), networkType, @@ -784,7 +808,7 @@ describe('TransactionHttp', () => { const addressAliasTransaction = AddressAliasTransaction.create( Deadline.create(), AliasAction.Unlink, - namespaceId, + addressAlias, account.address, networkType, helper.maxFee, @@ -846,7 +870,7 @@ describe('TransactionHttp', () => { const mosaicAliasTransaction = MosaicAliasTransaction.create( Deadline.create(), AliasAction.Link, - namespaceId, + mosaicAlias, mosaicId, networkType, helper.maxFee, @@ -883,7 +907,7 @@ describe('TransactionHttp', () => { const mosaicAliasTransaction = MosaicAliasTransaction.create( Deadline.create(), AliasAction.Unlink, - namespaceId, + mosaicAlias, mosaicId, networkType, helper.maxFee, @@ -1362,7 +1386,7 @@ describe('TransactionHttp', () => { it('should return transaction info given transactionHash', async () => { const transaction = await transactionRepository.getTransaction(transactionHash).toPromise(); expect(transaction.transactionInfo!.hash).to.be.equal(transactionHash); - expect(transaction.transactionInfo!.id).to.be.equal(transactionId); + transactionId = transaction.transactionInfo?.id!; }); it('should return transaction info given transactionId', async () => { @@ -1388,6 +1412,7 @@ describe('TransactionHttp', () => { describe('getTransactionStatus', () => { it('should return transaction status given transactionHash', async () => { + await new Promise((resolve) => setTimeout(resolve, 2000)); const transactionStatus = await transactionRepository.getTransactionStatus(transactionHash).toPromise(); expect(transactionStatus.group).to.be.equal('confirmed'); expect(transactionStatus.height!.lower).to.be.greaterThan(0); @@ -1416,7 +1441,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = transferTransaction.signWith(account, generationHash); const transactionAnnounceResponse = await transactionRepository.announce(signedTransaction).toPromise(); - expect(transactionAnnounceResponse.message).to.be.equal('packet 9 was pushed to the network via /transaction'); + expect(transactionAnnounceResponse.message).to.be.equal('packet 9 was pushed to the network via /transactions'); }); }); @@ -1439,7 +1464,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = aggregateTransaction.signWith(cosignAccount1, generationHash); const transactionAnnounceResponse = await transactionRepository.announceAggregateBonded(signedTransaction).toPromise(); - expect(transactionAnnounceResponse.message).to.be.equal('packet 500 was pushed to the network via /transaction/partial'); + expect(transactionAnnounceResponse.message).to.be.equal('packet 500 was pushed to the network via /transactions/partial'); }); }); @@ -1447,7 +1472,7 @@ describe('TransactionHttp', () => { it('should return success when announceAggregateBondedCosignature', async () => { const payload = new CosignatureSignedTransaction('', '', ''); const transactionAnnounceResponse = await transactionRepository.announceAggregateBondedCosignature(payload).toPromise(); - expect(transactionAnnounceResponse.message).to.be.equal('packet 501 was pushed to the network via /transaction/cosignature'); + expect(transactionAnnounceResponse.message).to.be.equal('packet 501 was pushed to the network via /transactions/cosignature'); }); }); @@ -1476,9 +1501,9 @@ describe('TransactionHttp', () => { it('should return transaction info given address', async () => { const streamer = new TransactionPaginationStreamer(transactionRepository); const transactionsNoStreamer = await transactionRepository - .search({ address: account.address, pageSize: 3 } as TransactionSearchCriteria) + .search({ address: account.address, pageSize: 10 } as TransactionSearchCriteria) .toPromise(); - const transactions = await streamer.search({ address: account.address, pageSize: 3 }).pipe(take(3), toArray()).toPromise(); + const transactions = await streamer.search({ address: account.address, pageSize: 10 }).pipe(take(10), toArray()).toPromise(); expect(transactions.length).to.be.greaterThan(0); deepEqual(transactionsNoStreamer.data, transactions); }); diff --git a/package-lock.json b/package-lock.json index 776e914b13..7c54b6bad4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1307,9 +1307,9 @@ "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, "catbuffer-typescript": { - "version": "0.0.20-alpha-202006031138", - "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.20-alpha-202006031138.tgz", - "integrity": "sha512-vXyKWhirl/CyLdf2NwqFFl1p/0c3E9VQL81Hr7acr0aiKeECao/V/HKY2b33VnlxVc07f0GBC+NpAhEPX8WVXg==" + "version": "0.0.20", + "resolved": "https://registry.npmjs.org/catbuffer-typescript/-/catbuffer-typescript-0.0.20.tgz", + "integrity": "sha512-dww9nmGqMyyHF+D53cqxBGppq0rfjG+Jvorfho8BGZ4cOwXTwdUDoD+HTpn6f0ZlBW2w8LlbBPEGNdR9CIeyHQ==" }, "chai": { "version": "4.1.2", @@ -6252,9 +6252,9 @@ } }, "symbol-openapi-typescript-node-client": { - "version": "0.8.13-SNAPSHOT.202006040918", - "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-node-client/-/symbol-openapi-typescript-node-client-0.8.13-SNAPSHOT.202006040918.tgz", - "integrity": "sha512-tyPmzLkWVoRPeewgyddnjipOBLS+LDi3RpGJ4WMuthJy8iQjnv/FOqUD7lQwdagVxjfuUsrpM2vw8E0Q5pmVww==", + "version": "0.8.13-SNAPSHOT.202006111332", + "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-node-client/-/symbol-openapi-typescript-node-client-0.8.13-SNAPSHOT.202006111332.tgz", + "integrity": "sha512-87n2Iy+qBbIt/+7X1MyMS6dnaHqUaYbTkCNTTJEmuRElqqQ9RTEWrXoc77r1852oufwopIfDhVnQX8VHeU+KIg==", "requires": { "@types/bluebird": "*", "@types/request": "*", diff --git a/package.json b/package.json index 231206a90c..594929ed1c 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ }, "dependencies": { "bluebird": "^3.7.2", - "catbuffer-typescript": "0.0.20-alpha-202006031138", + "catbuffer-typescript": "0.0.20", "crypto-js": "^4.0.0", "diff": "^4.0.2", "futoin-hkdf": "^1.3.1", @@ -89,7 +89,7 @@ "ripemd160": "^2.0.2", "rxjs": "^6.5.3", "rxjs-compat": "^6.5.3", - "symbol-openapi-typescript-node-client": "0.8.13-SNAPSHOT.202006040918", + "symbol-openapi-typescript-node-client": "0.8.13-SNAPSHOT.202006111332", "tweetnacl": "^1.0.3", "utf8": "^3.0.0", "ws": "^7.2.3" diff --git a/src/infrastructure/TransactionHttp.ts b/src/infrastructure/TransactionHttp.ts index 944a293f6c..589b4494e7 100644 --- a/src/infrastructure/TransactionHttp.ts +++ b/src/infrastructure/TransactionHttp.ts @@ -212,7 +212,7 @@ export class TransactionHttp extends Http implements TransactionRepository { criteria.offset, criteria.group, criteria.order, - criteria.transactionTypes?.map((type) => type.valueOf()), + criteria.type?.map((type) => type.valueOf()), criteria.embedded, ), (body) => super.toPage(body.pagination, body.data, CreateTransactionFromDTO), diff --git a/src/infrastructure/searchCriteria/TransactionSearchCriteria.ts b/src/infrastructure/searchCriteria/TransactionSearchCriteria.ts index a093d2fd0d..38e97fd157 100644 --- a/src/infrastructure/searchCriteria/TransactionSearchCriteria.ts +++ b/src/infrastructure/searchCriteria/TransactionSearchCriteria.ts @@ -25,11 +25,6 @@ import { TransactionGroupSubsetEnum } from 'symbol-openapi-typescript-node-clien * transactions queries using rest. */ export interface TransactionSearchCriteria extends SearchCriteria { - /** - * Transaction identifier up to which transactions are returned. (optional) - */ - id?: string; - /** * Filter by address involved in the transaction. * @@ -65,7 +60,7 @@ export interface TransactionSearchCriteria extends SearchCriteria { * Filter by transaction type. To filter by multiple transaction type. (optional, default to * new empty array) */ - transactionTypes?: TransactionType[]; + type?: TransactionType[]; /** * When true, the endpoint also returns all the embedded aggregate transactions. When diff --git a/test/infrastructure/TransactionHttp.spec.ts b/test/infrastructure/TransactionHttp.spec.ts index 1079f85737..0f600cc003 100644 --- a/test/infrastructure/TransactionHttp.spec.ts +++ b/test/infrastructure/TransactionHttp.spec.ts @@ -23,11 +23,11 @@ import { TransactionStatusDTO, TransactionStatusEnum, TransactionPage, - TransactionInfoExtendedDTO, TransactionMetaDTO, Pagination, TransferTransactionDTO, NetworkTypeEnum, + TransactionInfoDTO, } from 'symbol-openapi-typescript-node-client'; import { deepEqual, instance, mock, when } from 'ts-mockito'; @@ -131,7 +131,7 @@ describe('TransactionHttp', () => { paginationDto.totalEntries = 1; paginationDto.totalPages = 1; - const transactionInfoDto = new TransactionInfoExtendedDTO(); + const transactionInfoDto = new TransactionInfoDTO(); const metaDto = new TransactionMetaDTO(); metaDto.hash = 'hash'; metaDto.height = '1'; diff --git a/test/infrastructure/TransactionSearchCriteria.spec.ts b/test/infrastructure/TransactionSearchCriteria.spec.ts index 6c30f06985..5d71562980 100644 --- a/test/infrastructure/TransactionSearchCriteria.spec.ts +++ b/test/infrastructure/TransactionSearchCriteria.spec.ts @@ -35,11 +35,10 @@ describe('TransactionSearchCriteria', () => { embedded: true, group: TransactionGroupSubsetEnum.Confirmed, height: UInt64.fromUint(1), - id: '12345', offset: '6789', recipientAddress: account.address, signerPublicKey: account.publicKey, - transactionTypes: [TransactionType.ACCOUNT_ADDRESS_RESTRICTION], + type: [TransactionType.ACCOUNT_ADDRESS_RESTRICTION], }; expect(criteria.order?.valueOf()).to.be.equal('asc'); @@ -49,11 +48,10 @@ describe('TransactionSearchCriteria', () => { expect(criteria.embedded).to.be.equal(true); expect(criteria.group).to.be.equal(TransactionGroupSubsetEnum.Confirmed); expect(criteria.height?.toString()).to.be.equal('1'); - expect(criteria.id).to.be.equal('12345'); expect(criteria.offset).to.be.equal('6789'); expect(criteria.recipientAddress?.plain()).to.be.equal(account.address.plain()); expect(criteria.signerPublicKey).to.be.equal(account.publicKey); - deepEqual(criteria.transactionTypes, [TransactionType.ACCOUNT_ADDRESS_RESTRICTION]); + deepEqual(criteria.type, [TransactionType.ACCOUNT_ADDRESS_RESTRICTION]); const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); criteria = { @@ -64,11 +62,10 @@ describe('TransactionSearchCriteria', () => { embedded: false, group: TransactionGroupSubsetEnum.Unconfirmed, height: UInt64.fromUint(2), - id: 'aaa', offset: 'bbb', recipientAddress: address, signerPublicKey: 'publicKey', - transactionTypes: [TransactionType.TRANSFER], + type: [TransactionType.TRANSFER], }; expect(criteria.order?.valueOf()).to.be.equal('desc'); @@ -78,11 +75,10 @@ describe('TransactionSearchCriteria', () => { expect(criteria.embedded).to.be.equal(false); expect(criteria.group).to.be.equal(TransactionGroupSubsetEnum.Unconfirmed); expect(criteria.height?.toString()).to.be.equal('2'); - expect(criteria.id).to.be.equal('aaa'); expect(criteria.offset).to.be.equal('bbb'); expect(criteria.recipientAddress?.plain()).to.be.equal(address.plain()); expect(criteria.signerPublicKey).to.be.equal('publicKey'); - deepEqual(criteria.transactionTypes, [TransactionType.TRANSFER]); + deepEqual(criteria.type, [TransactionType.TRANSFER]); }); it('should create TransactionSearchCriteria - default', () => { @@ -93,12 +89,11 @@ describe('TransactionSearchCriteria', () => { expect(criteria.embedded).to.be.undefined; expect(criteria.group).to.be.undefined; expect(criteria.height).to.be.undefined; - expect(criteria.id).to.be.undefined; expect(criteria.offset).to.be.undefined; expect(criteria.pageNumber).to.be.undefined; expect(criteria.pageSize).to.be.undefined; expect(criteria.recipientAddress).to.be.undefined; expect(criteria.signerPublicKey).to.be.undefined; - expect(criteria.transactionTypes).to.be.undefined; + expect(criteria.type).to.be.undefined; }); }); From 45e7e572e45775a281d80ea320af154c987793f9 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 11 Jun 2020 16:54:54 +0100 Subject: [PATCH 07/22] mosaic test vector --- test/core/format/IdGenerator.spec.ts | 235 ++++++++++++++------------- 1 file changed, 124 insertions(+), 111 deletions(-) diff --git a/test/core/format/IdGenerator.spec.ts b/test/core/format/IdGenerator.spec.ts index 351f0ea661..dfbc2c32c4 100644 --- a/test/core/format/IdGenerator.spec.ts +++ b/test/core/format/IdGenerator.spec.ts @@ -16,6 +16,8 @@ import { expect } from 'chai'; import { sha3_256 } from 'js-sha3'; import { Convert as convert, IdGenerator as idGenerator, RawUInt64 as uint64 } from '../../../src/core/format'; +import { Address } from '../../../src/model/account/Address'; +import { MosaicId } from '../../../src/model/mosaic/MosaicId'; const constants = { nem_id: [0x375ffa4b, 0x84b3552d], @@ -29,110 +31,110 @@ const basicMosaicInfo = { id: [339608571, 538088181], }; -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', - }, - ], -}; +/** + * @links https://raw.githubusercontent.com/nemtech/test-vectors/master/5.test-mosaic-id.json + */ +const mosaicTestVector = [ + { + mosaicNonce: 2039925808, + address_Public: 'NATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34SQ33Y', + address_PublicTest: 'TATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA37JGO5Q', + address_Mijin: 'MATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34YACRA', + address_MijinTest: 'SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ', + mosaicId_Public: '044C577DBDD6DC71', + mosaicId_PublicTest: '1796754FB181EF1E', + mosaicId_Mijin: '7DCEDD54DAEDF7B7', + mosaicId_MijinTest: '5BCD295FC8801FE6', + }, + { + mosaicNonce: 1477337076, + address_Public: 'NDR6EW2WBHJQDYMNGFX2UBZHMMZC5PGL2YCZOQQ', + address_PublicTest: 'TDR6EW2WBHJQDYMNGFX2UBZHMMZC5PGL2YBO3KA', + address_Mijin: 'MDR6EW2WBHJQDYMNGFX2UBZHMMZC5PGL22B27FI', + address_MijinTest: 'SDR6EW2WBHJQDYMNGFX2UBZHMMZC5PGL2Z5UYYY', + mosaicId_Public: '7E45A001465DEEA0', + mosaicId_PublicTest: '5E55573E3EBBB596', + mosaicId_Mijin: '0D47486978FA4316', + mosaicId_MijinTest: '55595BF89461E7C1', + }, + { + mosaicNonce: 1921674920, + address_Public: 'NCOXVZMAZJTT4I3F7EAZYGNGR77D6WPTRH6SYIQ', + address_PublicTest: 'TCOXVZMAZJTT4I3F7EAZYGNGR77D6WPTRE3VIBQ', + address_Mijin: 'MCOXVZMAZJTT4I3F7EAZYGNGR77D6WPTRFDHL7I', + address_MijinTest: 'SCOXVZMAZJTT4I3F7EAZYGNGR77D6WPTRFENHXQ', + mosaicId_Public: '28E680397FDD9336', + mosaicId_PublicTest: '2F05C98474E9B263', + mosaicId_Mijin: '51B440266AE7F5B4', + mosaicId_MijinTest: '5693742C8290F33E', + }, + { + mosaicNonce: 737150288, + address_Public: 'NDZ4373ASEGJ7S7GQTKF26TIIMC7HK5EWFDDCHA', + address_PublicTest: 'TDZ4373ASEGJ7S7GQTKF26TIIMC7HK5EWEPHRSI', + address_Mijin: 'MDZ4373ASEGJ7S7GQTKF26TIIMC7HK5EWFN3NKY', + address_MijinTest: 'SDZ4373ASEGJ7S7GQTKF26TIIMC7HK5EWH6N46A', + mosaicId_Public: '75FAE31C9E1CEE38', + mosaicId_PublicTest: '35C831D2A6D9702B', + mosaicId_Mijin: '0476D83DF29A0426', + mosaicId_MijinTest: '4F5597E18C0182BC', + }, + { + mosaicNonce: 4118830514, + address_Public: 'NDI5I7Z3BRBAAHTZHGONGOXX742CW4W5QAZ4BMQ', + address_PublicTest: 'TDI5I7Z3BRBAAHTZHGONGOXX742CW4W5QCY5ZUA', + address_Mijin: 'MDI5I7Z3BRBAAHTZHGONGOXX742CW4W5QCLCVEA', + address_MijinTest: 'SDI5I7Z3BRBAAHTZHGONGOXX742CW4W5QDVZG2I', + mosaicId_Public: '656748D5F82E87A1', + mosaicId_PublicTest: '1CB636C5A32F0293', + mosaicId_Mijin: '35C2901E25DCF921', + mosaicId_MijinTest: '18FF3D8F9FA932D4', + }, + { + mosaicNonce: 2640226657, + address_Public: 'NAA6RO4ZAPEDGTCVADE3G4C7SWAE3DBQ4SCMOAI', + address_PublicTest: 'TAA6RO4ZAPEDGTCVADE3G4C7SWAE3DBQ4RTFBQY', + address_Mijin: 'MAA6RO4ZAPEDGTCVADE3G4C7SWAE3DBQ4TEKNHA', + address_MijinTest: 'SAA6RO4ZAPEDGTCVADE3G4C7SWAE3DBQ4RYAIEA', + mosaicId_Public: '3840F6C79934A159', + mosaicId_PublicTest: '5B0FFAA57C41D62E', + mosaicId_Mijin: '11BA1D842237D52B', + mosaicId_MijinTest: '0585182BF5BC7B57', + }, + { + mosaicNonce: 1996615061, + address_Public: 'NBEOZ72O73OYXFDLID5KGBMP67MROHONPQHVKAI', + address_PublicTest: 'TBEOZ72O73OYXFDLID5KGBMP67MROHONPR72UPQ', + address_Mijin: 'MBEOZ72O73OYXFDLID5KGBMP67MROHONPTHVSXQ', + address_MijinTest: 'SBEOZ72O73OYXFDLID5KGBMP67MROHONPTACBLI', + mosaicId_Public: '5AA0FF3892EF3345', + mosaicId_PublicTest: '79BD9AF30668FBDF', + mosaicId_Mijin: '0F8D3270B8ADDF77', + mosaicId_MijinTest: '092E4A9D08A9C1C5', + }, + { + mosaicNonce: 205824978, + address_Public: 'NAMJCSC2BEW52LVAULFRRJJTSRHLI7ABRG2X5RI', + address_PublicTest: 'TAMJCSC2BEW52LVAULFRRJJTSRHLI7ABRHFJZ5I', + address_Mijin: 'MAMJCSC2BEW52LVAULFRRJJTSRHLI7ABRG7GL5A', + address_MijinTest: 'SAMJCSC2BEW52LVAULFRRJJTSRHLI7ABRGLZY6A', + mosaicId_Public: '3AB75AF98A5E0365', + mosaicId_PublicTest: '3494FFAE1F6B2B4D', + mosaicId_Mijin: '3DF5D3B47E956692', + mosaicId_MijinTest: '4AA757991E36C79C', + }, + { + mosaicNonce: 3310277026, + address_Public: 'NCOVTFVVDZGNURZFU4IJLJR37X5TXNWMTSEHR6I', + address_PublicTest: 'TCOVTFVVDZGNURZFU4IJLJR37X5TXNWMTTXN3DI', + address_Mijin: 'MCOVTFVVDZGNURZFU4IJLJR37X5TXNWMTTARXZQ', + address_MijinTest: 'SCOVTFVVDZGNURZFU4IJLJR37X5TXNWMTSJ6YWY', + mosaicId_Public: '213E6E2EC43285C4', + mosaicId_PublicTest: '659C0D4A03D119D2', + mosaicId_Mijin: '756AC167798FA3DF', + mosaicId_MijinTest: '164D3F56862E9520', + }, +]; describe('id generator', () => { function generateNamespaceId(parentId, name): number[] { @@ -186,15 +188,26 @@ describe('id generator', () => { }); // @dataProvider mosaicTestVector - it('generates correct mosaicId given nonce and public key', () => { - mosaicTestVector.rows.map((row) => { - 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); + it('generates correct mosaicId given nonce and address', () => { + mosaicTestVector.map((row) => { + const addressPublic = Address.createFromRawAddress(row.address_Public).encoded(); + const addressTest = Address.createFromRawAddress(row.address_PublicTest); + const addressMijin = Address.createFromRawAddress(row.address_Mijin); + const addressMijinTest = Address.createFromRawAddress(row.address_MijinTest); + + const nonce = convert.numberToUint8Array(row.mosaicNonce, 4).reverse(); // Assert: - expect(mosaicId).to.deep.equal(expectedId); + expect(new MosaicId(idGenerator.generateMosaicId(nonce, addressPublic)).toHex(), 'Public').to.deep.equal( + row.mosaicId_Public, + ); + expect(new MosaicId(idGenerator.generateMosaicId(nonce, addressTest)).toHex(), 'PublicTest').to.deep.equal( + row.mosaicId_PublicTest, + ); + expect(new MosaicId(idGenerator.generateMosaicId(nonce, addressMijin)).toHex(), 'Mijin').to.deep.equal(row.mosaicId_Mijin); + expect(new MosaicId(idGenerator.generateMosaicId(nonce, addressMijinTest)).toHex(), 'MijinTest').to.deep.equal( + row.mosaicId_MijinTest, + ); }); }); }); From 0dfff86dc2ad174f9d62d5a61a82778d4b7dd260 Mon Sep 17 00:00:00 2001 From: fernando Date: Thu, 11 Jun 2020 13:12:52 -0300 Subject: [PATCH 08/22] Fixed mosaic vector test --- package-lock.json | 2 +- src/model/mosaic/MosaicId.ts | 15 +++++++++++++-- test/core/format/IdGenerator.spec.ts | 25 ++++++++++--------------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7c54b6bad4..b62c797c83 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4792,7 +4792,7 @@ }, "which-module": { "version": "2.0.0", - "resolved": "", + "resolved": false, "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", "dev": true }, diff --git a/src/model/mosaic/MosaicId.ts b/src/model/mosaic/MosaicId.ts index 603d7b6017..68e75310ad 100644 --- a/src/model/mosaic/MosaicId.ts +++ b/src/model/mosaic/MosaicId.ts @@ -15,6 +15,7 @@ */ import { Convert as convert, RawUInt64 as uint64_t } from '../../core/format'; import { NamespaceMosaicIdGenerator } from '../../infrastructure/transaction/NamespaceMosaicIdGenerator'; +import { Address } from '../account/Address'; import { PublicAccount } from '../account/PublicAccount'; import { Id } from '../Id'; import { MosaicNonce } from '../mosaic/MosaicNonce'; @@ -38,8 +39,18 @@ export class MosaicId { * @return {MosaicId} */ public static createFromNonce(nonce: MosaicNonce, owner: PublicAccount): MosaicId { - const mosaicId = NamespaceMosaicIdGenerator.mosaicId(nonce.toUint8Array(), convert.hexToUint8(owner.address.encoded())); - return new MosaicId(mosaicId); + return this.createFromNonceAndAddress(nonce, owner.address); + } + + /** + * Create a MosaicId for given `nonce` MosaicNonce and `owner` address. + * + * @param nonce {MosaicNonce} + * @param owner {Account} + * @return {MosaicId} + */ + public static createFromNonceAndAddress(nonce: MosaicNonce, owner: Address): MosaicId { + return new MosaicId(NamespaceMosaicIdGenerator.mosaicId(nonce.nonce, convert.hexToUint8(owner.encoded()))); } /** diff --git a/test/core/format/IdGenerator.spec.ts b/test/core/format/IdGenerator.spec.ts index dfbc2c32c4..7ed73d6333 100644 --- a/test/core/format/IdGenerator.spec.ts +++ b/test/core/format/IdGenerator.spec.ts @@ -18,6 +18,7 @@ import { sha3_256 } from 'js-sha3'; import { Convert as convert, IdGenerator as idGenerator, RawUInt64 as uint64 } from '../../../src/core/format'; import { Address } from '../../../src/model/account/Address'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; +import { MosaicNonce } from '../../../src/model/mosaic/MosaicNonce'; const constants = { nem_id: [0x375ffa4b, 0x84b3552d], @@ -186,26 +187,20 @@ describe('id generator', () => { // Assert: expect(idGenerator.generateMosaicId(basicMosaicInfo.nonce, basicMosaicInfo.address)).to.deep.equal(basicMosaicInfo.id); }); - - // @dataProvider mosaicTestVector - it('generates correct mosaicId given nonce and address', () => { - mosaicTestVector.map((row) => { - const addressPublic = Address.createFromRawAddress(row.address_Public).encoded(); + mosaicTestVector.forEach((row) => { + // @dataProvider mosaicTestVector + it('generates correct mosaicId given nonce and address', () => { + const addressPublic = Address.createFromRawAddress(row.address_Public); const addressTest = Address.createFromRawAddress(row.address_PublicTest); const addressMijin = Address.createFromRawAddress(row.address_Mijin); const addressMijinTest = Address.createFromRawAddress(row.address_MijinTest); - - const nonce = convert.numberToUint8Array(row.mosaicNonce, 4).reverse(); + const nonce = MosaicNonce.createFromNumber(row.mosaicNonce); // Assert: - expect(new MosaicId(idGenerator.generateMosaicId(nonce, addressPublic)).toHex(), 'Public').to.deep.equal( - row.mosaicId_Public, - ); - expect(new MosaicId(idGenerator.generateMosaicId(nonce, addressTest)).toHex(), 'PublicTest').to.deep.equal( - row.mosaicId_PublicTest, - ); - expect(new MosaicId(idGenerator.generateMosaicId(nonce, addressMijin)).toHex(), 'Mijin').to.deep.equal(row.mosaicId_Mijin); - expect(new MosaicId(idGenerator.generateMosaicId(nonce, addressMijinTest)).toHex(), 'MijinTest').to.deep.equal( + expect(MosaicId.createFromNonceAndAddress(nonce, addressPublic).toHex(), 'Public').to.deep.equal(row.mosaicId_Public); + expect(MosaicId.createFromNonceAndAddress(nonce, addressTest).toHex(), 'PublicTest').to.deep.equal(row.mosaicId_PublicTest); + expect(MosaicId.createFromNonceAndAddress(nonce, addressMijin).toHex(), 'Mijin').to.deep.equal(row.mosaicId_Mijin); + expect(MosaicId.createFromNonceAndAddress(nonce, addressMijinTest).toHex(), 'MijinTest').to.deep.equal( row.mosaicId_MijinTest, ); }); From f1cc1cb648912d1a50584710dfb949f092643819 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 11 Jun 2020 17:15:09 +0100 Subject: [PATCH 09/22] Fixed mosaic id test vector tests --- e2e/infrastructure/MetadataHttp.spec.ts | 2 +- e2e/infrastructure/MosaicHttp.spec.ts | 2 +- e2e/infrastructure/RestrictionHttp.spec.ts | 4 +-- e2e/infrastructure/TransactionHttp.spec.ts | 4 +-- e2e/infrastructure/UnresolvedMapping.spec.ts | 2 +- .../MetadataTransactionService.spec.ts | 2 +- ...osaicRestrictionTransactionService.spec.ts | 2 +- e2e/service/TransactionService.spec.ts | 4 +-- src/model/mosaic/MosaicId.ts | 8 ++--- test/core/format/IdGenerator.spec.ts | 29 ++++++++++++------- test/model/mosaic/MosaicId.spec.ts | 6 ++-- 11 files changed, 36 insertions(+), 29 deletions(-) diff --git a/e2e/infrastructure/MetadataHttp.spec.ts b/e2e/infrastructure/MetadataHttp.spec.ts index cd25ce585c..85d4f051d9 100644 --- a/e2e/infrastructure/MetadataHttp.spec.ts +++ b/e2e/infrastructure/MetadataHttp.spec.ts @@ -70,7 +70,7 @@ describe('MetadataHttp', () => { describe('MosaicDefinitionTransaction', () => { it('standalone', () => { const nonce = MosaicNonce.createRandom(); - mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount); + mosaicId = MosaicId.createFromNonce(nonce, account.address); const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), nonce, diff --git a/e2e/infrastructure/MosaicHttp.spec.ts b/e2e/infrastructure/MosaicHttp.spec.ts index 3d7cf3a870..e2b40f6f07 100644 --- a/e2e/infrastructure/MosaicHttp.spec.ts +++ b/e2e/infrastructure/MosaicHttp.spec.ts @@ -70,7 +70,7 @@ describe('MosaicHttp', () => { const nonce = MosaicNonce.createFromNumber(-1501238750); expect(nonce.toDTO()).to.be.equals(2793728546); expect(nonce.toHex()).to.be.equals('22EA84A6'); - mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount); + mosaicId = MosaicId.createFromNonce(nonce, account.address); const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), nonce, diff --git a/e2e/infrastructure/RestrictionHttp.spec.ts b/e2e/infrastructure/RestrictionHttp.spec.ts index e53a239481..ec96ac6b80 100644 --- a/e2e/infrastructure/RestrictionHttp.spec.ts +++ b/e2e/infrastructure/RestrictionHttp.spec.ts @@ -75,7 +75,7 @@ describe('RestrictionHttp', () => { describe('MosaicDefinitionTransaction', () => { it('standalone', () => { const nonce = MosaicNonce.createRandom(); - mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount); + mosaicId = MosaicId.createFromNonce(nonce, account.address); const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), nonce, @@ -94,7 +94,7 @@ describe('RestrictionHttp', () => { describe('MosaicDefinitionTransaction', () => { it('standalone', () => { const nonce = MosaicNonce.createRandom(); - referenceMosaicId = MosaicId.createFromNonce(nonce, account.publicAccount); + referenceMosaicId = MosaicId.createFromNonce(nonce, account.address); const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), nonce, diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 43af66d394..2dfce3b0c0 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -139,7 +139,7 @@ describe('TransactionHttp', () => { describe('MosaicDefinitionTransaction', () => { it('standalone', () => { const nonce = MosaicNonce.createRandom(); - mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount); + mosaicId = MosaicId.createFromNonce(nonce, account.address); const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), nonce, @@ -171,7 +171,7 @@ describe('TransactionHttp', () => { const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), nonce, - MosaicId.createFromNonce(nonce, account.publicAccount), + MosaicId.createFromNonce(nonce, account.address), MosaicFlags.create(true, true, true), 3, UInt64.fromUint(0), diff --git a/e2e/infrastructure/UnresolvedMapping.spec.ts b/e2e/infrastructure/UnresolvedMapping.spec.ts index 7b61be1a73..719935faf1 100644 --- a/e2e/infrastructure/UnresolvedMapping.spec.ts +++ b/e2e/infrastructure/UnresolvedMapping.spec.ts @@ -75,7 +75,7 @@ describe('Unresolved Mapping', () => { describe('MosaicDefinitionTransaction', () => { it('standalone', () => { const nonce = MosaicNonce.createRandom(); - mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount); + mosaicId = MosaicId.createFromNonce(nonce, account.address); const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), nonce, diff --git a/e2e/service/MetadataTransactionService.spec.ts b/e2e/service/MetadataTransactionService.spec.ts index 16fa62c13c..abe6be40ab 100644 --- a/e2e/service/MetadataTransactionService.spec.ts +++ b/e2e/service/MetadataTransactionService.spec.ts @@ -59,7 +59,7 @@ describe('MetadataTransactionService', () => { describe('MosaicDefinitionTransaction', () => { it('standalone', () => { const nonce = MosaicNonce.createRandom(); - mosaicId = MosaicId.createFromNonce(nonce, targetAccount.publicAccount); + mosaicId = MosaicId.createFromNonce(nonce, targetAccount.address); const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), nonce, diff --git a/e2e/service/MosaicRestrictionTransactionService.spec.ts b/e2e/service/MosaicRestrictionTransactionService.spec.ts index 1ecfcf1080..f6439aafab 100644 --- a/e2e/service/MosaicRestrictionTransactionService.spec.ts +++ b/e2e/service/MosaicRestrictionTransactionService.spec.ts @@ -63,7 +63,7 @@ describe('MosaicRestrictionTransactionService', () => { describe('MosaicDefinitionTransaction', () => { it('standalone', () => { const nonce = MosaicNonce.createRandom(); - mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount); + mosaicId = MosaicId.createFromNonce(nonce, account.address); const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), nonce, diff --git a/e2e/service/TransactionService.spec.ts b/e2e/service/TransactionService.spec.ts index 5cd81f506f..ce1f898cd2 100644 --- a/e2e/service/TransactionService.spec.ts +++ b/e2e/service/TransactionService.spec.ts @@ -106,7 +106,7 @@ describe('TransactionService', () => { // Create a new Mosaic const nonce = MosaicNonce.createRandom(); - newMosaicId = MosaicId.createFromNonce(nonce, account.publicAccount); + newMosaicId = MosaicId.createFromNonce(nonce, account.address); const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), nonce, @@ -213,7 +213,7 @@ describe('TransactionService', () => { describe('Setup test MosaicId', () => { it('Announce MosaicDefinitionTransaction', () => { const nonce = MosaicNonce.createRandom(); - mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount); + mosaicId = MosaicId.createFromNonce(nonce, account.address); const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create( Deadline.create(), nonce, diff --git a/src/model/mosaic/MosaicId.ts b/src/model/mosaic/MosaicId.ts index 603d7b6017..5bedc0a460 100644 --- a/src/model/mosaic/MosaicId.ts +++ b/src/model/mosaic/MosaicId.ts @@ -15,9 +15,9 @@ */ import { Convert as convert, RawUInt64 as uint64_t } from '../../core/format'; import { NamespaceMosaicIdGenerator } from '../../infrastructure/transaction/NamespaceMosaicIdGenerator'; -import { PublicAccount } from '../account/PublicAccount'; import { Id } from '../Id'; import { MosaicNonce } from '../mosaic/MosaicNonce'; +import { Address } from '../account/Address'; /** * The mosaic id structure describes mosaic id @@ -34,11 +34,11 @@ export class MosaicId { * Create a MosaicId for given `nonce` MosaicNonce and `owner` PublicAccount. * * @param nonce {MosaicNonce} - * @param owner {Account} + * @param ownerAddress {Address} * @return {MosaicId} */ - public static createFromNonce(nonce: MosaicNonce, owner: PublicAccount): MosaicId { - const mosaicId = NamespaceMosaicIdGenerator.mosaicId(nonce.toUint8Array(), convert.hexToUint8(owner.address.encoded())); + public static createFromNonce(nonce: MosaicNonce, ownerAddress: Address): MosaicId { + const mosaicId = NamespaceMosaicIdGenerator.mosaicId(nonce.toUint8Array(), convert.hexToUint8(ownerAddress.encoded())); return new MosaicId(mosaicId); } diff --git a/test/core/format/IdGenerator.spec.ts b/test/core/format/IdGenerator.spec.ts index dfbc2c32c4..321345c04b 100644 --- a/test/core/format/IdGenerator.spec.ts +++ b/test/core/format/IdGenerator.spec.ts @@ -18,6 +18,7 @@ import { sha3_256 } from 'js-sha3'; import { Convert as convert, IdGenerator as idGenerator, RawUInt64 as uint64 } from '../../../src/core/format'; import { Address } from '../../../src/model/account/Address'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; +import { MosaicNonce } from '../../../src/model/mosaic/MosaicNonce'; const constants = { nem_id: [0x375ffa4b, 0x84b3552d], @@ -190,7 +191,7 @@ describe('id generator', () => { // @dataProvider mosaicTestVector it('generates correct mosaicId given nonce and address', () => { mosaicTestVector.map((row) => { - const addressPublic = Address.createFromRawAddress(row.address_Public).encoded(); + const addressPublic = Address.createFromRawAddress(row.address_Public); const addressTest = Address.createFromRawAddress(row.address_PublicTest); const addressMijin = Address.createFromRawAddress(row.address_Mijin); const addressMijinTest = Address.createFromRawAddress(row.address_MijinTest); @@ -198,16 +199,22 @@ describe('id generator', () => { const nonce = convert.numberToUint8Array(row.mosaicNonce, 4).reverse(); // Assert: - expect(new MosaicId(idGenerator.generateMosaicId(nonce, addressPublic)).toHex(), 'Public').to.deep.equal( - row.mosaicId_Public, - ); - expect(new MosaicId(idGenerator.generateMosaicId(nonce, addressTest)).toHex(), 'PublicTest').to.deep.equal( - row.mosaicId_PublicTest, - ); - expect(new MosaicId(idGenerator.generateMosaicId(nonce, addressMijin)).toHex(), 'Mijin').to.deep.equal(row.mosaicId_Mijin); - expect(new MosaicId(idGenerator.generateMosaicId(nonce, addressMijinTest)).toHex(), 'MijinTest').to.deep.equal( - row.mosaicId_MijinTest, - ); + expect( + MosaicId.createFromNonce(MosaicNonce.createFromNumber(row.mosaicNonce), addressPublic).toHex(), + 'Public', + ).to.deep.equal(row.mosaicId_Public); + expect( + MosaicId.createFromNonce(MosaicNonce.createFromNumber(row.mosaicNonce), addressTest).toHex(), + 'PublicTest', + ).to.deep.equal(row.mosaicId_PublicTest); + expect( + MosaicId.createFromNonce(MosaicNonce.createFromNumber(row.mosaicNonce), addressMijin).toHex(), + 'Mijin', + ).to.deep.equal(row.mosaicId_Mijin); + expect( + MosaicId.createFromNonce(MosaicNonce.createFromNumber(row.mosaicNonce), addressMijinTest).toHex(), + 'MijinTest', + ).to.deep.equal(row.mosaicId_MijinTest); }); }); }); diff --git a/test/model/mosaic/MosaicId.spec.ts b/test/model/mosaic/MosaicId.spec.ts index eec5a8d949..37c447796f 100644 --- a/test/model/mosaic/MosaicId.spec.ts +++ b/test/model/mosaic/MosaicId.spec.ts @@ -36,14 +36,14 @@ describe('MosaicId', () => { it('should create id given nonce and owner', () => { const owner = PublicAccount.createFromPublicKey(publicKey, NetworkType.MIJIN_TEST); - const id = MosaicId.createFromNonce(MosaicNonce.createFromNumber(0), owner); + const id = MosaicId.createFromNonce(MosaicNonce.createFromNumber(0), owner.address); deepEqual(id.id, new Id([3526830425, 1241357627])); }); it('should create id twice the same given nonce and owner', () => { const owner = PublicAccount.createFromPublicKey(publicKey, NetworkType.MIJIN_TEST); - const id1 = MosaicId.createFromNonce(MosaicNonce.createFromNumber(12), owner); - const id2 = MosaicId.createFromNonce(MosaicNonce.createFromNumber(12), owner); + const id1 = MosaicId.createFromNonce(MosaicNonce.createFromNumber(12), owner.address); + const id2 = MosaicId.createFromNonce(MosaicNonce.createFromNumber(12), owner.address); deepEqual(id1.id, id2.id); }); From 24db7b1691ceac108f81dc39972a94bcda13c84a Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 11 Jun 2020 20:01:43 +0100 Subject: [PATCH 10/22] - updated networkd properties fields - added size to blockInfo --- package-lock.json | 8 ++++---- package.json | 2 +- src/infrastructure/BlockHttp.ts | 1 + src/infrastructure/NetworkHttp.ts | 8 ++++---- src/model/blockchain/BlockInfo.ts | 5 +++++ src/model/network/ChainProperties.ts | 4 ++-- src/model/network/MosaicNetworkProperties.ts | 4 ++-- src/model/network/NamespaceNetworkProperties.ts | 4 ++-- src/model/network/NetworkProperties.ts | 4 ++-- test/infrastructure/NetworkHttp.spec.ts | 8 ++++---- test/model/blockchain/BlockInfo.spec.ts | 3 +++ test/resource/TestResources.ts | 8 ++++---- test/service/BlockService.spec.ts | 2 ++ 13 files changed, 36 insertions(+), 25 deletions(-) diff --git a/package-lock.json b/package-lock.json index b62c797c83..d9d7f435ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4792,7 +4792,7 @@ }, "which-module": { "version": "2.0.0", - "resolved": false, + "resolved": "", "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", "dev": true }, @@ -6252,9 +6252,9 @@ } }, "symbol-openapi-typescript-node-client": { - "version": "0.8.13-SNAPSHOT.202006111332", - "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-node-client/-/symbol-openapi-typescript-node-client-0.8.13-SNAPSHOT.202006111332.tgz", - "integrity": "sha512-87n2Iy+qBbIt/+7X1MyMS6dnaHqUaYbTkCNTTJEmuRElqqQ9RTEWrXoc77r1852oufwopIfDhVnQX8VHeU+KIg==", + "version": "0.8.13-SNAPSHOT.202006111924", + "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-node-client/-/symbol-openapi-typescript-node-client-0.8.13-SNAPSHOT.202006111924.tgz", + "integrity": "sha512-OHZrlAA94fJsfj19GF4GMY/gBGRAV7oK8bp6x55SstAU3Jfo8lnto9BLsgzh/zLrQpTnFiPGm0TcSUYcZQlYVA==", "requires": { "@types/bluebird": "*", "@types/request": "*", diff --git a/package.json b/package.json index 594929ed1c..2ed1a7e999 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "ripemd160": "^2.0.2", "rxjs": "^6.5.3", "rxjs-compat": "^6.5.3", - "symbol-openapi-typescript-node-client": "0.8.13-SNAPSHOT.202006111332", + "symbol-openapi-typescript-node-client": "0.8.13-SNAPSHOT.202006111924", "tweetnacl": "^1.0.3", "utf8": "^3.0.0", "ws": "^7.2.3" diff --git a/src/infrastructure/BlockHttp.ts b/src/infrastructure/BlockHttp.ts index 705cd48a68..a8c2820c8f 100644 --- a/src/infrastructure/BlockHttp.ts +++ b/src/infrastructure/BlockHttp.ts @@ -89,6 +89,7 @@ export class BlockHttp extends Http implements BlockRepository { const networkType = dto.block.network.valueOf(); return new BlockInfo( dto.id ?? '', + dto.block.size, dto.meta.hash, dto.meta.generationHash, UInt64.fromNumericString(dto.meta.totalFee), diff --git a/src/infrastructure/NetworkHttp.ts b/src/infrastructure/NetworkHttp.ts index d19bbea261..5043f5ac45 100644 --- a/src/infrastructure/NetworkHttp.ts +++ b/src/infrastructure/NetworkHttp.ts @@ -140,7 +140,7 @@ export class NetworkHttp extends Http implements NetworkRepository { new NetworkProperties( dto.network.identifier, dto.network.nodeEqualityStrategy, - dto.network.publicKey, + dto.network.nemesisSignerPublicKey, dto.network.generationHashSeed, dto.network.epochAdjustment, ), @@ -167,7 +167,7 @@ export class NetworkHttp extends Http implements NetworkRepository { dto.chain.minVoterBalance, dto.chain.harvestBeneficiaryPercentage, dto.chain.harvestNetworkPercentage, - dto.chain.harvestNetworkFeeSinkPublicKey, + dto.chain.harvestNetworkFeeSinkAddress, dto.chain.blockPruneInterval, dto.chain.maxTransactionsPerBlock, ), @@ -191,7 +191,7 @@ export class NetworkHttp extends Http implements NetworkRepository { dto.plugins.mosaic?.maxMosaicsPerAccount, dto.plugins.mosaic?.maxMosaicDuration, dto.plugins.mosaic?.maxMosaicDivisibility, - dto.plugins.mosaic?.mosaicRentalFeeSinkPublicKey, + dto.plugins.mosaic?.mosaicRentalFeeSinkAddress, dto.plugins.mosaic?.mosaicRentalFee, ), new MultisigNetworkProperties( @@ -207,7 +207,7 @@ export class NetworkHttp extends Http implements NetworkRepository { dto.plugins.namespace?.maxNamespaceDuration, dto.plugins.namespace?.namespaceGracePeriodDuration, dto.plugins.namespace?.reservedRootNamespaceNames, - dto.plugins.namespace?.namespaceRentalFeeSinkPublicKey, + dto.plugins.namespace?.namespaceRentalFeeSinkAddress, dto.plugins.namespace?.rootNamespaceRentalFeePerBlock, dto.plugins.namespace?.childNamespaceRentalFee, ), diff --git a/src/model/blockchain/BlockInfo.ts b/src/model/blockchain/BlockInfo.ts index 955f5b810c..033977ee93 100644 --- a/src/model/blockchain/BlockInfo.ts +++ b/src/model/blockchain/BlockInfo.ts @@ -25,6 +25,7 @@ import { Address } from '../account/Address'; export class BlockInfo { /** * @param recordId + * @param size * @param hash * @param generationHash * @param totalFee @@ -54,6 +55,10 @@ export class BlockInfo { * The database record id. */ public readonly recordId: string, + /** + * Entity size in bytes. + */ + public readonly size: number, /** * The block hash. */ diff --git a/src/model/network/ChainProperties.ts b/src/model/network/ChainProperties.ts index 811556b435..bbf2b072a9 100644 --- a/src/model/network/ChainProperties.ts +++ b/src/model/network/ChainProperties.ts @@ -40,7 +40,7 @@ export class ChainProperties { * @param minVoterBalance - Minimum number of harvesting mosaic atomic units needed for an account to be eligible for voting. * @param harvestBeneficiaryPercentage - Percentage of the harvested fee that is collected by the beneficiary account. * @param harvestNetworkPercentage - Percentage of the harvested fee that is collected by network. - * @param harvestNetworkFeeSinkPublicKey - The harvest network fee sink public key. + * @param harvestNetworkFeeSinkAddress - The harvest network fee sink address. * @param blockPruneInterval - Number of blocks between cache pruning. * @param maxTransactionsPerBlock - Maximum number of transactions per block. */ @@ -67,7 +67,7 @@ export class ChainProperties { public readonly minVoterBalance?: string, public readonly harvestBeneficiaryPercentage?: string, public readonly harvestNetworkPercentage?: string, - public readonly harvestNetworkFeeSinkPublicKey?: string, + public readonly harvestNetworkFeeSinkAddress?: string, public readonly blockPruneInterval?: string, public readonly maxTransactionsPerBlock?: string, ) {} diff --git a/src/model/network/MosaicNetworkProperties.ts b/src/model/network/MosaicNetworkProperties.ts index c0e1675fc0..31d4cb9e9f 100644 --- a/src/model/network/MosaicNetworkProperties.ts +++ b/src/model/network/MosaicNetworkProperties.ts @@ -19,14 +19,14 @@ export class MosaicNetworkProperties { * @param maxMosaicsPerAccount - Maximum number of mosaics that an account can own. * @param maxMosaicDuration - Maximum mosaic duration. * @param maxMosaicDivisibility - Maximum mosaic divisibility. - * @param mosaicRentalFeeSinkPublicKey - Public key of the mosaic rental fee sink account. + * @param mosaicRentalFeeSinkAddress - Public key of the mosaic rental fee sink address. * @param mosaicRentalFee - Mosaic rental fee. */ constructor( public readonly maxMosaicsPerAccount?: string, public readonly maxMosaicDuration?: string, public readonly maxMosaicDivisibility?: string, - public readonly mosaicRentalFeeSinkPublicKey?: string, + public readonly mosaicRentalFeeSinkAddress?: string, public readonly mosaicRentalFee?: string, ) {} } diff --git a/src/model/network/NamespaceNetworkProperties.ts b/src/model/network/NamespaceNetworkProperties.ts index b1e981e40d..9ed7a083d9 100644 --- a/src/model/network/NamespaceNetworkProperties.ts +++ b/src/model/network/NamespaceNetworkProperties.ts @@ -23,7 +23,7 @@ export class NamespaceNetworkProperties { * @param maxNamespaceDuration - Maximum namespace duration. * @param namespaceGracePeriodDuration - Grace period during which time only the previous owner can renew an expired namespace. * @param reservedRootNamespaceNames - Reserved root namespaces that cannot be claimed. - * @param namespaceRentalFeeSinkPublicKey - Public key of the namespace rental fee sink account. + * @param namespaceRentalFeeSinkAddress - Public key of the namespace rental fee sink address. * @param rootNamespaceRentalFeePerBlock - Root namespace rental fee per block. * @param childNamespaceRentalFee - Child namespace rental fee. */ @@ -35,7 +35,7 @@ export class NamespaceNetworkProperties { public readonly maxNamespaceDuration?: string, public readonly namespaceGracePeriodDuration?: string, public readonly reservedRootNamespaceNames?: string, - public readonly namespaceRentalFeeSinkPublicKey?: string, + public readonly namespaceRentalFeeSinkAddress?: string, public readonly rootNamespaceRentalFeePerBlock?: string, public readonly childNamespaceRentalFee?: string, ) {} diff --git a/src/model/network/NetworkProperties.ts b/src/model/network/NetworkProperties.ts index 159346c371..3e13fd51d2 100644 --- a/src/model/network/NetworkProperties.ts +++ b/src/model/network/NetworkProperties.ts @@ -23,14 +23,14 @@ export class NetworkProperties { /** * @param identifier - Network identifier. * @param nodeEqualityStrategy - Node equality strategy. Defines if the identifier for the node must be its public key or host. - * @param publicKey - Nemesis public key. + * @param nemesisSignerPublicKey - Nemesis public key. * @param generationHashSeed - Seed for generate nemesis generation hash. * @param epochAdjustment - Nemesis epoch time adjustment. */ constructor( public readonly identifier?: string, public readonly nodeEqualityStrategy?: NodeIdentityEqualityStrategy, - public readonly publicKey?: string, + public readonly nemesisSignerPublicKey?: string, public readonly generationHashSeed?: string, public readonly epochAdjustment?: string, ) {} diff --git a/test/infrastructure/NetworkHttp.spec.ts b/test/infrastructure/NetworkHttp.spec.ts index a866139a82..9a11cbd25c 100644 --- a/test/infrastructure/NetworkHttp.spec.ts +++ b/test/infrastructure/NetworkHttp.spec.ts @@ -125,7 +125,7 @@ describe('NetworkHttp', () => { const network = new NetworkPropertiesDTO(); network.identifier = 'id'; network.nodeEqualityStrategy = NodeIdentityEqualityStrategy.Host; - network.publicKey = 'pubKey'; + network.nemesisSignerPublicKey = 'pubKey'; network.generationHashSeed = 'genHash'; network.epochAdjustment = '123456'; @@ -152,7 +152,7 @@ describe('NetworkHttp', () => { chain.minHarvesterBalance = '1'; chain.totalChainImportance = '1'; chain.harvestNetworkPercentage = '1'; - chain.harvestNetworkFeeSinkPublicKey = 'key'; + chain.harvestNetworkFeeSinkAddress = 'key'; chain.blockFinalizationInterval = '1'; chain.minVoterBalance = '1'; @@ -184,7 +184,7 @@ describe('NetworkHttp', () => { plugin.mosaic.maxMosaicDuration = '1'; plugin.mosaic.maxMosaicsPerAccount = '1'; plugin.mosaic.mosaicRentalFee = '1'; - plugin.mosaic.mosaicRentalFeeSinkPublicKey = '1'; + plugin.mosaic.mosaicRentalFeeSinkAddress = '1'; plugin.multisig = new MultisigNetworkPropertiesDTO(); plugin.multisig.maxCosignatoriesPerAccount = '1'; @@ -199,7 +199,7 @@ describe('NetworkHttp', () => { plugin.namespace.maxNamespaceDuration = '1'; plugin.namespace.minNamespaceDuration = '1'; plugin.namespace.namespaceGracePeriodDuration = '1'; - plugin.namespace.namespaceRentalFeeSinkPublicKey = '1'; + plugin.namespace.namespaceRentalFeeSinkAddress = '1'; plugin.namespace.reservedRootNamespaceNames = '1'; plugin.namespace.rootNamespaceRentalFeePerBlock = '1'; diff --git a/test/model/blockchain/BlockInfo.spec.ts b/test/model/blockchain/BlockInfo.spec.ts index 08a5cb53f1..456f7cac6b 100644 --- a/test/model/blockchain/BlockInfo.spec.ts +++ b/test/model/blockchain/BlockInfo.spec.ts @@ -26,6 +26,7 @@ describe('BlockInfo', () => { const blockDTO = { id: '12345', block: { + size: 1, blockTransactionsHash: '702090BA31CEF9E90C62BBDECC0CCCC0F88192B6625839382850357F70DD68A0', blockReceiptsHash: '702090BA31CEF9E90C62BBDECC0CCCC0F88192B6625839382850357F70DD68A0', stateHash: '702090BA31CEF9E90C62BBDECC0CCCC0F88192B6625839382850357F70DD68A0', @@ -58,6 +59,7 @@ describe('BlockInfo', () => { const blockInfo = new BlockInfo( blockDTO.id, + blockDTO.block.size, blockDTO.meta.hash, blockDTO.meta.generationHash, blockDTO.meta.totalFee, @@ -84,6 +86,7 @@ describe('BlockInfo', () => { ); expect(blockInfo.recordId).to.be.equal(blockDTO.id); + expect(blockInfo.size).to.be.equal(blockDTO.block.size); expect(blockInfo.hash).to.be.equal(blockDTO.meta.hash); expect(blockInfo.generationHash).to.be.equal(blockDTO.meta.generationHash); deepEqual(blockInfo.totalFee, blockDTO.meta.totalFee); diff --git a/test/resource/TestResources.ts b/test/resource/TestResources.ts index 7e0e089ab6..a8234c9cab 100644 --- a/test/resource/TestResources.ts +++ b/test/resource/TestResources.ts @@ -3,7 +3,7 @@ export const getDummyNetworkProperties = (): any => { "network": { "identifier": "public-test", "nodeEqualityStrategy": "public-key", - "publicKey": "86E8FDE6F3FE540ADC1B3A78DFA9B9E735736FC520E0D9C9CD4ADD3255CD9605", + "nemesisSignerPublicKey": "86E8FDE6F3FE540ADC1B3A78DFA9B9E735736FC520E0D9C9CD4ADD3255CD9605", "generationHashSeed": "E759C7C56FD20021C8F0CC7FF5F108A2FEBA3312F6EC6D6A702DF87657FEC55C", "epochAdjustment": "1573430400s" }, @@ -30,7 +30,7 @@ export const getDummyNetworkProperties = (): any => { "minVoterBalance": "50'000", "harvestBeneficiaryPercentage": "10", "harvestNetworkPercentage": "5", - "harvestNetworkFeeSinkPublicKey": "FF5563F1C5824EE0CD868799FBE8744B46D5549973FDA499939C952D951494E4", + "harvestNetworkFeeSinkAddress": "TDGY4DD2U4YQQGERFMDQYHPYS6M7LHIF6XUCJ4Q", "blockPruneInterval": "360", "maxTransactionsPerBlock": "6'000" }, @@ -61,7 +61,7 @@ export const getDummyNetworkProperties = (): any => { "maxMosaicsPerAccount": "1'000", "maxMosaicDuration": "3650d", "maxMosaicDivisibility": "6", - "mosaicRentalFeeSinkPublicKey": "53E140B5947F104CABC2D6FE8BAEDBC30EF9A0609C717D9613DE593EC2A266D3", + "mosaicRentalFeeSinkAddress": "TDGY4DD2U4YQQGERFMDQYHPYS6M7LHIF6XUCJ4Q", "mosaicRentalFee": "500" }, "multisig": { @@ -77,7 +77,7 @@ export const getDummyNetworkProperties = (): any => { "maxNamespaceDuration": "365d", "namespaceGracePeriodDuration": "30d", "reservedRootNamespaceNames": "xem, nem, user, account, org, com, biz, net, edu, mil, gov, info", - "namespaceRentalFeeSinkPublicKey": "3E82E1C1E4A75ADAA3CBA8C101C3CD31D9817A2EB966EB3B511FB2ED45B8E262", + "namespaceRentalFeeSinkAddress": "TDGY4DD2U4YQQGERFMDQYHPYS6M7LHIF6XUCJ4Q", "rootNamespaceRentalFeePerBlock": "1", "childNamespaceRentalFee": "100" }, diff --git a/test/service/BlockService.spec.ts b/test/service/BlockService.spec.ts index e5939c1f78..5ea43d78e4 100644 --- a/test/service/BlockService.spec.ts +++ b/test/service/BlockService.spec.ts @@ -40,6 +40,7 @@ describe('BlockService', () => { if (isFake) { return new BlockInfo( 'id', + 1, 'hash', 'generationHash', UInt64.fromNumericString('0'), @@ -66,6 +67,7 @@ describe('BlockService', () => { } return new BlockInfo( 'id', + 1, 'hash', 'generationHash', UInt64.fromNumericString('0'), From 468eb2e823a9a116836800a0c49e83064f38d94a Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 11 Jun 2020 20:10:10 +0100 Subject: [PATCH 11/22] Remvoed meta.id from createFromDto since all ids are from the top level --- .../transaction/CreateTransactionFromDTO.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index eecd9adeba..6c426def91 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -135,15 +135,9 @@ const extractTransactionMeta = (meta: any, id: string): TransactionInfo | Aggreg return undefined; } if (meta.aggregateHash || meta.aggregateId) { - return new AggregateTransactionInfo( - UInt64.fromNumericString(meta.height), - meta.index, - id || meta.id, - meta.aggregateHash, - meta.aggregateId, - ); + return new AggregateTransactionInfo(UInt64.fromNumericString(meta.height), meta.index, id, meta.aggregateHash, meta.aggregateId); } - return new TransactionInfo(UInt64.fromNumericString(meta.height), meta.index, id || meta.id, meta.hash, meta.merkleComponentHash); + return new TransactionInfo(UInt64.fromNumericString(meta.height), meta.index, id, meta.hash, meta.merkleComponentHash); }; /** * @internal From 7c666851c69ac4f3e8ca821ff4086d5c56b955df Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Fri, 12 Jun 2020 16:56:14 +0100 Subject: [PATCH 12/22] - Updated openAPI version - Fixed e2e tests --- e2e/infrastructure/Listener.spec.ts | 34 +++++++---- e2e/infrastructure/MetadataHttp.spec.ts | 2 +- .../MetadataTransactionService.spec.ts | 58 +++++++++---------- ...osaicRestrictionTransactionService.spec.ts | 23 ++++---- package-lock.json | 6 +- package.json | 2 +- 6 files changed, 65 insertions(+), 60 deletions(-) diff --git a/e2e/infrastructure/Listener.spec.ts b/e2e/infrastructure/Listener.spec.ts index 6be1e8fef9..adc54984a0 100644 --- a/e2e/infrastructure/Listener.spec.ts +++ b/e2e/infrastructure/Listener.spec.ts @@ -15,7 +15,7 @@ */ import { assert, expect } from 'chai'; import { ChronoUnit } from 'js-joda'; -import { filter } from 'rxjs/operators'; +import { filter, mergeMap } from 'rxjs/operators'; import { TransactionRepository } from '../../src/infrastructure/TransactionRepository'; import { Account } from '../../src/model/account/Account'; import { PlainMessage } from '../../src/model/message/PlainMessage'; @@ -242,27 +242,36 @@ describe('Listener', () => { }); }); }); + describe('Aggregate Bonded Transactions', () => { it('aggregateBondedTransactionsRemoved', (done) => { const signedAggregatedTx = createSignedAggregatedBondTransaction(multisigAccount, cosignAccount1, account2.address); - createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, helper.networkCurrencyNamespaceId); + helper.listener.aggregateBondedRemoved(cosignAccount1.address, signedAggregatedTx.hash).subscribe(() => { + done(); + }); helper.listener.confirmed(cosignAccount1.address).subscribe(() => { - helper.listener.aggregateBondedRemoved(cosignAccount1.address).subscribe(() => { - done(); - }); helper.listener.aggregateBondedAdded(cosignAccount1.address).subscribe(() => { const criteria: TransactionSearchCriteria = { address: cosignAccount1.address, group: TransactionGroupSubsetEnum.Partial, + embedded: true, }; - transactionRepository.search(criteria).subscribe((transactions) => { - console.log('Partial', transactions.data); - const transactionToCosign = transactions.data[0] as AggregateTransaction; - const cosignatureTransaction = CosignatureTransaction.create(transactionToCosign); - const cosignatureSignedTransaction = cosignAccount2.signCosignatureTransaction(cosignatureTransaction); - transactionRepository.announceAggregateBondedCosignature(cosignatureSignedTransaction); - }); + transactionRepository + .search(criteria) + .pipe( + mergeMap((page) => { + console.log('Partial Search', page.data); + return transactionRepository.getTransaction(page.data[0].transactionInfo?.hash!); + }), + ) + .subscribe((transactions) => { + console.log('getTransaction', transactions); + const transactionToCosign = transactions as AggregateTransaction; + const cosignatureTransaction = CosignatureTransaction.create(transactionToCosign); + const cosignatureSignedTransaction = cosignAccount2.signCosignatureTransaction(cosignatureTransaction); + transactionRepository.announceAggregateBondedCosignature(cosignatureSignedTransaction); + }); }); helper.listener.status(cosignAccount1.address).subscribe((error) => { console.log('Error:', error); @@ -347,6 +356,7 @@ describe('Listener', () => { ], networkType, [], + helper.maxFee, ); const signedTransaction = aggregateTransaction.signTransactionWithCosignatories( cosignAccount1, diff --git a/e2e/infrastructure/MetadataHttp.spec.ts b/e2e/infrastructure/MetadataHttp.spec.ts index 85d4f051d9..537647622f 100644 --- a/e2e/infrastructure/MetadataHttp.spec.ts +++ b/e2e/infrastructure/MetadataHttp.spec.ts @@ -209,7 +209,7 @@ describe('MetadataHttp', () => { }); describe('getAccountMetadataByKeyAndSender', () => { - it('should return metadata given a NEM Address and metadata key and sender public key', async () => { + it('should return metadata given a NEM Address and metadata key and sender address', async () => { const metadata = await metadataRepository .getAccountMetadataByKeyAndSender(accountAddress, UInt64.fromUint(6).toHex(), account.address) .toPromise(); diff --git a/e2e/service/MetadataTransactionService.spec.ts b/e2e/service/MetadataTransactionService.spec.ts index abe6be40ab..591231bdff 100644 --- a/e2e/service/MetadataTransactionService.spec.ts +++ b/e2e/service/MetadataTransactionService.spec.ts @@ -21,7 +21,7 @@ import { IntegrationTestHelper } from '../infrastructure/IntegrationTestHelper'; describe('MetadataTransactionService', () => { const deadline = Deadline.create(); - const key = UInt64.fromUint(123); + const key = UInt64.fromUint(Math.round(Math.random() * 10)); const newValue = 'new test value'; const helper = new IntegrationTestHelper(); @@ -195,6 +195,7 @@ describe('MetadataTransactionService', () => { }); it('should create NamespaceMetadataTransaction', async () => { + await new Promise((resolve) => setTimeout(resolve, 3000)); const metaDataService = new MetadataTransactionService(metadataRepository); const updateValue = newValue + 'delta'; @@ -225,7 +226,6 @@ describe('MetadataTransactionService', () => { describe('Announce transaction through service', () => { it('should create MosaicMetadataTransaction and announce', async () => { const metaDataService = new MetadataTransactionService(metadataRepository); - const transaction = await metaDataService .createMetadataTransaction( deadline, @@ -252,10 +252,10 @@ describe('MetadataTransactionService', () => { }); describe('Announce transaction through service with delta size increase', () => { - it('should create MosaicMetadataTransaction and announce', () => { + it('should create MosaicMetadataTransaction and announce', async () => { + await new Promise((resolve) => setTimeout(resolve, 3000)); const metaDataService = new MetadataTransactionService(metadataRepository); - - return metaDataService + const transaction = await metaDataService .createMetadataTransaction( deadline, networkType, @@ -267,26 +267,24 @@ describe('MetadataTransactionService', () => { mosaicId, helper.maxFee, ) - .toPromise() - .then((transaction: MosaicMetadataTransaction) => { - const aggregateTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [transaction.toAggregate(targetAccount.publicAccount)], - networkType, - [], - helper.maxFee, - ); - const signedTransaction = aggregateTransaction.signWith(targetAccount, generationHash); - return helper.announce(signedTransaction); - }); + .toPromise(); + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [transaction.toAggregate(targetAccount.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = aggregateTransaction.signWith(targetAccount, generationHash); + return await helper.announce(signedTransaction); }); }); describe('Announce transaction through service with delta size decrease', () => { it('should create MosaicMetadataTransaction and announce', async () => { + await new Promise((resolve) => setTimeout(resolve, 3000)); const metaDataService = new MetadataTransactionService(metadataRepository); - - return metaDataService + const transaction = await metaDataService .createMetadataTransaction( deadline, networkType, @@ -297,18 +295,16 @@ describe('MetadataTransactionService', () => { targetAccount.address, mosaicId, ) - .toPromise() - .then((transaction: MosaicMetadataTransaction) => { - const aggregateTransaction = AggregateTransaction.createComplete( - Deadline.create(), - [transaction.toAggregate(targetAccount.publicAccount)], - networkType, - [], - helper.maxFee, - ); - const signedTransaction = aggregateTransaction.signWith(targetAccount, generationHash); - return helper.announce(signedTransaction); - }); + .toPromise(); + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [transaction.toAggregate(targetAccount.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = aggregateTransaction.signWith(targetAccount, generationHash); + return await helper.announce(signedTransaction); }); }); }); diff --git a/e2e/service/MosaicRestrictionTransactionService.spec.ts b/e2e/service/MosaicRestrictionTransactionService.spec.ts index f6439aafab..b9a151c811 100644 --- a/e2e/service/MosaicRestrictionTransactionService.spec.ts +++ b/e2e/service/MosaicRestrictionTransactionService.spec.ts @@ -221,9 +221,10 @@ describe('MosaicRestrictionTransactionService', () => { }); describe('Test new services - MosaicGlobalRestriction', () => { - it('should create MosaicGlobalRestrictionTransaction using alias', () => { + it('should create MosaicGlobalRestrictionTransaction using alias', async () => { + await new Promise((resolve) => setTimeout(resolve, 3000)); const service = new MosaicRestrictionTransactionService(restrictionRepository, namespaceRepository); - return service + const transaction = (await service .createMosaicGlobalRestrictionTransaction( deadline, networkType, @@ -234,15 +235,13 @@ describe('MosaicRestrictionTransactionService', () => { undefined, helper.maxFee, ) - .toPromise() - .then((transaction: MosaicGlobalRestrictionTransaction) => { - expect(transaction.type).to.be.equal(TransactionType.MOSAIC_GLOBAL_RESTRICTION); - expect(transaction.previousRestrictionValue.toString()).to.be.equal('1'); - expect(transaction.previousRestrictionType).to.be.equal(MosaicRestrictionType.GE); - expect(transaction.newRestrictionValue.toString()).to.be.equal('2'); - expect(transaction.newRestrictionType).to.be.equal(MosaicRestrictionType.GE); - expect(transaction.restrictionKey.toHex()).to.be.equal(key.toHex()); - }); + .toPromise()) as MosaicGlobalRestrictionTransaction; + expect(transaction.type).to.be.equal(TransactionType.MOSAIC_GLOBAL_RESTRICTION); + expect(transaction.previousRestrictionValue.toString()).to.be.equal('0'); + expect(transaction.previousRestrictionType).to.be.equal(MosaicRestrictionType.GE); + expect(transaction.newRestrictionValue.toString()).to.be.equal('2'); + expect(transaction.newRestrictionType).to.be.equal(MosaicRestrictionType.GE); + expect(transaction.restrictionKey.toHex()).to.be.equal(key.toHex()); }); }); @@ -271,7 +270,7 @@ describe('MosaicRestrictionTransactionService', () => { .toPromise() .then((transaction: MosaicAddressRestrictionTransaction) => { expect(transaction.type).to.be.equal(TransactionType.MOSAIC_ADDRESS_RESTRICTION); - expect(transaction.previousRestrictionValue.toString()).to.be.equal('3'); + expect(transaction.previousRestrictionValue.toString()).to.be.equal('2'); expect(transaction.newRestrictionValue.toString()).to.be.equal('4'); expect(transaction.targetAddressToString()).to.be.equal(account.address.plain()); expect(transaction.restrictionKey.toHex()).to.be.equal(key.toHex()); diff --git a/package-lock.json b/package-lock.json index d9d7f435ff..4c71f6ad03 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6252,9 +6252,9 @@ } }, "symbol-openapi-typescript-node-client": { - "version": "0.8.13-SNAPSHOT.202006111924", - "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-node-client/-/symbol-openapi-typescript-node-client-0.8.13-SNAPSHOT.202006111924.tgz", - "integrity": "sha512-OHZrlAA94fJsfj19GF4GMY/gBGRAV7oK8bp6x55SstAU3Jfo8lnto9BLsgzh/zLrQpTnFiPGm0TcSUYcZQlYVA==", + "version": "0.8.13-SNAPSHOT.202006121228", + "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-node-client/-/symbol-openapi-typescript-node-client-0.8.13-SNAPSHOT.202006121228.tgz", + "integrity": "sha512-CjxB6gyLt+hX7Rvq4IZrVEfyqbOvknAWmz/rzIcDcl5gzIF8Iw3RAmAisK6E+jXD8Neh10YmgTSRTcf8uD4HVQ==", "requires": { "@types/bluebird": "*", "@types/request": "*", diff --git a/package.json b/package.json index 2ed1a7e999..d79f1fd850 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "ripemd160": "^2.0.2", "rxjs": "^6.5.3", "rxjs-compat": "^6.5.3", - "symbol-openapi-typescript-node-client": "0.8.13-SNAPSHOT.202006111924", + "symbol-openapi-typescript-node-client": "0.8.13-SNAPSHOT.202006121228", "tweetnacl": "^1.0.3", "utf8": "^3.0.0", "ws": "^7.2.3" From ffb30d3217b53e621d84ee18f2fbb14de6a455e8 Mon Sep 17 00:00:00 2001 From: fernando Date: Mon, 15 Jun 2020 09:23:02 -0300 Subject: [PATCH 13/22] Added MultisigAccounts.spect.ts --- e2e/infrastructure/MultisigAccounts.spect.ts | 100 +++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 e2e/infrastructure/MultisigAccounts.spect.ts diff --git a/e2e/infrastructure/MultisigAccounts.spect.ts b/e2e/infrastructure/MultisigAccounts.spect.ts new file mode 100644 index 0000000000..c0973a0910 --- /dev/null +++ b/e2e/infrastructure/MultisigAccounts.spect.ts @@ -0,0 +1,100 @@ +/* + * Copyright 2020 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { Crypto } from '../../src/core/crypto'; +import { Convert } from '../../src/core/format'; +import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; +import { TransactionRepository } from '../../src/infrastructure/TransactionRepository'; +import { Account } from '../../src/model/account/Account'; +import { NetworkType } from '../../src/model/network/NetworkType'; +import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction'; +import { Deadline } from '../../src/model/transaction/Deadline'; +import { MultisigAccountModificationTransaction } from '../../src/model/transaction/MultisigAccountModificationTransaction'; +import { IntegrationTestHelper } from './IntegrationTestHelper'; + +describe('MultisigAccounts', () => { + const helper = new IntegrationTestHelper(); + let account: Account; + let account2: Account; + let account3: Account; + let multisigAccount: Account; + let cosignAccount1: Account; + let cosignAccount2: Account; + let cosignAccount3: Account; + let namespaceRepository: NamespaceRepository; + let generationHash: string; + let networkType: NetworkType; + let harvestingAccount: Account; + let transactionRepository: TransactionRepository; + let votingKey: string; + + before(() => { + return helper.start().then(() => { + account = helper.account; + account2 = helper.account2; + account3 = helper.account3; + multisigAccount = helper.multisigAccount; + cosignAccount1 = helper.cosignAccount1; + cosignAccount2 = helper.cosignAccount2; + cosignAccount3 = helper.cosignAccount3; + harvestingAccount = helper.harvestingAccount; + generationHash = helper.generationHash; + networkType = helper.networkType; + votingKey = Convert.uint8ToHex(Crypto.randomBytes(48)); + namespaceRepository = helper.repositoryFactory.createNamespaceRepository(); + transactionRepository = helper.repositoryFactory.createTransactionRepository(); + }); + }); + before(() => { + return helper.listener.open(); + }); + + after(() => { + helper.listener.close(); + }); + + describe('Setup test multisig account', () => { + it('Announce MultisigAccountModificationTransaction', () => { + + console.log(`http://localhost:3000/account/${multisigAccount.address.plain()}`); + console.log(`http://localhost:3000/account/${multisigAccount.address.plain()}/multisig`); + const modifyMultisigAccountTransaction = MultisigAccountModificationTransaction.create( + Deadline.create(), + 2, + 1, + [cosignAccount1.address, cosignAccount2.address, cosignAccount3.address], + [], + networkType, + helper.maxFee, + ); + + const aggregateTransaction = AggregateTransaction.createComplete( + Deadline.create(), + [modifyMultisigAccountTransaction.toAggregate(multisigAccount.publicAccount)], + networkType, + [], + helper.maxFee, + ); + const signedTransaction = aggregateTransaction.signTransactionWithCosignatories( + multisigAccount, + [cosignAccount1, cosignAccount2, cosignAccount3], + generationHash, + ); + + console.log(signedTransaction.hash); + return helper.announce(signedTransaction); + }); + }); +}); From 8a0a4f69284b8b6f9480841842c81ef1d171259d Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 15 Jun 2020 18:51:50 +0100 Subject: [PATCH 14/22] - Updated opneAPI spec - Split transaction search & get into 3 - Made 'group' mandatory in transactionSearchCriteria - Added transactionStatus repository --- e2e/infrastructure/Listener.spec.ts | 11 +- e2e/infrastructure/MosaicHttp.spec.ts | 3 +- e2e/infrastructure/TransactionHttp.spec.ts | 21 +- e2e/service/BlockService.spec.ts | 3 +- package-lock.json | 6 +- package.json | 2 +- src/infrastructure/RepositoryFactory.ts | 8 +- src/infrastructure/RepositoryFactoryHttp.ts | 6 + src/infrastructure/TransactionHttp.ts | 154 ++++--- src/infrastructure/TransactionRepository.ts | 22 +- src/infrastructure/TransactionSearchGroup.ts | 24 ++ src/infrastructure/TransactionStatusHttp.ts | 90 +++++ .../TransactionStatusRepository.ts | 39 ++ .../TransactionSearchCriteria.ts | 11 +- test/infrastructure/RepositoryFactory.spec.ts | 38 ++ test/infrastructure/TransactionHttp.spec.ts | 377 +++++++++++++++--- .../TransactionSearchCriteria.spec.ts | 15 +- .../TransactionStatusHttp.spec.ts | 84 ++++ .../TransactionPaginationStreamer.spec.ts | 102 ++++- 19 files changed, 840 insertions(+), 176 deletions(-) create mode 100644 src/infrastructure/TransactionSearchGroup.ts create mode 100644 src/infrastructure/TransactionStatusHttp.ts create mode 100644 src/infrastructure/TransactionStatusRepository.ts create mode 100644 test/infrastructure/TransactionStatusHttp.spec.ts diff --git a/e2e/infrastructure/Listener.spec.ts b/e2e/infrastructure/Listener.spec.ts index adc54984a0..3d71676a1d 100644 --- a/e2e/infrastructure/Listener.spec.ts +++ b/e2e/infrastructure/Listener.spec.ts @@ -26,7 +26,6 @@ import { MultisigAccountModificationTransaction } from '../../src/model/transact import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; import { IntegrationTestHelper } from './IntegrationTestHelper'; import { TransactionSearchCriteria } from '../../src/infrastructure/searchCriteria/TransactionSearchCriteria'; -import { TransactionGroupSubsetEnum } from 'symbol-openapi-typescript-node-client'; import { Address } from '../../src/model/account/Address'; import { SignedTransaction } from '../../src/model/transaction/SignedTransaction'; import { LockFundsTransaction } from '../../src/model/transaction/LockFundsTransaction'; @@ -34,6 +33,7 @@ import { UInt64 } from '../../src/model/UInt64'; import { Mosaic } from '../../src/model/mosaic/Mosaic'; import { CosignatureTransaction } from '../../src/model/transaction/CosignatureTransaction'; import { UnresolvedMosaicId } from '../../src/model/mosaic/UnresolvedMosaicId'; +import { TransactionSearchGroup } from '../../src/infrastructure/TransactionSearchGroup'; describe('Listener', () => { const helper = new IntegrationTestHelper(); @@ -254,7 +254,7 @@ describe('Listener', () => { helper.listener.aggregateBondedAdded(cosignAccount1.address).subscribe(() => { const criteria: TransactionSearchCriteria = { address: cosignAccount1.address, - group: TransactionGroupSubsetEnum.Partial, + group: TransactionSearchGroup.Partial, embedded: true, }; transactionRepository @@ -262,7 +262,10 @@ describe('Listener', () => { .pipe( mergeMap((page) => { console.log('Partial Search', page.data); - return transactionRepository.getTransaction(page.data[0].transactionInfo?.hash!); + return transactionRepository.getTransaction( + page.data[0].transactionInfo?.hash!, + TransactionSearchGroup.Partial, + ); }), ) .subscribe((transactions) => { @@ -299,7 +302,7 @@ describe('Listener', () => { helper.listener.aggregateBondedAdded(cosignAccount1.address).subscribe(() => { const criteria: TransactionSearchCriteria = { address: cosignAccount1.publicAccount.address, - group: TransactionGroupSubsetEnum.Partial, + group: TransactionSearchGroup.Partial, }; transactionRepository.search(criteria).subscribe((transactions) => { const transactionToCosign = transactions.data[0] as AggregateTransaction; diff --git a/e2e/infrastructure/MosaicHttp.spec.ts b/e2e/infrastructure/MosaicHttp.spec.ts index e2b40f6f07..5bdfac5a4b 100644 --- a/e2e/infrastructure/MosaicHttp.spec.ts +++ b/e2e/infrastructure/MosaicHttp.spec.ts @@ -32,6 +32,7 @@ import { IntegrationTestHelper } from './IntegrationTestHelper'; import { MosaicPaginationStreamer } from '../../src/infrastructure/paginationStreamer/MosaicPaginationStreamer'; import { toArray, take } from 'rxjs/operators'; import { deepEqual } from 'assert'; +import { TransactionSearchGroup } from '../../src/infrastructure/TransactionSearchGroup'; describe('MosaicHttp', () => { let mosaicId: MosaicId; @@ -90,7 +91,7 @@ describe('MosaicHttp', () => { const savedTransaction = (await helper.repositoryFactory .createTransactionRepository() - .getTransaction(signedTransaction.hash) + .getTransaction(signedTransaction.hash, TransactionSearchGroup.Confirmed) .toPromise()) as MosaicDefinitionTransaction; expect(mosaicDefinitionTransaction.nonce.toHex()).to.be.equal(savedTransaction.nonce.toHex()); expect(mosaicDefinitionTransaction.nonce).to.deep.equal(savedTransaction.nonce); diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 2dfce3b0c0..7fdca9ba04 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -74,6 +74,8 @@ import { deepEqual } from 'assert'; import { AddressRestrictionFlag } from '../../src/model/restriction/AddressRestrictionFlag'; import { MosaicRestrictionFlag } from '../../src/model/restriction/MosaicRestrictionFlag'; import { OperationRestrictionFlag } from '../../src/model/restriction/OperationRestrictionFlag'; +import { TransactionSearchGroup } from '../../src/infrastructure/TransactionSearchGroup'; +import { TransactionStatusRepository } from '../../src/infrastructure/TransactionStatusRepository'; // eslint-disable-next-line @typescript-eslint/no-var-requires const CryptoJS = require('crypto-js'); @@ -97,6 +99,7 @@ describe('TransactionHttp', () => { let mosaicAlias: NamespaceId; let harvestingAccount: Account; let transactionRepository: TransactionRepository; + let transactionStatusRepository: TransactionStatusRepository; let votingKey: string; // eslint-disable-next-line @typescript-eslint/no-var-requires const secureRandom = require('secure-random'); @@ -120,6 +123,7 @@ describe('TransactionHttp', () => { votingKey = Convert.uint8ToHex(Crypto.randomBytes(48)); namespaceRepository = helper.repositoryFactory.createNamespaceRepository(); transactionRepository = helper.repositoryFactory.createTransactionRepository(); + transactionStatusRepository = helper.repositoryFactory.createTransactionStatusRepository(); }); }); before(() => { @@ -1384,13 +1388,13 @@ describe('TransactionHttp', () => { describe('getTransaction', () => { it('should return transaction info given transactionHash', async () => { - const transaction = await transactionRepository.getTransaction(transactionHash).toPromise(); + const transaction = await transactionRepository.getTransaction(transactionHash, TransactionSearchGroup.Confirmed).toPromise(); expect(transaction.transactionInfo!.hash).to.be.equal(transactionHash); transactionId = transaction.transactionInfo?.id!; }); it('should return transaction info given transactionId', async () => { - const transaction = await transactionRepository.getTransaction(transactionId).toPromise(); + const transaction = await transactionRepository.getTransaction(transactionId, TransactionSearchGroup.Confirmed).toPromise(); expect(transaction.transactionInfo!.hash).to.be.equal(transactionHash); expect(transaction.transactionInfo!.id).to.be.equal(transactionId); }); @@ -1413,7 +1417,7 @@ describe('TransactionHttp', () => { describe('getTransactionStatus', () => { it('should return transaction status given transactionHash', async () => { await new Promise((resolve) => setTimeout(resolve, 2000)); - const transactionStatus = await transactionRepository.getTransactionStatus(transactionHash).toPromise(); + const transactionStatus = await transactionStatusRepository.getTransactionStatus(transactionHash).toPromise(); expect(transactionStatus.group).to.be.equal('confirmed'); expect(transactionStatus.height!.lower).to.be.greaterThan(0); expect(transactionStatus.height!.higher).to.be.equal(0); @@ -1422,7 +1426,7 @@ describe('TransactionHttp', () => { describe('getTransactionsStatuses', () => { it('should return transaction status given array of transactionHash', async () => { - const transactionStatuses = await transactionRepository.getTransactionsStatuses([transactionHash]).toPromise(); + const transactionStatuses = await transactionStatusRepository.getTransactionStatuses([transactionHash]).toPromise(); expect(transactionStatuses[0].group).to.be.equal('confirmed'); expect(transactionStatuses[0].height!.lower).to.be.greaterThan(0); expect(transactionStatuses[0].height!.higher).to.be.equal(0); @@ -1478,7 +1482,9 @@ describe('TransactionHttp', () => { describe('getTransactionEffectiveFee', () => { it('should return effective paid fee given transactionHash', async () => { - const effectiveFee = await transactionRepository.getTransactionEffectiveFee(transactionHash).toPromise(); + const effectiveFee = await transactionRepository + .getTransactionEffectiveFee(transactionHash, TransactionSearchGroup.Confirmed) + .toPromise(); expect(effectiveFee).to.not.be.undefined; expect(effectiveFee).not.to.be.equal(0); }); @@ -1503,7 +1509,10 @@ describe('TransactionHttp', () => { const transactionsNoStreamer = await transactionRepository .search({ address: account.address, pageSize: 10 } as TransactionSearchCriteria) .toPromise(); - const transactions = await streamer.search({ address: account.address, pageSize: 10 }).pipe(take(10), toArray()).toPromise(); + const transactions = await streamer + .search({ group: TransactionSearchGroup.Confirmed, address: account.address, pageSize: 10 }) + .pipe(take(10), toArray()) + .toPromise(); expect(transactions.length).to.be.greaterThan(0); deepEqual(transactionsNoStreamer.data, transactions); }); diff --git a/e2e/service/BlockService.spec.ts b/e2e/service/BlockService.spec.ts index d54a9cf1f3..35eb6cffa7 100644 --- a/e2e/service/BlockService.spec.ts +++ b/e2e/service/BlockService.spec.ts @@ -26,6 +26,7 @@ import { TransferTransaction } from '../../src/model/transaction/TransferTransac import { UInt64 } from '../../src/model/UInt64'; import { BlockService } from '../../src/service/BlockService'; import { IntegrationTestHelper } from '../infrastructure/IntegrationTestHelper'; +import { TransactionSearchGroup } from '../../src/infrastructure/TransactionSearchGroup'; describe('BlockService', () => { const helper = new IntegrationTestHelper(); @@ -87,7 +88,7 @@ describe('BlockService', () => { describe('Validate transansaction', () => { it('call block service', async () => { - const transaction = await transactionRepository.getTransaction(transactionHash).toPromise(); + const transaction = await transactionRepository.getTransaction(transactionHash, TransactionSearchGroup.Confirmed).toPromise(); const transactionInfo = transaction.transactionInfo; if (transactionInfo && transactionInfo.height !== undefined) { const validationResult = await blockService.validateTransactionInBlock(transactionHash, transactionInfo.height).toPromise(); diff --git a/package-lock.json b/package-lock.json index 4c71f6ad03..79ad51fe2b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6252,9 +6252,9 @@ } }, "symbol-openapi-typescript-node-client": { - "version": "0.8.13-SNAPSHOT.202006121228", - "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-node-client/-/symbol-openapi-typescript-node-client-0.8.13-SNAPSHOT.202006121228.tgz", - "integrity": "sha512-CjxB6gyLt+hX7Rvq4IZrVEfyqbOvknAWmz/rzIcDcl5gzIF8Iw3RAmAisK6E+jXD8Neh10YmgTSRTcf8uD4HVQ==", + "version": "0.8.13-SNAPSHOT.202006151206", + "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-node-client/-/symbol-openapi-typescript-node-client-0.8.13-SNAPSHOT.202006151206.tgz", + "integrity": "sha512-0xNXCrWiia5nW3xgGC/oTadbZSr3Tjkt6gZC0yC+1n7JQU5ctqNoFZDdk6q1xUF50ROaTba3tef0jiNf0T0wFQ==", "requires": { "@types/bluebird": "*", "@types/request": "*", diff --git a/package.json b/package.json index d79f1fd850..93bf55ee7f 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "ripemd160": "^2.0.2", "rxjs": "^6.5.3", "rxjs-compat": "^6.5.3", - "symbol-openapi-typescript-node-client": "0.8.13-SNAPSHOT.202006121228", + "symbol-openapi-typescript-node-client": "0.8.13-SNAPSHOT.202006151206", "tweetnacl": "^1.0.3", "utf8": "^3.0.0", "ws": "^7.2.3" diff --git a/src/infrastructure/RepositoryFactory.ts b/src/infrastructure/RepositoryFactory.ts index 291a639ef0..4f6228f8a6 100644 --- a/src/infrastructure/RepositoryFactory.ts +++ b/src/infrastructure/RepositoryFactory.ts @@ -30,6 +30,7 @@ import { ReceiptRepository } from './ReceiptRepository'; import { RestrictionAccountRepository } from './RestrictionAccountRepository'; import { RestrictionMosaicRepository } from './RestrictionMosaicRepository'; import { TransactionRepository } from './TransactionRepository'; +import { TransactionStatusRepository } from './TransactionStatusRepository'; /** * A repository factory allows clients to create repositories to access NEM Server without knowing @@ -95,10 +96,15 @@ export interface RepositoryFactory { createNodeRepository(): NodeRepository; /** - * @returns a newly created {@link NodeRepository} + * @returns a newly created {@link TransactionRepository} */ createTransactionRepository(): TransactionRepository; + /** + * @returns a newly created {@link TransactionStatusRepository} + */ + createTransactionStatusRepository(): TransactionStatusRepository; + /** * @returns a newly created {@link MetadataRepository} */ diff --git a/src/infrastructure/RepositoryFactoryHttp.ts b/src/infrastructure/RepositoryFactoryHttp.ts index 1dca30a4bb..b17fd83922 100644 --- a/src/infrastructure/RepositoryFactoryHttp.ts +++ b/src/infrastructure/RepositoryFactoryHttp.ts @@ -47,6 +47,8 @@ import { RestrictionMosaicRepository } from './RestrictionMosaicRepository'; import { TransactionHttp } from './TransactionHttp'; import { TransactionRepository } from './TransactionRepository'; import { RepositoryFactoryConfig } from './RepositoryFactoryConfig'; +import { TransactionStatusHttp } from './TransactionStatusHttp'; +import { TransactionStatusRepository } from './TransactionStatusRepository'; /** * Receipt http repository. @@ -131,6 +133,10 @@ export class RepositoryFactoryHttp implements RepositoryFactory { return new TransactionHttp(this.url); } + createTransactionStatusRepository(): TransactionStatusRepository { + return new TransactionStatusHttp(this.url); + } + getGenerationHash(): Observable { return this.generationHash; } diff --git a/src/infrastructure/TransactionHttp.ts b/src/infrastructure/TransactionHttp.ts index 589b4494e7..72497d1257 100644 --- a/src/infrastructure/TransactionHttp.ts +++ b/src/infrastructure/TransactionHttp.ts @@ -17,21 +17,26 @@ import { ClientResponse } from 'http'; import { from as observableFrom, Observable, throwError } from 'rxjs'; import { catchError, map, mergeMap } from 'rxjs/operators'; -import { BlockInfoDTO, BlockRoutesApi, TransactionRoutesApi, TransactionStatusDTO } from 'symbol-openapi-typescript-node-client'; +import { + BlockInfoDTO, + BlockRoutesApi, + TransactionRoutesApi, + TransactionInfoDTO, + TransactionPage, +} from 'symbol-openapi-typescript-node-client'; import { CosignatureSignedTransaction } from '../model/transaction/CosignatureSignedTransaction'; -import { Deadline } from '../model/transaction/Deadline'; import { SignedTransaction } from '../model/transaction/SignedTransaction'; import { Transaction } from '../model/transaction/Transaction'; import { TransactionAnnounceResponse } from '../model/transaction/TransactionAnnounceResponse'; import { TransactionInfo } from '../model/transaction/TransactionInfo'; -import { TransactionStatus } from '../model/transaction/TransactionStatus'; import { TransactionType } from '../model/transaction/TransactionType'; -import { UInt64 } from '../model/UInt64'; import { Http } from './Http'; import { CreateTransactionFromDTO } from './transaction/CreateTransactionFromDTO'; import { TransactionRepository } from './TransactionRepository'; import { TransactionSearchCriteria } from './searchCriteria/TransactionSearchCriteria'; import { Page } from './Page'; +import { TransactionSearchGroup } from './TransactionSearchGroup'; +import http = require('http'); /** * Transaction http repository. @@ -66,10 +71,11 @@ export class TransactionHttp extends Http implements TransactionRepository { /** * Gets a transaction for a transactionId * @param transactionId - Transaction id or hash. + * @param transactionGroup - Transaction group. * @returns Observable */ - public getTransaction(transactionId: string): Observable { - return observableFrom(this.transactionRoutesApi.getTransaction(transactionId)).pipe( + public getTransaction(transactionId: string, transactionGroup: TransactionSearchGroup): Observable { + return observableFrom(this.getTransactionByGroup(transactionId, transactionGroup)).pipe( map(({ body }) => CreateTransactionFromDTO(body)), catchError((error) => throwError(this.errorHandling(error))), ); @@ -94,33 +100,6 @@ export class TransactionHttp extends Http implements TransactionRepository { ); } - /** - * Gets a transaction status for a transaction hash - * @param transactionHash - Transaction hash. - * @returns Observable - */ - public getTransactionStatus(transactionHash: string): Observable { - return observableFrom(this.transactionRoutesApi.getTransactionStatus(transactionHash)).pipe( - map(({ body }) => this.toTransactionStatus(body)), - catchError((error) => throwError(this.errorHandling(error))), - ); - } - - /** - * Gets an array of transaction status for different transaction hashes - * @param transactionHashes - Array of transaction hash - * @returns Observable - */ - public getTransactionsStatuses(transactionHashes: string[]): Observable { - const transactionHashesBody = { - hashes: transactionHashes, - }; - return observableFrom(this.transactionRoutesApi.getTransactionsStatuses(transactionHashesBody)).pipe( - map(({ body }) => body.map(this.toTransactionStatus)), - catchError((error) => throwError(this.errorHandling(error))), - ); - } - /** * Send a signed transaction * @param signedTransaction - Signed transaction @@ -168,10 +147,11 @@ export class TransactionHttp extends Http implements TransactionRepository { /** * Gets a transaction's effective paid fee * @param transactionId - Transaction id or hash. + * @param transactionGroup - Transaction group. * @returns Observable */ - public getTransactionEffectiveFee(transactionId: string): Observable { - return observableFrom(this.transactionRoutesApi.getTransaction(transactionId)).pipe( + public getTransactionEffectiveFee(transactionId: string, transactionGroup: TransactionSearchGroup): Observable { + return observableFrom(this.getTransactionByGroup(transactionId, transactionGroup)).pipe( mergeMap(({ body }) => { // parse transaction to take advantage of `size` getter overload const transaction = CreateTransactionFromDTO(body); @@ -201,38 +181,88 @@ export class TransactionHttp extends Http implements TransactionRepository { * @returns {Observable>} */ public search(criteria: TransactionSearchCriteria): Observable> { - return this.call( - this.transactionRoutesApi.searchTransactions( - criteria.address?.plain(), - criteria.recipientAddress?.plain(), - criteria.signerPublicKey, - criteria.height?.toString(), - criteria.pageSize, - criteria.pageNumber, - criteria.offset, - criteria.group, - criteria.order, - criteria.type?.map((type) => type.valueOf()), - criteria.embedded, - ), - (body) => super.toPage(body.pagination, body.data, CreateTransactionFromDTO), + return this.call(this.searchTransactionByGroup(criteria), (body) => + super.toPage(body.pagination, body.data, CreateTransactionFromDTO), ); } /** - * This method maps a TransactionStatusDTO from rest to the SDK's TransactionStatus model object. - * * @internal - * @param {TransactionStatusDTO} dto the TransactionStatusDTO object from rest. - * @returns {TransactionStatus} a TransactionStatus model + * Gets a transaction info + * @param transactionId - Transaction id or hash. + * @param transactionGroup - Transaction group. + * @returns Promise<{response: http.ClientResponse; body: TransactionInfoDTO;}> */ - private toTransactionStatus(dto: TransactionStatusDTO): TransactionStatus { - return new TransactionStatus( - dto.group, - dto.hash, - Deadline.createFromDTO(UInt64.fromNumericString(dto.deadline).toDTO()), - dto.code, - dto.height ? UInt64.fromNumericString(dto.height) : undefined, - ); + private getTransactionByGroup( + transactionId: string, + transactionGroup: TransactionSearchGroup, + ): Promise<{ + response: http.ClientResponse; + body: TransactionInfoDTO; + }> { + switch (transactionGroup) { + case TransactionSearchGroup.Confirmed: + return this.transactionRoutesApi.getConfirmedTransaction(transactionId); + case TransactionSearchGroup.Unconfirmed: + return this.transactionRoutesApi.getUnconfirmedTransaction(transactionId); + case TransactionSearchGroup.Partial: + return this.transactionRoutesApi.getPartialTransaction(transactionId); + } + } + + /** + * @internal + * Gets a transaction search result + * @param transactionId - Transaction id or hash. + * @param transactionGroup - Transaction group. + * @returns Promise<{response: http.ClientResponse; body: TransactionInfoDTO;}> + */ + private searchTransactionByGroup( + criteria: TransactionSearchCriteria, + ): Promise<{ + response: http.ClientResponse; + body: TransactionPage; + }> { + switch (criteria.group) { + case TransactionSearchGroup.Confirmed: + return this.transactionRoutesApi.searchConfirmedTransactions( + criteria.address?.plain(), + criteria.recipientAddress?.plain(), + criteria.signerPublicKey, + criteria.height?.toString(), + criteria.type?.map((type) => type.valueOf()), + criteria.embedded, + criteria.pageSize, + criteria.pageNumber, + criteria.offset, + criteria.order, + ); + case TransactionSearchGroup.Unconfirmed: + return this.transactionRoutesApi.searchUnconfirmedTransactions( + criteria.address?.plain(), + criteria.recipientAddress?.plain(), + criteria.signerPublicKey, + criteria.height?.toString(), + criteria.type?.map((type) => type.valueOf()), + criteria.embedded, + criteria.pageSize, + criteria.pageNumber, + criteria.offset, + criteria.order, + ); + case TransactionSearchGroup.Partial: + return this.transactionRoutesApi.searchPartialTransactions( + criteria.address?.plain(), + criteria.recipientAddress?.plain(), + criteria.signerPublicKey, + criteria.height?.toString(), + criteria.type?.map((type) => type.valueOf()), + criteria.embedded, + criteria.pageSize, + criteria.pageNumber, + criteria.offset, + criteria.order, + ); + } } } diff --git a/src/infrastructure/TransactionRepository.ts b/src/infrastructure/TransactionRepository.ts index 59734493c8..64b596a8ea 100644 --- a/src/infrastructure/TransactionRepository.ts +++ b/src/infrastructure/TransactionRepository.ts @@ -19,9 +19,9 @@ import { CosignatureSignedTransaction } from '../model/transaction/CosignatureSi import { SignedTransaction } from '../model/transaction/SignedTransaction'; import { Transaction } from '../model/transaction/Transaction'; import { TransactionAnnounceResponse } from '../model/transaction/TransactionAnnounceResponse'; -import { TransactionStatus } from '../model/transaction/TransactionStatus'; import { TransactionSearchCriteria } from './searchCriteria/TransactionSearchCriteria'; import { Searcher } from './paginationStreamer/Searcher'; +import { TransactionSearchGroup } from './TransactionSearchGroup'; /** * Transaction interface repository. @@ -32,9 +32,10 @@ export interface TransactionRepository extends Searcher */ - getTransaction(transactionId: string): Observable; + getTransaction(transactionId: string, transactionGroup: TransactionSearchGroup): Observable; /** * Gets an array of transactions for different transaction ids @@ -43,26 +44,13 @@ export interface TransactionRepository extends Searcher; - /** - * Gets a transaction status for a transaction hash - * @param transactionHash - Transaction hash. - * @returns Observable - */ - getTransactionStatus(transactionHash: string): Observable; - - /** - * Gets an array of transaction status for different transaction hashes - * @param transactionHashes - Array of transaction hash - * @returns Observable - */ - getTransactionsStatuses(transactionHashes: string[]): Observable; - /** * Gets a transaction's effective paid fee * @param transactionId - Transaction id or hash. + * @param transactionGroup - Transaction group. * @returns Observable */ - getTransactionEffectiveFee(transactionId: string): Observable; + getTransactionEffectiveFee(transactionId: string, transactionGroup: TransactionSearchGroup): Observable; /** * Send a signed transaction diff --git a/src/infrastructure/TransactionSearchGroup.ts b/src/infrastructure/TransactionSearchGroup.ts new file mode 100644 index 0000000000..6c3488ed99 --- /dev/null +++ b/src/infrastructure/TransactionSearchGroup.ts @@ -0,0 +1,24 @@ +/* + * Copyright 2020 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * A transaction could be classified in the following groups: * Unconfirmed: The transaction reached the P2P network. At this point, it is not guaranteed that the transaction will be included in a block. * Confirmed: The transaction is included in a block. * Partial: The transaction requires to be cosigned by other transaction participants in order to be included in a block. * Failed: The transaction did not pass the network validation, and it was rejected. + */ +export enum TransactionSearchGroup { + Unconfirmed = 'unconfirmed', + Confirmed = 'confirmed', + Partial = 'partial', +} diff --git a/src/infrastructure/TransactionStatusHttp.ts b/src/infrastructure/TransactionStatusHttp.ts new file mode 100644 index 0000000000..4c245b9cbb --- /dev/null +++ b/src/infrastructure/TransactionStatusHttp.ts @@ -0,0 +1,90 @@ +/* + * Copyright 2018 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { from as observableFrom, Observable, throwError } from 'rxjs'; +import { catchError, map } from 'rxjs/operators'; +import { TransactionStatusRoutesApi, TransactionStatusDTO } from 'symbol-openapi-typescript-node-client'; +import { Deadline } from '../model/transaction/Deadline'; +import { TransactionStatus } from '../model/transaction/TransactionStatus'; +import { UInt64 } from '../model/UInt64'; +import { Http } from './Http'; +import { TransactionStatusRepository } from './TransactionStatusRepository'; + +/** + * Transaction status http repository. + * + * @since 1.0 + */ +export class TransactionStatusHttp extends Http implements TransactionStatusRepository { + /** + * @internal + * Symbol openapi typescript-node client transaction status routes api + */ + private transactionStatusRoutesApi: TransactionStatusRoutesApi; + + /** + * Constructor + * @param url + */ + constructor(url: string) { + super(url); + this.transactionStatusRoutesApi = new TransactionStatusRoutesApi(url); + } + + /** + * Gets a transaction status for a transaction hash + * @param transactionHash - Transaction hash. + * @returns Observable + */ + public getTransactionStatus(transactionHash: string): Observable { + return observableFrom(this.transactionStatusRoutesApi.getTransactionStatus(transactionHash)).pipe( + map(({ body }) => this.toTransactionStatus(body)), + catchError((error) => throwError(this.errorHandling(error))), + ); + } + + /** + * Gets an array of transaction status for different transaction hashes + * @param transactionHashes - Array of transaction hash + * @returns Observable + */ + public getTransactionStatuses(transactionHashes: string[]): Observable { + const transactionHashesBody = { + hashes: transactionHashes, + }; + return observableFrom(this.transactionStatusRoutesApi.getTransactionStatuses(transactionHashesBody)).pipe( + map(({ body }) => body.map(this.toTransactionStatus)), + catchError((error) => throwError(this.errorHandling(error))), + ); + } + + /** + * This method maps a TransactionStatusDTO from rest to the SDK's TransactionStatus model object. + * + * @internal + * @param {TransactionStatusDTO} dto the TransactionStatusDTO object from rest. + * @returns {TransactionStatus} a TransactionStatus model + */ + private toTransactionStatus(dto: TransactionStatusDTO): TransactionStatus { + return new TransactionStatus( + dto.group, + dto.hash, + Deadline.createFromDTO(UInt64.fromNumericString(dto.deadline).toDTO()), + dto.code, + dto.height ? UInt64.fromNumericString(dto.height) : undefined, + ); + } +} diff --git a/src/infrastructure/TransactionStatusRepository.ts b/src/infrastructure/TransactionStatusRepository.ts new file mode 100644 index 0000000000..35ec822ea4 --- /dev/null +++ b/src/infrastructure/TransactionStatusRepository.ts @@ -0,0 +1,39 @@ +/* + * Copyright 2018 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Observable } from 'rxjs'; +import { TransactionStatus } from '../model/transaction/TransactionStatus'; + +/** + * Transaction status interface repository. + * + * @since 1.0 + */ +export interface TransactionStatusRepository { + /** + * Gets a transaction status for a transaction hash + * @param transactionHash - Transaction hash. + * @returns Observable + */ + getTransactionStatus(transactionHash: string): Observable; + + /** + * Gets an array of transaction status for different transaction hashes + * @param transactionHashes - Array of transaction hash + * @returns Observable + */ + getTransactionStatuses(transactionHashes: string[]): Observable; +} diff --git a/src/infrastructure/searchCriteria/TransactionSearchCriteria.ts b/src/infrastructure/searchCriteria/TransactionSearchCriteria.ts index 38e97fd157..a64d890f6f 100644 --- a/src/infrastructure/searchCriteria/TransactionSearchCriteria.ts +++ b/src/infrastructure/searchCriteria/TransactionSearchCriteria.ts @@ -18,13 +18,17 @@ import { SearchCriteria } from './SearchCriteria'; import { Address } from '../../model/account/Address'; import { UInt64 } from '../../model/UInt64'; import { TransactionType } from '../../model/transaction/TransactionType'; -import { TransactionGroupSubsetEnum } from 'symbol-openapi-typescript-node-client/dist/model/transactionGroupSubsetEnum'; +import { TransactionSearchGroup } from '../TransactionSearchGroup'; /** * Defines the params used to search transactions. With this criteria, you can sort and filter * transactions queries using rest. */ export interface TransactionSearchCriteria extends SearchCriteria { + /** + * The group of transaction (optional, default is confirmed) + */ + group: TransactionSearchGroup; /** * Filter by address involved in the transaction. * @@ -51,11 +55,6 @@ export interface TransactionSearchCriteria extends SearchCriteria { */ height?: UInt64; - /** - * The group of transaction (optional, default is confirmed) - */ - group?: TransactionGroupSubsetEnum; - /** * Filter by transaction type. To filter by multiple transaction type. (optional, default to * new empty array) diff --git a/test/infrastructure/RepositoryFactory.spec.ts b/test/infrastructure/RepositoryFactory.spec.ts index ccf6d0de84..a8a042a792 100644 --- a/test/infrastructure/RepositoryFactory.spec.ts +++ b/test/infrastructure/RepositoryFactory.spec.ts @@ -23,6 +23,21 @@ import { NetworkType } from '../../src/model/network/NetworkType'; import { NodeRepository } from '../../src/infrastructure/NodeRepository'; import { NodeInfo } from '../../src/model/node/NodeInfo'; import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; +import { AccountHttp } from '../../src/infrastructure/AccountHttp'; +import { BlockHttp } from '../../src/infrastructure/BlockHttp'; +import { ChainHttp } from '../../src/infrastructure/ChainHttp'; +import { Listener } from '../../src/infrastructure/Listener'; +import { MetadataHttp } from '../../src/infrastructure/MetadataHttp'; +import { MosaicHttp } from '../../src/infrastructure/MosaicHttp'; +import { MultisigHttp } from '../../src/infrastructure/MultisigHttp'; +import { NamespaceHttp } from '../../src/infrastructure/NamespaceHttp'; +import { NetworkHttp } from '../../src/infrastructure/NetworkHttp'; +import { NodeHttp } from '../../src/infrastructure/NodeHttp'; +import { ReceiptHttp } from '../../src/infrastructure/ReceiptHttp'; +import { RestrictionAccountHttp } from '../../src/infrastructure/RestrictionAccountHttp'; +import { RestrictionMosaicHttp } from '../../src/infrastructure/RestrictionMosaicHttp'; +import { TransactionHttp } from '../../src/infrastructure/TransactionHttp'; +import { TransactionStatusHttp } from '../../src/infrastructure/TransactionStatusHttp'; describe('RepositoryFactory', () => { it('Should create repositories', () => { @@ -189,4 +204,27 @@ describe('RepositoryFactory', () => { listener = repositoryFactory.createListener(); expect(listener.url).to.be.equal('ws://localhost:3000/ws'); }); + + it('Should create listener object using injected ws', () => { + const factory = new RepositoryFactoryHttp('url', { + networkType: NetworkType.MIJIN_TEST, + generationHash: 'testHash', + }); + + expect(factory.createAccountRepository() instanceof AccountHttp).to.be.true; + expect(factory.createBlockRepository() instanceof BlockHttp).to.be.true; + expect(factory.createChainRepository() instanceof ChainHttp).to.be.true; + expect(factory.createListener() instanceof Listener).to.be.true; + expect(factory.createMetadataRepository() instanceof MetadataHttp).to.be.true; + expect(factory.createMosaicRepository() instanceof MosaicHttp).to.be.true; + expect(factory.createMultisigRepository() instanceof MultisigHttp).to.be.true; + expect(factory.createNamespaceRepository() instanceof NamespaceHttp).to.be.true; + expect(factory.createNetworkRepository() instanceof NetworkHttp).to.be.true; + expect(factory.createNodeRepository() instanceof NodeHttp).to.be.true; + expect(factory.createReceiptRepository() instanceof ReceiptHttp).to.be.true; + expect(factory.createRestrictionAccountRepository() instanceof RestrictionAccountHttp).to.be.true; + expect(factory.createRestrictionMosaicRepository() instanceof RestrictionMosaicHttp).to.be.true; + expect(factory.createTransactionRepository() instanceof TransactionHttp).to.be.true; + expect(factory.createTransactionStatusRepository() instanceof TransactionStatusHttp).to.be.true; + }); }); diff --git a/test/infrastructure/TransactionHttp.spec.ts b/test/infrastructure/TransactionHttp.spec.ts index 0f600cc003..17884e3e4d 100644 --- a/test/infrastructure/TransactionHttp.spec.ts +++ b/test/infrastructure/TransactionHttp.spec.ts @@ -19,15 +19,16 @@ import http = require('http'); import { BlockRoutesApi, TransactionRoutesApi, - TransactionGroupEnum, - TransactionStatusDTO, - TransactionStatusEnum, TransactionPage, TransactionMetaDTO, Pagination, TransferTransactionDTO, NetworkTypeEnum, TransactionInfoDTO, + BlockDTO, + BlockMetaDTO, + BlockInfoDTO, + AnnounceTransactionInfoDTO, } from 'symbol-openapi-typescript-node-client'; import { deepEqual, instance, mock, when } from 'ts-mockito'; @@ -40,10 +41,28 @@ import { Deadline } from '../../src/model/transaction/Deadline'; import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; import { NIS2_URL, TestingAccount } from '../conf/conf.spec'; import { TransactionType } from '../../src/model/transaction/TransactionType'; +import { TransactionSearchGroup } from '../../src/infrastructure/TransactionSearchGroup'; +import { UInt64 } from '../../src/model/UInt64'; +import { CosignatureSignedTransaction } from '../../src/model/transaction/CosignatureSignedTransaction'; describe('TransactionHttp', () => { const account = TestingAccount; const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6'; + + let clientResponse: http.ClientResponse; + let transactionRoutesApi: TransactionRoutesApi; + let transactionHttp: TransactionHttp; + let blockRoutesApi: BlockRoutesApi; + + before(() => { + transactionRoutesApi = mock(); + blockRoutesApi = mock(); + clientResponse = mock(); + transactionHttp = new TransactionHttp(NIS2_URL); + (transactionHttp as object)['transactionRoutesApi'] = instance(transactionRoutesApi); + (transactionHttp as object)['blockRoutesApi'] = instance(blockRoutesApi); + }); + it('should return an error when a non aggregate transaction bonded is announced via announceAggregateBonded method', () => { const tx = TransferTransaction.create( Deadline.create(), @@ -66,63 +85,6 @@ describe('TransactionHttp', () => { }).to.throw(Error, 'Only Transaction Type 0x4241 is allowed for announce aggregate bonded'); }); - let clientResponse: http.ClientResponse; - let transactionRoutesApi: TransactionRoutesApi; - let transactionHttp: TransactionHttp; - let blockRoutesApi: BlockRoutesApi; - - before(() => { - transactionRoutesApi = mock(); - blockRoutesApi = mock(); - clientResponse = mock(); - transactionHttp = new TransactionHttp(NIS2_URL); - (transactionHttp as object)['transactionRoutesApi'] = instance(transactionRoutesApi); - (transactionHttp as object)['blockRoutesApi'] = instance(blockRoutesApi); - }); - - it('Test getTransactionStatus method', async () => { - const hash = 'abc'; - const transactionStatusDTO = new TransactionStatusDTO(); - transactionStatusDTO.code = TransactionStatusEnum.FailureAccountLinkInconsistentUnlinkData; - transactionStatusDTO.deadline = '1234'; - transactionStatusDTO.hash = hash; - transactionStatusDTO.group = TransactionGroupEnum.Failed; - transactionStatusDTO.height = '567'; - - when(transactionRoutesApi.getTransactionStatus(deepEqual(hash))).thenReturn( - Promise.resolve({ response: instance(clientResponse), body: transactionStatusDTO }), - ); - - const transactionStatus = await transactionHttp.getTransactionStatus(hash).toPromise(); - - expect(transactionStatus.deadline.toString()).to.be.equal('1234'); - expect(transactionStatus.hash).to.be.equal(hash); - expect(transactionStatus.code).to.be.equal('Failure_AccountLink_Inconsistent_Unlink_Data'); - expect(transactionStatus.group).to.be.equal('failed'); - }); - - it('Test getTransactionsStatuses method', async () => { - const hash = 'abc'; - const transactionStatusDTO = new TransactionStatusDTO(); - transactionStatusDTO.code = TransactionStatusEnum.FailureAccountLinkInconsistentUnlinkData; - transactionStatusDTO.deadline = '1234'; - transactionStatusDTO.hash = hash; - transactionStatusDTO.group = TransactionGroupEnum.Failed; - transactionStatusDTO.height = '567'; - when(transactionRoutesApi.getTransactionsStatuses(deepEqual({ hashes: [hash] }))).thenReturn( - Promise.resolve({ response: instance(clientResponse), body: [transactionStatusDTO] }), - ); - - const transactionStatuses = await transactionHttp.getTransactionsStatuses([hash]).toPromise(); - expect(transactionStatuses.length).to.be.equal(1); - const transactionStatus = transactionStatuses[0]; - - expect(transactionStatus.deadline.toString()).to.be.equal('1234'); - expect(transactionStatus.hash).to.be.equal(hash); - expect(transactionStatus.code).to.be.equal('Failure_AccountLink_Inconsistent_Unlink_Data'); - expect(transactionStatus.group).to.be.equal('failed'); - }); - it('Test searchTransaction method', async () => { const page = new TransactionPage(); const paginationDto = new Pagination(); @@ -155,7 +117,7 @@ describe('TransactionHttp', () => { page.pagination = paginationDto; when( - transactionRoutesApi.searchTransactions( + transactionRoutesApi.searchConfirmedTransactions( deepEqual(account.address.plain()), undefined, undefined, @@ -166,11 +128,70 @@ describe('TransactionHttp', () => { undefined, undefined, undefined, + ), + ).thenReturn(Promise.resolve({ response: instance(clientResponse), body: page })); + + when( + transactionRoutesApi.searchPartialTransactions( + deepEqual(account.address.plain()), + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + ), + ).thenReturn(Promise.resolve({ response: instance(clientResponse), body: page })); + + when( + transactionRoutesApi.searchUnconfirmedTransactions( + deepEqual(account.address.plain()), + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, undefined, ), ).thenReturn(Promise.resolve({ response: instance(clientResponse), body: page })); - const transactions = await transactionHttp.search({ address: account.address }).toPromise(); + let transactions = await transactionHttp.search({ group: TransactionSearchGroup.Confirmed, address: account.address }).toPromise(); + + expect(transactions.data.length).to.be.equal(1); + expect(transactions.data[0].type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf()); + expect(((transactions.data[0] as TransferTransaction).recipientAddress as Address).plain()).to.be.equal( + Address.createFromEncoded('6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144').plain(), + ); + expect(transactions.data[0].transactionInfo?.id).to.be.equal('id'); + expect(transactions.data[0].transactionInfo?.hash).to.be.equal('hash'); + + expect(transactions.pageNumber).to.be.equal(1); + expect(transactions.pageSize).to.be.equal(1); + expect(transactions.totalEntries).to.be.equal(1); + expect(transactions.totalPages).to.be.equal(1); + + transactions = await transactionHttp.search({ group: TransactionSearchGroup.Unconfirmed, address: account.address }).toPromise(); + + expect(transactions.data.length).to.be.equal(1); + expect(transactions.data[0].type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf()); + expect(((transactions.data[0] as TransferTransaction).recipientAddress as Address).plain()).to.be.equal( + Address.createFromEncoded('6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144').plain(), + ); + expect(transactions.data[0].transactionInfo?.id).to.be.equal('id'); + expect(transactions.data[0].transactionInfo?.hash).to.be.equal('hash'); + + expect(transactions.pageNumber).to.be.equal(1); + expect(transactions.pageSize).to.be.equal(1); + expect(transactions.totalEntries).to.be.equal(1); + expect(transactions.totalPages).to.be.equal(1); + + transactions = await transactionHttp.search({ group: TransactionSearchGroup.Partial, address: account.address }).toPromise(); expect(transactions.data.length).to.be.equal(1); expect(transactions.data[0].type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf()); @@ -185,4 +206,236 @@ describe('TransactionHttp', () => { expect(transactions.totalEntries).to.be.equal(1); expect(transactions.totalPages).to.be.equal(1); }); + + it('Test getTransaction method', async () => { + const transactionInfoDto = new TransactionInfoDTO(); + const metaDto = new TransactionMetaDTO(); + metaDto.hash = 'hash'; + metaDto.height = '1'; + metaDto.index = 0; + metaDto.merkleComponentHash = 'merkleHash'; + + const transactionDto = new TransferTransactionDTO(); + transactionDto.deadline = '1'; + transactionDto.maxFee = '1'; + transactionDto.mosaics = []; + transactionDto.network = NetworkTypeEnum.NUMBER_104; + transactionDto.recipientAddress = '6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144'; + transactionDto.type = TransactionType.TRANSFER.valueOf(); + transactionDto.version = 1; + + transactionInfoDto.id = 'id'; + transactionInfoDto.meta = metaDto; + transactionInfoDto.transaction = transactionDto; + + when(transactionRoutesApi.getConfirmedTransaction(generationHash)).thenReturn( + Promise.resolve({ response: instance(clientResponse), body: transactionInfoDto }), + ); + + when(transactionRoutesApi.getPartialTransaction(generationHash)).thenReturn( + Promise.resolve({ response: instance(clientResponse), body: transactionInfoDto }), + ); + when(transactionRoutesApi.getUnconfirmedTransaction(generationHash)).thenReturn( + Promise.resolve({ response: instance(clientResponse), body: transactionInfoDto }), + ); + + let transaction = await transactionHttp.getTransaction(generationHash, TransactionSearchGroup.Confirmed).toPromise(); + + expect(transaction.type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf()); + expect(((transaction as TransferTransaction).recipientAddress as Address).plain()).to.be.equal( + Address.createFromEncoded('6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144').plain(), + ); + expect(transaction.transactionInfo?.id).to.be.equal('id'); + expect(transaction.transactionInfo?.hash).to.be.equal('hash'); + + transaction = await transactionHttp.getTransaction(generationHash, TransactionSearchGroup.Partial).toPromise(); + + expect(transaction.type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf()); + expect(((transaction as TransferTransaction).recipientAddress as Address).plain()).to.be.equal( + Address.createFromEncoded('6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144').plain(), + ); + expect(transaction.transactionInfo?.id).to.be.equal('id'); + expect(transaction.transactionInfo?.hash).to.be.equal('hash'); + + transaction = await transactionHttp.getTransaction(generationHash, TransactionSearchGroup.Unconfirmed).toPromise(); + + expect(transaction.type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf()); + expect(((transaction as TransferTransaction).recipientAddress as Address).plain()).to.be.equal( + Address.createFromEncoded('6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144').plain(), + ); + expect(transaction.transactionInfo?.id).to.be.equal('id'); + expect(transaction.transactionInfo?.hash).to.be.equal('hash'); + }); + + it('Test getTransactionsById method', async () => { + const transactionInfoDto = new TransactionInfoDTO(); + const metaDto = new TransactionMetaDTO(); + metaDto.hash = 'hash'; + metaDto.height = '1'; + metaDto.index = 0; + metaDto.merkleComponentHash = 'merkleHash'; + + const transactionDto = new TransferTransactionDTO(); + transactionDto.deadline = '1'; + transactionDto.maxFee = '1'; + transactionDto.mosaics = []; + transactionDto.network = NetworkTypeEnum.NUMBER_104; + transactionDto.recipientAddress = '6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144'; + transactionDto.type = TransactionType.TRANSFER.valueOf(); + transactionDto.version = 1; + + transactionInfoDto.id = 'id'; + transactionInfoDto.meta = metaDto; + transactionInfoDto.transaction = transactionDto; + + when(transactionRoutesApi.getTransactionsById(deepEqual({ transactionIds: [generationHash] }))).thenReturn( + Promise.resolve({ response: instance(clientResponse), body: [transactionInfoDto] }), + ); + + const transaction = await transactionHttp.getTransactionsById([generationHash]).toPromise(); + + expect(transaction.length).to.be.equal(1); + expect(transaction[0].type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf()); + expect(((transaction[0] as TransferTransaction).recipientAddress as Address).plain()).to.be.equal( + Address.createFromEncoded('6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144').plain(), + ); + expect(transaction[0].transactionInfo?.id).to.be.equal('id'); + expect(transaction[0].transactionInfo?.hash).to.be.equal('hash'); + }); + + it('Test getTransactionsById method', async () => { + const transactionInfoDto = new TransactionInfoDTO(); + const metaDto = new TransactionMetaDTO(); + metaDto.hash = 'hash'; + metaDto.height = '1'; + metaDto.index = 0; + metaDto.merkleComponentHash = 'merkleHash'; + + const transactionDto = new TransferTransactionDTO(); + transactionDto.deadline = '1'; + transactionDto.maxFee = '1'; + transactionDto.mosaics = []; + transactionDto.network = NetworkTypeEnum.NUMBER_104; + transactionDto.recipientAddress = '6026D27E1D0A26CA4E316F901E23E55C8711DB20DF300144'; + transactionDto.type = TransactionType.TRANSFER.valueOf(); + transactionDto.version = 1; + + transactionInfoDto.id = 'id'; + transactionInfoDto.meta = metaDto; + transactionInfoDto.transaction = transactionDto; + + const blockDTO = new BlockDTO(); + blockDTO.version = 1; + blockDTO.network = NetworkTypeEnum.NUMBER_152; + blockDTO.difficulty = '2'; + blockDTO.feeMultiplier = 3; + blockDTO.height = '4'; + blockDTO.previousBlockHash = '5'; + blockDTO.type = 6; + blockDTO.signerPublicKey = '81E5E7AE49998802DABC816EC10158D3A7879702FF29084C2C992CD1289877A7'; + blockDTO.timestamp = '7'; + blockDTO.beneficiaryAddress = Address.createFromPublicKey( + '81E5E7AE49998802DABC816EC10158D3A7879702FF29084C2C992CD1289877A8', + NetworkType.MIJIN_TEST, + ).encoded(); + + const blockMetaDTO = new BlockMetaDTO(); + blockMetaDTO.generationHash = 'abc'; + blockMetaDTO.hash = 'aHash'; + blockMetaDTO.numStatements = 10; + blockMetaDTO.numTransactions = 20; + blockMetaDTO.totalFee = '30'; + blockMetaDTO.stateHashSubCacheMerkleRoots = ['a', 'b', 'c']; + + const blockInfoDto = new BlockInfoDTO(); + blockInfoDto.block = blockDTO; + blockInfoDto.meta = blockMetaDTO; + + when(transactionRoutesApi.getConfirmedTransaction(generationHash)).thenReturn( + Promise.resolve({ response: instance(clientResponse), body: transactionInfoDto }), + ); + + when(transactionRoutesApi.getPartialTransaction(generationHash)).thenReturn( + Promise.resolve({ response: instance(clientResponse), body: transactionInfoDto }), + ); + when(transactionRoutesApi.getUnconfirmedTransaction(generationHash)).thenReturn( + Promise.resolve({ response: instance(clientResponse), body: transactionInfoDto }), + ); + + when(blockRoutesApi.getBlockByHeight(deepEqual(UInt64.fromUint(1).toString()))).thenReturn( + Promise.resolve({ response: instance(clientResponse), body: blockInfoDto }), + ); + + let fees = await transactionHttp.getTransactionEffectiveFee(generationHash, TransactionSearchGroup.Confirmed).toPromise(); + expect(fees).to.be.equal(483); + fees = await transactionHttp.getTransactionEffectiveFee(generationHash, TransactionSearchGroup.Unconfirmed).toPromise(); + expect(fees).to.be.equal(483); + fees = await transactionHttp.getTransactionEffectiveFee(generationHash, TransactionSearchGroup.Partial).toPromise(); + expect(fees).to.be.equal(483); + }); + + it('Test announce', async () => { + const response = new AnnounceTransactionInfoDTO(); + response.message = 'done'; + + const tx = TransferTransaction.create( + Deadline.create(), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), + [], + PlainMessage.create('Hi'), + NetworkType.MIJIN_TEST, + ); + + const signedTx = account.sign(tx, generationHash); + + when(transactionRoutesApi.announceTransaction(deepEqual(signedTx))).thenReturn( + Promise.resolve({ response: instance(clientResponse), body: response }), + ); + const announceResult = await transactionHttp.announce(signedTx).toPromise(); + + expect(announceResult.message).to.be.equal(response.message); + }); + + it('Test announceAggregateBonded', async () => { + const response = new AnnounceTransactionInfoDTO(); + response.message = 'done'; + + const tx = TransferTransaction.create( + Deadline.create(), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), + [], + PlainMessage.create('Hi'), + NetworkType.MIJIN_TEST, + ); + + const aggTx = AggregateTransaction.createBonded( + Deadline.create(), + [tx.toAggregate(account.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + + const signedTx = account.sign(aggTx, generationHash); + + when(transactionRoutesApi.announcePartialTransaction(deepEqual(signedTx))).thenReturn( + Promise.resolve({ response: instance(clientResponse), body: response }), + ); + const announceResult = await transactionHttp.announceAggregateBonded(signedTx).toPromise(); + + expect(announceResult.message).to.be.equal(response.message); + }); + + it('Test announceAggregateBonded Cosignatures', async () => { + const response = new AnnounceTransactionInfoDTO(); + response.message = 'done'; + + const cosignTx = new CosignatureSignedTransaction('parentHash', 'signature', 'signerPubKey'); + + when(transactionRoutesApi.announceCosignatureTransaction(deepEqual(cosignTx))).thenReturn( + Promise.resolve({ response: instance(clientResponse), body: response }), + ); + const announceResult = await transactionHttp.announceAggregateBondedCosignature(cosignTx).toPromise(); + + expect(announceResult.message).to.be.equal(response.message); + }); }); diff --git a/test/infrastructure/TransactionSearchCriteria.spec.ts b/test/infrastructure/TransactionSearchCriteria.spec.ts index 5d71562980..2ef122fce6 100644 --- a/test/infrastructure/TransactionSearchCriteria.spec.ts +++ b/test/infrastructure/TransactionSearchCriteria.spec.ts @@ -15,13 +15,14 @@ */ import { expect } from 'chai'; -import { Order, TransactionGroupSubsetEnum } from 'symbol-openapi-typescript-node-client'; +import { Order } from 'symbol-openapi-typescript-node-client'; import { TransactionSearchCriteria } from '../../src/infrastructure/searchCriteria/TransactionSearchCriteria'; import { TestingAccount } from '../conf/conf.spec'; import { deepEqual } from 'assert'; import { TransactionType } from '../../src/model/transaction/TransactionType'; import { UInt64 } from '../../src/model/UInt64'; import { Address } from '../../src/model/account/Address'; +import { TransactionSearchGroup } from '../../src/infrastructure/TransactionSearchGroup'; describe('TransactionSearchCriteria', () => { const account = TestingAccount; @@ -33,7 +34,7 @@ describe('TransactionSearchCriteria', () => { pageSize: 1, address: account.address, embedded: true, - group: TransactionGroupSubsetEnum.Confirmed, + group: TransactionSearchGroup.Confirmed, height: UInt64.fromUint(1), offset: '6789', recipientAddress: account.address, @@ -46,7 +47,7 @@ describe('TransactionSearchCriteria', () => { expect(criteria.pageSize).to.be.equal(1); expect(criteria.address?.plain()).to.be.equal(account.address.plain()); expect(criteria.embedded).to.be.equal(true); - expect(criteria.group).to.be.equal(TransactionGroupSubsetEnum.Confirmed); + expect(criteria.group.toString()).to.be.equal(TransactionSearchGroup.Confirmed.toString()); expect(criteria.height?.toString()).to.be.equal('1'); expect(criteria.offset).to.be.equal('6789'); expect(criteria.recipientAddress?.plain()).to.be.equal(account.address.plain()); @@ -60,7 +61,7 @@ describe('TransactionSearchCriteria', () => { pageSize: 2, address: address, embedded: false, - group: TransactionGroupSubsetEnum.Unconfirmed, + group: TransactionSearchGroup.Unconfirmed, height: UInt64.fromUint(2), offset: 'bbb', recipientAddress: address, @@ -73,7 +74,7 @@ describe('TransactionSearchCriteria', () => { expect(criteria.pageSize).to.be.equal(2); expect(criteria.address?.plain()).to.be.equal(address.plain()); expect(criteria.embedded).to.be.equal(false); - expect(criteria.group).to.be.equal(TransactionGroupSubsetEnum.Unconfirmed); + expect(criteria.group.toString()).to.be.equal(TransactionSearchGroup.Unconfirmed.toString()); expect(criteria.height?.toString()).to.be.equal('2'); expect(criteria.offset).to.be.equal('bbb'); expect(criteria.recipientAddress?.plain()).to.be.equal(address.plain()); @@ -82,12 +83,12 @@ describe('TransactionSearchCriteria', () => { }); it('should create TransactionSearchCriteria - default', () => { - const criteria: TransactionSearchCriteria = {}; + const criteria: TransactionSearchCriteria = { group: TransactionSearchGroup.Confirmed }; expect(criteria.order).to.be.undefined; expect(criteria.address).to.be.undefined; expect(criteria.embedded).to.be.undefined; - expect(criteria.group).to.be.undefined; + expect(criteria.group).to.be.equal(TransactionSearchGroup.Confirmed); expect(criteria.height).to.be.undefined; expect(criteria.offset).to.be.undefined; expect(criteria.pageNumber).to.be.undefined; diff --git a/test/infrastructure/TransactionStatusHttp.spec.ts b/test/infrastructure/TransactionStatusHttp.spec.ts new file mode 100644 index 0000000000..6a13ea1369 --- /dev/null +++ b/test/infrastructure/TransactionStatusHttp.spec.ts @@ -0,0 +1,84 @@ +/* + * Copyright 2018 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { expect } from 'chai'; +import http = require('http'); +import { + TransactionGroupEnum, + TransactionStatusDTO, + TransactionStatusEnum, + TransactionStatusRoutesApi, +} from 'symbol-openapi-typescript-node-client'; +import { deepEqual, instance, mock, when } from 'ts-mockito'; + +import { NIS2_URL } from '../conf/conf.spec'; +import { TransactionStatusHttp } from '../../src/infrastructure/TransactionStatusHttp'; + +describe('TransactionStatusHttp', () => { + let clientResponse: http.ClientResponse; + let transactionStatusRoutesApi: TransactionStatusRoutesApi; + let transactionStatusHttp: TransactionStatusHttp; + + before(() => { + transactionStatusRoutesApi = mock(); + clientResponse = mock(); + transactionStatusHttp = new TransactionStatusHttp(NIS2_URL); + (transactionStatusHttp as object)['transactionStatusRoutesApi'] = instance(transactionStatusRoutesApi); + }); + + it('Test getTransactionStatus method', async () => { + const hash = 'abc'; + const transactionStatusDTO = new TransactionStatusDTO(); + transactionStatusDTO.code = TransactionStatusEnum.FailureAccountLinkInconsistentUnlinkData; + transactionStatusDTO.deadline = '1234'; + transactionStatusDTO.hash = hash; + transactionStatusDTO.group = TransactionGroupEnum.Failed; + transactionStatusDTO.height = '567'; + + when(transactionStatusRoutesApi.getTransactionStatus(deepEqual(hash))).thenReturn( + Promise.resolve({ response: instance(clientResponse), body: transactionStatusDTO }), + ); + + const transactionStatus = await transactionStatusHttp.getTransactionStatus(hash).toPromise(); + + expect(transactionStatus.deadline.toString()).to.be.equal('1234'); + expect(transactionStatus.hash).to.be.equal(hash); + expect(transactionStatus.code).to.be.equal('Failure_AccountLink_Inconsistent_Unlink_Data'); + expect(transactionStatus.group).to.be.equal('failed'); + }); + + it('Test getTransactionsStatuses method', async () => { + const hash = 'abc'; + const transactionStatusDTO = new TransactionStatusDTO(); + transactionStatusDTO.code = TransactionStatusEnum.FailureAccountLinkInconsistentUnlinkData; + transactionStatusDTO.deadline = '1234'; + transactionStatusDTO.hash = hash; + transactionStatusDTO.group = TransactionGroupEnum.Failed; + transactionStatusDTO.height = '567'; + when(transactionStatusRoutesApi.getTransactionStatuses(deepEqual({ hashes: [hash] }))).thenReturn( + Promise.resolve({ response: instance(clientResponse), body: [transactionStatusDTO] }), + ); + + const transactionStatuses = await transactionStatusHttp.getTransactionStatuses([hash]).toPromise(); + expect(transactionStatuses.length).to.be.equal(1); + const transactionStatus = transactionStatuses[0]; + + expect(transactionStatus.deadline.toString()).to.be.equal('1234'); + expect(transactionStatus.hash).to.be.equal(hash); + expect(transactionStatus.code).to.be.equal('Failure_AccountLink_Inconsistent_Unlink_Data'); + expect(transactionStatus.group).to.be.equal('failed'); + }); +}); diff --git a/test/infrastructure/streamer/TransactionPaginationStreamer.spec.ts b/test/infrastructure/streamer/TransactionPaginationStreamer.spec.ts index 33fd27a481..f53a691ff4 100644 --- a/test/infrastructure/streamer/TransactionPaginationStreamer.spec.ts +++ b/test/infrastructure/streamer/TransactionPaginationStreamer.spec.ts @@ -18,40 +18,132 @@ import { instance, mock } from 'ts-mockito'; import { TransactionPaginationStreamer } from '../../../src/infrastructure/paginationStreamer/TransactionPaginationStreamer'; import { TransactionRepository } from '../../../src/infrastructure/TransactionRepository'; import { PaginationStreamerTestHelper } from './PaginationStreamerTestHelper'; +import { TransactionSearchGroup } from '../../../src/infrastructure/TransactionSearchGroup'; describe('TransactionPaginationStreamer', () => { it('basicMultiPageTest', () => { const transactionRepositoryMock: TransactionRepository = mock(); const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); - const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, {}); + const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { + group: TransactionSearchGroup.Confirmed, + }); return tester.basicMultiPageTest(); }); it('basicSinglePageTest', () => { const transactionRepositoryMock: TransactionRepository = mock(); const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); - const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, {}); + const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { + group: TransactionSearchGroup.Confirmed, + }); return tester.basicSinglePageTest(); }); it('limitToTwoPages', () => { const transactionRepositoryMock: TransactionRepository = mock(); const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); - const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, {}); + const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { + group: TransactionSearchGroup.Confirmed, + }); return tester.limitToTwoPages(); }); it('multipageWithLimit', () => { const transactionRepositoryMock: TransactionRepository = mock(); const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); - const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, {}); + const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { + group: TransactionSearchGroup.Confirmed, + }); return tester.multipageWithLimit(); }); it('limitToThreePages', () => { const transactionRepositoryMock: TransactionRepository = mock(); const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); - const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, {}); + const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { + group: TransactionSearchGroup.Confirmed, + }); + return tester.limitToThreePages(); + }); + + it('basicMultiPageTest', () => { + const transactionRepositoryMock: TransactionRepository = mock(); + const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); + const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { + group: TransactionSearchGroup.Confirmed, + }); + return tester.basicMultiPageTest(); + }); + + it('basicSinglePageTest', () => { + const transactionRepositoryMock: TransactionRepository = mock(); + const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); + const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { + group: TransactionSearchGroup.Unconfirmed, + }); + return tester.basicSinglePageTest(); + }); + + it('limitToTwoPages', () => { + const transactionRepositoryMock: TransactionRepository = mock(); + const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); + const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { + group: TransactionSearchGroup.Unconfirmed, + }); + return tester.limitToTwoPages(); + }); + + it('multipageWithLimit', () => { + const transactionRepositoryMock: TransactionRepository = mock(); + const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); + const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { + group: TransactionSearchGroup.Unconfirmed, + }); + return tester.multipageWithLimit(); + }); + + it('limitToThreePages', () => { + const transactionRepositoryMock: TransactionRepository = mock(); + const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); + const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { + group: TransactionSearchGroup.Unconfirmed, + }); + return tester.limitToThreePages(); + }); + + it('basicSinglePageTest', () => { + const transactionRepositoryMock: TransactionRepository = mock(); + const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); + const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { + group: TransactionSearchGroup.Partial, + }); + return tester.basicSinglePageTest(); + }); + + it('limitToTwoPages', () => { + const transactionRepositoryMock: TransactionRepository = mock(); + const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); + const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { + group: TransactionSearchGroup.Partial, + }); + return tester.limitToTwoPages(); + }); + + it('multipageWithLimit', () => { + const transactionRepositoryMock: TransactionRepository = mock(); + const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); + const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { + group: TransactionSearchGroup.Unconfirmed, + }); + return tester.multipageWithLimit(); + }); + + it('limitToThreePages', () => { + const transactionRepositoryMock: TransactionRepository = mock(); + const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); + const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { + group: TransactionSearchGroup.Partial, + }); return tester.limitToThreePages(); }); }); From dda8b4de6ecf1fbd9b95f485505ab5fd8da534f3 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 15 Jun 2020 18:56:28 +0100 Subject: [PATCH 15/22] Fixed unit test --- e2e/infrastructure/MultisigAccounts.spect.ts | 23 -------------------- 1 file changed, 23 deletions(-) diff --git a/e2e/infrastructure/MultisigAccounts.spect.ts b/e2e/infrastructure/MultisigAccounts.spect.ts index c0973a0910..5541cf0b0b 100644 --- a/e2e/infrastructure/MultisigAccounts.spect.ts +++ b/e2e/infrastructure/MultisigAccounts.spect.ts @@ -13,10 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Crypto } from '../../src/core/crypto'; -import { Convert } from '../../src/core/format'; -import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; -import { TransactionRepository } from '../../src/infrastructure/TransactionRepository'; import { Account } from '../../src/model/account/Account'; import { NetworkType } from '../../src/model/network/NetworkType'; import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction'; @@ -26,35 +22,21 @@ import { IntegrationTestHelper } from './IntegrationTestHelper'; describe('MultisigAccounts', () => { const helper = new IntegrationTestHelper(); - let account: Account; - let account2: Account; - let account3: Account; let multisigAccount: Account; let cosignAccount1: Account; let cosignAccount2: Account; let cosignAccount3: Account; - let namespaceRepository: NamespaceRepository; let generationHash: string; let networkType: NetworkType; - let harvestingAccount: Account; - let transactionRepository: TransactionRepository; - let votingKey: string; before(() => { return helper.start().then(() => { - account = helper.account; - account2 = helper.account2; - account3 = helper.account3; multisigAccount = helper.multisigAccount; cosignAccount1 = helper.cosignAccount1; cosignAccount2 = helper.cosignAccount2; cosignAccount3 = helper.cosignAccount3; - harvestingAccount = helper.harvestingAccount; generationHash = helper.generationHash; networkType = helper.networkType; - votingKey = Convert.uint8ToHex(Crypto.randomBytes(48)); - namespaceRepository = helper.repositoryFactory.createNamespaceRepository(); - transactionRepository = helper.repositoryFactory.createTransactionRepository(); }); }); before(() => { @@ -67,9 +49,6 @@ describe('MultisigAccounts', () => { describe('Setup test multisig account', () => { it('Announce MultisigAccountModificationTransaction', () => { - - console.log(`http://localhost:3000/account/${multisigAccount.address.plain()}`); - console.log(`http://localhost:3000/account/${multisigAccount.address.plain()}/multisig`); const modifyMultisigAccountTransaction = MultisigAccountModificationTransaction.create( Deadline.create(), 2, @@ -92,8 +71,6 @@ describe('MultisigAccounts', () => { [cosignAccount1, cosignAccount2, cosignAccount3], generationHash, ); - - console.log(signedTransaction.hash); return helper.announce(signedTransaction); }); }); From b165bd50b1574fad51f083504780efb4ff61950a Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 16 Jun 2020 12:57:55 +0100 Subject: [PATCH 16/22] Added some unit tests --- e2e/infrastructure/Listener.spec.ts | 2 - test/infrastructure/NamespaceHttp.spec.ts | 239 ++++++++++++++++++ .../TransactionPaginationStreamer.spec.ts | 15 -- 3 files changed, 239 insertions(+), 17 deletions(-) create mode 100644 test/infrastructure/NamespaceHttp.spec.ts delete mode 100644 test/infrastructure/TransactionPaginationStreamer.spec.ts diff --git a/e2e/infrastructure/Listener.spec.ts b/e2e/infrastructure/Listener.spec.ts index 3d71676a1d..6e9db3ca81 100644 --- a/e2e/infrastructure/Listener.spec.ts +++ b/e2e/infrastructure/Listener.spec.ts @@ -261,7 +261,6 @@ describe('Listener', () => { .search(criteria) .pipe( mergeMap((page) => { - console.log('Partial Search', page.data); return transactionRepository.getTransaction( page.data[0].transactionInfo?.hash!, TransactionSearchGroup.Partial, @@ -269,7 +268,6 @@ describe('Listener', () => { }), ) .subscribe((transactions) => { - console.log('getTransaction', transactions); const transactionToCosign = transactions as AggregateTransaction; const cosignatureTransaction = CosignatureTransaction.create(transactionToCosign); const cosignatureSignedTransaction = cosignAccount2.signCosignatureTransaction(cosignatureTransaction); diff --git a/test/infrastructure/NamespaceHttp.spec.ts b/test/infrastructure/NamespaceHttp.spec.ts new file mode 100644 index 0000000000..fb4a701a10 --- /dev/null +++ b/test/infrastructure/NamespaceHttp.spec.ts @@ -0,0 +1,239 @@ +/* + * Copyright 2020 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { expect } from 'chai'; +import * as http from 'http'; +import { + NamespaceRoutesApi, + AccountNamesDTO, + AccountsNamesDTO, + MosaicsNamesDTO, + MosaicNamesDTO, + NamespaceMetaDTO, + AliasTypeEnum, + NamespaceNameDTO, + NamespacesInfoDTO, + AliasDTO, +} from 'symbol-openapi-typescript-node-client'; +import { instance, mock, reset, when, deepEqual } from 'ts-mockito'; +import { DtoMapping } from '../../src/core/utils/DtoMapping'; +import { NetworkType } from '../../src/model/network/NetworkType'; +import { MosaicId } from '../../src/model/mosaic/MosaicId'; +import { PublicAccount } from '../../src/model/account/PublicAccount'; +import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; +import { NamespaceHttp } from '../../src/infrastructure/NamespaceHttp'; +import { NamespaceId } from '../../src/model/namespace/NamespaceId'; +import { NamespaceDTO } from 'symbol-openapi-typescript-node-client'; +import { NamespaceInfoDTO } from 'symbol-openapi-typescript-node-client'; +import { NamespaceInfo } from '../../src/model/namespace/NamespaceInfo'; + +describe('NamespaceHttp', () => { + const publicAccount = PublicAccount.createFromPublicKey( + '9801508C58666C746F471538E43002B85B1CD542F9874B2861183919BA8787B6', + NetworkType.MIJIN_TEST, + ); + const address = publicAccount.address; + const mosaicId = new MosaicId('941299B2B7E1291C'); + const namespaceId = new NamespaceId('testnamespace'); + const namespaceMetaDto = new NamespaceMetaDTO(); + namespaceMetaDto.active = true; + namespaceMetaDto.id = '1'; + namespaceMetaDto.index = 0; + + const namespaceDto = new NamespaceDTO(); + const aliasDtoAddress = new AliasDTO(); + aliasDtoAddress.address = address.encoded(); + aliasDtoAddress.type = AliasTypeEnum.NUMBER_2; + + namespaceDto.alias = aliasDtoAddress; + namespaceDto.depth = 1; + namespaceDto.endHeight = '12'; + namespaceDto.level0 = namespaceId.toHex(); + namespaceDto.ownerAddress = address.encoded(); + namespaceDto.parentId = namespaceId.toHex(); + namespaceDto.registrationType = 0; + namespaceDto.startHeight = '10'; + + const namespaceInfoDto = new NamespaceInfoDTO(); + namespaceInfoDto.meta = namespaceMetaDto; + namespaceInfoDto.namespace = namespaceDto; + + const aliasDtoMosaic = new AliasDTO(); + aliasDtoMosaic.mosaicId = mosaicId.toHex(); + aliasDtoMosaic.type = AliasTypeEnum.NUMBER_1; + const namespaceDtoMosaic = new NamespaceDTO(); + namespaceDtoMosaic.alias = aliasDtoMosaic; + namespaceDtoMosaic.depth = 1; + namespaceDtoMosaic.endHeight = '12'; + namespaceDtoMosaic.level0 = namespaceId.toHex(); + namespaceDtoMosaic.ownerAddress = address.encoded(); + namespaceDtoMosaic.parentId = namespaceId.toHex(); + namespaceDtoMosaic.registrationType = 0; + namespaceDtoMosaic.startHeight = '10'; + + const namespaceInfoDtoMosaic = new NamespaceInfoDTO(); + namespaceInfoDtoMosaic.meta = namespaceMetaDto; + namespaceInfoDtoMosaic.namespace = namespaceDtoMosaic; + + const url = 'http://someHost'; + const response: http.IncomingMessage = mock(); + const namespaceRoutesApi: NamespaceRoutesApi = mock(); + const namespaceRepository: NamespaceRepository = DtoMapping.assign(new NamespaceHttp(url, NetworkType.MIJIN_TEST), { + namespaceRoutesApi: instance(namespaceRoutesApi), + }); + + function assertNamespaceInfo(namespace: NamespaceInfo): void { + expect(namespace.active).to.be.true; + expect(namespace.alias.address?.plain()).to.be.equal(address.plain()); + expect(namespace.alias.mosaicId).to.be.undefined; + expect(namespace.alias.type).to.be.equal(2); + expect(namespace.depth).to.be.equal(1); + expect(namespace.endHeight.toString()).to.be.equal('12'); + expect(namespace.startHeight.toString()).to.be.equal('10'); + expect(namespace.metaId).to.be.equal('1'); + expect(namespace.index).to.be.equal(0); + expect(namespace.levels[0].toHex()).to.be.equal(namespaceId.toHex()); + expect(namespace.isRoot()).to.be.true; + expect(namespace.ownerAddress.plain()).to.be.equal(address.plain()); + } + + before(() => { + reset(response); + reset(namespaceRoutesApi); + }); + + it('getAccountNames', async () => { + const accountsNamesDto = new AccountsNamesDTO(); + const accountNamesDto = new AccountNamesDTO(); + accountNamesDto.address = address.encoded(); + accountNamesDto.names = ['name1', 'name2']; + accountsNamesDto.accountNames = [accountNamesDto]; + + when(namespaceRoutesApi.getAccountsNames(deepEqual({ addresses: [address.plain()] }))).thenReturn( + Promise.resolve({ response, body: accountsNamesDto }), + ); + const accountNames = await namespaceRepository.getAccountsNames([address]).toPromise(); + expect(accountNames.length).to.be.greaterThan(0); + expect(accountNames[0].address.plain()).to.be.equal(address.plain()); + expect(accountNames[0].names.map((n) => n.name).join(',')).to.be.equal(['name1', 'name2'].join(',')); + }); + + it('getMosaicNames', async () => { + const mosaicsNamesDto = new MosaicsNamesDTO(); + const mosaicNamesDto = new MosaicNamesDTO(); + mosaicNamesDto.mosaicId = mosaicId.toHex(); + mosaicNamesDto.names = ['name1', 'name2']; + mosaicsNamesDto.mosaicNames = [mosaicNamesDto]; + + when(namespaceRoutesApi.getMosaicsNames(deepEqual({ mosaicIds: [mosaicId.toHex()] }))).thenReturn( + Promise.resolve({ response, body: mosaicsNamesDto }), + ); + const names = await namespaceRepository.getMosaicsNames([mosaicId]).toPromise(); + expect(names.length).to.be.greaterThan(0); + expect(names[0].mosaicId.toHex()).to.be.equal(mosaicId.toHex()); + expect(names[0].names.map((n) => n.name).join(',')).to.be.equal(['name1', 'name2'].join(',')); + }); + + it('getNamespace', async () => { + when(namespaceRoutesApi.getNamespace(deepEqual(namespaceId.toHex()))).thenReturn( + Promise.resolve({ response, body: namespaceInfoDto }), + ); + const namespace = await namespaceRepository.getNamespace(namespaceId).toPromise(); + assertNamespaceInfo(namespace); + }); + + it('getNamespaceName', async () => { + const namespaceNameParent = new NamespaceNameDTO(); + namespaceNameParent.id = namespaceId.toHex(); + namespaceNameParent.name = 'parent'; + + const namespaceNameChild = new NamespaceNameDTO(); + namespaceNameChild.id = new NamespaceId('child').toHex(); + namespaceNameChild.name = 'child'; + namespaceNameChild.parentId = namespaceId.toHex(); + + when(namespaceRoutesApi.getNamespacesNames(deepEqual({ namespaceIds: [namespaceId.toHex()] }))).thenReturn( + Promise.resolve({ response, body: [namespaceNameParent, namespaceNameChild] }), + ); + const namespace = await namespaceRepository.getNamespacesName([namespaceId]).toPromise(); + expect(namespace.length).to.be.equal(2); + expect(namespace[0].name).to.be.equal('parent'); + expect(namespace[0].namespaceId.toHex()).to.be.equal(namespaceId.toHex()); + expect(namespace[0].parentId).to.be.undefined; + expect(namespace[1].name).to.be.equal('child'); + expect(namespace[1].parentId!.toHex()).to.be.equal(namespaceId.toHex()); + expect(namespace[1].namespaceId.toHex()).to.be.equal(new NamespaceId('child').toHex()); + }); + + it('getNamespaceFromAccount', async () => { + const namespacesInfoDto = new NamespacesInfoDTO(); + namespacesInfoDto.namespaces = [namespaceInfoDto]; + when(namespaceRoutesApi.getNamespacesFromAccount(deepEqual(address.plain()), undefined, undefined, undefined)).thenReturn( + Promise.resolve({ response, body: namespacesInfoDto }), + ); + const namespaces = await namespaceRepository.getNamespacesFromAccount(address).toPromise(); + + assertNamespaceInfo(namespaces[0]); + }); + + it('getNamespaceFromAccounts', async () => { + const namespacesInfoDto = new NamespacesInfoDTO(); + namespacesInfoDto.namespaces = [namespaceInfoDto]; + when(namespaceRoutesApi.getNamespacesFromAccounts(deepEqual(deepEqual({ addresses: [address.plain()] })))).thenReturn( + Promise.resolve({ response, body: namespacesInfoDto }), + ); + const namespaces = await namespaceRepository.getNamespacesFromAccount(address).toPromise(); + + assertNamespaceInfo(namespaces[0]); + }); + + it('getLinkedAddress', async () => { + when(namespaceRoutesApi.getNamespace(deepEqual(namespaceId.toHex()))).thenReturn( + Promise.resolve({ response, body: namespaceInfoDto }), + ); + const namespaces = await namespaceRepository.getLinkedAddress(namespaceId).toPromise(); + + expect(namespaces?.plain()).to.be.equal(address.plain()); + }); + + it('getLinkedMosaicId', async () => { + when(namespaceRoutesApi.getNamespace(deepEqual(namespaceId.toHex()))).thenReturn( + Promise.resolve({ response, body: namespaceInfoDtoMosaic }), + ); + const namespaces = await namespaceRepository.getLinkedMosaicId(namespaceId).toPromise(); + + expect(namespaces?.toHex()).to.be.equal(mosaicId.toHex()); + }); + + it('getLinkedMosaicId - Error', async () => { + when(namespaceRoutesApi.getNamespace(deepEqual(namespaceId.toHex()))).thenReturn( + Promise.resolve({ response, body: namespaceInfoDto }), + ); + await namespaceRepository + .getLinkedMosaicId(namespaceId) + .toPromise() + .catch((error) => expect(error).not.to.be.undefined); + }); + + it('getLinkedAddress - Error', async () => { + when(namespaceRoutesApi.getNamespace(deepEqual(namespaceId.toHex()))).thenReturn( + Promise.resolve({ response, body: namespaceInfoDtoMosaic }), + ); + await namespaceRepository + .getLinkedAddress(namespaceId) + .toPromise() + .catch((error) => expect(error).not.to.be.undefined); + }); +}); diff --git a/test/infrastructure/TransactionPaginationStreamer.spec.ts b/test/infrastructure/TransactionPaginationStreamer.spec.ts deleted file mode 100644 index 821c177da0..0000000000 --- a/test/infrastructure/TransactionPaginationStreamer.spec.ts +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright 2020 NEM - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ From fb0f09e984149719ca56fcd7329c93609d385f83 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 16 Jun 2020 17:11:49 +0100 Subject: [PATCH 17/22] - Renamed TransactionSearchGroup -> TransactionGroup - Removed transactionGroup from getEffectiveFees - Other PR comments fixed --- e2e/infrastructure/Listener.spec.ts | 11 +++---- e2e/infrastructure/MosaicHttp.spec.ts | 4 +-- ...unts.spect.ts => MultisigAccounts.spec.ts} | 0 e2e/infrastructure/TransactionHttp.spec.ts | 12 ++++---- e2e/service/BlockService.spec.ts | 4 +-- ...tionSearchGroup.ts => TransactionGroup.ts} | 7 +++-- src/infrastructure/TransactionHttp.ts | 23 +++++++------- src/infrastructure/TransactionRepository.ts | 7 ++--- .../TransactionSearchCriteria.ts | 4 +-- test/infrastructure/TransactionHttp.spec.ts | 28 +++++------------ .../TransactionSearchCriteria.spec.ts | 14 ++++----- .../TransactionPaginationStreamer.spec.ts | 30 +++++++++---------- 12 files changed, 64 insertions(+), 80 deletions(-) rename e2e/infrastructure/{MultisigAccounts.spect.ts => MultisigAccounts.spec.ts} (100%) rename src/infrastructure/{TransactionSearchGroup.ts => TransactionGroup.ts} (57%) diff --git a/e2e/infrastructure/Listener.spec.ts b/e2e/infrastructure/Listener.spec.ts index 6e9db3ca81..1bf0f004ca 100644 --- a/e2e/infrastructure/Listener.spec.ts +++ b/e2e/infrastructure/Listener.spec.ts @@ -33,7 +33,7 @@ import { UInt64 } from '../../src/model/UInt64'; import { Mosaic } from '../../src/model/mosaic/Mosaic'; import { CosignatureTransaction } from '../../src/model/transaction/CosignatureTransaction'; import { UnresolvedMosaicId } from '../../src/model/mosaic/UnresolvedMosaicId'; -import { TransactionSearchGroup } from '../../src/infrastructure/TransactionSearchGroup'; +import { TransactionGroup } from '../../src/infrastructure/TransactionGroup'; describe('Listener', () => { const helper = new IntegrationTestHelper(); @@ -254,17 +254,14 @@ describe('Listener', () => { helper.listener.aggregateBondedAdded(cosignAccount1.address).subscribe(() => { const criteria: TransactionSearchCriteria = { address: cosignAccount1.address, - group: TransactionSearchGroup.Partial, + group: TransactionGroup.Partial, embedded: true, }; transactionRepository .search(criteria) .pipe( mergeMap((page) => { - return transactionRepository.getTransaction( - page.data[0].transactionInfo?.hash!, - TransactionSearchGroup.Partial, - ); + return transactionRepository.getTransaction(page.data[0].transactionInfo?.hash!, TransactionGroup.Partial); }), ) .subscribe((transactions) => { @@ -300,7 +297,7 @@ describe('Listener', () => { helper.listener.aggregateBondedAdded(cosignAccount1.address).subscribe(() => { const criteria: TransactionSearchCriteria = { address: cosignAccount1.publicAccount.address, - group: TransactionSearchGroup.Partial, + group: TransactionGroup.Partial, }; transactionRepository.search(criteria).subscribe((transactions) => { const transactionToCosign = transactions.data[0] as AggregateTransaction; diff --git a/e2e/infrastructure/MosaicHttp.spec.ts b/e2e/infrastructure/MosaicHttp.spec.ts index 5bdfac5a4b..55e88d9701 100644 --- a/e2e/infrastructure/MosaicHttp.spec.ts +++ b/e2e/infrastructure/MosaicHttp.spec.ts @@ -32,7 +32,7 @@ import { IntegrationTestHelper } from './IntegrationTestHelper'; import { MosaicPaginationStreamer } from '../../src/infrastructure/paginationStreamer/MosaicPaginationStreamer'; import { toArray, take } from 'rxjs/operators'; import { deepEqual } from 'assert'; -import { TransactionSearchGroup } from '../../src/infrastructure/TransactionSearchGroup'; +import { TransactionGroup } from '../../src/infrastructure/TransactionGroup'; describe('MosaicHttp', () => { let mosaicId: MosaicId; @@ -91,7 +91,7 @@ describe('MosaicHttp', () => { const savedTransaction = (await helper.repositoryFactory .createTransactionRepository() - .getTransaction(signedTransaction.hash, TransactionSearchGroup.Confirmed) + .getTransaction(signedTransaction.hash, TransactionGroup.Confirmed) .toPromise()) as MosaicDefinitionTransaction; expect(mosaicDefinitionTransaction.nonce.toHex()).to.be.equal(savedTransaction.nonce.toHex()); expect(mosaicDefinitionTransaction.nonce).to.deep.equal(savedTransaction.nonce); diff --git a/e2e/infrastructure/MultisigAccounts.spect.ts b/e2e/infrastructure/MultisigAccounts.spec.ts similarity index 100% rename from e2e/infrastructure/MultisigAccounts.spect.ts rename to e2e/infrastructure/MultisigAccounts.spec.ts diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 7fdca9ba04..c2674396a8 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -74,7 +74,7 @@ import { deepEqual } from 'assert'; import { AddressRestrictionFlag } from '../../src/model/restriction/AddressRestrictionFlag'; import { MosaicRestrictionFlag } from '../../src/model/restriction/MosaicRestrictionFlag'; import { OperationRestrictionFlag } from '../../src/model/restriction/OperationRestrictionFlag'; -import { TransactionSearchGroup } from '../../src/infrastructure/TransactionSearchGroup'; +import { TransactionGroup } from '../../src/infrastructure/TransactionGroup'; import { TransactionStatusRepository } from '../../src/infrastructure/TransactionStatusRepository'; // eslint-disable-next-line @typescript-eslint/no-var-requires @@ -1388,13 +1388,13 @@ describe('TransactionHttp', () => { describe('getTransaction', () => { it('should return transaction info given transactionHash', async () => { - const transaction = await transactionRepository.getTransaction(transactionHash, TransactionSearchGroup.Confirmed).toPromise(); + const transaction = await transactionRepository.getTransaction(transactionHash, TransactionGroup.Confirmed).toPromise(); expect(transaction.transactionInfo!.hash).to.be.equal(transactionHash); transactionId = transaction.transactionInfo?.id!; }); it('should return transaction info given transactionId', async () => { - const transaction = await transactionRepository.getTransaction(transactionId, TransactionSearchGroup.Confirmed).toPromise(); + const transaction = await transactionRepository.getTransaction(transactionId, TransactionGroup.Confirmed).toPromise(); expect(transaction.transactionInfo!.hash).to.be.equal(transactionHash); expect(transaction.transactionInfo!.id).to.be.equal(transactionId); }); @@ -1482,9 +1482,7 @@ describe('TransactionHttp', () => { describe('getTransactionEffectiveFee', () => { it('should return effective paid fee given transactionHash', async () => { - const effectiveFee = await transactionRepository - .getTransactionEffectiveFee(transactionHash, TransactionSearchGroup.Confirmed) - .toPromise(); + const effectiveFee = await transactionRepository.getTransactionEffectiveFee(transactionHash).toPromise(); expect(effectiveFee).to.not.be.undefined; expect(effectiveFee).not.to.be.equal(0); }); @@ -1510,7 +1508,7 @@ describe('TransactionHttp', () => { .search({ address: account.address, pageSize: 10 } as TransactionSearchCriteria) .toPromise(); const transactions = await streamer - .search({ group: TransactionSearchGroup.Confirmed, address: account.address, pageSize: 10 }) + .search({ group: TransactionGroup.Confirmed, address: account.address, pageSize: 10 }) .pipe(take(10), toArray()) .toPromise(); expect(transactions.length).to.be.greaterThan(0); diff --git a/e2e/service/BlockService.spec.ts b/e2e/service/BlockService.spec.ts index 35eb6cffa7..30e46dac73 100644 --- a/e2e/service/BlockService.spec.ts +++ b/e2e/service/BlockService.spec.ts @@ -26,7 +26,7 @@ import { TransferTransaction } from '../../src/model/transaction/TransferTransac import { UInt64 } from '../../src/model/UInt64'; import { BlockService } from '../../src/service/BlockService'; import { IntegrationTestHelper } from '../infrastructure/IntegrationTestHelper'; -import { TransactionSearchGroup } from '../../src/infrastructure/TransactionSearchGroup'; +import { TransactionGroup } from '../../src/infrastructure/TransactionGroup'; describe('BlockService', () => { const helper = new IntegrationTestHelper(); @@ -88,7 +88,7 @@ describe('BlockService', () => { describe('Validate transansaction', () => { it('call block service', async () => { - const transaction = await transactionRepository.getTransaction(transactionHash, TransactionSearchGroup.Confirmed).toPromise(); + const transaction = await transactionRepository.getTransaction(transactionHash, TransactionGroup.Confirmed).toPromise(); const transactionInfo = transaction.transactionInfo; if (transactionInfo && transactionInfo.height !== undefined) { const validationResult = await blockService.validateTransactionInBlock(transactionHash, transactionInfo.height).toPromise(); diff --git a/src/infrastructure/TransactionSearchGroup.ts b/src/infrastructure/TransactionGroup.ts similarity index 57% rename from src/infrastructure/TransactionSearchGroup.ts rename to src/infrastructure/TransactionGroup.ts index 6c3488ed99..77d17b2581 100644 --- a/src/infrastructure/TransactionSearchGroup.ts +++ b/src/infrastructure/TransactionGroup.ts @@ -15,9 +15,12 @@ */ /** - * A transaction could be classified in the following groups: * Unconfirmed: The transaction reached the P2P network. At this point, it is not guaranteed that the transaction will be included in a block. * Confirmed: The transaction is included in a block. * Partial: The transaction requires to be cosigned by other transaction participants in order to be included in a block. * Failed: The transaction did not pass the network validation, and it was rejected. + * A transaction could be classified in the following groups: + * - Unconfirmed: The transaction reached the P2P network. At this point, it is not guaranteed that the transaction will be included in a block. + * -Confirmed: The transaction is included in a block. + * - Partial: The transaction requires to be cosigned by other transaction participants in order to be included in a block. */ -export enum TransactionSearchGroup { +export enum TransactionGroup { Unconfirmed = 'unconfirmed', Confirmed = 'confirmed', Partial = 'partial', diff --git a/src/infrastructure/TransactionHttp.ts b/src/infrastructure/TransactionHttp.ts index 72497d1257..a03ffca5a7 100644 --- a/src/infrastructure/TransactionHttp.ts +++ b/src/infrastructure/TransactionHttp.ts @@ -35,7 +35,7 @@ import { CreateTransactionFromDTO } from './transaction/CreateTransactionFromDTO import { TransactionRepository } from './TransactionRepository'; import { TransactionSearchCriteria } from './searchCriteria/TransactionSearchCriteria'; import { Page } from './Page'; -import { TransactionSearchGroup } from './TransactionSearchGroup'; +import { TransactionGroup } from './TransactionGroup'; import http = require('http'); /** @@ -74,7 +74,7 @@ export class TransactionHttp extends Http implements TransactionRepository { * @param transactionGroup - Transaction group. * @returns Observable */ - public getTransaction(transactionId: string, transactionGroup: TransactionSearchGroup): Observable { + public getTransaction(transactionId: string, transactionGroup: TransactionGroup): Observable { return observableFrom(this.getTransactionByGroup(transactionId, transactionGroup)).pipe( map(({ body }) => CreateTransactionFromDTO(body)), catchError((error) => throwError(this.errorHandling(error))), @@ -147,11 +147,10 @@ export class TransactionHttp extends Http implements TransactionRepository { /** * Gets a transaction's effective paid fee * @param transactionId - Transaction id or hash. - * @param transactionGroup - Transaction group. * @returns Observable */ - public getTransactionEffectiveFee(transactionId: string, transactionGroup: TransactionSearchGroup): Observable { - return observableFrom(this.getTransactionByGroup(transactionId, transactionGroup)).pipe( + public getTransactionEffectiveFee(transactionId: string): Observable { + return observableFrom(this.getTransactionByGroup(transactionId, TransactionGroup.Confirmed)).pipe( mergeMap(({ body }) => { // parse transaction to take advantage of `size` getter overload const transaction = CreateTransactionFromDTO(body); @@ -195,17 +194,17 @@ export class TransactionHttp extends Http implements TransactionRepository { */ private getTransactionByGroup( transactionId: string, - transactionGroup: TransactionSearchGroup, + transactionGroup: TransactionGroup, ): Promise<{ response: http.ClientResponse; body: TransactionInfoDTO; }> { switch (transactionGroup) { - case TransactionSearchGroup.Confirmed: + case TransactionGroup.Confirmed: return this.transactionRoutesApi.getConfirmedTransaction(transactionId); - case TransactionSearchGroup.Unconfirmed: + case TransactionGroup.Unconfirmed: return this.transactionRoutesApi.getUnconfirmedTransaction(transactionId); - case TransactionSearchGroup.Partial: + case TransactionGroup.Partial: return this.transactionRoutesApi.getPartialTransaction(transactionId); } } @@ -224,7 +223,7 @@ export class TransactionHttp extends Http implements TransactionRepository { body: TransactionPage; }> { switch (criteria.group) { - case TransactionSearchGroup.Confirmed: + case TransactionGroup.Confirmed: return this.transactionRoutesApi.searchConfirmedTransactions( criteria.address?.plain(), criteria.recipientAddress?.plain(), @@ -237,7 +236,7 @@ export class TransactionHttp extends Http implements TransactionRepository { criteria.offset, criteria.order, ); - case TransactionSearchGroup.Unconfirmed: + case TransactionGroup.Unconfirmed: return this.transactionRoutesApi.searchUnconfirmedTransactions( criteria.address?.plain(), criteria.recipientAddress?.plain(), @@ -250,7 +249,7 @@ export class TransactionHttp extends Http implements TransactionRepository { criteria.offset, criteria.order, ); - case TransactionSearchGroup.Partial: + case TransactionGroup.Partial: return this.transactionRoutesApi.searchPartialTransactions( criteria.address?.plain(), criteria.recipientAddress?.plain(), diff --git a/src/infrastructure/TransactionRepository.ts b/src/infrastructure/TransactionRepository.ts index 64b596a8ea..b5f1702bf3 100644 --- a/src/infrastructure/TransactionRepository.ts +++ b/src/infrastructure/TransactionRepository.ts @@ -21,7 +21,7 @@ import { Transaction } from '../model/transaction/Transaction'; import { TransactionAnnounceResponse } from '../model/transaction/TransactionAnnounceResponse'; import { TransactionSearchCriteria } from './searchCriteria/TransactionSearchCriteria'; import { Searcher } from './paginationStreamer/Searcher'; -import { TransactionSearchGroup } from './TransactionSearchGroup'; +import { TransactionGroup } from './TransactionGroup'; /** * Transaction interface repository. @@ -35,7 +35,7 @@ export interface TransactionRepository extends Searcher */ - getTransaction(transactionId: string, transactionGroup: TransactionSearchGroup): Observable; + getTransaction(transactionId: string, transactionGroup: TransactionGroup): Observable; /** * Gets an array of transactions for different transaction ids @@ -47,10 +47,9 @@ export interface TransactionRepository extends Searcher */ - getTransactionEffectiveFee(transactionId: string, transactionGroup: TransactionSearchGroup): Observable; + getTransactionEffectiveFee(transactionId: string): Observable; /** * Send a signed transaction diff --git a/src/infrastructure/searchCriteria/TransactionSearchCriteria.ts b/src/infrastructure/searchCriteria/TransactionSearchCriteria.ts index a64d890f6f..32a1e829a7 100644 --- a/src/infrastructure/searchCriteria/TransactionSearchCriteria.ts +++ b/src/infrastructure/searchCriteria/TransactionSearchCriteria.ts @@ -18,7 +18,7 @@ import { SearchCriteria } from './SearchCriteria'; import { Address } from '../../model/account/Address'; import { UInt64 } from '../../model/UInt64'; import { TransactionType } from '../../model/transaction/TransactionType'; -import { TransactionSearchGroup } from '../TransactionSearchGroup'; +import { TransactionGroup } from '../TransactionGroup'; /** * Defines the params used to search transactions. With this criteria, you can sort and filter @@ -28,7 +28,7 @@ export interface TransactionSearchCriteria extends SearchCriteria { /** * The group of transaction (optional, default is confirmed) */ - group: TransactionSearchGroup; + group: TransactionGroup; /** * Filter by address involved in the transaction. * diff --git a/test/infrastructure/TransactionHttp.spec.ts b/test/infrastructure/TransactionHttp.spec.ts index 17884e3e4d..99c6aa26fd 100644 --- a/test/infrastructure/TransactionHttp.spec.ts +++ b/test/infrastructure/TransactionHttp.spec.ts @@ -41,7 +41,7 @@ import { Deadline } from '../../src/model/transaction/Deadline'; import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; import { NIS2_URL, TestingAccount } from '../conf/conf.spec'; import { TransactionType } from '../../src/model/transaction/TransactionType'; -import { TransactionSearchGroup } from '../../src/infrastructure/TransactionSearchGroup'; +import { TransactionGroup } from '../../src/infrastructure/TransactionGroup'; import { UInt64 } from '../../src/model/UInt64'; import { CosignatureSignedTransaction } from '../../src/model/transaction/CosignatureSignedTransaction'; @@ -161,7 +161,7 @@ describe('TransactionHttp', () => { ), ).thenReturn(Promise.resolve({ response: instance(clientResponse), body: page })); - let transactions = await transactionHttp.search({ group: TransactionSearchGroup.Confirmed, address: account.address }).toPromise(); + let transactions = await transactionHttp.search({ group: TransactionGroup.Confirmed, address: account.address }).toPromise(); expect(transactions.data.length).to.be.equal(1); expect(transactions.data[0].type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf()); @@ -176,7 +176,7 @@ describe('TransactionHttp', () => { expect(transactions.totalEntries).to.be.equal(1); expect(transactions.totalPages).to.be.equal(1); - transactions = await transactionHttp.search({ group: TransactionSearchGroup.Unconfirmed, address: account.address }).toPromise(); + transactions = await transactionHttp.search({ group: TransactionGroup.Unconfirmed, address: account.address }).toPromise(); expect(transactions.data.length).to.be.equal(1); expect(transactions.data[0].type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf()); @@ -191,7 +191,7 @@ describe('TransactionHttp', () => { expect(transactions.totalEntries).to.be.equal(1); expect(transactions.totalPages).to.be.equal(1); - transactions = await transactionHttp.search({ group: TransactionSearchGroup.Partial, address: account.address }).toPromise(); + transactions = await transactionHttp.search({ group: TransactionGroup.Partial, address: account.address }).toPromise(); expect(transactions.data.length).to.be.equal(1); expect(transactions.data[0].type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf()); @@ -239,7 +239,7 @@ describe('TransactionHttp', () => { Promise.resolve({ response: instance(clientResponse), body: transactionInfoDto }), ); - let transaction = await transactionHttp.getTransaction(generationHash, TransactionSearchGroup.Confirmed).toPromise(); + let transaction = await transactionHttp.getTransaction(generationHash, TransactionGroup.Confirmed).toPromise(); expect(transaction.type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf()); expect(((transaction as TransferTransaction).recipientAddress as Address).plain()).to.be.equal( @@ -248,7 +248,7 @@ describe('TransactionHttp', () => { expect(transaction.transactionInfo?.id).to.be.equal('id'); expect(transaction.transactionInfo?.hash).to.be.equal('hash'); - transaction = await transactionHttp.getTransaction(generationHash, TransactionSearchGroup.Partial).toPromise(); + transaction = await transactionHttp.getTransaction(generationHash, TransactionGroup.Partial).toPromise(); expect(transaction.type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf()); expect(((transaction as TransferTransaction).recipientAddress as Address).plain()).to.be.equal( @@ -257,7 +257,7 @@ describe('TransactionHttp', () => { expect(transaction.transactionInfo?.id).to.be.equal('id'); expect(transaction.transactionInfo?.hash).to.be.equal('hash'); - transaction = await transactionHttp.getTransaction(generationHash, TransactionSearchGroup.Unconfirmed).toPromise(); + transaction = await transactionHttp.getTransaction(generationHash, TransactionGroup.Unconfirmed).toPromise(); expect(transaction.type.valueOf()).to.be.equal(TransactionType.TRANSFER.valueOf()); expect(((transaction as TransferTransaction).recipientAddress as Address).plain()).to.be.equal( @@ -354,23 +354,11 @@ describe('TransactionHttp', () => { when(transactionRoutesApi.getConfirmedTransaction(generationHash)).thenReturn( Promise.resolve({ response: instance(clientResponse), body: transactionInfoDto }), ); - - when(transactionRoutesApi.getPartialTransaction(generationHash)).thenReturn( - Promise.resolve({ response: instance(clientResponse), body: transactionInfoDto }), - ); - when(transactionRoutesApi.getUnconfirmedTransaction(generationHash)).thenReturn( - Promise.resolve({ response: instance(clientResponse), body: transactionInfoDto }), - ); - when(blockRoutesApi.getBlockByHeight(deepEqual(UInt64.fromUint(1).toString()))).thenReturn( Promise.resolve({ response: instance(clientResponse), body: blockInfoDto }), ); - let fees = await transactionHttp.getTransactionEffectiveFee(generationHash, TransactionSearchGroup.Confirmed).toPromise(); - expect(fees).to.be.equal(483); - fees = await transactionHttp.getTransactionEffectiveFee(generationHash, TransactionSearchGroup.Unconfirmed).toPromise(); - expect(fees).to.be.equal(483); - fees = await transactionHttp.getTransactionEffectiveFee(generationHash, TransactionSearchGroup.Partial).toPromise(); + const fees = await transactionHttp.getTransactionEffectiveFee(generationHash).toPromise(); expect(fees).to.be.equal(483); }); diff --git a/test/infrastructure/TransactionSearchCriteria.spec.ts b/test/infrastructure/TransactionSearchCriteria.spec.ts index 2ef122fce6..791fb585f5 100644 --- a/test/infrastructure/TransactionSearchCriteria.spec.ts +++ b/test/infrastructure/TransactionSearchCriteria.spec.ts @@ -22,7 +22,7 @@ import { deepEqual } from 'assert'; import { TransactionType } from '../../src/model/transaction/TransactionType'; import { UInt64 } from '../../src/model/UInt64'; import { Address } from '../../src/model/account/Address'; -import { TransactionSearchGroup } from '../../src/infrastructure/TransactionSearchGroup'; +import { TransactionGroup } from '../../src/infrastructure/TransactionGroup'; describe('TransactionSearchCriteria', () => { const account = TestingAccount; @@ -34,7 +34,7 @@ describe('TransactionSearchCriteria', () => { pageSize: 1, address: account.address, embedded: true, - group: TransactionSearchGroup.Confirmed, + group: TransactionGroup.Confirmed, height: UInt64.fromUint(1), offset: '6789', recipientAddress: account.address, @@ -47,7 +47,7 @@ describe('TransactionSearchCriteria', () => { expect(criteria.pageSize).to.be.equal(1); expect(criteria.address?.plain()).to.be.equal(account.address.plain()); expect(criteria.embedded).to.be.equal(true); - expect(criteria.group.toString()).to.be.equal(TransactionSearchGroup.Confirmed.toString()); + expect(criteria.group.toString()).to.be.equal(TransactionGroup.Confirmed.toString()); expect(criteria.height?.toString()).to.be.equal('1'); expect(criteria.offset).to.be.equal('6789'); expect(criteria.recipientAddress?.plain()).to.be.equal(account.address.plain()); @@ -61,7 +61,7 @@ describe('TransactionSearchCriteria', () => { pageSize: 2, address: address, embedded: false, - group: TransactionSearchGroup.Unconfirmed, + group: TransactionGroup.Unconfirmed, height: UInt64.fromUint(2), offset: 'bbb', recipientAddress: address, @@ -74,7 +74,7 @@ describe('TransactionSearchCriteria', () => { expect(criteria.pageSize).to.be.equal(2); expect(criteria.address?.plain()).to.be.equal(address.plain()); expect(criteria.embedded).to.be.equal(false); - expect(criteria.group.toString()).to.be.equal(TransactionSearchGroup.Unconfirmed.toString()); + expect(criteria.group.toString()).to.be.equal(TransactionGroup.Unconfirmed.toString()); expect(criteria.height?.toString()).to.be.equal('2'); expect(criteria.offset).to.be.equal('bbb'); expect(criteria.recipientAddress?.plain()).to.be.equal(address.plain()); @@ -83,12 +83,12 @@ describe('TransactionSearchCriteria', () => { }); it('should create TransactionSearchCriteria - default', () => { - const criteria: TransactionSearchCriteria = { group: TransactionSearchGroup.Confirmed }; + const criteria: TransactionSearchCriteria = { group: TransactionGroup.Confirmed }; expect(criteria.order).to.be.undefined; expect(criteria.address).to.be.undefined; expect(criteria.embedded).to.be.undefined; - expect(criteria.group).to.be.equal(TransactionSearchGroup.Confirmed); + expect(criteria.group).to.be.equal(TransactionGroup.Confirmed); expect(criteria.height).to.be.undefined; expect(criteria.offset).to.be.undefined; expect(criteria.pageNumber).to.be.undefined; diff --git a/test/infrastructure/streamer/TransactionPaginationStreamer.spec.ts b/test/infrastructure/streamer/TransactionPaginationStreamer.spec.ts index f53a691ff4..c44b62120e 100644 --- a/test/infrastructure/streamer/TransactionPaginationStreamer.spec.ts +++ b/test/infrastructure/streamer/TransactionPaginationStreamer.spec.ts @@ -18,14 +18,14 @@ import { instance, mock } from 'ts-mockito'; import { TransactionPaginationStreamer } from '../../../src/infrastructure/paginationStreamer/TransactionPaginationStreamer'; import { TransactionRepository } from '../../../src/infrastructure/TransactionRepository'; import { PaginationStreamerTestHelper } from './PaginationStreamerTestHelper'; -import { TransactionSearchGroup } from '../../../src/infrastructure/TransactionSearchGroup'; +import { TransactionGroup } from '../../../src/infrastructure/TransactionGroup'; describe('TransactionPaginationStreamer', () => { it('basicMultiPageTest', () => { const transactionRepositoryMock: TransactionRepository = mock(); const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { - group: TransactionSearchGroup.Confirmed, + group: TransactionGroup.Confirmed, }); return tester.basicMultiPageTest(); }); @@ -34,7 +34,7 @@ describe('TransactionPaginationStreamer', () => { const transactionRepositoryMock: TransactionRepository = mock(); const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { - group: TransactionSearchGroup.Confirmed, + group: TransactionGroup.Confirmed, }); return tester.basicSinglePageTest(); }); @@ -43,7 +43,7 @@ describe('TransactionPaginationStreamer', () => { const transactionRepositoryMock: TransactionRepository = mock(); const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { - group: TransactionSearchGroup.Confirmed, + group: TransactionGroup.Confirmed, }); return tester.limitToTwoPages(); }); @@ -52,7 +52,7 @@ describe('TransactionPaginationStreamer', () => { const transactionRepositoryMock: TransactionRepository = mock(); const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { - group: TransactionSearchGroup.Confirmed, + group: TransactionGroup.Confirmed, }); return tester.multipageWithLimit(); }); @@ -61,7 +61,7 @@ describe('TransactionPaginationStreamer', () => { const transactionRepositoryMock: TransactionRepository = mock(); const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { - group: TransactionSearchGroup.Confirmed, + group: TransactionGroup.Confirmed, }); return tester.limitToThreePages(); }); @@ -70,7 +70,7 @@ describe('TransactionPaginationStreamer', () => { const transactionRepositoryMock: TransactionRepository = mock(); const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { - group: TransactionSearchGroup.Confirmed, + group: TransactionGroup.Confirmed, }); return tester.basicMultiPageTest(); }); @@ -79,7 +79,7 @@ describe('TransactionPaginationStreamer', () => { const transactionRepositoryMock: TransactionRepository = mock(); const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { - group: TransactionSearchGroup.Unconfirmed, + group: TransactionGroup.Unconfirmed, }); return tester.basicSinglePageTest(); }); @@ -88,7 +88,7 @@ describe('TransactionPaginationStreamer', () => { const transactionRepositoryMock: TransactionRepository = mock(); const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { - group: TransactionSearchGroup.Unconfirmed, + group: TransactionGroup.Unconfirmed, }); return tester.limitToTwoPages(); }); @@ -97,7 +97,7 @@ describe('TransactionPaginationStreamer', () => { const transactionRepositoryMock: TransactionRepository = mock(); const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { - group: TransactionSearchGroup.Unconfirmed, + group: TransactionGroup.Unconfirmed, }); return tester.multipageWithLimit(); }); @@ -106,7 +106,7 @@ describe('TransactionPaginationStreamer', () => { const transactionRepositoryMock: TransactionRepository = mock(); const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { - group: TransactionSearchGroup.Unconfirmed, + group: TransactionGroup.Unconfirmed, }); return tester.limitToThreePages(); }); @@ -115,7 +115,7 @@ describe('TransactionPaginationStreamer', () => { const transactionRepositoryMock: TransactionRepository = mock(); const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { - group: TransactionSearchGroup.Partial, + group: TransactionGroup.Partial, }); return tester.basicSinglePageTest(); }); @@ -124,7 +124,7 @@ describe('TransactionPaginationStreamer', () => { const transactionRepositoryMock: TransactionRepository = mock(); const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { - group: TransactionSearchGroup.Partial, + group: TransactionGroup.Partial, }); return tester.limitToTwoPages(); }); @@ -133,7 +133,7 @@ describe('TransactionPaginationStreamer', () => { const transactionRepositoryMock: TransactionRepository = mock(); const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { - group: TransactionSearchGroup.Unconfirmed, + group: TransactionGroup.Unconfirmed, }); return tester.multipageWithLimit(); }); @@ -142,7 +142,7 @@ describe('TransactionPaginationStreamer', () => { const transactionRepositoryMock: TransactionRepository = mock(); const streamer = new TransactionPaginationStreamer(instance(transactionRepositoryMock)); const tester = new PaginationStreamerTestHelper(streamer, mock(), transactionRepositoryMock, { - group: TransactionSearchGroup.Partial, + group: TransactionGroup.Partial, }); return tester.limitToThreePages(); }); From 5acda1feb5e3e2ee8ff3724645df392476e03420 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 16 Jun 2020 17:14:28 +0100 Subject: [PATCH 18/22] Fixed doc --- src/infrastructure/searchCriteria/BlockSearchCriteria.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/infrastructure/searchCriteria/BlockSearchCriteria.ts b/src/infrastructure/searchCriteria/BlockSearchCriteria.ts index ee7945235a..4015d11a31 100644 --- a/src/infrastructure/searchCriteria/BlockSearchCriteria.ts +++ b/src/infrastructure/searchCriteria/BlockSearchCriteria.ts @@ -28,7 +28,7 @@ export interface BlockSearchCriteria extends SearchCriteria { signerPublicKey?: string; /** - * beneficiary public key. (optional) + * beneficiary address. (optional) */ beneficiaryAddress?: string; From 5dc74c6dbf524eec04bede021063ec05bb21e113 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 16 Jun 2020 21:59:38 +0100 Subject: [PATCH 19/22] Improved test coverage --- src/infrastructure/TransactionHttp.ts | 5 +- .../receipt/CreateReceiptFromDTO.ts | 4 +- test/infrastructure/ReceiptHttp.spec.ts | 110 ++++++++ .../RestrictionAccountHttp.spec.ts | 102 +++++++ .../RestrictionMosaicHttp.spec.ts | 179 ++++++++++++ test/infrastructure/TransactionHttp.spec.ts | 106 ++++++- .../TransactionStatusHttp.spec.ts | 16 ++ .../receipt/CreateReceiptFromDTO.spec.ts | 258 +++++++++++++++++- 8 files changed, 771 insertions(+), 9 deletions(-) create mode 100644 test/infrastructure/ReceiptHttp.spec.ts create mode 100644 test/infrastructure/RestrictionAccountHttp.spec.ts create mode 100644 test/infrastructure/RestrictionMosaicHttp.spec.ts diff --git a/src/infrastructure/TransactionHttp.ts b/src/infrastructure/TransactionHttp.ts index a03ffca5a7..be3ba02863 100644 --- a/src/infrastructure/TransactionHttp.ts +++ b/src/infrastructure/TransactionHttp.ts @@ -164,12 +164,9 @@ export class TransactionHttp extends Http implements TransactionRepository { // effective_fee = feeMultiplier x transaction::size return blockDTO.block.feeMultiplier * transaction.size; }), - catchError((error) => throwError(this.errorHandling(error))), ); }), - catchError((err) => { - return throwError(err); - }), + catchError((error) => throwError(this.errorHandling(error))), ); } diff --git a/src/infrastructure/receipt/CreateReceiptFromDTO.ts b/src/infrastructure/receipt/CreateReceiptFromDTO.ts index 9340e15f2b..3086f55351 100644 --- a/src/infrastructure/receipt/CreateReceiptFromDTO.ts +++ b/src/infrastructure/receipt/CreateReceiptFromDTO.ts @@ -60,7 +60,7 @@ const extractUnresolvedAddress = (unresolvedAddress: any): UnresolvedAddress => * @returns {ResolutionStatement} * @constructor */ -const createResolutionStatement = (statementDTO, resolutionType): ResolutionStatement => { +const createResolutionStatement = (statementDTO, resolutionType: ResolutionType): ResolutionStatement => { switch (resolutionType) { case ResolutionType.Address: return new ResolutionStatement( @@ -86,8 +86,6 @@ const createResolutionStatement = (statementDTO, resolutionType): ResolutionStat ); }), ); - default: - throw new Error('Resolution type invalid'); } }; diff --git a/test/infrastructure/ReceiptHttp.spec.ts b/test/infrastructure/ReceiptHttp.spec.ts new file mode 100644 index 0000000000..031713a03f --- /dev/null +++ b/test/infrastructure/ReceiptHttp.spec.ts @@ -0,0 +1,110 @@ +/* + * Copyright 2020 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { expect } from 'chai'; +import * as http from 'http'; +import { + AccountRestrictionsDTO, + AccountRestrictionFlagsEnum, + AccountRestrictionsInfoDTO, + AccountRestrictionDTO, + ReceiptRoutesApi, + StatementsDTO, + MerkleProofInfoDTO, + MerklePathItemDTO, + PositionEnum, +} from 'symbol-openapi-typescript-node-client'; +import { instance, mock, reset, when } from 'ts-mockito'; +import { DtoMapping } from '../../src/core/utils/DtoMapping'; +import { NetworkType } from '../../src/model/network/NetworkType'; +import { PublicAccount } from '../../src/model/account/PublicAccount'; +import { ReceiptHttp } from '../../src/infrastructure/ReceiptHttp'; +import { UInt64 } from '../../src/model/model'; + +describe('ReceiptHttp', () => { + const publicAccount = PublicAccount.createFromPublicKey( + '9801508C58666C746F471538E43002B85B1CD542F9874B2861183919BA8787B6', + NetworkType.MIJIN_TEST, + ); + const address = publicAccount.address; + const url = 'http://someHost'; + const response: http.IncomingMessage = mock(); + const receiptRoutesApi: ReceiptRoutesApi = mock(); + const receiptRepository = DtoMapping.assign(new ReceiptHttp(url, NetworkType.MIJIN_TEST), { + receiptRoutesApi: instance(receiptRoutesApi), + }); + + const restrictionInfo = new AccountRestrictionsInfoDTO(); + const restrictionsDto = new AccountRestrictionsDTO(); + const restriction = new AccountRestrictionDTO(); + restriction.restrictionFlags = AccountRestrictionFlagsEnum.NUMBER_1; + restriction.values = [address.encoded()]; + restrictionsDto.restrictions = [restriction]; + restrictionsDto.address = address.encoded(); + + restrictionInfo.accountRestrictions = restrictionsDto; + + before(() => { + reset(response); + reset(receiptRoutesApi); + }); + + it('getBlockReceipt', async () => { + const statementDto = new StatementsDTO(); + statementDto.addressResolutionStatements = []; + statementDto.transactionStatements = []; + statementDto.mosaicResolutionStatements = []; + + when(receiptRoutesApi.getBlockReceipts('1')).thenReturn(Promise.resolve({ response, body: statementDto })); + + const statement = await receiptRepository.getBlockReceipts(UInt64.fromUint(1)).toPromise(); + expect(statement).to.be.not.null; + expect(statement.addressResolutionStatements.length).to.be.equal(0); + expect(statement.mosaicResolutionStatements.length).to.be.equal(0); + expect(statement.transactionStatements.length).to.be.equal(0); + }); + + it('getMerkleReceipts', async () => { + const merkleProofInfoDto = new MerkleProofInfoDTO(); + const merklePathDto = new MerklePathItemDTO(); + merklePathDto.hash = 'merkleHash'; + merklePathDto.position = PositionEnum.Left; + merkleProofInfoDto.merklePath = [merklePathDto]; + + when(receiptRoutesApi.getMerkleReceipts('1', 'Hash')).thenReturn(Promise.resolve({ response, body: merkleProofInfoDto })); + + const proof = await receiptRepository.getMerkleReceipts(UInt64.fromUint(1), 'Hash').toPromise(); + expect(proof).to.be.not.null; + expect(proof.merklePath!.length).to.be.greaterThan(0); + expect(proof.merklePath![0].hash).to.be.equal('merkleHash'); + expect(proof.merklePath![0].position!.toString()).to.be.equal('left'); + }); + + it('getBlockReceipt - Error', async () => { + when(receiptRoutesApi.getBlockReceipts('1')).thenReject(new Error('Mocked Error')); + await receiptRepository + .getBlockReceipts(UInt64.fromUint(1)) + .toPromise() + .catch((error) => expect(error).not.to.be.undefined); + }); + + it('getMerkleReceipts - Error', async () => { + when(receiptRoutesApi.getMerkleReceipts('1', 'Hash')).thenReject(new Error('Mocked Error')); + await receiptRepository + .getMerkleReceipts(UInt64.fromUint(1), 'Hash') + .toPromise() + .catch((error) => expect(error).not.to.be.undefined); + }); +}); diff --git a/test/infrastructure/RestrictionAccountHttp.spec.ts b/test/infrastructure/RestrictionAccountHttp.spec.ts new file mode 100644 index 0000000000..7a7758dc9c --- /dev/null +++ b/test/infrastructure/RestrictionAccountHttp.spec.ts @@ -0,0 +1,102 @@ +/* + * Copyright 2020 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { expect } from 'chai'; +import * as http from 'http'; +import { + AccountRestrictionsDTO, + AccountRestrictionFlagsEnum, + AccountRestrictionsInfoDTO, + AccountRestrictionDTO, +} from 'symbol-openapi-typescript-node-client'; +import { instance, mock, reset, when, deepEqual } from 'ts-mockito'; +import { DtoMapping } from '../../src/core/utils/DtoMapping'; +import { NetworkType } from '../../src/model/network/NetworkType'; +import { RestrictionAccountRoutesApi } from 'symbol-openapi-typescript-node-client'; +import { PublicAccount } from '../../src/model/account/PublicAccount'; +import { RestrictionAccountHttp } from '../../src/infrastructure/RestrictionAccountHttp'; +import { Address } from '../../src/model/account/Address'; +import { AddressRestrictionFlag } from '../../src/model/restriction/AddressRestrictionFlag'; + +describe('RestrictionAccountHttp', () => { + const publicAccount = PublicAccount.createFromPublicKey( + '9801508C58666C746F471538E43002B85B1CD542F9874B2861183919BA8787B6', + NetworkType.MIJIN_TEST, + ); + const address = publicAccount.address; + const url = 'http://someHost'; + const response: http.IncomingMessage = mock(); + const restrictionAccountRoutesApi: RestrictionAccountRoutesApi = mock(); + const restrictionAccountRepository = DtoMapping.assign(new RestrictionAccountHttp(url), { + restrictionAccountRoutesApi: instance(restrictionAccountRoutesApi), + }); + + const restrictionInfo = new AccountRestrictionsInfoDTO(); + const restrictionsDto = new AccountRestrictionsDTO(); + const restriction = new AccountRestrictionDTO(); + restriction.restrictionFlags = AccountRestrictionFlagsEnum.NUMBER_1; + restriction.values = [address.encoded()]; + restrictionsDto.restrictions = [restriction]; + restrictionsDto.address = address.encoded(); + + restrictionInfo.accountRestrictions = restrictionsDto; + + before(() => { + reset(response); + reset(restrictionAccountRoutesApi); + }); + + it('getAccountRestrictions', async () => { + when(restrictionAccountRoutesApi.getAccountRestrictions(deepEqual(address.plain()))).thenReturn( + Promise.resolve({ response, body: restrictionInfo }), + ); + + const restrictions = await restrictionAccountRepository.getAccountRestrictions(address).toPromise(); + expect(restrictions).to.be.not.null; + expect(restrictions.length).to.be.greaterThan(0); + expect(restrictions[0].restrictionFlags).to.be.equals(AddressRestrictionFlag.AllowIncomingAddress); + expect((restrictions[0].values[0] as Address).plain()).to.be.equals(address.plain()); + }); + + it('getAccountRestrictionsFromAccounts', async () => { + when(restrictionAccountRoutesApi.getAccountRestrictionsFromAccounts(deepEqual({ addresses: [address.plain()] }))).thenReturn( + Promise.resolve({ response, body: [restrictionInfo] }), + ); + + const restrictions = await restrictionAccountRepository.getAccountRestrictions(address).toPromise(); + expect(restrictions).to.be.not.null; + expect(restrictions.length).to.be.greaterThan(0); + expect(restrictions[0].restrictionFlags).to.be.equals(AddressRestrictionFlag.AllowIncomingAddress); + expect((restrictions[0].values[0] as Address).plain()).to.be.equals(address.plain()); + }); + + it('getAccountRestrictions - Error', async () => { + when(restrictionAccountRoutesApi.getAccountRestrictions(deepEqual(address.plain()))).thenReject(new Error('Mocked Error')); + await restrictionAccountRepository + .getAccountRestrictions(address) + .toPromise() + .catch((error) => expect(error).not.to.be.undefined); + }); + + it('getAccountsRestrictions - Error', async () => { + when(restrictionAccountRoutesApi.getAccountRestrictionsFromAccounts(deepEqual({ addresses: [address.plain()] }))).thenReject( + new Error('Mocked Error'), + ); + await restrictionAccountRepository + .getAccountRestrictions(address) + .toPromise() + .catch((error) => expect(error).not.to.be.undefined); + }); +}); diff --git a/test/infrastructure/RestrictionMosaicHttp.spec.ts b/test/infrastructure/RestrictionMosaicHttp.spec.ts new file mode 100644 index 0000000000..261b57d5b6 --- /dev/null +++ b/test/infrastructure/RestrictionMosaicHttp.spec.ts @@ -0,0 +1,179 @@ +/* + * Copyright 2020 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { expect } from 'chai'; +import * as http from 'http'; +import { + RestrictionMosaicRoutesApi, + MosaicAddressRestrictionDTO, + MosaicAddressRestrictionEntryWrapperDTO, + MosaicAddressRestrictionEntryDTO, + MosaicRestrictionEntryTypeEnum, + MosaicGlobalRestrictionDTO, + MosaicGlobalRestrictionEntryDTO, + MosaicGlobalRestrictionEntryWrapperDTO, + MosaicGlobalRestrictionEntryRestrictionDTO, + MosaicRestrictionTypeEnum, +} from 'symbol-openapi-typescript-node-client'; +import { instance, mock, reset, when, deepEqual } from 'ts-mockito'; +import { DtoMapping } from '../../src/core/utils/DtoMapping'; +import { NetworkType } from '../../src/model/network/NetworkType'; +import { PublicAccount } from '../../src/model/account/PublicAccount'; +import { RestrictionMosaicHttp } from '../../src/infrastructure/RestrictionMosaicHttp'; +import { MosaicId } from '../../src/model/mosaic/MosaicId'; + +describe('RestrictionMosaicHttp', () => { + const publicAccount = PublicAccount.createFromPublicKey( + '9801508C58666C746F471538E43002B85B1CD542F9874B2861183919BA8787B6', + NetworkType.MIJIN_TEST, + ); + const address = publicAccount.address; + const mosaicId = new MosaicId('941299B2B7E1291C'); + const url = 'http://someHost'; + const response: http.IncomingMessage = mock(); + const restrictionMosaicRoutesApi: RestrictionMosaicRoutesApi = mock(); + const restrictionMosaicRepository = DtoMapping.assign(new RestrictionMosaicHttp(url), { + restrictionMosaicRoutesApi: instance(restrictionMosaicRoutesApi), + }); + + const mosaicAddressRestrictionDto = new MosaicAddressRestrictionDTO(); + const mosaicAddressRestrictionEntryWrapperDto = new MosaicAddressRestrictionEntryWrapperDTO(); + const mosaicAddressRestrictionEntryDto = new MosaicAddressRestrictionEntryDTO(); + + mosaicAddressRestrictionEntryDto.key = 'key'; + mosaicAddressRestrictionEntryDto.value = 'value'; + + mosaicAddressRestrictionEntryWrapperDto.compositeHash = 'hash'; + mosaicAddressRestrictionEntryWrapperDto.entryType = MosaicRestrictionEntryTypeEnum.NUMBER_0; + mosaicAddressRestrictionEntryWrapperDto.mosaicId = mosaicId.toHex(); + mosaicAddressRestrictionEntryWrapperDto.targetAddress = address.encoded(); + mosaicAddressRestrictionEntryWrapperDto.restrictions = [mosaicAddressRestrictionEntryDto]; + + mosaicAddressRestrictionDto.mosaicRestrictionEntry = mosaicAddressRestrictionEntryWrapperDto; + + const mosaicGlobalRestrictionDto = new MosaicGlobalRestrictionDTO(); + const mosaicGlobalRestrictionEntryWrapperDto = new MosaicGlobalRestrictionEntryWrapperDTO(); + const mosaicGlobalRestrictionEntryDto = new MosaicGlobalRestrictionEntryDTO(); + const mosaicGlobalRestrictionEntryRestrictionDto = new MosaicGlobalRestrictionEntryRestrictionDTO(); + mosaicGlobalRestrictionEntryRestrictionDto.referenceMosaicId = mosaicId.toHex(); + mosaicGlobalRestrictionEntryRestrictionDto.restrictionType = MosaicRestrictionTypeEnum.NUMBER_0; + mosaicGlobalRestrictionEntryRestrictionDto.restrictionValue = 'value'; + mosaicGlobalRestrictionEntryDto.key = 'key'; + mosaicGlobalRestrictionEntryDto.restriction = mosaicGlobalRestrictionEntryRestrictionDto; + + mosaicGlobalRestrictionEntryWrapperDto.compositeHash = 'hash'; + mosaicGlobalRestrictionEntryWrapperDto.entryType = MosaicRestrictionEntryTypeEnum.NUMBER_0; + mosaicGlobalRestrictionEntryWrapperDto.mosaicId = mosaicId.toHex(); + mosaicGlobalRestrictionEntryWrapperDto.restrictions = [mosaicGlobalRestrictionEntryDto]; + + mosaicGlobalRestrictionDto.mosaicRestrictionEntry = mosaicGlobalRestrictionEntryWrapperDto; + + before(() => { + reset(response); + reset(restrictionMosaicRoutesApi); + }); + + it('getMosaicAddressRestriction', async () => { + when(restrictionMosaicRoutesApi.getMosaicAddressRestriction(mosaicId.toHex(), address.plain())).thenReturn( + Promise.resolve({ response, body: mosaicAddressRestrictionDto }), + ); + + const restrictions = await restrictionMosaicRepository.getMosaicAddressRestriction(mosaicId, address).toPromise(); + expect(restrictions).to.be.not.null; + expect(restrictions.compositeHash).to.be.equal('hash'); + expect(restrictions.entryType.valueOf()).to.be.equal(0); + expect(restrictions.mosaicId.toHex()).to.be.equal(mosaicId.toHex()); + expect(restrictions.targetAddress.plain()).to.be.equal(address.plain()); + expect(restrictions.restrictions.get('key')).not.to.be.undefined; + }); + + it('getMosaicAddressRestrictions', async () => { + when( + restrictionMosaicRoutesApi.getMosaicAddressRestrictions(mosaicId.toHex(), deepEqual({ addresses: [address.plain()] })), + ).thenReturn(Promise.resolve({ response, body: [mosaicAddressRestrictionDto] })); + + const restrictions = await restrictionMosaicRepository.getMosaicAddressRestrictions(mosaicId, [address]).toPromise(); + expect(restrictions).to.be.not.null; + expect(restrictions[0].compositeHash).to.be.equal('hash'); + expect(restrictions[0].entryType.valueOf()).to.be.equal(0); + expect(restrictions[0].mosaicId.toHex()).to.be.equal(mosaicId.toHex()); + expect(restrictions[0].targetAddress.plain()).to.be.equal(address.plain()); + expect(restrictions[0].restrictions.get('key')).not.to.be.undefined; + }); + + it('getMosaicGlobalRestriction', async () => { + when(restrictionMosaicRoutesApi.getMosaicGlobalRestriction(mosaicId.toHex())).thenReturn( + Promise.resolve({ response, body: mosaicGlobalRestrictionDto }), + ); + + const restrictions = await restrictionMosaicRepository.getMosaicGlobalRestriction(mosaicId).toPromise(); + expect(restrictions).to.be.not.null; + expect(restrictions.compositeHash).to.be.equal('hash'); + expect(restrictions.entryType.valueOf()).to.be.equal(0); + expect(restrictions.mosaicId.toHex()).to.be.equal(mosaicId.toHex()); + expect(restrictions.restrictions.get('key')).not.to.be.undefined; + }); + + it('getMosaicGlobalRestrictions', async () => { + when(restrictionMosaicRoutesApi.getMosaicGlobalRestrictions(deepEqual({ mosaicIds: [mosaicId.toHex()] }))).thenReturn( + Promise.resolve({ response, body: [mosaicGlobalRestrictionDto] }), + ); + + const restrictions = await restrictionMosaicRepository.getMosaicGlobalRestrictions([mosaicId]).toPromise(); + expect(restrictions).to.be.not.null; + expect(restrictions[0].compositeHash).to.be.equal('hash'); + expect(restrictions[0].entryType.valueOf()).to.be.equal(0); + expect(restrictions[0].mosaicId.toHex()).to.be.equal(mosaicId.toHex()); + expect(restrictions[0].restrictions.get('key')).not.to.be.undefined; + }); + + it('getMosaicAddressRestriction - Error', async () => { + when(restrictionMosaicRoutesApi.getMosaicAddressRestriction(mosaicId.toHex(), address.plain())).thenReject( + new Error('Mocked Error'), + ); + await restrictionMosaicRepository + .getMosaicAddressRestriction(mosaicId, address) + .toPromise() + .catch((error) => expect(error).not.to.be.undefined); + }); + + it('getMosaicAddressRestrictions - Error', async () => { + when( + restrictionMosaicRoutesApi.getMosaicAddressRestrictions(mosaicId.toHex(), deepEqual({ addresses: [address.plain()] })), + ).thenReject(new Error('Mocked Error')); + await restrictionMosaicRepository + .getMosaicAddressRestrictions(mosaicId, [address]) + .toPromise() + .catch((error) => expect(error).not.to.be.undefined); + }); + + it('getMosaicGlobalRestriction - Error', async () => { + when(restrictionMosaicRoutesApi.getMosaicGlobalRestriction(mosaicId.toHex())).thenReject(new Error('Mocked Error')); + await restrictionMosaicRepository + .getMosaicGlobalRestriction(mosaicId) + .toPromise() + .catch((error) => expect(error).not.to.be.undefined); + }); + + it('getMosaicGlobalRestriction - Error', async () => { + when(restrictionMosaicRoutesApi.getMosaicGlobalRestrictions(deepEqual({ mosaicIds: [mosaicId.toHex()] }))).thenReject( + new Error('Mocked Error'), + ); + await restrictionMosaicRepository + .getMosaicGlobalRestrictions([mosaicId]) + .toPromise() + .catch((error) => expect(error).not.to.be.undefined); + }); +}); diff --git a/test/infrastructure/TransactionHttp.spec.ts b/test/infrastructure/TransactionHttp.spec.ts index 99c6aa26fd..663c4cbcc2 100644 --- a/test/infrastructure/TransactionHttp.spec.ts +++ b/test/infrastructure/TransactionHttp.spec.ts @@ -303,7 +303,7 @@ describe('TransactionHttp', () => { expect(transaction[0].transactionInfo?.hash).to.be.equal('hash'); }); - it('Test getTransactionsById method', async () => { + it('Test getEffectiveFees method', async () => { const transactionInfoDto = new TransactionInfoDTO(); const metaDto = new TransactionMetaDTO(); metaDto.hash = 'hash'; @@ -426,4 +426,108 @@ describe('TransactionHttp', () => { expect(announceResult.message).to.be.equal(response.message); }); + + it('getTransaction - Error', async () => { + when(transactionRoutesApi.getConfirmedTransaction(generationHash)).thenReject(new Error('Mocked Error')); + await transactionHttp + .getTransaction(generationHash, TransactionGroup.Confirmed) + .toPromise() + .catch((error) => expect(error).not.to.be.undefined); + }); + + it('getTransactionById - Error', async () => { + when(transactionRoutesApi.getTransactionsById(deepEqual({ transactionIds: [generationHash] }))).thenReject( + new Error('Mocked Error'), + ); + await transactionHttp + .getTransactionsById([generationHash]) + .toPromise() + .catch((error) => expect(error).not.to.be.undefined); + }); + + it('announceAggregateBonded - Error', async () => { + const cosignTx = new CosignatureSignedTransaction('parentHash', 'signature', 'signerPubKey'); + when(transactionRoutesApi.announceCosignatureTransaction(deepEqual(cosignTx))).thenReject(new Error('Mocked Error')); + await transactionHttp + .announceAggregateBondedCosignature(cosignTx) + .toPromise() + .catch((error) => expect(error).not.to.be.undefined); + }); + + it('announceAggregateBonded Cosignatures - Error', async () => { + const cosignTx = new CosignatureSignedTransaction('parentHash', 'signature', 'signerPubKey'); + + when(transactionRoutesApi.announceCosignatureTransaction(deepEqual(cosignTx))).thenReject(new Error('Mocked Error')); + await transactionHttp + .announceAggregateBondedCosignature(cosignTx) + .toPromise() + .catch((error) => expect(error).not.to.be.undefined); + }); + + it('Test getEffectiveFees method', async () => { + when(transactionRoutesApi.getConfirmedTransaction(generationHash)).thenReject(new Error('Mocked Error')); + await transactionHttp + .getTransactionEffectiveFee(generationHash) + .toPromise() + .catch((error) => expect(error).not.to.be.undefined); + }); + + it('getEffectiveFees - Error', async () => { + when(blockRoutesApi.getBlockByHeight(deepEqual(UInt64.fromUint(1).toString()))).thenReject(new Error('Mocked Error')); + await transactionHttp + .getTransactionEffectiveFee(generationHash) + .toPromise() + .catch((error) => expect(error).not.to.be.undefined); + }); + + it('announce - Error', async () => { + const response = new AnnounceTransactionInfoDTO(); + response.message = 'done'; + + const tx = TransferTransaction.create( + Deadline.create(), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), + [], + PlainMessage.create('Hi'), + NetworkType.MIJIN_TEST, + ); + + const signedTx = account.sign(tx, generationHash); + + when(transactionRoutesApi.announceTransaction(deepEqual(signedTx))).thenReject(new Error('Mocked Error')); + await transactionHttp + .announce(signedTx) + .toPromise() + .catch((error) => expect(error).not.to.be.undefined); + }); + + it('announce - Error', async () => { + const response = new AnnounceTransactionInfoDTO(); + response.message = 'done'; + + const tx = TransferTransaction.create( + Deadline.create(), + Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'), + [], + PlainMessage.create('Hi'), + NetworkType.MIJIN_TEST, + ); + + const aggTx = AggregateTransaction.createBonded( + Deadline.create(), + [tx.toAggregate(account.publicAccount)], + NetworkType.MIJIN_TEST, + [], + ); + const signedTx = account.sign(aggTx, generationHash); + + when(transactionRoutesApi.announceTransaction(deepEqual(signedTx))).thenReturn( + Promise.resolve({ response: instance(clientResponse), body: response }), + ); + try { + await transactionHttp.announce(signedTx).toPromise(); + } catch (error) { + expect(error).not.to.be.undefined; + } + }); }); diff --git a/test/infrastructure/TransactionStatusHttp.spec.ts b/test/infrastructure/TransactionStatusHttp.spec.ts index 6a13ea1369..801aadb715 100644 --- a/test/infrastructure/TransactionStatusHttp.spec.ts +++ b/test/infrastructure/TransactionStatusHttp.spec.ts @@ -81,4 +81,20 @@ describe('TransactionStatusHttp', () => { expect(transactionStatus.code).to.be.equal('Failure_AccountLink_Inconsistent_Unlink_Data'); expect(transactionStatus.group).to.be.equal('failed'); }); + + it('getTransactionStatus - Error', async () => { + when(transactionStatusRoutesApi.getTransactionStatus('abc')).thenReject(new Error('Mocked Error')); + await transactionStatusHttp + .getTransactionStatus('abc') + .toPromise() + .catch((error) => expect(error).not.to.be.undefined); + }); + + it('getTransactionStatuss - Error', async () => { + when(transactionStatusRoutesApi.getTransactionStatuses(deepEqual({ hashes: ['abc'] }))).thenReject(new Error('Mocked Error')); + await transactionStatusHttp + .getTransactionStatuses(['abc']) + .toPromise() + .catch((error) => expect(error).not.to.be.undefined); + }); }); diff --git a/test/infrastructure/receipt/CreateReceiptFromDTO.spec.ts b/test/infrastructure/receipt/CreateReceiptFromDTO.spec.ts index 7dba1fd1cb..229845a906 100644 --- a/test/infrastructure/receipt/CreateReceiptFromDTO.spec.ts +++ b/test/infrastructure/receipt/CreateReceiptFromDTO.spec.ts @@ -51,6 +51,90 @@ describe('Receipt - CreateStatementFromDTO', () => { ], }, }, + { + statement: { + height: '52', + source: { + primaryId: 0, + secondaryId: 0, + }, + receipts: [ + { + version: 1, + type: 4685, + senderAddress: account.address.encoded(), + recipientAddress: account.address.encoded(), + mosaicId: '85BBEA6CC462B244', + amount: '1000', + }, + ], + }, + }, + { + statement: { + height: '52', + source: { + primaryId: 0, + secondaryId: 0, + }, + receipts: [ + { + version: 1, + type: 16717, + artifactId: '85BBEA6CC462B244', + }, + ], + }, + }, + { + statement: { + height: '52', + source: { + primaryId: 0, + secondaryId: 0, + }, + receipts: [ + { + version: 1, + type: 16718, + artifactId: '85BBEA6CC462B244', + }, + ], + }, + }, + { + statement: { + height: '52', + source: { + primaryId: 0, + secondaryId: 0, + }, + receipts: [ + { + version: 1, + type: 16974, + artifactId: '85BBEA6CC462B244', + }, + ], + }, + }, + { + statement: { + height: '52', + source: { + primaryId: 0, + secondaryId: 0, + }, + receipts: [ + { + version: 1, + type: 20803, + mosaicId: '85BBEA6CC462B244', + amount: '1000', + }, + ], + }, + }, ], addressResolutionStatements: [ { @@ -123,7 +207,7 @@ describe('Receipt - CreateStatementFromDTO', () => { const unresolvedAddress = statement.addressResolutionStatements[0].unresolved as NamespaceId; const unresolvedMosaicId = statement.mosaicResolutionStatements[0].unresolved as NamespaceId; - expect(statement.transactionStatements.length).to.be.equal(1); + expect(statement.transactionStatements.length).to.be.equal(6); expect(statement.addressResolutionStatements.length).to.be.equal(2); expect(statement.mosaicResolutionStatements.length).to.be.equal(2); @@ -133,6 +217,36 @@ describe('Receipt - CreateStatementFromDTO', () => { expect(statement.transactionStatements[0].source.secondaryId).to.be.equal(0); expect(statement.transactionStatements[0].receipts[0].type).to.be.equal(ReceiptType.Harvest_Fee); + expect(statement.transactionStatements[1].receipts.length).to.be.equal(1); + deepEqual(statement.transactionStatements[1].height, UInt64.fromNumericString('52')); + expect(statement.transactionStatements[1].source.primaryId).to.be.equal(0); + expect(statement.transactionStatements[1].source.secondaryId).to.be.equal(0); + expect(statement.transactionStatements[1].receipts[0].type).to.be.equal(ReceiptType.Mosaic_Rental_Fee); + + expect(statement.transactionStatements[2].receipts.length).to.be.equal(1); + deepEqual(statement.transactionStatements[2].height, UInt64.fromNumericString('52')); + expect(statement.transactionStatements[2].source.primaryId).to.be.equal(0); + expect(statement.transactionStatements[2].source.secondaryId).to.be.equal(0); + expect(statement.transactionStatements[2].receipts[0].type).to.be.equal(ReceiptType.Mosaic_Expired); + + expect(statement.transactionStatements[3].receipts.length).to.be.equal(1); + deepEqual(statement.transactionStatements[3].height, UInt64.fromNumericString('52')); + expect(statement.transactionStatements[3].source.primaryId).to.be.equal(0); + expect(statement.transactionStatements[3].source.secondaryId).to.be.equal(0); + expect(statement.transactionStatements[3].receipts[0].type).to.be.equal(ReceiptType.Namespace_Expired); + + expect(statement.transactionStatements[4].receipts.length).to.be.equal(1); + deepEqual(statement.transactionStatements[4].height, UInt64.fromNumericString('52')); + expect(statement.transactionStatements[4].source.primaryId).to.be.equal(0); + expect(statement.transactionStatements[4].source.secondaryId).to.be.equal(0); + expect(statement.transactionStatements[4].receipts[0].type).to.be.equal(ReceiptType.Namespace_Deleted); + + expect(statement.transactionStatements[5].receipts.length).to.be.equal(1); + deepEqual(statement.transactionStatements[5].height, UInt64.fromNumericString('52')); + expect(statement.transactionStatements[5].source.primaryId).to.be.equal(0); + expect(statement.transactionStatements[5].source.secondaryId).to.be.equal(0); + expect(statement.transactionStatements[5].receipts[0].type).to.be.equal(ReceiptType.Inflation); + deepEqual(statement.addressResolutionStatements[0].height, UInt64.fromNumericString('1488')); deepEqual(unresolvedAddress.toHex(), '83686227AF0AB603'); expect(statement.addressResolutionStatements[0].resolutionEntries.length).to.be.equal(1); @@ -145,4 +259,146 @@ describe('Receipt - CreateStatementFromDTO', () => { expect(statement.mosaicResolutionStatements[0].resolutionEntries.length).to.be.equal(1); deepEqual((statement.mosaicResolutionStatements[0].resolutionEntries[0].resolved as MosaicId).toHex(), '941299B2B7E1291C'); }); + + it('extractUnresolvedAddress', () => { + const dto = { + transactionStatements: [], + addressResolutionStatements: [ + { + statement: { + height: '1488', + unresolved: account.address, + resolutionEntries: [ + { + source: { + primaryId: 4, + secondaryId: 0, + }, + resolved: '917E7E29A01014C2F3000000000000000000000000000000', + }, + ], + }, + }, + ], + mosaicResolutionStatements: [], + }; + const statement = CreateStatementFromDTO(dto); + expect(statement.addressResolutionStatements.length).to.be.equal(1); + expect((statement.addressResolutionStatements[0].unresolved as Address).plain()).to.be.equal(account.address.plain()); + + const dtoJson = { + transactionStatements: [], + addressResolutionStatements: [ + { + statement: { + height: '1488', + unresolved: { + address: account.address.plain(), + networkType: 152, + }, + resolutionEntries: [ + { + source: { + primaryId: 4, + secondaryId: 0, + }, + resolved: '917E7E29A01014C2F3000000000000000000000000000000', + }, + ], + }, + }, + ], + mosaicResolutionStatements: [], + }; + + const statementJson = CreateStatementFromDTO(dtoJson); + expect(statementJson.addressResolutionStatements.length).to.be.equal(1); + expect((statementJson.addressResolutionStatements[0].unresolved as Address).plain()).to.be.equal(account.address.plain()); + + const dtoId = { + transactionStatements: [], + addressResolutionStatements: [ + { + statement: { + height: '1488', + unresolved: { + id: new NamespaceId('name').toHex(), + name: 'name', + }, + resolutionEntries: [ + { + source: { + primaryId: 4, + secondaryId: 0, + }, + resolved: '917E7E29A01014C2F3000000000000000000000000000000', + }, + ], + }, + }, + ], + mosaicResolutionStatements: [], + }; + + const statementId = CreateStatementFromDTO(dtoId); + expect(statementId.addressResolutionStatements.length).to.be.equal(1); + expect((statementId.addressResolutionStatements[0].unresolved as NamespaceId).toHex()).to.be.equal(new NamespaceId('name').toHex()); + + const dtoError = { + transactionStatements: [], + addressResolutionStatements: [ + { + statement: { + height: '1488', + unresolved: { + error: 'error', + }, + resolutionEntries: [ + { + source: { + primaryId: 4, + secondaryId: 0, + }, + resolved: '917E7E29A01014C2F3000000000000000000000000000000', + }, + ], + }, + }, + ], + mosaicResolutionStatements: [], + }; + + expect(() => { + CreateStatementFromDTO(dtoError); + }).to.throw(); + }); + + it('Statement - Error', () => { + const dtoError = { + transactionStatements: [ + { + statement: { + height: '52', + source: { + primaryId: 0, + secondaryId: 0, + }, + receipts: [ + { + version: 1, + type: 99999, + artifactId: '85BBEA6CC462B244', + }, + ], + }, + }, + ], + addressResolutionStatements: [], + mosaicResolutionStatements: [], + }; + + expect(() => { + CreateStatementFromDTO(dtoError); + }).to.throw(); + }); }); From a48ccfb812b53f13ca9ba5c2fd0f2a1390b6e917 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 16 Jun 2020 23:42:18 +0100 Subject: [PATCH 20/22] - Added missing export - More coverage improvment --- src/infrastructure/infrastructure.ts | 2 + test/core/utils/DtoMapping.spec.ts | 66 ++++++++ test/infrastructure/MetadataHttp.spec.ts | 159 ++++++++++++++++++ .../RestrictionAccountHttp.spec.ts | 7 +- test/model/namespace/Alias.spec.ts | 15 ++ test/model/receipt/Receipt.spec.ts | 13 ++ test/model/receipt/ResolutionEntry.spec.ts | 45 +++++ .../AddressAliasTransaction.spec.ts | 24 +++ .../MosaicAliasTransaction.spec.ts | 25 +++ test/model/transaction/SyncAnnounce.spec.ts | 28 +++ 10 files changed, 381 insertions(+), 3 deletions(-) create mode 100644 test/core/utils/DtoMapping.spec.ts create mode 100644 test/model/receipt/ResolutionEntry.spec.ts create mode 100644 test/model/transaction/SyncAnnounce.spec.ts diff --git a/src/infrastructure/infrastructure.ts b/src/infrastructure/infrastructure.ts index e89cd48c09..2e8ee1ece8 100644 --- a/src/infrastructure/infrastructure.ts +++ b/src/infrastructure/infrastructure.ts @@ -56,3 +56,5 @@ export * from './paginationStreamer/MosaicPaginationStreamer'; export * from './paginationStreamer/PaginationStreamer'; export * from './paginationStreamer/Searcher'; export * from './paginationStreamer/TransactionPaginationStreamer'; +export * from './TransactionStatusHttp'; +export * from './TransactionStatusRepository'; diff --git a/test/core/utils/DtoMapping.spec.ts b/test/core/utils/DtoMapping.spec.ts new file mode 100644 index 0000000000..fa1c43c8f9 --- /dev/null +++ b/test/core/utils/DtoMapping.spec.ts @@ -0,0 +1,66 @@ +/* + * Copyright 2020 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { expect } from 'chai'; +import { MosaicId } from '../../../src/model/mosaic/MosaicId'; +import { NetworkType } from '../../../src/model/network/NetworkType'; +import { PublicAccount } from '../../../src/model/account/PublicAccount'; +import { + AccountRestrictionsInfoDTO, + AccountRestrictionsDTO, + AccountRestrictionDTO, + AccountRestrictionFlagsEnum, +} from 'symbol-openapi-typescript-node-client'; +import { DtoMapping } from '../../../src/core/utils/DtoMapping'; + +describe('DtoMapping', () => { + const publicAccount = PublicAccount.createFromPublicKey( + '9801508C58666C746F471538E43002B85B1CD542F9874B2861183919BA8787B6', + NetworkType.MIJIN_TEST, + ); + const address = publicAccount.address; + const mosaicId = new MosaicId('11F4B1B3AC033DB5'); + + it('extractRestrictionInfo - Operation', () => { + const restrictionInfo = new AccountRestrictionsInfoDTO(); + const restrictionsDto = new AccountRestrictionsDTO(); + const restriction = new AccountRestrictionDTO(); + restriction.restrictionFlags = AccountRestrictionFlagsEnum.NUMBER_16388; + restriction.values = [16724]; + restrictionsDto.restrictions = [restriction]; + restrictionsDto.address = address.encoded(); + + restrictionInfo.accountRestrictions = restrictionsDto; + const result = DtoMapping.extractAccountRestrictionFromDto(restrictionInfo); + expect(result).not.to.be.undefined; + expect(result.accountRestrictions.restrictions[0].values[0]).to.be.equal(16724); + }); + + it('extractRestrictionInfo - Mosaic', () => { + const address = publicAccount.address; + const restrictionInfo = new AccountRestrictionsInfoDTO(); + const restrictionsDto = new AccountRestrictionsDTO(); + const restriction = new AccountRestrictionDTO(); + restriction.restrictionFlags = AccountRestrictionFlagsEnum.NUMBER_2; + restriction.values = [mosaicId.toHex()]; + restrictionsDto.restrictions = [restriction]; + restrictionsDto.address = address.encoded(); + + restrictionInfo.accountRestrictions = restrictionsDto; + const result = DtoMapping.extractAccountRestrictionFromDto(restrictionInfo); + expect(result).not.to.be.undefined; + expect((result.accountRestrictions.restrictions[0].values[0] as MosaicId).toHex()).to.be.equal(mosaicId.toHex()); + }); +}); diff --git a/test/infrastructure/MetadataHttp.spec.ts b/test/infrastructure/MetadataHttp.spec.ts index 2f44178516..96f7544724 100644 --- a/test/infrastructure/MetadataHttp.spec.ts +++ b/test/infrastructure/MetadataHttp.spec.ts @@ -33,6 +33,14 @@ import { MetadataType } from '../../src/model/metadata/MetadataType'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { Order } from 'symbol-openapi-typescript-node-client/dist/model/order'; +import { MetadataTransactionService } from '../../src/service/MetadataTransactionService'; +import { Deadline } from '../../src/model/transaction/Deadline'; +import { NetworkType } from '../../src/model/network/NetworkType'; +import { UInt64 } from '../../src/model/UInt64'; +import { AccountMetadataTransaction } from '../../src/model/transaction/AccountMetadataTransaction'; +import { TransactionType } from '../../src/model/transaction/TransactionType'; +import { MosaicMetadataTransaction } from '../../src/model/transaction/MosaicMetadataTransaction'; +import { NamespaceMetadataTransaction } from '../../src/model/transaction/NamespaceMetadataTransaction'; describe('MetadataHttp', () => { const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); @@ -247,4 +255,155 @@ describe('MetadataHttp', () => { const metadata = await metadataRepository.getNamespaceMetadataByKeyAndSender(namespaceId, 'cccc', address).toPromise(); assertMetadataInfo(metadata, metadataDTOMosaic); }); + + it('Address meta no previous value', (done) => { + response.statusCode = 404; + when(metadataRoutesApi.getAccountMetadataByKeyAndSender(address.plain(), '85BBEA6CC462B244', address.plain())).thenReturn( + Promise.reject({ + response, + body: undefined, + }), + ); + const metadataTransactionService = new MetadataTransactionService(metadataRepository); + metadataTransactionService + .createMetadataTransaction( + Deadline.create(), + NetworkType.MIJIN_TEST, + MetadataType.Account, + address, + UInt64.fromHex('85BBEA6CC462B244'), + 'test', + address, + ) + .subscribe((transaction: AccountMetadataTransaction) => { + expect(transaction.type).to.be.equal(TransactionType.ACCOUNT_METADATA); + expect(transaction.scopedMetadataKey.toHex()).to.be.equal('85BBEA6CC462B244'); + done(); + }); + }); + + it('Mosaic meta no previous value', (done) => { + response.statusCode = 404; + when(metadataRoutesApi.getMosaicMetadataByKeyAndSender(mosaicId.toHex(), '85BBEA6CC462B244', address.plain())).thenReturn( + Promise.reject({ + response, + body: undefined, + }), + ); + const metadataTransactionService = new MetadataTransactionService(metadataRepository); + metadataTransactionService + .createMetadataTransaction( + Deadline.create(), + NetworkType.MIJIN_TEST, + MetadataType.Mosaic, + address, + UInt64.fromHex('85BBEA6CC462B244'), + 'test', + address, + mosaicId, + ) + .subscribe((transaction: MosaicMetadataTransaction) => { + expect(transaction.type).to.be.equal(TransactionType.MOSAIC_METADATA); + expect(transaction.scopedMetadataKey.toHex()).to.be.equal('85BBEA6CC462B244'); + done(); + }); + }); + + it('Namespace meta no previous value', (done) => { + response.statusCode = 404; + when(metadataRoutesApi.getNamespaceMetadataByKeyAndSender(namespaceId.toHex(), '85BBEA6CC462B244', address.plain())).thenReturn( + Promise.reject({ + response, + body: undefined, + }), + ); + const metadataTransactionService = new MetadataTransactionService(metadataRepository); + metadataTransactionService + .createMetadataTransaction( + Deadline.create(), + NetworkType.MIJIN_TEST, + MetadataType.Namespace, + address, + UInt64.fromHex('85BBEA6CC462B244'), + 'test', + address, + namespaceId, + ) + .subscribe((transaction: NamespaceMetadataTransaction) => { + expect(transaction.type).to.be.equal(TransactionType.NAMESPACE_METADATA); + expect(transaction.scopedMetadataKey.toHex()).to.be.equal('85BBEA6CC462B244'); + done(); + }); + }); + + it('Address meta no previous value Error', async () => { + response.statusCode = 409; + when(metadataRoutesApi.getAccountMetadataByKeyAndSender(address.plain(), '85BBEA6CC462B244', address.plain())).thenReturn( + Promise.reject({ + response, + body: undefined, + }), + ); + const metadataTransactionService = new MetadataTransactionService(metadataRepository); + await metadataTransactionService + .createMetadataTransaction( + Deadline.create(), + NetworkType.MIJIN_TEST, + MetadataType.Account, + address, + UInt64.fromHex('85BBEA6CC462B244'), + 'test', + address, + ) + .toPromise() + .catch((error) => expect(error).not.to.be.undefined); + }); + + it('Mosaic meta no previous value', async () => { + response.statusCode = 409; + when(metadataRoutesApi.getMosaicMetadataByKeyAndSender(mosaicId.toHex(), '85BBEA6CC462B244', address.plain())).thenReturn( + Promise.reject({ + response, + body: undefined, + }), + ); + const metadataTransactionService = new MetadataTransactionService(metadataRepository); + await metadataTransactionService + .createMetadataTransaction( + Deadline.create(), + NetworkType.MIJIN_TEST, + MetadataType.Mosaic, + address, + UInt64.fromHex('85BBEA6CC462B244'), + 'test', + address, + mosaicId, + ) + .toPromise() + .catch((error) => expect(error).not.to.be.undefined); + }); + + it('Namespace meta no previous value', async () => { + response.statusCode = 409; + when(metadataRoutesApi.getNamespaceMetadataByKeyAndSender(namespaceId.toHex(), '85BBEA6CC462B244', address.plain())).thenReturn( + Promise.reject({ + response, + body: undefined, + }), + ); + const metadataTransactionService = new MetadataTransactionService(metadataRepository); + await metadataTransactionService + .createMetadataTransaction( + Deadline.create(), + NetworkType.MIJIN_TEST, + MetadataType.Namespace, + address, + UInt64.fromHex('85BBEA6CC462B244'), + 'test', + address, + namespaceId, + ) + .toPromise() + .catch((error) => expect(error).not.to.be.undefined); + }); }); diff --git a/test/infrastructure/RestrictionAccountHttp.spec.ts b/test/infrastructure/RestrictionAccountHttp.spec.ts index 7a7758dc9c..db3279cfbf 100644 --- a/test/infrastructure/RestrictionAccountHttp.spec.ts +++ b/test/infrastructure/RestrictionAccountHttp.spec.ts @@ -75,11 +75,12 @@ describe('RestrictionAccountHttp', () => { Promise.resolve({ response, body: [restrictionInfo] }), ); - const restrictions = await restrictionAccountRepository.getAccountRestrictions(address).toPromise(); + const restrictions = await restrictionAccountRepository.getAccountRestrictionsFromAccounts([address]).toPromise(); expect(restrictions).to.be.not.null; expect(restrictions.length).to.be.greaterThan(0); - expect(restrictions[0].restrictionFlags).to.be.equals(AddressRestrictionFlag.AllowIncomingAddress); - expect((restrictions[0].values[0] as Address).plain()).to.be.equals(address.plain()); + expect(restrictions[0].address.plain()).to.be.equals(address.plain()); + expect(restrictions[0].restrictions[0].restrictionFlags).to.be.equals(AddressRestrictionFlag.AllowIncomingAddress); + expect((restrictions[0].restrictions[0].values[0] as Address).plain()).to.be.equals(address.plain()); }); it('getAccountRestrictions - Error', async () => { diff --git a/test/model/namespace/Alias.spec.ts b/test/model/namespace/Alias.spec.ts index b76e9fe23d..0fcb439e58 100644 --- a/test/model/namespace/Alias.spec.ts +++ b/test/model/namespace/Alias.spec.ts @@ -75,4 +75,19 @@ describe('Alias', () => { expect(alias1.equals(alias2)).to.be.equal(true); expect(alias1.equals(alias3)).to.be.equal(false); }); + + it('EmptyAlias.equals()', () => { + const alias1 = new MosaicAlias(mosaicAliasDTO.mosaicId); + const alias2 = new EmptyAlias(); + const alias3 = new EmptyAlias(); + + expect(alias2.equals(alias3)).to.be.equal(true); + expect(alias2.equals(alias1)).to.be.equal(false); + }); + + it('EmptyAlias.serialize()', () => { + const alias3 = new EmptyAlias(); + + expect(alias3.serialize()).to.be.deep.equal(new Uint8Array(0)); + }); }); diff --git a/test/model/receipt/Receipt.spec.ts b/test/model/receipt/Receipt.spec.ts index 53071c2265..85ea586998 100644 --- a/test/model/receipt/Receipt.spec.ts +++ b/test/model/receipt/Receipt.spec.ts @@ -34,6 +34,7 @@ import { ResolutionStatement } from '../../../src/model/receipt/ResolutionStatem import { ResolutionType } from '../../../src/model/receipt/ResolutionType'; import { TransactionStatement } from '../../../src/model/receipt/TransactionStatement'; import { UInt64 } from '../../../src/model/UInt64'; +import { Convert } from '../../../src/core/format/Convert'; describe('Receipt', () => { let account: Account; @@ -357,4 +358,16 @@ describe('Receipt', () => { const hash = receipt.generateHash(); expect(hash).to.be.equal('E73E67382162C38AED77D5D5D67F96AA590DC12FF13AE263AA50932896AC4801'); }); + + it('artifactExpiryReceipt - serialize', () => { + const receipt = new ArtifactExpiryReceipt(new NamespaceId([3646934825, 3576016193]), 1, 16718); + const byte = receipt.serialize(); + expect(Convert.uint8ToHex(byte)).to.be.equal('01004E4129CF5FD941AD25D5'); + }); + + it('artifactExpiryReceipt - serialize', () => { + const receipt = new ArtifactExpiryReceipt(new MosaicId([3646934825, 3576016193]), 1, 16717); + const byte = receipt.serialize(); + expect(Convert.uint8ToHex(byte)).to.be.equal('01004D4129CF5FD941AD25D5'); + }); }); diff --git a/test/model/receipt/ResolutionEntry.spec.ts b/test/model/receipt/ResolutionEntry.spec.ts new file mode 100644 index 0000000000..edde3a73d8 --- /dev/null +++ b/test/model/receipt/ResolutionEntry.spec.ts @@ -0,0 +1,45 @@ +/* + * Copyright 2020 NEM + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { expect } from 'chai'; +import { Address } from '../../../src/model/account/Address'; +import { MosaicId } from '../../../src/model/mosaic/MosaicId'; +import { ReceiptSource } from '../../../src/model/receipt/ReceiptSource'; +import { ResolutionEntry } from '../../../src/model/receipt/ResolutionEntry'; +import { TestingAccount } from '../../conf/conf.spec'; +import { Convert } from '../../../src/core/format/Convert'; + +describe('ResolutionEntry', () => { + const address = TestingAccount.address; + const mosaicId = new MosaicId('941299B2B7E1291C'); + + it('Should create resolution entry', () => { + const entry = new ResolutionEntry(address, new ReceiptSource(0, 1)); + expect((entry.resolved as Address).plain()).to.be.equal(address.plain()); + }); + + it('Should serialize', () => { + const entry = new ResolutionEntry(address, new ReceiptSource(0, 1)); + const result = entry.serialize(); + expect(Convert.uint8ToHex(result)).to.be.equal('90D66C33420E5411995BACFCA2B28CF1C9F5DD7AB1204EA40000000001000000'); + }); + + it('Should serialize - Mosaic', () => { + const entry = new ResolutionEntry(mosaicId, new ReceiptSource(0, 1)); + const result = entry.serialize(); + expect(Convert.uint8ToHex(result)).to.be.equal('1C29E1B7B29912940000000001000000'); + }); +}); diff --git a/test/model/transaction/AddressAliasTransaction.spec.ts b/test/model/transaction/AddressAliasTransaction.spec.ts index 1a57b96b4d..cbe3f07076 100644 --- a/test/model/transaction/AddressAliasTransaction.spec.ts +++ b/test/model/transaction/AddressAliasTransaction.spec.ts @@ -25,6 +25,7 @@ import { AddressAliasTransaction } from '../../../src/model/transaction/AddressA import { Deadline } from '../../../src/model/transaction/Deadline'; import { UInt64 } from '../../../src/model/UInt64'; import { TestingAccount } from '../../conf/conf.spec'; +import { AliasTransaction } from '../../../src/model/model'; describe('AddressAliasTransaction', () => { let account: Account; @@ -87,6 +88,29 @@ describe('AddressAliasTransaction', () => { ); }); + it('should createComplete an AddressAliasTransaction using abstract', () => { + const namespaceId = new NamespaceId([33347626, 3779697293]); + const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); + const addressAliasTransaction = AliasTransaction.createForAddress( + Deadline.create(), + AliasAction.Link, + namespaceId, + address, + NetworkType.MIJIN_TEST, + ) as AddressAliasTransaction; + + expect(addressAliasTransaction.aliasAction).to.be.equal(AliasAction.Link); + expect(addressAliasTransaction.namespaceId.id.lower).to.be.equal(33347626); + expect(addressAliasTransaction.namespaceId.id.higher).to.be.equal(3779697293); + expect(addressAliasTransaction.address.plain()).to.be.equal('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); + + const signedTransaction = addressAliasTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( + '2AD8FC018D9A49E19026D27E1D0A26CA4E316F901E23E55C8711DB20DF11A7B201', + ); + }); + describe('size', () => { it('should return 161 for AggregateTransaction byte size with TransferTransaction with 1 mosaic and message NEM', () => { const namespaceId = new NamespaceId([33347626, 3779697293]); diff --git a/test/model/transaction/MosaicAliasTransaction.spec.ts b/test/model/transaction/MosaicAliasTransaction.spec.ts index ab8244c76d..195f0fe8ef 100644 --- a/test/model/transaction/MosaicAliasTransaction.spec.ts +++ b/test/model/transaction/MosaicAliasTransaction.spec.ts @@ -28,6 +28,7 @@ import { TestingAccount } from '../../conf/conf.spec'; import { deepEqual } from 'assert'; import { EmbeddedTransactionBuilder } from 'catbuffer-typescript/dist/EmbeddedTransactionBuilder'; import { TransactionType } from '../../../src/model/transaction/TransactionType'; +import { AliasTransaction } from '../../../src/model/transaction/AliasTransaction'; describe('MosaicAliasTransaction', () => { let account: Account; @@ -91,6 +92,30 @@ describe('MosaicAliasTransaction', () => { ); }); + it('should createComplete an MosaicAliasTransaction using abstract', () => { + const namespaceId = new NamespaceId([33347626, 3779697293]); + const mosaicId = new MosaicId([2262289484, 3405110546]); + const mosaicAliasTransaction = AliasTransaction.createForMosaic( + Deadline.create(), + AliasAction.Link, + namespaceId, + mosaicId, + NetworkType.MIJIN_TEST, + ) as MosaicAliasTransaction; + + expect(mosaicAliasTransaction.aliasAction).to.be.equal(AliasAction.Link); + expect(mosaicAliasTransaction.namespaceId.id.lower).to.be.equal(33347626); + expect(mosaicAliasTransaction.namespaceId.id.higher).to.be.equal(3779697293); + expect(mosaicAliasTransaction.mosaicId.id.lower).to.be.equal(2262289484); + expect(mosaicAliasTransaction.mosaicId.id.higher).to.be.equal(3405110546); + + const signedTransaction = mosaicAliasTransaction.signWith(account, generationHash); + + expect(signedTransaction.payload.substring(256, signedTransaction.payload.length)).to.be.equal( + '2AD8FC018D9A49E14CCCD78612DDF5CA01', + ); + }); + describe('size', () => { it('should return 145 for MosaicAliasTransaction transaction byte size', () => { const namespaceId = new NamespaceId([33347626, 3779697293]); diff --git a/test/model/transaction/SyncAnnounce.spec.ts b/test/model/transaction/SyncAnnounce.spec.ts new file mode 100644 index 0000000000..fd9ca7893f --- /dev/null +++ b/test/model/transaction/SyncAnnounce.spec.ts @@ -0,0 +1,28 @@ +/* + * Copyright 2020 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { deepEqual } from 'assert'; +import { SyncAnnounce } from '../../../src/model/transaction/SyncAnnounce'; + +describe('SyncAnnounce', () => { + it('should create SyncAnnounce', () => { + const syncAnnounce = new SyncAnnounce('payload', 'hash', 'address'); + + deepEqual(syncAnnounce.payload, 'payload'); + deepEqual(syncAnnounce.hash, 'hash'); + deepEqual(syncAnnounce.address, 'address'); + }); +}); From 50bc0001844213676f4be35825e1d7dedee5472b Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Wed, 17 Jun 2020 23:14:22 +0100 Subject: [PATCH 21/22] Fixed missing version in detached cosignature issue --- e2e/infrastructure/TransactionHttp.spec.ts | 8 +++++--- package-lock.json | 6 +++--- package.json | 2 +- src/infrastructure/TransactionHttp.ts | 8 +++++++- .../transaction/CreateTransactionFromDTO.ts | 2 +- src/model/transaction/AggregateTransaction.ts | 4 ++-- .../transaction/AggregateTransactionCosignature.ts | 10 +++++----- .../transaction/CosignatureSignedTransaction.ts | 7 +++++++ test/infrastructure/TransactionHttp.spec.ts | 13 ++++++++++--- test/model/transaction/AggregateTransaction.spec.ts | 1 - .../transaction/CosignatureTransaction.spec.ts | 2 ++ 11 files changed, 43 insertions(+), 20 deletions(-) diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index c2674396a8..3741f28a9a 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -1490,12 +1490,14 @@ describe('TransactionHttp', () => { describe('searchTransactions', () => { it('should return transaction info given address', async () => { - const transactions = await transactionRepository.search({ address: account.address } as TransactionSearchCriteria).toPromise(); + const transactions = await transactionRepository + .search({ group: TransactionGroup.Confirmed, address: account.address } as TransactionSearchCriteria) + .toPromise(); expect(transactions.data.length).to.be.greaterThan(0); }); it('should return transaction info given height', async () => { const transactions = await transactionRepository - .search({ height: UInt64.fromUint(1) } as TransactionSearchCriteria) + .search({ group: TransactionGroup.Confirmed, height: UInt64.fromUint(1) } as TransactionSearchCriteria) .toPromise(); expect(transactions.data.length).to.be.greaterThan(0); }); @@ -1505,7 +1507,7 @@ describe('TransactionHttp', () => { it('should return transaction info given address', async () => { const streamer = new TransactionPaginationStreamer(transactionRepository); const transactionsNoStreamer = await transactionRepository - .search({ address: account.address, pageSize: 10 } as TransactionSearchCriteria) + .search({ group: TransactionGroup.Confirmed, address: account.address, pageSize: 10 } as TransactionSearchCriteria) .toPromise(); const transactions = await streamer .search({ group: TransactionGroup.Confirmed, address: account.address, pageSize: 10 }) diff --git a/package-lock.json b/package-lock.json index 79ad51fe2b..256ae45f40 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6252,9 +6252,9 @@ } }, "symbol-openapi-typescript-node-client": { - "version": "0.8.13-SNAPSHOT.202006151206", - "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-node-client/-/symbol-openapi-typescript-node-client-0.8.13-SNAPSHOT.202006151206.tgz", - "integrity": "sha512-0xNXCrWiia5nW3xgGC/oTadbZSr3Tjkt6gZC0yC+1n7JQU5ctqNoFZDdk6q1xUF50ROaTba3tef0jiNf0T0wFQ==", + "version": "0.9.1-SNAPSHOT.202006172259", + "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-node-client/-/symbol-openapi-typescript-node-client-0.9.1-SNAPSHOT.202006172259.tgz", + "integrity": "sha512-hlb9vfrvengkh4JLFTKoTPIzvmxiyqRHcv9+GuLjkLUwppZiSol6cGdxD3hM7xqWABTuaE7B7Dgk3g02zDMqOA==", "requires": { "@types/bluebird": "*", "@types/request": "*", diff --git a/package.json b/package.json index 93bf55ee7f..5246e7830c 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "ripemd160": "^2.0.2", "rxjs": "^6.5.3", "rxjs-compat": "^6.5.3", - "symbol-openapi-typescript-node-client": "0.8.13-SNAPSHOT.202006151206", + "symbol-openapi-typescript-node-client": "0.9.1-SNAPSHOT.202006172259", "tweetnacl": "^1.0.3", "utf8": "^3.0.0", "ws": "^7.2.3" diff --git a/src/infrastructure/TransactionHttp.ts b/src/infrastructure/TransactionHttp.ts index be3ba02863..4ecc937cf3 100644 --- a/src/infrastructure/TransactionHttp.ts +++ b/src/infrastructure/TransactionHttp.ts @@ -23,6 +23,7 @@ import { TransactionRoutesApi, TransactionInfoDTO, TransactionPage, + Cosignature, } from 'symbol-openapi-typescript-node-client'; import { CosignatureSignedTransaction } from '../model/transaction/CosignatureSignedTransaction'; import { SignedTransaction } from '../model/transaction/SignedTransaction'; @@ -138,7 +139,12 @@ export class TransactionHttp extends Http implements TransactionRepository { public announceAggregateBondedCosignature( cosignatureSignedTransaction: CosignatureSignedTransaction, ): Observable { - return observableFrom(this.transactionRoutesApi.announceCosignatureTransaction(cosignatureSignedTransaction)).pipe( + const cosignature = new Cosignature(); + cosignature.parentHash = cosignatureSignedTransaction.parentHash; + cosignature.signerPublicKey = cosignatureSignedTransaction.signerPublicKey; + cosignature.signature = cosignatureSignedTransaction.signature; + cosignature.version = cosignatureSignedTransaction.version.toString(); + return observableFrom(this.transactionRoutesApi.announceCosignatureTransaction(cosignature)).pipe( map(({ body }) => new TransactionAnnounceResponse(body.message)), catchError((error) => throwError(this.errorHandling(error))), ); diff --git a/src/infrastructure/transaction/CreateTransactionFromDTO.ts b/src/infrastructure/transaction/CreateTransactionFromDTO.ts index 6c426def91..45f8cda6c9 100644 --- a/src/infrastructure/transaction/CreateTransactionFromDTO.ts +++ b/src/infrastructure/transaction/CreateTransactionFromDTO.ts @@ -532,9 +532,9 @@ export const CreateTransactionFromDTO = (transactionDTO): Transaction => { transactionDTO.transaction.cosignatures ? transactionDTO.transaction.cosignatures.map((aggregateCosignatureDTO) => { return new AggregateTransactionCosignature( - UInt64.fromNumericString(aggregateCosignatureDTO.version), aggregateCosignatureDTO.signature, PublicAccount.createFromPublicKey(aggregateCosignatureDTO.signerPublicKey, transactionDTO.transaction.network), + UInt64.fromNumericString(aggregateCosignatureDTO.version), ); }) : [], diff --git a/src/model/transaction/AggregateTransaction.ts b/src/model/transaction/AggregateTransaction.ts index f7b7a6c1c2..36ac758587 100644 --- a/src/model/transaction/AggregateTransaction.ts +++ b/src/model/transaction/AggregateTransaction.ts @@ -172,9 +172,9 @@ export class AggregateTransaction extends Transaction { const signature = payload.substring(16, 144); const consignatures = builder.getCosignatures().map((cosig) => { return new AggregateTransactionCosignature( - new UInt64(cosig.version), Convert.uint8ToHex(cosig.signature.signature), PublicAccount.createFromPublicKey(Convert.uint8ToHex(cosig.signerPublicKey.key), networkType), + new UInt64(cosig.version), ); }); @@ -274,7 +274,7 @@ export class AggregateTransaction extends Transaction { const signedTransaction = this.signWith(initiatorAccount, generationHash); let signedPayload = signedTransaction.payload; cosignatureSignedTransactions.forEach((cosignedTransaction) => { - signedPayload += UInt64.fromUint(0).toHex() + cosignedTransaction.signerPublicKey + cosignedTransaction.signature; + signedPayload += cosignedTransaction.version.toHex() + cosignedTransaction.signerPublicKey + cosignedTransaction.signature; }); // Calculate new size diff --git a/src/model/transaction/AggregateTransactionCosignature.ts b/src/model/transaction/AggregateTransactionCosignature.ts index 12f7cf9ae1..859b9a9a92 100644 --- a/src/model/transaction/AggregateTransactionCosignature.ts +++ b/src/model/transaction/AggregateTransactionCosignature.ts @@ -21,15 +21,11 @@ import { UInt64 } from '../UInt64'; */ export class AggregateTransactionCosignature { /** - * @param version * @param signature * @param signer + * @param version */ constructor( - /** - * Version - */ - public readonly version: UInt64, /** * The signature of aggregate transaction done by the cosigner. */ @@ -38,6 +34,10 @@ export class AggregateTransactionCosignature { * The cosigner public account. */ public readonly signer: PublicAccount, + /** + * Version + */ + public readonly version = UInt64.fromUint(0), ) {} /** diff --git a/src/model/transaction/CosignatureSignedTransaction.ts b/src/model/transaction/CosignatureSignedTransaction.ts index e9004b16f7..abdfa44006 100644 --- a/src/model/transaction/CosignatureSignedTransaction.ts +++ b/src/model/transaction/CosignatureSignedTransaction.ts @@ -14,6 +14,8 @@ * limitations under the License. */ +import { UInt64 } from '../UInt64'; + /** * Co-signature signed transaction. */ @@ -22,6 +24,7 @@ export class CosignatureSignedTransaction { * @param parentHash * @param signature * @param signerPublicKey + * @param version */ constructor( /** @@ -36,5 +39,9 @@ export class CosignatureSignedTransaction { * The signer publicKey of the transaction. */ public readonly signerPublicKey: string, + /** + * Version + */ + public readonly version = UInt64.fromUint(0), ) {} } diff --git a/test/infrastructure/TransactionHttp.spec.ts b/test/infrastructure/TransactionHttp.spec.ts index 663c4cbcc2..4cb6dd1746 100644 --- a/test/infrastructure/TransactionHttp.spec.ts +++ b/test/infrastructure/TransactionHttp.spec.ts @@ -29,6 +29,7 @@ import { BlockMetaDTO, BlockInfoDTO, AnnounceTransactionInfoDTO, + Cosignature, } from 'symbol-openapi-typescript-node-client'; import { deepEqual, instance, mock, when } from 'ts-mockito'; @@ -54,6 +55,12 @@ describe('TransactionHttp', () => { let transactionHttp: TransactionHttp; let blockRoutesApi: BlockRoutesApi; + const cosignature = new Cosignature(); + cosignature.parentHash = 'parentHash'; + cosignature.signerPublicKey = 'signerPubKey'; + cosignature.signature = 'signature'; + cosignature.version = '0'; + before(() => { transactionRoutesApi = mock(); blockRoutesApi = mock(); @@ -419,7 +426,7 @@ describe('TransactionHttp', () => { const cosignTx = new CosignatureSignedTransaction('parentHash', 'signature', 'signerPubKey'); - when(transactionRoutesApi.announceCosignatureTransaction(deepEqual(cosignTx))).thenReturn( + when(transactionRoutesApi.announceCosignatureTransaction(deepEqual(cosignature))).thenReturn( Promise.resolve({ response: instance(clientResponse), body: response }), ); const announceResult = await transactionHttp.announceAggregateBondedCosignature(cosignTx).toPromise(); @@ -447,7 +454,7 @@ describe('TransactionHttp', () => { it('announceAggregateBonded - Error', async () => { const cosignTx = new CosignatureSignedTransaction('parentHash', 'signature', 'signerPubKey'); - when(transactionRoutesApi.announceCosignatureTransaction(deepEqual(cosignTx))).thenReject(new Error('Mocked Error')); + when(transactionRoutesApi.announceCosignatureTransaction(deepEqual(cosignature))).thenReject(new Error('Mocked Error')); await transactionHttp .announceAggregateBondedCosignature(cosignTx) .toPromise() @@ -457,7 +464,7 @@ describe('TransactionHttp', () => { it('announceAggregateBonded Cosignatures - Error', async () => { const cosignTx = new CosignatureSignedTransaction('parentHash', 'signature', 'signerPubKey'); - when(transactionRoutesApi.announceCosignatureTransaction(deepEqual(cosignTx))).thenReject(new Error('Mocked Error')); + when(transactionRoutesApi.announceCosignatureTransaction(deepEqual(cosignature))).thenReject(new Error('Mocked Error')); await transactionHttp .announceAggregateBondedCosignature(cosignTx) .toPromise() diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index 2ef2511f20..1d12c612bc 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -557,7 +557,6 @@ describe('AggregateTransaction', () => { // add cosignature after creation const signedTransaction = aggregateTransaction.signWith(account, generationHash); const cosignature = new AggregateTransactionCosignature( - UInt64.fromUint(0), signedTransaction.payload, PublicAccount.createFromPublicKey(signedTransaction.signerPublicKey, NetworkType.MIJIN_TEST), ); diff --git a/test/model/transaction/CosignatureTransaction.spec.ts b/test/model/transaction/CosignatureTransaction.spec.ts index 7d097895b8..187a996456 100644 --- a/test/model/transaction/CosignatureTransaction.spec.ts +++ b/test/model/transaction/CosignatureTransaction.spec.ts @@ -101,6 +101,7 @@ describe('CosignatureTransaction', () => { '1179E72AF0CDF5AC1C0F7404AF6FC7268EE416204240DD3D5B11420D80215F19AA314FC86D6E03E0D', ); expect(cosignatureSignedTransaction.signerPublicKey).to.be.equal(account.publicKey); + expect(cosignatureSignedTransaction.version.toString()).to.be.equal('0'); }); it('should sign a transaction with transaction payload', () => { @@ -116,5 +117,6 @@ describe('CosignatureTransaction', () => { expect(signedTx.signerPublicKey).to.be.equal('9801508C58666C746F471538E43002B85B1CD542F9874B2861183919BA8787B6'); expect(signedTx.signerPublicKey).to.be.equal(account.publicKey); + expect(signedTx.version.toString()).to.be.equal('0'); }); }); From e9d6391f998fb6ca4aa9108c68c3345f286051ce Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 18 Jun 2020 11:02:49 +0100 Subject: [PATCH 22/22] - Updated openAPI version - Fixed a small issues in e2e tests --- .../MosaicRestrictionTransactionService.spec.ts | 2 +- e2e/service/TransactionService.spec.ts | 13 ++++++++++++- .../TransactionService_AggregateBonded.spec.ts | 2 +- package-lock.json | 6 +++--- package.json | 2 +- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/e2e/service/MosaicRestrictionTransactionService.spec.ts b/e2e/service/MosaicRestrictionTransactionService.spec.ts index b9a151c811..94cc090dfc 100644 --- a/e2e/service/MosaicRestrictionTransactionService.spec.ts +++ b/e2e/service/MosaicRestrictionTransactionService.spec.ts @@ -272,7 +272,7 @@ describe('MosaicRestrictionTransactionService', () => { expect(transaction.type).to.be.equal(TransactionType.MOSAIC_ADDRESS_RESTRICTION); expect(transaction.previousRestrictionValue.toString()).to.be.equal('2'); expect(transaction.newRestrictionValue.toString()).to.be.equal('4'); - expect(transaction.targetAddressToString()).to.be.equal(account.address.plain()); + expect(transaction.targetAddressToString()).to.be.equal(namespaceIdAddress.toHex()); expect(transaction.restrictionKey.toHex()).to.be.equal(key.toHex()); }); }); diff --git a/e2e/service/TransactionService.spec.ts b/e2e/service/TransactionService.spec.ts index ce1f898cd2..943530c279 100644 --- a/e2e/service/TransactionService.spec.ts +++ b/e2e/service/TransactionService.spec.ts @@ -118,6 +118,15 @@ describe('TransactionService', () => { helper.maxFee, ); + const mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.create( + Deadline.create(), + newMosaicId, + MosaicSupplyChangeAction.Increase, + UInt64.fromUint(200000), + networkType, + helper.maxFee, + ); + // Link namespace with new MosaicId const mosaicAliasTransactionRelink = MosaicAliasTransaction.create( Deadline.create(), @@ -145,6 +154,7 @@ describe('TransactionService', () => { transferTransaction.toAggregate(account.publicAccount), mosaicAliasTransactionUnlink.toAggregate(account.publicAccount), mosaicDefinitionTransaction.toAggregate(account.publicAccount), + mosaicSupplyChangeTransaction.toAggregate(account.publicAccount), mosaicAliasTransactionRelink.toAggregate(account.publicAccount), mosaicMetadataTransaction.toAggregate(account.publicAccount), ], @@ -306,7 +316,7 @@ describe('TransactionService', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account3.address, - [new Mosaic(mosaicAlias, UInt64.fromUint(200))], + [new Mosaic(mosaicAlias, UInt64.fromUint(1))], PlainMessage.create('test-message'), networkType, helper.maxFee, @@ -384,6 +394,7 @@ describe('TransactionService', () => { expect((tx.recipientAddress as Address).plain()).to.be.equal(account.address.plain()); expect(tx.mosaics.find((m) => m.id.toHex() === mosaicId.toHex())).not.to.equal(undefined); } else if (tx instanceof AggregateTransaction) { + console.log(tx.innerTransactions); expect(tx.innerTransactions.length).to.be.equal(5); // Assert Transfer expect(((tx.innerTransactions[0] as TransferTransaction).recipientAddress as Address).plain()).to.be.equal( diff --git a/e2e/service/TransactionService_AggregateBonded.spec.ts b/e2e/service/TransactionService_AggregateBonded.spec.ts index 969717e3f9..f57b0fa002 100644 --- a/e2e/service/TransactionService_AggregateBonded.spec.ts +++ b/e2e/service/TransactionService_AggregateBonded.spec.ts @@ -36,7 +36,7 @@ import { UInt64 } from '../../src/model/UInt64'; import { TransactionService } from '../../src/service/TransactionService'; import { IntegrationTestHelper } from '../infrastructure/IntegrationTestHelper'; -describe('TransactionService', () => { +describe('TransactionService - AggregateBonded', () => { const helper = new IntegrationTestHelper(); let account: Account; let account2: Account; diff --git a/package-lock.json b/package-lock.json index 256ae45f40..6a485b23f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6252,9 +6252,9 @@ } }, "symbol-openapi-typescript-node-client": { - "version": "0.9.1-SNAPSHOT.202006172259", - "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-node-client/-/symbol-openapi-typescript-node-client-0.9.1-SNAPSHOT.202006172259.tgz", - "integrity": "sha512-hlb9vfrvengkh4JLFTKoTPIzvmxiyqRHcv9+GuLjkLUwppZiSol6cGdxD3hM7xqWABTuaE7B7Dgk3g02zDMqOA==", + "version": "0.9.2", + "resolved": "https://registry.npmjs.org/symbol-openapi-typescript-node-client/-/symbol-openapi-typescript-node-client-0.9.2.tgz", + "integrity": "sha512-9J/V9C/HrbLzRUUbRPpDQrZkV1qyOYQU6OhD1xjnUCXdAo9VsuBFuUnGot0xnjafbAcqRvgqW83tCcMBhZtg6Q==", "requires": { "@types/bluebird": "*", "@types/request": "*", diff --git a/package.json b/package.json index 5246e7830c..4d5586951b 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "ripemd160": "^2.0.2", "rxjs": "^6.5.3", "rxjs-compat": "^6.5.3", - "symbol-openapi-typescript-node-client": "0.9.1-SNAPSHOT.202006172259", + "symbol-openapi-typescript-node-client": "0.9.2", "tweetnacl": "^1.0.3", "utf8": "^3.0.0", "ws": "^7.2.3"