Skip to content

Commit

Permalink
refactor(core-transactions): remove custom wallet repository (#3803)
Browse files Browse the repository at this point in the history
  • Loading branch information
rainydio authored Jun 17, 2020
1 parent b219609 commit bb8cb12
Show file tree
Hide file tree
Showing 43 changed files with 566 additions and 1,048 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,19 @@ 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;
}

protected getConstructor() {
return {
staticFee: () => "50000000"
staticFee: () => "50000000",
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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);
});

Expand All @@ -204,7 +200,7 @@ describe("BusinessRegistration", () => {
walletRepository.index(senderWallet);

await expect(
handler.throwIfCannotBeApplied(bridgechainRegistrationTransaction, senderWallet, walletRepository),
handler.throwIfCannotBeApplied(bridgechainRegistrationTransaction, senderWallet),
).rejects.toThrowError(BridgechainAlreadyRegisteredError);
});

Expand All @@ -222,7 +218,7 @@ describe("BusinessRegistration", () => {
walletRepository.index(senderWallet);

await expect(
handler.throwIfCannotBeApplied(bridgechainRegistrationTransaction, senderWallet, walletRepository),
handler.throwIfCannotBeApplied(bridgechainRegistrationTransaction, senderWallet),
).rejects.toThrowError(GenesisHashAlreadyRegisteredError);
});

Expand All @@ -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);
});
});
Expand All @@ -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]
Expand Down Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand All @@ -173,7 +171,7 @@ describe("BusinessRegistration", () => {

senderWallet.setAttribute("business", businessAttributes);
await expect(
handler.throwIfCannotBeApplied(bridgechainResignationTransaction, senderWallet, walletRepository),
handler.throwIfCannotBeApplied(bridgechainResignationTransaction, senderWallet),
).rejects.toThrowError(BridgechainIsNotRegisteredByWalletError);
});

Expand All @@ -185,7 +183,7 @@ describe("BusinessRegistration", () => {
.build();

await expect(
handler.throwIfCannotBeApplied(bridgechainResignationTransaction, senderWallet, walletRepository),
handler.throwIfCannotBeApplied(bridgechainResignationTransaction, senderWallet),
).rejects.toThrowError(BridgechainIsNotRegisteredByWalletError);
});

Expand All @@ -195,22 +193,22 @@ describe("BusinessRegistration", () => {

senderWallet.setAttribute("business", businessAttributes);
await expect(
handler.throwIfCannotBeApplied(bridgechainResignationTransaction, senderWallet, walletRepository),
handler.throwIfCannotBeApplied(bridgechainResignationTransaction, senderWallet),
).rejects.toThrowError(BridgechainIsResignedError);
});

it("should throw if transaction asset is missing", async () => {
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);
});
});
Expand All @@ -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,
Expand All @@ -251,21 +249,21 @@ 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();
});
});

describe("revert", () => {
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,
Expand All @@ -275,15 +273,15 @@ 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,
).toBeTrue();

delete bridgechainResignationTransaction.data.asset;

await expect(handler.revert(bridgechainResignationTransaction, walletRepository)).rejects.toThrowError();
await expect(handler.revert(bridgechainResignationTransaction)).rejects.toThrowError();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand All @@ -206,7 +204,7 @@ describe("BusinessRegistration", () => {
delete businessAttributes.bridgechains;

await expect(
handler.throwIfCannotBeApplied(bridgechainUpdateTransaction, senderWallet, walletRepository),
handler.throwIfCannotBeApplied(bridgechainUpdateTransaction, senderWallet),
).rejects.toThrowError(BridgechainIsNotRegisteredByWalletError);
});

Expand All @@ -220,7 +218,7 @@ describe("BusinessRegistration", () => {
.build();

await expect(
handler.throwIfCannotBeApplied(bridgechainUpdateTransaction, senderWallet, walletRepository),
handler.throwIfCannotBeApplied(bridgechainUpdateTransaction, senderWallet),
).rejects.toThrowError(BridgechainIsNotRegisteredByWalletError);
});

Expand All @@ -229,15 +227,15 @@ describe("BusinessRegistration", () => {
businessAttributes.bridgechains[bridgechainRegistrationAsset.genesisHash].resigned = true;

await expect(
handler.throwIfCannotBeApplied(bridgechainUpdateTransaction, senderWallet, walletRepository),
handler.throwIfCannotBeApplied(bridgechainUpdateTransaction, senderWallet),
).rejects.toThrowError(BridgechainIsResignedError);
});

it("should throw if wallet is port name is invalid", async () => {
bridgechainUpdateTransaction.data.asset!.bridgechainUpdate.ports = { "@arkecosystem/INVALID": 55555 };

await expect(
handler.throwIfCannotBeApplied(bridgechainUpdateTransaction, senderWallet, walletRepository),
handler.throwIfCannotBeApplied(bridgechainUpdateTransaction, senderWallet),
).rejects.toThrowError(PortKeyMustBeValidPackageNameError);
});
});
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -334,7 +332,7 @@ describe("BusinessRegistration", () => {
secondBridgechainUpdateTransaction.data,
]);

await handler.revert(secondBridgechainUpdateTransaction, walletRepository);
await handler.revert(secondBridgechainUpdateTransaction);

expect(
senderWallet.getAttribute("business.bridgechains")[bridgechainRegistrationAsset.genesisHash]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand All @@ -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);
Expand All @@ -173,19 +171,19 @@ 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();
});
});

describe("revert", () => {
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));
Expand Down
Loading

0 comments on commit bb8cb12

Please sign in to comment.