Skip to content

Commit

Permalink
merge: cherry pick from develop (#4784)
Browse files Browse the repository at this point in the history
* fix(core-database): remove delegate registration expression (#4781)

* Remove delegate registration expression

* Fix tests

* Fix integration tests

* deps(p2p): update protobufjs (#4782)

* Update protobufjs

* Add protobufjs-cli

* Generate protos
  • Loading branch information
sebastijankuzner authored Jul 10, 2023
1 parent 9729f40 commit 6b0d009
Show file tree
Hide file tree
Showing 7 changed files with 1,023 additions and 338 deletions.
4 changes: 2 additions & 2 deletions __tests__/integration/core-api/handlers/transactions.test.ts
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

0 comments on commit 6b0d009

Please sign in to comment.