From aad1d5e33408cc4a12f56ba2e541c6ea85af6ac8 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 22 Jun 2020 17:46:03 +0100 Subject: [PATCH 1/2] Fixed #608 - Added enumMapper - Added wrapper enums for Order, BlockOrderBy and MeklePosition --- src/core/utils/DtoMapping.ts | 8 ++ src/infrastructure/BlockHttp.ts | 10 ++- src/infrastructure/Listener.ts | 2 +- src/infrastructure/MosaicHttp.ts | 3 +- src/infrastructure/QueryParams.ts | 2 +- src/infrastructure/ReceiptHttp.ts | 15 ++-- src/infrastructure/TransactionHttp.ts | 7 +- src/infrastructure/infrastructure.ts | 2 + .../searchCriteria/BlockOrderBy.ts | 19 ++++ .../searchCriteria/BlockSearchCriteria.ts | 4 +- src/infrastructure/searchCriteria/Order.ts | 22 +++++ .../searchCriteria/SearchCriteria.ts | 2 +- src/model/blockchain/MerklePathItem.ts | 6 +- src/model/blockchain/MerklePosition.ts | 19 ++++ src/model/model.ts | 1 + src/service/BlockService.ts | 4 +- test/core/utils/EnumMapping.spec.ts | 90 +++++++++++++++++++ test/infrastructure/AccountHttp.spec.ts | 2 +- test/infrastructure/BlockHttp.spec.ts | 3 +- test/infrastructure/MetadataHttp.spec.ts | 2 +- test/infrastructure/QueryParams.spec.ts | 2 +- test/infrastructure/SearchCriteria.spec.ts | 2 +- .../TransactionSearchCriteria.spec.ts | 2 +- test/service/BlockService.spec.ts | 12 +-- 24 files changed, 204 insertions(+), 37 deletions(-) create mode 100644 src/infrastructure/searchCriteria/BlockOrderBy.ts create mode 100644 src/infrastructure/searchCriteria/Order.ts create mode 100644 src/model/blockchain/MerklePosition.ts create mode 100644 test/core/utils/EnumMapping.spec.ts diff --git a/src/core/utils/DtoMapping.ts b/src/core/utils/DtoMapping.ts index cf133408cd..9bf8aae4b2 100644 --- a/src/core/utils/DtoMapping.ts +++ b/src/core/utils/DtoMapping.ts @@ -70,4 +70,12 @@ export class DtoMapping { public static assign(object: T, attributes: any): T { return Object.assign({ __proto__: Object.getPrototypeOf(object) }, object, attributes); } + + /** + * Map one enum type to another by value + * @param value enum value to be mapped + */ + public static mapEnum(value: E1 | undefined): E2 { + return (value as unknown) as E2; + } } diff --git a/src/infrastructure/BlockHttp.ts b/src/infrastructure/BlockHttp.ts index a8c2820c8f..27c0b60cdb 100644 --- a/src/infrastructure/BlockHttp.ts +++ b/src/infrastructure/BlockHttp.ts @@ -26,6 +26,7 @@ import { Http } from './Http'; import { BlockSearchCriteria } from './searchCriteria/BlockSearchCriteria'; import { Page } from './Page'; import { Address } from '../model/account/Address'; +import { DtoMapping } from '../core/utils/DtoMapping'; /** * Blockchain http repository. @@ -71,8 +72,8 @@ export class BlockHttp extends Http implements BlockRepository { criteria.pageSize, criteria.pageNumber, criteria.offset, - criteria.order, - criteria.orderBy, + DtoMapping.mapEnum(criteria.order), + DtoMapping.mapEnum(criteria.orderBy), ), (body) => super.toPage(body.pagination, body.data, this.toBlockInfo), ); @@ -129,7 +130,10 @@ export class BlockHttp extends Http implements BlockRepository { public getMerkleTransaction(height: UInt64, hash: string): Observable { return this.call( this.blockRoutesApi.getMerkleTransaction(height.toString(), hash), - (body) => new MerkleProofInfo(body.merklePath!.map((payload) => new MerklePathItem(payload.position, payload.hash))), + (body) => + new MerkleProofInfo( + body.merklePath!.map((payload) => new MerklePathItem(DtoMapping.mapEnum(payload.position), payload.hash)), + ), ); } } diff --git a/src/infrastructure/Listener.ts b/src/infrastructure/Listener.ts index bb34121903..0d147fcd4a 100644 --- a/src/infrastructure/Listener.ts +++ b/src/infrastructure/Listener.ts @@ -27,7 +27,7 @@ import { TransactionStatusError } from '../model/transaction/TransactionStatusEr import { IListener } from './IListener'; import { NamespaceRepository } from './NamespaceRepository'; import { CreateTransactionFromDTO } from './transaction/CreateTransactionFromDTO'; -import { BlockInfoDTO } from 'symbol-openapi-typescript-node-client/dist/model/blockInfoDTO'; +import { BlockInfoDTO } from 'symbol-openapi-typescript-node-client'; import { NewBlock } from '../model/blockchain/NewBlock'; import { PublicAccount } from '../model/account/PublicAccount'; import { UInt64 } from '../model/UInt64'; diff --git a/src/infrastructure/MosaicHttp.ts b/src/infrastructure/MosaicHttp.ts index c973bd6c3e..00af619adb 100644 --- a/src/infrastructure/MosaicHttp.ts +++ b/src/infrastructure/MosaicHttp.ts @@ -27,6 +27,7 @@ import { MosaicSearchCriteria } from './searchCriteria/MosaicSearchCriteria'; import { Page } from './Page'; import { MosaicRoutesApi, MosaicIds, MosaicInfoDTO } from 'symbol-openapi-typescript-node-client'; import { Address } from '../model/account/Address'; +import { DtoMapping } from '../core/utils/DtoMapping'; /** * Mosaic http repository. @@ -92,7 +93,7 @@ export class MosaicHttp extends Http implements MosaicRepository { criteria.pageSize, criteria.pageNumber, criteria.offset, - criteria.order, + DtoMapping.mapEnum(criteria.order), ), (body) => super.toPage(body.pagination, body.data, this.toMosaicInfo, networkType), ), diff --git a/src/infrastructure/QueryParams.ts b/src/infrastructure/QueryParams.ts index b4ad882b91..8aae8af75d 100644 --- a/src/infrastructure/QueryParams.ts +++ b/src/infrastructure/QueryParams.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Order } from 'symbol-openapi-typescript-node-client/dist/model/order'; +import { Order } from './searchCriteria/Order'; /** * The query params structure describes pagination params for requests. diff --git a/src/infrastructure/ReceiptHttp.ts b/src/infrastructure/ReceiptHttp.ts index 7ad45680b3..2580e38ae3 100644 --- a/src/infrastructure/ReceiptHttp.ts +++ b/src/infrastructure/ReceiptHttp.ts @@ -25,6 +25,7 @@ import { UInt64 } from '../model/UInt64'; import { Http } from './Http'; import { CreateStatementFromDTO } from './receipt/CreateReceiptFromDTO'; import { ReceiptRepository } from './ReceiptRepository'; +import { DtoMapping } from '../core/utils/DtoMapping'; /** * Receipt http repository. @@ -38,12 +39,6 @@ export class ReceiptHttp extends Http implements ReceiptRepository { */ private readonly receiptRoutesApi: ReceiptRoutesApi; - /** - * @internal - * network type for the mappings. - */ - private readonly networkTypeObservable: Observable; - /** * Constructor * @param url @@ -52,7 +47,6 @@ export class ReceiptHttp extends Http implements ReceiptRepository { constructor(url: string, networkType?: NetworkType | Observable) { super(url); this.receiptRoutesApi = new ReceiptRoutesApi(url); - this.networkTypeObservable = this.createNetworkTypeObservable(networkType); this.receiptRoutesApi.useQuerystring = true; } @@ -68,7 +62,12 @@ export class ReceiptHttp extends Http implements ReceiptRepository { */ public getMerkleReceipts(height: UInt64, hash: string): Observable { return observableFrom(this.receiptRoutesApi.getMerkleReceipts(height.toString(), hash)).pipe( - map(({ body }) => new MerkleProofInfo(body.merklePath!.map((payload) => new MerklePathItem(payload.position, payload.hash)))), + map( + ({ body }) => + new MerkleProofInfo( + body.merklePath!.map((payload) => new MerklePathItem(DtoMapping.mapEnum(payload.position), payload.hash)), + ), + ), catchError((error) => throwError(this.errorHandling(error))), ); } diff --git a/src/infrastructure/TransactionHttp.ts b/src/infrastructure/TransactionHttp.ts index 4ecc937cf3..fe294e9285 100644 --- a/src/infrastructure/TransactionHttp.ts +++ b/src/infrastructure/TransactionHttp.ts @@ -38,6 +38,7 @@ import { TransactionSearchCriteria } from './searchCriteria/TransactionSearchCri import { Page } from './Page'; import { TransactionGroup } from './TransactionGroup'; import http = require('http'); +import { DtoMapping } from '../core/utils/DtoMapping'; /** * Transaction http repository. @@ -237,7 +238,7 @@ export class TransactionHttp extends Http implements TransactionRepository { criteria.pageSize, criteria.pageNumber, criteria.offset, - criteria.order, + DtoMapping.mapEnum(criteria.order), ); case TransactionGroup.Unconfirmed: return this.transactionRoutesApi.searchUnconfirmedTransactions( @@ -250,7 +251,7 @@ export class TransactionHttp extends Http implements TransactionRepository { criteria.pageSize, criteria.pageNumber, criteria.offset, - criteria.order, + DtoMapping.mapEnum(criteria.order), ); case TransactionGroup.Partial: return this.transactionRoutesApi.searchPartialTransactions( @@ -263,7 +264,7 @@ export class TransactionHttp extends Http implements TransactionRepository { criteria.pageSize, criteria.pageNumber, criteria.offset, - criteria.order, + DtoMapping.mapEnum(criteria.order), ); } } diff --git a/src/infrastructure/infrastructure.ts b/src/infrastructure/infrastructure.ts index 917c7e5fc2..319c70002a 100644 --- a/src/infrastructure/infrastructure.ts +++ b/src/infrastructure/infrastructure.ts @@ -59,3 +59,5 @@ export * from './paginationStreamer/TransactionPaginationStreamer'; export * from './TransactionStatusHttp'; export * from './TransactionStatusRepository'; export * from './TransactionGroup'; +export * from './searchCriteria/BlockOrderBy'; +export * from './searchCriteria/Order'; diff --git a/src/infrastructure/searchCriteria/BlockOrderBy.ts b/src/infrastructure/searchCriteria/BlockOrderBy.ts new file mode 100644 index 0000000000..3ec5f5c8ea --- /dev/null +++ b/src/infrastructure/searchCriteria/BlockOrderBy.ts @@ -0,0 +1,19 @@ +/* + * Copyright 2020 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export enum BlockOrderBy { + Id = 'id', + Height = 'height', +} diff --git a/src/infrastructure/searchCriteria/BlockSearchCriteria.ts b/src/infrastructure/searchCriteria/BlockSearchCriteria.ts index 4015d11a31..f04fec1e71 100644 --- a/src/infrastructure/searchCriteria/BlockSearchCriteria.ts +++ b/src/infrastructure/searchCriteria/BlockSearchCriteria.ts @@ -15,7 +15,7 @@ */ import { SearchCriteria } from './SearchCriteria'; -import { BlockOrderByEnum } from 'symbol-openapi-typescript-node-client/dist/model/blockOrderByEnum'; +import { BlockOrderBy } from './BlockOrderBy'; /** * Defines the params used to search blocks. With this criteria, you can sort and filter @@ -35,5 +35,5 @@ export interface BlockSearchCriteria extends SearchCriteria { /** * Order by block id or height. (optional) */ - orderBy?: BlockOrderByEnum; + orderBy?: BlockOrderBy; } diff --git a/src/infrastructure/searchCriteria/Order.ts b/src/infrastructure/searchCriteria/Order.ts new file mode 100644 index 0000000000..7747417321 --- /dev/null +++ b/src/infrastructure/searchCriteria/Order.ts @@ -0,0 +1,22 @@ +/* + * 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. + */ +/** + * Indicates how to sort the results: * ``asc`` - ascending * ``desc`` - descending + */ +export enum Order { + Asc = 'asc', + Desc = 'desc', +} diff --git a/src/infrastructure/searchCriteria/SearchCriteria.ts b/src/infrastructure/searchCriteria/SearchCriteria.ts index f79c5d7b41..9496e0bc7a 100644 --- a/src/infrastructure/searchCriteria/SearchCriteria.ts +++ b/src/infrastructure/searchCriteria/SearchCriteria.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Order } from 'symbol-openapi-typescript-node-client/dist/model/order'; +import { Order } from './Order'; export interface SearchCriteria { /** diff --git a/src/model/blockchain/MerklePathItem.ts b/src/model/blockchain/MerklePathItem.ts index 97380293a7..215bdb0c10 100644 --- a/src/model/blockchain/MerklePathItem.ts +++ b/src/model/blockchain/MerklePathItem.ts @@ -1,5 +1,3 @@ -import { PositionEnum } from 'symbol-openapi-typescript-node-client/dist/model/positionEnum'; - /* * Copyright 2019 NEM * @@ -16,6 +14,8 @@ import { PositionEnum } from 'symbol-openapi-typescript-node-client/dist/model/p * limitations under the License. */ +import { MerklePosition } from './MerklePosition'; + /** * The block merkle path item */ @@ -28,7 +28,7 @@ export class MerklePathItem { /** * The position */ - public readonly position?: PositionEnum, + public readonly position?: MerklePosition, /** * The hash */ diff --git a/src/model/blockchain/MerklePosition.ts b/src/model/blockchain/MerklePosition.ts new file mode 100644 index 0000000000..c9a5a9e0f4 --- /dev/null +++ b/src/model/blockchain/MerklePosition.ts @@ -0,0 +1,19 @@ +/* + * Copyright 2020 NEM + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export enum MerklePosition { + Left = 'left', + Right = 'right', +} diff --git a/src/model/model.ts b/src/model/model.ts index c48d9e9094..b3cb800d28 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -39,6 +39,7 @@ export * from './blockchain/BlockInfo'; export * from './blockchain/MerklePathItem'; export * from './blockchain/MerkleProofInfo'; export * from './blockchain/NewBlock'; +export * from './blockchain/MerklePosition'; // Diagnostic export * from './node/ServerInfo'; diff --git a/src/service/BlockService.ts b/src/service/BlockService.ts index 269271259e..6b54ffa978 100644 --- a/src/service/BlockService.ts +++ b/src/service/BlockService.ts @@ -17,13 +17,13 @@ import { sha3_256 } from 'js-sha3'; import { combineLatest, Observable, of } from 'rxjs'; import { catchError, map } from 'rxjs/operators'; -import { PositionEnum } from 'symbol-openapi-typescript-node-client/dist/model/positionEnum'; 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 { IBlockService } from './interfaces/IBlockService'; +import { MerklePosition } from '../model/blockchain/MerklePosition'; /** * Block Service @@ -82,7 +82,7 @@ export class BlockService implements IBlockService { const rootToCompare = merklePathItem.reduce((proofHash, pathItem) => { const hasher = sha3_256.create(); // Left - if (pathItem.position !== undefined && pathItem.position === PositionEnum.Left) { + if (pathItem.position !== undefined && pathItem.position === MerklePosition.Left) { return hasher.update(Buffer.from(pathItem.hash + proofHash, 'hex')).hex(); } else { // Right diff --git a/test/core/utils/EnumMapping.spec.ts b/test/core/utils/EnumMapping.spec.ts new file mode 100644 index 0000000000..8a9e8fab42 --- /dev/null +++ b/test/core/utils/EnumMapping.spec.ts @@ -0,0 +1,90 @@ +/* + * 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, PositionEnum, BlockOrderByEnum } from 'symbol-openapi-typescript-node-client'; +import { Order as OrderModel } from '../../../src/infrastructure/searchCriteria/Order'; +import { DtoMapping } from '../../../src/core/utils/DtoMapping'; +import { BlockOrderBy } from '../../../src/infrastructure/searchCriteria/BlockOrderBy'; +import { MerklePosition } from '../../../src/model/blockchain/MerklePosition'; + +describe('Order', () => { + it('should be able to map Order', () => { + const value1: Order = Order.Asc; + const value2: OrderModel = DtoMapping.mapEnum(value1); + expect(value2).eq(OrderModel.Asc); + }); + it('should be able to map Order when undefined', () => { + const value1: Order | undefined = undefined; + const value2: OrderModel = DtoMapping.mapEnum(value1); + expect(value2).eq(undefined); + }); + it('should be able to map OrderModel', () => { + const value1: OrderModel = OrderModel.Asc; + const value2: Order = DtoMapping.mapEnum(value1); + expect(value2).eq(Order.Asc); + }); + it('should be able to map OrderModel when undefined', () => { + const value1: OrderModel | undefined = undefined; + const value2: Order = DtoMapping.mapEnum(value1); + expect(value2).eq(undefined); + }); +}); + +describe('BlockOrderBy', () => { + it('should be able to map BlockOrderByEnum', () => { + const value1: BlockOrderByEnum = BlockOrderByEnum.Id; + const value2: BlockOrderBy = DtoMapping.mapEnum(value1); + expect(value2).eq(BlockOrderBy.Id); + }); + it('should be able to map BlockOrderBy when undefined', () => { + const value1: BlockOrderByEnum | undefined = undefined; + const value2: BlockOrderBy = DtoMapping.mapEnum(value1); + expect(value2).eq(undefined); + }); + it('should be able to map BlockOrderBy', () => { + const value1: BlockOrderBy = BlockOrderBy.Height; + const value2: Order = DtoMapping.mapEnum(value1); + expect(value2).eq(BlockOrderByEnum.Height); + }); + it('should be able to map BlockOrderBy when undefined', () => { + const value1: BlockOrderBy | undefined = undefined; + const value2: BlockOrderByEnum = DtoMapping.mapEnum(value1); + expect(value2).eq(undefined); + }); +}); + +describe('MerklePosition', () => { + it('should be able to map MerklePosition', () => { + const value1: PositionEnum = PositionEnum.Left; + const value2: MerklePosition = DtoMapping.mapEnum(value1); + expect(value2).eq(MerklePosition.Left); + }); + it('should be able to map MerklePosition when undefined', () => { + const value1: BlockOrderByEnum | undefined = undefined; + const value2: MerklePosition = DtoMapping.mapEnum(value1); + expect(value2).eq(undefined); + }); + it('should be able to map MerklePosition', () => { + const value1: MerklePosition = MerklePosition.Right; + const value2: Order = DtoMapping.mapEnum(value1); + expect(value2).eq(PositionEnum.Right); + }); + it('should be able to map MerklePosition when undefined', () => { + const value1: MerklePosition | undefined = undefined; + const value2: PositionEnum = DtoMapping.mapEnum(value1); + expect(value2).eq(undefined); + }); +}); diff --git a/test/infrastructure/AccountHttp.spec.ts b/test/infrastructure/AccountHttp.spec.ts index e68155a347..52c0d0ae9a 100644 --- a/test/infrastructure/AccountHttp.spec.ts +++ b/test/infrastructure/AccountHttp.spec.ts @@ -31,7 +31,7 @@ import { AccountRepository } from '../../src/infrastructure/AccountRepository'; import { AccountInfo } from '../../src/model/account/AccountInfo'; import { AccountType } from '../../src/model/account/AccountType'; import { Address } from '../../src/model/account/Address'; -import { AccountKeyDTO } from 'symbol-openapi-typescript-node-client/dist/model/accountKeyDTO'; +import { AccountKeyDTO } from 'symbol-openapi-typescript-node-client'; describe('AccountHttp', () => { const address = Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'); diff --git a/test/infrastructure/BlockHttp.spec.ts b/test/infrastructure/BlockHttp.spec.ts index cb30d4f340..77bd4fed07 100644 --- a/test/infrastructure/BlockHttp.spec.ts +++ b/test/infrastructure/BlockHttp.spec.ts @@ -36,6 +36,7 @@ import { MerklePathItem } from '../../src/model/blockchain/MerklePathItem'; import { UInt64 } from '../../src/model/UInt64'; import { Address } from '../../src/model/account/Address'; import { NetworkType } from '../../src/model/network/NetworkType'; +import { MerklePosition } from '../../src/model/blockchain/MerklePosition'; describe('BlockHttp', () => { const blockDTO = new BlockDTO(); @@ -149,6 +150,6 @@ describe('BlockHttp', () => { ); const merkleProofInfo = await blockRepository.getMerkleTransaction(UInt64.fromUint(2), 'abc').toPromise(); expect(merkleProofInfo).to.be.not.null; - expect(merkleProofInfo.merklePath).to.deep.equals([new MerklePathItem(PositionEnum.Left, 'bbb')]); + expect(merkleProofInfo.merklePath).to.deep.equals([new MerklePathItem(MerklePosition.Left, 'bbb')]); }); }); diff --git a/test/infrastructure/MetadataHttp.spec.ts b/test/infrastructure/MetadataHttp.spec.ts index 96f7544724..266aecb203 100644 --- a/test/infrastructure/MetadataHttp.spec.ts +++ b/test/infrastructure/MetadataHttp.spec.ts @@ -32,7 +32,7 @@ import { Metadata } from '../../src/model/metadata/Metadata'; import { MetadataType } from '../../src/model/metadata/MetadataType'; import { MosaicId } from '../../src/model/mosaic/MosaicId'; import { NamespaceId } from '../../src/model/namespace/NamespaceId'; -import { Order } from 'symbol-openapi-typescript-node-client/dist/model/order'; +import { Order } from 'symbol-openapi-typescript-node-client'; import { MetadataTransactionService } from '../../src/service/MetadataTransactionService'; import { Deadline } from '../../src/model/transaction/Deadline'; import { NetworkType } from '../../src/model/network/NetworkType'; diff --git a/test/infrastructure/QueryParams.spec.ts b/test/infrastructure/QueryParams.spec.ts index 6f3bec4816..664c0e6c2f 100644 --- a/test/infrastructure/QueryParams.spec.ts +++ b/test/infrastructure/QueryParams.spec.ts @@ -16,7 +16,7 @@ import { QueryParams } from '../../src/infrastructure/QueryParams'; import { expect } from 'chai'; -import { Order } from 'symbol-openapi-typescript-node-client/dist/model/order'; +import { Order } from '../../src/infrastructure/searchCriteria/Order'; describe('QueryParams', () => { it('should create QueryParams', () => { diff --git a/test/infrastructure/SearchCriteria.spec.ts b/test/infrastructure/SearchCriteria.spec.ts index 282ed4078a..40369ba9ae 100644 --- a/test/infrastructure/SearchCriteria.spec.ts +++ b/test/infrastructure/SearchCriteria.spec.ts @@ -16,7 +16,7 @@ import { expect } from 'chai'; import { SearchCriteria } from '../../src/infrastructure/searchCriteria/SearchCriteria'; -import { Order } from 'symbol-openapi-typescript-node-client'; +import { Order } from '../../src/infrastructure/searchCriteria/Order'; describe('SearchCriteria', () => { it('should create SearchCriteria', () => { diff --git a/test/infrastructure/TransactionSearchCriteria.spec.ts b/test/infrastructure/TransactionSearchCriteria.spec.ts index 791fb585f5..1b693caa08 100644 --- a/test/infrastructure/TransactionSearchCriteria.spec.ts +++ b/test/infrastructure/TransactionSearchCriteria.spec.ts @@ -15,7 +15,6 @@ */ import { expect } from 'chai'; -import { Order } from 'symbol-openapi-typescript-node-client'; import { TransactionSearchCriteria } from '../../src/infrastructure/searchCriteria/TransactionSearchCriteria'; import { TestingAccount } from '../conf/conf.spec'; import { deepEqual } from 'assert'; @@ -23,6 +22,7 @@ import { TransactionType } from '../../src/model/transaction/TransactionType'; import { UInt64 } from '../../src/model/UInt64'; import { Address } from '../../src/model/account/Address'; import { TransactionGroup } from '../../src/infrastructure/TransactionGroup'; +import { Order } from '../../src/infrastructure/searchCriteria/Order'; describe('TransactionSearchCriteria', () => { const account = TestingAccount; diff --git a/test/service/BlockService.spec.ts b/test/service/BlockService.spec.ts index 5ea43d78e4..16ef1384ac 100644 --- a/test/service/BlockService.spec.ts +++ b/test/service/BlockService.spec.ts @@ -16,7 +16,6 @@ import { expect } from 'chai'; import { of as observableOf } from 'rxjs'; -import { PositionEnum } from 'symbol-openapi-typescript-node-client'; import { deepEqual, instance, mock, when } from 'ts-mockito'; import { BlockRepository } from '../../src/infrastructure/BlockRepository'; import { ReceiptRepository } from '../../src/infrastructure/ReceiptRepository'; @@ -29,6 +28,7 @@ import { NetworkType } from '../../src/model/network/NetworkType'; import { UInt64 } from '../../src/model/UInt64'; import { BlockService } from '../../src/service/BlockService'; import { TestingAccount } from '../conf/conf.spec'; +import { MerklePosition } from '../../src/model/blockchain/MerklePosition'; describe('BlockService', () => { const mockBlockHash = 'D4EC16FCFE696EFDBF1820F68245C88135ACF4C6F888599C8E18BC09B9F08C7B'; @@ -98,11 +98,11 @@ describe('BlockService', () => { emtpy ? [] : [ - 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'), + new MerklePathItem(MerklePosition.Left, 'CDE45D740536E5361F392025A44B26546A138958E69CD6F18D22908F8F11ECF2'), + new MerklePathItem(MerklePosition.Right, '4EF55DAB8FEF9711B23DA71D2ACC58EFFF3969C3D572E06ACB898F99BED4827A'), + new MerklePathItem(MerklePosition.Left, '1BB95470065ED69D184948A0175EDC2EAB9E86A0CEB47B648A58A02A5445AF66'), + new MerklePathItem(MerklePosition.Right, 'D96B03809B8B198EFA5824191A979F7B85C0E9B7A6623DAFF38D4B2927EFDFB5'), + new MerklePathItem(MerklePosition.Right, '9981EBDBCA8E36BA4D4D4A450072026AC8C85BA6497666219E0E049BE3362E51'), ], ); } From 5fbcf59220441bf5914653fb1a78ddfc7924192c Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 22 Jun 2020 18:10:49 +0100 Subject: [PATCH 2/2] Added sanity check --- test/core/utils/EnumMapping.spec.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/core/utils/EnumMapping.spec.ts b/test/core/utils/EnumMapping.spec.ts index 8a9e8fab42..c882b4e94d 100644 --- a/test/core/utils/EnumMapping.spec.ts +++ b/test/core/utils/EnumMapping.spec.ts @@ -41,6 +41,12 @@ describe('Order', () => { const value2: Order = DtoMapping.mapEnum(value1); expect(value2).eq(undefined); }); + it('openAPI sanity check', () => { + for (const item in Order) { + const value: OrderModel = DtoMapping.mapEnum(item); + expect(value).not.to.be.undefined; + } + }); }); describe('BlockOrderBy', () => { @@ -64,6 +70,12 @@ describe('BlockOrderBy', () => { const value2: BlockOrderByEnum = DtoMapping.mapEnum(value1); expect(value2).eq(undefined); }); + it('openAPI sanity check', () => { + for (const item in BlockOrderByEnum) { + const value: BlockOrderBy = DtoMapping.mapEnum(item); + expect(value).not.to.be.undefined; + } + }); }); describe('MerklePosition', () => { @@ -87,4 +99,10 @@ describe('MerklePosition', () => { const value2: PositionEnum = DtoMapping.mapEnum(value1); expect(value2).eq(undefined); }); + it('openAPI sanity check', () => { + for (const item in PositionEnum) { + const value: MerklePosition = DtoMapping.mapEnum(item); + expect(value).not.to.be.undefined; + } + }); });