Skip to content

Commit

Permalink
Statement recipient types filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
fboucquez committed Jul 31, 2020
1 parent 212e777 commit d77263c
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 7 deletions.
76 changes: 76 additions & 0 deletions e2e/infrastructure/ReceiptHttp.spec.ts
@@ -0,0 +1,76 @@
/*
* Copyright 2018 NEM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { expect } from 'chai';
import { toArray } from 'rxjs/operators';
import { ReceiptHttp } from '../../src/infrastructure/infrastructure';
import { ReceiptPaginationStreamer } from '../../src/infrastructure/paginationStreamer/ReceiptPaginationStreamer';
import { ReceiptRepository } from '../../src/infrastructure/ReceiptRepository';
import { ReceiptType, UInt64 } from '../../src/model/model';
import { IntegrationTestHelper } from './IntegrationTestHelper';

describe('ReceiptHttp', () => {
const helper = new IntegrationTestHelper();
let receiptRepository: ReceiptRepository;

before(() => {
return helper.start().then(() => {
receiptRepository = helper.repositoryFactory.createReceiptRepository();
});
});

describe('searchReceipt with streamer and recipient type type', () => {
async function searchByRecipientType(receiptTypes: ReceiptType[], empty: boolean) {
const streamer = ReceiptPaginationStreamer.transactionStatements(receiptRepository);

const infos = await streamer
.search({ pageSize: 20, height: UInt64.fromUint(1), receiptTypes: receiptTypes })
.pipe(toArray())
.toPromise();

infos.forEach((s) => {
s.receipts.forEach((r) => {
expect(receiptTypes.indexOf(r.type)).to.not.eq(-1);
});
});
if (empty) {
expect(infos.length).to.be.eq(0);
} else {
expect(infos.length).to.not.eq(0);
}
}

it('should return receipt info Harvest_Fee', async () => {
await searchByRecipientType([ReceiptType.Harvest_Fee], false);
});

it('should return receipt info Namespace_Rental_Fee', async () => {
await searchByRecipientType([ReceiptType.Namespace_Rental_Fee], false);
});

it('should return receipt info Harvest_Fee and Namespace_Rental_Fee', async () => {
await searchByRecipientType([ReceiptType.Harvest_Fee, ReceiptType.Namespace_Rental_Fee], false);
});

it('should return receipt info LockHash_Completed and Namespace_Rental_Fee', async () => {
await searchByRecipientType([ReceiptType.LockHash_Completed, ReceiptType.Namespace_Rental_Fee], false);
});

it('should return receipt info LockHash_Completed', async () => {
await searchByRecipientType([ReceiptType.LockHash_Completed], true);
});
});
});
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -99,7 +99,7 @@
"ripemd160": "^2.0.2",
"rxjs": "^6.5.3",
"rxjs-compat": "^6.5.3",
"symbol-openapi-typescript-fetch-client": "0.9.5",
"symbol-openapi-typescript-fetch-client": "0.9.6-SNAPSHOT.202007311152",
"tweetnacl": "^1.0.3",
"utf8": "^3.0.0",
"ws": "^7.2.3"
Expand Down
2 changes: 1 addition & 1 deletion src/infrastructure/ReceiptHttp.ts
Expand Up @@ -82,7 +82,7 @@ export class ReceiptHttp extends Http implements ReceiptRepository {
return this.call(
this.receiptRoutesApi.searchReceipts(
criteria.height?.toString(),
criteria.receiptType?.valueOf(),
criteria.receiptTypes?.map((t) => t.valueOf()),
criteria.recipientAddress?.plain(),
criteria.senderAddress?.plain(),
criteria.targetAddress?.plain(),
Expand Down
Expand Up @@ -32,9 +32,9 @@ export interface TransactionStatementSearchCriteria extends SearchCriteria {
height?: UInt64;

/**
* receipt type. (optional, TransactionStatement only)
* receipt types. (optional, TransactionStatement only)
*/
receiptType?: ReceiptType;
receiptTypes?: ReceiptType[];

/**
* Recipient address. (optional, TransactionStatement only)
Expand Down

0 comments on commit d77263c

Please sign in to comment.