Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use correct data format in vesting aminomessage #1114

Merged
merged 5 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions packages/stargate/src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,5 @@ export {
} from "./staking/messages";
export { setupStakingExtension, StakingExtension } from "./staking/queries";
export { setupTxExtension, TxExtension } from "./tx/queries";
export {
AminoMsgCreateVestingAccount,
createVestingAminoConverters,
isAminoMsgCreateVestingAccount,
} from "./vesting/aminomessages";
export { createVestingAminoConverters } from "./vesting/aminomessages";
export { vestingTypes } from "./vesting/messages";
52 changes: 1 addition & 51 deletions packages/stargate/src/modules/vesting/aminomessages.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { AminoMsg, Coin } from "@cosmjs/amino";
import { MsgCreateVestingAccount } from "cosmjs-types/cosmos/vesting/v1beta1/tx";
import Long from "long";

import { AminoConverters } from "../../aminotypes";

export interface AminoMsgCreateVestingAccount extends AminoMsg {
readonly type: "cosmos-sdk/MsgCreateVestingAccount";
readonly value: {
/** Bech32 account address */
readonly from_address: string;
/** Bech32 account address */
readonly to_address: string;
readonly amount: readonly Coin[];
readonly end_time: Long;
readonly delayed: boolean;
};
}

export function isAminoMsgCreateVestingAccount(msg: AminoMsg): msg is AminoMsgCreateVestingAccount {
return msg.type === "cosmos-sdk/MsgCreateVestingAccount";
}

export function createVestingAminoConverters(): AminoConverters {
return {
"/cosmos.vesting.v1beta1.MsgCreateVestingAccount": {
aminoType: "cosmos-sdk/MsgCreateVestingAccount",
toAmino: ({
fromAddress,
toAddress,
amount,
endTime,
delayed,
}: MsgCreateVestingAccount): AminoMsgCreateVestingAccount["value"] => ({
from_address: fromAddress,
to_address: toAddress,
amount: [...amount],
end_time: endTime,
delayed: delayed,
}),
fromAmino: ({
from_address,
to_address,
amount,
end_time,
delayed,
}: AminoMsgCreateVestingAccount["value"]): MsgCreateVestingAccount => ({
fromAddress: from_address,
toAddress: to_address,
amount: [...amount],
endTime: end_time,
delayed: delayed,
}),
},
msteiner96 marked this conversation as resolved.
Show resolved Hide resolved
"/cosmos.vesting.v1beta1.MsgCreateVestingAccount": "not_supported_by_chain",
};
}
45 changes: 45 additions & 0 deletions packages/stargate/src/modules/vesting/messages.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { coins } from "@cosmjs/amino";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { MsgCreateVestingAccount } from "cosmjs-types/cosmos/vesting/v1beta1/tx";
import Long from "long";

import { SigningStargateClient } from "../../signingstargateclient";
import { isDeliverTxSuccess } from "../../stargateclient";
import {
defaultSigningClientOptions,
faucet,
makeRandomAddress,
pendingWithoutSimapp,
simapp,
} from "../../testutils.spec";

describe("VestingExtension direct", () => {
it("works with direct signing", async () => {
pendingWithoutSimapp();
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic);
const client = await SigningStargateClient.connectWithSigner(
simapp.tendermintUrl,
wallet,
defaultSigningClientOptions,
);
const memo = "Vesting is cool!";
const fee = {
amount: coins(2000, "ucosm"),
gas: "180000", // 180k
};

const vestingMsg = {
typeUrl: "/cosmos.vesting.v1beta1.MsgCreateVestingAccount",
value: MsgCreateVestingAccount.fromPartial({
fromAddress: faucet.address0,
toAddress: makeRandomAddress(),
amount: coins(1234, "ucosm"),
endTime: Long.fromString("1838718434"),
delayed: true,
}),
};

const result = await client.signAndBroadcast(faucet.address0, [vestingMsg], fee, memo);
expect(isDeliverTxSuccess(result)).toEqual(true);
});
});