Skip to content

Commit ffca22d

Browse files
authored
Statement recipient types filtering (#638)
1 parent 0bebf5b commit ffca22d

File tree

5 files changed

+83
-7
lines changed

5 files changed

+83
-7
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright 2018 NEM
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { expect } from 'chai';
18+
import { toArray } from 'rxjs/operators';
19+
import { ReceiptHttp } from '../../src/infrastructure/infrastructure';
20+
import { ReceiptPaginationStreamer } from '../../src/infrastructure/paginationStreamer/ReceiptPaginationStreamer';
21+
import { ReceiptRepository } from '../../src/infrastructure/ReceiptRepository';
22+
import { ReceiptType, UInt64 } from '../../src/model/model';
23+
import { IntegrationTestHelper } from './IntegrationTestHelper';
24+
25+
describe('ReceiptHttp', () => {
26+
const helper = new IntegrationTestHelper();
27+
let receiptRepository: ReceiptRepository;
28+
29+
before(() => {
30+
return helper.start().then(() => {
31+
receiptRepository = helper.repositoryFactory.createReceiptRepository();
32+
});
33+
});
34+
35+
describe('searchReceipt with streamer and recipient type type', () => {
36+
async function searchByRecipientType(receiptTypes: ReceiptType[], empty: boolean) {
37+
const streamer = ReceiptPaginationStreamer.transactionStatements(receiptRepository);
38+
39+
const infos = await streamer
40+
.search({ pageSize: 20, height: UInt64.fromUint(1), receiptTypes: receiptTypes })
41+
.pipe(toArray())
42+
.toPromise();
43+
44+
infos.forEach((s) => {
45+
s.receipts.forEach((r) => {
46+
expect(receiptTypes.indexOf(r.type)).to.not.eq(-1);
47+
});
48+
});
49+
if (empty) {
50+
expect(infos.length).to.be.eq(0);
51+
} else {
52+
expect(infos.length).to.not.eq(0);
53+
}
54+
}
55+
56+
it('should return receipt info Harvest_Fee', async () => {
57+
await searchByRecipientType([ReceiptType.Harvest_Fee], false);
58+
});
59+
60+
it('should return receipt info Namespace_Rental_Fee', async () => {
61+
await searchByRecipientType([ReceiptType.Namespace_Rental_Fee], false);
62+
});
63+
64+
it('should return receipt info Harvest_Fee and Namespace_Rental_Fee', async () => {
65+
await searchByRecipientType([ReceiptType.Harvest_Fee, ReceiptType.Namespace_Rental_Fee], false);
66+
});
67+
68+
it('should return receipt info LockHash_Completed and Namespace_Rental_Fee', async () => {
69+
await searchByRecipientType([ReceiptType.LockHash_Completed, ReceiptType.Namespace_Rental_Fee], false);
70+
});
71+
72+
it('should return receipt info LockHash_Completed', async () => {
73+
await searchByRecipientType([ReceiptType.LockHash_Completed], true);
74+
});
75+
});
76+
});

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
"ripemd160": "^2.0.2",
100100
"rxjs": "^6.5.3",
101101
"rxjs-compat": "^6.5.3",
102-
"symbol-openapi-typescript-fetch-client": "0.9.5",
102+
"symbol-openapi-typescript-fetch-client": "0.9.6-SNAPSHOT.202007311152",
103103
"tweetnacl": "^1.0.3",
104104
"utf8": "^3.0.0",
105105
"ws": "^7.2.3"

src/infrastructure/ReceiptHttp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class ReceiptHttp extends Http implements ReceiptRepository {
8282
return this.call(
8383
this.receiptRoutesApi.searchReceipts(
8484
criteria.height?.toString(),
85-
criteria.receiptType?.valueOf(),
85+
criteria.receiptTypes?.map((t) => t.valueOf()),
8686
criteria.recipientAddress?.plain(),
8787
criteria.senderAddress?.plain(),
8888
criteria.targetAddress?.plain(),

src/infrastructure/searchCriteria/TransactionStatementSearchCriteria.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export interface TransactionStatementSearchCriteria extends SearchCriteria {
3232
height?: UInt64;
3333

3434
/**
35-
* receipt type. (optional, TransactionStatement only)
35+
* receipt types. (optional, TransactionStatement only)
3636
*/
37-
receiptType?: ReceiptType;
37+
receiptTypes?: ReceiptType[];
3838

3939
/**
4040
* Recipient address. (optional, TransactionStatement only)

0 commit comments

Comments
 (0)