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
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ describe("API 2.0 - Transactions", () => {
const response = await api.request("GET", "transactions", { recipientId: recipientAddress });
expect(response).toBeSuccessfulResponse();
expect(response.data.data).toBeArray();
expect(response.data.data).toHaveLength(3);
expect(response.data.data).toHaveLength(2);

for (const transaction of response.data.data) {
api.expectTransaction(transaction);
Expand All @@ -224,7 +224,7 @@ describe("API 2.0 - Transactions", () => {
expect(response).toBeSuccessfulResponse();

expect(response.data.data).toBeArray();
expect(response.data.data).toHaveLength(6);
expect(response.data.data).toHaveLength(4);

for (const transaction of response.data.data) {
api.expectTransaction(transaction);
Expand Down
46 changes: 2 additions & 44 deletions __tests__/unit/core-database/transaction-filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("TransactionFilter.getExpression", () => {
});

describe("TransactionCriteria.address", () => {
it("should compare senderPublicKey, recipientId, multipayment recipientId, delegate registration sender", async () => {
it("should compare senderPublicKey, recipientId, multipayment recipientId", async () => {
walletRepository.hasByAddress.mockReturnValue(true);
walletRepository.findByAddress
.mockReturnValueOnce({
Expand Down Expand Up @@ -58,14 +58,6 @@ describe("TransactionFilter.getExpression", () => {
{ property: "asset", op: "contains", value: { payments: [{ recipientId: "123" }] } },
],
},
{
op: "and",
expressions: [
{ property: "typeGroup", op: "equal", value: Enums.TransactionTypeGroup.Core },
{ property: "type", op: "equal", value: Enums.TransactionType.DelegateRegistration },
{ property: "senderPublicKey", op: "equal", value: "456" },
],
},
],
});
});
Expand Down Expand Up @@ -125,7 +117,7 @@ describe("TransactionFilter.getExpression", () => {
});

describe("TransactionCriteria.recipientId", () => {
it("should compare using equal expression and include multipayment and include delegate registration transaction", async () => {
it("should compare using equal expression and include multipayment", async () => {
walletRepository.hasByAddress.mockReturnValue(true);
walletRepository.findByAddress.mockReturnValueOnce({
getPublicKey: () => {
Expand All @@ -136,40 +128,6 @@ describe("TransactionFilter.getExpression", () => {
const transactionFilter = container.resolve(TransactionFilter);
const expression = await transactionFilter.getExpression({ recipientId: "123" });

expect(walletRepository.hasByAddress).toBeCalledWith("123");
expect(walletRepository.findByAddress).toBeCalledWith("123");
expect(expression).toEqual({
op: "or",
expressions: [
{ property: "recipientId", op: "equal", value: "123" },
{
op: "and",
expressions: [
{ property: "typeGroup", op: "equal", value: Enums.TransactionTypeGroup.Core },
{ property: "type", op: "equal", value: Enums.TransactionType.MultiPayment },
{ property: "asset", op: "contains", value: { payments: [{ recipientId: "123" }] } },
],
},
{
op: "and",
expressions: [
{ property: "typeGroup", op: "equal", value: Enums.TransactionTypeGroup.Core },
{ property: "type", op: "equal", value: Enums.TransactionType.DelegateRegistration },
{ property: "senderPublicKey", op: "equal", value: "456" },
],
},
],
});
});

it("should compare using equal expression and include multipayment when wallet not found", async () => {
walletRepository.hasByAddress.mockReturnValue(false);

const transactionFilter = container.resolve(TransactionFilter);
const expression = await transactionFilter.getExpression({ recipientId: "123" });

expect(walletRepository.hasByAddress).toBeCalledWith("123");
expect(walletRepository.findByAddress).not.toBeCalled();
expect(expression).toEqual({
op: "or",
expressions: [
Expand Down
23 changes: 0 additions & 23 deletions packages/core-database/src/transaction-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,29 +142,6 @@ export class TransactionFilter implements Contracts.Database.TransactionFilter {
],
};

if (this.walletRepository.hasByAddress(criteria)) {
const recipientWallet = this.walletRepository.findByAddress(criteria);
if (recipientWallet && recipientWallet.getPublicKey()) {
const delegateRegistrationExpression: Contracts.Search.AndExpression<Transaction> = {
op: "and",
expressions: [
{ op: "equal", property: "typeGroup", value: Enums.TransactionTypeGroup.Core },
{ op: "equal", property: "type", value: Enums.TransactionType.DelegateRegistration },
{ op: "equal", property: "senderPublicKey", value: recipientWallet.getPublicKey() },
],
};

return {
op: "or",
expressions: [
recipientIdExpression,
multipaymentRecipientIdExpression,
delegateRegistrationExpression,
],
};
}
}

return {
op: "or",
expressions: [recipientIdExpression, multipaymentRecipientIdExpression],
Expand Down