Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions e2e/infrastructure/BlockHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions src/infrastructure/BlockHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export class BlockHttp extends Http implements BlockRepository {
* @param height - Block height
* @returns Observable<BlockInfo>
*/
public getBlockByHeight(height: string): Observable<BlockInfo> {
return observableFrom(this.blockRoutesApi.getBlockByHeight(height)).pipe(
public getBlockByHeight(height: UInt64): Observable<BlockInfo> {
return observableFrom(this.blockRoutesApi.getBlockByHeight(height.toString())).pipe(
map(({body}) => this.toBlockInfo(body)),
catchError((error) => throwError(this.errorHandling(error))),
);
Expand All @@ -67,10 +67,10 @@ export class BlockHttp extends Http implements BlockRepository {
* @param queryParams - (Optional) Query params
* @returns Observable<Transaction[]>
*/
public getBlockTransactions(height: string,
public getBlockTransactions(height: UInt64,
queryParams?: QueryParams): Observable<Transaction[]> {
return observableFrom(
this.blockRoutesApi.getBlockTransactions(height,
this.blockRoutesApi.getBlockTransactions(height.toString(),
this.queryParams(queryParams).pageSize,
this.queryParams(queryParams).id,
this.queryParams(queryParams).order))
Expand All @@ -87,9 +87,9 @@ export class BlockHttp extends Http implements BlockRepository {
* @param limit - Number of blocks returned.
* @returns Observable<BlockInfo[]>
*/
public getBlocksByHeightWithLimit(height: string, limit: number): Observable<BlockInfo[]> {
public getBlocksByHeightWithLimit(height: UInt64, limit: number): Observable<BlockInfo[]> {
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))),
);
Expand Down Expand Up @@ -136,9 +136,9 @@ export class BlockHttp extends Http implements BlockRepository {
* @param hash The hash of the transaction.
* @return Observable<MerkleProofInfo>
*/
public getMerkleTransaction(height: string, hash: string): Observable<MerkleProofInfo> {
public getMerkleTransaction(height: UInt64, hash: string): Observable<MerkleProofInfo> {
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)),
)),
Expand Down
10 changes: 5 additions & 5 deletions src/infrastructure/BlockRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand All @@ -33,15 +33,15 @@ export interface BlockRepository {
* @param height - Block height
* @returns Observable<BlockInfo>
*/
getBlockByHeight(height: string): Observable<BlockInfo>;
getBlockByHeight(height: UInt64): Observable<BlockInfo>;

/**
* Gets array of transactions included in a block for a block height
* @param height - Block height
* @param queryParams - (Optional) Query params
* @returns Observable<Transaction[]>
*/
getBlockTransactions(height: string,
getBlockTransactions(height: UInt64,
queryParams?: QueryParams): Observable<Transaction[]>;

/**
Expand All @@ -51,7 +51,7 @@ export interface BlockRepository {
* @returns Observable<BlockInfo[]>
*/

getBlocksByHeightWithLimit(height: string, limit: number): Observable<BlockInfo[]>;
getBlocksByHeightWithLimit(height: UInt64, limit: number): Observable<BlockInfo[]>;

/**
* Get the merkle path for a given a transaction and block
Expand All @@ -63,5 +63,5 @@ export interface BlockRepository {
* @param hash The hash of the transaction.
* @return Observable<MerkleProofInfo>
*/
getMerkleTransaction(height: string, hash: string): Observable<MerkleProofInfo>;
getMerkleTransaction(height: UInt64, hash: string): Observable<MerkleProofInfo>;
}
9 changes: 5 additions & 4 deletions src/infrastructure/ReceiptHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -64,9 +65,9 @@ export class ReceiptHttp extends Http implements ReceiptRepository {
* @param hash The hash of the receipt statement or resolution.
* @return Observable<MerkleProofInfo>
*/
public getMerkleReceipts(height: string, hash: string): Observable<MerkleProofInfo> {
public getMerkleReceipts(height: UInt64, hash: string): Observable<MerkleProofInfo> {
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)),
Expand All @@ -81,10 +82,10 @@ export class ReceiptHttp extends Http implements ReceiptRepository {
* @param queryParams - (Optional) Query params
* @returns Observable<Statement>
*/
public getBlockReceipts(height: string): Observable<Statement> {
public getBlockReceipts(height: UInt64): Observable<Statement> {
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))),
),
Expand Down
7 changes: 4 additions & 3 deletions src/infrastructure/ReceiptRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<Statement>
*/
getBlockReceipts(height: string): Observable<Statement>;
getBlockReceipts(height: UInt64): Observable<Statement>;

/**
* Get the merkle path for a given a receipt statement hash and block
Expand All @@ -43,5 +44,5 @@ export interface ReceiptRepository {
* @param hash The hash of the receipt statement or resolution.
* @return Observable<MerkleProofInfo>
*/
getMerkleReceipts(height: string, hash: string): Observable<MerkleProofInfo>;
getMerkleReceipts(height: UInt64, hash: string): Observable<MerkleProofInfo>;
}
3 changes: 2 additions & 1 deletion src/infrastructure/RepositoryFactoryHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/service/TransactionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class TransactionService implements ITransactionService {
* @return {Observable<Transaction>}
*/
private resolvedFromReceipt(transaction: Transaction, aggregateIndex: number): Observable<Transaction> {
return this.receiptRepository.getBlockReceipts(transaction.transactionInfo!.height.toString()).pipe(
return this.receiptRepository.getBlockReceipts(transaction.transactionInfo!.height).pipe(
map((statement) => transaction.resolveAliases(statement, aggregateIndex)),
);
}
Expand Down
5 changes: 3 additions & 2 deletions test/infrastructure/RepositoryFactory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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 {

Expand Down