Add support for undefined memo in makeSignDoc
This commit is contained in:
parent
b9f87cffe7
commit
5a47d64037
@ -22,6 +22,7 @@
|
||||
remove such functionality from `CosmosClient.searchTx`.
|
||||
- @cosmjs/launchpad: Add `SigningCosmosClient.sign` method for signing without
|
||||
broadcasting.
|
||||
- @cosmjs/launchpad: Add support for undefined memo in `makeSignDoc`.
|
||||
- @cosmjs/launchpad-ledger: `LedgerSigner.sign` method renamed `signAmino`.
|
||||
- @cosmjs/proto-signing: Add new package for handling transaction signing with
|
||||
protobuf encoding.
|
||||
|
||||
@ -1,4 +1,8 @@
|
||||
import { sortedJsonStringify } from "./encoding";
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { coin, coins } from "./coins";
|
||||
import { makeSignDoc, sortedJsonStringify } from "./encoding";
|
||||
import { MsgDelegate, MsgSend } from "./msgs";
|
||||
import { faucet, launchpad, makeRandomAddress } from "./testutils.spec";
|
||||
|
||||
describe("encoding", () => {
|
||||
describe("sortedJsonStringify", () => {
|
||||
@ -47,4 +51,79 @@ describe("encoding", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("makeSignDoc", () => {
|
||||
it("works", () => {
|
||||
const chainId = "testspace-12";
|
||||
const msg1: MsgDelegate = {
|
||||
type: "cosmos-sdk/MsgDelegate",
|
||||
value: {
|
||||
delegator_address: faucet.address,
|
||||
validator_address: launchpad.validator.address,
|
||||
amount: coin(1234, "ustake"),
|
||||
},
|
||||
};
|
||||
const msg2: MsgSend = {
|
||||
type: "cosmos-sdk/MsgSend",
|
||||
value: {
|
||||
from_address: faucet.address,
|
||||
to_address: makeRandomAddress(),
|
||||
amount: coins(1234567, "ucosm"),
|
||||
},
|
||||
};
|
||||
const fee = {
|
||||
amount: coins(2000, "ucosm"),
|
||||
gas: "180000", // 180k
|
||||
};
|
||||
const memo = "Use your power wisely";
|
||||
const accountNumber = 15;
|
||||
const sequence = 16;
|
||||
|
||||
const signDoc = makeSignDoc([msg1, msg2], fee, chainId, memo, accountNumber, sequence);
|
||||
expect(signDoc).toEqual({
|
||||
msgs: [msg1, msg2],
|
||||
fee: fee,
|
||||
chain_id: chainId,
|
||||
account_number: accountNumber.toString(),
|
||||
sequence: sequence.toString(),
|
||||
memo: memo,
|
||||
});
|
||||
});
|
||||
|
||||
it("works with undefined memo", () => {
|
||||
const chainId = "testspace-12";
|
||||
const msg1: MsgDelegate = {
|
||||
type: "cosmos-sdk/MsgDelegate",
|
||||
value: {
|
||||
delegator_address: faucet.address,
|
||||
validator_address: launchpad.validator.address,
|
||||
amount: coin(1234, "ustake"),
|
||||
},
|
||||
};
|
||||
const msg2: MsgSend = {
|
||||
type: "cosmos-sdk/MsgSend",
|
||||
value: {
|
||||
from_address: faucet.address,
|
||||
to_address: makeRandomAddress(),
|
||||
amount: coins(1234567, "ucosm"),
|
||||
},
|
||||
};
|
||||
const fee = {
|
||||
amount: coins(2000, "ucosm"),
|
||||
gas: "180000", // 180k
|
||||
};
|
||||
const accountNumber = 15;
|
||||
const sequence = 16;
|
||||
|
||||
const signDoc = makeSignDoc([msg1, msg2], fee, chainId, undefined, accountNumber, sequence);
|
||||
expect(signDoc).toEqual({
|
||||
msgs: [msg1, msg2],
|
||||
fee: fee,
|
||||
chain_id: chainId,
|
||||
account_number: accountNumber.toString(),
|
||||
sequence: sequence.toString(),
|
||||
memo: "",
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -47,7 +47,7 @@ export function makeSignDoc(
|
||||
msgs: readonly Msg[],
|
||||
fee: StdFee,
|
||||
chainId: string,
|
||||
memo: string,
|
||||
memo: string | undefined,
|
||||
accountNumber: number | string,
|
||||
sequence: number | string,
|
||||
): StdSignDoc {
|
||||
@ -57,7 +57,7 @@ export function makeSignDoc(
|
||||
sequence: Uint53.fromString(sequence.toString()).toString(),
|
||||
fee: fee,
|
||||
msgs: msgs,
|
||||
memo: memo,
|
||||
memo: memo || "",
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
2
packages/launchpad/types/encoding.d.ts
vendored
2
packages/launchpad/types/encoding.d.ts
vendored
@ -19,7 +19,7 @@ export declare function makeSignDoc(
|
||||
msgs: readonly Msg[],
|
||||
fee: StdFee,
|
||||
chainId: string,
|
||||
memo: string,
|
||||
memo: string | undefined,
|
||||
accountNumber: number | string,
|
||||
sequence: number | string,
|
||||
): StdSignDoc;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user