diff --git a/e2e/infrastructure/BlockHttp.spec.ts b/e2e/infrastructure/BlockHttp.spec.ts index f87504ef83..9b721000ba 100644 --- a/e2e/infrastructure/BlockHttp.spec.ts +++ b/e2e/infrastructure/BlockHttp.spec.ts @@ -28,6 +28,7 @@ import { Deadline } from '../../src/model/transaction/Deadline'; import { TransactionInfo } from '../../src/model/transaction/TransactionInfo'; import { TransferTransaction } from '../../src/model/transaction/TransferTransaction'; import { IntegrationTestHelper } from './IntegrationTestHelper'; +import { UInt64 } from '../../src/model/UInt64'; describe('BlockHttp', () => { const helper = new IntegrationTestHelper(); @@ -87,7 +88,7 @@ describe('BlockHttp', () => { describe('getBlockByHeight', () => { it('should return block info given height', (done) => { - blockRepository.getBlockByHeight('1') + blockRepository.getBlockByHeight(UInt64.fromUint(1)) .subscribe((blockInfo) => { blockReceiptHash = blockInfo.blockReceiptsHash; blockTransactionHash = blockInfo.blockTransactionsHash; @@ -105,7 +106,7 @@ describe('BlockHttp', () => { let firstId: string; it('should return block transactions data given height', (done) => { - blockRepository.getBlockTransactions('1') + blockRepository.getBlockTransactions(UInt64.fromUint(1)) .subscribe((transactions) => { nextId = transactions[0].transactionInfo!.id; firstId = transactions[1].transactionInfo!.id; @@ -115,7 +116,7 @@ describe('BlockHttp', () => { }); it('should return block transactions data given height with paginated transactionId', (done) => { - blockRepository.getBlockTransactions('1', new QueryParams(10, nextId)) + blockRepository.getBlockTransactions(UInt64.fromUint(1), new QueryParams(10, nextId)) .subscribe((transactions) => { expect(transactions[0].transactionInfo!.id).to.be.equal(firstId); expect(transactions.length).to.be.greaterThan(0); diff --git a/src/infrastructure/BlockHttp.ts b/src/infrastructure/BlockHttp.ts index 597e9e73ed..c30b03939c 100644 --- a/src/infrastructure/BlockHttp.ts +++ b/src/infrastructure/BlockHttp.ts @@ -54,8 +54,8 @@ export class BlockHttp extends Http implements BlockRepository { * @param height - Block height * @returns Observable */ - public getBlockByHeight(height: string): Observable { - return observableFrom(this.blockRoutesApi.getBlockByHeight(height)).pipe( + public getBlockByHeight(height: UInt64): Observable { + return observableFrom(this.blockRoutesApi.getBlockByHeight(height.toString())).pipe( map(({body}) => this.toBlockInfo(body)), catchError((error) => throwError(this.errorHandling(error))), ); @@ -67,10 +67,10 @@ export class BlockHttp extends Http implements BlockRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - public getBlockTransactions(height: string, + public getBlockTransactions(height: UInt64, queryParams?: QueryParams): Observable { return observableFrom( - this.blockRoutesApi.getBlockTransactions(height, + this.blockRoutesApi.getBlockTransactions(height.toString(), this.queryParams(queryParams).pageSize, this.queryParams(queryParams).id, this.queryParams(queryParams).order)) @@ -87,9 +87,9 @@ export class BlockHttp extends Http implements BlockRepository { * @param limit - Number of blocks returned. * @returns Observable */ - public getBlocksByHeightWithLimit(height: string, limit: number): Observable { + public getBlocksByHeightWithLimit(height: UInt64, limit: number): Observable { return observableFrom( - this.blockRoutesApi.getBlocksByHeightWithLimit(height, limit)).pipe( + this.blockRoutesApi.getBlocksByHeightWithLimit(height.toString(), limit)).pipe( map(({body}) => body.map((blockDTO) => this.toBlockInfo(blockDTO))), catchError((error) => throwError(this.errorHandling(error))), ); @@ -136,9 +136,9 @@ export class BlockHttp extends Http implements BlockRepository { * @param hash The hash of the transaction. * @return Observable */ - public getMerkleTransaction(height: string, hash: string): Observable { + public getMerkleTransaction(height: UInt64, hash: string): Observable { return observableFrom( - this.blockRoutesApi.getMerkleTransaction(height, hash)).pipe( + this.blockRoutesApi.getMerkleTransaction(height.toString(), hash)).pipe( map(({body}) => new MerkleProofInfo( body.merklePath!.map((payload) => new MerklePathItem(payload.position, payload.hash)), )), diff --git a/src/infrastructure/BlockRepository.ts b/src/infrastructure/BlockRepository.ts index cd606ef22a..c4c6d97af1 100644 --- a/src/infrastructure/BlockRepository.ts +++ b/src/infrastructure/BlockRepository.ts @@ -17,8 +17,8 @@ import {Observable} from 'rxjs'; import {BlockInfo} from '../model/blockchain/BlockInfo'; import { MerkleProofInfo } from '../model/blockchain/MerkleProofInfo'; -import { Statement } from '../model/receipt/Statement'; import {Transaction} from '../model/transaction/Transaction'; +import { UInt64 } from '../model/UInt64'; import {QueryParams} from './QueryParams'; /** @@ -33,7 +33,7 @@ export interface BlockRepository { * @param height - Block height * @returns Observable */ - getBlockByHeight(height: string): Observable; + getBlockByHeight(height: UInt64): Observable; /** * Gets array of transactions included in a block for a block height @@ -41,7 +41,7 @@ export interface BlockRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - getBlockTransactions(height: string, + getBlockTransactions(height: UInt64, queryParams?: QueryParams): Observable; /** @@ -51,7 +51,7 @@ export interface BlockRepository { * @returns Observable */ - getBlocksByHeightWithLimit(height: string, limit: number): Observable; + getBlocksByHeightWithLimit(height: UInt64, limit: number): Observable; /** * Get the merkle path for a given a transaction and block @@ -63,5 +63,5 @@ export interface BlockRepository { * @param hash The hash of the transaction. * @return Observable */ - getMerkleTransaction(height: string, hash: string): Observable; + getMerkleTransaction(height: UInt64, hash: string): Observable; } diff --git a/src/infrastructure/ReceiptHttp.ts b/src/infrastructure/ReceiptHttp.ts index 95ae940ae7..dad400a03a 100644 --- a/src/infrastructure/ReceiptHttp.ts +++ b/src/infrastructure/ReceiptHttp.ts @@ -21,6 +21,7 @@ import { MerklePathItem } from '../model/blockchain/MerklePathItem'; import { MerkleProofInfo } from '../model/blockchain/MerkleProofInfo'; import { NetworkType } from '../model/blockchain/NetworkType'; import { Statement } from '../model/receipt/Statement'; +import { UInt64 } from '../model/UInt64'; import { Http } from './Http'; import { CreateStatementFromDTO } from './receipt/CreateReceiptFromDTO'; import { ReceiptRepository } from './ReceiptRepository'; @@ -64,9 +65,9 @@ export class ReceiptHttp extends Http implements ReceiptRepository { * @param hash The hash of the receipt statement or resolution. * @return Observable */ - public getMerkleReceipts(height: string, hash: string): Observable { + public getMerkleReceipts(height: UInt64, hash: string): Observable { return observableFrom( - this.receiptRoutesApi.getMerkleReceipts(height, hash)).pipe( + this.receiptRoutesApi.getMerkleReceipts(height.toString(), hash)).pipe( map(({body}) => new MerkleProofInfo( body.merklePath!.map( (payload) => new MerklePathItem(payload.position, payload.hash)), @@ -81,10 +82,10 @@ export class ReceiptHttp extends Http implements ReceiptRepository { * @param queryParams - (Optional) Query params * @returns Observable */ - public getBlockReceipts(height: string): Observable { + public getBlockReceipts(height: UInt64): Observable { return this.networkTypeObservable.pipe( mergeMap((networkType) => observableFrom( - this.receiptRoutesApi.getBlockReceipts(height)).pipe( + this.receiptRoutesApi.getBlockReceipts(height.toString())).pipe( map(({body}) => CreateStatementFromDTO(body, networkType)), catchError((error) => throwError(this.errorHandling(error))), ), diff --git a/src/infrastructure/ReceiptRepository.ts b/src/infrastructure/ReceiptRepository.ts index a9e98df384..4c0660a63f 100644 --- a/src/infrastructure/ReceiptRepository.ts +++ b/src/infrastructure/ReceiptRepository.ts @@ -17,6 +17,7 @@ import {Observable} from 'rxjs'; import { MerkleProofInfo } from '../model/blockchain/MerkleProofInfo'; import { Statement } from '../model/receipt/Statement'; +import { UInt64 } from '../model/UInt64'; /** * Receipt interface repository. @@ -28,10 +29,10 @@ export interface ReceiptRepository { /** * Get receipts from a block * Returns the receipts linked to a block. - * @param {string} height The height of the block. + * @param {UInt64} height The height of the block. * @return Observable */ - getBlockReceipts(height: string): Observable; + getBlockReceipts(height: UInt64): Observable; /** * Get the merkle path for a given a receipt statement hash and block @@ -43,5 +44,5 @@ export interface ReceiptRepository { * @param hash The hash of the receipt statement or resolution. * @return Observable */ - getMerkleReceipts(height: string, hash: string): Observable; + getMerkleReceipts(height: UInt64, hash: string): Observable; } diff --git a/src/infrastructure/RepositoryFactoryHttp.ts b/src/infrastructure/RepositoryFactoryHttp.ts index 85357ed5d0..1bd08e7783 100644 --- a/src/infrastructure/RepositoryFactoryHttp.ts +++ b/src/infrastructure/RepositoryFactoryHttp.ts @@ -17,6 +17,7 @@ import { Observable, of as observableOf } from 'rxjs'; import { map, share, shareReplay } from 'rxjs/operators'; import { NetworkType } from '../model/blockchain/NetworkType'; +import { UInt64 } from '../model/UInt64'; import { AccountHttp } from './AccountHttp'; import { AccountRepository } from './AccountRepository'; import { BlockHttp } from './BlockHttp'; @@ -69,7 +70,7 @@ export class RepositoryFactoryHttp implements RepositoryFactory { this.url = url; this.networkType = networkType ? observableOf(networkType) : this.createNetworkRepository().getNetworkType().pipe(shareReplay(1)); this.generationHash = generationHash ? observableOf(generationHash) : - this.createBlockRepository().getBlockByHeight('1').pipe(map((b) => b.generationHash)).pipe(shareReplay(1)); + this.createBlockRepository().getBlockByHeight(UInt64.fromUint(1)).pipe(map((b) => b.generationHash)).pipe(shareReplay(1)); } createAccountRepository(): AccountRepository { diff --git a/src/service/TransactionService.ts b/src/service/TransactionService.ts index 902a77496f..fc2aa8da73 100644 --- a/src/service/TransactionService.ts +++ b/src/service/TransactionService.ts @@ -181,7 +181,7 @@ export class TransactionService implements ITransactionService { * @return {Observable} */ private resolvedFromReceipt(transaction: Transaction, aggregateIndex: number): Observable { - return this.receiptRepository.getBlockReceipts(transaction.transactionInfo!.height.toString()).pipe( + return this.receiptRepository.getBlockReceipts(transaction.transactionInfo!.height).pipe( map((statement) => transaction.resolveAliases(statement, aggregateIndex)), ); } diff --git a/test/infrastructure/RepositoryFactory.spec.ts b/test/infrastructure/RepositoryFactory.spec.ts index 5dfcbcfd05..e80f44bf9b 100644 --- a/test/infrastructure/RepositoryFactory.spec.ts +++ b/test/infrastructure/RepositoryFactory.spec.ts @@ -16,12 +16,13 @@ import { expect } from 'chai'; import { of as observableOf } from 'rxjs'; import { map } from 'rxjs/operators'; -import { instance, mock, when } from 'ts-mockito'; +import { deepEqual, instance, mock, when } from 'ts-mockito'; import { BlockRepository } from '../../src/infrastructure/BlockRepository'; import { NetworkRepository } from '../../src/infrastructure/NetworkRepository'; import { RepositoryFactoryHttp } from '../../src/infrastructure/RepositoryFactoryHttp'; import { BlockInfo } from '../../src/model/blockchain/BlockInfo'; import { NetworkType } from '../../src/model/blockchain/NetworkType'; +import { UInt64 } from '../../src/model/UInt64'; describe('RepositoryFactory', () => { it('Should create repositories', () => { @@ -52,7 +53,7 @@ describe('RepositoryFactory', () => { counter++; return v; })); - when(repositoryMock.getBlockByHeight('1')).thenReturn(observableOfBlockInfo); + when(repositoryMock.getBlockByHeight(deepEqual(UInt64.fromUint(1)))).thenReturn(observableOfBlockInfo); expect(observableOfBlockInfo).to.be.equals(observableOfBlockInfo); const repositoryFactory = new (class RepositoryFactoryHttpForTest extends RepositoryFactoryHttp {