Removing Amino Support for Vesting Messages

This commit is contained in:
Milan Steiner 2022-04-08 10:26:10 +02:00
parent 4a4e54b1ce
commit 43b6e99312
3 changed files with 1 additions and 157 deletions

View File

@ -1,103 +0,0 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { coins, Secp256k1HdWallet } from "@cosmjs/amino";
import { MsgCreateVestingAccount } from "cosmjs-types/cosmos/vesting/v1beta1/tx";
import Long from "long";
import { AminoTypes } from "../../aminotypes";
import { SigningStargateClient } from "../../signingstargateclient";
import { isDeliverTxSuccess } from "../../stargateclient";
import {
defaultSigningClientOptions,
faucet,
pendingWithoutSimapp,
simapp,
unused,
} from "../../testutils.spec";
import { AminoMsgCreateVestingAccount, createVestingAminoConverters } from "./aminomessages";
describe("VestingExtension Amino", () => {
describe("toAmino", () => {
it("works for MsgCreateVestingAccount", () => {
const msg: MsgCreateVestingAccount = {
fromAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
toAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
amount: coins(1234, "utest"),
endTime: Long.fromString("1838718434"),
delayed: true,
};
const aminoTypes = new AminoTypes(createVestingAminoConverters());
const aminoMsg = aminoTypes.toAmino({
typeUrl: "/cosmos.vesting.v1beta1.MsgCreateVestingAccount",
value: msg,
});
const expected: AminoMsgCreateVestingAccount = {
type: "cosmos-sdk/MsgCreateVestingAccount",
value: {
from_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
to_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
amount: coins(1234, "utest"),
end_time: "1838718434",
delayed: true,
},
};
expect(aminoMsg).toEqual(expected);
});
});
describe("fromAmino", () => {
it("works for MsgCreateVestingAccount", () => {
const aminoMsg: AminoMsgCreateVestingAccount = {
type: "cosmos-sdk/MsgCreateVestingAccount",
value: {
from_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
to_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
amount: coins(1234, "utest"),
end_time: "1838718434",
delayed: true,
},
};
const msg = new AminoTypes(createVestingAminoConverters()).fromAmino(aminoMsg);
const expectedValue: MsgCreateVestingAccount = {
fromAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
toAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
amount: coins(1234, "utest"),
endTime: Long.fromString("1838718434"),
delayed: true,
};
expect(msg).toEqual({
typeUrl: "/cosmos.vesting.v1beta1.MsgCreateVestingAccount",
value: expectedValue,
});
});
});
});
describe("Signing and broadcasting", () => {
it("works with Amino Signing", async () => {
pendingWithoutSimapp();
const wallet = await Secp256k1HdWallet.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: unused.address,
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);
});
});

View File

@ -1,56 +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: string;
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.toString(),
delayed: delayed,
}),
fromAmino: ({
from_address,
to_address,
amount,
end_time,
delayed,
}: AminoMsgCreateVestingAccount["value"]): MsgCreateVestingAccount => ({
fromAddress: from_address,
toAddress: to_address,
amount: [...amount],
endTime: Long.fromString(end_time),
delayed: delayed,
}),
},
"/cosmos.vesting.v1beta1.MsgCreateVestingAccount": "not_supported_by_chain",
};
}

View File

@ -38,7 +38,6 @@ import {
MsgUndelegateEncodeObject,
MsgWithdrawDelegatorRewardEncodeObject,
stakingTypes,
vestingTypes,
} from "./modules";
import {
createAuthzAminoConverters,
@ -48,7 +47,6 @@ import {
createGovAminoConverters,
createIbcAminoConverters,
createStakingAminoConverters,
createVestingAminoConverters,
} from "./modules";
import { DeliverTxResponse, StargateClient, StargateClientOptions } from "./stargateclient";
@ -61,7 +59,6 @@ export const defaultRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [
...govTypes,
...stakingTypes,
...ibcTypes,
...vestingTypes,
];
function createDefaultRegistry(): Registry {
@ -102,7 +99,6 @@ function createDefaultTypes(prefix: string): AminoConverters {
...createStakingAminoConverters(prefix),
...createIbcAminoConverters(),
...createFreegrantAminoConverters(),
...createVestingAminoConverters(),
};
}