Throw early if transaction fee is missing

This commit is contained in:
Simon Warta 2020-02-18 11:23:41 +01:00
parent 2f41f93d96
commit a9c605de51
2 changed files with 7 additions and 39 deletions

View File

@ -230,7 +230,8 @@ describe("encode", () => {
);
});
it("builds a send transaction without fee", () => {
it("throws for a send transaction without fee", () => {
// This will be rejected by the REST server. Better throw early to avoid hard to debug errors.
const tx = {
kind: "bcp/send",
chainId: defaultChainId,
@ -239,32 +240,7 @@ describe("encode", () => {
recipient: defaultRecipient,
memo: defaultMemo,
};
expect(buildUnsignedTx(tx, defaultTokens)).toEqual({
type: "cosmos-sdk/StdTx",
value: {
msg: [
{
type: "cosmos-sdk/MsgSend",
value: {
from_address: "cosmos1h806c7khnvmjlywdrkdgk2vrayy2mmvf9rxk2r",
to_address: "cosmos1z7g5w84ynmjyg0kqpahdjqpj7yq34v3suckp0e",
amount: [
{
denom: "uatom",
amount: "11657995",
},
],
},
},
],
signatures: [],
memo: defaultMemo,
fee: {
amount: [],
gas: "",
},
},
});
expect(() => buildUnsignedTx(tx, defaultTokens)).toThrowError(/transaction fee must be set/i);
});
it("builds a send transaction with fee", () => {

View File

@ -91,6 +91,8 @@ export function buildUnsignedTx(
const matchingBankToken = bankTokens.find(t => t.ticker === tx.amount.tokenTicker);
const matchingErc20Token = erc20Tokens.find(t => t.ticker === tx.amount.tokenTicker);
if (!tx.fee) throw new Error("Transaction fee must be set");
if (matchingBankToken) {
return {
type: "cosmos-sdk/StdTx",
@ -107,12 +109,7 @@ export function buildUnsignedTx(
],
memo: tx.memo || "",
signatures: [],
fee: tx.fee
? encodeFee(tx.fee, bankTokens)
: {
amount: [],
gas: "",
},
fee: encodeFee(tx.fee, bankTokens),
},
};
} else if (matchingErc20Token) {
@ -137,12 +134,7 @@ export function buildUnsignedTx(
],
memo: tx.memo || "",
signatures: [],
fee: tx.fee
? encodeFee(tx.fee, bankTokens)
: {
amount: [],
gas: "",
},
fee: encodeFee(tx.fee, bankTokens),
},
};
} else {