From 1b9edd30133174e443fe677d01ca1e7a321a293c Mon Sep 17 00:00:00 2001 From: Dmitry Tyshchenko Date: Tue, 16 Jun 2020 08:51:47 +0300 Subject: [PATCH 1/2] Remove custom wallet repository --- .../handlers/__mocks__/transaction-handler.ts | 16 +--- .../handlers/bridgechain-registration.test.ts | 26 +++--- .../handlers/bridgechain-resignation.test.ts | 30 +++--- .../handlers/bridgechain-update.test.ts | 22 ++--- .../handlers/business-registration.test.ts | 16 ++-- .../handlers/business-resignation.test.ts | 24 +++-- .../handlers/business-update.test.ts | 32 +++---- .../handlers/general.test.ts | 6 +- .../handlers/handler-registry.test.ts | 22 +---- .../one/multi-signature-registration.test.ts | 10 +- .../two/delegate-registration.test.ts | 42 ++++----- .../handlers/two/delegate-resignation.test.ts | 68 +++++--------- .../handlers/two/general.test.ts | 92 +++++++++---------- .../handlers/two/htlc-claim.test.ts | 68 +++++--------- .../handlers/two/htlc-lock.test.ts | 46 +++------- .../handlers/two/htlc-refund.test.ts | 62 +++++-------- .../handlers/two/ipfs.test.ts | 34 +++---- .../handlers/two/multi-payment.test.ts | 32 +++---- .../two/multi-signature-registration.test.ts | 60 +++++------- .../two/second-signature-registration.test.ts | 48 ++++------ .../handlers/two/transfer.test.ts | 44 ++++----- .../handlers/two/vote.test.ts | 60 ++++++------ .../src/handlers/bridgechain-registration.ts | 34 ++----- .../src/handlers/bridgechain-resignation.ts | 27 ++---- .../src/handlers/bridgechain-update.ts | 31 ++----- .../src/handlers/business-registration.ts | 33 ++----- .../src/handlers/business-resignation.ts | 31 ++----- .../src/handlers/business-update.ts | 27 ++---- .../src/handlers/entity.ts | 30 ++---- .../src/handlers/magistrate-handler.ts | 3 +- .../src/handlers/one/delegate-registration.ts | 45 +++------ .../one/multi-signature-registration.ts | 11 +-- .../one/second-signature-registration.ts | 43 +++------ .../src/handlers/one/transfer.ts | 21 +---- .../src/handlers/one/vote.ts | 38 ++------ .../src/handlers/transaction.ts | 68 ++++---------- .../src/handlers/two/delegate-resignation.ts | 32 +++---- .../src/handlers/two/htlc-claim.ts | 60 +++++------- .../src/handlers/two/htlc-lock.ts | 47 +++------- .../src/handlers/two/htlc-refund.ts | 46 +++------- .../src/handlers/two/ipfs.ts | 42 +++------ .../src/handlers/two/multi-payment.ts | 43 +++------ .../two/multi-signature-registration.ts | 42 +++------ 43 files changed, 566 insertions(+), 1048 deletions(-) diff --git a/__tests__/unit/core-magistrate-transactions/handlers/__mocks__/transaction-handler.ts b/__tests__/unit/core-magistrate-transactions/handlers/__mocks__/transaction-handler.ts index e5a85e900f..0818c1dd25 100644 --- a/__tests__/unit/core-magistrate-transactions/handlers/__mocks__/transaction-handler.ts +++ b/__tests__/unit/core-magistrate-transactions/handlers/__mocks__/transaction-handler.ts @@ -8,17 +8,11 @@ export class TransactionHandler { protected app = app; protected walletRepository = walletRepository; - public applyToSender(transaction, customWalletRepository?) { + public applyToSender(transaction) {} - } - - public revertForSender(transaction, customWalletRepository?) { - - } - - public throwIfCannotBeApplied(transaction, wallet, customWalletRepository?) { + public revertForSender(transaction) {} - } + public throwIfCannotBeApplied(transaction, wallet) {} protected getTransactionReader() { return transactionReader; @@ -26,7 +20,7 @@ export class TransactionHandler { protected getConstructor() { return { - staticFee: () => "50000000" + staticFee: () => "50000000", }; } -} \ No newline at end of file +} diff --git a/__tests__/unit/core-magistrate-transactions/handlers/bridgechain-registration.test.ts b/__tests__/unit/core-magistrate-transactions/handlers/bridgechain-registration.test.ts index 93f79d77ee..2e7a9a5802 100644 --- a/__tests__/unit/core-magistrate-transactions/handlers/bridgechain-registration.test.ts +++ b/__tests__/unit/core-magistrate-transactions/handlers/bridgechain-registration.test.ts @@ -155,9 +155,7 @@ describe("BusinessRegistration", () => { }); it("should not throw", async () => { - await expect( - handler.throwIfCannotBeApplied(bridgechainRegistrationTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(bridgechainRegistrationTransaction, senderWallet)).toResolve(); }); it("should not throw without custom wallet repository", async () => { @@ -168,22 +166,20 @@ describe("BusinessRegistration", () => { configManager.set("network.pubKeyHash", 99); configManager.set("exceptions.transactions", [bridgechainRegistrationTransaction.data.id]); - await expect( - handler.throwIfCannotBeApplied(bridgechainRegistrationTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(bridgechainRegistrationTransaction, senderWallet)).toResolve(); }); it("should throw if wallet is not business", async () => { senderWallet.forgetAttribute("business"); await expect( - handler.throwIfCannotBeApplied(bridgechainRegistrationTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(bridgechainRegistrationTransaction, senderWallet), ).rejects.toThrowError(WalletIsNotBusinessError); }); it("should throw if business is resigned", async () => { senderWallet.setAttribute("business.resigned", true); await expect( - handler.throwIfCannotBeApplied(bridgechainRegistrationTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(bridgechainRegistrationTransaction, senderWallet), ).rejects.toThrowError(BusinessIsResignedError); }); @@ -204,7 +200,7 @@ describe("BusinessRegistration", () => { walletRepository.index(senderWallet); await expect( - handler.throwIfCannotBeApplied(bridgechainRegistrationTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(bridgechainRegistrationTransaction, senderWallet), ).rejects.toThrowError(BridgechainAlreadyRegisteredError); }); @@ -222,7 +218,7 @@ describe("BusinessRegistration", () => { walletRepository.index(senderWallet); await expect( - handler.throwIfCannotBeApplied(bridgechainRegistrationTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(bridgechainRegistrationTransaction, senderWallet), ).rejects.toThrowError(GenesisHashAlreadyRegisteredError); }); @@ -232,14 +228,14 @@ describe("BusinessRegistration", () => { }; await expect( - handler.throwIfCannotBeApplied(bridgechainRegistrationTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(bridgechainRegistrationTransaction, senderWallet), ).rejects.toThrowError(PortKeyMustBeValidPackageNameError); }); it("should throw if wallet has insufficient balance", async () => { senderWallet.balance = Utils.BigNumber.ZERO; await expect( - handler.throwIfCannotBeApplied(bridgechainRegistrationTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(bridgechainRegistrationTransaction, senderWallet), ).rejects.toThrowError(InsufficientBalanceError); }); }); @@ -254,7 +250,7 @@ describe("BusinessRegistration", () => { it("should be ok", async () => { const senderBalance = senderWallet.balance; - await handler.apply(bridgechainRegistrationTransaction, walletRepository); + await handler.apply(bridgechainRegistrationTransaction); expect( senderWallet.getAttribute("business.bridgechains")[bridgechainRegistrationAsset.genesisHash] @@ -296,14 +292,14 @@ describe("BusinessRegistration", () => { it("should be ok", async () => { const senderBalance = senderWallet.balance; - await handler.apply(bridgechainRegistrationTransaction, walletRepository); + await handler.apply(bridgechainRegistrationTransaction); expect( senderWallet.getAttribute("business.bridgechains")[bridgechainRegistrationAsset.genesisHash] .bridgechainAsset, ).toEqual(bridgechainRegistrationAsset); - await handler.revert(bridgechainRegistrationTransaction, walletRepository); + await handler.revert(bridgechainRegistrationTransaction); expect( senderWallet.hasAttribute("business.bridgechains")[bridgechainRegistrationAsset.genesisHash], diff --git a/__tests__/unit/core-magistrate-transactions/handlers/bridgechain-resignation.test.ts b/__tests__/unit/core-magistrate-transactions/handlers/bridgechain-resignation.test.ts index 627b21fb2b..d17c180b0a 100644 --- a/__tests__/unit/core-magistrate-transactions/handlers/bridgechain-resignation.test.ts +++ b/__tests__/unit/core-magistrate-transactions/handlers/bridgechain-resignation.test.ts @@ -148,22 +148,20 @@ describe("BusinessRegistration", () => { describe("throwIfCannotBeApplied", () => { it("should not throw", async () => { - await expect( - handler.throwIfCannotBeApplied(bridgechainResignationTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(bridgechainResignationTransaction, senderWallet)).toResolve(); }); it("should throw if wallet is not business", async () => { senderWallet.forgetAttribute("business"); await expect( - handler.throwIfCannotBeApplied(bridgechainResignationTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(bridgechainResignationTransaction, senderWallet), ).rejects.toThrowError(WalletIsNotBusinessError); }); it("should throw if business is resigned", async () => { senderWallet.setAttribute("business.resigned", true); await expect( - handler.throwIfCannotBeApplied(bridgechainResignationTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(bridgechainResignationTransaction, senderWallet), ).rejects.toThrowError(BusinessIsResignedError); }); @@ -173,7 +171,7 @@ describe("BusinessRegistration", () => { senderWallet.setAttribute("business", businessAttributes); await expect( - handler.throwIfCannotBeApplied(bridgechainResignationTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(bridgechainResignationTransaction, senderWallet), ).rejects.toThrowError(BridgechainIsNotRegisteredByWalletError); }); @@ -185,7 +183,7 @@ describe("BusinessRegistration", () => { .build(); await expect( - handler.throwIfCannotBeApplied(bridgechainResignationTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(bridgechainResignationTransaction, senderWallet), ).rejects.toThrowError(BridgechainIsNotRegisteredByWalletError); }); @@ -195,7 +193,7 @@ describe("BusinessRegistration", () => { senderWallet.setAttribute("business", businessAttributes); await expect( - handler.throwIfCannotBeApplied(bridgechainResignationTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(bridgechainResignationTransaction, senderWallet), ).rejects.toThrowError(BridgechainIsResignedError); }); @@ -203,14 +201,14 @@ describe("BusinessRegistration", () => { delete bridgechainResignationTransaction.data.asset; await expect( - handler.throwIfCannotBeApplied(bridgechainResignationTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(bridgechainResignationTransaction, senderWallet), ).rejects.toThrowError(); }); it("should throw if wallet has insufficient balance", async () => { senderWallet.balance = Utils.BigNumber.ZERO; await expect( - handler.throwIfCannotBeApplied(bridgechainResignationTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(bridgechainResignationTransaction, senderWallet), ).rejects.toThrowError(InsufficientBalanceError); }); }); @@ -235,7 +233,7 @@ describe("BusinessRegistration", () => { it("should be ok", async () => { const senderBalance = senderWallet.balance; - await handler.apply(bridgechainResignationTransaction, walletRepository); + await handler.apply(bridgechainResignationTransaction); expect( senderWallet.getAttribute("business.bridgechains")[bridgechainRegistrationAsset.genesisHash].resigned, @@ -251,7 +249,7 @@ describe("BusinessRegistration", () => { it("should throw if transaction asset is missing", async () => { delete bridgechainResignationTransaction.data.asset; - await expect(handler.apply(bridgechainResignationTransaction, walletRepository)).rejects.toThrowError(); + await expect(handler.apply(bridgechainResignationTransaction)).rejects.toThrowError(); }); }); @@ -259,13 +257,13 @@ describe("BusinessRegistration", () => { it("should be ok", async () => { const senderBalance = senderWallet.balance; - await handler.apply(bridgechainResignationTransaction, walletRepository); + await handler.apply(bridgechainResignationTransaction); expect( senderWallet.getAttribute("business.bridgechains")[bridgechainRegistrationAsset.genesisHash].resigned, ).toBeTrue(); - await handler.revert(bridgechainResignationTransaction, walletRepository); + await handler.revert(bridgechainResignationTransaction); expect( senderWallet.getAttribute("business.bridgechains")[bridgechainRegistrationAsset.genesisHash].resigned, @@ -275,7 +273,7 @@ describe("BusinessRegistration", () => { }); it("should throw if transaction asset is missing", async () => { - await handler.apply(bridgechainResignationTransaction, walletRepository); + await handler.apply(bridgechainResignationTransaction); expect( senderWallet.getAttribute("business.bridgechains")[bridgechainRegistrationAsset.genesisHash].resigned, @@ -283,7 +281,7 @@ describe("BusinessRegistration", () => { delete bridgechainResignationTransaction.data.asset; - await expect(handler.revert(bridgechainResignationTransaction, walletRepository)).rejects.toThrowError(); + await expect(handler.revert(bridgechainResignationTransaction)).rejects.toThrowError(); }); }); }); diff --git a/__tests__/unit/core-magistrate-transactions/handlers/bridgechain-update.test.ts b/__tests__/unit/core-magistrate-transactions/handlers/bridgechain-update.test.ts index a263e72986..b49345f93f 100644 --- a/__tests__/unit/core-magistrate-transactions/handlers/bridgechain-update.test.ts +++ b/__tests__/unit/core-magistrate-transactions/handlers/bridgechain-update.test.ts @@ -182,22 +182,20 @@ describe("BusinessRegistration", () => { describe("throwIfCannotBeApplied", () => { it("should not throw", async () => { - await expect( - handler.throwIfCannotBeApplied(bridgechainUpdateTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(bridgechainUpdateTransaction, senderWallet)).toResolve(); }); it("should throw if wallet is not business", async () => { senderWallet.forgetAttribute("business"); await expect( - handler.throwIfCannotBeApplied(bridgechainUpdateTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(bridgechainUpdateTransaction, senderWallet), ).rejects.toThrowError(BusinessIsNotRegisteredError); }); it("should throw if business is resigned", async () => { senderWallet.setAttribute("business.resigned", true); await expect( - handler.throwIfCannotBeApplied(bridgechainUpdateTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(bridgechainUpdateTransaction, senderWallet), ).rejects.toThrowError(BusinessIsResignedError); }); @@ -206,7 +204,7 @@ describe("BusinessRegistration", () => { delete businessAttributes.bridgechains; await expect( - handler.throwIfCannotBeApplied(bridgechainUpdateTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(bridgechainUpdateTransaction, senderWallet), ).rejects.toThrowError(BridgechainIsNotRegisteredByWalletError); }); @@ -220,7 +218,7 @@ describe("BusinessRegistration", () => { .build(); await expect( - handler.throwIfCannotBeApplied(bridgechainUpdateTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(bridgechainUpdateTransaction, senderWallet), ).rejects.toThrowError(BridgechainIsNotRegisteredByWalletError); }); @@ -229,7 +227,7 @@ describe("BusinessRegistration", () => { businessAttributes.bridgechains[bridgechainRegistrationAsset.genesisHash].resigned = true; await expect( - handler.throwIfCannotBeApplied(bridgechainUpdateTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(bridgechainUpdateTransaction, senderWallet), ).rejects.toThrowError(BridgechainIsResignedError); }); @@ -237,7 +235,7 @@ describe("BusinessRegistration", () => { bridgechainUpdateTransaction.data.asset!.bridgechainUpdate.ports = { "@arkecosystem/INVALID": 55555 }; await expect( - handler.throwIfCannotBeApplied(bridgechainUpdateTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(bridgechainUpdateTransaction, senderWallet), ).rejects.toThrowError(PortKeyMustBeValidPackageNameError); }); }); @@ -260,7 +258,7 @@ describe("BusinessRegistration", () => { it("should be ok", async () => { const senderBalance = senderWallet.balance; - await handler.apply(bridgechainUpdateTransaction, walletRepository); + await handler.apply(bridgechainUpdateTransaction); const bridgechainUpdateAssetClone = Object.assign({}, bridgechainUpdateAsset); delete bridgechainUpdateAssetClone.bridgechainId; @@ -314,7 +312,7 @@ describe("BusinessRegistration", () => { .sign(passphrases[0]) .build(); - await handler.apply(secondBridgechainUpdateTransaction, walletRepository); + await handler.apply(secondBridgechainUpdateTransaction); const secondBridgechainUpdateAssetClone = Object.assign({}, secondBridgechainUpdateAsset); delete secondBridgechainUpdateAssetClone.bridgechainId; @@ -334,7 +332,7 @@ describe("BusinessRegistration", () => { secondBridgechainUpdateTransaction.data, ]); - await handler.revert(secondBridgechainUpdateTransaction, walletRepository); + await handler.revert(secondBridgechainUpdateTransaction); expect( senderWallet.getAttribute("business.bridgechains")[bridgechainRegistrationAsset.genesisHash] diff --git a/__tests__/unit/core-magistrate-transactions/handlers/business-registration.test.ts b/__tests__/unit/core-magistrate-transactions/handlers/business-registration.test.ts index 37cadcc50b..794ce47a99 100644 --- a/__tests__/unit/core-magistrate-transactions/handlers/business-registration.test.ts +++ b/__tests__/unit/core-magistrate-transactions/handlers/business-registration.test.ts @@ -116,22 +116,20 @@ describe("BusinessRegistration", () => { describe("throwIfCannotBeApplied", () => { it("should not throw", async () => { - await expect( - handler.throwIfCannotBeApplied(businessRegistrationTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(businessRegistrationTransaction, senderWallet)).toResolve(); }); it("should throw if business already registered", async () => { senderWallet.setAttribute("business", {}); await expect( - handler.throwIfCannotBeApplied(businessRegistrationTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(businessRegistrationTransaction, senderWallet), ).rejects.toThrowError(BusinessAlreadyRegisteredError); }); it("should throw if wallet has insufficient balance", async () => { senderWallet.balance = Utils.BigNumber.ZERO; await expect( - handler.throwIfCannotBeApplied(businessRegistrationTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(businessRegistrationTransaction, senderWallet), ).rejects.toThrowError(InsufficientBalanceError); }); }); @@ -154,7 +152,7 @@ describe("BusinessRegistration", () => { it("should be ok", async () => { const senderBalance = senderWallet.balance; - await handler.apply(businessRegistrationTransaction, walletRepository); + await handler.apply(businessRegistrationTransaction); expect(senderWallet.hasAttribute("business")).toBeTrue(); expect(senderWallet.getAttribute("business.businessAsset")).toEqual(businessRegistrationAsset); @@ -173,7 +171,7 @@ describe("BusinessRegistration", () => { it("should throw if transaction asset is missing", async () => { delete businessRegistrationTransaction.data.asset; - await expect(handler.apply(businessRegistrationTransaction, walletRepository)).rejects.toThrowError(); + await expect(handler.apply(businessRegistrationTransaction)).rejects.toThrowError(); }); }); @@ -181,11 +179,11 @@ describe("BusinessRegistration", () => { it("should be ok", async () => { const senderBalance = senderWallet.balance; - await handler.apply(businessRegistrationTransaction, walletRepository); + await handler.apply(businessRegistrationTransaction); expect(senderWallet.hasAttribute("business")).toBeTrue(); - await handler.revert(businessRegistrationTransaction, walletRepository); + await handler.revert(businessRegistrationTransaction); expect(senderWallet.hasAttribute("business")).toBeFalse(); expect(senderWallet.balance).toEqual(Utils.BigNumber.make(senderBalance)); diff --git a/__tests__/unit/core-magistrate-transactions/handlers/business-resignation.test.ts b/__tests__/unit/core-magistrate-transactions/handlers/business-resignation.test.ts index dee190d307..177b120454 100644 --- a/__tests__/unit/core-magistrate-transactions/handlers/business-resignation.test.ts +++ b/__tests__/unit/core-magistrate-transactions/handlers/business-resignation.test.ts @@ -123,29 +123,27 @@ describe("BusinessRegistration", () => { describe("throwIfCannotBeApplied", () => { it("should not throw", async () => { - await expect( - handler.throwIfCannotBeApplied(businessResignationTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(businessResignationTransaction, senderWallet)).toResolve(); }); it("should throw if business is not registered", async () => { senderWallet.forgetAttribute("business"); - await expect( - handler.throwIfCannotBeApplied(businessResignationTransaction, senderWallet, walletRepository), - ).rejects.toThrow(BusinessIsNotRegisteredError); + await expect(handler.throwIfCannotBeApplied(businessResignationTransaction, senderWallet)).rejects.toThrow( + BusinessIsNotRegisteredError, + ); }); it("should throw if business is resigned", async () => { senderWallet.setAttribute("business.resigned", true); - await expect( - handler.throwIfCannotBeApplied(businessResignationTransaction, senderWallet, walletRepository), - ).rejects.toThrow(BusinessIsResignedError); + await expect(handler.throwIfCannotBeApplied(businessResignationTransaction, senderWallet)).rejects.toThrow( + BusinessIsResignedError, + ); }); it("should throw if wallet has insufficient balance", async () => { senderWallet.balance = Utils.BigNumber.ZERO; await expect( - handler.throwIfCannotBeApplied(businessResignationTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(businessResignationTransaction, senderWallet), ).rejects.toThrowError(InsufficientBalanceError); }); }); @@ -172,7 +170,7 @@ describe("BusinessRegistration", () => { senderWallet, ); - await handler.apply(businessResignationTransaction, walletRepository); + await handler.apply(businessResignationTransaction); expect(senderWallet.hasAttribute("business")).toBeTrue(); expect(senderWallet.getAttribute("business.resigned")).toBeTrue(); @@ -193,11 +191,11 @@ describe("BusinessRegistration", () => { it("should be ok", async () => { const senderBalance = senderWallet.balance; - await handler.apply(businessResignationTransaction, walletRepository); + await handler.apply(businessResignationTransaction); expect(senderWallet.getAttribute("business.resigned")).toBeTrue(); - await handler.revert(businessResignationTransaction, walletRepository); + await handler.revert(businessResignationTransaction); expect(senderWallet.hasAttribute("business.resigned")).toBeFalse(); expect(senderWallet.balance).toEqual(Utils.BigNumber.make(senderBalance)); diff --git a/__tests__/unit/core-magistrate-transactions/handlers/business-update.test.ts b/__tests__/unit/core-magistrate-transactions/handlers/business-update.test.ts index b3d9dfffa7..a4fedf873f 100644 --- a/__tests__/unit/core-magistrate-transactions/handlers/business-update.test.ts +++ b/__tests__/unit/core-magistrate-transactions/handlers/business-update.test.ts @@ -135,30 +135,28 @@ describe("BusinessRegistration", () => { describe("throwIfCannotBeApplied", () => { it("should not throw", async () => { - await expect( - handler.throwIfCannotBeApplied(businessUpdateTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(businessUpdateTransaction, senderWallet)).toResolve(); }); it("should throw if business is not registered", async () => { senderWallet.forgetAttribute("business"); - await expect( - handler.throwIfCannotBeApplied(businessUpdateTransaction, senderWallet, walletRepository), - ).rejects.toThrow(BusinessIsNotRegisteredError); + await expect(handler.throwIfCannotBeApplied(businessUpdateTransaction, senderWallet)).rejects.toThrow( + BusinessIsNotRegisteredError, + ); }); it("should throw if business is resigned", async () => { senderWallet.setAttribute("business.resigned", true); - await expect( - handler.throwIfCannotBeApplied(businessUpdateTransaction, senderWallet, walletRepository), - ).rejects.toThrow(BusinessIsResignedError); + await expect(handler.throwIfCannotBeApplied(businessUpdateTransaction, senderWallet)).rejects.toThrow( + BusinessIsResignedError, + ); }); it("should throw if wallet has insufficient balance", async () => { senderWallet.balance = Utils.BigNumber.ZERO; - await expect( - handler.throwIfCannotBeApplied(businessUpdateTransaction, senderWallet, walletRepository), - ).rejects.toThrowError(InsufficientBalanceError); + await expect(handler.throwIfCannotBeApplied(businessUpdateTransaction, senderWallet)).rejects.toThrowError( + InsufficientBalanceError, + ); }); }); @@ -180,7 +178,7 @@ describe("BusinessRegistration", () => { it("should be ok", async () => { const senderBalance = senderWallet.balance; - await handler.apply(businessUpdateTransaction, walletRepository); + await handler.apply(businessUpdateTransaction); expect(senderWallet.getAttribute("business.businessAsset")).toEqual(businessUpdateAsset); @@ -195,7 +193,7 @@ describe("BusinessRegistration", () => { it("should be ok", async () => { const senderBalance = senderWallet.balance; - await handler.apply(businessUpdateTransaction, walletRepository); + await handler.apply(businessUpdateTransaction); expect(senderWallet.getAttribute("business.businessAsset")).toEqual(businessUpdateAsset); @@ -207,7 +205,7 @@ describe("BusinessRegistration", () => { transactionHistoryService.findManyByCriteria.mockResolvedValue([businessRegistrationTransaction.data]); - await handler.revert(businessUpdateTransaction, walletRepository); + await handler.revert(businessUpdateTransaction); expect(senderWallet.getAttribute("business.businessAsset")).toEqual(businessRegistrationAsset); expect(senderWallet.balance).toEqual(Utils.BigNumber.make(senderBalance)); @@ -240,7 +238,7 @@ describe("BusinessRegistration", () => { .sign(passphrases[0]) .build(); - await handler.apply(secondBusinessUpdateTransaction, walletRepository); + await handler.apply(secondBusinessUpdateTransaction); expect(senderWallet.getAttribute("business.businessAsset")).toEqual({ ...businessRegistrationAsset, @@ -254,7 +252,7 @@ describe("BusinessRegistration", () => { secondBusinessUpdateTransaction.data, ]); - await handler.revert(secondBusinessUpdateTransaction, walletRepository); + await handler.revert(secondBusinessUpdateTransaction); expect(senderWallet.getAttribute("business.businessAsset")).toEqual({ ...businessRegistrationAsset, diff --git a/__tests__/unit/core-magistrate-transactions/handlers/general.test.ts b/__tests__/unit/core-magistrate-transactions/handlers/general.test.ts index 4e08a02c9a..2ae7f2d95f 100644 --- a/__tests__/unit/core-magistrate-transactions/handlers/general.test.ts +++ b/__tests__/unit/core-magistrate-transactions/handlers/general.test.ts @@ -102,15 +102,13 @@ describe("BusinessRegistration", () => { configManager.set("network.pubKeyHash", 99); configManager.set("exceptions.transactions", [businessRegistrationTransaction.data.id]); - await expect( - handler.throwIfCannotBeApplied(businessRegistrationTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(businessRegistrationTransaction, senderWallet)).toResolve(); }); it("should throw on fee mismatch", async () => { businessRegistrationTransaction.data.fee = Utils.BigNumber.ZERO; await expect( - handler.throwIfCannotBeApplied(businessRegistrationTransaction, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(businessRegistrationTransaction, senderWallet), ).rejects.toThrowError(StaticFeeMismatchError); }); }); diff --git a/__tests__/unit/core-transactions/handlers/handler-registry.test.ts b/__tests__/unit/core-transactions/handlers/handler-registry.test.ts index 2da20ec3b1..28097bf7d6 100644 --- a/__tests__/unit/core-transactions/handlers/handler-registry.test.ts +++ b/__tests__/unit/core-transactions/handlers/handler-registry.test.ts @@ -81,15 +81,9 @@ class TestTransactionHandler extends TransactionHandler { return true; } - async applyToRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise {} - - async revertForRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise {} + async applyToRecipient(transaction: Interfaces.ITransaction): Promise {} + + async revertForRecipient(transaction: Interfaces.ITransaction): Promise {} } class TestWithDependencyTransactionHandler extends TransactionHandler { @@ -113,15 +107,9 @@ class TestWithDependencyTransactionHandler extends TransactionHandler { return true; } - async applyToRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise {} + async applyToRecipient(transaction: Interfaces.ITransaction): Promise {} - async revertForRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise {} + async revertForRecipient(transaction: Interfaces.ITransaction): Promise {} } beforeEach(() => { diff --git a/__tests__/unit/core-transactions/handlers/one/multi-signature-registration.test.ts b/__tests__/unit/core-transactions/handlers/one/multi-signature-registration.test.ts index 57d40041ae..86130d4ac0 100644 --- a/__tests__/unit/core-transactions/handlers/one/multi-signature-registration.test.ts +++ b/__tests__/unit/core-transactions/handlers/one/multi-signature-registration.test.ts @@ -147,18 +147,16 @@ describe("MultiSignatureRegistrationTransaction", () => { }); it("should throw", async () => { - await expect( - handler.throwIfCannotBeApplied(multiSignatureTransaction, senderWallet, walletRepository), - ).rejects.toThrow(LegacyMultiSignatureError); + await expect(handler.throwIfCannotBeApplied(multiSignatureTransaction, senderWallet)).rejects.toThrow( + LegacyMultiSignatureError, + ); }); it("should not throw defined as exception", async () => { configManager.set("network.pubKeyHash", 99); configManager.set("exceptions.transactions", [multiSignatureTransaction.id]); - await expect( - handler.throwIfCannotBeApplied(multiSignatureTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(multiSignatureTransaction, senderWallet)).toResolve(); }); }); diff --git a/__tests__/unit/core-transactions/handlers/two/delegate-registration.test.ts b/__tests__/unit/core-transactions/handlers/two/delegate-registration.test.ts index 59ddb4ce5e..17f8db0256 100644 --- a/__tests__/unit/core-transactions/handlers/two/delegate-registration.test.ts +++ b/__tests__/unit/core-transactions/handlers/two/delegate-registration.test.ts @@ -178,18 +178,12 @@ describe("DelegateRegistrationTransaction", () => { describe("throwIfCannotBeApplied", () => { it("should not throw", async () => { - await expect( - handler.throwIfCannotBeApplied(delegateRegistrationTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(delegateRegistrationTransaction, senderWallet)).toResolve(); }); it("should not throw - second sign", async () => { await expect( - handler.throwIfCannotBeApplied( - secondSignaturedDelegateRegistrationTransaction, - secondSignatureWallet, - walletRepository, - ), + handler.throwIfCannotBeApplied(secondSignaturedDelegateRegistrationTransaction, secondSignatureWallet), ).toResolve(); }); @@ -205,15 +199,15 @@ describe("DelegateRegistrationTransaction", () => { senderWallet.setAttribute("multiSignature", multiSignatureAsset); - await expect( - handler.throwIfCannotBeApplied(delegateRegistrationTransaction, senderWallet, walletRepository), - ).rejects.toThrow(NotSupportedForMultiSignatureWalletError); + await expect(handler.throwIfCannotBeApplied(delegateRegistrationTransaction, senderWallet)).rejects.toThrow( + NotSupportedForMultiSignatureWalletError, + ); }); // it("should throw if transaction does not have delegate", async () => { // delegateRegistrationTransaction.data.asset.delegate.username! = null; // - // await expect(handler.throwIfCannotBeApplied(delegateRegistrationTransaction, senderWallet, walletRepository)).rejects.toThrow( + // await expect(handler.throwIfCannotBeApplied(delegateRegistrationTransaction, senderWallet)).rejects.toThrow( // WalletNotADelegateError, // ); // }); @@ -221,9 +215,9 @@ describe("DelegateRegistrationTransaction", () => { it("should throw if wallet already registered a username", async () => { senderWallet.setAttribute("delegate", { username: "dummy" }); - await expect( - handler.throwIfCannotBeApplied(delegateRegistrationTransaction, senderWallet, walletRepository), - ).rejects.toThrow(WalletIsAlreadyDelegateError); + await expect(handler.throwIfCannotBeApplied(delegateRegistrationTransaction, senderWallet)).rejects.toThrow( + WalletIsAlreadyDelegateError, + ); }); it("should throw if another wallet already registered a username", async () => { @@ -239,17 +233,17 @@ describe("DelegateRegistrationTransaction", () => { walletRepository.index(delegateWallet); - await expect( - handler.throwIfCannotBeApplied(delegateRegistrationTransaction, senderWallet, walletRepository), - ).rejects.toThrow(WalletUsernameAlreadyRegisteredError); + await expect(handler.throwIfCannotBeApplied(delegateRegistrationTransaction, senderWallet)).rejects.toThrow( + WalletUsernameAlreadyRegisteredError, + ); }); it("should throw if wallet has insufficient funds", async () => { senderWallet.balance = Utils.BigNumber.ZERO; - await expect( - handler.throwIfCannotBeApplied(delegateRegistrationTransaction, senderWallet, walletRepository), - ).rejects.toThrow(InsufficientBalanceError); + await expect(handler.throwIfCannotBeApplied(delegateRegistrationTransaction, senderWallet)).rejects.toThrow( + InsufficientBalanceError, + ); }); }); @@ -297,7 +291,7 @@ describe("DelegateRegistrationTransaction", () => { describe("apply", () => { it("should set username", async () => { - await handler.apply(delegateRegistrationTransaction, walletRepository); + await handler.apply(delegateRegistrationTransaction); expect(senderWallet.getAttribute("delegate.username")).toBe("dummy"); }); }); @@ -306,12 +300,12 @@ describe("DelegateRegistrationTransaction", () => { it("should unset username", async () => { expect(senderWallet.hasAttribute("delegate.username")).toBeFalse(); - await handler.apply(delegateRegistrationTransaction, walletRepository); + await handler.apply(delegateRegistrationTransaction); expect(senderWallet.hasAttribute("delegate.username")).toBeTrue(); expect(senderWallet.getAttribute("delegate.username")).toBe("dummy"); - await handler.revert(delegateRegistrationTransaction, walletRepository); + await handler.revert(delegateRegistrationTransaction); expect(senderWallet.nonce.isZero()).toBeTrue(); expect(senderWallet.hasAttribute("delegate.username")).toBeFalse(); diff --git a/__tests__/unit/core-transactions/handlers/two/delegate-resignation.test.ts b/__tests__/unit/core-transactions/handlers/two/delegate-resignation.test.ts index 81d4c9d437..078b3bb048 100644 --- a/__tests__/unit/core-transactions/handlers/two/delegate-resignation.test.ts +++ b/__tests__/unit/core-transactions/handlers/two/delegate-resignation.test.ts @@ -167,20 +167,14 @@ describe("DelegateResignationTransaction", () => { describe("throwIfCannotBeApplied", () => { it("should not throw if wallet is a delegate", async () => { - await expect( - handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet)).toResolve(); }); it("should not throw if wallet is a delegate - second sign", async () => { secondSignatureWallet.setAttribute("delegate", { username: "dummy" }); walletRepository.index(secondSignatureWallet); await expect( - handler.throwIfCannotBeApplied( - secondSignatureDelegateResignationTransaction, - secondSignatureWallet, - walletRepository, - ), + handler.throwIfCannotBeApplied(secondSignatureDelegateResignationTransaction, secondSignatureWallet), ).toResolve(); }); @@ -196,44 +190,38 @@ describe("DelegateResignationTransaction", () => { anotherDelegate.setAttribute("delegate", { username: "another" }); walletRepository.index(anotherDelegate); - await expect( - handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet)).toResolve(); }); it("should throw if wallet is not a delegate", async () => { delegateWallet.forgetAttribute("delegate"); await expect( - handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet, walletRepository), + handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet), ).rejects.toThrow(WalletNotADelegateError); }); it("should throw if wallet has insufficient funds", async () => { delegateWallet.balance = Utils.BigNumber.ZERO; await expect( - handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet, walletRepository), + handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet), ).rejects.toThrow(InsufficientBalanceError); }); it("should throw if not enough delegates", async () => { - await expect( - handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet)).toResolve(); allDelegates[0].setAttribute("delegate.resigned", true); await expect( - handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet, walletRepository), + handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet), ).rejects.toThrow(NotEnoughDelegatesError); }); it("should throw if not enough delegates due to already resigned delegates", async () => { - await expect( - handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet)).toResolve(); delegateWallet.setAttribute("delegate.resigned", true); await expect( - handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet, walletRepository), + handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet), ).rejects.toThrow(WalletAlreadyResignedError); }); @@ -248,7 +236,7 @@ describe("DelegateResignationTransaction", () => { // // delegateWallet.setAttribute("delegate", {username: "another"}); // - // await expect(handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet, walletRepository)).toResolve(); + // await expect(handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet)).toResolve(); // }); }); @@ -268,24 +256,20 @@ describe("DelegateResignationTransaction", () => { describe("apply", () => { it("should apply delegate resignation", async () => { - await expect( - handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet)).toResolve(); - await handler.apply(delegateResignationTransaction, walletRepository); + await handler.apply(delegateResignationTransaction); expect(delegateWallet.getAttribute("delegate.resigned")).toBeTrue(); }); it("should fail when already resigned", async () => { - await expect( - handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet)).toResolve(); - await handler.apply(delegateResignationTransaction, walletRepository); + await handler.apply(delegateResignationTransaction); expect(delegateWallet.getAttribute("delegate.resigned")).toBeTrue(); await expect( - handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet, walletRepository), + handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet), ).rejects.toThrow(WalletAlreadyResignedError); }); @@ -293,16 +277,14 @@ describe("DelegateResignationTransaction", () => { delegateWallet.forgetAttribute("delegate"); await expect( - handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet, walletRepository), + handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet), ).rejects.toThrow(WalletNotADelegateError); }); it("should fail when voting for a resigned delegate", async () => { - await expect( - handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet)).toResolve(); - await handler.apply(delegateResignationTransaction, walletRepository); + await handler.apply(delegateResignationTransaction); expect(delegateWallet.getAttribute("delegate.resigned")).toBeTrue(); const voteTransaction = BuilderFactory.vote() @@ -311,22 +293,20 @@ describe("DelegateResignationTransaction", () => { .sign(passphrases[0]) .build(); - await expect( - voteHandler.throwIfCannotBeApplied(voteTransaction, senderWallet, walletRepository), - ).rejects.toThrow(VotedForResignedDelegateError); + await expect(voteHandler.throwIfCannotBeApplied(voteTransaction, senderWallet)).rejects.toThrow( + VotedForResignedDelegateError, + ); }); }); describe("revert", () => { it("should be ok", async () => { expect(delegateWallet.hasAttribute("delegate.resigned")).toBeFalse(); - await expect( - handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(delegateResignationTransaction, delegateWallet)).toResolve(); - await handler.apply(delegateResignationTransaction, walletRepository); + await handler.apply(delegateResignationTransaction); expect(delegateWallet.getAttribute("delegate.resigned")).toBeTrue(); - await handler.revert(delegateResignationTransaction, walletRepository); + await handler.revert(delegateResignationTransaction); expect(delegateWallet.hasAttribute("delegate.resigned")).toBeFalse(); }); }); diff --git a/__tests__/unit/core-transactions/handlers/two/general.test.ts b/__tests__/unit/core-transactions/handlers/two/general.test.ts index 6ff78f87de..8b18245ae0 100644 --- a/__tests__/unit/core-transactions/handlers/two/general.test.ts +++ b/__tests__/unit/core-transactions/handlers/two/general.test.ts @@ -113,31 +113,29 @@ describe("General Tests", () => { describe("verify", () => { it("should be verified", async () => { - await expect(handler.verify(transferTransaction, walletRepository)).resolves.toBeTrue(); + await expect(handler.verify(transferTransaction)).resolves.toBeTrue(); }); it("should be verified with multi sign", async () => { - await expect(handler.verify(multiSignatureTransferTransaction, walletRepository)).resolves.toBeTrue(); + await expect(handler.verify(multiSignatureTransferTransaction)).resolves.toBeTrue(); }); }); describe("throwIfCannotBeApplied", () => { it("should not throw", async () => { - await expect( - handler.throwIfCannotBeApplied(transferTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(transferTransaction, senderWallet)).toResolve(); }); it("should throw if wallet publicKey does not match transaction senderPublicKey", async () => { transferTransaction.data.senderPublicKey = "a".repeat(66); - await expect( - handler.throwIfCannotBeApplied(transferTransaction, senderWallet, walletRepository), - ).rejects.toThrowError(SenderWalletMismatchError); + await expect(handler.throwIfCannotBeApplied(transferTransaction, senderWallet)).rejects.toThrowError( + SenderWalletMismatchError, + ); }); it("should throw if the transaction has a second signature but wallet does not", async () => { await expect( - handler.throwIfCannotBeApplied(transactionWithSecondSignature, senderWallet, walletRepository), + handler.throwIfCannotBeApplied(transactionWithSecondSignature, senderWallet), ).rejects.toThrowError(UnexpectedSecondSignatureError); }); @@ -147,16 +145,16 @@ describe("General Tests", () => { "secondPublicKey", "038082dad560a22ea003022015e3136b21ef1ffd9f2fd50049026cbe8e2258ca17", ); - await expect( - handler.throwIfCannotBeApplied(transferTransaction, secondSigWallet, walletRepository), - ).rejects.toThrowError(UnexpectedSecondSignatureError); + await expect(handler.throwIfCannotBeApplied(transferTransaction, secondSigWallet)).rejects.toThrowError( + UnexpectedSecondSignatureError, + ); }); it("should throw if nonce is invalid", async () => { senderWallet.nonce = Utils.BigNumber.make(1); - await expect( - handler.throwIfCannotBeApplied(transferTransaction, senderWallet, walletRepository), - ).rejects.toThrowError(UnexpectedNonceError); + await expect(handler.throwIfCannotBeApplied(transferTransaction, senderWallet)).rejects.toThrowError( + UnexpectedNonceError, + ); }); it("should throw if sender has legacy multi signature", async () => { @@ -172,9 +170,9 @@ describe("General Tests", () => { }; senderWallet.setAttribute("multiSignature", multiSignatureAsset); - await expect( - handler.throwIfCannotBeApplied(transferTransaction, senderWallet, walletRepository), - ).rejects.toThrowError(LegacyMultiSignatureError); + await expect(handler.throwIfCannotBeApplied(transferTransaction, senderWallet)).rejects.toThrowError( + LegacyMultiSignatureError, + ); }); it("should throw if sender has multi signature, but indexed wallet has not", async () => { @@ -189,9 +187,9 @@ describe("General Tests", () => { const multiSigWallet = buildSenderWallet(factoryBuilder); multiSigWallet.setAttribute("multiSignature", multiSignatureAsset); - await expect( - handler.throwIfCannotBeApplied(transferTransaction, multiSigWallet, walletRepository), - ).rejects.toThrowError(UnexpectedMultiSignatureError); + await expect(handler.throwIfCannotBeApplied(transferTransaction, multiSigWallet)).rejects.toThrowError( + UnexpectedMultiSignatureError, + ); }); it("should throw if sender and transaction multi signatures does not match", async () => { @@ -206,11 +204,7 @@ describe("General Tests", () => { multiSignatureWallet.setAttribute("multiSignature", multiSignatureAsset); await expect( - handler.throwIfCannotBeApplied( - multiSignatureTransferTransaction, - multiSignatureWallet, - walletRepository, - ), + handler.throwIfCannotBeApplied(multiSignatureTransferTransaction, multiSignatureWallet), ).rejects.toThrowError(InvalidMultiSignatureError); }); @@ -220,24 +214,24 @@ describe("General Tests", () => { "0116779a98b2009b35d4003dda7628e46365f1a52068489bfbd80594770967a3949f76bc09e204eddd7d460e1e519b826c53dc6e2c9573096326dbc495050cf292", "02687bd0f4a91be39daf648a5b1e1af5ffa4a3d4319b2e38b1fc2dc206db03f542f3b26c4803e0b4c8a53ddfb6cf4533b512d71ae869d4e4ccba989c4a4222396b", ]; - await expect( - handler.throwIfCannotBeApplied(transferTransaction, senderWallet, walletRepository), - ).rejects.toThrowError(UnexpectedMultiSignatureError); + await expect(handler.throwIfCannotBeApplied(transferTransaction, senderWallet)).rejects.toThrowError( + UnexpectedMultiSignatureError, + ); }); it("should throw if wallet and transaction second signatures does not match", async () => { senderWallet.setAttribute("secondPublicKey", "invalid-public-key"); - await expect( - handler.throwIfCannotBeApplied(transactionWithSecondSignature, senderWallet, walletRepository), - ).rejects.toThrow(InvalidSecondSignatureError); + await expect(handler.throwIfCannotBeApplied(transactionWithSecondSignature, senderWallet)).rejects.toThrow( + InvalidSecondSignatureError, + ); }); it("should throw if wallet has not enough balance", async () => { // 1 arktoshi short senderWallet.balance = transferTransaction.data.amount.plus(transferTransaction.data.fee).minus(1); - await expect( - handler.throwIfCannotBeApplied(transferTransaction, senderWallet, walletRepository), - ).rejects.toThrow(InsufficientBalanceError); + await expect(handler.throwIfCannotBeApplied(transferTransaction, senderWallet)).rejects.toThrow( + InsufficientBalanceError, + ); }); it("should be true even with publicKey case mismatch", async () => { @@ -247,7 +241,7 @@ describe("General Tests", () => { const instance: Interfaces.ITransaction = Transactions.TransactionFactory.fromData( transferTransaction.data, ); - await expect(handler.throwIfCannotBeApplied(instance, senderWallet, walletRepository)).toResolve(); + await expect(handler.throwIfCannotBeApplied(instance, senderWallet)).toResolve(); }); }); @@ -319,7 +313,7 @@ describe("General Tests", () => { }); it("should resolve", async () => { - await expect(handler.apply(transferTransaction, walletRepository)).toResolve(); + await expect(handler.apply(transferTransaction)).toResolve(); }); it("should not fail due to case mismatch", async () => { @@ -330,7 +324,7 @@ describe("General Tests", () => { const senderBalance = senderWallet.balance; const recipientBalance = recipientWallet.balance; - await handler.apply(instance, walletRepository); + await handler.apply(instance); expect(senderWallet.balance).toEqual( Utils.BigNumber.make(senderBalance).minus(instance.data.amount).minus(instance.data.fee), @@ -342,7 +336,7 @@ describe("General Tests", () => { it("should resolve defined as exception", async () => { configManager.set("exceptions.transactions", [transferTransaction.id]); configManager.set("network.pubKeyHash", 99); - await expect(handler.apply(transferTransaction, walletRepository)).toResolve(); + await expect(handler.apply(transferTransaction)).toResolve(); }); it("should resolve with V1", async () => { @@ -355,35 +349,31 @@ describe("General Tests", () => { .sign(passphrases[0]) .build(); - await expect(handler.apply(transferTransaction, walletRepository)).toResolve(); + await expect(handler.apply(transferTransaction)).toResolve(); }); it("should throw with negative balance", async () => { senderWallet.balance = Utils.BigNumber.ZERO; - await expect(handler.apply(transferTransaction, walletRepository)).rejects.toThrow( - InsufficientBalanceError, - ); + await expect(handler.apply(transferTransaction)).rejects.toThrow(InsufficientBalanceError); }); it("should throw with negative balance if environment is not test", async () => { process.env.CORE_ENV === "unitest"; senderWallet.balance = Utils.BigNumber.ZERO; - await expect(handler.apply(transferTransaction, walletRepository)).rejects.toThrow( - InsufficientBalanceError, - ); + await expect(handler.apply(transferTransaction)).rejects.toThrow(InsufficientBalanceError); }); }); describe("revert", () => { it("should resolve", async () => { - await expect(handler.apply(transferTransaction, walletRepository)).toResolve(); - await expect(handler.revert(transferTransaction, walletRepository)).toResolve(); + await expect(handler.apply(transferTransaction)).toResolve(); + await expect(handler.revert(transferTransaction)).toResolve(); }); it("should throw if nonce is invalid", async () => { - await expect(handler.apply(transferTransaction, walletRepository)).toResolve(); + await expect(handler.apply(transferTransaction)).toResolve(); senderWallet.nonce = Utils.BigNumber.make(100); - await expect(handler.revert(transferTransaction, walletRepository)).rejects.toThrow(UnexpectedNonceError); + await expect(handler.revert(transferTransaction)).rejects.toThrow(UnexpectedNonceError); }); it("should not fail due to case mismatch", async () => { @@ -396,7 +386,7 @@ describe("General Tests", () => { const senderBalance = senderWallet.balance; const recipientBalance = recipientWallet.balance; - await handler.revert(instance, walletRepository); + await handler.revert(instance); expect(senderWallet.balance).toEqual( Utils.BigNumber.make(senderBalance).plus(instance.data.amount).plus(instance.data.fee), ); diff --git a/__tests__/unit/core-transactions/handlers/two/htlc-claim.test.ts b/__tests__/unit/core-transactions/handlers/two/htlc-claim.test.ts index 2311aff359..c26f997ad7 100644 --- a/__tests__/unit/core-transactions/handlers/two/htlc-claim.test.ts +++ b/__tests__/unit/core-transactions/handlers/two/htlc-claim.test.ts @@ -212,37 +212,27 @@ describe("Htlc claim", () => { describe("throwIfCannotBeApplied", () => { it("should not throw", async () => { - await expect( - handler.throwIfCannotBeApplied(htlcClaimTransaction, claimWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(htlcClaimTransaction, claimWallet)).toResolve(); }); it("should not throw - second sign", async () => { await expect( - handler.throwIfCannotBeApplied( - secondSignHtlcClaimTransaction, - secondSignatureWallet, - walletRepository, - ), + handler.throwIfCannotBeApplied(secondSignHtlcClaimTransaction, secondSignatureWallet), ).toResolve(); }); it("should not throw - multi sign", async () => { await expect( - handler.throwIfCannotBeApplied( - multiSignHtlcClaimTransaction, - multiSignatureWallet, - walletRepository, - ), + handler.throwIfCannotBeApplied(multiSignHtlcClaimTransaction, multiSignatureWallet), ).toResolve(); }); it("should throw if no wallet has a lock with associated transaction id", async () => { lockWallet.setAttribute("htlc.locks", {}); - await expect( - handler.throwIfCannotBeApplied(htlcClaimTransaction, claimWallet, walletRepository), - ).rejects.toThrow(HtlcLockTransactionNotFoundError); + await expect(handler.throwIfCannotBeApplied(htlcClaimTransaction, claimWallet)).rejects.toThrow( + HtlcLockTransactionNotFoundError, + ); }); it("should throw if secret hash does not match", async () => { @@ -255,9 +245,9 @@ describe("Htlc claim", () => { .sign(claimPassphrase) .build(); - await expect( - handler.throwIfCannotBeApplied(htlcClaimTransaction, claimWallet, walletRepository), - ).rejects.toThrow(HtlcSecretHashMismatchError); + await expect(handler.throwIfCannotBeApplied(htlcClaimTransaction, claimWallet)).rejects.toThrow( + HtlcSecretHashMismatchError, + ); }); it("should not throw if claiming wallet is not recipient of lock transaction", async () => { @@ -281,9 +271,7 @@ describe("Htlc claim", () => { .nonce("1") .build(); - await expect( - handler.throwIfCannotBeApplied(htlcClaimTransaction, dummyWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(htlcClaimTransaction, dummyWallet)).toResolve(); }); it("should throw if lock expired", async () => { @@ -326,9 +314,9 @@ describe("Htlc claim", () => { .nonce("1") .build(); - await expect( - handler.throwIfCannotBeApplied(htlcClaimTransaction, claimWallet, walletRepository), - ).rejects.toThrow(HtlcLockExpiredError); + await expect(handler.throwIfCannotBeApplied(htlcClaimTransaction, claimWallet)).rejects.toThrow( + HtlcLockExpiredError, + ); }); }); @@ -394,16 +382,14 @@ describe("Htlc claim", () => { }); it("should apply htlc claim transaction", async () => { - await expect( - handler.throwIfCannotBeApplied(htlcClaimTransaction, claimWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(htlcClaimTransaction, claimWallet)).toResolve(); const balanceBefore = claimWallet.balance; expect(lockWallet.getAttribute("htlc.locks")).toBeDefined(); expect(lockWallet.getAttribute("htlc.lockedBalance")).toEqual(htlcLockTransaction.data.amount); - await handler.apply(htlcClaimTransaction, walletRepository); + await handler.apply(htlcClaimTransaction); expect(lockWallet.getAttribute("htlc.locks")).toBeEmpty(); expect(lockWallet.getAttribute("htlc.lockedBalance")).toEqual(Utils.BigNumber.ZERO); @@ -416,7 +402,7 @@ describe("Htlc claim", () => { configManager.set("network.pubKeyHash", 99); configManager.set("exceptions.transactions", [htlcClaimTransaction.id]); - expect(handler.apply(htlcClaimTransaction, walletRepository)).toResolve(); + expect(handler.apply(htlcClaimTransaction)).toResolve(); }); it("should apply htlc claim transaction - when sender is not claim wallet", async () => { @@ -440,16 +426,14 @@ describe("Htlc claim", () => { .nonce("1") .build(); - await expect( - handler.throwIfCannotBeApplied(htlcClaimTransaction, dummyWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(htlcClaimTransaction, dummyWallet)).toResolve(); const balanceBefore = claimWallet.balance; expect(lockWallet.getAttribute("htlc.locks")).not.toBeEmpty(); expect(lockWallet.getAttribute("htlc.lockedBalance")).toEqual(htlcLockTransaction.data.amount); - await handler.apply(htlcClaimTransaction, walletRepository); + await handler.apply(htlcClaimTransaction); expect(lockWallet.getAttribute("htlc.locks")).toBeEmpty(); expect(lockWallet.getAttribute("htlc.lockedBalance")).toEqual(Utils.BigNumber.ZERO); @@ -461,15 +445,13 @@ describe("Htlc claim", () => { describe("revert", () => { it("should be ok", async () => { - await expect( - handler.throwIfCannotBeApplied(htlcClaimTransaction, claimWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(htlcClaimTransaction, claimWallet)).toResolve(); Mocks.TransactionRepository.setTransactions([Mapper.mapTransactionToModel(htlcLockTransaction)]); const balanceBefore = claimWallet.balance; - await handler.apply(htlcClaimTransaction, walletRepository); + await handler.apply(htlcClaimTransaction); expect(lockWallet.getAttribute("htlc.locks")).toBeEmpty(); expect(lockWallet.getAttribute("htlc.lockedBalance")).toEqual(Utils.BigNumber.ZERO); @@ -477,7 +459,7 @@ describe("Htlc claim", () => { balanceBefore.plus(htlcLockTransaction.data.amount).minus(htlcClaimTransaction.data.fee), ); - await handler.revert(htlcClaimTransaction, walletRepository); + await handler.revert(htlcClaimTransaction); const foundLockWallet = walletRepository.findByIndex( Contracts.State.WalletIndexes.Locks, @@ -499,15 +481,13 @@ describe("Htlc claim", () => { it("should be ok if lock transaction has vendorField", async () => { htlcLockTransaction.data.vendorField = "dummy"; - await expect( - handler.throwIfCannotBeApplied(htlcClaimTransaction, claimWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(htlcClaimTransaction, claimWallet)).toResolve(); Mocks.TransactionRepository.setTransactions([Mapper.mapTransactionToModel(htlcLockTransaction)]); const balanceBefore = claimWallet.balance; - await handler.apply(htlcClaimTransaction, walletRepository); + await handler.apply(htlcClaimTransaction); expect(lockWallet.getAttribute("htlc.locks")).toBeEmpty(); expect(lockWallet.getAttribute("htlc.lockedBalance")).toEqual(Utils.BigNumber.ZERO); @@ -515,7 +495,7 @@ describe("Htlc claim", () => { balanceBefore.plus(htlcLockTransaction.data.amount).minus(htlcClaimTransaction.data.fee), ); - await handler.revert(htlcClaimTransaction, walletRepository); + await handler.revert(htlcClaimTransaction); const foundLockWallet = walletRepository.findByIndex( Contracts.State.WalletIndexes.Locks, diff --git a/__tests__/unit/core-transactions/handlers/two/htlc-lock.test.ts b/__tests__/unit/core-transactions/handlers/two/htlc-lock.test.ts index 2430eae6dd..7479364374 100644 --- a/__tests__/unit/core-transactions/handlers/two/htlc-lock.test.ts +++ b/__tests__/unit/core-transactions/handlers/two/htlc-lock.test.ts @@ -180,37 +180,27 @@ describe("Htlc lock", () => { describe("throwIfCannotBeApplied", () => { it("should not throw", async () => { - await expect( - handler.throwIfCannotBeApplied(htlcLockTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(htlcLockTransaction, senderWallet)).toResolve(); }); it("should not throw - second sign", async () => { await expect( - handler.throwIfCannotBeApplied( - secondSignatureHtlcLockTransaction, - secondSignatureWallet, - walletRepository, - ), + handler.throwIfCannotBeApplied(secondSignatureHtlcLockTransaction, secondSignatureWallet), ).toResolve(); }); it("should not throw - multi sign", async () => { await expect( - handler.throwIfCannotBeApplied( - multiSignatureHtlcLockTransaction, - multiSignatureWallet, - walletRepository, - ), + handler.throwIfCannotBeApplied(multiSignatureHtlcLockTransaction, multiSignatureWallet), ).toResolve(); }); it("should throw if wallet has insufficient funds", async () => { senderWallet.balance = Utils.BigNumber.ZERO; - await expect( - handler.throwIfCannotBeApplied(htlcLockTransaction, senderWallet, walletRepository), - ).rejects.toThrow(InsufficientBalanceError); + await expect(handler.throwIfCannotBeApplied(htlcLockTransaction, senderWallet)).rejects.toThrow( + InsufficientBalanceError, + ); }); it("should throw if lock is already expired", async () => { @@ -222,9 +212,9 @@ describe("Htlc lock", () => { htlcLockTransaction.data.asset!.lock!.expiration.value = Crypto.Slots.getTime(); } - await expect( - handler.throwIfCannotBeApplied(htlcLockTransaction, senderWallet, walletRepository), - ).rejects.toThrow(HtlcLockExpiredError); + await expect(handler.throwIfCannotBeApplied(htlcLockTransaction, senderWallet)).rejects.toThrow( + HtlcLockExpiredError, + ); if (expirationType === Enums.HtlcLockExpirationType.BlockHeight) { htlcLockTransaction.data.asset!.lock!.expiration.value = 1000; @@ -232,9 +222,7 @@ describe("Htlc lock", () => { htlcLockTransaction.data.asset!.lock!.expiration.value = Crypto.Slots.getTime() + 10000; } - await expect( - handler.throwIfCannotBeApplied(htlcLockTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(htlcLockTransaction, senderWallet)).toResolve(); process.env.CORE_ENV = "test"; }); @@ -242,13 +230,11 @@ describe("Htlc lock", () => { describe("apply", () => { it("should apply htlc lock transaction", async () => { - await expect( - handler.throwIfCannotBeApplied(htlcLockTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(htlcLockTransaction, senderWallet)).toResolve(); const balanceBefore = senderWallet.balance; - await handler.apply(htlcLockTransaction, walletRepository); + await handler.apply(htlcLockTransaction); expect(senderWallet.getAttribute("htlc.locks", {})[htlcLockTransaction.id!]).toBeDefined(); expect(senderWallet.getAttribute("htlc.lockedBalance")).toEqual(htlcLockTransaction.data.amount); @@ -260,13 +246,11 @@ describe("Htlc lock", () => { describe("revert", () => { it("should be ok", async () => { - await expect( - handler.throwIfCannotBeApplied(htlcLockTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(htlcLockTransaction, senderWallet)).toResolve(); const balanceBefore = senderWallet.balance; - await handler.apply(htlcLockTransaction, walletRepository); + await handler.apply(htlcLockTransaction); expect(senderWallet.getAttribute("htlc.locks", {})[htlcLockTransaction.id!]).toBeDefined(); expect(senderWallet.getAttribute("htlc.lockedBalance", Utils.BigNumber.ZERO)).toEqual( @@ -276,7 +260,7 @@ describe("Htlc lock", () => { balanceBefore.minus(htlcLockTransaction.data.fee).minus(htlcLockTransaction.data.amount), ); - await handler.revert(htlcLockTransaction, walletRepository); + await handler.revert(htlcLockTransaction); expect(senderWallet.getAttribute("htlc.locks", {})[htlcLockTransaction.id!]).toBeUndefined(); expect(senderWallet.getAttribute("htlc.lockedBalance", Utils.BigNumber.ZERO)).toEqual( diff --git a/__tests__/unit/core-transactions/handlers/two/htlc-refund.test.ts b/__tests__/unit/core-transactions/handlers/two/htlc-refund.test.ts index a6b09ef745..e7821673dd 100644 --- a/__tests__/unit/core-transactions/handlers/two/htlc-refund.test.ts +++ b/__tests__/unit/core-transactions/handlers/two/htlc-refund.test.ts @@ -193,37 +193,27 @@ describe("Htlc refund", () => { describe("throwIfCannotBeApplied", () => { it("should not throw", async () => { - await expect( - handler.throwIfCannotBeApplied(htlcRefundTransaction, lockWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(htlcRefundTransaction, lockWallet)).toResolve(); }); it("should not throw - second sign", async () => { await expect( - handler.throwIfCannotBeApplied( - secondSignatureHtlcRefundTransaction, - secondSignatureWallet, - walletRepository, - ), + handler.throwIfCannotBeApplied(secondSignatureHtlcRefundTransaction, secondSignatureWallet), ).toResolve(); }); it("should not throw - multi sign", async () => { await expect( - handler.throwIfCannotBeApplied( - multiSignatureHtlcRefundTransaction, - multiSignatureWallet, - walletRepository, - ), + handler.throwIfCannotBeApplied(multiSignatureHtlcRefundTransaction, multiSignatureWallet), ).toResolve(); }); it("should throw if no wallet has a lock with associated transaction id", async () => { lockWallet.setAttribute("htlc.locks", {}); - await expect( - handler.throwIfCannotBeApplied(htlcRefundTransaction, lockWallet, walletRepository), - ).rejects.toThrow(HtlcLockTransactionNotFoundError); + await expect(handler.throwIfCannotBeApplied(htlcRefundTransaction, lockWallet)).rejects.toThrow( + HtlcLockTransactionNotFoundError, + ); }); it("should not throw if refund wallet is not sender of lock transaction", async () => { @@ -246,9 +236,7 @@ describe("Htlc refund", () => { .sign(dummyPassphrase) .build(); - await expect( - handler.throwIfCannotBeApplied(htlcRefundTransaction, dummyWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(htlcRefundTransaction, dummyWallet)).toResolve(); }); it("should throw if lock didn't expire - expiration type %i", async () => { @@ -289,9 +277,9 @@ describe("Htlc refund", () => { .sign(lockPassphrase) .build(); - await expect( - handler.throwIfCannotBeApplied(htlcRefundTransaction, lockWallet, walletRepository), - ).rejects.toThrow(HtlcLockNotExpiredError); + await expect(handler.throwIfCannotBeApplied(htlcRefundTransaction, lockWallet)).rejects.toThrow( + HtlcLockNotExpiredError, + ); }); }); @@ -350,9 +338,7 @@ describe("Htlc refund", () => { }); it("should apply htlc refund transaction", async () => { - await expect( - handler.throwIfCannotBeApplied(htlcRefundTransaction, lockWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(htlcRefundTransaction, lockWallet)).toResolve(); const balanceBefore = lockWallet.balance; @@ -360,7 +346,7 @@ describe("Htlc refund", () => { expect(lockWallet.getAttribute("htlc.locks")[htlcLockTransaction.id]).toBeDefined(); expect(lockWallet.getAttribute("htlc.lockedBalance")).toEqual(htlcLockTransaction.data.amount); - await handler.apply(htlcRefundTransaction, walletRepository); + await handler.apply(htlcRefundTransaction); expect(lockWallet.getAttribute("htlc.locks")).toBeEmpty(); expect(lockWallet.getAttribute("htlc.lockedBalance")).toEqual(Utils.BigNumber.ZERO); @@ -373,7 +359,7 @@ describe("Htlc refund", () => { configManager.set("network.pubKeyHash", 99); configManager.set("exceptions.transactions", [htlcRefundTransaction.id]); - await expect(handler.apply(htlcRefundTransaction, walletRepository)).toResolve(); + await expect(handler.apply(htlcRefundTransaction)).toResolve(); }); it("should apply htlc refund transaction - when sender is not refund wallet", async () => { @@ -396,9 +382,7 @@ describe("Htlc refund", () => { .sign(dummyPassphrase) .build(); - await expect( - handler.throwIfCannotBeApplied(htlcRefundTransaction, dummyWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(htlcRefundTransaction, dummyWallet)).toResolve(); const balanceBefore = lockWallet.balance; @@ -406,7 +390,7 @@ describe("Htlc refund", () => { expect(lockWallet.getAttribute("htlc.locks")[htlcLockTransaction.id]).toBeDefined(); expect(lockWallet.getAttribute("htlc.lockedBalance")).toEqual(htlcLockTransaction.data.amount); - await handler.apply(htlcRefundTransaction, walletRepository); + await handler.apply(htlcRefundTransaction); expect(lockWallet.getAttribute("htlc.locks")).toBeEmpty(); expect(lockWallet.getAttribute("htlc.lockedBalance")).toEqual(Utils.BigNumber.ZERO); @@ -418,14 +402,12 @@ describe("Htlc refund", () => { describe("revert", () => { it("should be ok", async () => { - await expect( - handler.throwIfCannotBeApplied(htlcRefundTransaction, lockWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(htlcRefundTransaction, lockWallet)).toResolve(); Mocks.TransactionRepository.setTransactions([Mapper.mapTransactionToModel(htlcLockTransaction)]); const balanceBefore = lockWallet.balance; - await handler.apply(htlcRefundTransaction, walletRepository); + await handler.apply(htlcRefundTransaction); // @ts-ignore expect(lockWallet.getAttribute("htlc.locks")[htlcLockTransaction.id]).toBeUndefined(); @@ -434,7 +416,7 @@ describe("Htlc refund", () => { balanceBefore.plus(htlcLockTransaction.data.amount).minus(htlcRefundTransaction.data.fee), ); - await handler.revert(htlcRefundTransaction, walletRepository); + await handler.revert(htlcRefundTransaction); const foundLockWallet = walletRepository.findByIndex( Contracts.State.WalletIndexes.Locks, @@ -454,14 +436,12 @@ describe("Htlc refund", () => { it("should be ok if lcok transaction has vendor field", async () => { htlcLockTransaction.data.vendorField = "dummy"; - await expect( - handler.throwIfCannotBeApplied(htlcRefundTransaction, lockWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(htlcRefundTransaction, lockWallet)).toResolve(); Mocks.TransactionRepository.setTransactions([Mapper.mapTransactionToModel(htlcLockTransaction)]); const balanceBefore = lockWallet.balance; - await handler.apply(htlcRefundTransaction, walletRepository); + await handler.apply(htlcRefundTransaction); // @ts-ignore expect(lockWallet.getAttribute("htlc.locks")[htlcLockTransaction.id]).toBeUndefined(); @@ -470,7 +450,7 @@ describe("Htlc refund", () => { balanceBefore.plus(htlcLockTransaction.data.amount).minus(htlcRefundTransaction.data.fee), ); - await handler.revert(htlcRefundTransaction, walletRepository); + await handler.revert(htlcRefundTransaction); const foundLockWallet = walletRepository.findByIndex( Contracts.State.WalletIndexes.Locks, diff --git a/__tests__/unit/core-transactions/handlers/two/ipfs.test.ts b/__tests__/unit/core-transactions/handlers/two/ipfs.test.ts index d572892c4c..240a0d477a 100644 --- a/__tests__/unit/core-transactions/handlers/two/ipfs.test.ts +++ b/__tests__/unit/core-transactions/handlers/two/ipfs.test.ts @@ -122,52 +122,52 @@ describe("Ipfs", () => { }); it("should not throw", async () => { - await expect(handler.throwIfCannotBeApplied(ipfsTransaction, senderWallet, walletRepository)).toResolve(); + await expect(handler.throwIfCannotBeApplied(ipfsTransaction, senderWallet)).toResolve(); }); it("should not throw defined as exception", async () => { configManager.set("network.pubKeyHash", 99); configManager.set("exceptions.transactions", [ipfsTransaction.id]); - await expect(handler.throwIfCannotBeApplied(ipfsTransaction, senderWallet, walletRepository)).toResolve(); + await expect(handler.throwIfCannotBeApplied(ipfsTransaction, senderWallet)).toResolve(); }); it("should not throw - second sign", async () => { await expect( - handler.throwIfCannotBeApplied(secondSignatureIpfsTransaction, secondSignatureWallet, walletRepository), + handler.throwIfCannotBeApplied(secondSignatureIpfsTransaction, secondSignatureWallet), ).toResolve(); }); it("should not throw - multi sign", async () => { await expect( - handler.throwIfCannotBeApplied(multiSignatureIpfsTransaction, multiSignatureWallet, walletRepository), + handler.throwIfCannotBeApplied(multiSignatureIpfsTransaction, multiSignatureWallet), ).toResolve(); }); it("should throw if wallet has insufficient funds", async () => { senderWallet.balance = Utils.BigNumber.ZERO; - await expect( - handler.throwIfCannotBeApplied(ipfsTransaction, senderWallet, walletRepository), - ).rejects.toThrow(InsufficientBalanceError); + await expect(handler.throwIfCannotBeApplied(ipfsTransaction, senderWallet)).rejects.toThrow( + InsufficientBalanceError, + ); }); it("should throw if hash already exists", async () => { - await expect(handler.throwIfCannotBeApplied(ipfsTransaction, senderWallet, walletRepository)).toResolve(); - await expect(handler.apply(ipfsTransaction, walletRepository)).toResolve(); - await expect( - handler.throwIfCannotBeApplied(ipfsTransaction, senderWallet, walletRepository), - ).rejects.toThrow(IpfsHashAlreadyExists); + await expect(handler.throwIfCannotBeApplied(ipfsTransaction, senderWallet)).toResolve(); + await expect(handler.apply(ipfsTransaction)).toResolve(); + await expect(handler.throwIfCannotBeApplied(ipfsTransaction, senderWallet)).rejects.toThrow( + IpfsHashAlreadyExists, + ); }); }); describe("apply", () => { it("should apply ipfs transaction", async () => { - await expect(handler.throwIfCannotBeApplied(ipfsTransaction, senderWallet, walletRepository)).toResolve(); + await expect(handler.throwIfCannotBeApplied(ipfsTransaction, senderWallet)).toResolve(); const balanceBefore = senderWallet.balance; - await handler.apply(ipfsTransaction, walletRepository); + await handler.apply(ipfsTransaction); expect( senderWallet.getAttribute("ipfs.hashes")[ @@ -180,11 +180,11 @@ describe("Ipfs", () => { describe("revert", () => { it("should be ok", async () => { - await expect(handler.throwIfCannotBeApplied(ipfsTransaction, senderWallet, walletRepository)).toResolve(); + await expect(handler.throwIfCannotBeApplied(ipfsTransaction, senderWallet)).toResolve(); const balanceBefore = senderWallet.balance; - await handler.apply(ipfsTransaction, walletRepository); + await handler.apply(ipfsTransaction); expect(senderWallet.balance).toEqual(balanceBefore.minus(ipfsTransaction.data.fee)); expect( @@ -193,7 +193,7 @@ describe("Ipfs", () => { ], ).toBeTrue(); - await handler.revert(ipfsTransaction, walletRepository); + await handler.revert(ipfsTransaction); expect(senderWallet.hasAttribute("ipfs")).toBeFalse(); expect(senderWallet.balance).toEqual(balanceBefore); diff --git a/__tests__/unit/core-transactions/handlers/two/multi-payment.test.ts b/__tests__/unit/core-transactions/handlers/two/multi-payment.test.ts index 466c178bb4..428da63636 100644 --- a/__tests__/unit/core-transactions/handlers/two/multi-payment.test.ts +++ b/__tests__/unit/core-transactions/handlers/two/multi-payment.test.ts @@ -126,43 +126,33 @@ describe("MultiPaymentTransaction", () => { describe("throwIfCannotBeApplied", () => { it("should not throw", async () => { - await expect( - handler.throwIfCannotBeApplied(multiPaymentTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(multiPaymentTransaction, senderWallet)).toResolve(); }); it("should not throw - second sign", async () => { await expect( - handler.throwIfCannotBeApplied( - secondSignatureMultiPaymentTransaction, - secondSignatureWallet, - walletRepository, - ), + handler.throwIfCannotBeApplied(secondSignatureMultiPaymentTransaction, secondSignatureWallet), ).toResolve(); }); it("should not throw - multi sign", async () => { await expect( - handler.throwIfCannotBeApplied( - multiSignatureMultiPaymentTransaction, - multiSignatureWallet, - walletRepository, - ), + handler.throwIfCannotBeApplied(multiSignatureMultiPaymentTransaction, multiSignatureWallet), ).toResolve(); }); it("should throw if wallet has insufficient funds", async () => { senderWallet.balance = Utils.BigNumber.ZERO; - await expect( - handler.throwIfCannotBeApplied(multiPaymentTransaction, senderWallet, walletRepository), - ).rejects.toThrow(InsufficientBalanceError); + await expect(handler.throwIfCannotBeApplied(multiPaymentTransaction, senderWallet)).rejects.toThrow( + InsufficientBalanceError, + ); }); it("should throw if wallet has insufficient funds send all payouts", async () => { senderWallet.balance = Utils.BigNumber.make(150); // short by the fee - await expect( - handler.throwIfCannotBeApplied(multiPaymentTransaction, senderWallet, walletRepository), - ).rejects.toThrow(InsufficientBalanceError); + await expect(handler.throwIfCannotBeApplied(multiPaymentTransaction, senderWallet)).rejects.toThrow( + InsufficientBalanceError, + ); }); }); @@ -174,7 +164,7 @@ describe("MultiPaymentTransaction", () => { Utils.BigNumber.ZERO, ); - await handler.apply(multiPaymentTransaction, walletRepository); + await handler.apply(multiPaymentTransaction); expect(senderWallet.balance).toEqual( Utils.BigNumber.make(senderBalance).minus(totalPaymentsAmount).minus(multiPaymentTransaction.data.fee), @@ -201,7 +191,7 @@ describe("MultiPaymentTransaction", () => { Utils.BigNumber.ZERO, ); - await handler.revert(multiPaymentTransaction, walletRepository); + await handler.revert(multiPaymentTransaction); expect(senderWallet.balance).toEqual( Utils.BigNumber.make(senderBalance).plus(totalPaymentsAmount).plus(multiPaymentTransaction.data.fee), ); diff --git a/__tests__/unit/core-transactions/handlers/two/multi-signature-registration.test.ts b/__tests__/unit/core-transactions/handlers/two/multi-signature-registration.test.ts index c72abc28a7..4198a1a5f4 100644 --- a/__tests__/unit/core-transactions/handlers/two/multi-signature-registration.test.ts +++ b/__tests__/unit/core-transactions/handlers/two/multi-signature-registration.test.ts @@ -152,36 +152,30 @@ describe("MultiSignatureRegistrationTransaction", () => { }); it("should not throw", async () => { - await expect( - handler.throwIfCannotBeApplied(multiSignatureTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(multiSignatureTransaction, senderWallet)).toResolve(); }); it("should not throw - second sign", async () => { await expect( - handler.throwIfCannotBeApplied( - secondSignatureMultiSignatureTransaction, - secondSignatureWallet, - walletRepository, - ), + handler.throwIfCannotBeApplied(secondSignatureMultiSignatureTransaction, secondSignatureWallet), ).toResolve(); }); it("should throw if the wallet already has multisignatures", async () => { recipientWallet.setAttribute("multiSignature", multiSignatureTransaction.data.asset!.multiSignature); - await expect( - handler.throwIfCannotBeApplied(multiSignatureTransaction, senderWallet, walletRepository), - ).rejects.toThrow(MultiSignatureAlreadyRegisteredError); + await expect(handler.throwIfCannotBeApplied(multiSignatureTransaction, senderWallet)).rejects.toThrow( + MultiSignatureAlreadyRegisteredError, + ); }); it("should throw if failure to verify signatures", async () => { handler.verifySignatures = jest.fn(() => false); senderWallet.forgetAttribute("multiSignature"); - await expect( - handler.throwIfCannotBeApplied(multiSignatureTransaction, senderWallet, walletRepository), - ).rejects.toThrow(InvalidMultiSignatureError); + await expect(handler.throwIfCannotBeApplied(multiSignatureTransaction, senderWallet)).rejects.toThrow( + InvalidMultiSignatureError, + ); }); it("should throw with aip11 set to false and transaction is legacy", async () => { @@ -205,9 +199,9 @@ describe("MultiSignatureRegistrationTransaction", () => { handler.verifySignatures = jest.fn().mockReturnValue(true); - await expect( - handler.throwIfCannotBeApplied(multiSignatureTransaction, senderWallet, walletRepository), - ).rejects.toThrow(UnexpectedMultiSignatureError); + await expect(handler.throwIfCannotBeApplied(multiSignatureTransaction, senderWallet)).rejects.toThrow( + UnexpectedMultiSignatureError, + ); }); // TODO: check value 02 thwors DuplicateParticipantInMultiSignatureError, 03 throws nodeError @@ -216,9 +210,7 @@ describe("MultiSignatureRegistrationTransaction", () => { "00", "02", ); - await expect( - handler.throwIfCannotBeApplied(multiSignatureTransaction, senderWallet, walletRepository), - ).rejects.toThrow( + await expect(handler.throwIfCannotBeApplied(multiSignatureTransaction, senderWallet)).rejects.toThrow( Error, // InvalidMultiSignatureError, ); @@ -231,9 +223,9 @@ describe("MultiSignatureRegistrationTransaction", () => { Transactions.Verifier.verifySecondSignature = jest.fn(() => true); multiSignatureTransaction.data.asset!.multiSignature!.publicKeys.splice(0, 2); - await expect( - handler.throwIfCannotBeApplied(multiSignatureTransaction, senderWallet, walletRepository), - ).rejects.toThrow(MultiSignatureMinimumKeysError); + await expect(handler.throwIfCannotBeApplied(multiSignatureTransaction, senderWallet)).rejects.toThrow( + MultiSignatureMinimumKeysError, + ); }); it("should throw if the number of keys does not equal the signature count", async () => { @@ -243,9 +235,9 @@ describe("MultiSignatureRegistrationTransaction", () => { Transactions.Verifier.verifySecondSignature = jest.fn(() => true); multiSignatureTransaction.data.signatures!.splice(0, 2); - await expect( - handler.throwIfCannotBeApplied(multiSignatureTransaction, senderWallet, walletRepository), - ).rejects.toThrow(MultiSignatureKeyCountMismatchError); + await expect(handler.throwIfCannotBeApplied(multiSignatureTransaction, senderWallet)).rejects.toThrow( + MultiSignatureKeyCountMismatchError, + ); }); it("should throw if the same participant provides multiple signatures", async () => { @@ -277,13 +269,11 @@ describe("MultiSignatureRegistrationTransaction", () => { Identities.PublicKey.fromMultiSignatureAsset(multiSignatureTransaction.data.asset!.multiSignature!), ); - await expect( - handler.throwIfCannotBeApplied(multiSignatureTransaction, participantWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(multiSignatureTransaction, participantWallet)).toResolve(); expect(multiSigWallet.hasMultiSignature()).toBeFalse(); - await handler.apply(multiSignatureTransaction, walletRepository); + await handler.apply(multiSignatureTransaction); expect(multiSigWallet.hasMultiSignature()).toBeTrue(); @@ -324,9 +314,9 @@ describe("MultiSignatureRegistrationTransaction", () => { senderWallet.forgetAttribute("multiSignature"); senderWallet.balance = Utils.BigNumber.ZERO; - await expect( - handler.throwIfCannotBeApplied(multiSignatureTransaction, senderWallet, walletRepository), - ).rejects.toThrow(InsufficientBalanceError); + await expect(handler.throwIfCannotBeApplied(multiSignatureTransaction, senderWallet)).rejects.toThrow( + InsufficientBalanceError, + ); }); }); @@ -354,7 +344,7 @@ describe("MultiSignatureRegistrationTransaction", () => { expect(senderWallet.balance).toEqual(Utils.BigNumber.make(100390000000)); expect(recipientWallet.balance).toEqual(Utils.BigNumber.ZERO); - await handler.apply(multiSignatureTransaction, walletRepository); + await handler.apply(multiSignatureTransaction); expect(senderWallet.balance).toEqual(Utils.BigNumber.make(98390000000)); expect(recipientWallet.balance).toEqual(Utils.BigNumber.ZERO); @@ -370,7 +360,7 @@ describe("MultiSignatureRegistrationTransaction", () => { it("should be ok", async () => { senderWallet.nonce = Utils.BigNumber.make(1); - await handler.revert(multiSignatureTransaction, walletRepository); + await handler.revert(multiSignatureTransaction); expect(senderWallet.nonce.isZero()).toBeTrue(); expect(senderWallet.hasMultiSignature()).toBeFalse(); diff --git a/__tests__/unit/core-transactions/handlers/two/second-signature-registration.test.ts b/__tests__/unit/core-transactions/handlers/two/second-signature-registration.test.ts index dbcbe6b9d4..a6af9c94f4 100644 --- a/__tests__/unit/core-transactions/handlers/two/second-signature-registration.test.ts +++ b/__tests__/unit/core-transactions/handlers/two/second-signature-registration.test.ts @@ -103,9 +103,7 @@ describe("SecondSignatureRegistrationTransaction", () => { describe("throwIfCannotBeApplied", () => { it("should not throw", async () => { - await expect( - handler.throwIfCannotBeApplied(secondSignatureTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(secondSignatureTransaction, senderWallet)).toResolve(); }); it("should throw if wallet already has a second signature", async () => { @@ -114,9 +112,9 @@ describe("SecondSignatureRegistrationTransaction", () => { "02def27da9336e7fbf63131b8d7e5c9f45b296235db035f1f4242c507398f0f21d", ); - await expect( - handler.throwIfCannotBeApplied(secondSignatureTransaction, senderWallet, walletRepository), - ).rejects.toThrow(SecondSignatureAlreadyRegisteredError); + await expect(handler.throwIfCannotBeApplied(secondSignatureTransaction, senderWallet)).rejects.toThrow( + SecondSignatureAlreadyRegisteredError, + ); }); it("should throw if wallet already has a multi signature", async () => { @@ -131,17 +129,17 @@ describe("SecondSignatureRegistrationTransaction", () => { senderWallet.setAttribute("multiSignature", multiSignatureAsset); - await expect( - handler.throwIfCannotBeApplied(secondSignatureTransaction, senderWallet, walletRepository), - ).rejects.toThrow(NotSupportedForMultiSignatureWalletError); + await expect(handler.throwIfCannotBeApplied(secondSignatureTransaction, senderWallet)).rejects.toThrow( + NotSupportedForMultiSignatureWalletError, + ); }); it("should throw if wallet has insufficient funds", async () => { senderWallet.balance = Utils.BigNumber.ZERO; - await expect( - handler.throwIfCannotBeApplied(secondSignatureTransaction, senderWallet, walletRepository), - ).rejects.toThrow(InsufficientBalanceError); + await expect(handler.throwIfCannotBeApplied(secondSignatureTransaction, senderWallet)).rejects.toThrow( + InsufficientBalanceError, + ); }); }); @@ -161,46 +159,40 @@ describe("SecondSignatureRegistrationTransaction", () => { describe("apply", () => { it("should not throw with second signature registration", async () => { - await expect( - handler.throwIfCannotBeApplied(secondSignatureTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(secondSignatureTransaction, senderWallet)).toResolve(); - await handler.apply(secondSignatureTransaction, walletRepository); + await handler.apply(secondSignatureTransaction); expect(senderWallet.getAttribute("secondPublicKey")).toBe( "02def27da9336e7fbf63131b8d7e5c9f45b296235db035f1f4242c507398f0f21d", ); }); it("should be invalid to apply a second signature registration twice", async () => { - await expect( - handler.throwIfCannotBeApplied(secondSignatureTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(secondSignatureTransaction, senderWallet)).toResolve(); - await handler.apply(secondSignatureTransaction, walletRepository); + await handler.apply(secondSignatureTransaction); expect(senderWallet.getAttribute("secondPublicKey")).toBe( "02def27da9336e7fbf63131b8d7e5c9f45b296235db035f1f4242c507398f0f21d", ); - await expect( - handler.throwIfCannotBeApplied(secondSignatureTransaction, senderWallet, walletRepository), - ).rejects.toThrow(SecondSignatureAlreadyRegisteredError); + await expect(handler.throwIfCannotBeApplied(secondSignatureTransaction, senderWallet)).rejects.toThrow( + SecondSignatureAlreadyRegisteredError, + ); }); }); describe("revert", () => { it("should be ok", async () => { expect(senderWallet.hasAttribute("secondPublicKey")).toBe(false); - await expect( - handler.throwIfCannotBeApplied(secondSignatureTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(secondSignatureTransaction, senderWallet)).toResolve(); - await handler.apply(secondSignatureTransaction, walletRepository); + await handler.apply(secondSignatureTransaction); expect(senderWallet.hasAttribute("secondPublicKey")).toBe(true); expect(senderWallet.getAttribute("secondPublicKey")).toBe( "02def27da9336e7fbf63131b8d7e5c9f45b296235db035f1f4242c507398f0f21d", ); - await handler.revert(secondSignatureTransaction, walletRepository); + await handler.revert(secondSignatureTransaction); expect(senderWallet.hasAttribute("secondPublicKey")).toBe(false); }); }); diff --git a/__tests__/unit/core-transactions/handlers/two/transfer.test.ts b/__tests__/unit/core-transactions/handlers/two/transfer.test.ts index 8229c93759..0c59aef85d 100644 --- a/__tests__/unit/core-transactions/handlers/two/transfer.test.ts +++ b/__tests__/unit/core-transactions/handlers/two/transfer.test.ts @@ -132,43 +132,33 @@ describe("TransferTransaction", () => { describe("throwIfCannotBeApplied", () => { it("should not throw", async () => { - await expect( - handler.throwIfCannotBeApplied(transferTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(transferTransaction, senderWallet)).toResolve(); }); it("should not throw - second sign", async () => { await expect( - handler.throwIfCannotBeApplied( - secondSignatureTransferTransaction, - secondSignatureWallet, - walletRepository, - ), + handler.throwIfCannotBeApplied(secondSignatureTransferTransaction, secondSignatureWallet), ).toResolve(); }); it("should not throw - multi sign", async () => { await expect( - handler.throwIfCannotBeApplied( - multiSignatureTransferTransaction, - multiSignatureWallet, - walletRepository, - ), + handler.throwIfCannotBeApplied(multiSignatureTransferTransaction, multiSignatureWallet), ).toResolve(); }); it("should throw", async () => { transferTransaction.data.senderPublicKey = "a".repeat(66); - await expect( - handler.throwIfCannotBeApplied(transferTransaction, senderWallet, walletRepository), - ).rejects.toThrow(SenderWalletMismatchError); + await expect(handler.throwIfCannotBeApplied(transferTransaction, senderWallet)).rejects.toThrow( + SenderWalletMismatchError, + ); }); it("should throw if wallet has insufficient funds for vote", async () => { senderWallet.balance = Utils.BigNumber.ZERO; - await expect( - handler.throwIfCannotBeApplied(transferTransaction, senderWallet, walletRepository), - ).rejects.toThrow(InsufficientBalanceError); + await expect(handler.throwIfCannotBeApplied(transferTransaction, senderWallet)).rejects.toThrow( + InsufficientBalanceError, + ); }); it("should throw if sender is cold wallet", async () => { @@ -189,9 +179,9 @@ describe("TransferTransaction", () => { .sign(passphrases[3]) .build(); - await expect( - handler.throwIfCannotBeApplied(transferTransaction, coldWallet, walletRepository), - ).rejects.toThrow(ColdWalletError); + await expect(handler.throwIfCannotBeApplied(transferTransaction, coldWallet)).rejects.toThrow( + ColdWalletError, + ); }); it("should not throw if recipient is cold wallet", async () => { @@ -212,9 +202,7 @@ describe("TransferTransaction", () => { .sign(passphrases[0]) .build(); - await expect( - handler.throwIfCannotBeApplied(transferTransaction, senderWallet, walletRepository), - ).toResolve(); + await expect(handler.throwIfCannotBeApplied(transferTransaction, senderWallet)).toResolve(); }); }); @@ -237,7 +225,7 @@ describe("TransferTransaction", () => { const senderBalance = senderWallet.balance; const recipientBalance = recipientWallet.balance; - await handler.apply(transferTransaction, walletRepository); + await handler.apply(transferTransaction); expect(senderWallet.balance).toEqual( Utils.BigNumber.make(senderBalance) @@ -256,7 +244,7 @@ describe("TransferTransaction", () => { const senderBalance = senderWallet.balance; const recipientBalance = recipientWallet.balance; - await handler.apply(transferTransaction, walletRepository); + await handler.apply(transferTransaction); expect(senderWallet.balance).toEqual( Utils.BigNumber.make(senderBalance) @@ -268,7 +256,7 @@ describe("TransferTransaction", () => { Utils.BigNumber.make(recipientBalance).plus(transferTransaction.data.amount), ); - await handler.revert(transferTransaction, walletRepository); + await handler.revert(transferTransaction); expect(senderWallet.balance).toEqual(Utils.BigNumber.make(senderBalance)); diff --git a/__tests__/unit/core-transactions/handlers/two/vote.test.ts b/__tests__/unit/core-transactions/handlers/two/vote.test.ts index f94b7e2a5d..c142f21ca3 100644 --- a/__tests__/unit/core-transactions/handlers/two/vote.test.ts +++ b/__tests__/unit/core-transactions/handlers/two/vote.test.ts @@ -195,85 +195,79 @@ describe("VoteTransaction", () => { describe("throwIfCannotBeApplied", () => { it("should not throw if the vote is valid and the wallet has not voted", async () => { - await expect(handler.throwIfCannotBeApplied(voteTransaction, senderWallet, walletRepository)).toResolve(); + await expect(handler.throwIfCannotBeApplied(voteTransaction, senderWallet)).toResolve(); }); it("should not throw - second sign vote", async () => { await expect( - handler.throwIfCannotBeApplied(secondSignatureVoteTransaction, secondSignatureWallet, walletRepository), + handler.throwIfCannotBeApplied(secondSignatureVoteTransaction, secondSignatureWallet), ).toResolve(); }); it("should not throw - multi sign vote", async () => { await expect( - handler.throwIfCannotBeApplied(multiSignatureVoteTransaction, multiSignatureWallet, walletRepository), + handler.throwIfCannotBeApplied(multiSignatureVoteTransaction, multiSignatureWallet), ).toResolve(); }); it("should not throw if the unvote is valid and the wallet has voted", async () => { senderWallet.setAttribute("vote", delegateWallet.publicKey); - await expect(handler.throwIfCannotBeApplied(unvoteTransaction, senderWallet, walletRepository)).toResolve(); + await expect(handler.throwIfCannotBeApplied(unvoteTransaction, senderWallet)).toResolve(); }); it("should not throw - second sign unvote", async () => { secondSignatureWallet.setAttribute("vote", delegateWallet.publicKey); await expect( - handler.throwIfCannotBeApplied( - secondSignatureUnvoteTransaction, - secondSignatureWallet, - walletRepository, - ), + handler.throwIfCannotBeApplied(secondSignatureUnvoteTransaction, secondSignatureWallet), ).toResolve(); }); it("should not throw - multi sign unvote", async () => { multiSignatureWallet.setAttribute("vote", delegateWallet.publicKey); await expect( - handler.throwIfCannotBeApplied(multiSignatureUnvoteTransaction, multiSignatureWallet, walletRepository), + handler.throwIfCannotBeApplied(multiSignatureUnvoteTransaction, multiSignatureWallet), ).toResolve(); }); it("should throw if wallet has already voted", async () => { senderWallet.setAttribute("vote", delegateWallet.publicKey); - await expect( - handler.throwIfCannotBeApplied(voteTransaction, senderWallet, walletRepository), - ).rejects.toThrow(AlreadyVotedError); + await expect(handler.throwIfCannotBeApplied(voteTransaction, senderWallet)).rejects.toThrow( + AlreadyVotedError, + ); }); it("should throw if vote for non delegate wallet", async () => { delegateWallet.forgetAttribute("delegate"); walletRepository.index(delegateWallet); - await expect( - handler.throwIfCannotBeApplied(voteTransaction, senderWallet, walletRepository), - ).rejects.toThrow(VotedForNonDelegateError); + await expect(handler.throwIfCannotBeApplied(voteTransaction, senderWallet)).rejects.toThrow( + VotedForNonDelegateError, + ); }); it("should throw if the asset public key differs from the currently voted one", async () => { senderWallet.setAttribute("vote", "a310ad026647eed112d1a46145eed58b8c19c67c505a67f1199361a511ce7860c0"); - await expect( - handler.throwIfCannotBeApplied(unvoteTransaction, senderWallet, walletRepository), - ).rejects.toThrow(UnvoteMismatchError); + await expect(handler.throwIfCannotBeApplied(unvoteTransaction, senderWallet)).rejects.toThrow( + UnvoteMismatchError, + ); }); it("should throw if unvoting a non-voted wallet", async () => { - await expect( - handler.throwIfCannotBeApplied(unvoteTransaction, senderWallet, walletRepository), - ).rejects.toThrow(NoVoteError); + await expect(handler.throwIfCannotBeApplied(unvoteTransaction, senderWallet)).rejects.toThrow(NoVoteError); }); it("should throw if wallet has insufficient funds for vote", async () => { senderWallet.balance = Utils.BigNumber.ZERO; - await expect( - handler.throwIfCannotBeApplied(voteTransaction, senderWallet, walletRepository), - ).rejects.toThrow(InsufficientBalanceError); + await expect(handler.throwIfCannotBeApplied(voteTransaction, senderWallet)).rejects.toThrow( + InsufficientBalanceError, + ); }); it("should not if wallet has insufficient funds for unvote", async () => { senderWallet.balance = Utils.BigNumber.ZERO; senderWallet.setAttribute("vote", delegateWallet.publicKey); - await expect( - handler.throwIfCannotBeApplied(unvoteTransaction, senderWallet, walletRepository), - ).rejects.toThrow(InsufficientBalanceError); + await expect(handler.throwIfCannotBeApplied(unvoteTransaction, senderWallet)).rejects.toThrow( + InsufficientBalanceError, + ); }); }); @@ -296,7 +290,7 @@ describe("VoteTransaction", () => { it("should be ok", async () => { expect(senderWallet.hasAttribute("vote")).toBeFalse(); - await handler.apply(voteTransaction, walletRepository); + await handler.apply(voteTransaction); expect(senderWallet.getAttribute("vote")).not.toBeUndefined(); }); @@ -305,7 +299,7 @@ describe("VoteTransaction", () => { expect(senderWallet.getAttribute("vote")).not.toBeUndefined(); - await expect(handler.apply(voteTransaction, walletRepository)).rejects.toThrow(AlreadyVotedError); + await expect(handler.apply(voteTransaction)).rejects.toThrow(AlreadyVotedError); expect(senderWallet.getAttribute("vote")).not.toBeUndefined(); }); @@ -317,7 +311,7 @@ describe("VoteTransaction", () => { expect(senderWallet.getAttribute("vote")).not.toBeUndefined(); - await handler.apply(unvoteTransaction, walletRepository); + await handler.apply(unvoteTransaction); expect(senderWallet.hasAttribute("vote")).toBeFalse(); }); @@ -332,7 +326,7 @@ describe("VoteTransaction", () => { expect(senderWallet.getAttribute("vote")).not.toBeUndefined(); - await handler.revert(voteTransaction, walletRepository); + await handler.revert(voteTransaction); expect(senderWallet.nonce.isZero()).toBeTrue(); expect(senderWallet.hasAttribute("vote")).toBeFalse(); @@ -345,7 +339,7 @@ describe("VoteTransaction", () => { expect(senderWallet.hasAttribute("vote")).toBeFalse(); - await handler.revert(unvoteTransaction, walletRepository); + await handler.revert(unvoteTransaction); expect(senderWallet.nonce.isZero()).toBeTrue(); expect(senderWallet.getAttribute("vote")).toBe(delegateWallet.publicKey); diff --git a/packages/core-magistrate-transactions/src/handlers/bridgechain-registration.ts b/packages/core-magistrate-transactions/src/handlers/bridgechain-registration.ts index 4c76053394..ba0e61b9ee 100644 --- a/packages/core-magistrate-transactions/src/handlers/bridgechain-registration.ts +++ b/packages/core-magistrate-transactions/src/handlers/bridgechain-registration.ts @@ -61,7 +61,6 @@ export class BridgechainRegistrationTransactionHandler extends MagistrateTransac public async throwIfCannotBeApplied( transaction: Interfaces.ITransaction, wallet: Contracts.State.Wallet, - customWalletRepository?: Contracts.State.WalletRepository, ): Promise { if (Utils.isException(transaction.data.id)) { return; @@ -102,8 +101,7 @@ export class BridgechainRegistrationTransactionHandler extends MagistrateTransac } } - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; - for (const wallet of walletRepository.getIndex(MagistrateIndex.Businesses).values()) { + for (const wallet of this.walletRepository.getIndex(MagistrateIndex.Businesses).values()) { if (wallet.hasAttribute("business.bridgechains")) { const bridgechainValues: IBridgechainWalletAttributes[] = Object.values( wallet.getAttribute("business.bridgechains"), @@ -122,24 +120,19 @@ export class BridgechainRegistrationTransactionHandler extends MagistrateTransac } } - return super.throwIfCannotBeApplied(transaction, wallet, customWalletRepository); + return super.throwIfCannotBeApplied(transaction, wallet); } public emitEvents(transaction: Interfaces.ITransaction, emitter: Contracts.Kernel.EventDispatcher): void { emitter.dispatch(MagistrateApplicationEvents.BridgechainRegistered, transaction.data); } - public async applyToSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.applyToSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async applyToSender(transaction: Interfaces.ITransaction): Promise { + await super.applyToSender(transaction); AppUtils.assert.defined(transaction.data.senderPublicKey); - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); const businessAttributes: IBusinessWalletAttributes = sender.getAttribute( "business", @@ -159,20 +152,15 @@ export class BridgechainRegistrationTransactionHandler extends MagistrateTransac }; sender.setAttribute("business", businessAttributes); - walletRepository.index(sender); + this.walletRepository.index(sender); } - public async revertForSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.revertForSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async revertForSender(transaction: Interfaces.ITransaction): Promise { + await super.revertForSender(transaction); AppUtils.assert.defined(transaction.data.senderPublicKey); - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); const businessAttributes: IBusinessWalletAttributes = sender.getAttribute( "business", @@ -186,18 +174,16 @@ export class BridgechainRegistrationTransactionHandler extends MagistrateTransac delete businessAttributes.bridgechains[bridgechainId]; - walletRepository.index(sender); + this.walletRepository.index(sender); } public async applyToRecipient( transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, // tslint:disable-next-line: no-empty ): Promise {} public async revertForRecipient( transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, // tslint:disable-next-line:no-empty ): Promise {} } diff --git a/packages/core-magistrate-transactions/src/handlers/bridgechain-resignation.ts b/packages/core-magistrate-transactions/src/handlers/bridgechain-resignation.ts index cbd497e14d..a3ac7bc1b1 100644 --- a/packages/core-magistrate-transactions/src/handlers/bridgechain-resignation.ts +++ b/packages/core-magistrate-transactions/src/handlers/bridgechain-resignation.ts @@ -56,7 +56,6 @@ export class BridgechainResignationTransactionHandler extends MagistrateTransact public async throwIfCannotBeApplied( transaction: Interfaces.ITransaction, wallet: Contracts.State.Wallet, - customWalletRepository?: Contracts.State.WalletRepository, ): Promise { if (!wallet.hasAttribute("business")) { throw new WalletIsNotBusinessError(); @@ -92,7 +91,7 @@ export class BridgechainResignationTransactionHandler extends MagistrateTransact throw new BridgechainIsResignedError(); } - return super.throwIfCannotBeApplied(transaction, wallet, customWalletRepository); + return super.throwIfCannotBeApplied(transaction, wallet); } public emitEvents(transaction: Interfaces.ITransaction, emitter: Contracts.Kernel.EventDispatcher): void { @@ -118,17 +117,12 @@ export class BridgechainResignationTransactionHandler extends MagistrateTransact } } - public async applyToSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.applyToSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async applyToSender(transaction: Interfaces.ITransaction): Promise { + await super.applyToSender(transaction); Utils.assert.defined(transaction.data.senderPublicKey); - const businessAttributes: IBusinessWalletAttributes = walletRepository + const businessAttributes: IBusinessWalletAttributes = this.walletRepository .findByPublicKey(transaction.data.senderPublicKey) .getAttribute("business"); @@ -145,17 +139,12 @@ export class BridgechainResignationTransactionHandler extends MagistrateTransact businessAttributes.bridgechains[bridgechainResignation.bridgechainId].resigned = true; } - public async revertForSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.revertForSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async revertForSender(transaction: Interfaces.ITransaction): Promise { + await super.revertForSender(transaction); Utils.assert.defined(transaction.data.senderPublicKey); - const businessAttributes: IBusinessWalletAttributes = walletRepository + const businessAttributes: IBusinessWalletAttributes = this.walletRepository .findByPublicKey(transaction.data.senderPublicKey) .getAttribute("business"); @@ -173,13 +162,11 @@ export class BridgechainResignationTransactionHandler extends MagistrateTransact public async applyToRecipient( transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, // tslint:disable-next-line: no-empty ): Promise {} public async revertForRecipient( transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, // tslint:disable-next-line:no-empty ): Promise {} } diff --git a/packages/core-magistrate-transactions/src/handlers/bridgechain-update.ts b/packages/core-magistrate-transactions/src/handlers/bridgechain-update.ts index a3c883daec..e4ccc5dec3 100644 --- a/packages/core-magistrate-transactions/src/handlers/bridgechain-update.ts +++ b/packages/core-magistrate-transactions/src/handlers/bridgechain-update.ts @@ -67,7 +67,6 @@ export class BridgechainUpdateTransactionHandler extends MagistrateTransactionHa public async throwIfCannotBeApplied( transaction: Interfaces.ITransaction, wallet: Contracts.State.Wallet, - customWalletRepository?: Contracts.State.WalletRepository, ): Promise { if (!wallet.hasAttribute("business")) { throw new BusinessIsNotRegisteredError(); @@ -109,7 +108,7 @@ export class BridgechainUpdateTransactionHandler extends MagistrateTransactionHa } } - return super.throwIfCannotBeApplied(transaction, wallet, customWalletRepository); + return super.throwIfCannotBeApplied(transaction, wallet); } public emitEvents(transaction: Interfaces.ITransaction, emitter: Contracts.Kernel.EventDispatcher): void { @@ -135,17 +134,12 @@ export class BridgechainUpdateTransactionHandler extends MagistrateTransactionHa } } - public async applyToSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.applyToSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async applyToSender(transaction: Interfaces.ITransaction): Promise { + await super.applyToSender(transaction); Utils.assert.defined(transaction.data.senderPublicKey); - const wallet: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const wallet: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); const businessAttributes: IBusinessWalletAttributes = wallet.getAttribute( "business", @@ -168,16 +162,11 @@ export class BridgechainUpdateTransactionHandler extends MagistrateTransactionHa ...shallowCloneBridgechainUpdate, }; - walletRepository.index(wallet); + this.walletRepository.index(wallet); } - public async revertForSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.revertForSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async revertForSender(transaction: Interfaces.ITransaction): Promise { + await super.revertForSender(transaction); Utils.assert.defined(transaction.data.senderPublicKey); Utils.assert.defined(transaction.data.asset); @@ -185,7 +174,7 @@ export class BridgechainUpdateTransactionHandler extends MagistrateTransactionHa // Here we have to "replay" all bridgechain registration and update transactions for this bridgechain id // (except the current one being reverted) to rebuild previous wallet state. - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); Utils.assert.defined(sender.publicKey); const businessAttributes: IBusinessWalletAttributes = sender.getAttribute( @@ -220,18 +209,16 @@ export class BridgechainUpdateTransactionHandler extends MagistrateTransactionHa Utils.assert.defined(businessAttributes.bridgechains); businessAttributes.bridgechains[bridgechainId] = { bridgechainAsset }; - walletRepository.index(sender); + this.walletRepository.index(sender); } public async applyToRecipient( transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, // tslint:disable-next-line: no-empty ): Promise {} public async revertForRecipient( transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, // tslint:disable-next-line:no-empty ): Promise {} } diff --git a/packages/core-magistrate-transactions/src/handlers/business-registration.ts b/packages/core-magistrate-transactions/src/handlers/business-registration.ts index 7fd744c936..3f755ab725 100644 --- a/packages/core-magistrate-transactions/src/handlers/business-registration.ts +++ b/packages/core-magistrate-transactions/src/handlers/business-registration.ts @@ -54,13 +54,12 @@ export class BusinessRegistrationTransactionHandler extends MagistrateTransactio public async throwIfCannotBeApplied( transaction: Interfaces.ITransaction, wallet: Contracts.State.Wallet, - customWalletRepository?: Contracts.State.WalletRepository, ): Promise { if (wallet.hasAttribute("business")) { throw new BusinessAlreadyRegisteredError(); } - return super.throwIfCannotBeApplied(transaction, wallet, customWalletRepository); + return super.throwIfCannotBeApplied(transaction, wallet); } public emitEvents(transaction: Interfaces.ITransaction, emitter: Contracts.Kernel.EventDispatcher): void { @@ -84,17 +83,12 @@ export class BusinessRegistrationTransactionHandler extends MagistrateTransactio } } - public async applyToSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.applyToSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async applyToSender(transaction: Interfaces.ITransaction): Promise { + await super.applyToSender(transaction); AppUtils.assert.defined(transaction.data.senderPublicKey); - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); AppUtils.assert.defined( transaction.data.asset?.businessRegistration, @@ -104,37 +98,30 @@ export class BusinessRegistrationTransactionHandler extends MagistrateTransactio businessAsset: transaction.data.asset.businessRegistration, }); - walletRepository.index(sender); + this.walletRepository.index(sender); } - public async revertForSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.revertForSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async revertForSender(transaction: Interfaces.ITransaction): Promise { + await super.revertForSender(transaction); AppUtils.assert.defined(transaction.data.senderPublicKey); - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); sender.forgetAttribute("business"); - walletRepository.forgetByIndex(MagistrateIndex.Businesses, transaction.data.senderPublicKey); + this.walletRepository.forgetByIndex(MagistrateIndex.Businesses, transaction.data.senderPublicKey); - walletRepository.index(sender); + this.walletRepository.index(sender); } public async applyToRecipient( transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, // tslint:disable-next-line: no-empty ): Promise {} public async revertForRecipient( transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, // tslint:disable-next-line:no-empty ): Promise {} } diff --git a/packages/core-magistrate-transactions/src/handlers/business-resignation.ts b/packages/core-magistrate-transactions/src/handlers/business-resignation.ts index 83653cda0e..e5e688e330 100644 --- a/packages/core-magistrate-transactions/src/handlers/business-resignation.ts +++ b/packages/core-magistrate-transactions/src/handlers/business-resignation.ts @@ -41,7 +41,6 @@ export class BusinessResignationTransactionHandler extends MagistrateTransaction public async throwIfCannotBeApplied( transaction: Interfaces.ITransaction, wallet: Contracts.State.Wallet, - customWalletRepository?: Contracts.State.WalletRepository, ): Promise { if (!wallet.hasAttribute("business")) { throw new BusinessIsNotRegisteredError(); @@ -51,7 +50,7 @@ export class BusinessResignationTransactionHandler extends MagistrateTransaction throw new BusinessIsResignedError(); } - return super.throwIfCannotBeApplied(transaction, wallet, customWalletRepository); + return super.throwIfCannotBeApplied(transaction, wallet); } public emitEvents(transaction: Interfaces.ITransaction, emitter: Contracts.Kernel.EventDispatcher): void { @@ -75,47 +74,35 @@ export class BusinessResignationTransactionHandler extends MagistrateTransaction } } - public async applyToSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.applyToSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async applyToSender(transaction: Interfaces.ITransaction): Promise { + await super.applyToSender(transaction); AppUtils.assert.defined(transaction.data.senderPublicKey); - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); sender.setAttribute("business.resigned", true); - walletRepository.index(sender); + this.walletRepository.index(sender); } - public async revertForSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.revertForSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async revertForSender(transaction: Interfaces.ITransaction): Promise { + await super.revertForSender(transaction); AppUtils.assert.defined(transaction.data.senderPublicKey); - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); sender.forgetAttribute("business.resigned"); - walletRepository.index(sender); + this.walletRepository.index(sender); } public async applyToRecipient( transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, // tslint:disable-next-line: no-empty ): Promise {} public async revertForRecipient( transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, // tslint:disable-next-line:no-empty ): Promise {} } diff --git a/packages/core-magistrate-transactions/src/handlers/business-update.ts b/packages/core-magistrate-transactions/src/handlers/business-update.ts index f460974706..370fea3410 100644 --- a/packages/core-magistrate-transactions/src/handlers/business-update.ts +++ b/packages/core-magistrate-transactions/src/handlers/business-update.ts @@ -56,7 +56,6 @@ export class BusinessUpdateTransactionHandler extends MagistrateTransactionHandl public async throwIfCannotBeApplied( transaction: Interfaces.ITransaction, wallet: Contracts.State.Wallet, - customWalletRepository?: Contracts.State.WalletRepository, ): Promise { if (!wallet.hasAttribute("business")) { throw new BusinessIsNotRegisteredError(); @@ -66,7 +65,7 @@ export class BusinessUpdateTransactionHandler extends MagistrateTransactionHandl throw new BusinessIsResignedError(); } - return super.throwIfCannotBeApplied(transaction, wallet, customWalletRepository); + return super.throwIfCannotBeApplied(transaction, wallet); } public emitEvents(transaction: Interfaces.ITransaction, emitter: Contracts.Kernel.EventDispatcher): void { @@ -90,17 +89,12 @@ export class BusinessUpdateTransactionHandler extends MagistrateTransactionHandl } } - public async applyToSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.applyToSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async applyToSender(transaction: Interfaces.ITransaction): Promise { + await super.applyToSender(transaction); Utils.assert.defined(transaction.data.senderPublicKey); - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); const businessWalletAsset: MagistrateInterfaces.IBusinessRegistrationAsset = sender.getAttribute< IBusinessWalletAttributes @@ -116,20 +110,15 @@ export class BusinessUpdateTransactionHandler extends MagistrateTransactionHandl }); } - public async revertForSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.revertForSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async revertForSender(transaction: Interfaces.ITransaction): Promise { + await super.revertForSender(transaction); Utils.assert.defined(transaction.data.senderPublicKey); Utils.assert.defined(transaction.data.typeGroup); // Here we have to "replay" all business registration and update transactions // (except the current one being reverted) to rebuild previous wallet state. - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); Utils.assert.defined(sender.publicKey); const businessTransactions = await this.transactionHistoryService.findManyByCriteria([ @@ -158,13 +147,11 @@ export class BusinessUpdateTransactionHandler extends MagistrateTransactionHandl public async applyToRecipient( transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, // tslint:disable-next-line: no-empty ): Promise {} public async revertForRecipient( transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, // tslint:disable-next-line:no-empty ): Promise {} } diff --git a/packages/core-magistrate-transactions/src/handlers/entity.ts b/packages/core-magistrate-transactions/src/handlers/entity.ts index 2161c1d501..57dfea7832 100644 --- a/packages/core-magistrate-transactions/src/handlers/entity.ts +++ b/packages/core-magistrate-transactions/src/handlers/entity.ts @@ -68,7 +68,6 @@ export class EntityTransactionHandler extends Handlers.TransactionHandler { public async throwIfCannotBeApplied( transaction: CryptoInterfaces.ITransaction, wallet: Contracts.State.Wallet, - customWalletRepository?: Contracts.State.WalletRepository, ): Promise { if (Utils.isException(transaction.data.id)) { return; @@ -79,56 +78,43 @@ export class EntityTransactionHandler extends Handlers.TransactionHandler { throw new StaticFeeMismatchError(staticFee.toFixed()); } - super.throwIfCannotBeApplied(transaction, wallet, customWalletRepository); - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + super.throwIfCannotBeApplied(transaction, wallet); const handler = this.getHandler(transaction); if (!handler) { throw new EntityWrongSubTypeError(); // wrong sub type / type association } - return this.getHandler(transaction)!.throwIfCannotBeApplied(transaction, wallet, walletRepository); + return this.getHandler(transaction)!.throwIfCannotBeApplied(transaction, wallet, this.walletRepository); } public emitEvents(transaction: Interfaces.ITransaction, emitter: Contracts.Kernel.EventDispatcher): void { return this.getHandler(transaction)!.emitEvents(transaction, emitter); } - public async applyToSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.applyToSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async applyToSender(transaction: Interfaces.ITransaction): Promise { + await super.applyToSender(transaction); - return this.getHandler(transaction)!.applyToSender(transaction, walletRepository); + return this.getHandler(transaction)!.applyToSender(transaction, this.walletRepository); } - public async revertForSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.revertForSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async revertForSender(transaction: Interfaces.ITransaction): Promise { + await super.revertForSender(transaction); return this.getHandler(transaction)!.revertForSender( transaction, - walletRepository, + this.walletRepository, this.transactionHistoryService, ); } public async applyToRecipient( transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, // tslint:disable-next-line: no-empty ): Promise {} public async revertForRecipient( transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, // tslint:disable-next-line:no-empty ): Promise {} diff --git a/packages/core-magistrate-transactions/src/handlers/magistrate-handler.ts b/packages/core-magistrate-transactions/src/handlers/magistrate-handler.ts index 20f244c0ac..78e7cf4950 100644 --- a/packages/core-magistrate-transactions/src/handlers/magistrate-handler.ts +++ b/packages/core-magistrate-transactions/src/handlers/magistrate-handler.ts @@ -16,7 +16,6 @@ export abstract class MagistrateTransactionHandler extends Handlers.TransactionH public async throwIfCannotBeApplied( transaction: CryptoInterfaces.ITransaction, wallet: Contracts.State.Wallet, - customWalletRepository?: Contracts.State.WalletRepository, ): Promise { if (Utils.isException(transaction.data.id)) { return; @@ -27,6 +26,6 @@ export abstract class MagistrateTransactionHandler extends Handlers.TransactionH throw new StaticFeeMismatchError(staticFee.toFixed()); } - return super.throwIfCannotBeApplied(transaction, wallet, customWalletRepository); + return super.throwIfCannotBeApplied(transaction, wallet); } } diff --git a/packages/core-transactions/src/handlers/one/delegate-registration.ts b/packages/core-transactions/src/handlers/one/delegate-registration.ts index ca5e50cda7..ae673bd625 100644 --- a/packages/core-transactions/src/handlers/one/delegate-registration.ts +++ b/packages/core-transactions/src/handlers/one/delegate-registration.ts @@ -48,15 +48,12 @@ export class DelegateRegistrationTransactionHandler extends TransactionHandler { public async throwIfCannotBeApplied( transaction: Interfaces.ITransaction, wallet: Contracts.State.Wallet, - customWalletRepository?: Contracts.State.WalletRepository, ): Promise { - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; - const { data }: Interfaces.ITransaction = transaction; AppUtils.assert.defined(data.senderPublicKey); - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(data.senderPublicKey); if (sender.hasMultiSignature()) { throw new NotSupportedForMultiSignatureWalletError(); @@ -70,11 +67,11 @@ export class DelegateRegistrationTransactionHandler extends TransactionHandler { throw new WalletIsAlreadyDelegateError(); } - if (walletRepository.hasByUsername(username)) { + if (this.walletRepository.hasByUsername(username)) { throw new WalletUsernameAlreadyRegisteredError(username); } - return super.throwIfCannotBeApplied(transaction, wallet, customWalletRepository); + return super.throwIfCannotBeApplied(transaction, wallet); } public emitEvents(transaction: Interfaces.ITransaction, emitter: Contracts.Kernel.EventDispatcher): void { @@ -114,17 +111,12 @@ export class DelegateRegistrationTransactionHandler extends TransactionHandler { } } - public async applyToSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.applyToSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async applyToSender(transaction: Interfaces.ITransaction): Promise { + await super.applyToSender(transaction); AppUtils.assert.defined(transaction.data.senderPublicKey); - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); AppUtils.assert.defined(transaction.data.asset?.delegate?.username); @@ -137,33 +129,22 @@ export class DelegateRegistrationTransactionHandler extends TransactionHandler { round: 0, }); - walletRepository.index(sender); + this.walletRepository.index(sender); } - public async revertForSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.revertForSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async revertForSender(transaction: Interfaces.ITransaction): Promise { + await super.revertForSender(transaction); AppUtils.assert.defined(transaction.data.senderPublicKey); - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); - walletRepository.forgetByUsername(sender.getAttribute("delegate.username")); + this.walletRepository.forgetByUsername(sender.getAttribute("delegate.username")); sender.forgetAttribute("delegate"); } - public async applyToRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise {} + public async applyToRecipient(transaction: Interfaces.ITransaction): Promise {} - public async revertForRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise {} + public async revertForRecipient(transaction: Interfaces.ITransaction): Promise {} } diff --git a/packages/core-transactions/src/handlers/one/multi-signature-registration.ts b/packages/core-transactions/src/handlers/one/multi-signature-registration.ts index 1835df218a..e75c777977 100644 --- a/packages/core-transactions/src/handlers/one/multi-signature-registration.ts +++ b/packages/core-transactions/src/handlers/one/multi-signature-registration.ts @@ -47,7 +47,6 @@ export class MultiSignatureRegistrationTransactionHandler extends TransactionHan public async throwIfCannotBeApplied( transaction: Interfaces.ITransaction, wallet: Contracts.State.Wallet, - customWalletRepository?: Contracts.State.WalletRepository, ): Promise { const { data }: Interfaces.ITransaction = transaction; @@ -66,13 +65,7 @@ export class MultiSignatureRegistrationTransactionHandler extends TransactionHan ); } - public async applyToRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository | undefined, - ): Promise {} + public async applyToRecipient(transaction: Interfaces.ITransaction): Promise {} - public async revertForRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository | undefined, - ): Promise {} + public async revertForRecipient(transaction: Interfaces.ITransaction): Promise {} } diff --git a/packages/core-transactions/src/handlers/one/second-signature-registration.ts b/packages/core-transactions/src/handlers/one/second-signature-registration.ts index 5c31c1ed7b..60e0155d7d 100644 --- a/packages/core-transactions/src/handlers/one/second-signature-registration.ts +++ b/packages/core-transactions/src/handlers/one/second-signature-registration.ts @@ -32,23 +32,22 @@ export class SecondSignatureRegistrationTransactionHandler extends TransactionHa public async throwIfCannotBeApplied( transaction: Interfaces.ITransaction, wallet: Contracts.State.Wallet, - customWalletRepository?: Contracts.State.WalletRepository, ): Promise { if (wallet.hasSecondSignature()) { throw new SecondSignatureAlreadyRegisteredError(); } - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; - Utils.assert.defined(transaction.data.senderPublicKey); - const senderWallet: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const senderWallet: Contracts.State.Wallet = this.walletRepository.findByPublicKey( + transaction.data.senderPublicKey, + ); if (senderWallet.hasMultiSignature()) { throw new NotSupportedForMultiSignatureWalletError(); } - return super.throwIfCannotBeApplied(transaction, wallet, customWalletRepository); + return super.throwIfCannotBeApplied(transaction, wallet); } public async throwIfCannotEnterPool(transaction: Interfaces.ITransaction): Promise { @@ -68,43 +67,29 @@ export class SecondSignatureRegistrationTransactionHandler extends TransactionHa } } - public async applyToSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.applyToSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async applyToSender(transaction: Interfaces.ITransaction): Promise { + await super.applyToSender(transaction); Utils.assert.defined(transaction.data.senderPublicKey); - const senderWallet: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const senderWallet: Contracts.State.Wallet = this.walletRepository.findByPublicKey( + transaction.data.senderPublicKey, + ); Utils.assert.defined(transaction.data.asset?.signature?.publicKey); senderWallet.setAttribute("secondPublicKey", transaction.data.asset.signature.publicKey); } - public async revertForSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.revertForSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async revertForSender(transaction: Interfaces.ITransaction): Promise { + await super.revertForSender(transaction); Utils.assert.defined(transaction.data.senderPublicKey); - walletRepository.findByPublicKey(transaction.data.senderPublicKey).forgetAttribute("secondPublicKey"); + this.walletRepository.findByPublicKey(transaction.data.senderPublicKey).forgetAttribute("secondPublicKey"); } - public async applyToRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise {} + public async applyToRecipient(transaction: Interfaces.ITransaction): Promise {} - public async revertForRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise {} + public async revertForRecipient(transaction: Interfaces.ITransaction): Promise {} } diff --git a/packages/core-transactions/src/handlers/one/transfer.ts b/packages/core-transactions/src/handlers/one/transfer.ts index 3ce64c055c..ecc9888f42 100644 --- a/packages/core-transactions/src/handlers/one/transfer.ts +++ b/packages/core-transactions/src/handlers/one/transfer.ts @@ -29,9 +29,8 @@ export class TransferTransactionHandler extends TransactionHandler { public async throwIfCannotBeApplied( transaction: Interfaces.ITransaction, sender: Contracts.State.Wallet, - customWalletRepository?: Contracts.State.WalletRepository, ): Promise { - return super.throwIfCannotBeApplied(transaction, sender, customWalletRepository); + return super.throwIfCannotBeApplied(transaction, sender); } public hasVendorField(): boolean { @@ -52,28 +51,18 @@ export class TransferTransactionHandler extends TransactionHandler { } } - public async applyToRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; - + public async applyToRecipient(transaction: Interfaces.ITransaction): Promise { Utils.assert.defined(transaction.data.recipientId); - const recipient: Contracts.State.Wallet = walletRepository.findByAddress(transaction.data.recipientId); + const recipient: Contracts.State.Wallet = this.walletRepository.findByAddress(transaction.data.recipientId); recipient.balance = recipient.balance.plus(transaction.data.amount); } - public async revertForRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; - + public async revertForRecipient(transaction: Interfaces.ITransaction): Promise { Utils.assert.defined(transaction.data.recipientId); - const recipient: Contracts.State.Wallet = walletRepository.findByAddress(transaction.data.recipientId); + const recipient: Contracts.State.Wallet = this.walletRepository.findByAddress(transaction.data.recipientId); recipient.balance = recipient.balance.minus(transaction.data.amount); } diff --git a/packages/core-transactions/src/handlers/one/vote.ts b/packages/core-transactions/src/handlers/one/vote.ts index 37def4f06a..ef217f6cd3 100644 --- a/packages/core-transactions/src/handlers/one/vote.ts +++ b/packages/core-transactions/src/handlers/one/vote.ts @@ -39,17 +39,15 @@ export class VoteTransactionHandler extends TransactionHandler { public async throwIfCannotBeApplied( transaction: Interfaces.ITransaction, wallet: Contracts.State.Wallet, - customWalletRepository?: Contracts.State.WalletRepository, ): Promise { Utils.assert.defined(transaction.data.asset?.votes); const vote: string = transaction.data.asset.votes[0]; - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; let walletVote: string | undefined; const delegatePublicKey: string = vote.slice(1); - const delegateWallet: Contracts.State.Wallet = walletRepository.findByPublicKey(delegatePublicKey); + const delegateWallet: Contracts.State.Wallet = this.walletRepository.findByPublicKey(delegatePublicKey); if (wallet.hasAttribute("vote")) { walletVote = wallet.getAttribute("vote"); @@ -75,7 +73,7 @@ export class VoteTransactionHandler extends TransactionHandler { throw new VotedForNonDelegateError(vote); } - return super.throwIfCannotBeApplied(transaction, wallet, customWalletRepository); + return super.throwIfCannotBeApplied(transaction, wallet); } public emitEvents(transaction: Interfaces.ITransaction, emitter: Contracts.Kernel.EventDispatcher): void { @@ -106,17 +104,12 @@ export class VoteTransactionHandler extends TransactionHandler { } } - public async applyToSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.applyToSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async applyToSender(transaction: Interfaces.ITransaction): Promise { + await super.applyToSender(transaction); Utils.assert.defined(transaction.data.senderPublicKey); - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); Utils.assert.defined(transaction.data.asset?.votes); @@ -129,17 +122,12 @@ export class VoteTransactionHandler extends TransactionHandler { } } - public async revertForSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.revertForSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async revertForSender(transaction: Interfaces.ITransaction): Promise { + await super.revertForSender(transaction); Utils.assert.defined(transaction.data.senderPublicKey); - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); Utils.assert.defined(transaction.data.asset?.votes); @@ -152,13 +140,7 @@ export class VoteTransactionHandler extends TransactionHandler { } } - public async applyToRecipient( - transaction: Interfaces.ITransaction, - walletRepository: Contracts.State.WalletRepository, - ): Promise {} + public async applyToRecipient(transaction: Interfaces.ITransaction): Promise {} - public async revertForRecipient( - transaction: Interfaces.ITransaction, - walletRepository: Contracts.State.WalletRepository, - ): Promise {} + public async revertForRecipient(transaction: Interfaces.ITransaction): Promise {} } diff --git a/packages/core-transactions/src/handlers/transaction.ts b/packages/core-transactions/src/handlers/transaction.ts index 76c4afc240..af9fc25c35 100644 --- a/packages/core-transactions/src/handlers/transaction.ts +++ b/packages/core-transactions/src/handlers/transaction.ts @@ -31,15 +31,12 @@ export abstract class TransactionHandler { @Container.inject(Container.Identifiers.WalletRepository) protected readonly walletRepository!: Contracts.State.WalletRepository; - public async verify( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; - + public async verify(transaction: Interfaces.ITransaction): Promise { AppUtils.assert.defined(transaction.data.senderPublicKey); - const senderWallet: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const senderWallet: Contracts.State.Wallet = this.walletRepository.findByPublicKey( + transaction.data.senderPublicKey, + ); if (senderWallet.hasMultiSignature()) { transaction.isVerified = this.verifySignatures(senderWallet, transaction.data); @@ -66,45 +63,32 @@ export abstract class TransactionHandler { public async throwIfCannotBeApplied( transaction: Interfaces.ITransaction, sender: Contracts.State.Wallet, - customWalletRepository?: Contracts.State.WalletRepository, ): Promise { - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; - const senderWallet: Contracts.State.Wallet = walletRepository.findByAddress(sender.address); + const senderWallet: Contracts.State.Wallet = this.walletRepository.findByAddress(sender.address); AppUtils.assert.defined(sender.publicKey); - if (!walletRepository.hasByPublicKey(sender.publicKey) && senderWallet.balance.isZero()) { + if (!this.walletRepository.hasByPublicKey(sender.publicKey) && senderWallet.balance.isZero()) { throw new ColdWalletError(); } - return this.performGenericWalletChecks(transaction, sender, customWalletRepository); + return this.performGenericWalletChecks(transaction, sender); } - public async apply( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await this.applyToSender(transaction, customWalletRepository); - await this.applyToRecipient(transaction, customWalletRepository); + public async apply(transaction: Interfaces.ITransaction): Promise { + await this.applyToSender(transaction); + await this.applyToRecipient(transaction); } - public async revert( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await this.revertForSender(transaction, customWalletRepository); - await this.revertForRecipient(transaction, customWalletRepository); + public async revert(transaction: Interfaces.ITransaction): Promise { + await this.revertForSender(transaction); + await this.revertForRecipient(transaction); } - public async applyToSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; - + public async applyToSender(transaction: Interfaces.ITransaction): Promise { AppUtils.assert.defined(transaction.data.senderPublicKey); - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); const data: Interfaces.ITransactionData = transaction.data; @@ -112,7 +96,7 @@ export abstract class TransactionHandler { this.app.log.warning(`Transaction forcibly applied as an exception: ${transaction.id}.`); } - await this.throwIfCannotBeApplied(transaction, sender, customWalletRepository); + await this.throwIfCannotBeApplied(transaction, sender); // TODO: extract version specific code if (data.version && data.version > 1) { @@ -150,15 +134,10 @@ export abstract class TransactionHandler { sender.balance = newBalance; } - public async revertForSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; - + public async revertForSender(transaction: Interfaces.ITransaction): Promise { AppUtils.assert.defined(transaction.data.senderPublicKey); - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); const data: Interfaces.ITransactionData = transaction.data; @@ -205,7 +184,6 @@ export abstract class TransactionHandler { protected async performGenericWalletChecks( transaction: Interfaces.ITransaction, sender: Contracts.State.Wallet, - customWalletRepository?: Contracts.State.WalletRepository, ): Promise { const data: Interfaces.ITransactionData = transaction.data; @@ -324,15 +302,9 @@ export abstract class TransactionHandler { public abstract async bootstrap(): Promise; - public abstract async applyToRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise; + public abstract async applyToRecipient(transaction: Interfaces.ITransaction): Promise; - public abstract async revertForRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise; + public abstract async revertForRecipient(transaction: Interfaces.ITransaction): Promise; } export type TransactionHandlerConstructor = typeof TransactionHandler; diff --git a/packages/core-transactions/src/handlers/two/delegate-resignation.ts b/packages/core-transactions/src/handlers/two/delegate-resignation.ts index 956c660660..8c37e9f53c 100644 --- a/packages/core-transactions/src/handlers/two/delegate-resignation.ts +++ b/packages/core-transactions/src/handlers/two/delegate-resignation.ts @@ -42,7 +42,6 @@ export class DelegateResignationTransactionHandler extends TransactionHandler { public async throwIfCannotBeApplied( transaction: Interfaces.ITransaction, wallet: Contracts.State.Wallet, - customWalletRepository?: Contracts.State.WalletRepository, ): Promise { if (!wallet.isDelegate()) { throw new WalletNotADelegateError(); @@ -61,7 +60,7 @@ export class DelegateResignationTransactionHandler extends TransactionHandler { throw new NotEnoughDelegatesError(); } - return super.throwIfCannotBeApplied(transaction, wallet, customWalletRepository); + return super.throwIfCannotBeApplied(transaction, wallet); } public emitEvents(transaction: Interfaces.ITransaction, emitter: Contracts.Kernel.EventDispatcher): void { @@ -88,44 +87,35 @@ export class DelegateResignationTransactionHandler extends TransactionHandler { } } - public async applyToSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.applyToSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async applyToSender(transaction: Interfaces.ITransaction): Promise { + await super.applyToSender(transaction); Utils.assert.defined(transaction.data.senderPublicKey); - const senderWallet: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const senderWallet: Contracts.State.Wallet = this.walletRepository.findByPublicKey( + transaction.data.senderPublicKey, + ); senderWallet.setAttribute("delegate.resigned", true); - walletRepository.index(senderWallet); - } - public async revertForSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.revertForSender(transaction, customWalletRepository); + this.walletRepository.index(senderWallet); + } - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async revertForSender(transaction: Interfaces.ITransaction): Promise { + await super.revertForSender(transaction); Utils.assert.defined(transaction.data.senderPublicKey); - walletRepository.findByPublicKey(transaction.data.senderPublicKey).forgetAttribute("delegate.resigned"); + this.walletRepository.findByPublicKey(transaction.data.senderPublicKey).forgetAttribute("delegate.resigned"); } public async applyToRecipient( transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, // tslint:disable-next-line: no-empty ): Promise {} public async revertForRecipient( transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, // tslint:disable-next-line: no-empty ): Promise {} } diff --git a/packages/core-transactions/src/handlers/two/htlc-claim.ts b/packages/core-transactions/src/handlers/two/htlc-claim.ts index 520dc61be5..3220ec6185 100644 --- a/packages/core-transactions/src/handlers/two/htlc-claim.ts +++ b/packages/core-transactions/src/handlers/two/htlc-claim.ts @@ -44,18 +44,16 @@ export class HtlcClaimTransactionHandler extends TransactionHandler { public async throwIfCannotBeApplied( transaction: Interfaces.ITransaction, sender: Contracts.State.Wallet, - customWalletRepository?: Contracts.State.WalletRepository, ): Promise { - await this.performGenericWalletChecks(transaction, sender, customWalletRepository); + await this.performGenericWalletChecks(transaction, sender); // Specific HTLC claim checks - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; AppUtils.assert.defined(transaction.data.asset?.claim); const claimAsset: Interfaces.IHtlcClaimAsset = transaction.data.asset.claim; const lockId: string = claimAsset.lockTransactionId; - const lockWallet: Contracts.State.Wallet = walletRepository.findByIndex( + const lockWallet: Contracts.State.Wallet = this.walletRepository.findByIndex( Contracts.State.WalletIndexes.Locks, lockId, ); @@ -111,15 +109,10 @@ export class HtlcClaimTransactionHandler extends TransactionHandler { } } - public async applyToSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; - + public async applyToSender(transaction: Interfaces.ITransaction): Promise { AppUtils.assert.defined(transaction.data.senderPublicKey); - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); const data: Interfaces.ITransactionData = transaction.data; @@ -127,7 +120,7 @@ export class HtlcClaimTransactionHandler extends TransactionHandler { this.app.log.warning(`Transaction forcibly applied as an exception: ${transaction.id}.`); } - await this.throwIfCannotBeApplied(transaction, sender, customWalletRepository); + await this.throwIfCannotBeApplied(transaction, sender); this.verifyTransactionNonceApply(sender, transaction); @@ -138,7 +131,7 @@ export class HtlcClaimTransactionHandler extends TransactionHandler { AppUtils.assert.defined(data.asset?.claim?.lockTransactionId); const lockId: string = data.asset.claim.lockTransactionId; - const lockWallet: Contracts.State.Wallet = walletRepository.findByIndex( + const lockWallet: Contracts.State.Wallet = this.walletRepository.findByIndex( Contracts.State.WalletIndexes.Locks, lockId, ); @@ -151,7 +144,7 @@ export class HtlcClaimTransactionHandler extends TransactionHandler { AppUtils.assert.defined(recipientId); - const recipientWallet: Contracts.State.Wallet = walletRepository.findByAddress(recipientId); + const recipientWallet: Contracts.State.Wallet = this.walletRepository.findByAddress(recipientId); const newBalance: Utils.BigNumber = recipientWallet.balance.plus(locks[lockId].amount).minus(data.fee); @@ -165,20 +158,15 @@ export class HtlcClaimTransactionHandler extends TransactionHandler { delete locks[lockId]; - walletRepository.index(sender); - walletRepository.index(lockWallet); - walletRepository.index(recipientWallet); + this.walletRepository.index(sender); + this.walletRepository.index(lockWallet); + this.walletRepository.index(recipientWallet); } - public async revertForSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; - + public async revertForSender(transaction: Interfaces.ITransaction): Promise { AppUtils.assert.defined(transaction.data.senderPublicKey); - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); const data: Interfaces.ITransactionData = transaction.data; @@ -195,12 +183,16 @@ export class HtlcClaimTransactionHandler extends TransactionHandler { AppUtils.assert.defined(lockTransaction.recipientId); - const recipientWallet: Contracts.State.Wallet = walletRepository.findByAddress(lockTransaction.recipientId); + const recipientWallet: Contracts.State.Wallet = this.walletRepository.findByAddress( + lockTransaction.recipientId, + ); recipientWallet.balance = recipientWallet.balance.minus(lockTransaction.amount).plus(data.fee); AppUtils.assert.defined(lockTransaction.senderPublicKey); - const lockWallet: Contracts.State.Wallet = walletRepository.findByPublicKey(lockTransaction.senderPublicKey); + const lockWallet: Contracts.State.Wallet = this.walletRepository.findByPublicKey( + lockTransaction.senderPublicKey, + ); const lockedBalance: Utils.BigNumber = lockWallet.getAttribute("htlc.lockedBalance"); lockWallet.setAttribute("htlc.lockedBalance", lockedBalance.plus(lockTransaction.amount)); @@ -220,18 +212,12 @@ export class HtlcClaimTransactionHandler extends TransactionHandler { ...lockTransaction.asset.lock, }; - walletRepository.index(sender); - walletRepository.index(lockWallet); - walletRepository.index(recipientWallet); + this.walletRepository.index(sender); + this.walletRepository.index(lockWallet); + this.walletRepository.index(recipientWallet); } - public async applyToRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise {} + public async applyToRecipient(transaction: Interfaces.ITransaction): Promise {} - public async revertForRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise {} + public async revertForRecipient(transaction: Interfaces.ITransaction): Promise {} } diff --git a/packages/core-transactions/src/handlers/two/htlc-lock.ts b/packages/core-transactions/src/handlers/two/htlc-lock.ts index 3687135fcd..b76cb9b730 100644 --- a/packages/core-transactions/src/handlers/two/htlc-lock.ts +++ b/packages/core-transactions/src/handlers/two/htlc-lock.ts @@ -62,7 +62,6 @@ export class HtlcLockTransactionHandler extends TransactionHandler { public async throwIfCannotBeApplied( transaction: Interfaces.ITransaction, wallet: Contracts.State.Wallet, - customWalletRepository?: Contracts.State.WalletRepository, ): Promise { AppUtils.assert.defined(transaction.data.asset?.lock); @@ -88,45 +87,34 @@ export class HtlcLockTransactionHandler extends TransactionHandler { throw new HtlcLockExpiredError(); } - return super.throwIfCannotBeApplied(transaction, wallet, customWalletRepository); + return super.throwIfCannotBeApplied(transaction, wallet); } - public async applyToSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.applyToSender(transaction, customWalletRepository); + public async applyToSender(transaction: Interfaces.ITransaction): Promise { + await super.applyToSender(transaction); AppUtils.assert.defined(transaction.data.senderPublicKey); - const walletRepository = customWalletRepository ?? this.walletRepository; - const sender = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); const lockedBalance = sender.getAttribute("htlc.lockedBalance", Utils.BigNumber.ZERO); sender.setAttribute("htlc.lockedBalance", lockedBalance.plus(transaction.data.amount)); - walletRepository.index(sender); + this.walletRepository.index(sender); } - public async revertForSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.revertForSender(transaction, customWalletRepository); + public async revertForSender(transaction: Interfaces.ITransaction): Promise { + await super.revertForSender(transaction); AppUtils.assert.defined(transaction.data.senderPublicKey); - const walletRepository = customWalletRepository ?? this.walletRepository; - const sender = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); const lockedBalance = sender.getAttribute("htlc.lockedBalance", Utils.BigNumber.ZERO); sender.setAttribute("htlc.lockedBalance", lockedBalance.minus(transaction.data.amount)); - walletRepository.index(sender); + this.walletRepository.index(sender); } - public async applyToRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { + public async applyToRecipient(transaction: Interfaces.ITransaction): Promise { // It may seem that htlc-lock doesn't have recipient because it only updates sender's wallet. // But actually applyToSender applies state changes that only affect sender. // While applyToRecipient applies state changes that can affect others. @@ -136,8 +124,7 @@ export class HtlcLockTransactionHandler extends TransactionHandler { AppUtils.assert.defined(transaction.data.senderPublicKey); AppUtils.assert.defined(transaction.data.asset?.lock); - const walletRepository = customWalletRepository ?? this.walletRepository; - const sender = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); const locks = sender.getAttribute("htlc.locks", {}); locks[transaction.id] = { amount: transaction.data.amount, @@ -148,22 +135,18 @@ export class HtlcLockTransactionHandler extends TransactionHandler { }; sender.setAttribute("htlc.locks", locks); - walletRepository.index(sender); + this.walletRepository.index(sender); } - public async revertForRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { + public async revertForRecipient(transaction: Interfaces.ITransaction): Promise { AppUtils.assert.defined(transaction.id); AppUtils.assert.defined(transaction.data.senderPublicKey); - const walletRepository = customWalletRepository ?? this.walletRepository; - const sender = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); const locks = sender.getAttribute("htlc.locks", {}); delete locks[transaction.id]; sender.setAttribute("htlc.locks", locks); - walletRepository.index(sender); + this.walletRepository.index(sender); } } diff --git a/packages/core-transactions/src/handlers/two/htlc-refund.ts b/packages/core-transactions/src/handlers/two/htlc-refund.ts index 552ecf4030..bf2bf09506 100644 --- a/packages/core-transactions/src/handlers/two/htlc-refund.ts +++ b/packages/core-transactions/src/handlers/two/htlc-refund.ts @@ -46,19 +46,17 @@ export class HtlcRefundTransactionHandler extends TransactionHandler { public async throwIfCannotBeApplied( transaction: Interfaces.ITransaction, sender: Contracts.State.Wallet, - customWalletRepository?: Contracts.State.WalletRepository, ): Promise { - await this.performGenericWalletChecks(transaction, sender, customWalletRepository); + await this.performGenericWalletChecks(transaction, sender); AppUtils.assert.defined(transaction.data.asset?.refund); // Specific HTLC refund checks - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; AppUtils.assert.defined(transaction.data.asset.refund); const lockId: string = transaction.data.asset.refund.lockTransactionId; - const lockWallet: Contracts.State.Wallet = walletRepository.findByIndex( + const lockWallet: Contracts.State.Wallet = this.walletRepository.findByIndex( Contracts.State.WalletIndexes.Locks, lockId, ); @@ -108,15 +106,10 @@ export class HtlcRefundTransactionHandler extends TransactionHandler { } } - public async applyToSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; - + public async applyToSender(transaction: Interfaces.ITransaction): Promise { AppUtils.assert.defined(transaction.data.senderPublicKey); - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); const data: Interfaces.ITransactionData = transaction.data; @@ -124,7 +117,7 @@ export class HtlcRefundTransactionHandler extends TransactionHandler { this.app.log.warning(`Transaction forcibly applied as an exception: ${transaction.id}.`); } - await this.throwIfCannotBeApplied(transaction, sender, customWalletRepository); + await this.throwIfCannotBeApplied(transaction, sender); this.verifyTransactionNonceApply(sender, transaction); @@ -135,7 +128,7 @@ export class HtlcRefundTransactionHandler extends TransactionHandler { AppUtils.assert.defined(data.asset?.refund?.lockTransactionId); const lockId: string = data.asset.refund.lockTransactionId; - const lockWallet: Contracts.State.Wallet = walletRepository.findByIndex( + const lockWallet: Contracts.State.Wallet = this.walletRepository.findByIndex( Contracts.State.WalletIndexes.Locks, lockId, ); @@ -156,18 +149,13 @@ export class HtlcRefundTransactionHandler extends TransactionHandler { delete locks[lockId]; - walletRepository.index(lockWallet); + this.walletRepository.index(lockWallet); } - public async revertForSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; - + public async revertForSender(transaction: Interfaces.ITransaction): Promise { AppUtils.assert.defined(transaction.data.senderPublicKey); - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); this.verifyTransactionNonceRevert(sender, transaction); @@ -181,7 +169,9 @@ export class HtlcRefundTransactionHandler extends TransactionHandler { AppUtils.assert.defined(lockTransaction.senderPublicKey); - const lockWallet: Contracts.State.Wallet = walletRepository.findByPublicKey(lockTransaction.senderPublicKey); + const lockWallet: Contracts.State.Wallet = this.walletRepository.findByPublicKey( + lockTransaction.senderPublicKey, + ); lockWallet.balance = lockWallet.balance.minus(lockTransaction.amount).plus(transaction.data.fee); @@ -206,16 +196,10 @@ export class HtlcRefundTransactionHandler extends TransactionHandler { }; } - walletRepository.index(lockWallet); + this.walletRepository.index(lockWallet); } - public async applyToRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise {} + public async applyToRecipient(transaction: Interfaces.ITransaction): Promise {} - public async revertForRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise {} + public async revertForRecipient(transaction: Interfaces.ITransaction): Promise {} } diff --git a/packages/core-transactions/src/handlers/two/ipfs.ts b/packages/core-transactions/src/handlers/two/ipfs.ts index f1b3e3d1b5..589877d9e0 100644 --- a/packages/core-transactions/src/handlers/two/ipfs.ts +++ b/packages/core-transactions/src/handlers/two/ipfs.ts @@ -44,31 +44,24 @@ export class IpfsTransactionHandler extends TransactionHandler { public async throwIfCannotBeApplied( transaction: Interfaces.ITransaction, wallet: Contracts.State.Wallet, - customWalletRepository?: Contracts.State.WalletRepository, ): Promise { if (CryptoUtils.isException(transaction.data.id)) { return; } - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; - if (walletRepository.getIndex(Contracts.State.WalletIndexes.Ipfs).has(transaction.data.asset!.ipfs!)) { + if (this.walletRepository.getIndex(Contracts.State.WalletIndexes.Ipfs).has(transaction.data.asset!.ipfs!)) { throw new IpfsHashAlreadyExists(); } - return super.throwIfCannotBeApplied(transaction, wallet, customWalletRepository); + return super.throwIfCannotBeApplied(transaction, wallet); } - public async applyToSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.applyToSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async applyToSender(transaction: Interfaces.ITransaction): Promise { + await super.applyToSender(transaction); Utils.assert.defined(transaction.data.senderPublicKey); - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); if (!sender.hasAttribute("ipfs")) { sender.setAttribute("ipfs", { hashes: {} }); @@ -78,20 +71,15 @@ export class IpfsTransactionHandler extends TransactionHandler { sender.getAttribute("ipfs.hashes", {})[transaction.data.asset.ipfs] = true; - walletRepository.index(sender); + this.walletRepository.index(sender); } - public async revertForSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.revertForSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async revertForSender(transaction: Interfaces.ITransaction): Promise { + await super.revertForSender(transaction); Utils.assert.defined(transaction.data.senderPublicKey); - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); Utils.assert.defined(transaction.data.asset?.ipfs); @@ -102,16 +90,10 @@ export class IpfsTransactionHandler extends TransactionHandler { sender.forgetAttribute("ipfs"); } - walletRepository.index(sender); + this.walletRepository.index(sender); } - public async applyToRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise {} + public async applyToRecipient(transaction: Interfaces.ITransaction): Promise {} - public async revertForRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise {} + public async revertForRecipient(transaction: Interfaces.ITransaction): Promise {} } diff --git a/packages/core-transactions/src/handlers/two/multi-payment.ts b/packages/core-transactions/src/handlers/two/multi-payment.ts index e38e73c951..f08df9bde7 100644 --- a/packages/core-transactions/src/handlers/two/multi-payment.ts +++ b/packages/core-transactions/src/handlers/two/multi-payment.ts @@ -40,7 +40,6 @@ export class MultiPaymentTransactionHandler extends TransactionHandler { public async throwIfCannotBeApplied( transaction: Interfaces.ITransaction, wallet: Contracts.State.Wallet, - customWalletRepository?: Contracts.State.WalletRepository, ): Promise { AppUtils.assert.defined(transaction.data.asset?.payments); @@ -51,16 +50,11 @@ export class MultiPaymentTransactionHandler extends TransactionHandler { throw new InsufficientBalanceError(); } - return super.throwIfCannotBeApplied(transaction, wallet, customWalletRepository); + return super.throwIfCannotBeApplied(transaction, wallet); } - public async applyToSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.applyToSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async applyToSender(transaction: Interfaces.ITransaction): Promise { + await super.applyToSender(transaction); AppUtils.assert.defined(transaction.data.asset?.payments); @@ -71,18 +65,13 @@ export class MultiPaymentTransactionHandler extends TransactionHandler { AppUtils.assert.defined(transaction.data.senderPublicKey); - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); sender.balance = sender.balance.minus(totalPaymentsAmount); } - public async revertForSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.revertForSender(transaction, customWalletRepository); - - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; + public async revertForSender(transaction: Interfaces.ITransaction): Promise { + await super.revertForSender(transaction); AppUtils.assert.defined(transaction.data.asset?.payments); @@ -93,36 +82,26 @@ export class MultiPaymentTransactionHandler extends TransactionHandler { AppUtils.assert.defined(transaction.data.senderPublicKey); - const sender: Contracts.State.Wallet = walletRepository.findByPublicKey(transaction.data.senderPublicKey); + const sender: Contracts.State.Wallet = this.walletRepository.findByPublicKey(transaction.data.senderPublicKey); sender.balance = sender.balance.plus(totalPaymentsAmount); } - public async applyToRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; - + public async applyToRecipient(transaction: Interfaces.ITransaction): Promise { AppUtils.assert.defined(transaction.data.asset?.payments); for (const payment of transaction.data.asset.payments) { - const recipient: Contracts.State.Wallet = walletRepository.findByAddress(payment.recipientId); + const recipient: Contracts.State.Wallet = this.walletRepository.findByAddress(payment.recipientId); recipient.balance = recipient.balance.plus(payment.amount); } } - public async revertForRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; - + public async revertForRecipient(transaction: Interfaces.ITransaction): Promise { AppUtils.assert.defined(transaction.data.asset?.payments); for (const payment of transaction.data.asset.payments) { - const recipient: Contracts.State.Wallet = walletRepository.findByAddress(payment.recipientId); + const recipient: Contracts.State.Wallet = this.walletRepository.findByAddress(payment.recipientId); recipient.balance = recipient.balance.minus(payment.amount); } diff --git a/packages/core-transactions/src/handlers/two/multi-signature-registration.ts b/packages/core-transactions/src/handlers/two/multi-signature-registration.ts index 76a3158cf0..78d6083505 100644 --- a/packages/core-transactions/src/handlers/two/multi-signature-registration.ts +++ b/packages/core-transactions/src/handlers/two/multi-signature-registration.ts @@ -53,7 +53,6 @@ export class MultiSignatureRegistrationTransactionHandler extends TransactionHan public async throwIfCannotBeApplied( transaction: Interfaces.ITransaction, wallet: Contracts.State.Wallet, - customWalletRepository?: Contracts.State.WalletRepository, ): Promise { const { data }: Interfaces.ITransaction = transaction; @@ -70,12 +69,10 @@ export class MultiSignatureRegistrationTransactionHandler extends TransactionHan throw new MultiSignatureKeyCountMismatchError(); } - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; - AppUtils.assert.defined(data.asset.multiSignature); const multiSigPublicKey: string = Identities.PublicKey.fromMultiSignatureAsset(data.asset.multiSignature); - const recipientWallet: Contracts.State.Wallet = walletRepository.findByPublicKey(multiSigPublicKey); + const recipientWallet: Contracts.State.Wallet = this.walletRepository.findByPublicKey(multiSigPublicKey); if (recipientWallet.hasMultiSignature()) { throw new MultiSignatureAlreadyRegisteredError(); @@ -85,7 +82,7 @@ export class MultiSignatureRegistrationTransactionHandler extends TransactionHan throw new InvalidMultiSignatureError(); } - return super.throwIfCannotBeApplied(transaction, wallet, customWalletRepository); + return super.throwIfCannotBeApplied(transaction, wallet); } public async throwIfCannotEnterPool(transaction: Interfaces.ITransaction): Promise { @@ -105,58 +102,41 @@ export class MultiSignatureRegistrationTransactionHandler extends TransactionHan } } - public async applyToSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.applyToSender(transaction, customWalletRepository); + public async applyToSender(transaction: Interfaces.ITransaction): Promise { + await super.applyToSender(transaction); // Create the multi sig wallet - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; AppUtils.assert.defined(transaction.data.asset?.multiSignature); - walletRepository + this.walletRepository .findByPublicKey(Identities.PublicKey.fromMultiSignatureAsset(transaction.data.asset.multiSignature)) .setAttribute("multiSignature", transaction.data.asset.multiSignature); } - public async revertForSender( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { - await super.revertForSender(transaction, customWalletRepository); + public async revertForSender(transaction: Interfaces.ITransaction): Promise { + await super.revertForSender(transaction); // Nothing else to do for the sender since the recipient wallet // is made into a multi sig wallet. } - public async applyToRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { + public async applyToRecipient(transaction: Interfaces.ITransaction): Promise { const { data }: Interfaces.ITransaction = transaction; - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; - AppUtils.assert.defined(data.asset?.multiSignature); - const recipientWallet: Contracts.State.Wallet = walletRepository.findByPublicKey( + const recipientWallet: Contracts.State.Wallet = this.walletRepository.findByPublicKey( Identities.PublicKey.fromMultiSignatureAsset(data.asset.multiSignature), ); recipientWallet.setAttribute("multiSignature", data.asset.multiSignature); } - public async revertForRecipient( - transaction: Interfaces.ITransaction, - customWalletRepository?: Contracts.State.WalletRepository, - ): Promise { + public async revertForRecipient(transaction: Interfaces.ITransaction): Promise { const { data }: Interfaces.ITransaction = transaction; - const walletRepository: Contracts.State.WalletRepository = customWalletRepository ?? this.walletRepository; - AppUtils.assert.defined(data.asset?.multiSignature); - const recipientWallet: Contracts.State.Wallet = walletRepository.findByPublicKey( + const recipientWallet: Contracts.State.Wallet = this.walletRepository.findByPublicKey( Identities.PublicKey.fromMultiSignatureAsset(data.asset.multiSignature), ); From 7670886b2ef7c1b67ff02839debd7b0135b304f7 Mon Sep 17 00:00:00 2001 From: Dmitry Tyshchenko Date: Tue, 16 Jun 2020 09:04:57 +0300 Subject: [PATCH 2/2] Remove unused import --- .../unit/core-transactions/handlers/handler-registry.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/unit/core-transactions/handlers/handler-registry.test.ts b/__tests__/unit/core-transactions/handlers/handler-registry.test.ts index 28097bf7d6..ba3273a6e7 100644 --- a/__tests__/unit/core-transactions/handlers/handler-registry.test.ts +++ b/__tests__/unit/core-transactions/handlers/handler-registry.test.ts @@ -1,6 +1,6 @@ import "jest-extended"; -import { Contracts, Services } from "@packages/core-kernel"; +import { Services } from "@packages/core-kernel"; import { Application } from "@packages/core-kernel/src/application"; import { Container, Identifiers } from "@packages/core-kernel/src/ioc"; import {