From b7e28cc576ce76f6b5f8dc5601778d8f63113bd0 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 18 Feb 2020 11:23:12 +0000 Subject: [PATCH 01/13] Fixed #449 Added blockService --- e2e/service/BlockService.spec.ts | 117 +++++++++++++++++++++++++++++++ src/service/BlockService.ts | 87 +++++++++++++++++++++++ src/service/service.ts | 1 + 3 files changed, 205 insertions(+) create mode 100644 e2e/service/BlockService.spec.ts create mode 100644 src/service/BlockService.ts diff --git a/e2e/service/BlockService.spec.ts b/e2e/service/BlockService.spec.ts new file mode 100644 index 0000000000..18df0cd34c --- /dev/null +++ b/e2e/service/BlockService.spec.ts @@ -0,0 +1,117 @@ +/* + * Copyright 2019 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 { assert, expect } from 'chai'; +import { ReceiptRepository } from '../../src/infrastructure/ReceiptRepository'; +import { TransactionRepository } from '../../src/infrastructure/TransactionRepository'; +import { Account } from '../../src/model/account/Account'; +import { NetworkType } from '../../src/model/blockchain/NetworkType'; +import { PlainMessage } from '../../src/model/message/PlainMessage'; +import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { Deadline } from '../../src/model/transaction/Deadline'; +import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; +import { UInt64 } from '../../src/model/UInt64'; +import { BlockService } from '../../src/service/BlockService'; +import { IntegrationTestHelper } from '../infrastructure/IntegrationTestHelper'; + +describe('BlockService', () => { + const helper = new IntegrationTestHelper(); + let generationHash: string; + let account: Account; + let account2: Account; + let account3: Account; + let networkType: NetworkType; + let transactionHash: string; + let blockService: BlockService; + let transactionRepository: TransactionRepository; + let receiptRepository: ReceiptRepository; + + before(() => { + return helper.start().then(() => { + account = helper.account; + account2 = helper.account2; + account3 = helper.account3; + generationHash = helper.generationHash; + networkType = helper.networkType; + transactionRepository = helper.repositoryFactory.createTransactionRepository(); + receiptRepository = helper.repositoryFactory.createReceiptRepository(); + blockService = new BlockService(helper.repositoryFactory.createBlockRepository(), receiptRepository); + }); + }); + before(() => { + return helper.listener.open(); + }); + + after(() => { + helper.listener.close(); + }); + + /** + * ========================= + * Setup test data + * ========================= + */ + describe('Create a transfer', () => { + it('Announce TransferTransaction', () => { + const transferTransaction = TransferTransaction.create( + Deadline.create(), + account2.address, + [NetworkCurrencyMosaic.createAbsolute(1)], + PlainMessage.create('test-message'), + networkType, + helper.maxFee, + ); + + const signedTransaction = transferTransaction.signWith(account, generationHash); + transactionHash = signedTransaction.hash; + return helper.announce(signedTransaction); + }); + }); + + /** + * ========================= + * Test + * ========================= + */ + + describe('Validate transansaction', () => { + it('call block service', () => { + return transactionRepository.getTransaction(transactionHash).subscribe( + (transaction) => { + const transactionInfo = transaction.transactionInfo; + if (transactionInfo && transactionInfo.height !== undefined) { + const validationResult = blockService.validateTransactionInBlock(transactionHash, transactionInfo.height); + expect(validationResult).to.be.true; + } + assert(false, `Transaction (hash: ${transactionHash}) not found`); + }, + ); + }); + }); + + describe('Validate receipt', () => { + it('call block service', () => { + return receiptRepository.getBlockReceipts(UInt64.fromUint(1)).subscribe( + (statement) => { + const receipt = statement.transactionStatements[0]; + const validationResult = blockService.validateReceiptInBlock(receipt.generateHash(), UInt64.fromUint(1)); + expect(validationResult).to.be.true; + }, + ); + }); + }); + +}); diff --git a/src/service/BlockService.ts b/src/service/BlockService.ts new file mode 100644 index 0000000000..40b98983bc --- /dev/null +++ b/src/service/BlockService.ts @@ -0,0 +1,87 @@ +/* + * 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 { sha3_256 } from 'js-sha3'; +import { combineLatest, Observable } from 'rxjs'; +import { map } from 'rxjs/operators'; +import { BlockRepository } from '../infrastructure/BlockRepository'; +import { ReceiptRepository } from '../infrastructure/ReceiptRepository'; +import { MerklePathItem } from '../model/blockchain/MerklePathItem'; +import { UInt64 } from '../model/UInt64'; + +/** + * Transaction Service + */ +export class BlockService { + + /** + * Constructor + * @param blockRepository + * @param receiptRepository + */ + constructor(private readonly blockRepository: BlockRepository, private readonly receiptRepository: ReceiptRepository) { + } + + /** + * Validate transaction hash in block + * @param leaf transaction hash + * @param height block height + */ + public validateTransactionInBlock(leaf: string, height: UInt64): Observable { + const rootHashObservable = this.blockRepository.getBlockByHeight(height); + const merklePathItemObservable = this.blockRepository.getMerkleTransaction(height, leaf); + return combineLatest(rootHashObservable, merklePathItemObservable).pipe( + map((combined) => this.validateInBlock(leaf, combined[1].merklePath, combined[0].blockTransactionsHash)), + ); + } + + /** + * Validate receipt hash in block + * @param leaf receipt hash + * @param height block height + */ + public validateReceiptInBlock(leaf: string, height: UInt64): Observable { + const rootHashObservable = this.blockRepository.getBlockByHeight(height); + const merklePathItemObservable = this.receiptRepository.getMerkleReceipts(height, leaf); + return combineLatest(rootHashObservable, merklePathItemObservable).pipe( + map((combined) => this.validateInBlock(leaf, combined[1].merklePath, combined[0].blockReceiptsHash)), + ); + } + + /** + * @internal + * Validate leaf against merkle tree in block + * @param leaf Leaf hash in merkle tree + * @param merklePathItem Merkle path item array + * @param rootHash Block root hash + */ + private validateInBlock(leaf: string, merklePathItem: MerklePathItem[] = [], rootHash: string): boolean { + if (merklePathItem.length === 0) { + return leaf.toUpperCase() === rootHash.toUpperCase(); + } + const rootToCompare = merklePathItem.reduce((proofHash, pathItem) => { + const hasher = sha3_256.create(); + // Left + if (pathItem.position === 1) { + return hasher.update(Buffer.from(pathItem.hash + proofHash, 'hex')).hex(); + } else { + // Right + return hasher.update(Buffer.from(proofHash + pathItem.hash, 'hex')).hex(); + } + }, leaf); + return rootToCompare.toUpperCase() === rootHash.toUpperCase(); + } +} diff --git a/src/service/service.ts b/src/service/service.ts index fd6074d5c4..ed73b3ff59 100644 --- a/src/service/service.ts +++ b/src/service/service.ts @@ -20,3 +20,4 @@ export * from './AggregateTransactionService'; export * from './MetadataTransactionService'; export * from './MosaicRestrictionTransactionService'; export * from './TransactionService'; +export * from './BlockService'; From 0bb1832b9d9d3e60168e56e33a88c61d54de2611 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 18 Feb 2020 11:43:45 +0000 Subject: [PATCH 02/13] Updated tests to use async --- e2e/service/BlockService.spec.ts | 34 +++++++++++++------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/e2e/service/BlockService.spec.ts b/e2e/service/BlockService.spec.ts index 18df0cd34c..1bd2440e58 100644 --- a/e2e/service/BlockService.spec.ts +++ b/e2e/service/BlockService.spec.ts @@ -88,30 +88,24 @@ describe('BlockService', () => { */ describe('Validate transansaction', () => { - it('call block service', () => { - return transactionRepository.getTransaction(transactionHash).subscribe( - (transaction) => { - const transactionInfo = transaction.transactionInfo; - if (transactionInfo && transactionInfo.height !== undefined) { - const validationResult = blockService.validateTransactionInBlock(transactionHash, transactionInfo.height); - expect(validationResult).to.be.true; - } - assert(false, `Transaction (hash: ${transactionHash}) not found`); - }, - ); + it('call block service', async () => { + const transaction = await transactionRepository.getTransaction(transactionHash).toPromise(); + const transactionInfo = transaction.transactionInfo; + if (transactionInfo && transactionInfo.height !== undefined) { + const validationResult = await blockService.validateTransactionInBlock(transactionHash, transactionInfo.height).toPromise(); + expect(validationResult).to.be.true; + } else { + assert(false, `Transaction (hash: ${transactionHash}) not found`); + } }); }); describe('Validate receipt', () => { - it('call block service', () => { - return receiptRepository.getBlockReceipts(UInt64.fromUint(1)).subscribe( - (statement) => { - const receipt = statement.transactionStatements[0]; - const validationResult = blockService.validateReceiptInBlock(receipt.generateHash(), UInt64.fromUint(1)); - expect(validationResult).to.be.true; - }, - ); + it('call block service', async () => { + const statement = await receiptRepository.getBlockReceipts(UInt64.fromUint(1)).toPromise(); + const receipt = statement.transactionStatements[0]; + const validationResult = await blockService.validateReceiptInBlock(receipt.generateHash(), UInt64.fromUint(1)).toPromise(); + expect(validationResult).to.be.true; }); }); - }); From ec3833127b461f24ae4219a02bbb1fb15f5cfc06 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 18 Feb 2020 13:10:50 +0000 Subject: [PATCH 03/13] Added interface, --- e2e/service/BlockService.spec.ts | 8 +++--- src/service/BlockService.ts | 16 +++++++---- src/service/interfaces/IBlockService.ts | 38 +++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 src/service/interfaces/IBlockService.ts diff --git a/e2e/service/BlockService.spec.ts b/e2e/service/BlockService.spec.ts index 1bd2440e58..43c1b8ca38 100644 --- a/e2e/service/BlockService.spec.ts +++ b/e2e/service/BlockService.spec.ts @@ -48,7 +48,7 @@ describe('BlockService', () => { networkType = helper.networkType; transactionRepository = helper.repositoryFactory.createTransactionRepository(); receiptRepository = helper.repositoryFactory.createReceiptRepository(); - blockService = new BlockService(helper.repositoryFactory.createBlockRepository(), receiptRepository); + blockService = new BlockService(helper.repositoryFactory); }); }); before(() => { @@ -102,9 +102,9 @@ describe('BlockService', () => { describe('Validate receipt', () => { it('call block service', async () => { - const statement = await receiptRepository.getBlockReceipts(UInt64.fromUint(1)).toPromise(); - const receipt = statement.transactionStatements[0]; - const validationResult = await blockService.validateReceiptInBlock(receipt.generateHash(), UInt64.fromUint(1)).toPromise(); + const statements = await receiptRepository.getBlockReceipts(UInt64.fromUint(1)).toPromise(); + const statement = statements.transactionStatements[0]; + const validationResult = await blockService.validateStatementInBlock(statement.generateHash(), UInt64.fromUint(1)).toPromise(); expect(validationResult).to.be.true; }); }); diff --git a/src/service/BlockService.ts b/src/service/BlockService.ts index 40b98983bc..0c6a2c60d4 100644 --- a/src/service/BlockService.ts +++ b/src/service/BlockService.ts @@ -19,6 +19,7 @@ import { combineLatest, Observable } from 'rxjs'; import { map } from 'rxjs/operators'; import { BlockRepository } from '../infrastructure/BlockRepository'; import { ReceiptRepository } from '../infrastructure/ReceiptRepository'; +import { RepositoryFactory } from '../infrastructure/RepositoryFactory'; import { MerklePathItem } from '../model/blockchain/MerklePathItem'; import { UInt64 } from '../model/UInt64'; @@ -26,13 +27,16 @@ import { UInt64 } from '../model/UInt64'; * Transaction Service */ export class BlockService { + private readonly blockRepository: BlockRepository; + private readonly receiptRepository: ReceiptRepository; /** * Constructor - * @param blockRepository - * @param receiptRepository + * @param repositoryFactory */ - constructor(private readonly blockRepository: BlockRepository, private readonly receiptRepository: ReceiptRepository) { + constructor(public readonly repositoryFactory: RepositoryFactory) { + this.blockRepository = repositoryFactory.createBlockRepository(); + this.receiptRepository = repositoryFactory.createReceiptRepository(); } /** @@ -49,11 +53,11 @@ export class BlockService { } /** - * Validate receipt hash in block - * @param leaf receipt hash + * Validate statement hash in block + * @param leaf statement hash * @param height block height */ - public validateReceiptInBlock(leaf: string, height: UInt64): Observable { + public validateStatementInBlock(leaf: string, height: UInt64): Observable { const rootHashObservable = this.blockRepository.getBlockByHeight(height); const merklePathItemObservable = this.receiptRepository.getMerkleReceipts(height, leaf); return combineLatest(rootHashObservable, merklePathItemObservable).pipe( diff --git a/src/service/interfaces/IBlockService.ts b/src/service/interfaces/IBlockService.ts new file mode 100644 index 0000000000..e8d349c25b --- /dev/null +++ b/src/service/interfaces/IBlockService.ts @@ -0,0 +1,38 @@ +/* + * 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 { Observable } from 'rxjs'; +import { UInt64 } from '../../model/UInt64'; + +/** + * Block Service Interface + */ +export interface IBlockService { + + /** + * Validate transaction hash in block + * @param leaf transaction hash + * @param height block height + */ + validateTransactionInBlock(leaf: string, height: UInt64): Observable; + + /** + * Validate statement hash in block + * @param leaf statement hash + * @param height block height + */ + validateStatementInBlock(leaf: string, height: UInt64): Observable; +} From 5c6ef67bc8e2af27dbc85c1e9efd77326aa1737a Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 18 Feb 2020 14:34:57 +0000 Subject: [PATCH 04/13] Added unit tests --- test/service/BlockService.spec.ts | 111 ++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 test/service/BlockService.spec.ts diff --git a/test/service/BlockService.spec.ts b/test/service/BlockService.spec.ts new file mode 100644 index 0000000000..0fe6aa0068 --- /dev/null +++ b/test/service/BlockService.spec.ts @@ -0,0 +1,111 @@ +/* + * Copyright 2019 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 { of as observableOf } from 'rxjs'; +import { deepEqual, instance, mock, when } from 'ts-mockito'; +import { BlockRepository } from '../../src/infrastructure/BlockRepository'; +import { ReceiptRepository } from '../../src/infrastructure/ReceiptRepository'; +import { RepositoryFactory } from '../../src/infrastructure/RepositoryFactory'; +import { Account } from '../../src/model/account/Account'; +import { BlockInfo } from '../../src/model/blockchain/BlockInfo'; +import { MerklePathItem } from '../../src/model/blockchain/MerklePathItem'; +import { MerkleProofInfo } from '../../src/model/blockchain/MerkleProofInfo'; +import { NetworkType } from '../../src/model/blockchain/NetworkType'; +import { UInt64 } from '../../src/model/UInt64'; +import { BlockService } from '../../src/service/BlockService'; +import { TestingAccount } from '../conf/conf.spec'; + +describe('BlockService', () => { + + const mockBlockHash = 'D4EC16FCFE696EFDBF1820F68245C88135ACF4C6F888599C8E18BC09B9F08C7B'; + const leaf = '2717C8AAB0A21896D0C56375209E761F84383C3882F37A11D9D0159007263EB2'; + let blockService: BlockService; + let account: Account; + before(() => { + account = TestingAccount; + const mockBlockRepository = mock(); + const mockReceiptRepository = mock(); + const mockRepoFactory = mock(); + + when(mockBlockRepository.getBlockByHeight(deepEqual(UInt64.fromUint(1)))) + .thenReturn(observableOf(mockBlockInfo())); + when(mockBlockRepository.getBlockByHeight(deepEqual(UInt64.fromUint(2)))) + .thenReturn(observableOf(mockBlockInfo(true))); + when(mockBlockRepository.getMerkleTransaction(deepEqual(UInt64.fromUint(1)), leaf)) + .thenReturn(observableOf(mockMerklePath())); + when(mockBlockRepository.getMerkleTransaction(deepEqual(UInt64.fromUint(2)), leaf)) + .thenReturn(observableOf(mockMerklePath())); + when(mockReceiptRepository.getMerkleReceipts(deepEqual(UInt64.fromUint(1)), leaf)) + .thenReturn(observableOf(mockMerklePath())); + when(mockReceiptRepository.getMerkleReceipts(deepEqual(UInt64.fromUint(2)), leaf)) + .thenReturn(observableOf(mockMerklePath())); + const blockRepository = instance(mockBlockRepository); + const receiptRepository = instance(mockReceiptRepository); + + when(mockRepoFactory.createBlockRepository()).thenReturn(blockRepository); + when(mockRepoFactory.createReceiptRepository()).thenReturn(receiptRepository); + const repoFactory = instance(mockRepoFactory); + blockService = new BlockService(repoFactory); + }); + + it('should validate transaction', async () => { + const result = await blockService.validateTransactionInBlock(leaf, UInt64.fromUint(1)).toPromise(); + expect(result).to.be.true; + }); + + it('should validate transaction - wrong hash', async () => { + const result = await blockService.validateTransactionInBlock(leaf, UInt64.fromUint(2)).toPromise(); + expect(result).to.be.false; + }); + + it('should validate statement', async () => { + const result = await blockService.validateStatementInBlock(leaf, UInt64.fromUint(1)).toPromise(); + expect(result).to.be.true; + }); + + it('should validate statement - wrong hash', async () => { + const result = await blockService.validateStatementInBlock(leaf, UInt64.fromUint(2)).toPromise(); + expect(result).to.be.false; + }); + + function mockBlockInfo(isFake: boolean = false): BlockInfo { + if (isFake) { + return new BlockInfo( + 'hash', 'generationHash', UInt64.fromNumericString('0'), 1, 'signature', account.publicAccount, + NetworkType.MIJIN_TEST, 0, 0, UInt64.fromUint(1), UInt64.fromUint(0), UInt64.fromUint(0), 0, 'previousHash', + 'fakeHash', 'fakeHash', 'stateHash', undefined, + ); + } + return new BlockInfo( + 'hash', 'generationHash', UInt64.fromNumericString('0'), 1, 'signature', account.publicAccount, + NetworkType.MIJIN_TEST, 0, 0, UInt64.fromUint(1), UInt64.fromUint(0), UInt64.fromUint(0), 0, 'previousHash', + mockBlockHash, mockBlockHash, 'stateHash', undefined, + ); + } + + function mockMerklePath(): MerkleProofInfo { + return new MerkleProofInfo( + [ + new MerklePathItem(1, 'CDE45D740536E5361F392025A44B26546A138958E69CD6F18D22908F8F11ECF2'), + new MerklePathItem(2, '4EF55DAB8FEF9711B23DA71D2ACC58EFFF3969C3D572E06ACB898F99BED4827A'), + new MerklePathItem(1, '1BB95470065ED69D184948A0175EDC2EAB9E86A0CEB47B648A58A02A5445AF66'), + new MerklePathItem(2, 'D96B03809B8B198EFA5824191A979F7B85C0E9B7A6623DAFF38D4B2927EFDFB5'), + new MerklePathItem(2, '9981EBDBCA8E36BA4D4D4A450072026AC8C85BA6497666219E0E049BE3362E51'), + ], + ); + } +}); From c4878c757475d76ebc1351ad16f07164f9da6744 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 18 Feb 2020 14:38:21 +0000 Subject: [PATCH 05/13] Capture error after combineLatest --- src/service/BlockService.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/service/BlockService.ts b/src/service/BlockService.ts index 0c6a2c60d4..0c3b5ec955 100644 --- a/src/service/BlockService.ts +++ b/src/service/BlockService.ts @@ -15,8 +15,8 @@ */ import { sha3_256 } from 'js-sha3'; -import { combineLatest, Observable } from 'rxjs'; -import { map } from 'rxjs/operators'; +import { combineLatest, Observable, of } from 'rxjs'; +import { catchError, map } from 'rxjs/operators'; import { BlockRepository } from '../infrastructure/BlockRepository'; import { ReceiptRepository } from '../infrastructure/ReceiptRepository'; import { RepositoryFactory } from '../infrastructure/RepositoryFactory'; @@ -49,7 +49,7 @@ export class BlockService { const merklePathItemObservable = this.blockRepository.getMerkleTransaction(height, leaf); return combineLatest(rootHashObservable, merklePathItemObservable).pipe( map((combined) => this.validateInBlock(leaf, combined[1].merklePath, combined[0].blockTransactionsHash)), - ); + ).pipe(catchError(() => of(false))); } /** @@ -62,7 +62,7 @@ export class BlockService { const merklePathItemObservable = this.receiptRepository.getMerkleReceipts(height, leaf); return combineLatest(rootHashObservable, merklePathItemObservable).pipe( map((combined) => this.validateInBlock(leaf, combined[1].merklePath, combined[0].blockReceiptsHash)), - ); + ).pipe(catchError(() => of(false))); } /** From d4b2103ad655c97df2de9005d92661202c863e62 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 18 Feb 2020 18:50:02 +0000 Subject: [PATCH 06/13] Fixed #451 - Added positionEnum for merklePathItem - Changed to use comma separated string for transaction type filtering - Added generationHash in NodeInfo --- e2e/infrastructure/AccountHttp.spec.ts | 6 +- e2e/infrastructure/BlockHttp.spec.ts | 3 +- package-lock.json | 6 +- package.json | 2 +- src/infrastructure/AccountHttp.ts | 62 +++++++------ src/infrastructure/AccountRepository.ts | 12 +-- src/infrastructure/BlockHttp.ts | 2 +- src/infrastructure/Http.ts | 13 ++- src/infrastructure/MetadataHttp.ts | 6 +- src/infrastructure/NamespaceHttp.ts | 2 +- src/infrastructure/NodeHttp.ts | 1 + src/infrastructure/QueryParams.ts | 50 +++++----- .../TransactionSearchCriteria.ts | 45 +++++++++ src/model/blockchain/MerklePathItem.ts | 4 +- src/model/node/NodeInfo.ts | 5 + src/service/BlockService.ts | 92 +++++++++++++++++++ 16 files changed, 238 insertions(+), 73 deletions(-) create mode 100644 src/infrastructure/TransactionSearchCriteria.ts create mode 100644 src/service/BlockService.ts diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index 214cf281ed..1544377232 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -18,7 +18,7 @@ import { expect } from 'chai'; import { AccountRepository } from '../../src/infrastructure/AccountRepository'; import { MultisigRepository } from '../../src/infrastructure/MultisigRepository'; import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; -import { QueryParams } from '../../src/infrastructure/QueryParams'; +import { TransactionSearchCriteria } from '../../src/infrastructure/TransactionSearchCriteria'; import { Account } from '../../src/model/account/Account'; import { Address } from '../../src/model/account/Address'; import { PublicAccount } from '../../src/model/account/PublicAccount'; @@ -213,7 +213,7 @@ describe('AccountHttp', () => { describe('transactions', () => { it('should not return accounts when account does not exist', () => { - return accountRepository.getAccountInfo(Account.generateNewAccount(networkType).address).toPromise().then((r) => { + return accountRepository.getAccountInfo(Account.generateNewAccount(networkType).address).toPromise().then(() => { return Promise.reject('should fail!'); }, (err) => { const error = JSON.parse(err.message); @@ -227,7 +227,7 @@ describe('AccountHttp', () => { describe('transactions', () => { it('should call transactions successfully by type', async () => { const transactions = await accountRepository.getAccountTransactions( - publicAccount.address, {transactionType: TransactionType.TRANSFER} as QueryParams).toPromise(); + publicAccount.address, new TransactionSearchCriteria().setTransactionTypes([TransactionType.TRANSFER])).toPromise(); expect(transactions.length).to.be.greaterThan(0); transactions.forEach((t) => { expect(t.type).to.be.eq(TransactionType.TRANSFER); diff --git a/e2e/infrastructure/BlockHttp.spec.ts b/e2e/infrastructure/BlockHttp.spec.ts index 0d12e7a93b..d6d8298873 100644 --- a/e2e/infrastructure/BlockHttp.spec.ts +++ b/e2e/infrastructure/BlockHttp.spec.ts @@ -111,7 +111,8 @@ describe('BlockHttp', () => { }); it('should return block transactions data given height with paginated transactionId', async () => { - const transactions = await blockRepository.getBlockTransactions(UInt64.fromUint(1), new QueryParams(10, nextId)).toPromise(); + const transactions = await blockRepository.getBlockTransactions(UInt64.fromUint(1), + new QueryParams().setPageSize(10).setId(nextId)).toPromise(); expect(transactions[0].transactionInfo!.id).to.be.equal(firstId); expect(transactions.length).to.be.greaterThan(0); }); diff --git a/package-lock.json b/package-lock.json index 293580cdef..603c759bc9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3833,9 +3833,9 @@ } }, "nem2-sdk-openapi-typescript-node-client": { - "version": "0.8.3", - "resolved": "https://registry.npmjs.org/nem2-sdk-openapi-typescript-node-client/-/nem2-sdk-openapi-typescript-node-client-0.8.3.tgz", - "integrity": "sha512-e0B4FCi/uOjag84wpWTMAvR/J//JAmtP0agKg8fEBTiuD4gbGDKLLhfNtMCuMWdCw1nFX5aVVJrx3MakP/ad8w==", + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/nem2-sdk-openapi-typescript-node-client/-/nem2-sdk-openapi-typescript-node-client-0.8.4.tgz", + "integrity": "sha512-53DukFQUCKr0+bH1fm3fLzIT/v10lv5kdMqBHX4h4jDUslQeXnlBpPi/qX/XDmu2hyjwOWZa7hFzLhlt8xqhdQ==", "requires": { "@types/bluebird": "*", "@types/request": "*", diff --git a/package.json b/package.json index 9b33dcbc47..58b0f5b0ec 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "js-sha512": "^0.8.0", "long": "^4.0.0", "merkletreejs": "^0.1.7", - "nem2-sdk-openapi-typescript-node-client": "0.8.3", + "nem2-sdk-openapi-typescript-node-client": "0.8.4", "request": "^2.88.0", "request-promise-native": "^1.0.5", "ripemd160": "^2.0.2", diff --git a/src/infrastructure/AccountHttp.ts b/src/infrastructure/AccountHttp.ts index 7e3a6df1f3..0beabe0ce2 100644 --- a/src/infrastructure/AccountHttp.ts +++ b/src/infrastructure/AccountHttp.ts @@ -29,6 +29,7 @@ import { AccountRepository } from './AccountRepository'; import { Http } from './Http'; import { QueryParams } from './QueryParams'; import { CreateTransactionFromDTO } from './transaction/CreateTransactionFromDTO'; +import { TransactionSearchCriteria } from './TransactionSearchCriteria'; /** * Account http repository. @@ -108,6 +109,7 @@ export class AccountHttp extends Http implements AccountRepository { UInt64.fromNumericString(dto.account.importance), UInt64.fromNumericString(dto.account.importanceHeight), ); + } /** @@ -116,18 +118,18 @@ export class AccountHttp extends Http implements AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - public getAccountTransactions(address: Address, queryParams?: QueryParams): Observable { + public getAccountTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable { return observableFrom( this.accountRoutesApi.getAccountConfirmedTransactions(address.plain(), - this.queryParams(queryParams).pageSize, - this.queryParams(queryParams).id, - this.queryParams(queryParams).order, - this.queryParams(queryParams).transactionType)).pipe( - map(({body}) => body.map((transactionDTO) => { - return CreateTransactionFromDTO(transactionDTO); - })), - catchError((error) => throwError(this.errorHandling(error))), - ); + this.transactionSearchCriteria(queryParams).pageSize, + this.transactionSearchCriteria(queryParams).id, + this.transactionSearchCriteria(queryParams).ordering, + this.transactionSearchCriteria(queryParams).type)).pipe( + map(({body}) => body.map((transactionDTO) => { + return CreateTransactionFromDTO(transactionDTO); + })), + catchError((error) => throwError(this.errorHandling(error))), + ); } /** @@ -137,13 +139,13 @@ export class AccountHttp extends Http implements AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - public getAccountIncomingTransactions(address: Address, queryParams?: QueryParams): Observable { + public getAccountIncomingTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable { return observableFrom( this.accountRoutesApi.getAccountIncomingTransactions(address.plain(), - this.queryParams(queryParams).pageSize, - this.queryParams(queryParams).id, - this.queryParams(queryParams).order), - this.queryParams(queryParams).transactionType).pipe( + this.transactionSearchCriteria(queryParams).pageSize, + this.transactionSearchCriteria(queryParams).id, + this.transactionSearchCriteria(queryParams).ordering), + this.transactionSearchCriteria(queryParams).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), @@ -158,13 +160,13 @@ export class AccountHttp extends Http implements AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - public getAccountOutgoingTransactions(address: Address, queryParams?: QueryParams): Observable { + public getAccountOutgoingTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable { return observableFrom( this.accountRoutesApi.getAccountOutgoingTransactions(address.plain(), - this.queryParams(queryParams).pageSize, - this.queryParams(queryParams).id, - this.queryParams(queryParams).order), - this.queryParams(queryParams).transactionType).pipe( + this.transactionSearchCriteria(queryParams).pageSize, + this.transactionSearchCriteria(queryParams).id, + this.transactionSearchCriteria(queryParams).ordering), + this.transactionSearchCriteria(queryParams).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), @@ -180,13 +182,13 @@ export class AccountHttp extends Http implements AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - public getAccountUnconfirmedTransactions(address: Address, queryParams?: QueryParams): Observable { + public getAccountUnconfirmedTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable { return observableFrom( this.accountRoutesApi.getAccountUnconfirmedTransactions(address.plain(), - this.queryParams(queryParams).pageSize, - this.queryParams(queryParams).id, - this.queryParams(queryParams).order), - this.queryParams(queryParams).transactionType).pipe( + this.transactionSearchCriteria(queryParams).pageSize, + this.transactionSearchCriteria(queryParams).id, + this.transactionSearchCriteria(queryParams).ordering), + this.transactionSearchCriteria(queryParams).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), @@ -201,13 +203,13 @@ export class AccountHttp extends Http implements AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - public getAccountPartialTransactions(address: Address, queryParams?: QueryParams): Observable { + public getAccountPartialTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable { return observableFrom( this.accountRoutesApi.getAccountPartialTransactions(address.plain(), - this.queryParams(queryParams).pageSize, - this.queryParams(queryParams).id, - this.queryParams(queryParams).order), - this.queryParams(queryParams).transactionType).pipe( + this.transactionSearchCriteria(queryParams).pageSize, + this.transactionSearchCriteria(queryParams).id, + this.transactionSearchCriteria(queryParams).ordering), + this.transactionSearchCriteria(queryParams).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO) as AggregateTransaction; })), diff --git a/src/infrastructure/AccountRepository.ts b/src/infrastructure/AccountRepository.ts index 3e2ee11701..83126caed3 100644 --- a/src/infrastructure/AccountRepository.ts +++ b/src/infrastructure/AccountRepository.ts @@ -19,7 +19,7 @@ import {AccountInfo} from '../model/account/AccountInfo'; import {Address} from '../model/account/Address'; import {AggregateTransaction} from '../model/transaction/AggregateTransaction'; import {Transaction} from '../model/transaction/Transaction'; -import {QueryParams} from './QueryParams'; +import { TransactionSearchCriteria } from './TransactionSearchCriteria'; /** * Account interface repository. @@ -48,7 +48,7 @@ export interface AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - getAccountTransactions(address: Address, queryParams?: QueryParams): Observable; + getAccountTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable; /** * Gets an array of transactions for which an account is the recipient of a transaction. @@ -57,7 +57,7 @@ export interface AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - getAccountIncomingTransactions(address: Address, queryParams?: QueryParams): Observable; + getAccountIncomingTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable; /** * Gets an array of transactions for which an account is the sender a transaction. @@ -66,7 +66,7 @@ export interface AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - getAccountOutgoingTransactions(address: Address, queryParams?: QueryParams): Observable; + getAccountOutgoingTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable; /** * Gets the array of transactions for which an account is the sender or receiver and which have not yet been included in a block. @@ -76,7 +76,7 @@ export interface AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - getAccountUnconfirmedTransactions(address: Address, queryParams?: QueryParams): Observable; + getAccountUnconfirmedTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable; /** * Gets an array of transactions for which an account is the sender or has sign the transaction. @@ -85,5 +85,5 @@ export interface AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - getAccountPartialTransactions(address: Address, queryParams?: QueryParams): Observable; + getAccountPartialTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable; } diff --git a/src/infrastructure/BlockHttp.ts b/src/infrastructure/BlockHttp.ts index eb3a5d94a4..7877dd3600 100644 --- a/src/infrastructure/BlockHttp.ts +++ b/src/infrastructure/BlockHttp.ts @@ -73,7 +73,7 @@ export class BlockHttp extends Http implements BlockRepository { this.blockRoutesApi.getBlockTransactions(height.toString(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, - this.queryParams(queryParams).order)) + this.queryParams(queryParams).ordering)) .pipe(map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), diff --git a/src/infrastructure/Http.ts b/src/infrastructure/Http.ts index 4a1fcca01c..abd673cb77 100644 --- a/src/infrastructure/Http.ts +++ b/src/infrastructure/Http.ts @@ -20,6 +20,7 @@ import { from as observableFrom, Observable, of as observableOf, throwError } fr import { catchError, map, shareReplay } from 'rxjs/operators'; import { NetworkType } from '../model/blockchain/NetworkType'; import { QueryParams } from './QueryParams'; +import { TransactionSearchCriteria } from './TransactionSearchCriteria'; /** * Http extended by all http services @@ -52,8 +53,16 @@ export abstract class Http { return { pageSize: queryParams ? queryParams.pageSize : undefined, id: queryParams ? queryParams.id : undefined, - order: queryParams ? queryParams.order : undefined, - transactionType: queryParams ? queryParams.transactionType : undefined, + ordering: queryParams ? queryParams.order : undefined, + }; + } + + transactionSearchCriteria(queryParams?: TransactionSearchCriteria): any { + return { + pageSize: queryParams ? queryParams.pageSize : undefined, + id: queryParams ? queryParams.id : undefined, + ordering: queryParams ? queryParams.order : undefined, + type: queryParams ? queryParams.type : undefined, }; } diff --git a/src/infrastructure/MetadataHttp.ts b/src/infrastructure/MetadataHttp.ts index fbd3ca4577..221cfcbe8a 100644 --- a/src/infrastructure/MetadataHttp.ts +++ b/src/infrastructure/MetadataHttp.ts @@ -62,7 +62,7 @@ export class MetadataHttp extends Http implements MetadataRepository { this.metadataRoutesApi.getAccountMetadata(address.plain(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, - this.queryParams(queryParams).order)).pipe( + this.queryParams(queryParams).ordering)).pipe( map(({body}) => body.metadataEntries.map((metadataEntry) => { return this.buildMetadata(metadataEntry); })), @@ -112,7 +112,7 @@ export class MetadataHttp extends Http implements MetadataRepository { this.metadataRoutesApi.getMosaicMetadata(mosaicId.toHex(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, - this.queryParams(queryParams).order)).pipe( + this.queryParams(queryParams).ordering)).pipe( map(({body}) => body.metadataEntries.map((metadataEntry) => { return this.buildMetadata(metadataEntry); })), @@ -162,7 +162,7 @@ export class MetadataHttp extends Http implements MetadataRepository { this.metadataRoutesApi.getNamespaceMetadata(namespaceId.toHex(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, - this.queryParams(queryParams).order)).pipe( + this.queryParams(queryParams).ordering)).pipe( map(({body}) => body.metadataEntries.map((metadataEntry) => { return this.buildMetadata(metadataEntry); })), diff --git a/src/infrastructure/NamespaceHttp.ts b/src/infrastructure/NamespaceHttp.ts index 86b3bff8ea..8471e95d5d 100644 --- a/src/infrastructure/NamespaceHttp.ts +++ b/src/infrastructure/NamespaceHttp.ts @@ -152,7 +152,7 @@ export class NamespaceHttp extends Http implements NamespaceRepository { this.namespaceRoutesApi.getNamespacesFromAccount(address.plain(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, - this.queryParams(queryParams).order)).pipe( + this.queryParams(queryParams).ordering)).pipe( map(({body}) => body.namespaces.map((namespaceInfoDTO) => { return new NamespaceInfo( namespaceInfoDTO.meta.active, diff --git a/src/infrastructure/NodeHttp.ts b/src/infrastructure/NodeHttp.ts index 988c8758d5..ce74c0fe8b 100644 --- a/src/infrastructure/NodeHttp.ts +++ b/src/infrastructure/NodeHttp.ts @@ -56,6 +56,7 @@ export class NodeHttp extends Http implements NodeRepository { return observableFrom(this.nodeRoutesApi.getNodeInfo()).pipe( map(({body}) => new NodeInfo( body.publicKey, + body.networkGenerationHash, body.port, body.networkIdentifier, body.version, diff --git a/src/infrastructure/QueryParams.ts b/src/infrastructure/QueryParams.ts index fa3fc36b73..68722bd39f 100644 --- a/src/infrastructure/QueryParams.ts +++ b/src/infrastructure/QueryParams.ts @@ -30,32 +30,40 @@ export enum Order { * @since 1.0 */ export class QueryParams { - + /** + * Page size between 10 and 100, otherwise 10 + */ + public pageSize = 10; + /** + * Id after which we want objects to be returned + */ + public id?: string; + /** + * Order of transactions. + * DESC. Newer to older. + * ASC. Older to newer. + */ + public order: Order = Order.DESC; /** * Constructor * @param pageSize * @param id */ - constructor( - /** - * Page size between 10 and 100, otherwise 10 - */ - public readonly pageSize: number, - /** - * Id after which we want objects to be returned - */ - public readonly id?: string, - /** - * Order of transactions. - * DESC. Newer to older. - * ASC. Older to newer. - */ - public readonly order: Order = Order.DESC, - /** - * Transaction type filter - */ - public readonly transactionType?: TransactionType, - ) { + constructor() { + } + + public setPageSize(pageSize: number): QueryParams { this.pageSize = (pageSize >= 10 && pageSize <= 100) ? pageSize : 10; + return this; + } + + public setId(id?: string): QueryParams { + this.id = id; + return this; + } + + public setOrder(order: Order = Order.DESC): QueryParams { + this.order = order; + return this; } } diff --git a/src/infrastructure/TransactionSearchCriteria.ts b/src/infrastructure/TransactionSearchCriteria.ts new file mode 100644 index 0000000000..4db17aea42 --- /dev/null +++ b/src/infrastructure/TransactionSearchCriteria.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 { TransactionType } from '../model/transaction/TransactionType'; +import { QueryParams } from './QueryParams'; + + /** + * Transaction search criteria for filtering transaction list + */ +export class TransactionSearchCriteria extends QueryParams { + /** + * Transaction type filter + */ + public type?: string; + /** + * Constructor + * @param pageSize + * @param id + */ + constructor() { + super(); + } + + public setTransactionTypes(transactionTypes?: TransactionType[]): TransactionSearchCriteria { + if (!transactionTypes || transactionTypes.length === 0) { + this.type = undefined; + } else { + this.type = transactionTypes.map((type) => type.valueOf().toString()).join(','); + } + return this; + } +} diff --git a/src/model/blockchain/MerklePathItem.ts b/src/model/blockchain/MerklePathItem.ts index a004229c18..d87006889d 100644 --- a/src/model/blockchain/MerklePathItem.ts +++ b/src/model/blockchain/MerklePathItem.ts @@ -1,3 +1,5 @@ +import { PositionEnum } from "nem2-sdk-openapi-typescript-node-client/dist/model/positionEnum"; + /* * Copyright 2019 NEM * @@ -26,7 +28,7 @@ export class MerklePathItem { constructor(/** * The position */ - public readonly position?: number, + public readonly position?: PositionEnum, /** * The hash */ diff --git a/src/model/node/NodeInfo.ts b/src/model/node/NodeInfo.ts index 82947da021..1d0632366d 100644 --- a/src/model/node/NodeInfo.ts +++ b/src/model/node/NodeInfo.ts @@ -22,6 +22,7 @@ export class NodeInfo { /** * @param publicKey + * @param networkGenerationHash * @param port * @param networkIdentifier * @param version @@ -33,6 +34,10 @@ export class NodeInfo { * The public key used to identify the node. */ public readonly publicKey: string, + /** + * The network generation hash + */ + public readonly networkGenerationHash: string, /** * The port used for the communication. */ diff --git a/src/service/BlockService.ts b/src/service/BlockService.ts new file mode 100644 index 0000000000..ca07e40da4 --- /dev/null +++ b/src/service/BlockService.ts @@ -0,0 +1,92 @@ +/* + * 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 { sha3_256 } from 'js-sha3'; +import { combineLatest, Observable, of } from 'rxjs'; +import { catchError, map } from 'rxjs/operators'; +import { BlockRepository } from '../infrastructure/BlockRepository'; +import { ReceiptRepository } from '../infrastructure/ReceiptRepository'; +import { RepositoryFactory } from '../infrastructure/RepositoryFactory'; +import { MerklePathItem } from '../model/blockchain/MerklePathItem'; +import { UInt64 } from '../model/UInt64'; +import { PositionEnum } from 'nem2-sdk-openapi-typescript-node-client/dist/model/positionEnum'; + +/** + * Transaction Service + */ +export class BlockService { + private readonly blockRepository: BlockRepository; + private readonly receiptRepository: ReceiptRepository; + + /** + * Constructor + * @param repositoryFactory + */ + constructor(public readonly repositoryFactory: RepositoryFactory) { + this.blockRepository = repositoryFactory.createBlockRepository(); + this.receiptRepository = repositoryFactory.createReceiptRepository(); + } + + /** + * Validate transaction hash in block + * @param leaf transaction hash + * @param height block height + */ + public validateTransactionInBlock(leaf: string, height: UInt64): Observable { + const rootHashObservable = this.blockRepository.getBlockByHeight(height); + const merklePathItemObservable = this.blockRepository.getMerkleTransaction(height, leaf); + return combineLatest(rootHashObservable, merklePathItemObservable).pipe( + map((combined) => this.validateInBlock(leaf, combined[1].merklePath, combined[0].blockTransactionsHash)), + ).pipe(catchError(() => of(false))); + } + + /** + * Validate statement hash in block + * @param leaf statement hash + * @param height block height + */ + public validateStatementInBlock(leaf: string, height: UInt64): Observable { + const rootHashObservable = this.blockRepository.getBlockByHeight(height); + const merklePathItemObservable = this.receiptRepository.getMerkleReceipts(height, leaf); + return combineLatest(rootHashObservable, merklePathItemObservable).pipe( + map((combined) => this.validateInBlock(leaf, combined[1].merklePath, combined[0].blockReceiptsHash)), + ).pipe(catchError(() => of(false))); + } + + /** + * @internal + * Validate leaf against merkle tree in block + * @param leaf Leaf hash in merkle tree + * @param merklePathItem Merkle path item array + * @param rootHash Block root hash + */ + private validateInBlock(leaf: string, merklePathItem: MerklePathItem[] = [], rootHash: string): boolean { + if (merklePathItem.length === 0) { + return leaf.toUpperCase() === rootHash.toUpperCase(); + } + const rootToCompare = merklePathItem.reduce((proofHash, pathItem) => { + const hasher = sha3_256.create(); + // Left + if (pathItem.position !== undefined && pathItem.position === PositionEnum.Left) { + return hasher.update(Buffer.from(pathItem.hash + proofHash, 'hex')).hex(); + } else { + // Right + return hasher.update(Buffer.from(proofHash + pathItem.hash, 'hex')).hex(); + } + }, leaf); + return rootToCompare.toUpperCase() === rootHash.toUpperCase(); + } +} From 5095c65eec9b591a0ce0c7a7411ac1fbf695838d Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 18 Feb 2020 19:12:51 +0000 Subject: [PATCH 07/13] Updated ticker - Changed NetworkCurrencyMosaic -> NetworkCurrencyLocal - Added NetworkCurrencyPublic --- e2e/infrastructure/AccountHttp.spec.ts | 4 +- e2e/infrastructure/BlockHttp.spec.ts | 4 +- e2e/infrastructure/Listener.spec.ts | 16 +-- e2e/infrastructure/NamespaceHttp.spec.ts | 4 +- e2e/infrastructure/TransactionHttp.spec.ts | 58 +++++------ e2e/infrastructure/UnresolvedMapping.spec.ts | 8 +- e2e/service/TransactionService.spec.ts | 6 +- ...TransactionService_AggregateBonded.spec.ts | 12 +-- src/infrastructure/infrastructure.ts | 1 + src/model/model.ts | 5 +- ...rencyMosaic.ts => NetworkCurrencyLocal.ts} | 24 ++--- src/model/mosaic/NetworkCurrencyPublic.ts | 98 +++++++++++++++++++ ...arvestMosaic.ts => NetworkHarvestLocal.ts} | 24 ++--- test/core/utils/TransactionMapping.spec.ts | 22 ++--- .../SerializeTransactionToJSON.spec.ts | 8 +- test/model/message/EncryptedMessage.spec.ts | 4 +- test/model/mosaic/NetworkCurrency.spec.ts | 69 +++++++++++++ .../mosaic/NetworkCurrencyMosaic.spec.ts | 45 --------- ...ic.spec.ts => NetworkHarvestLocal.spec.ts} | 18 ++-- .../transaction/AggregateTransaction.spec.ts | 4 +- .../transaction/HashLockTransaction.spec.ts | 8 +- .../transaction/LockFundsTransaction.spec.ts | 18 ++-- .../transaction/SecretLockTransaction.spec.ts | 40 ++++---- .../transaction/TransferTransaction.spec.ts | 24 ++--- 24 files changed, 324 insertions(+), 200 deletions(-) rename src/model/mosaic/{NetworkCurrencyMosaic.ts => NetworkCurrencyLocal.ts} (68%) create mode 100644 src/model/mosaic/NetworkCurrencyPublic.ts rename src/model/mosaic/{NetworkHarvestMosaic.ts => NetworkHarvestLocal.ts} (69%) create mode 100644 test/model/mosaic/NetworkCurrency.spec.ts delete mode 100644 test/model/mosaic/NetworkCurrencyMosaic.spec.ts rename test/model/mosaic/{NetworkHarvestMosaic.spec.ts => NetworkHarvestLocal.spec.ts} (65%) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index 1544377232..86754b93aa 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -24,7 +24,7 @@ import { Address } from '../../src/model/account/Address'; import { PublicAccount } from '../../src/model/account/PublicAccount'; import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { PlainMessage } from '../../src/model/message/PlainMessage'; -import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction'; @@ -92,7 +92,7 @@ describe('AccountHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, diff --git a/e2e/infrastructure/BlockHttp.spec.ts b/e2e/infrastructure/BlockHttp.spec.ts index d6d8298873..088bc62ce2 100644 --- a/e2e/infrastructure/BlockHttp.spec.ts +++ b/e2e/infrastructure/BlockHttp.spec.ts @@ -23,7 +23,7 @@ import { ReceiptRepository } from '../../src/infrastructure/ReceiptRepository'; import { Account } from '../../src/model/account/Account'; import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { PlainMessage } from '../../src/model/message/PlainMessage'; -import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { Deadline } from '../../src/model/transaction/Deadline'; import { TransactionInfo } from '../../src/model/transaction/TransactionInfo'; import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; @@ -73,7 +73,7 @@ describe('BlockHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, diff --git a/e2e/infrastructure/Listener.spec.ts b/e2e/infrastructure/Listener.spec.ts index 5fcfbfea62..287c19a5b6 100644 --- a/e2e/infrastructure/Listener.spec.ts +++ b/e2e/infrastructure/Listener.spec.ts @@ -24,7 +24,7 @@ import { NetworkType } from '../../src/model/blockchain/NetworkType'; 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 { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction'; import { Deadline } from '../../src/model/transaction/Deadline'; @@ -45,7 +45,7 @@ describe('Listener', () => { let namespaceRepository: NamespaceRepository; let generationHash: string; let networkType: NetworkType; - const networkCurrencyMosaicId: NamespaceId = NetworkCurrencyMosaic.NAMESPACE_ID; + const NetworkCurrencyLocalId: NamespaceId = NetworkCurrencyLocal.NAMESPACE_ID; let transactionRepository: TransactionRepository; before(() => { @@ -100,7 +100,7 @@ describe('Listener', () => { mosaicId: MosaicId | NamespaceId) => { const lockFundsTransaction = LockFundsTransaction.create( Deadline.create(), - new Mosaic(mosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), + new Mosaic(mosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))), UInt64.fromUint(1000), signedAggregatedTransaction, networkType, helper.maxFee, @@ -180,7 +180,7 @@ describe('Listener', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), cosignAccount1.address, - [new Mosaic(networkCurrencyMosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY)))], + [new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY)))], PlainMessage.create('test-message'), networkType, helper.maxFee, ); @@ -220,7 +220,7 @@ describe('Listener', () => { it('aggregateBondedTransactionsAdded', (done) => { const signedAggregatedTx = createSignedAggregatedBondTransaction(multisigAccount, account, account2.address); - createHashLockTransactionAndAnnounce(signedAggregatedTx, account, networkCurrencyMosaicId); + createHashLockTransactionAndAnnounce(signedAggregatedTx, account, NetworkCurrencyLocalId); helper.listener.aggregateBondedAdded(account.address).subscribe(() => { done(); }); @@ -239,7 +239,7 @@ describe('Listener', () => { const signedAggregatedTx = createSignedAggregatedBondTransaction(multisigAccount, cosignAccount1, account2.address); - createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, networkCurrencyMosaicId); + createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, NetworkCurrencyLocalId); helper.listener.confirmed(cosignAccount1.address).subscribe(() => { helper.listener.aggregateBondedRemoved(cosignAccount1.address).subscribe(() => { done(); @@ -274,7 +274,7 @@ describe('Listener', () => { const signedAggregatedTx = createSignedAggregatedBondTransaction(multisigAccount, cosignAccount1, account2.address); - createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, networkCurrencyMosaicId); + createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, NetworkCurrencyLocalId); helper.listener.cosignatureAdded(cosignAccount1.address).subscribe(() => { done(); }); @@ -341,7 +341,7 @@ describe('Listener', () => { describe('Transactions Status', () => { it('transactionStatusGiven', () => { - const mosaics = [NetworkCurrencyMosaic.createRelative(1000000000000)]; + const mosaics = [NetworkCurrencyLocal.createRelative(1000000000000)]; const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, diff --git a/e2e/infrastructure/NamespaceHttp.spec.ts b/e2e/infrastructure/NamespaceHttp.spec.ts index b32a912997..2f99342369 100644 --- a/e2e/infrastructure/NamespaceHttp.spec.ts +++ b/e2e/infrastructure/NamespaceHttp.spec.ts @@ -18,7 +18,7 @@ import { expect } from 'chai'; import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; import { Account } from '../../src/model/account/Account'; import { Address } from '../../src/model/account/Address'; -import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction'; @@ -28,7 +28,7 @@ import { UInt64 } from '../../src/model/UInt64'; import { IntegrationTestHelper } from './IntegrationTestHelper'; describe('NamespaceHttp', () => { - const defaultNamespaceId = NetworkCurrencyMosaic.NAMESPACE_ID; + const defaultNamespaceId = NetworkCurrencyLocal.NAMESPACE_ID; let namespaceId: NamespaceId; let namespaceRepository: NamespaceRepository; let account: Account; diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 9b081b9b24..b0da9ac687 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -35,7 +35,7 @@ import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce'; import { MosaicSupplyChangeAction } from '../../src/model/mosaic/MosaicSupplyChangeAction'; -import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AccountRestrictionModificationAction } from '../../src/model/restriction/AccountRestrictionModificationAction'; @@ -94,7 +94,7 @@ describe('TransactionHttp', () => { let generationHash: string; let networkType: NetworkType; let mosaicId: MosaicId; - let networkCurrencyMosaicId: MosaicId; + let NetworkCurrencyLocalId: MosaicId; let namespaceId: NamespaceId; let harvestingAccount: Account; let transactionRepository: TransactionRepository; @@ -134,7 +134,7 @@ describe('TransactionHttp', () => { describe('Get network currency mosaic id', () => { it('get mosaicId', async () => { - networkCurrencyMosaicId = + NetworkCurrencyLocalId = (await namespaceRepository.getLinkedMosaicId(new NamespaceId('cat.currency')).toPromise()) as MosaicId; }); }); @@ -386,7 +386,7 @@ describe('TransactionHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, ); @@ -399,7 +399,7 @@ describe('TransactionHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, ); @@ -672,7 +672,7 @@ describe('TransactionHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), namespaceId, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, ); @@ -772,7 +772,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const hashLockTransaction = HashLockTransaction.create(Deadline.create(), - new Mosaic(new NamespaceId('cat.currency'), UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), + new Mosaic(new NamespaceId('cat.currency'), UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))), UInt64.fromUint(10000), signedTransaction, networkType, helper.maxFee); @@ -812,7 +812,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), - new Mosaic(networkCurrencyMosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), + new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))), UInt64.fromUint(10000), signedTransaction, networkType, helper.maxFee); @@ -831,7 +831,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), - new Mosaic(networkCurrencyMosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), + new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))), UInt64.fromUint(10), signedTransaction, networkType, helper.maxFee); @@ -871,7 +871,7 @@ describe('TransactionHttp', () => { it('standalone', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), @@ -893,7 +893,7 @@ describe('TransactionHttp', () => { it('aggregate', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), @@ -912,7 +912,7 @@ describe('TransactionHttp', () => { it('standalone', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Keccak_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), @@ -927,7 +927,7 @@ describe('TransactionHttp', () => { it('aggregate', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Keccak_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), @@ -948,7 +948,7 @@ describe('TransactionHttp', () => { const secret = CryptoJS.RIPEMD160(CryptoJS.SHA256(secretSeed).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_160, secret, @@ -965,7 +965,7 @@ describe('TransactionHttp', () => { const secret = CryptoJS.RIPEMD160(CryptoJS.SHA256(secretSeed).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_160, secret, @@ -984,7 +984,7 @@ describe('TransactionHttp', () => { it('standalone', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), @@ -999,7 +999,7 @@ describe('TransactionHttp', () => { it('aggregate', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), @@ -1023,7 +1023,7 @@ describe('TransactionHttp', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(1, ChronoUnit.HOURS), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(11), HashType.Op_Sha3_256, secret, @@ -1061,7 +1061,7 @@ describe('TransactionHttp', () => { const proof = convert.uint8ToHex(secretSeed); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, secret, @@ -1094,7 +1094,7 @@ describe('TransactionHttp', () => { const proof = convert.uint8ToHex(secretSeed); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Keccak_256, secret, @@ -1123,7 +1123,7 @@ describe('TransactionHttp', () => { const proof = convert.uint8ToHex(secretSeed); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Keccak_256, secret, @@ -1157,7 +1157,7 @@ describe('TransactionHttp', () => { const proof = secretSeed; const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_160, secret, @@ -1189,7 +1189,7 @@ describe('TransactionHttp', () => { const proof = secretSeed; const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_160, secret, @@ -1223,7 +1223,7 @@ describe('TransactionHttp', () => { const proof = secretSeed; const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_256, secret, @@ -1254,7 +1254,7 @@ describe('TransactionHttp', () => { const proof = secretSeed; const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_256, secret, @@ -1288,8 +1288,8 @@ describe('TransactionHttp', () => { // AliceAccount: account // BobAccount: account - const sendAmount = NetworkCurrencyMosaic.createRelative(1000); - const backAmount = NetworkCurrencyMosaic.createRelative(1); + const sendAmount = NetworkCurrencyLocal.createRelative(1000); + const backAmount = NetworkCurrencyLocal.createRelative(1); const aliceTransferTransaction = TransferTransaction.create(Deadline.create(), account2.address, [sendAmount], PlainMessage.create('payout'), networkType, helper.maxFee); @@ -1384,7 +1384,7 @@ describe('TransactionHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, ); @@ -1399,7 +1399,7 @@ describe('TransactionHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, - [NetworkCurrencyMosaic.createRelative(1)], + [NetworkCurrencyLocal.createRelative(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, ); diff --git a/e2e/infrastructure/UnresolvedMapping.spec.ts b/e2e/infrastructure/UnresolvedMapping.spec.ts index 4b5a6f1e0c..e8713e202b 100644 --- a/e2e/infrastructure/UnresolvedMapping.spec.ts +++ b/e2e/infrastructure/UnresolvedMapping.spec.ts @@ -24,7 +24,7 @@ import { PlainMessage } from '../../src/model/message/PlainMessage'; import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce'; -import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { MosaicRestrictionType } from '../../src/model/restriction/MosaicRestrictionType'; @@ -50,7 +50,7 @@ describe('TransactionHttp', () => { let generationHash: string; let networkType: NetworkType; let mosaicId: MosaicId; - let networkCurrencyMosaicId: MosaicId; + let NetworkCurrencyLocalId: MosaicId; let namespaceIdAddress: NamespaceId; let namespaceIdMosaic: NamespaceId; @@ -79,7 +79,7 @@ describe('TransactionHttp', () => { */ describe('Get network currency mosaic id', () => { it('get mosaicId', async () => { - networkCurrencyMosaicId = + NetworkCurrencyLocalId = (await namespaceRepository.getLinkedMosaicId(new NamespaceId('cat.currency')).toPromise()) as MosaicId; }); }); @@ -259,7 +259,7 @@ describe('TransactionHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, ); diff --git a/e2e/service/TransactionService.spec.ts b/e2e/service/TransactionService.spec.ts index afaae119ff..19aadb7c3c 100644 --- a/e2e/service/TransactionService.spec.ts +++ b/e2e/service/TransactionService.spec.ts @@ -26,7 +26,7 @@ import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce'; import { MosaicSupplyChangeAction } from '../../src/model/mosaic/MosaicSupplyChangeAction'; -import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction'; @@ -199,7 +199,7 @@ describe('TransactionService', () => { Deadline.create(), addressAlias, [ - NetworkCurrencyMosaic.createAbsolute(1), + NetworkCurrencyLocal.createAbsolute(1), new Mosaic(mosaicAlias, UInt64.fromUint(1)), ], PlainMessage.create('test-message'), @@ -353,7 +353,7 @@ describe('TransactionService', () => { Deadline.create(), addressAlias, [ - NetworkCurrencyMosaic.createAbsolute(1), + NetworkCurrencyLocal.createAbsolute(1), new Mosaic(mosaicAlias, UInt64.fromUint(1)), ], PlainMessage.create('test-message'), diff --git a/e2e/service/TransactionService_AggregateBonded.spec.ts b/e2e/service/TransactionService_AggregateBonded.spec.ts index 5b5a50f493..b4c4ec81d6 100644 --- a/e2e/service/TransactionService_AggregateBonded.spec.ts +++ b/e2e/service/TransactionService_AggregateBonded.spec.ts @@ -23,7 +23,7 @@ import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { PlainMessage } from '../../src/model/message/PlainMessage'; import { Mosaic } from '../../src/model/mosaic/Mosaic'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; -import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction'; import { Deadline } from '../../src/model/transaction/Deadline'; @@ -49,7 +49,7 @@ describe('TransactionService', () => { let generationHash: string; let networkType: NetworkType; let transactionService: TransactionService; - let networkCurrencyMosaicId: MosaicId; + let NetworkCurrencyLocalId: MosaicId; before(() => { return helper.start().then(() => { @@ -100,7 +100,7 @@ describe('TransactionService', () => { describe('Get network currency mosaic id', () => { it('get mosaicId', () => { return namespaceRepository.getLinkedMosaicId(new NamespaceId('cat.currency')).toPromise().then((networkMosaicId: MosaicId) => { - networkCurrencyMosaicId = networkMosaicId; + NetworkCurrencyLocalId = networkMosaicId; }); }); }); @@ -144,7 +144,7 @@ describe('TransactionService', () => { Deadline.create(), account2.address, [ - NetworkCurrencyMosaic.createAbsolute(1), + NetworkCurrencyLocal.createAbsolute(1), ], PlainMessage.create('test-message'), networkType, helper.maxFee, @@ -164,7 +164,7 @@ describe('TransactionService', () => { const signedAggregatedTransaction = createSignedAggregatedBondTransaction(multisigAccount, account, account2.address); const lockFundsTransaction = LockFundsTransaction.create( Deadline.create(), - new Mosaic(networkCurrencyMosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), + new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))), UInt64.fromUint(1000), signedAggregatedTransaction, networkType, helper.maxFee, @@ -184,7 +184,7 @@ describe('TransactionService', () => { const signedAggregatedTransaction = createSignedAggregatedBondTransaction(multisigAccount, account, account2.address); const lockFundsTransaction = LockFundsTransaction.create( Deadline.create(), - new Mosaic(networkCurrencyMosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), + new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))), UInt64.fromUint(1000), signedAggregatedTransaction, networkType, helper.maxFee, diff --git a/src/infrastructure/infrastructure.ts b/src/infrastructure/infrastructure.ts index 3a297391a7..9ac061be35 100644 --- a/src/infrastructure/infrastructure.ts +++ b/src/infrastructure/infrastructure.ts @@ -47,3 +47,4 @@ export * from './RepositoryFactory'; export * from './RestrictionAccountRepository'; export * from './RestrictionMosaicRepository'; export * from './TransactionRepository'; +export * from './TransactionSearchCriteria'; diff --git a/src/model/model.ts b/src/model/model.ts index ee624e7d69..4f97aa7e4a 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -49,8 +49,9 @@ export * from './mosaic/MosaicSupplyChangeAction'; export * from './mosaic/MosaicFlags'; export * from '../service/MosaicView'; export * from '../service/MosaicAmountView'; -export * from './mosaic/NetworkCurrencyMosaic'; -export * from './mosaic/NetworkHarvestMosaic'; +export * from './mosaic/NetworkCurrencyLocal'; +export * from './mosaic/NetworkCurrencyPublic'; +export * from './mosaic/NetworkHarvestLocal'; export * from './mosaic/MosaicNames'; // Mosaic diff --git a/src/model/mosaic/NetworkCurrencyMosaic.ts b/src/model/mosaic/NetworkCurrencyLocal.ts similarity index 68% rename from src/model/mosaic/NetworkCurrencyMosaic.ts rename to src/model/mosaic/NetworkCurrencyLocal.ts index fb2ebc2722..c1a6e34dc9 100644 --- a/src/model/mosaic/NetworkCurrencyMosaic.ts +++ b/src/model/mosaic/NetworkCurrencyLocal.ts @@ -20,14 +20,14 @@ import {Mosaic} from './Mosaic'; import {MosaicId} from './MosaicId'; /** - * NetworkCurrencyMosaic mosaic + * NetworkCurrencyLocal mosaic for local test network (local bootstrap server) * * This represents the per-network currency mosaic. This mosaicId is aliased * with namespace name `cat.currency`. * * @since 0.10.2 */ -export class NetworkCurrencyMosaic extends Mosaic { +export class NetworkCurrencyLocal extends Mosaic { /** * namespaceId of `currency` namespace. @@ -66,33 +66,33 @@ export class NetworkCurrencyMosaic extends Mosaic { * @param amount */ private constructor(amount: UInt64) { - super(NetworkCurrencyMosaic.NAMESPACE_ID, amount); + super(NetworkCurrencyLocal.NAMESPACE_ID, amount); } /** - * Create NetworkCurrencyMosaic with using NetworkCurrencyMosaic as unit. + * Create NetworkCurrencyLocal with using NetworkCurrencyLocal as unit. * * @param amount - * @returns {NetworkCurrencyMosaic} + * @returns {NetworkCurrencyLocal} */ public static createRelative(amount: UInt64 | number) { if (typeof amount === 'number') { - return new NetworkCurrencyMosaic(UInt64.fromUint(amount * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))); + return new NetworkCurrencyLocal(UInt64.fromUint(amount * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))); } - return new NetworkCurrencyMosaic(UInt64.fromUint((amount as UInt64).compact() * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))); + return new NetworkCurrencyLocal(UInt64.fromUint((amount as UInt64).compact() * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))); } /** - * Create NetworkCurrencyMosaic with using micro NetworkCurrencyMosaic as unit, - * 1 NetworkCurrencyMosaic = 1000000 micro NetworkCurrencyMosaic. + * Create NetworkCurrencyLocal with using micro NetworkCurrencyLocal as unit, + * 1 NetworkCurrencyLocal = 1000000 micro NetworkCurrencyLocal. * * @param amount - * @returns {NetworkCurrencyMosaic} + * @returns {NetworkCurrencyLocal} */ public static createAbsolute(amount: UInt64 | number) { if (typeof amount === 'number') { - return new NetworkCurrencyMosaic(UInt64.fromUint(amount)); + return new NetworkCurrencyLocal(UInt64.fromUint(amount)); } - return new NetworkCurrencyMosaic(amount as UInt64); + return new NetworkCurrencyLocal(amount as UInt64); } } diff --git a/src/model/mosaic/NetworkCurrencyPublic.ts b/src/model/mosaic/NetworkCurrencyPublic.ts new file mode 100644 index 0000000000..bb9b39bf04 --- /dev/null +++ b/src/model/mosaic/NetworkCurrencyPublic.ts @@ -0,0 +1,98 @@ +/* + * Copyright 2019 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 {UInt64} from '../UInt64'; +import {Mosaic} from './Mosaic'; +import {MosaicId} from './MosaicId'; + +/** + * NetworkCurrencyPublic mosaic for public / Public_test network + * + * This represents the per-network currency mosaic. This mosaicId is aliased + * with namespace name `symbol.xym`. + * + * @since 0.10.2 + */ +export class NetworkCurrencyPublic extends Mosaic { + + /** + * namespaceId of `currency` namespace. + * + * @type {Id} + */ + public static NAMESPACE_ID = new NamespaceId('symbol.xym'); + + /** + * Divisiblity + * @type {number} + */ + public static DIVISIBILITY = 6; + + /** + * Initial supply + * @type {number} + */ + public static INITIAL_SUPPLY = 8999999998; + + /** + * Is tranferable + * @type {boolean} + */ + public static TRANSFERABLE = true; + + /** + * Is Supply mutable + * @type {boolean} + */ + public static SUPPLY_MUTABLE = false; + + /** + * constructor + * @param owner + * @param amount + */ + private constructor(amount: UInt64) { + super(NetworkCurrencyPublic.NAMESPACE_ID, amount); + } + + /** + * Create NetworkCurrencyPublic with using NetworkCurrencyPublic as unit. + * + * @param amount + * @returns {NetworkCurrencyPublic} + */ + public static createRelative(amount: UInt64 | number) { + if (typeof amount === 'number') { + return new NetworkCurrencyPublic(UInt64.fromUint(amount * Math.pow(10, NetworkCurrencyPublic.DIVISIBILITY))); + } + return new NetworkCurrencyPublic(UInt64.fromUint((amount as UInt64).compact() * Math.pow(10, NetworkCurrencyPublic.DIVISIBILITY))); + } + + /** + * Create NetworkCurrencyPublic with using micro NetworkCurrencyPublic as unit, + * 1 NetworkCurrencyPublic = 1000000 micro NetworkCurrencyPublic. + * + * @param amount + * @returns {NetworkCurrencyPublic} + */ + public static createAbsolute(amount: UInt64 | number) { + if (typeof amount === 'number') { + return new NetworkCurrencyPublic(UInt64.fromUint(amount)); + } + return new NetworkCurrencyPublic(amount as UInt64); + } +} diff --git a/src/model/mosaic/NetworkHarvestMosaic.ts b/src/model/mosaic/NetworkHarvestLocal.ts similarity index 69% rename from src/model/mosaic/NetworkHarvestMosaic.ts rename to src/model/mosaic/NetworkHarvestLocal.ts index f9df23fb98..c600988cf1 100644 --- a/src/model/mosaic/NetworkHarvestMosaic.ts +++ b/src/model/mosaic/NetworkHarvestLocal.ts @@ -19,14 +19,14 @@ import {Mosaic} from './Mosaic'; import {MosaicId} from './MosaicId'; /** - * NetworkHarvestMosaic mosaic + * NetworkHarvestLocal mosaic * * This represents the per-network harvest mosaic. This mosaicId is aliased * with namespace name `cat.harvest`. * * @since 0.10.2 */ -export class NetworkHarvestMosaic extends Mosaic { +export class NetworkHarvestLocal extends Mosaic { /** * namespaceId of `currency` namespace. @@ -65,33 +65,33 @@ export class NetworkHarvestMosaic extends Mosaic { * @param amount */ private constructor(amount: UInt64) { - super(NetworkHarvestMosaic.NAMESPACE_ID, amount); + super(NetworkHarvestLocal.NAMESPACE_ID, amount); } /** - * Create NetworkHarvestMosaic with using NetworkHarvestMosaic as unit. + * Create NetworkHarvestLocal with using NetworkHarvestLocal as unit. * * @param amount - * @returns {NetworkHarvestMosaic} + * @returns {NetworkHarvestLocal} */ public static createRelative(amount: UInt64 | number) { if (typeof amount === 'number') { - return new NetworkHarvestMosaic(UInt64.fromUint(amount * Math.pow(10, NetworkHarvestMosaic.DIVISIBILITY))); + return new NetworkHarvestLocal(UInt64.fromUint(amount * Math.pow(10, NetworkHarvestLocal.DIVISIBILITY))); } - return new NetworkHarvestMosaic(UInt64.fromUint((amount as UInt64).compact() * Math.pow(10, NetworkHarvestMosaic.DIVISIBILITY))); + return new NetworkHarvestLocal(UInt64.fromUint((amount as UInt64).compact() * Math.pow(10, NetworkHarvestLocal.DIVISIBILITY))); } /** - * Create NetworkHarvestMosaic with using micro NetworkHarvestMosaic as unit, - * 1 NetworkHarvestMosaic = 1000000 micro NetworkHarvestMosaic. + * Create NetworkHarvestLocal with using micro NetworkHarvestLocal as unit, + * 1 NetworkHarvestLocal = 1000000 micro NetworkHarvestLocal. * * @param amount - * @returns {NetworkHarvestMosaic} + * @returns {NetworkHarvestLocal} */ public static createAbsolute(amount: UInt64 | number) { if (typeof amount === 'number') { - return new NetworkHarvestMosaic(UInt64.fromUint(amount)); + return new NetworkHarvestLocal(UInt64.fromUint(amount)); } - return new NetworkHarvestMosaic(amount as UInt64); + return new NetworkHarvestLocal(amount as UInt64); } } diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index 30618d20c0..ecfda570d4 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -31,7 +31,7 @@ import { MosaicFlags } from '../../../src/model/mosaic/MosaicFlags'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; import { MosaicNonce } from '../../../src/model/mosaic/MosaicNonce'; import { MosaicSupplyChangeAction } from '../../../src/model/mosaic/MosaicSupplyChangeAction'; -import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../../src/model/mosaic/NetworkCurrencyLocal'; import { AliasAction } from '../../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { NamespaceRegistrationType } from '../../../src/model/namespace/NamespaceRegistrationType'; @@ -320,7 +320,7 @@ describe('TransactionMapping - createFromPayload', () => { Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -341,7 +341,7 @@ describe('TransactionMapping - createFromPayload', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(Convert.hexToUint8(proof)).hex(), @@ -462,7 +462,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); @@ -471,7 +471,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping.createFromPayload(signedLockFundTransaction.payload) as LockFundsTransaction; - deepEqual(transaction.mosaic.id.id, NetworkCurrencyMosaic.NAMESPACE_ID.id); + deepEqual(transaction.mosaic.id.id, NetworkCurrencyLocal.NAMESPACE_ID.id); expect(transaction.mosaic.amount.compact()).to.be.equal(10000000); expect(transaction.hash).to.be.equal(signedTransaction.hash); }); @@ -676,7 +676,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -693,7 +693,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => Deadline.create(), new NamespaceId([33347626, 3779697293]), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -710,7 +710,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], new EncryptedMessage('12324556'), NetworkType.MIJIN_TEST, @@ -871,7 +871,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(Convert.hexToUint8(proof)).hex(), @@ -892,7 +892,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => const recipientAddress = new NamespaceId('test'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(Convert.hexToUint8(proof)).hex(), @@ -1049,7 +1049,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index fece5987ac..5e23359f61 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -26,7 +26,7 @@ import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce'; import { MosaicSupplyChangeAction } from '../../src/model/mosaic/MosaicSupplyChangeAction'; -import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AccountRestrictionFlags } from '../../src/model/restriction/AccountRestrictionType'; @@ -217,7 +217,7 @@ describe('SerializeTransactionToJSON', () => { Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -236,7 +236,7 @@ describe('SerializeTransactionToJSON', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(convert.hexToUint8(proof)).hex(), @@ -341,7 +341,7 @@ describe('SerializeTransactionToJSON', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); diff --git a/test/model/message/EncryptedMessage.spec.ts b/test/model/message/EncryptedMessage.spec.ts index 7031093396..ae4cf20a5a 100644 --- a/test/model/message/EncryptedMessage.spec.ts +++ b/test/model/message/EncryptedMessage.spec.ts @@ -17,7 +17,7 @@ import {expect} from 'chai'; import {Account} from '../../../src/model/account/Account'; import {EncryptedMessage} from '../../../src/model/message/EncryptedMessage'; -import { Deadline, NetworkCurrencyMosaic, NetworkType, TransferTransaction } from '../../../src/model/model'; +import { Deadline, NetworkCurrencyLocal, NetworkType, TransferTransaction } from '../../../src/model/model'; describe('EncryptedMessage', () => { @@ -61,7 +61,7 @@ describe('EncryptedMessage', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), recipient.address, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], sender.encryptMessage('Testing simple transfer', recipient.publicAccount, NetworkType.MIJIN_TEST), NetworkType.MIJIN_TEST, ); diff --git a/test/model/mosaic/NetworkCurrency.spec.ts b/test/model/mosaic/NetworkCurrency.spec.ts new file mode 100644 index 0000000000..7f61656afa --- /dev/null +++ b/test/model/mosaic/NetworkCurrency.spec.ts @@ -0,0 +1,69 @@ +/* + * 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 {deepEqual} from 'assert'; +import {expect} from 'chai'; +import {NetworkCurrencyLocal} from '../../../src/model/mosaic/NetworkCurrencyLocal'; +import { NetworkCurrencyPublic } from '../../../src/model/mosaic/NetworkCurrencyPublic'; +import {NamespaceId} from '../../../src/model/namespace/NamespaceId'; +import { UInt64 } from '../../../src/model/UInt64'; + +describe('NetworkCurrencyLocal', () => { + + it('should createComplete an NetworkCurrencyLocal object', () => { + + const currency = NetworkCurrencyLocal.createRelative(1000); + + deepEqual(currency.id.id.toHex(), '85BBEA6CC462B244'); // holds NAMESPACE_ID + expect(currency.amount.compact()).to.be.equal(1000 * 1000000); + }); + + it('should set amount in smallest unit when toDTO()', () => { + + const currency = NetworkCurrencyLocal.createRelative(1000); + expect(UInt64.fromNumericString(currency.toDTO().amount).toDTO()[0]).to.be.equal(1000 * 1000000); + }); + + it('should have valid statics', () => { + deepEqual(NetworkCurrencyLocal.NAMESPACE_ID.id, new NamespaceId([3294802500, 2243684972]).id); + expect(NetworkCurrencyLocal.DIVISIBILITY).to.be.equal(6); + expect(NetworkCurrencyLocal.TRANSFERABLE).to.be.equal(true); + expect(NetworkCurrencyLocal.SUPPLY_MUTABLE).to.be.equal(false); + }); +}); + +describe('NetworkCurrencyPublic', () => { + + it('should createComplete an NetworkCurrencyPublic object', () => { + + const currency = NetworkCurrencyPublic.createRelative(1000); + deepEqual(currency.id.id.toHex(), 'E74B99BA41F4AFEE'); // holds NAMESPACE_ID + expect(currency.amount.compact()).to.be.equal(1000 * 1000000); + }); + + it('should set amount in smallest unit when toDTO()', () => { + + const currency = NetworkCurrencyPublic.createRelative(1000); + expect(UInt64.fromNumericString(currency.toDTO().amount).toDTO()[0]).to.be.equal(1000 * 1000000); + }); + + it('should have valid statics', () => { + deepEqual(NetworkCurrencyPublic.NAMESPACE_ID.id, new NamespaceId([1106554862, 3880491450]).id); + expect(NetworkCurrencyPublic.DIVISIBILITY).to.be.equal(6); + expect(NetworkCurrencyPublic.TRANSFERABLE).to.be.equal(true); + expect(NetworkCurrencyPublic.SUPPLY_MUTABLE).to.be.equal(false); + }); +}); diff --git a/test/model/mosaic/NetworkCurrencyMosaic.spec.ts b/test/model/mosaic/NetworkCurrencyMosaic.spec.ts deleted file mode 100644 index dd0acf6e2c..0000000000 --- a/test/model/mosaic/NetworkCurrencyMosaic.spec.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 {deepEqual} from 'assert'; -import {expect} from 'chai'; -import {NetworkCurrencyMosaic} from '../../../src/model/mosaic/NetworkCurrencyMosaic'; -import {NamespaceId} from '../../../src/model/namespace/NamespaceId'; -import { UInt64 } from '../../../src/model/UInt64'; - -describe('NetworkCurrencyMosaic', () => { - - it('should createComplete an NetworkCurrencyMosaic object', () => { - - const currency = NetworkCurrencyMosaic.createRelative(1000); - - deepEqual(currency.id.id.toHex(), '85BBEA6CC462B244'); // holds NAMESPACE_ID - expect(currency.amount.compact()).to.be.equal(1000 * 1000000); - }); - - it('should set amount in smallest unit when toDTO()', () => { - - const currency = NetworkCurrencyMosaic.createRelative(1000); - expect(UInt64.fromNumericString(currency.toDTO().amount).toDTO()[0]).to.be.equal(1000 * 1000000); - }); - - it('should have valid statics', () => { - deepEqual(NetworkCurrencyMosaic.NAMESPACE_ID.id, new NamespaceId([3294802500, 2243684972]).id); - expect(NetworkCurrencyMosaic.DIVISIBILITY).to.be.equal(6); - expect(NetworkCurrencyMosaic.TRANSFERABLE).to.be.equal(true); - expect(NetworkCurrencyMosaic.SUPPLY_MUTABLE).to.be.equal(false); - }); -}); diff --git a/test/model/mosaic/NetworkHarvestMosaic.spec.ts b/test/model/mosaic/NetworkHarvestLocal.spec.ts similarity index 65% rename from test/model/mosaic/NetworkHarvestMosaic.spec.ts rename to test/model/mosaic/NetworkHarvestLocal.spec.ts index baa710071a..83cf35dd91 100644 --- a/test/model/mosaic/NetworkHarvestMosaic.spec.ts +++ b/test/model/mosaic/NetworkHarvestLocal.spec.ts @@ -17,15 +17,15 @@ import {deepEqual} from 'assert'; import {expect} from 'chai'; import {MosaicId} from '../../../src/model/mosaic/MosaicId'; -import {NetworkHarvestMosaic} from '../../../src/model/mosaic/NetworkHarvestMosaic'; +import {NetworkHarvestLocal} from '../../../src/model/mosaic/NetworkHarvestLocal'; import {NamespaceId} from '../../../src/model/namespace/NamespaceId'; import { UInt64 } from '../../../src/model/UInt64'; -describe('NetworkHarvestMosaic', () => { +describe('NetworkHarvestLocal', () => { - it('should createComplete an NetworkHarvestMosaic object', () => { + it('should createComplete an NetworkHarvestLocal object', () => { - const currency = NetworkHarvestMosaic.createRelative(1000); + const currency = NetworkHarvestLocal.createRelative(1000); deepEqual(currency.id.id.toHex(), '941299B2B7E1291C'); expect(currency.amount.compact()).to.be.equal(1000 * 1000); @@ -33,14 +33,14 @@ describe('NetworkHarvestMosaic', () => { it('should set amount in smallest unit when toDTO()', () => { - const currency = NetworkHarvestMosaic.createRelative(1000); + const currency = NetworkHarvestLocal.createRelative(1000); expect(UInt64.fromNumericString(currency.toDTO().amount).toDTO()[0]).to.be.equal(1000 * 1000); }); it('should have valid statics', () => { - deepEqual(NetworkHarvestMosaic.NAMESPACE_ID.id, new NamespaceId([3084986652, 2484246962]).id); - expect(NetworkHarvestMosaic.DIVISIBILITY).to.be.equal(3); - expect(NetworkHarvestMosaic.TRANSFERABLE).to.be.equal(true); - expect(NetworkHarvestMosaic.SUPPLY_MUTABLE).to.be.equal(true); + deepEqual(NetworkHarvestLocal.NAMESPACE_ID.id, new NamespaceId([3084986652, 2484246962]).id); + expect(NetworkHarvestLocal.DIVISIBILITY).to.be.equal(3); + expect(NetworkHarvestLocal.TRANSFERABLE).to.be.equal(true); + expect(NetworkHarvestLocal.SUPPLY_MUTABLE).to.be.equal(true); }); }); diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index f4b136adc6..83fbb051e0 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -30,7 +30,7 @@ import {MosaicFlags} from '../../../src/model/mosaic/MosaicFlags'; import {MosaicId} from '../../../src/model/mosaic/MosaicId'; import {MosaicNonce} from '../../../src/model/mosaic/MosaicNonce'; import {MosaicSupplyChangeAction} from '../../../src/model/mosaic/MosaicSupplyChangeAction'; -import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../../src/model/mosaic/NetworkCurrencyLocal'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { ReceiptSource } from '../../../src/model/receipt/ReceiptSource'; import { ResolutionEntry } from '../../../src/model/receipt/ResolutionEntry'; @@ -549,7 +549,7 @@ describe('AggregateTransaction', () => { Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('NEM'), NetworkType.MIJIN_TEST, diff --git a/test/model/transaction/HashLockTransaction.spec.ts b/test/model/transaction/HashLockTransaction.spec.ts index 70df873a44..65a2fca403 100644 --- a/test/model/transaction/HashLockTransaction.spec.ts +++ b/test/model/transaction/HashLockTransaction.spec.ts @@ -16,7 +16,7 @@ import {expect} from 'chai'; import {Convert} from '../../../src/core/format'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; -import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../../src/model/mosaic/NetworkCurrencyLocal'; import {AggregateTransaction} from '../../../src/model/transaction/AggregateTransaction'; import {Deadline} from '../../../src/model/transaction/Deadline'; import {HashLockTransaction} from '../../../src/model/transaction/HashLockTransaction'; @@ -35,11 +35,11 @@ describe('HashLockTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const transaction = HashLockTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); - expect(transaction.mosaic.id).to.be.equal(NetworkCurrencyMosaic.NAMESPACE_ID); + expect(transaction.mosaic.id).to.be.equal(NetworkCurrencyLocal.NAMESPACE_ID); expect(transaction.mosaic.amount.compact()).to.be.equal(10000000); expect(transaction.hash).to.be.equal(signedTransaction.hash); expect(Convert.hexToUint8(transaction.serialize()).length).to.be.equal(transaction.size); @@ -55,7 +55,7 @@ describe('HashLockTransaction', () => { const signedTransaction = account.sign(aggregateTransaction, generationHash); expect(() => { HashLockTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); diff --git a/test/model/transaction/LockFundsTransaction.spec.ts b/test/model/transaction/LockFundsTransaction.spec.ts index 3287d3abda..f43a11b4c7 100644 --- a/test/model/transaction/LockFundsTransaction.spec.ts +++ b/test/model/transaction/LockFundsTransaction.spec.ts @@ -20,7 +20,7 @@ import {Account} from '../../../src/model/account/Account'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import { Mosaic } from '../../../src/model/mosaic/Mosaic'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; -import {NetworkCurrencyMosaic} from '../../../src/model/mosaic/NetworkCurrencyMosaic'; +import {NetworkCurrencyLocal} from '../../../src/model/mosaic/NetworkCurrencyLocal'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { ReceiptSource } from '../../../src/model/receipt/ReceiptSource'; import { ResolutionEntry } from '../../../src/model/receipt/ResolutionEntry'; @@ -58,7 +58,7 @@ describe('LockFundsTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST, @@ -78,7 +78,7 @@ describe('LockFundsTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST, @@ -98,11 +98,11 @@ describe('LockFundsTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const transaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); - deepEqual(transaction.mosaic.id.id, NetworkCurrencyMosaic.NAMESPACE_ID.id); + deepEqual(transaction.mosaic.id.id, NetworkCurrencyLocal.NAMESPACE_ID.id); expect(transaction.mosaic.amount.compact()).to.be.equal(10000000); expect(transaction.hash).to.be.equal(signedTransaction.hash); }); @@ -117,7 +117,7 @@ describe('LockFundsTransaction', () => { const signedTransaction = account.sign(aggregateTransaction, generationHash); expect(() => { LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); @@ -133,7 +133,7 @@ describe('LockFundsTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST, @@ -156,7 +156,7 @@ describe('LockFundsTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST, @@ -174,7 +174,7 @@ describe('LockFundsTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST, diff --git a/test/model/transaction/SecretLockTransaction.spec.ts b/test/model/transaction/SecretLockTransaction.spec.ts index 612b1ef7b8..ebb2d0cb04 100644 --- a/test/model/transaction/SecretLockTransaction.spec.ts +++ b/test/model/transaction/SecretLockTransaction.spec.ts @@ -23,7 +23,7 @@ import {Address} from '../../../src/model/account/Address'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import { Mosaic } from '../../../src/model/mosaic/Mosaic'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; -import {NetworkCurrencyMosaic} from '../../../src/model/mosaic/NetworkCurrencyMosaic'; +import {NetworkCurrencyLocal} from '../../../src/model/mosaic/NetworkCurrencyLocal'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { ReceiptSource } from '../../../src/model/receipt/ReceiptSource'; import { ResolutionEntry } from '../../../src/model/receipt/ResolutionEntry'; @@ -59,7 +59,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(convert.hexToUint8(proof)).hex(), @@ -76,7 +76,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(convert.hexToUint8(proof)).hex(), @@ -94,14 +94,14 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(convert.hexToUint8(proof)).hex(), recipientAddress, NetworkType.MIJIN_TEST, ); - deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyMosaic.NAMESPACE_ID.id); + deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyLocal.NAMESPACE_ID.id); expect(secretLockTransaction.mosaic.amount.equals(UInt64.fromUint(10))).to.be.equal(true); expect(secretLockTransaction.duration.equals(UInt64.fromUint(100))).to.be.equal(true); expect(secretLockTransaction.hashType).to.be.equal(0); @@ -114,7 +114,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(convert.hexToUint8(proof)).hex(), @@ -135,7 +135,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, 'non valid hash', @@ -150,14 +150,14 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Keccak_256, keccak_256.create().update(convert.hexToUint8(proof)).hex(), recipientAddress, NetworkType.MIJIN_TEST, ); - deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyMosaic.NAMESPACE_ID.id); + deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyLocal.NAMESPACE_ID.id); expect(secretLockTransaction.mosaic.amount.equals(UInt64.fromUint(10))).to.be.equal(true); expect(secretLockTransaction.duration.equals(UInt64.fromUint(100))).to.be.equal(true); expect(secretLockTransaction.hashType).to.be.equal(1); @@ -170,7 +170,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Keccak_256, 'non valid hash', @@ -184,14 +184,14 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_160, CryptoJS.RIPEMD160(CryptoJS.SHA256(proof).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex), recipientAddress, NetworkType.MIJIN_TEST, ); - deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyMosaic.NAMESPACE_ID.id); + deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyLocal.NAMESPACE_ID.id); expect(secretLockTransaction.mosaic.amount.equals(UInt64.fromUint(10))).to.be.equal(true); expect(secretLockTransaction.duration.equals(UInt64.fromUint(100))).to.be.equal(true); expect(secretLockTransaction.hashType).to.be.equal(2); @@ -204,7 +204,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_160, 'non valid hash', @@ -218,14 +218,14 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_256, CryptoJS.SHA256(CryptoJS.SHA256(proof).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex), recipientAddress, NetworkType.MIJIN_TEST, ); - deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyMosaic.NAMESPACE_ID.id); + deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyLocal.NAMESPACE_ID.id); expect(secretLockTransaction.mosaic.amount.equals(UInt64.fromUint(10))).to.be.equal(true); expect(secretLockTransaction.duration.equals(UInt64.fromUint(100))).to.be.equal(true); expect(secretLockTransaction.hashType).to.be.equal(3); @@ -238,7 +238,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_256, 'non valid hash', @@ -254,7 +254,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_256, CryptoJS.SHA256(CryptoJS.SHA256(proof).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex), @@ -271,14 +271,14 @@ describe('SecretLockTransaction', () => { const recipientAddress = new NamespaceId('test'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(convert.hexToUint8(proof)).hex(), recipientAddress, NetworkType.MIJIN_TEST, ); - deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyMosaic.NAMESPACE_ID.id); + deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyLocal.NAMESPACE_ID.id); expect(secretLockTransaction.mosaic.amount.equals(UInt64.fromUint(10))).to.be.equal(true); expect(secretLockTransaction.duration.equals(UInt64.fromUint(100))).to.be.equal(true); expect(secretLockTransaction.hashType).to.be.equal(0); @@ -291,7 +291,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(convert.hexToUint8(proof)).hex(), diff --git a/test/model/transaction/TransferTransaction.spec.ts b/test/model/transaction/TransferTransaction.spec.ts index 6bdc150911..e8f551fda1 100644 --- a/test/model/transaction/TransferTransaction.spec.ts +++ b/test/model/transaction/TransferTransaction.spec.ts @@ -27,7 +27,7 @@ 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 { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../../src/model/mosaic/NetworkCurrencyLocal'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { ResolutionStatement } from '../../../src/model/receipt/ResolutionStatement'; import { Statement } from '../../../src/model/receipt/Statement'; @@ -113,7 +113,7 @@ describe('TransferTransaction', () => { Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -140,7 +140,7 @@ describe('TransferTransaction', () => { Deadline.create(), addressAlias, [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -166,7 +166,7 @@ describe('TransferTransaction', () => { Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -188,7 +188,7 @@ describe('TransferTransaction', () => { Deadline.create(), new NamespaceId('nem.owner'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -211,7 +211,7 @@ describe('TransferTransaction', () => { Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('NEM'), NetworkType.MIJIN_TEST, @@ -226,7 +226,7 @@ describe('TransferTransaction', () => { Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -289,7 +289,7 @@ describe('TransferTransaction', () => { TransferTransaction.create( Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), - [NetworkCurrencyMosaic.createRelative(100)], + [NetworkCurrencyLocal.createRelative(100)], PersistentHarvestingDelegationMessage .create(delegatedPrivateKey, recipientPublicKey, NetworkType.MIJIN_TEST), NetworkType.MIJIN_TEST, @@ -302,7 +302,7 @@ describe('TransferTransaction', () => { TransferTransaction.create( Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), - [NetworkCurrencyMosaic.createRelative(100)], + [NetworkCurrencyLocal.createRelative(100)], PersistentHarvestingDelegationMessage.create('abc', recipientPublicKey, NetworkType.MIJIN_TEST), NetworkType.MIJIN_TEST, ); @@ -314,7 +314,7 @@ describe('TransferTransaction', () => { TransferTransaction.create( Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), - [NetworkCurrencyMosaic.createRelative(100)], + [NetworkCurrencyLocal.createRelative(100)], PersistentHarvestingDelegationMessage.create(delegatedPrivateKey, recipientPublicKey, NetworkType.MIJIN_TEST), NetworkType.MIJIN_TEST, ); @@ -384,7 +384,7 @@ describe('TransferTransaction', () => { const transferTransaction = TransferTransaction.create( Deadline.createFromDTO('1'), namespaceId, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, ); @@ -401,7 +401,7 @@ describe('TransferTransaction', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, ).setMaxFee(2); From 4bdea2cfdc75b21a2794ff36154af06ccab4770c Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 18 Feb 2020 20:46:09 +0000 Subject: [PATCH 08/13] Removed transaction search criteria Added queryParam tests --- e2e/infrastructure/AccountHttp.spec.ts | 4 +- src/infrastructure/AccountHttp.ts | 51 +++++++++---------- src/infrastructure/AccountRepository.ts | 12 ++--- src/infrastructure/Http.ts | 5 +- src/infrastructure/QueryParams.ts | 24 ++++++++- .../TransactionSearchCriteria.ts | 45 ---------------- src/infrastructure/infrastructure.ts | 1 - test/infrastructure/QueryParams.spec.ts | 33 ++++++++++++ 8 files changed, 90 insertions(+), 85 deletions(-) delete mode 100644 src/infrastructure/TransactionSearchCriteria.ts create mode 100644 test/infrastructure/QueryParams.spec.ts diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index 86754b93aa..c7b67c8d42 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -18,7 +18,6 @@ import { expect } from 'chai'; import { AccountRepository } from '../../src/infrastructure/AccountRepository'; import { MultisigRepository } from '../../src/infrastructure/MultisigRepository'; import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; -import { TransactionSearchCriteria } from '../../src/infrastructure/TransactionSearchCriteria'; import { Account } from '../../src/model/account/Account'; import { Address } from '../../src/model/account/Address'; import { PublicAccount } from '../../src/model/account/PublicAccount'; @@ -36,6 +35,7 @@ import { TransactionType } from '../../src/model/transaction/TransactionType'; import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; import { UInt64 } from '../../src/model/UInt64'; import { IntegrationTestHelper } from './IntegrationTestHelper'; +import { QueryParams } from '../../src/infrastructure/QueryParams'; describe('AccountHttp', () => { const helper = new IntegrationTestHelper(); @@ -227,7 +227,7 @@ describe('AccountHttp', () => { describe('transactions', () => { it('should call transactions successfully by type', async () => { const transactions = await accountRepository.getAccountTransactions( - publicAccount.address, new TransactionSearchCriteria().setTransactionTypes([TransactionType.TRANSFER])).toPromise(); + publicAccount.address, new QueryParams().setType([TransactionType.TRANSFER])).toPromise(); expect(transactions.length).to.be.greaterThan(0); transactions.forEach((t) => { expect(t.type).to.be.eq(TransactionType.TRANSFER); diff --git a/src/infrastructure/AccountHttp.ts b/src/infrastructure/AccountHttp.ts index 0beabe0ce2..00534731ca 100644 --- a/src/infrastructure/AccountHttp.ts +++ b/src/infrastructure/AccountHttp.ts @@ -29,7 +29,6 @@ import { AccountRepository } from './AccountRepository'; import { Http } from './Http'; import { QueryParams } from './QueryParams'; import { CreateTransactionFromDTO } from './transaction/CreateTransactionFromDTO'; -import { TransactionSearchCriteria } from './TransactionSearchCriteria'; /** * Account http repository. @@ -118,13 +117,13 @@ export class AccountHttp extends Http implements AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - public getAccountTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable { + public getAccountTransactions(address: Address, queryParams?: QueryParams): Observable { return observableFrom( this.accountRoutesApi.getAccountConfirmedTransactions(address.plain(), - this.transactionSearchCriteria(queryParams).pageSize, - this.transactionSearchCriteria(queryParams).id, - this.transactionSearchCriteria(queryParams).ordering, - this.transactionSearchCriteria(queryParams).type)).pipe( + this.queryParams(queryParams).pageSize, + this.queryParams(queryParams).id, + this.queryParams(queryParams).ordering, + this.queryParams(queryParams).type)).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), @@ -139,13 +138,13 @@ export class AccountHttp extends Http implements AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - public getAccountIncomingTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable { + public getAccountIncomingTransactions(address: Address, queryParams?: QueryParams): Observable { return observableFrom( this.accountRoutesApi.getAccountIncomingTransactions(address.plain(), - this.transactionSearchCriteria(queryParams).pageSize, - this.transactionSearchCriteria(queryParams).id, - this.transactionSearchCriteria(queryParams).ordering), - this.transactionSearchCriteria(queryParams).type).pipe( + this.queryParams(queryParams).pageSize, + this.queryParams(queryParams).id, + this.queryParams(queryParams).ordering), + this.queryParams(queryParams).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), @@ -160,13 +159,13 @@ export class AccountHttp extends Http implements AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - public getAccountOutgoingTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable { + public getAccountOutgoingTransactions(address: Address, queryParams?: QueryParams): Observable { return observableFrom( this.accountRoutesApi.getAccountOutgoingTransactions(address.plain(), - this.transactionSearchCriteria(queryParams).pageSize, - this.transactionSearchCriteria(queryParams).id, - this.transactionSearchCriteria(queryParams).ordering), - this.transactionSearchCriteria(queryParams).type).pipe( + this.queryParams(queryParams).pageSize, + this.queryParams(queryParams).id, + this.queryParams(queryParams).ordering), + this.queryParams(queryParams).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), @@ -182,13 +181,13 @@ export class AccountHttp extends Http implements AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - public getAccountUnconfirmedTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable { + public getAccountUnconfirmedTransactions(address: Address, queryParams?: QueryParams): Observable { return observableFrom( this.accountRoutesApi.getAccountUnconfirmedTransactions(address.plain(), - this.transactionSearchCriteria(queryParams).pageSize, - this.transactionSearchCriteria(queryParams).id, - this.transactionSearchCriteria(queryParams).ordering), - this.transactionSearchCriteria(queryParams).type).pipe( + this.queryParams(queryParams).pageSize, + this.queryParams(queryParams).id, + this.queryParams(queryParams).ordering), + this.queryParams(queryParams).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), @@ -203,13 +202,13 @@ export class AccountHttp extends Http implements AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - public getAccountPartialTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable { + public getAccountPartialTransactions(address: Address, queryParams?: QueryParams): Observable { return observableFrom( this.accountRoutesApi.getAccountPartialTransactions(address.plain(), - this.transactionSearchCriteria(queryParams).pageSize, - this.transactionSearchCriteria(queryParams).id, - this.transactionSearchCriteria(queryParams).ordering), - this.transactionSearchCriteria(queryParams).type).pipe( + this.queryParams(queryParams).pageSize, + this.queryParams(queryParams).id, + this.queryParams(queryParams).ordering), + this.queryParams(queryParams).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO) as AggregateTransaction; })), diff --git a/src/infrastructure/AccountRepository.ts b/src/infrastructure/AccountRepository.ts index 83126caed3..1f9b564217 100644 --- a/src/infrastructure/AccountRepository.ts +++ b/src/infrastructure/AccountRepository.ts @@ -19,7 +19,7 @@ import {AccountInfo} from '../model/account/AccountInfo'; import {Address} from '../model/account/Address'; import {AggregateTransaction} from '../model/transaction/AggregateTransaction'; import {Transaction} from '../model/transaction/Transaction'; -import { TransactionSearchCriteria } from './TransactionSearchCriteria'; +import { QueryParams } from './QueryParams'; /** * Account interface repository. @@ -48,7 +48,7 @@ export interface AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - getAccountTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable; + getAccountTransactions(address: Address, queryParams?: QueryParams): Observable; /** * Gets an array of transactions for which an account is the recipient of a transaction. @@ -57,7 +57,7 @@ export interface AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - getAccountIncomingTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable; + getAccountIncomingTransactions(address: Address, queryParams?: QueryParams): Observable; /** * Gets an array of transactions for which an account is the sender a transaction. @@ -66,7 +66,7 @@ export interface AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - getAccountOutgoingTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable; + getAccountOutgoingTransactions(address: Address, queryParams?: QueryParams): Observable; /** * Gets the array of transactions for which an account is the sender or receiver and which have not yet been included in a block. @@ -76,7 +76,7 @@ export interface AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - getAccountUnconfirmedTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable; + getAccountUnconfirmedTransactions(address: Address, queryParams?: QueryParams): Observable; /** * Gets an array of transactions for which an account is the sender or has sign the transaction. @@ -85,5 +85,5 @@ export interface AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - getAccountPartialTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable; + getAccountPartialTransactions(address: Address, queryParams?: QueryParams): Observable; } diff --git a/src/infrastructure/Http.ts b/src/infrastructure/Http.ts index abd673cb77..1401600e0f 100644 --- a/src/infrastructure/Http.ts +++ b/src/infrastructure/Http.ts @@ -20,7 +20,6 @@ import { from as observableFrom, Observable, of as observableOf, throwError } fr import { catchError, map, shareReplay } from 'rxjs/operators'; import { NetworkType } from '../model/blockchain/NetworkType'; import { QueryParams } from './QueryParams'; -import { TransactionSearchCriteria } from './TransactionSearchCriteria'; /** * Http extended by all http services @@ -57,12 +56,12 @@ export abstract class Http { }; } - transactionSearchCriteria(queryParams?: TransactionSearchCriteria): any { + transactionSearchCriteria(queryParams?: QueryParams): any { return { pageSize: queryParams ? queryParams.pageSize : undefined, id: queryParams ? queryParams.id : undefined, ordering: queryParams ? queryParams.order : undefined, - type: queryParams ? queryParams.type : undefined, + type: queryParams ? queryParams.convertCSV(queryParams.type) : undefined, }; } diff --git a/src/infrastructure/QueryParams.ts b/src/infrastructure/QueryParams.ts index 68722bd39f..c13667e688 100644 --- a/src/infrastructure/QueryParams.ts +++ b/src/infrastructure/QueryParams.ts @@ -44,10 +44,13 @@ export class QueryParams { * ASC. Older to newer. */ public order: Order = Order.DESC; + + /** + * Transaction type list + */ + public type?: TransactionType[]; /** * Constructor - * @param pageSize - * @param id */ constructor() { } @@ -66,4 +69,21 @@ export class QueryParams { this.order = order; return this; } + + public setType(type?: TransactionType[]): QueryParams { + this.type = type; + return this; + } + + /** + * Return comma seperated list + * @param type Transaction type list + */ + public convertCSV(type?: TransactionType[]): string | undefined { + if (!type || type.length === 0) { + return undefined; + } else { + return type.map((t) => t.valueOf().toString()).join(','); + } + } } diff --git a/src/infrastructure/TransactionSearchCriteria.ts b/src/infrastructure/TransactionSearchCriteria.ts deleted file mode 100644 index 4db17aea42..0000000000 --- a/src/infrastructure/TransactionSearchCriteria.ts +++ /dev/null @@ -1,45 +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. - */ - -import { TransactionType } from '../model/transaction/TransactionType'; -import { QueryParams } from './QueryParams'; - - /** - * Transaction search criteria for filtering transaction list - */ -export class TransactionSearchCriteria extends QueryParams { - /** - * Transaction type filter - */ - public type?: string; - /** - * Constructor - * @param pageSize - * @param id - */ - constructor() { - super(); - } - - public setTransactionTypes(transactionTypes?: TransactionType[]): TransactionSearchCriteria { - if (!transactionTypes || transactionTypes.length === 0) { - this.type = undefined; - } else { - this.type = transactionTypes.map((type) => type.valueOf().toString()).join(','); - } - return this; - } -} diff --git a/src/infrastructure/infrastructure.ts b/src/infrastructure/infrastructure.ts index 9ac061be35..3a297391a7 100644 --- a/src/infrastructure/infrastructure.ts +++ b/src/infrastructure/infrastructure.ts @@ -47,4 +47,3 @@ export * from './RepositoryFactory'; export * from './RestrictionAccountRepository'; export * from './RestrictionMosaicRepository'; export * from './TransactionRepository'; -export * from './TransactionSearchCriteria'; diff --git a/test/infrastructure/QueryParams.spec.ts b/test/infrastructure/QueryParams.spec.ts new file mode 100644 index 0000000000..7b61fa9279 --- /dev/null +++ b/test/infrastructure/QueryParams.spec.ts @@ -0,0 +1,33 @@ +/* + * 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 { Order, QueryParams } from '../../src/infrastructure/QueryParams'; +import { TransactionType } from '../../src/model/transaction/TransactionType'; + +describe('QueryParams', () => { + it('should return correct query param', () => { + const param = new QueryParams().setId('0') + .setOrder(Order.ASC) + .setPageSize(10) + .setType([TransactionType.TRANSFER, TransactionType.ACCOUNT_LINK]); + + expect(param.id).to.be.equal('0'); + expect(param.order.valueOf()).to.be.equal(Order.ASC.valueOf()); + expect(param.pageSize).to.be.equal(10); + expect(param.convertCSV(param.type)).to.be.equal('16724,16716'); + }); +}); From d752678425d0461bf65cf0b2b456fd2f881b8f99 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 18 Feb 2020 18:50:02 +0000 Subject: [PATCH 09/13] Fixed #451 - Added positionEnum for merklePathItem - Changed to use comma separated string for transaction type filtering - Added generationHash in NodeInfo --- e2e/infrastructure/AccountHttp.spec.ts | 6 +- e2e/infrastructure/BlockHttp.spec.ts | 3 +- package-lock.json | 6 +- package.json | 2 +- src/infrastructure/AccountHttp.ts | 62 ++++++++++--------- src/infrastructure/AccountRepository.ts | 12 ++-- src/infrastructure/BlockHttp.ts | 2 +- src/infrastructure/Http.ts | 13 +++- src/infrastructure/MetadataHttp.ts | 6 +- src/infrastructure/NamespaceHttp.ts | 2 +- src/infrastructure/NodeHttp.ts | 1 + src/infrastructure/QueryParams.ts | 50 ++++++++------- .../TransactionSearchCriteria.ts | 45 ++++++++++++++ src/model/blockchain/MerklePathItem.ts | 4 +- src/model/node/NodeInfo.ts | 5 ++ src/service/BlockService.ts | 3 +- 16 files changed, 148 insertions(+), 74 deletions(-) create mode 100644 src/infrastructure/TransactionSearchCriteria.ts diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index 214cf281ed..1544377232 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -18,7 +18,7 @@ import { expect } from 'chai'; import { AccountRepository } from '../../src/infrastructure/AccountRepository'; import { MultisigRepository } from '../../src/infrastructure/MultisigRepository'; import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; -import { QueryParams } from '../../src/infrastructure/QueryParams'; +import { TransactionSearchCriteria } from '../../src/infrastructure/TransactionSearchCriteria'; import { Account } from '../../src/model/account/Account'; import { Address } from '../../src/model/account/Address'; import { PublicAccount } from '../../src/model/account/PublicAccount'; @@ -213,7 +213,7 @@ describe('AccountHttp', () => { describe('transactions', () => { it('should not return accounts when account does not exist', () => { - return accountRepository.getAccountInfo(Account.generateNewAccount(networkType).address).toPromise().then((r) => { + return accountRepository.getAccountInfo(Account.generateNewAccount(networkType).address).toPromise().then(() => { return Promise.reject('should fail!'); }, (err) => { const error = JSON.parse(err.message); @@ -227,7 +227,7 @@ describe('AccountHttp', () => { describe('transactions', () => { it('should call transactions successfully by type', async () => { const transactions = await accountRepository.getAccountTransactions( - publicAccount.address, {transactionType: TransactionType.TRANSFER} as QueryParams).toPromise(); + publicAccount.address, new TransactionSearchCriteria().setTransactionTypes([TransactionType.TRANSFER])).toPromise(); expect(transactions.length).to.be.greaterThan(0); transactions.forEach((t) => { expect(t.type).to.be.eq(TransactionType.TRANSFER); diff --git a/e2e/infrastructure/BlockHttp.spec.ts b/e2e/infrastructure/BlockHttp.spec.ts index 0d12e7a93b..d6d8298873 100644 --- a/e2e/infrastructure/BlockHttp.spec.ts +++ b/e2e/infrastructure/BlockHttp.spec.ts @@ -111,7 +111,8 @@ describe('BlockHttp', () => { }); it('should return block transactions data given height with paginated transactionId', async () => { - const transactions = await blockRepository.getBlockTransactions(UInt64.fromUint(1), new QueryParams(10, nextId)).toPromise(); + const transactions = await blockRepository.getBlockTransactions(UInt64.fromUint(1), + new QueryParams().setPageSize(10).setId(nextId)).toPromise(); expect(transactions[0].transactionInfo!.id).to.be.equal(firstId); expect(transactions.length).to.be.greaterThan(0); }); diff --git a/package-lock.json b/package-lock.json index 293580cdef..603c759bc9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3833,9 +3833,9 @@ } }, "nem2-sdk-openapi-typescript-node-client": { - "version": "0.8.3", - "resolved": "https://registry.npmjs.org/nem2-sdk-openapi-typescript-node-client/-/nem2-sdk-openapi-typescript-node-client-0.8.3.tgz", - "integrity": "sha512-e0B4FCi/uOjag84wpWTMAvR/J//JAmtP0agKg8fEBTiuD4gbGDKLLhfNtMCuMWdCw1nFX5aVVJrx3MakP/ad8w==", + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/nem2-sdk-openapi-typescript-node-client/-/nem2-sdk-openapi-typescript-node-client-0.8.4.tgz", + "integrity": "sha512-53DukFQUCKr0+bH1fm3fLzIT/v10lv5kdMqBHX4h4jDUslQeXnlBpPi/qX/XDmu2hyjwOWZa7hFzLhlt8xqhdQ==", "requires": { "@types/bluebird": "*", "@types/request": "*", diff --git a/package.json b/package.json index 9b33dcbc47..58b0f5b0ec 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "js-sha512": "^0.8.0", "long": "^4.0.0", "merkletreejs": "^0.1.7", - "nem2-sdk-openapi-typescript-node-client": "0.8.3", + "nem2-sdk-openapi-typescript-node-client": "0.8.4", "request": "^2.88.0", "request-promise-native": "^1.0.5", "ripemd160": "^2.0.2", diff --git a/src/infrastructure/AccountHttp.ts b/src/infrastructure/AccountHttp.ts index 7e3a6df1f3..0beabe0ce2 100644 --- a/src/infrastructure/AccountHttp.ts +++ b/src/infrastructure/AccountHttp.ts @@ -29,6 +29,7 @@ import { AccountRepository } from './AccountRepository'; import { Http } from './Http'; import { QueryParams } from './QueryParams'; import { CreateTransactionFromDTO } from './transaction/CreateTransactionFromDTO'; +import { TransactionSearchCriteria } from './TransactionSearchCriteria'; /** * Account http repository. @@ -108,6 +109,7 @@ export class AccountHttp extends Http implements AccountRepository { UInt64.fromNumericString(dto.account.importance), UInt64.fromNumericString(dto.account.importanceHeight), ); + } /** @@ -116,18 +118,18 @@ export class AccountHttp extends Http implements AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - public getAccountTransactions(address: Address, queryParams?: QueryParams): Observable { + public getAccountTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable { return observableFrom( this.accountRoutesApi.getAccountConfirmedTransactions(address.plain(), - this.queryParams(queryParams).pageSize, - this.queryParams(queryParams).id, - this.queryParams(queryParams).order, - this.queryParams(queryParams).transactionType)).pipe( - map(({body}) => body.map((transactionDTO) => { - return CreateTransactionFromDTO(transactionDTO); - })), - catchError((error) => throwError(this.errorHandling(error))), - ); + this.transactionSearchCriteria(queryParams).pageSize, + this.transactionSearchCriteria(queryParams).id, + this.transactionSearchCriteria(queryParams).ordering, + this.transactionSearchCriteria(queryParams).type)).pipe( + map(({body}) => body.map((transactionDTO) => { + return CreateTransactionFromDTO(transactionDTO); + })), + catchError((error) => throwError(this.errorHandling(error))), + ); } /** @@ -137,13 +139,13 @@ export class AccountHttp extends Http implements AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - public getAccountIncomingTransactions(address: Address, queryParams?: QueryParams): Observable { + public getAccountIncomingTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable { return observableFrom( this.accountRoutesApi.getAccountIncomingTransactions(address.plain(), - this.queryParams(queryParams).pageSize, - this.queryParams(queryParams).id, - this.queryParams(queryParams).order), - this.queryParams(queryParams).transactionType).pipe( + this.transactionSearchCriteria(queryParams).pageSize, + this.transactionSearchCriteria(queryParams).id, + this.transactionSearchCriteria(queryParams).ordering), + this.transactionSearchCriteria(queryParams).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), @@ -158,13 +160,13 @@ export class AccountHttp extends Http implements AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - public getAccountOutgoingTransactions(address: Address, queryParams?: QueryParams): Observable { + public getAccountOutgoingTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable { return observableFrom( this.accountRoutesApi.getAccountOutgoingTransactions(address.plain(), - this.queryParams(queryParams).pageSize, - this.queryParams(queryParams).id, - this.queryParams(queryParams).order), - this.queryParams(queryParams).transactionType).pipe( + this.transactionSearchCriteria(queryParams).pageSize, + this.transactionSearchCriteria(queryParams).id, + this.transactionSearchCriteria(queryParams).ordering), + this.transactionSearchCriteria(queryParams).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), @@ -180,13 +182,13 @@ export class AccountHttp extends Http implements AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - public getAccountUnconfirmedTransactions(address: Address, queryParams?: QueryParams): Observable { + public getAccountUnconfirmedTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable { return observableFrom( this.accountRoutesApi.getAccountUnconfirmedTransactions(address.plain(), - this.queryParams(queryParams).pageSize, - this.queryParams(queryParams).id, - this.queryParams(queryParams).order), - this.queryParams(queryParams).transactionType).pipe( + this.transactionSearchCriteria(queryParams).pageSize, + this.transactionSearchCriteria(queryParams).id, + this.transactionSearchCriteria(queryParams).ordering), + this.transactionSearchCriteria(queryParams).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), @@ -201,13 +203,13 @@ export class AccountHttp extends Http implements AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - public getAccountPartialTransactions(address: Address, queryParams?: QueryParams): Observable { + public getAccountPartialTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable { return observableFrom( this.accountRoutesApi.getAccountPartialTransactions(address.plain(), - this.queryParams(queryParams).pageSize, - this.queryParams(queryParams).id, - this.queryParams(queryParams).order), - this.queryParams(queryParams).transactionType).pipe( + this.transactionSearchCriteria(queryParams).pageSize, + this.transactionSearchCriteria(queryParams).id, + this.transactionSearchCriteria(queryParams).ordering), + this.transactionSearchCriteria(queryParams).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO) as AggregateTransaction; })), diff --git a/src/infrastructure/AccountRepository.ts b/src/infrastructure/AccountRepository.ts index 3e2ee11701..83126caed3 100644 --- a/src/infrastructure/AccountRepository.ts +++ b/src/infrastructure/AccountRepository.ts @@ -19,7 +19,7 @@ import {AccountInfo} from '../model/account/AccountInfo'; import {Address} from '../model/account/Address'; import {AggregateTransaction} from '../model/transaction/AggregateTransaction'; import {Transaction} from '../model/transaction/Transaction'; -import {QueryParams} from './QueryParams'; +import { TransactionSearchCriteria } from './TransactionSearchCriteria'; /** * Account interface repository. @@ -48,7 +48,7 @@ export interface AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - getAccountTransactions(address: Address, queryParams?: QueryParams): Observable; + getAccountTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable; /** * Gets an array of transactions for which an account is the recipient of a transaction. @@ -57,7 +57,7 @@ export interface AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - getAccountIncomingTransactions(address: Address, queryParams?: QueryParams): Observable; + getAccountIncomingTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable; /** * Gets an array of transactions for which an account is the sender a transaction. @@ -66,7 +66,7 @@ export interface AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - getAccountOutgoingTransactions(address: Address, queryParams?: QueryParams): Observable; + getAccountOutgoingTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable; /** * Gets the array of transactions for which an account is the sender or receiver and which have not yet been included in a block. @@ -76,7 +76,7 @@ export interface AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - getAccountUnconfirmedTransactions(address: Address, queryParams?: QueryParams): Observable; + getAccountUnconfirmedTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable; /** * Gets an array of transactions for which an account is the sender or has sign the transaction. @@ -85,5 +85,5 @@ export interface AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - getAccountPartialTransactions(address: Address, queryParams?: QueryParams): Observable; + getAccountPartialTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable; } diff --git a/src/infrastructure/BlockHttp.ts b/src/infrastructure/BlockHttp.ts index eb3a5d94a4..7877dd3600 100644 --- a/src/infrastructure/BlockHttp.ts +++ b/src/infrastructure/BlockHttp.ts @@ -73,7 +73,7 @@ export class BlockHttp extends Http implements BlockRepository { this.blockRoutesApi.getBlockTransactions(height.toString(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, - this.queryParams(queryParams).order)) + this.queryParams(queryParams).ordering)) .pipe(map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), diff --git a/src/infrastructure/Http.ts b/src/infrastructure/Http.ts index 4a1fcca01c..abd673cb77 100644 --- a/src/infrastructure/Http.ts +++ b/src/infrastructure/Http.ts @@ -20,6 +20,7 @@ import { from as observableFrom, Observable, of as observableOf, throwError } fr import { catchError, map, shareReplay } from 'rxjs/operators'; import { NetworkType } from '../model/blockchain/NetworkType'; import { QueryParams } from './QueryParams'; +import { TransactionSearchCriteria } from './TransactionSearchCriteria'; /** * Http extended by all http services @@ -52,8 +53,16 @@ export abstract class Http { return { pageSize: queryParams ? queryParams.pageSize : undefined, id: queryParams ? queryParams.id : undefined, - order: queryParams ? queryParams.order : undefined, - transactionType: queryParams ? queryParams.transactionType : undefined, + ordering: queryParams ? queryParams.order : undefined, + }; + } + + transactionSearchCriteria(queryParams?: TransactionSearchCriteria): any { + return { + pageSize: queryParams ? queryParams.pageSize : undefined, + id: queryParams ? queryParams.id : undefined, + ordering: queryParams ? queryParams.order : undefined, + type: queryParams ? queryParams.type : undefined, }; } diff --git a/src/infrastructure/MetadataHttp.ts b/src/infrastructure/MetadataHttp.ts index fbd3ca4577..221cfcbe8a 100644 --- a/src/infrastructure/MetadataHttp.ts +++ b/src/infrastructure/MetadataHttp.ts @@ -62,7 +62,7 @@ export class MetadataHttp extends Http implements MetadataRepository { this.metadataRoutesApi.getAccountMetadata(address.plain(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, - this.queryParams(queryParams).order)).pipe( + this.queryParams(queryParams).ordering)).pipe( map(({body}) => body.metadataEntries.map((metadataEntry) => { return this.buildMetadata(metadataEntry); })), @@ -112,7 +112,7 @@ export class MetadataHttp extends Http implements MetadataRepository { this.metadataRoutesApi.getMosaicMetadata(mosaicId.toHex(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, - this.queryParams(queryParams).order)).pipe( + this.queryParams(queryParams).ordering)).pipe( map(({body}) => body.metadataEntries.map((metadataEntry) => { return this.buildMetadata(metadataEntry); })), @@ -162,7 +162,7 @@ export class MetadataHttp extends Http implements MetadataRepository { this.metadataRoutesApi.getNamespaceMetadata(namespaceId.toHex(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, - this.queryParams(queryParams).order)).pipe( + this.queryParams(queryParams).ordering)).pipe( map(({body}) => body.metadataEntries.map((metadataEntry) => { return this.buildMetadata(metadataEntry); })), diff --git a/src/infrastructure/NamespaceHttp.ts b/src/infrastructure/NamespaceHttp.ts index 86b3bff8ea..8471e95d5d 100644 --- a/src/infrastructure/NamespaceHttp.ts +++ b/src/infrastructure/NamespaceHttp.ts @@ -152,7 +152,7 @@ export class NamespaceHttp extends Http implements NamespaceRepository { this.namespaceRoutesApi.getNamespacesFromAccount(address.plain(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, - this.queryParams(queryParams).order)).pipe( + this.queryParams(queryParams).ordering)).pipe( map(({body}) => body.namespaces.map((namespaceInfoDTO) => { return new NamespaceInfo( namespaceInfoDTO.meta.active, diff --git a/src/infrastructure/NodeHttp.ts b/src/infrastructure/NodeHttp.ts index 988c8758d5..ce74c0fe8b 100644 --- a/src/infrastructure/NodeHttp.ts +++ b/src/infrastructure/NodeHttp.ts @@ -56,6 +56,7 @@ export class NodeHttp extends Http implements NodeRepository { return observableFrom(this.nodeRoutesApi.getNodeInfo()).pipe( map(({body}) => new NodeInfo( body.publicKey, + body.networkGenerationHash, body.port, body.networkIdentifier, body.version, diff --git a/src/infrastructure/QueryParams.ts b/src/infrastructure/QueryParams.ts index fa3fc36b73..68722bd39f 100644 --- a/src/infrastructure/QueryParams.ts +++ b/src/infrastructure/QueryParams.ts @@ -30,32 +30,40 @@ export enum Order { * @since 1.0 */ export class QueryParams { - + /** + * Page size between 10 and 100, otherwise 10 + */ + public pageSize = 10; + /** + * Id after which we want objects to be returned + */ + public id?: string; + /** + * Order of transactions. + * DESC. Newer to older. + * ASC. Older to newer. + */ + public order: Order = Order.DESC; /** * Constructor * @param pageSize * @param id */ - constructor( - /** - * Page size between 10 and 100, otherwise 10 - */ - public readonly pageSize: number, - /** - * Id after which we want objects to be returned - */ - public readonly id?: string, - /** - * Order of transactions. - * DESC. Newer to older. - * ASC. Older to newer. - */ - public readonly order: Order = Order.DESC, - /** - * Transaction type filter - */ - public readonly transactionType?: TransactionType, - ) { + constructor() { + } + + public setPageSize(pageSize: number): QueryParams { this.pageSize = (pageSize >= 10 && pageSize <= 100) ? pageSize : 10; + return this; + } + + public setId(id?: string): QueryParams { + this.id = id; + return this; + } + + public setOrder(order: Order = Order.DESC): QueryParams { + this.order = order; + return this; } } diff --git a/src/infrastructure/TransactionSearchCriteria.ts b/src/infrastructure/TransactionSearchCriteria.ts new file mode 100644 index 0000000000..4db17aea42 --- /dev/null +++ b/src/infrastructure/TransactionSearchCriteria.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 { TransactionType } from '../model/transaction/TransactionType'; +import { QueryParams } from './QueryParams'; + + /** + * Transaction search criteria for filtering transaction list + */ +export class TransactionSearchCriteria extends QueryParams { + /** + * Transaction type filter + */ + public type?: string; + /** + * Constructor + * @param pageSize + * @param id + */ + constructor() { + super(); + } + + public setTransactionTypes(transactionTypes?: TransactionType[]): TransactionSearchCriteria { + if (!transactionTypes || transactionTypes.length === 0) { + this.type = undefined; + } else { + this.type = transactionTypes.map((type) => type.valueOf().toString()).join(','); + } + return this; + } +} diff --git a/src/model/blockchain/MerklePathItem.ts b/src/model/blockchain/MerklePathItem.ts index a004229c18..d87006889d 100644 --- a/src/model/blockchain/MerklePathItem.ts +++ b/src/model/blockchain/MerklePathItem.ts @@ -1,3 +1,5 @@ +import { PositionEnum } from "nem2-sdk-openapi-typescript-node-client/dist/model/positionEnum"; + /* * Copyright 2019 NEM * @@ -26,7 +28,7 @@ export class MerklePathItem { constructor(/** * The position */ - public readonly position?: number, + public readonly position?: PositionEnum, /** * The hash */ diff --git a/src/model/node/NodeInfo.ts b/src/model/node/NodeInfo.ts index 82947da021..1d0632366d 100644 --- a/src/model/node/NodeInfo.ts +++ b/src/model/node/NodeInfo.ts @@ -22,6 +22,7 @@ export class NodeInfo { /** * @param publicKey + * @param networkGenerationHash * @param port * @param networkIdentifier * @param version @@ -33,6 +34,10 @@ export class NodeInfo { * The public key used to identify the node. */ public readonly publicKey: string, + /** + * The network generation hash + */ + public readonly networkGenerationHash: string, /** * The port used for the communication. */ diff --git a/src/service/BlockService.ts b/src/service/BlockService.ts index 0c3b5ec955..2e357ccae3 100644 --- a/src/service/BlockService.ts +++ b/src/service/BlockService.ts @@ -15,6 +15,7 @@ */ import { sha3_256 } from 'js-sha3'; +import { PositionEnum } from 'nem2-sdk-openapi-typescript-node-client/dist/model/positionEnum'; import { combineLatest, Observable, of } from 'rxjs'; import { catchError, map } from 'rxjs/operators'; import { BlockRepository } from '../infrastructure/BlockRepository'; @@ -79,7 +80,7 @@ export class BlockService { const rootToCompare = merklePathItem.reduce((proofHash, pathItem) => { const hasher = sha3_256.create(); // Left - if (pathItem.position === 1) { + if (pathItem.position !== undefined && pathItem.position === PositionEnum.Left) { return hasher.update(Buffer.from(pathItem.hash + proofHash, 'hex')).hex(); } else { // Right From 8b8a3c2352007b7085c3caaa86ccdf42b74ff77b Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 18 Feb 2020 19:12:51 +0000 Subject: [PATCH 10/13] Updated ticker - Changed NetworkCurrencyMosaic -> NetworkCurrencyLocal - Added NetworkCurrencyPublic --- e2e/infrastructure/AccountHttp.spec.ts | 4 +- e2e/infrastructure/BlockHttp.spec.ts | 4 +- e2e/infrastructure/Listener.spec.ts | 16 +-- e2e/infrastructure/NamespaceHttp.spec.ts | 4 +- e2e/infrastructure/TransactionHttp.spec.ts | 58 +++++------ e2e/infrastructure/UnresolvedMapping.spec.ts | 8 +- e2e/service/TransactionService.spec.ts | 6 +- ...TransactionService_AggregateBonded.spec.ts | 12 +-- src/infrastructure/infrastructure.ts | 1 + src/model/model.ts | 5 +- ...rencyMosaic.ts => NetworkCurrencyLocal.ts} | 24 ++--- src/model/mosaic/NetworkCurrencyPublic.ts | 98 +++++++++++++++++++ ...arvestMosaic.ts => NetworkHarvestLocal.ts} | 24 ++--- test/core/utils/TransactionMapping.spec.ts | 22 ++--- .../SerializeTransactionToJSON.spec.ts | 8 +- test/model/message/EncryptedMessage.spec.ts | 4 +- test/model/mosaic/NetworkCurrency.spec.ts | 69 +++++++++++++ .../mosaic/NetworkCurrencyMosaic.spec.ts | 45 --------- ...ic.spec.ts => NetworkHarvestLocal.spec.ts} | 18 ++-- .../transaction/AggregateTransaction.spec.ts | 4 +- .../transaction/HashLockTransaction.spec.ts | 8 +- .../transaction/LockFundsTransaction.spec.ts | 18 ++-- .../transaction/SecretLockTransaction.spec.ts | 40 ++++---- .../transaction/TransferTransaction.spec.ts | 24 ++--- 24 files changed, 324 insertions(+), 200 deletions(-) rename src/model/mosaic/{NetworkCurrencyMosaic.ts => NetworkCurrencyLocal.ts} (68%) create mode 100644 src/model/mosaic/NetworkCurrencyPublic.ts rename src/model/mosaic/{NetworkHarvestMosaic.ts => NetworkHarvestLocal.ts} (69%) create mode 100644 test/model/mosaic/NetworkCurrency.spec.ts delete mode 100644 test/model/mosaic/NetworkCurrencyMosaic.spec.ts rename test/model/mosaic/{NetworkHarvestMosaic.spec.ts => NetworkHarvestLocal.spec.ts} (65%) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index 1544377232..86754b93aa 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -24,7 +24,7 @@ import { Address } from '../../src/model/account/Address'; import { PublicAccount } from '../../src/model/account/PublicAccount'; import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { PlainMessage } from '../../src/model/message/PlainMessage'; -import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction'; @@ -92,7 +92,7 @@ describe('AccountHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, diff --git a/e2e/infrastructure/BlockHttp.spec.ts b/e2e/infrastructure/BlockHttp.spec.ts index d6d8298873..088bc62ce2 100644 --- a/e2e/infrastructure/BlockHttp.spec.ts +++ b/e2e/infrastructure/BlockHttp.spec.ts @@ -23,7 +23,7 @@ import { ReceiptRepository } from '../../src/infrastructure/ReceiptRepository'; import { Account } from '../../src/model/account/Account'; import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { PlainMessage } from '../../src/model/message/PlainMessage'; -import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { Deadline } from '../../src/model/transaction/Deadline'; import { TransactionInfo } from '../../src/model/transaction/TransactionInfo'; import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; @@ -73,7 +73,7 @@ describe('BlockHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, diff --git a/e2e/infrastructure/Listener.spec.ts b/e2e/infrastructure/Listener.spec.ts index 5fcfbfea62..287c19a5b6 100644 --- a/e2e/infrastructure/Listener.spec.ts +++ b/e2e/infrastructure/Listener.spec.ts @@ -24,7 +24,7 @@ import { NetworkType } from '../../src/model/blockchain/NetworkType'; 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 { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction'; import { Deadline } from '../../src/model/transaction/Deadline'; @@ -45,7 +45,7 @@ describe('Listener', () => { let namespaceRepository: NamespaceRepository; let generationHash: string; let networkType: NetworkType; - const networkCurrencyMosaicId: NamespaceId = NetworkCurrencyMosaic.NAMESPACE_ID; + const NetworkCurrencyLocalId: NamespaceId = NetworkCurrencyLocal.NAMESPACE_ID; let transactionRepository: TransactionRepository; before(() => { @@ -100,7 +100,7 @@ describe('Listener', () => { mosaicId: MosaicId | NamespaceId) => { const lockFundsTransaction = LockFundsTransaction.create( Deadline.create(), - new Mosaic(mosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), + new Mosaic(mosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))), UInt64.fromUint(1000), signedAggregatedTransaction, networkType, helper.maxFee, @@ -180,7 +180,7 @@ describe('Listener', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), cosignAccount1.address, - [new Mosaic(networkCurrencyMosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY)))], + [new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY)))], PlainMessage.create('test-message'), networkType, helper.maxFee, ); @@ -220,7 +220,7 @@ describe('Listener', () => { it('aggregateBondedTransactionsAdded', (done) => { const signedAggregatedTx = createSignedAggregatedBondTransaction(multisigAccount, account, account2.address); - createHashLockTransactionAndAnnounce(signedAggregatedTx, account, networkCurrencyMosaicId); + createHashLockTransactionAndAnnounce(signedAggregatedTx, account, NetworkCurrencyLocalId); helper.listener.aggregateBondedAdded(account.address).subscribe(() => { done(); }); @@ -239,7 +239,7 @@ describe('Listener', () => { const signedAggregatedTx = createSignedAggregatedBondTransaction(multisigAccount, cosignAccount1, account2.address); - createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, networkCurrencyMosaicId); + createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, NetworkCurrencyLocalId); helper.listener.confirmed(cosignAccount1.address).subscribe(() => { helper.listener.aggregateBondedRemoved(cosignAccount1.address).subscribe(() => { done(); @@ -274,7 +274,7 @@ describe('Listener', () => { const signedAggregatedTx = createSignedAggregatedBondTransaction(multisigAccount, cosignAccount1, account2.address); - createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, networkCurrencyMosaicId); + createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, NetworkCurrencyLocalId); helper.listener.cosignatureAdded(cosignAccount1.address).subscribe(() => { done(); }); @@ -341,7 +341,7 @@ describe('Listener', () => { describe('Transactions Status', () => { it('transactionStatusGiven', () => { - const mosaics = [NetworkCurrencyMosaic.createRelative(1000000000000)]; + const mosaics = [NetworkCurrencyLocal.createRelative(1000000000000)]; const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, diff --git a/e2e/infrastructure/NamespaceHttp.spec.ts b/e2e/infrastructure/NamespaceHttp.spec.ts index b32a912997..2f99342369 100644 --- a/e2e/infrastructure/NamespaceHttp.spec.ts +++ b/e2e/infrastructure/NamespaceHttp.spec.ts @@ -18,7 +18,7 @@ import { expect } from 'chai'; import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; import { Account } from '../../src/model/account/Account'; import { Address } from '../../src/model/account/Address'; -import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction'; @@ -28,7 +28,7 @@ import { UInt64 } from '../../src/model/UInt64'; import { IntegrationTestHelper } from './IntegrationTestHelper'; describe('NamespaceHttp', () => { - const defaultNamespaceId = NetworkCurrencyMosaic.NAMESPACE_ID; + const defaultNamespaceId = NetworkCurrencyLocal.NAMESPACE_ID; let namespaceId: NamespaceId; let namespaceRepository: NamespaceRepository; let account: Account; diff --git a/e2e/infrastructure/TransactionHttp.spec.ts b/e2e/infrastructure/TransactionHttp.spec.ts index 9b081b9b24..b0da9ac687 100644 --- a/e2e/infrastructure/TransactionHttp.spec.ts +++ b/e2e/infrastructure/TransactionHttp.spec.ts @@ -35,7 +35,7 @@ import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce'; import { MosaicSupplyChangeAction } from '../../src/model/mosaic/MosaicSupplyChangeAction'; -import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AccountRestrictionModificationAction } from '../../src/model/restriction/AccountRestrictionModificationAction'; @@ -94,7 +94,7 @@ describe('TransactionHttp', () => { let generationHash: string; let networkType: NetworkType; let mosaicId: MosaicId; - let networkCurrencyMosaicId: MosaicId; + let NetworkCurrencyLocalId: MosaicId; let namespaceId: NamespaceId; let harvestingAccount: Account; let transactionRepository: TransactionRepository; @@ -134,7 +134,7 @@ describe('TransactionHttp', () => { describe('Get network currency mosaic id', () => { it('get mosaicId', async () => { - networkCurrencyMosaicId = + NetworkCurrencyLocalId = (await namespaceRepository.getLinkedMosaicId(new NamespaceId('cat.currency')).toPromise()) as MosaicId; }); }); @@ -386,7 +386,7 @@ describe('TransactionHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, ); @@ -399,7 +399,7 @@ describe('TransactionHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, ); @@ -672,7 +672,7 @@ describe('TransactionHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), namespaceId, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, ); @@ -772,7 +772,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const hashLockTransaction = HashLockTransaction.create(Deadline.create(), - new Mosaic(new NamespaceId('cat.currency'), UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), + new Mosaic(new NamespaceId('cat.currency'), UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))), UInt64.fromUint(10000), signedTransaction, networkType, helper.maxFee); @@ -812,7 +812,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), - new Mosaic(networkCurrencyMosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), + new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))), UInt64.fromUint(10000), signedTransaction, networkType, helper.maxFee); @@ -831,7 +831,7 @@ describe('TransactionHttp', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), - new Mosaic(networkCurrencyMosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), + new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))), UInt64.fromUint(10), signedTransaction, networkType, helper.maxFee); @@ -871,7 +871,7 @@ describe('TransactionHttp', () => { it('standalone', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), @@ -893,7 +893,7 @@ describe('TransactionHttp', () => { it('aggregate', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), @@ -912,7 +912,7 @@ describe('TransactionHttp', () => { it('standalone', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Keccak_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), @@ -927,7 +927,7 @@ describe('TransactionHttp', () => { it('aggregate', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Keccak_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), @@ -948,7 +948,7 @@ describe('TransactionHttp', () => { const secret = CryptoJS.RIPEMD160(CryptoJS.SHA256(secretSeed).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_160, secret, @@ -965,7 +965,7 @@ describe('TransactionHttp', () => { const secret = CryptoJS.RIPEMD160(CryptoJS.SHA256(secretSeed).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_160, secret, @@ -984,7 +984,7 @@ describe('TransactionHttp', () => { it('standalone', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), @@ -999,7 +999,7 @@ describe('TransactionHttp', () => { it('aggregate', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_256, sha3_256.create().update(Crypto.randomBytes(20)).hex(), @@ -1023,7 +1023,7 @@ describe('TransactionHttp', () => { const secretLockTransaction = SecretLockTransaction.create( Deadline.create(1, ChronoUnit.HOURS), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(11), HashType.Op_Sha3_256, secret, @@ -1061,7 +1061,7 @@ describe('TransactionHttp', () => { const proof = convert.uint8ToHex(secretSeed); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, secret, @@ -1094,7 +1094,7 @@ describe('TransactionHttp', () => { const proof = convert.uint8ToHex(secretSeed); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Keccak_256, secret, @@ -1123,7 +1123,7 @@ describe('TransactionHttp', () => { const proof = convert.uint8ToHex(secretSeed); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Keccak_256, secret, @@ -1157,7 +1157,7 @@ describe('TransactionHttp', () => { const proof = secretSeed; const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_160, secret, @@ -1189,7 +1189,7 @@ describe('TransactionHttp', () => { const proof = secretSeed; const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_160, secret, @@ -1223,7 +1223,7 @@ describe('TransactionHttp', () => { const proof = secretSeed; const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_256, secret, @@ -1254,7 +1254,7 @@ describe('TransactionHttp', () => { const proof = secretSeed; const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_256, secret, @@ -1288,8 +1288,8 @@ describe('TransactionHttp', () => { // AliceAccount: account // BobAccount: account - const sendAmount = NetworkCurrencyMosaic.createRelative(1000); - const backAmount = NetworkCurrencyMosaic.createRelative(1); + const sendAmount = NetworkCurrencyLocal.createRelative(1000); + const backAmount = NetworkCurrencyLocal.createRelative(1); const aliceTransferTransaction = TransferTransaction.create(Deadline.create(), account2.address, [sendAmount], PlainMessage.create('payout'), networkType, helper.maxFee); @@ -1384,7 +1384,7 @@ describe('TransactionHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, ); @@ -1399,7 +1399,7 @@ describe('TransactionHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, - [NetworkCurrencyMosaic.createRelative(1)], + [NetworkCurrencyLocal.createRelative(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, ); diff --git a/e2e/infrastructure/UnresolvedMapping.spec.ts b/e2e/infrastructure/UnresolvedMapping.spec.ts index 4b5a6f1e0c..e8713e202b 100644 --- a/e2e/infrastructure/UnresolvedMapping.spec.ts +++ b/e2e/infrastructure/UnresolvedMapping.spec.ts @@ -24,7 +24,7 @@ import { PlainMessage } from '../../src/model/message/PlainMessage'; import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce'; -import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { MosaicRestrictionType } from '../../src/model/restriction/MosaicRestrictionType'; @@ -50,7 +50,7 @@ describe('TransactionHttp', () => { let generationHash: string; let networkType: NetworkType; let mosaicId: MosaicId; - let networkCurrencyMosaicId: MosaicId; + let NetworkCurrencyLocalId: MosaicId; let namespaceIdAddress: NamespaceId; let namespaceIdMosaic: NamespaceId; @@ -79,7 +79,7 @@ describe('TransactionHttp', () => { */ describe('Get network currency mosaic id', () => { it('get mosaicId', async () => { - networkCurrencyMosaicId = + NetworkCurrencyLocalId = (await namespaceRepository.getLinkedMosaicId(new NamespaceId('cat.currency')).toPromise()) as MosaicId; }); }); @@ -259,7 +259,7 @@ describe('TransactionHttp', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, ); diff --git a/e2e/service/TransactionService.spec.ts b/e2e/service/TransactionService.spec.ts index afaae119ff..19aadb7c3c 100644 --- a/e2e/service/TransactionService.spec.ts +++ b/e2e/service/TransactionService.spec.ts @@ -26,7 +26,7 @@ import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce'; import { MosaicSupplyChangeAction } from '../../src/model/mosaic/MosaicSupplyChangeAction'; -import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction'; @@ -199,7 +199,7 @@ describe('TransactionService', () => { Deadline.create(), addressAlias, [ - NetworkCurrencyMosaic.createAbsolute(1), + NetworkCurrencyLocal.createAbsolute(1), new Mosaic(mosaicAlias, UInt64.fromUint(1)), ], PlainMessage.create('test-message'), @@ -353,7 +353,7 @@ describe('TransactionService', () => { Deadline.create(), addressAlias, [ - NetworkCurrencyMosaic.createAbsolute(1), + NetworkCurrencyLocal.createAbsolute(1), new Mosaic(mosaicAlias, UInt64.fromUint(1)), ], PlainMessage.create('test-message'), diff --git a/e2e/service/TransactionService_AggregateBonded.spec.ts b/e2e/service/TransactionService_AggregateBonded.spec.ts index 5b5a50f493..b4c4ec81d6 100644 --- a/e2e/service/TransactionService_AggregateBonded.spec.ts +++ b/e2e/service/TransactionService_AggregateBonded.spec.ts @@ -23,7 +23,7 @@ import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { PlainMessage } from '../../src/model/message/PlainMessage'; import { Mosaic } from '../../src/model/mosaic/Mosaic'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; -import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction'; import { Deadline } from '../../src/model/transaction/Deadline'; @@ -49,7 +49,7 @@ describe('TransactionService', () => { let generationHash: string; let networkType: NetworkType; let transactionService: TransactionService; - let networkCurrencyMosaicId: MosaicId; + let NetworkCurrencyLocalId: MosaicId; before(() => { return helper.start().then(() => { @@ -100,7 +100,7 @@ describe('TransactionService', () => { describe('Get network currency mosaic id', () => { it('get mosaicId', () => { return namespaceRepository.getLinkedMosaicId(new NamespaceId('cat.currency')).toPromise().then((networkMosaicId: MosaicId) => { - networkCurrencyMosaicId = networkMosaicId; + NetworkCurrencyLocalId = networkMosaicId; }); }); }); @@ -144,7 +144,7 @@ describe('TransactionService', () => { Deadline.create(), account2.address, [ - NetworkCurrencyMosaic.createAbsolute(1), + NetworkCurrencyLocal.createAbsolute(1), ], PlainMessage.create('test-message'), networkType, helper.maxFee, @@ -164,7 +164,7 @@ describe('TransactionService', () => { const signedAggregatedTransaction = createSignedAggregatedBondTransaction(multisigAccount, account, account2.address); const lockFundsTransaction = LockFundsTransaction.create( Deadline.create(), - new Mosaic(networkCurrencyMosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), + new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))), UInt64.fromUint(1000), signedAggregatedTransaction, networkType, helper.maxFee, @@ -184,7 +184,7 @@ describe('TransactionService', () => { const signedAggregatedTransaction = createSignedAggregatedBondTransaction(multisigAccount, account, account2.address); const lockFundsTransaction = LockFundsTransaction.create( Deadline.create(), - new Mosaic(networkCurrencyMosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))), + new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))), UInt64.fromUint(1000), signedAggregatedTransaction, networkType, helper.maxFee, diff --git a/src/infrastructure/infrastructure.ts b/src/infrastructure/infrastructure.ts index 3a297391a7..9ac061be35 100644 --- a/src/infrastructure/infrastructure.ts +++ b/src/infrastructure/infrastructure.ts @@ -47,3 +47,4 @@ export * from './RepositoryFactory'; export * from './RestrictionAccountRepository'; export * from './RestrictionMosaicRepository'; export * from './TransactionRepository'; +export * from './TransactionSearchCriteria'; diff --git a/src/model/model.ts b/src/model/model.ts index ee624e7d69..4f97aa7e4a 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -49,8 +49,9 @@ export * from './mosaic/MosaicSupplyChangeAction'; export * from './mosaic/MosaicFlags'; export * from '../service/MosaicView'; export * from '../service/MosaicAmountView'; -export * from './mosaic/NetworkCurrencyMosaic'; -export * from './mosaic/NetworkHarvestMosaic'; +export * from './mosaic/NetworkCurrencyLocal'; +export * from './mosaic/NetworkCurrencyPublic'; +export * from './mosaic/NetworkHarvestLocal'; export * from './mosaic/MosaicNames'; // Mosaic diff --git a/src/model/mosaic/NetworkCurrencyMosaic.ts b/src/model/mosaic/NetworkCurrencyLocal.ts similarity index 68% rename from src/model/mosaic/NetworkCurrencyMosaic.ts rename to src/model/mosaic/NetworkCurrencyLocal.ts index fb2ebc2722..c1a6e34dc9 100644 --- a/src/model/mosaic/NetworkCurrencyMosaic.ts +++ b/src/model/mosaic/NetworkCurrencyLocal.ts @@ -20,14 +20,14 @@ import {Mosaic} from './Mosaic'; import {MosaicId} from './MosaicId'; /** - * NetworkCurrencyMosaic mosaic + * NetworkCurrencyLocal mosaic for local test network (local bootstrap server) * * This represents the per-network currency mosaic. This mosaicId is aliased * with namespace name `cat.currency`. * * @since 0.10.2 */ -export class NetworkCurrencyMosaic extends Mosaic { +export class NetworkCurrencyLocal extends Mosaic { /** * namespaceId of `currency` namespace. @@ -66,33 +66,33 @@ export class NetworkCurrencyMosaic extends Mosaic { * @param amount */ private constructor(amount: UInt64) { - super(NetworkCurrencyMosaic.NAMESPACE_ID, amount); + super(NetworkCurrencyLocal.NAMESPACE_ID, amount); } /** - * Create NetworkCurrencyMosaic with using NetworkCurrencyMosaic as unit. + * Create NetworkCurrencyLocal with using NetworkCurrencyLocal as unit. * * @param amount - * @returns {NetworkCurrencyMosaic} + * @returns {NetworkCurrencyLocal} */ public static createRelative(amount: UInt64 | number) { if (typeof amount === 'number') { - return new NetworkCurrencyMosaic(UInt64.fromUint(amount * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))); + return new NetworkCurrencyLocal(UInt64.fromUint(amount * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))); } - return new NetworkCurrencyMosaic(UInt64.fromUint((amount as UInt64).compact() * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))); + return new NetworkCurrencyLocal(UInt64.fromUint((amount as UInt64).compact() * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))); } /** - * Create NetworkCurrencyMosaic with using micro NetworkCurrencyMosaic as unit, - * 1 NetworkCurrencyMosaic = 1000000 micro NetworkCurrencyMosaic. + * Create NetworkCurrencyLocal with using micro NetworkCurrencyLocal as unit, + * 1 NetworkCurrencyLocal = 1000000 micro NetworkCurrencyLocal. * * @param amount - * @returns {NetworkCurrencyMosaic} + * @returns {NetworkCurrencyLocal} */ public static createAbsolute(amount: UInt64 | number) { if (typeof amount === 'number') { - return new NetworkCurrencyMosaic(UInt64.fromUint(amount)); + return new NetworkCurrencyLocal(UInt64.fromUint(amount)); } - return new NetworkCurrencyMosaic(amount as UInt64); + return new NetworkCurrencyLocal(amount as UInt64); } } diff --git a/src/model/mosaic/NetworkCurrencyPublic.ts b/src/model/mosaic/NetworkCurrencyPublic.ts new file mode 100644 index 0000000000..bb9b39bf04 --- /dev/null +++ b/src/model/mosaic/NetworkCurrencyPublic.ts @@ -0,0 +1,98 @@ +/* + * Copyright 2019 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 {UInt64} from '../UInt64'; +import {Mosaic} from './Mosaic'; +import {MosaicId} from './MosaicId'; + +/** + * NetworkCurrencyPublic mosaic for public / Public_test network + * + * This represents the per-network currency mosaic. This mosaicId is aliased + * with namespace name `symbol.xym`. + * + * @since 0.10.2 + */ +export class NetworkCurrencyPublic extends Mosaic { + + /** + * namespaceId of `currency` namespace. + * + * @type {Id} + */ + public static NAMESPACE_ID = new NamespaceId('symbol.xym'); + + /** + * Divisiblity + * @type {number} + */ + public static DIVISIBILITY = 6; + + /** + * Initial supply + * @type {number} + */ + public static INITIAL_SUPPLY = 8999999998; + + /** + * Is tranferable + * @type {boolean} + */ + public static TRANSFERABLE = true; + + /** + * Is Supply mutable + * @type {boolean} + */ + public static SUPPLY_MUTABLE = false; + + /** + * constructor + * @param owner + * @param amount + */ + private constructor(amount: UInt64) { + super(NetworkCurrencyPublic.NAMESPACE_ID, amount); + } + + /** + * Create NetworkCurrencyPublic with using NetworkCurrencyPublic as unit. + * + * @param amount + * @returns {NetworkCurrencyPublic} + */ + public static createRelative(amount: UInt64 | number) { + if (typeof amount === 'number') { + return new NetworkCurrencyPublic(UInt64.fromUint(amount * Math.pow(10, NetworkCurrencyPublic.DIVISIBILITY))); + } + return new NetworkCurrencyPublic(UInt64.fromUint((amount as UInt64).compact() * Math.pow(10, NetworkCurrencyPublic.DIVISIBILITY))); + } + + /** + * Create NetworkCurrencyPublic with using micro NetworkCurrencyPublic as unit, + * 1 NetworkCurrencyPublic = 1000000 micro NetworkCurrencyPublic. + * + * @param amount + * @returns {NetworkCurrencyPublic} + */ + public static createAbsolute(amount: UInt64 | number) { + if (typeof amount === 'number') { + return new NetworkCurrencyPublic(UInt64.fromUint(amount)); + } + return new NetworkCurrencyPublic(amount as UInt64); + } +} diff --git a/src/model/mosaic/NetworkHarvestMosaic.ts b/src/model/mosaic/NetworkHarvestLocal.ts similarity index 69% rename from src/model/mosaic/NetworkHarvestMosaic.ts rename to src/model/mosaic/NetworkHarvestLocal.ts index f9df23fb98..c600988cf1 100644 --- a/src/model/mosaic/NetworkHarvestMosaic.ts +++ b/src/model/mosaic/NetworkHarvestLocal.ts @@ -19,14 +19,14 @@ import {Mosaic} from './Mosaic'; import {MosaicId} from './MosaicId'; /** - * NetworkHarvestMosaic mosaic + * NetworkHarvestLocal mosaic * * This represents the per-network harvest mosaic. This mosaicId is aliased * with namespace name `cat.harvest`. * * @since 0.10.2 */ -export class NetworkHarvestMosaic extends Mosaic { +export class NetworkHarvestLocal extends Mosaic { /** * namespaceId of `currency` namespace. @@ -65,33 +65,33 @@ export class NetworkHarvestMosaic extends Mosaic { * @param amount */ private constructor(amount: UInt64) { - super(NetworkHarvestMosaic.NAMESPACE_ID, amount); + super(NetworkHarvestLocal.NAMESPACE_ID, amount); } /** - * Create NetworkHarvestMosaic with using NetworkHarvestMosaic as unit. + * Create NetworkHarvestLocal with using NetworkHarvestLocal as unit. * * @param amount - * @returns {NetworkHarvestMosaic} + * @returns {NetworkHarvestLocal} */ public static createRelative(amount: UInt64 | number) { if (typeof amount === 'number') { - return new NetworkHarvestMosaic(UInt64.fromUint(amount * Math.pow(10, NetworkHarvestMosaic.DIVISIBILITY))); + return new NetworkHarvestLocal(UInt64.fromUint(amount * Math.pow(10, NetworkHarvestLocal.DIVISIBILITY))); } - return new NetworkHarvestMosaic(UInt64.fromUint((amount as UInt64).compact() * Math.pow(10, NetworkHarvestMosaic.DIVISIBILITY))); + return new NetworkHarvestLocal(UInt64.fromUint((amount as UInt64).compact() * Math.pow(10, NetworkHarvestLocal.DIVISIBILITY))); } /** - * Create NetworkHarvestMosaic with using micro NetworkHarvestMosaic as unit, - * 1 NetworkHarvestMosaic = 1000000 micro NetworkHarvestMosaic. + * Create NetworkHarvestLocal with using micro NetworkHarvestLocal as unit, + * 1 NetworkHarvestLocal = 1000000 micro NetworkHarvestLocal. * * @param amount - * @returns {NetworkHarvestMosaic} + * @returns {NetworkHarvestLocal} */ public static createAbsolute(amount: UInt64 | number) { if (typeof amount === 'number') { - return new NetworkHarvestMosaic(UInt64.fromUint(amount)); + return new NetworkHarvestLocal(UInt64.fromUint(amount)); } - return new NetworkHarvestMosaic(amount as UInt64); + return new NetworkHarvestLocal(amount as UInt64); } } diff --git a/test/core/utils/TransactionMapping.spec.ts b/test/core/utils/TransactionMapping.spec.ts index 30618d20c0..ecfda570d4 100644 --- a/test/core/utils/TransactionMapping.spec.ts +++ b/test/core/utils/TransactionMapping.spec.ts @@ -31,7 +31,7 @@ import { MosaicFlags } from '../../../src/model/mosaic/MosaicFlags'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; import { MosaicNonce } from '../../../src/model/mosaic/MosaicNonce'; import { MosaicSupplyChangeAction } from '../../../src/model/mosaic/MosaicSupplyChangeAction'; -import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../../src/model/mosaic/NetworkCurrencyLocal'; import { AliasAction } from '../../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { NamespaceRegistrationType } from '../../../src/model/namespace/NamespaceRegistrationType'; @@ -320,7 +320,7 @@ describe('TransactionMapping - createFromPayload', () => { Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -341,7 +341,7 @@ describe('TransactionMapping - createFromPayload', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(Convert.hexToUint8(proof)).hex(), @@ -462,7 +462,7 @@ describe('TransactionMapping - createFromPayload', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); @@ -471,7 +471,7 @@ describe('TransactionMapping - createFromPayload', () => { const transaction = TransactionMapping.createFromPayload(signedLockFundTransaction.payload) as LockFundsTransaction; - deepEqual(transaction.mosaic.id.id, NetworkCurrencyMosaic.NAMESPACE_ID.id); + deepEqual(transaction.mosaic.id.id, NetworkCurrencyLocal.NAMESPACE_ID.id); expect(transaction.mosaic.amount.compact()).to.be.equal(10000000); expect(transaction.hash).to.be.equal(signedTransaction.hash); }); @@ -676,7 +676,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -693,7 +693,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => Deadline.create(), new NamespaceId([33347626, 3779697293]), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -710,7 +710,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], new EncryptedMessage('12324556'), NetworkType.MIJIN_TEST, @@ -871,7 +871,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(Convert.hexToUint8(proof)).hex(), @@ -892,7 +892,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => const recipientAddress = new NamespaceId('test'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(Convert.hexToUint8(proof)).hex(), @@ -1049,7 +1049,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () => ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); diff --git a/test/infrastructure/SerializeTransactionToJSON.spec.ts b/test/infrastructure/SerializeTransactionToJSON.spec.ts index fece5987ac..5e23359f61 100644 --- a/test/infrastructure/SerializeTransactionToJSON.spec.ts +++ b/test/infrastructure/SerializeTransactionToJSON.spec.ts @@ -26,7 +26,7 @@ import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce'; import { MosaicSupplyChangeAction } from '../../src/model/mosaic/MosaicSupplyChangeAction'; -import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { AliasAction } from '../../src/model/namespace/AliasAction'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; import { AccountRestrictionFlags } from '../../src/model/restriction/AccountRestrictionType'; @@ -217,7 +217,7 @@ describe('SerializeTransactionToJSON', () => { Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -236,7 +236,7 @@ describe('SerializeTransactionToJSON', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(convert.hexToUint8(proof)).hex(), @@ -341,7 +341,7 @@ describe('SerializeTransactionToJSON', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); diff --git a/test/model/message/EncryptedMessage.spec.ts b/test/model/message/EncryptedMessage.spec.ts index 7031093396..ae4cf20a5a 100644 --- a/test/model/message/EncryptedMessage.spec.ts +++ b/test/model/message/EncryptedMessage.spec.ts @@ -17,7 +17,7 @@ import {expect} from 'chai'; import {Account} from '../../../src/model/account/Account'; import {EncryptedMessage} from '../../../src/model/message/EncryptedMessage'; -import { Deadline, NetworkCurrencyMosaic, NetworkType, TransferTransaction } from '../../../src/model/model'; +import { Deadline, NetworkCurrencyLocal, NetworkType, TransferTransaction } from '../../../src/model/model'; describe('EncryptedMessage', () => { @@ -61,7 +61,7 @@ describe('EncryptedMessage', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), recipient.address, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], sender.encryptMessage('Testing simple transfer', recipient.publicAccount, NetworkType.MIJIN_TEST), NetworkType.MIJIN_TEST, ); diff --git a/test/model/mosaic/NetworkCurrency.spec.ts b/test/model/mosaic/NetworkCurrency.spec.ts new file mode 100644 index 0000000000..7f61656afa --- /dev/null +++ b/test/model/mosaic/NetworkCurrency.spec.ts @@ -0,0 +1,69 @@ +/* + * 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 {deepEqual} from 'assert'; +import {expect} from 'chai'; +import {NetworkCurrencyLocal} from '../../../src/model/mosaic/NetworkCurrencyLocal'; +import { NetworkCurrencyPublic } from '../../../src/model/mosaic/NetworkCurrencyPublic'; +import {NamespaceId} from '../../../src/model/namespace/NamespaceId'; +import { UInt64 } from '../../../src/model/UInt64'; + +describe('NetworkCurrencyLocal', () => { + + it('should createComplete an NetworkCurrencyLocal object', () => { + + const currency = NetworkCurrencyLocal.createRelative(1000); + + deepEqual(currency.id.id.toHex(), '85BBEA6CC462B244'); // holds NAMESPACE_ID + expect(currency.amount.compact()).to.be.equal(1000 * 1000000); + }); + + it('should set amount in smallest unit when toDTO()', () => { + + const currency = NetworkCurrencyLocal.createRelative(1000); + expect(UInt64.fromNumericString(currency.toDTO().amount).toDTO()[0]).to.be.equal(1000 * 1000000); + }); + + it('should have valid statics', () => { + deepEqual(NetworkCurrencyLocal.NAMESPACE_ID.id, new NamespaceId([3294802500, 2243684972]).id); + expect(NetworkCurrencyLocal.DIVISIBILITY).to.be.equal(6); + expect(NetworkCurrencyLocal.TRANSFERABLE).to.be.equal(true); + expect(NetworkCurrencyLocal.SUPPLY_MUTABLE).to.be.equal(false); + }); +}); + +describe('NetworkCurrencyPublic', () => { + + it('should createComplete an NetworkCurrencyPublic object', () => { + + const currency = NetworkCurrencyPublic.createRelative(1000); + deepEqual(currency.id.id.toHex(), 'E74B99BA41F4AFEE'); // holds NAMESPACE_ID + expect(currency.amount.compact()).to.be.equal(1000 * 1000000); + }); + + it('should set amount in smallest unit when toDTO()', () => { + + const currency = NetworkCurrencyPublic.createRelative(1000); + expect(UInt64.fromNumericString(currency.toDTO().amount).toDTO()[0]).to.be.equal(1000 * 1000000); + }); + + it('should have valid statics', () => { + deepEqual(NetworkCurrencyPublic.NAMESPACE_ID.id, new NamespaceId([1106554862, 3880491450]).id); + expect(NetworkCurrencyPublic.DIVISIBILITY).to.be.equal(6); + expect(NetworkCurrencyPublic.TRANSFERABLE).to.be.equal(true); + expect(NetworkCurrencyPublic.SUPPLY_MUTABLE).to.be.equal(false); + }); +}); diff --git a/test/model/mosaic/NetworkCurrencyMosaic.spec.ts b/test/model/mosaic/NetworkCurrencyMosaic.spec.ts deleted file mode 100644 index dd0acf6e2c..0000000000 --- a/test/model/mosaic/NetworkCurrencyMosaic.spec.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 {deepEqual} from 'assert'; -import {expect} from 'chai'; -import {NetworkCurrencyMosaic} from '../../../src/model/mosaic/NetworkCurrencyMosaic'; -import {NamespaceId} from '../../../src/model/namespace/NamespaceId'; -import { UInt64 } from '../../../src/model/UInt64'; - -describe('NetworkCurrencyMosaic', () => { - - it('should createComplete an NetworkCurrencyMosaic object', () => { - - const currency = NetworkCurrencyMosaic.createRelative(1000); - - deepEqual(currency.id.id.toHex(), '85BBEA6CC462B244'); // holds NAMESPACE_ID - expect(currency.amount.compact()).to.be.equal(1000 * 1000000); - }); - - it('should set amount in smallest unit when toDTO()', () => { - - const currency = NetworkCurrencyMosaic.createRelative(1000); - expect(UInt64.fromNumericString(currency.toDTO().amount).toDTO()[0]).to.be.equal(1000 * 1000000); - }); - - it('should have valid statics', () => { - deepEqual(NetworkCurrencyMosaic.NAMESPACE_ID.id, new NamespaceId([3294802500, 2243684972]).id); - expect(NetworkCurrencyMosaic.DIVISIBILITY).to.be.equal(6); - expect(NetworkCurrencyMosaic.TRANSFERABLE).to.be.equal(true); - expect(NetworkCurrencyMosaic.SUPPLY_MUTABLE).to.be.equal(false); - }); -}); diff --git a/test/model/mosaic/NetworkHarvestMosaic.spec.ts b/test/model/mosaic/NetworkHarvestLocal.spec.ts similarity index 65% rename from test/model/mosaic/NetworkHarvestMosaic.spec.ts rename to test/model/mosaic/NetworkHarvestLocal.spec.ts index baa710071a..83cf35dd91 100644 --- a/test/model/mosaic/NetworkHarvestMosaic.spec.ts +++ b/test/model/mosaic/NetworkHarvestLocal.spec.ts @@ -17,15 +17,15 @@ import {deepEqual} from 'assert'; import {expect} from 'chai'; import {MosaicId} from '../../../src/model/mosaic/MosaicId'; -import {NetworkHarvestMosaic} from '../../../src/model/mosaic/NetworkHarvestMosaic'; +import {NetworkHarvestLocal} from '../../../src/model/mosaic/NetworkHarvestLocal'; import {NamespaceId} from '../../../src/model/namespace/NamespaceId'; import { UInt64 } from '../../../src/model/UInt64'; -describe('NetworkHarvestMosaic', () => { +describe('NetworkHarvestLocal', () => { - it('should createComplete an NetworkHarvestMosaic object', () => { + it('should createComplete an NetworkHarvestLocal object', () => { - const currency = NetworkHarvestMosaic.createRelative(1000); + const currency = NetworkHarvestLocal.createRelative(1000); deepEqual(currency.id.id.toHex(), '941299B2B7E1291C'); expect(currency.amount.compact()).to.be.equal(1000 * 1000); @@ -33,14 +33,14 @@ describe('NetworkHarvestMosaic', () => { it('should set amount in smallest unit when toDTO()', () => { - const currency = NetworkHarvestMosaic.createRelative(1000); + const currency = NetworkHarvestLocal.createRelative(1000); expect(UInt64.fromNumericString(currency.toDTO().amount).toDTO()[0]).to.be.equal(1000 * 1000); }); it('should have valid statics', () => { - deepEqual(NetworkHarvestMosaic.NAMESPACE_ID.id, new NamespaceId([3084986652, 2484246962]).id); - expect(NetworkHarvestMosaic.DIVISIBILITY).to.be.equal(3); - expect(NetworkHarvestMosaic.TRANSFERABLE).to.be.equal(true); - expect(NetworkHarvestMosaic.SUPPLY_MUTABLE).to.be.equal(true); + deepEqual(NetworkHarvestLocal.NAMESPACE_ID.id, new NamespaceId([3084986652, 2484246962]).id); + expect(NetworkHarvestLocal.DIVISIBILITY).to.be.equal(3); + expect(NetworkHarvestLocal.TRANSFERABLE).to.be.equal(true); + expect(NetworkHarvestLocal.SUPPLY_MUTABLE).to.be.equal(true); }); }); diff --git a/test/model/transaction/AggregateTransaction.spec.ts b/test/model/transaction/AggregateTransaction.spec.ts index f4b136adc6..83fbb051e0 100644 --- a/test/model/transaction/AggregateTransaction.spec.ts +++ b/test/model/transaction/AggregateTransaction.spec.ts @@ -30,7 +30,7 @@ import {MosaicFlags} from '../../../src/model/mosaic/MosaicFlags'; import {MosaicId} from '../../../src/model/mosaic/MosaicId'; import {MosaicNonce} from '../../../src/model/mosaic/MosaicNonce'; import {MosaicSupplyChangeAction} from '../../../src/model/mosaic/MosaicSupplyChangeAction'; -import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../../src/model/mosaic/NetworkCurrencyLocal'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { ReceiptSource } from '../../../src/model/receipt/ReceiptSource'; import { ResolutionEntry } from '../../../src/model/receipt/ResolutionEntry'; @@ -549,7 +549,7 @@ describe('AggregateTransaction', () => { Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('NEM'), NetworkType.MIJIN_TEST, diff --git a/test/model/transaction/HashLockTransaction.spec.ts b/test/model/transaction/HashLockTransaction.spec.ts index 70df873a44..65a2fca403 100644 --- a/test/model/transaction/HashLockTransaction.spec.ts +++ b/test/model/transaction/HashLockTransaction.spec.ts @@ -16,7 +16,7 @@ import {expect} from 'chai'; import {Convert} from '../../../src/core/format'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; -import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../../src/model/mosaic/NetworkCurrencyLocal'; import {AggregateTransaction} from '../../../src/model/transaction/AggregateTransaction'; import {Deadline} from '../../../src/model/transaction/Deadline'; import {HashLockTransaction} from '../../../src/model/transaction/HashLockTransaction'; @@ -35,11 +35,11 @@ describe('HashLockTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const transaction = HashLockTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); - expect(transaction.mosaic.id).to.be.equal(NetworkCurrencyMosaic.NAMESPACE_ID); + expect(transaction.mosaic.id).to.be.equal(NetworkCurrencyLocal.NAMESPACE_ID); expect(transaction.mosaic.amount.compact()).to.be.equal(10000000); expect(transaction.hash).to.be.equal(signedTransaction.hash); expect(Convert.hexToUint8(transaction.serialize()).length).to.be.equal(transaction.size); @@ -55,7 +55,7 @@ describe('HashLockTransaction', () => { const signedTransaction = account.sign(aggregateTransaction, generationHash); expect(() => { HashLockTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); diff --git a/test/model/transaction/LockFundsTransaction.spec.ts b/test/model/transaction/LockFundsTransaction.spec.ts index 3287d3abda..f43a11b4c7 100644 --- a/test/model/transaction/LockFundsTransaction.spec.ts +++ b/test/model/transaction/LockFundsTransaction.spec.ts @@ -20,7 +20,7 @@ import {Account} from '../../../src/model/account/Account'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import { Mosaic } from '../../../src/model/mosaic/Mosaic'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; -import {NetworkCurrencyMosaic} from '../../../src/model/mosaic/NetworkCurrencyMosaic'; +import {NetworkCurrencyLocal} from '../../../src/model/mosaic/NetworkCurrencyLocal'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { ReceiptSource } from '../../../src/model/receipt/ReceiptSource'; import { ResolutionEntry } from '../../../src/model/receipt/ResolutionEntry'; @@ -58,7 +58,7 @@ describe('LockFundsTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST, @@ -78,7 +78,7 @@ describe('LockFundsTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST, @@ -98,11 +98,11 @@ describe('LockFundsTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const transaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); - deepEqual(transaction.mosaic.id.id, NetworkCurrencyMosaic.NAMESPACE_ID.id); + deepEqual(transaction.mosaic.id.id, NetworkCurrencyLocal.NAMESPACE_ID.id); expect(transaction.mosaic.amount.compact()).to.be.equal(10000000); expect(transaction.hash).to.be.equal(signedTransaction.hash); }); @@ -117,7 +117,7 @@ describe('LockFundsTransaction', () => { const signedTransaction = account.sign(aggregateTransaction, generationHash); expect(() => { LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST); @@ -133,7 +133,7 @@ describe('LockFundsTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST, @@ -156,7 +156,7 @@ describe('LockFundsTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST, @@ -174,7 +174,7 @@ describe('LockFundsTransaction', () => { ); const signedTransaction = account.sign(aggregateTransaction, generationHash); const lockFundsTransaction = LockFundsTransaction.create(Deadline.create(), - NetworkCurrencyMosaic.createRelative(10), + NetworkCurrencyLocal.createRelative(10), UInt64.fromUint(10), signedTransaction, NetworkType.MIJIN_TEST, diff --git a/test/model/transaction/SecretLockTransaction.spec.ts b/test/model/transaction/SecretLockTransaction.spec.ts index 612b1ef7b8..ebb2d0cb04 100644 --- a/test/model/transaction/SecretLockTransaction.spec.ts +++ b/test/model/transaction/SecretLockTransaction.spec.ts @@ -23,7 +23,7 @@ import {Address} from '../../../src/model/account/Address'; import {NetworkType} from '../../../src/model/blockchain/NetworkType'; import { Mosaic } from '../../../src/model/mosaic/Mosaic'; import { MosaicId } from '../../../src/model/mosaic/MosaicId'; -import {NetworkCurrencyMosaic} from '../../../src/model/mosaic/NetworkCurrencyMosaic'; +import {NetworkCurrencyLocal} from '../../../src/model/mosaic/NetworkCurrencyLocal'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { ReceiptSource } from '../../../src/model/receipt/ReceiptSource'; import { ResolutionEntry } from '../../../src/model/receipt/ResolutionEntry'; @@ -59,7 +59,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(convert.hexToUint8(proof)).hex(), @@ -76,7 +76,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(convert.hexToUint8(proof)).hex(), @@ -94,14 +94,14 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(convert.hexToUint8(proof)).hex(), recipientAddress, NetworkType.MIJIN_TEST, ); - deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyMosaic.NAMESPACE_ID.id); + deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyLocal.NAMESPACE_ID.id); expect(secretLockTransaction.mosaic.amount.equals(UInt64.fromUint(10))).to.be.equal(true); expect(secretLockTransaction.duration.equals(UInt64.fromUint(100))).to.be.equal(true); expect(secretLockTransaction.hashType).to.be.equal(0); @@ -114,7 +114,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(convert.hexToUint8(proof)).hex(), @@ -135,7 +135,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, 'non valid hash', @@ -150,14 +150,14 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Keccak_256, keccak_256.create().update(convert.hexToUint8(proof)).hex(), recipientAddress, NetworkType.MIJIN_TEST, ); - deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyMosaic.NAMESPACE_ID.id); + deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyLocal.NAMESPACE_ID.id); expect(secretLockTransaction.mosaic.amount.equals(UInt64.fromUint(10))).to.be.equal(true); expect(secretLockTransaction.duration.equals(UInt64.fromUint(100))).to.be.equal(true); expect(secretLockTransaction.hashType).to.be.equal(1); @@ -170,7 +170,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Keccak_256, 'non valid hash', @@ -184,14 +184,14 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_160, CryptoJS.RIPEMD160(CryptoJS.SHA256(proof).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex), recipientAddress, NetworkType.MIJIN_TEST, ); - deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyMosaic.NAMESPACE_ID.id); + deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyLocal.NAMESPACE_ID.id); expect(secretLockTransaction.mosaic.amount.equals(UInt64.fromUint(10))).to.be.equal(true); expect(secretLockTransaction.duration.equals(UInt64.fromUint(100))).to.be.equal(true); expect(secretLockTransaction.hashType).to.be.equal(2); @@ -204,7 +204,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_160, 'non valid hash', @@ -218,14 +218,14 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_256, CryptoJS.SHA256(CryptoJS.SHA256(proof).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex), recipientAddress, NetworkType.MIJIN_TEST, ); - deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyMosaic.NAMESPACE_ID.id); + deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyLocal.NAMESPACE_ID.id); expect(secretLockTransaction.mosaic.amount.equals(UInt64.fromUint(10))).to.be.equal(true); expect(secretLockTransaction.duration.equals(UInt64.fromUint(100))).to.be.equal(true); expect(secretLockTransaction.hashType).to.be.equal(3); @@ -238,7 +238,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_256, 'non valid hash', @@ -254,7 +254,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Hash_256, CryptoJS.SHA256(CryptoJS.SHA256(proof).toString(CryptoJS.enc.Hex)).toString(CryptoJS.enc.Hex), @@ -271,14 +271,14 @@ describe('SecretLockTransaction', () => { const recipientAddress = new NamespaceId('test'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(convert.hexToUint8(proof)).hex(), recipientAddress, NetworkType.MIJIN_TEST, ); - deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyMosaic.NAMESPACE_ID.id); + deepEqual(secretLockTransaction.mosaic.id.id, NetworkCurrencyLocal.NAMESPACE_ID.id); expect(secretLockTransaction.mosaic.amount.equals(UInt64.fromUint(10))).to.be.equal(true); expect(secretLockTransaction.duration.equals(UInt64.fromUint(100))).to.be.equal(true); expect(secretLockTransaction.hashType).to.be.equal(0); @@ -291,7 +291,7 @@ describe('SecretLockTransaction', () => { const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL'); const secretLockTransaction = SecretLockTransaction.create( Deadline.create(), - NetworkCurrencyMosaic.createAbsolute(10), + NetworkCurrencyLocal.createAbsolute(10), UInt64.fromUint(100), HashType.Op_Sha3_256, sha3_256.create().update(convert.hexToUint8(proof)).hex(), diff --git a/test/model/transaction/TransferTransaction.spec.ts b/test/model/transaction/TransferTransaction.spec.ts index 6bdc150911..e8f551fda1 100644 --- a/test/model/transaction/TransferTransaction.spec.ts +++ b/test/model/transaction/TransferTransaction.spec.ts @@ -27,7 +27,7 @@ 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 { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../../src/model/mosaic/NetworkCurrencyLocal'; import { NamespaceId } from '../../../src/model/namespace/NamespaceId'; import { ResolutionStatement } from '../../../src/model/receipt/ResolutionStatement'; import { Statement } from '../../../src/model/receipt/Statement'; @@ -113,7 +113,7 @@ describe('TransferTransaction', () => { Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -140,7 +140,7 @@ describe('TransferTransaction', () => { Deadline.create(), addressAlias, [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -166,7 +166,7 @@ describe('TransferTransaction', () => { Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -188,7 +188,7 @@ describe('TransferTransaction', () => { Deadline.create(), new NamespaceId('nem.owner'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -211,7 +211,7 @@ describe('TransferTransaction', () => { Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('NEM'), NetworkType.MIJIN_TEST, @@ -226,7 +226,7 @@ describe('TransferTransaction', () => { Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), [ - NetworkCurrencyMosaic.createRelative(100), + NetworkCurrencyLocal.createRelative(100), ], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, @@ -289,7 +289,7 @@ describe('TransferTransaction', () => { TransferTransaction.create( Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), - [NetworkCurrencyMosaic.createRelative(100)], + [NetworkCurrencyLocal.createRelative(100)], PersistentHarvestingDelegationMessage .create(delegatedPrivateKey, recipientPublicKey, NetworkType.MIJIN_TEST), NetworkType.MIJIN_TEST, @@ -302,7 +302,7 @@ describe('TransferTransaction', () => { TransferTransaction.create( Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), - [NetworkCurrencyMosaic.createRelative(100)], + [NetworkCurrencyLocal.createRelative(100)], PersistentHarvestingDelegationMessage.create('abc', recipientPublicKey, NetworkType.MIJIN_TEST), NetworkType.MIJIN_TEST, ); @@ -314,7 +314,7 @@ describe('TransferTransaction', () => { TransferTransaction.create( Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), - [NetworkCurrencyMosaic.createRelative(100)], + [NetworkCurrencyLocal.createRelative(100)], PersistentHarvestingDelegationMessage.create(delegatedPrivateKey, recipientPublicKey, NetworkType.MIJIN_TEST), NetworkType.MIJIN_TEST, ); @@ -384,7 +384,7 @@ describe('TransferTransaction', () => { const transferTransaction = TransferTransaction.create( Deadline.createFromDTO('1'), namespaceId, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, ); @@ -401,7 +401,7 @@ describe('TransferTransaction', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'), - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), NetworkType.MIJIN_TEST, ).setMaxFee(2); From 17c42f1d17d40ba83432af0d5a01bdbf600f7983 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 18 Feb 2020 20:46:09 +0000 Subject: [PATCH 11/13] Removed transaction search criteria Added queryParam tests --- e2e/infrastructure/AccountHttp.spec.ts | 4 +- src/infrastructure/AccountHttp.ts | 51 +++++++++---------- src/infrastructure/AccountRepository.ts | 12 ++--- src/infrastructure/Http.ts | 5 +- src/infrastructure/QueryParams.ts | 24 ++++++++- .../TransactionSearchCriteria.ts | 45 ---------------- src/infrastructure/infrastructure.ts | 1 - test/infrastructure/QueryParams.spec.ts | 33 ++++++++++++ 8 files changed, 90 insertions(+), 85 deletions(-) delete mode 100644 src/infrastructure/TransactionSearchCriteria.ts create mode 100644 test/infrastructure/QueryParams.spec.ts diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index 86754b93aa..c7b67c8d42 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -18,7 +18,6 @@ import { expect } from 'chai'; import { AccountRepository } from '../../src/infrastructure/AccountRepository'; import { MultisigRepository } from '../../src/infrastructure/MultisigRepository'; import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; -import { TransactionSearchCriteria } from '../../src/infrastructure/TransactionSearchCriteria'; import { Account } from '../../src/model/account/Account'; import { Address } from '../../src/model/account/Address'; import { PublicAccount } from '../../src/model/account/PublicAccount'; @@ -36,6 +35,7 @@ import { TransactionType } from '../../src/model/transaction/TransactionType'; import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; import { UInt64 } from '../../src/model/UInt64'; import { IntegrationTestHelper } from './IntegrationTestHelper'; +import { QueryParams } from '../../src/infrastructure/QueryParams'; describe('AccountHttp', () => { const helper = new IntegrationTestHelper(); @@ -227,7 +227,7 @@ describe('AccountHttp', () => { describe('transactions', () => { it('should call transactions successfully by type', async () => { const transactions = await accountRepository.getAccountTransactions( - publicAccount.address, new TransactionSearchCriteria().setTransactionTypes([TransactionType.TRANSFER])).toPromise(); + publicAccount.address, new QueryParams().setType([TransactionType.TRANSFER])).toPromise(); expect(transactions.length).to.be.greaterThan(0); transactions.forEach((t) => { expect(t.type).to.be.eq(TransactionType.TRANSFER); diff --git a/src/infrastructure/AccountHttp.ts b/src/infrastructure/AccountHttp.ts index 0beabe0ce2..00534731ca 100644 --- a/src/infrastructure/AccountHttp.ts +++ b/src/infrastructure/AccountHttp.ts @@ -29,7 +29,6 @@ import { AccountRepository } from './AccountRepository'; import { Http } from './Http'; import { QueryParams } from './QueryParams'; import { CreateTransactionFromDTO } from './transaction/CreateTransactionFromDTO'; -import { TransactionSearchCriteria } from './TransactionSearchCriteria'; /** * Account http repository. @@ -118,13 +117,13 @@ export class AccountHttp extends Http implements AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - public getAccountTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable { + public getAccountTransactions(address: Address, queryParams?: QueryParams): Observable { return observableFrom( this.accountRoutesApi.getAccountConfirmedTransactions(address.plain(), - this.transactionSearchCriteria(queryParams).pageSize, - this.transactionSearchCriteria(queryParams).id, - this.transactionSearchCriteria(queryParams).ordering, - this.transactionSearchCriteria(queryParams).type)).pipe( + this.queryParams(queryParams).pageSize, + this.queryParams(queryParams).id, + this.queryParams(queryParams).ordering, + this.queryParams(queryParams).type)).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), @@ -139,13 +138,13 @@ export class AccountHttp extends Http implements AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - public getAccountIncomingTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable { + public getAccountIncomingTransactions(address: Address, queryParams?: QueryParams): Observable { return observableFrom( this.accountRoutesApi.getAccountIncomingTransactions(address.plain(), - this.transactionSearchCriteria(queryParams).pageSize, - this.transactionSearchCriteria(queryParams).id, - this.transactionSearchCriteria(queryParams).ordering), - this.transactionSearchCriteria(queryParams).type).pipe( + this.queryParams(queryParams).pageSize, + this.queryParams(queryParams).id, + this.queryParams(queryParams).ordering), + this.queryParams(queryParams).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), @@ -160,13 +159,13 @@ export class AccountHttp extends Http implements AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - public getAccountOutgoingTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable { + public getAccountOutgoingTransactions(address: Address, queryParams?: QueryParams): Observable { return observableFrom( this.accountRoutesApi.getAccountOutgoingTransactions(address.plain(), - this.transactionSearchCriteria(queryParams).pageSize, - this.transactionSearchCriteria(queryParams).id, - this.transactionSearchCriteria(queryParams).ordering), - this.transactionSearchCriteria(queryParams).type).pipe( + this.queryParams(queryParams).pageSize, + this.queryParams(queryParams).id, + this.queryParams(queryParams).ordering), + this.queryParams(queryParams).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), @@ -182,13 +181,13 @@ export class AccountHttp extends Http implements AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - public getAccountUnconfirmedTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable { + public getAccountUnconfirmedTransactions(address: Address, queryParams?: QueryParams): Observable { return observableFrom( this.accountRoutesApi.getAccountUnconfirmedTransactions(address.plain(), - this.transactionSearchCriteria(queryParams).pageSize, - this.transactionSearchCriteria(queryParams).id, - this.transactionSearchCriteria(queryParams).ordering), - this.transactionSearchCriteria(queryParams).type).pipe( + this.queryParams(queryParams).pageSize, + this.queryParams(queryParams).id, + this.queryParams(queryParams).ordering), + this.queryParams(queryParams).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), @@ -203,13 +202,13 @@ export class AccountHttp extends Http implements AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - public getAccountPartialTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable { + public getAccountPartialTransactions(address: Address, queryParams?: QueryParams): Observable { return observableFrom( this.accountRoutesApi.getAccountPartialTransactions(address.plain(), - this.transactionSearchCriteria(queryParams).pageSize, - this.transactionSearchCriteria(queryParams).id, - this.transactionSearchCriteria(queryParams).ordering), - this.transactionSearchCriteria(queryParams).type).pipe( + this.queryParams(queryParams).pageSize, + this.queryParams(queryParams).id, + this.queryParams(queryParams).ordering), + this.queryParams(queryParams).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO) as AggregateTransaction; })), diff --git a/src/infrastructure/AccountRepository.ts b/src/infrastructure/AccountRepository.ts index 83126caed3..1f9b564217 100644 --- a/src/infrastructure/AccountRepository.ts +++ b/src/infrastructure/AccountRepository.ts @@ -19,7 +19,7 @@ import {AccountInfo} from '../model/account/AccountInfo'; import {Address} from '../model/account/Address'; import {AggregateTransaction} from '../model/transaction/AggregateTransaction'; import {Transaction} from '../model/transaction/Transaction'; -import { TransactionSearchCriteria } from './TransactionSearchCriteria'; +import { QueryParams } from './QueryParams'; /** * Account interface repository. @@ -48,7 +48,7 @@ export interface AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - getAccountTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable; + getAccountTransactions(address: Address, queryParams?: QueryParams): Observable; /** * Gets an array of transactions for which an account is the recipient of a transaction. @@ -57,7 +57,7 @@ export interface AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - getAccountIncomingTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable; + getAccountIncomingTransactions(address: Address, queryParams?: QueryParams): Observable; /** * Gets an array of transactions for which an account is the sender a transaction. @@ -66,7 +66,7 @@ export interface AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - getAccountOutgoingTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable; + getAccountOutgoingTransactions(address: Address, queryParams?: QueryParams): Observable; /** * Gets the array of transactions for which an account is the sender or receiver and which have not yet been included in a block. @@ -76,7 +76,7 @@ export interface AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - getAccountUnconfirmedTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable; + getAccountUnconfirmedTransactions(address: Address, queryParams?: QueryParams): Observable; /** * Gets an array of transactions for which an account is the sender or has sign the transaction. @@ -85,5 +85,5 @@ export interface AccountRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - getAccountPartialTransactions(address: Address, queryParams?: TransactionSearchCriteria): Observable; + getAccountPartialTransactions(address: Address, queryParams?: QueryParams): Observable; } diff --git a/src/infrastructure/Http.ts b/src/infrastructure/Http.ts index abd673cb77..1401600e0f 100644 --- a/src/infrastructure/Http.ts +++ b/src/infrastructure/Http.ts @@ -20,7 +20,6 @@ import { from as observableFrom, Observable, of as observableOf, throwError } fr import { catchError, map, shareReplay } from 'rxjs/operators'; import { NetworkType } from '../model/blockchain/NetworkType'; import { QueryParams } from './QueryParams'; -import { TransactionSearchCriteria } from './TransactionSearchCriteria'; /** * Http extended by all http services @@ -57,12 +56,12 @@ export abstract class Http { }; } - transactionSearchCriteria(queryParams?: TransactionSearchCriteria): any { + transactionSearchCriteria(queryParams?: QueryParams): any { return { pageSize: queryParams ? queryParams.pageSize : undefined, id: queryParams ? queryParams.id : undefined, ordering: queryParams ? queryParams.order : undefined, - type: queryParams ? queryParams.type : undefined, + type: queryParams ? queryParams.convertCSV(queryParams.type) : undefined, }; } diff --git a/src/infrastructure/QueryParams.ts b/src/infrastructure/QueryParams.ts index 68722bd39f..c13667e688 100644 --- a/src/infrastructure/QueryParams.ts +++ b/src/infrastructure/QueryParams.ts @@ -44,10 +44,13 @@ export class QueryParams { * ASC. Older to newer. */ public order: Order = Order.DESC; + + /** + * Transaction type list + */ + public type?: TransactionType[]; /** * Constructor - * @param pageSize - * @param id */ constructor() { } @@ -66,4 +69,21 @@ export class QueryParams { this.order = order; return this; } + + public setType(type?: TransactionType[]): QueryParams { + this.type = type; + return this; + } + + /** + * Return comma seperated list + * @param type Transaction type list + */ + public convertCSV(type?: TransactionType[]): string | undefined { + if (!type || type.length === 0) { + return undefined; + } else { + return type.map((t) => t.valueOf().toString()).join(','); + } + } } diff --git a/src/infrastructure/TransactionSearchCriteria.ts b/src/infrastructure/TransactionSearchCriteria.ts deleted file mode 100644 index 4db17aea42..0000000000 --- a/src/infrastructure/TransactionSearchCriteria.ts +++ /dev/null @@ -1,45 +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. - */ - -import { TransactionType } from '../model/transaction/TransactionType'; -import { QueryParams } from './QueryParams'; - - /** - * Transaction search criteria for filtering transaction list - */ -export class TransactionSearchCriteria extends QueryParams { - /** - * Transaction type filter - */ - public type?: string; - /** - * Constructor - * @param pageSize - * @param id - */ - constructor() { - super(); - } - - public setTransactionTypes(transactionTypes?: TransactionType[]): TransactionSearchCriteria { - if (!transactionTypes || transactionTypes.length === 0) { - this.type = undefined; - } else { - this.type = transactionTypes.map((type) => type.valueOf().toString()).join(','); - } - return this; - } -} diff --git a/src/infrastructure/infrastructure.ts b/src/infrastructure/infrastructure.ts index 9ac061be35..3a297391a7 100644 --- a/src/infrastructure/infrastructure.ts +++ b/src/infrastructure/infrastructure.ts @@ -47,4 +47,3 @@ export * from './RepositoryFactory'; export * from './RestrictionAccountRepository'; export * from './RestrictionMosaicRepository'; export * from './TransactionRepository'; -export * from './TransactionSearchCriteria'; diff --git a/test/infrastructure/QueryParams.spec.ts b/test/infrastructure/QueryParams.spec.ts new file mode 100644 index 0000000000..7b61fa9279 --- /dev/null +++ b/test/infrastructure/QueryParams.spec.ts @@ -0,0 +1,33 @@ +/* + * 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 { Order, QueryParams } from '../../src/infrastructure/QueryParams'; +import { TransactionType } from '../../src/model/transaction/TransactionType'; + +describe('QueryParams', () => { + it('should return correct query param', () => { + const param = new QueryParams().setId('0') + .setOrder(Order.ASC) + .setPageSize(10) + .setType([TransactionType.TRANSFER, TransactionType.ACCOUNT_LINK]); + + expect(param.id).to.be.equal('0'); + expect(param.order.valueOf()).to.be.equal(Order.ASC.valueOf()); + expect(param.pageSize).to.be.equal(10); + expect(param.convertCSV(param.type)).to.be.equal('16724,16716'); + }); +}); From 84190386994cb442cf0c2de9bbbe8eaa66a99c34 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 18 Feb 2020 20:53:23 +0000 Subject: [PATCH 12/13] Fixed test issue --- e2e/service/BlockService.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/service/BlockService.spec.ts b/e2e/service/BlockService.spec.ts index 43c1b8ca38..675510c51e 100644 --- a/e2e/service/BlockService.spec.ts +++ b/e2e/service/BlockService.spec.ts @@ -20,7 +20,7 @@ import { TransactionRepository } from '../../src/infrastructure/TransactionRepos import { Account } from '../../src/model/account/Account'; import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { PlainMessage } from '../../src/model/message/PlainMessage'; -import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic'; +import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal'; import { Deadline } from '../../src/model/transaction/Deadline'; import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; import { UInt64 } from '../../src/model/UInt64'; @@ -69,7 +69,7 @@ describe('BlockService', () => { const transferTransaction = TransferTransaction.create( Deadline.create(), account2.address, - [NetworkCurrencyMosaic.createAbsolute(1)], + [NetworkCurrencyLocal.createAbsolute(1)], PlainMessage.create('test-message'), networkType, helper.maxFee, From 2808eb89a291cfc8f94c226d3cb98e964906da9e Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Tue, 18 Feb 2020 21:34:00 +0000 Subject: [PATCH 13/13] Added transaction filter param in accontHttp --- e2e/infrastructure/AccountHttp.spec.ts | 5 +- src/infrastructure/AccountHttp.ts | 36 +++++++++---- src/infrastructure/AccountRepository.ts | 20 ++++++-- src/infrastructure/Http.ts | 8 ++- src/infrastructure/QueryParams.ts | 25 +--------- src/infrastructure/TransactionFilter.ts | 50 +++++++++++++++++++ src/infrastructure/infrastructure.ts | 1 + ...rams.spec.ts => TransactionFilter.spec.ts} | 11 ++-- test/service/BlockService.spec.ts | 11 ++-- 9 files changed, 109 insertions(+), 58 deletions(-) create mode 100644 src/infrastructure/TransactionFilter.ts rename test/infrastructure/{QueryParams.spec.ts => TransactionFilter.spec.ts} (70%) diff --git a/e2e/infrastructure/AccountHttp.spec.ts b/e2e/infrastructure/AccountHttp.spec.ts index c7b67c8d42..6600a2c992 100644 --- a/e2e/infrastructure/AccountHttp.spec.ts +++ b/e2e/infrastructure/AccountHttp.spec.ts @@ -16,8 +16,10 @@ import { expect } from 'chai'; import { AccountRepository } from '../../src/infrastructure/AccountRepository'; +import { TransactionFilter } from '../../src/infrastructure/infrastructure'; import { MultisigRepository } from '../../src/infrastructure/MultisigRepository'; import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository'; +import { QueryParams } from '../../src/infrastructure/QueryParams'; import { Account } from '../../src/model/account/Account'; import { Address } from '../../src/model/account/Address'; import { PublicAccount } from '../../src/model/account/PublicAccount'; @@ -35,7 +37,6 @@ import { TransactionType } from '../../src/model/transaction/TransactionType'; import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; import { UInt64 } from '../../src/model/UInt64'; import { IntegrationTestHelper } from './IntegrationTestHelper'; -import { QueryParams } from '../../src/infrastructure/QueryParams'; describe('AccountHttp', () => { const helper = new IntegrationTestHelper(); @@ -227,7 +228,7 @@ describe('AccountHttp', () => { describe('transactions', () => { it('should call transactions successfully by type', async () => { const transactions = await accountRepository.getAccountTransactions( - publicAccount.address, new QueryParams().setType([TransactionType.TRANSFER])).toPromise(); + publicAccount.address, new QueryParams(), new TransactionFilter().setType([TransactionType.TRANSFER])).toPromise(); expect(transactions.length).to.be.greaterThan(0); transactions.forEach((t) => { expect(t.type).to.be.eq(TransactionType.TRANSFER); diff --git a/src/infrastructure/AccountHttp.ts b/src/infrastructure/AccountHttp.ts index 00534731ca..2242d63afb 100644 --- a/src/infrastructure/AccountHttp.ts +++ b/src/infrastructure/AccountHttp.ts @@ -29,6 +29,7 @@ import { AccountRepository } from './AccountRepository'; import { Http } from './Http'; import { QueryParams } from './QueryParams'; import { CreateTransactionFromDTO } from './transaction/CreateTransactionFromDTO'; +import { TransactionFilter } from './TransactionFilter'; /** * Account http repository. @@ -115,15 +116,18 @@ export class AccountHttp extends Http implements AccountRepository { * Gets an array of confirmed transactions for which an account is signer or receiver. * @param address - * Address can be created rawAddress or publicKey * @param queryParams - (Optional) Query params + * @param transactionFilter - (Optional) Transaction filter * @returns Observable */ - public getAccountTransactions(address: Address, queryParams?: QueryParams): Observable { + public getAccountTransactions(address: Address, + queryParams?: QueryParams, + transactionFilter?: TransactionFilter): Observable { return observableFrom( this.accountRoutesApi.getAccountConfirmedTransactions(address.plain(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, this.queryParams(queryParams).ordering, - this.queryParams(queryParams).type)).pipe( + this.transactionFilter(transactionFilter).type)).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), @@ -136,15 +140,18 @@ export class AccountHttp extends Http implements AccountRepository { * A transaction is said to be incoming with respect to an account if the account is the recipient of a transaction. * @param address - * Address can be created rawAddress or publicKey * @param queryParams - (Optional) Query params + * @param transactionFilter - (Optional) Transaction filter * @returns Observable */ - public getAccountIncomingTransactions(address: Address, queryParams?: QueryParams): Observable { + public getAccountIncomingTransactions(address: Address, + queryParams?: QueryParams, + transactionFilter?: TransactionFilter): Observable { return observableFrom( this.accountRoutesApi.getAccountIncomingTransactions(address.plain(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, this.queryParams(queryParams).ordering), - this.queryParams(queryParams).type).pipe( + this.transactionFilter(transactionFilter).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), @@ -157,15 +164,18 @@ export class AccountHttp extends Http implements AccountRepository { * A transaction is said to be outgoing with respect to an account if the account is the sender of a transaction. * @param address - * Address can be created rawAddress or publicKey * @param queryParams - (Optional) Query params + * @param transactionFilter - (Optional) Transaction filter * @returns Observable */ - public getAccountOutgoingTransactions(address: Address, queryParams?: QueryParams): Observable { + public getAccountOutgoingTransactions(address: Address, + queryParams?: QueryParams, + transactionFilter?: TransactionFilter): Observable { return observableFrom( this.accountRoutesApi.getAccountOutgoingTransactions(address.plain(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, this.queryParams(queryParams).ordering), - this.queryParams(queryParams).type).pipe( + this.transactionFilter(transactionFilter).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), @@ -179,15 +189,18 @@ export class AccountHttp extends Http implements AccountRepository { * Unconfirmed transactions are not guaranteed to be included in any block. * @param address - * Address can be created rawAddress or publicKey * @param queryParams - (Optional) Query params + * @param transactionFilter - (Optional) Transaction filter * @returns Observable */ - public getAccountUnconfirmedTransactions(address: Address, queryParams?: QueryParams): Observable { + public getAccountUnconfirmedTransactions(address: Address, + queryParams?: QueryParams, + transactionFilter?: TransactionFilter): Observable { return observableFrom( this.accountRoutesApi.getAccountUnconfirmedTransactions(address.plain(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, this.queryParams(queryParams).ordering), - this.queryParams(queryParams).type).pipe( + this.transactionFilter(transactionFilter).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO); })), @@ -200,15 +213,18 @@ export class AccountHttp extends Http implements AccountRepository { * A transaction is said to be aggregate bonded with respect to an account if there are missing signatures. * @param address - * Address can be created rawAddress or publicKey * @param queryParams - (Optional) Query params + * @param transactionFilter - (Optional) Transaction filter * @returns Observable */ - public getAccountPartialTransactions(address: Address, queryParams?: QueryParams): Observable { + public getAccountPartialTransactions(address: Address, + queryParams?: QueryParams, + transactionFilter?: TransactionFilter): Observable { return observableFrom( this.accountRoutesApi.getAccountPartialTransactions(address.plain(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, this.queryParams(queryParams).ordering), - this.queryParams(queryParams).type).pipe( + this.transactionFilter(transactionFilter).type).pipe( map(({body}) => body.map((transactionDTO) => { return CreateTransactionFromDTO(transactionDTO) as AggregateTransaction; })), diff --git a/src/infrastructure/AccountRepository.ts b/src/infrastructure/AccountRepository.ts index 1f9b564217..bf6c77ae3f 100644 --- a/src/infrastructure/AccountRepository.ts +++ b/src/infrastructure/AccountRepository.ts @@ -20,6 +20,7 @@ import {Address} from '../model/account/Address'; import {AggregateTransaction} from '../model/transaction/AggregateTransaction'; import {Transaction} from '../model/transaction/Transaction'; import { QueryParams } from './QueryParams'; +import { TransactionFilter } from './TransactionFilter'; /** * Account interface repository. @@ -46,27 +47,32 @@ export interface AccountRepository { * Gets an array of confirmed transactions for which an account is signer or receiver. * @param address - * Address can be created rawAddress or publicKey * @param queryParams - (Optional) Query params + * @param transactionFilter - (Optional) Transaction fitler * @returns Observable */ - getAccountTransactions(address: Address, queryParams?: QueryParams): Observable; + getAccountTransactions(address: Address, queryParams?: QueryParams, transactionFilter?: TransactionFilter): Observable; /** * Gets an array of transactions for which an account is the recipient of a transaction. * A transaction is said to be incoming with respect to an account if the account is the recipient of a transaction. * @param address - * Address can be created rawAddress or publicKey * @param queryParams - (Optional) Query params + * @param transactionFilter - (Optional) Transaction fitler * @returns Observable */ - getAccountIncomingTransactions(address: Address, queryParams?: QueryParams): Observable; + getAccountIncomingTransactions( + address: Address, queryParams?: QueryParams, transactionFilter?: TransactionFilter): Observable; /** * Gets an array of transactions for which an account is the sender a transaction. * A transaction is said to be outgoing with respect to an account if the account is the sender of a transaction. * @param address - * Address can be created rawAddress or publicKey * @param queryParams - (Optional) Query params + * @param transactionFilter - (Optional) Transaction fitler * @returns Observable */ - getAccountOutgoingTransactions(address: Address, queryParams?: QueryParams): Observable; + getAccountOutgoingTransactions( + address: Address, queryParams?: QueryParams, transactionFilter?: TransactionFilter): Observable; /** * Gets the array of transactions for which an account is the sender or receiver and which have not yet been included in a block. @@ -74,16 +80,20 @@ export interface AccountRepository { * Unconfirmed transactions are not guaranteed to be included in any block. * @param address - * Address can be created rawAddress or publicKey * @param queryParams - (Optional) Query params + * @param transactionFilter - (Optional) Transaction fitler * @returns Observable */ - getAccountUnconfirmedTransactions(address: Address, queryParams?: QueryParams): Observable; + getAccountUnconfirmedTransactions( + address: Address, queryParams?: QueryParams, transactionFilter?: TransactionFilter): Observable; /** * Gets an array of transactions for which an account is the sender or has sign the transaction. * A transaction is said to be aggregate bonded with respect to an account if there are missing signatures. * @param address - * Address can be created rawAddress or publicKey * @param queryParams - (Optional) Query params + * @param transactionFilter - (Optional) Transaction fitler * @returns Observable */ - getAccountPartialTransactions(address: Address, queryParams?: QueryParams): Observable; + getAccountPartialTransactions( + address: Address, queryParams?: QueryParams, transactionFilter?: TransactionFilter): Observable; } diff --git a/src/infrastructure/Http.ts b/src/infrastructure/Http.ts index 1401600e0f..ea1bc767bb 100644 --- a/src/infrastructure/Http.ts +++ b/src/infrastructure/Http.ts @@ -20,6 +20,7 @@ import { from as observableFrom, Observable, of as observableOf, throwError } fr import { catchError, map, shareReplay } from 'rxjs/operators'; import { NetworkType } from '../model/blockchain/NetworkType'; import { QueryParams } from './QueryParams'; +import { TransactionFilter } from './TransactionFilter'; /** * Http extended by all http services @@ -56,12 +57,9 @@ export abstract class Http { }; } - transactionSearchCriteria(queryParams?: QueryParams): any { + transactionFilter(filter?: TransactionFilter): any { return { - pageSize: queryParams ? queryParams.pageSize : undefined, - id: queryParams ? queryParams.id : undefined, - ordering: queryParams ? queryParams.order : undefined, - type: queryParams ? queryParams.convertCSV(queryParams.type) : undefined, + type: filter ? filter.convertCSV(filter.type) : undefined, }; } diff --git a/src/infrastructure/QueryParams.ts b/src/infrastructure/QueryParams.ts index c13667e688..e271e04ee3 100644 --- a/src/infrastructure/QueryParams.ts +++ b/src/infrastructure/QueryParams.ts @@ -1,5 +1,3 @@ -import { TransactionType } from '../model/transaction/TransactionType'; - /* * Copyright 2018 NEM * @@ -16,6 +14,8 @@ import { TransactionType } from '../model/transaction/TransactionType'; * limitations under the License. */ +import { TransactionType } from '../model/transaction/TransactionType'; + /** * @since 0.11.3 */ @@ -45,10 +45,6 @@ export class QueryParams { */ public order: Order = Order.DESC; - /** - * Transaction type list - */ - public type?: TransactionType[]; /** * Constructor */ @@ -69,21 +65,4 @@ export class QueryParams { this.order = order; return this; } - - public setType(type?: TransactionType[]): QueryParams { - this.type = type; - return this; - } - - /** - * Return comma seperated list - * @param type Transaction type list - */ - public convertCSV(type?: TransactionType[]): string | undefined { - if (!type || type.length === 0) { - return undefined; - } else { - return type.map((t) => t.valueOf().toString()).join(','); - } - } } diff --git a/src/infrastructure/TransactionFilter.ts b/src/infrastructure/TransactionFilter.ts new file mode 100644 index 0000000000..fcf54d197e --- /dev/null +++ b/src/infrastructure/TransactionFilter.ts @@ -0,0 +1,50 @@ +/* + * 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 { TransactionType } from '../model/transaction/TransactionType'; +import { QueryParams } from './QueryParams'; + +/** + * The Transaction filter class + */ +export class TransactionFilter { + /** + * Transaction type list + */ + public type?: TransactionType[]; + /** + * Constructor + */ + constructor() { + } + + public setType(type?: TransactionType[]): TransactionFilter { + this.type = type; + return this; + } + + /** + * Return comma seperated list + * @param type Transaction type list + */ + public convertCSV(type?: TransactionType[]): string | undefined { + if (!type || type.length === 0) { + return undefined; + } else { + return type.map((t) => t.valueOf().toString()).join(','); + } + } +} diff --git a/src/infrastructure/infrastructure.ts b/src/infrastructure/infrastructure.ts index 3a297391a7..46ab3b8f29 100644 --- a/src/infrastructure/infrastructure.ts +++ b/src/infrastructure/infrastructure.ts @@ -47,3 +47,4 @@ export * from './RepositoryFactory'; export * from './RestrictionAccountRepository'; export * from './RestrictionMosaicRepository'; export * from './TransactionRepository'; +export * from './TransactionFilter'; diff --git a/test/infrastructure/QueryParams.spec.ts b/test/infrastructure/TransactionFilter.spec.ts similarity index 70% rename from test/infrastructure/QueryParams.spec.ts rename to test/infrastructure/TransactionFilter.spec.ts index 7b61fa9279..4e90894047 100644 --- a/test/infrastructure/QueryParams.spec.ts +++ b/test/infrastructure/TransactionFilter.spec.ts @@ -15,19 +15,14 @@ */ import { expect } from 'chai'; -import { Order, QueryParams } from '../../src/infrastructure/QueryParams'; +import { TransactionFilter } from '../../src/infrastructure/TransactionFilter'; import { TransactionType } from '../../src/model/transaction/TransactionType'; -describe('QueryParams', () => { +describe('TransactionFilter', () => { it('should return correct query param', () => { - const param = new QueryParams().setId('0') - .setOrder(Order.ASC) - .setPageSize(10) + const param = new TransactionFilter() .setType([TransactionType.TRANSFER, TransactionType.ACCOUNT_LINK]); - expect(param.id).to.be.equal('0'); - expect(param.order.valueOf()).to.be.equal(Order.ASC.valueOf()); - expect(param.pageSize).to.be.equal(10); expect(param.convertCSV(param.type)).to.be.equal('16724,16716'); }); }); diff --git a/test/service/BlockService.spec.ts b/test/service/BlockService.spec.ts index 0fe6aa0068..6145946807 100644 --- a/test/service/BlockService.spec.ts +++ b/test/service/BlockService.spec.ts @@ -28,6 +28,7 @@ import { NetworkType } from '../../src/model/blockchain/NetworkType'; import { UInt64 } from '../../src/model/UInt64'; import { BlockService } from '../../src/service/BlockService'; import { TestingAccount } from '../conf/conf.spec'; +import { PositionEnum } from 'nem2-sdk-openapi-typescript-node-client'; describe('BlockService', () => { @@ -100,11 +101,11 @@ describe('BlockService', () => { function mockMerklePath(): MerkleProofInfo { return new MerkleProofInfo( [ - new MerklePathItem(1, 'CDE45D740536E5361F392025A44B26546A138958E69CD6F18D22908F8F11ECF2'), - new MerklePathItem(2, '4EF55DAB8FEF9711B23DA71D2ACC58EFFF3969C3D572E06ACB898F99BED4827A'), - new MerklePathItem(1, '1BB95470065ED69D184948A0175EDC2EAB9E86A0CEB47B648A58A02A5445AF66'), - new MerklePathItem(2, 'D96B03809B8B198EFA5824191A979F7B85C0E9B7A6623DAFF38D4B2927EFDFB5'), - new MerklePathItem(2, '9981EBDBCA8E36BA4D4D4A450072026AC8C85BA6497666219E0E049BE3362E51'), + new MerklePathItem(PositionEnum.Left, 'CDE45D740536E5361F392025A44B26546A138958E69CD6F18D22908F8F11ECF2'), + new MerklePathItem(PositionEnum.Right, '4EF55DAB8FEF9711B23DA71D2ACC58EFFF3969C3D572E06ACB898F99BED4827A'), + new MerklePathItem(PositionEnum.Left, '1BB95470065ED69D184948A0175EDC2EAB9E86A0CEB47B648A58A02A5445AF66'), + new MerklePathItem(PositionEnum.Right, 'D96B03809B8B198EFA5824191A979F7B85C0E9B7A6623DAFF38D4B2927EFDFB5'), + new MerklePathItem(PositionEnum.Right, '9981EBDBCA8E36BA4D4D4A450072026AC8C85BA6497666219E0E049BE3362E51'), ], ); }