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

merge: cherry pick from develop #4784

Merged
merged 2 commits into from
Jul 10, 2023
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
5 changes: 3 additions & 2 deletions packages/core-p2p/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"joi": "17.4.2",
"pluralize": "8.0.0",
"pretty-ms": "7.0.1",
"protobufjs": "6.11.3",
"protobufjs": "7.2.4",
"rate-limiter-flexible": "1.3.2",
"semver": "6.3.0",
"ws": "7.5.5"
Expand All @@ -54,7 +54,8 @@
"@types/fs-extra": "8.1.2",
"@types/hapi__sntp": "3.1.2",
"@types/ip": "1.1.0",
"@types/semver": "6.2.3"
"@types/semver": "6.2.3",
"protobufjs-cli": "1.1.1"
},
"engines": {
"node": ">=10.x"
Expand Down
Loading
Loading