Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statement recipient types filtering #638

Merged
merged 1 commit into from Aug 1, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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