From d5dc2d2cea875a3a45cb81a027ddefc669d324d9 Mon Sep 17 00:00:00 2001 From: Milan Steiner Date: Thu, 7 Apr 2022 12:56:32 +0200 Subject: [PATCH 1/5] Use correct data format in vesting aminomessage --- packages/stargate/src/modules/vesting/aminomessages.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/stargate/src/modules/vesting/aminomessages.ts b/packages/stargate/src/modules/vesting/aminomessages.ts index 46fa54f1..76b1e64e 100644 --- a/packages/stargate/src/modules/vesting/aminomessages.ts +++ b/packages/stargate/src/modules/vesting/aminomessages.ts @@ -4,7 +4,6 @@ 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: { @@ -13,7 +12,7 @@ export interface AminoMsgCreateVestingAccount extends AminoMsg { /** Bech32 account address */ readonly to_address: string; readonly amount: readonly Coin[]; - readonly end_time: Long; + readonly end_time: string; readonly delayed: boolean; }; } @@ -36,7 +35,7 @@ export function createVestingAminoConverters(): AminoConverters { from_address: fromAddress, to_address: toAddress, amount: [...amount], - end_time: endTime, + end_time: endTime.toString(), delayed: delayed, }), fromAmino: ({ @@ -49,7 +48,7 @@ export function createVestingAminoConverters(): AminoConverters { fromAddress: from_address, toAddress: to_address, amount: [...amount], - endTime: end_time, + endTime: Long.fromString(end_time), delayed: delayed, }), }, From 1899e212dba3deedd415b875e9c4d23dad64a116 Mon Sep 17 00:00:00 2001 From: Milan Steiner Date: Thu, 7 Apr 2022 13:13:36 +0200 Subject: [PATCH 2/5] Adding tests --- .../src/modules/vesting/aminomessages.spec.ts | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 packages/stargate/src/modules/vesting/aminomessages.spec.ts diff --git a/packages/stargate/src/modules/vesting/aminomessages.spec.ts b/packages/stargate/src/modules/vesting/aminomessages.spec.ts new file mode 100644 index 00000000..a498efcc --- /dev/null +++ b/packages/stargate/src/modules/vesting/aminomessages.spec.ts @@ -0,0 +1,63 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import { AminoMsg, coins } from "@cosmjs/amino"; +import { MsgCreateVestingAccount } from "cosmjs-types/cosmos/vesting/v1beta1/tx"; +import Long from "long"; + +import { AminoTypes } from "../../aminotypes"; +import { AminoMsgCreateVestingAccount, createVestingAminoConverters } from "./aminomessages"; + +describe("AminoTypes", () => { + 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, + }); + }); + }); +}); From 4a4e54b1ce7627e15c8ece17b8f1c048350f3ce4 Mon Sep 17 00:00:00 2001 From: Milan Steiner Date: Thu, 7 Apr 2022 15:48:29 +0200 Subject: [PATCH 3/5] Adding more tests --- .../src/modules/vesting/aminomessages.spec.ts | 44 +++++++++++++++++- .../src/modules/vesting/messages.spec.ts | 45 +++++++++++++++++++ 2 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 packages/stargate/src/modules/vesting/messages.spec.ts diff --git a/packages/stargate/src/modules/vesting/aminomessages.spec.ts b/packages/stargate/src/modules/vesting/aminomessages.spec.ts index a498efcc..ef31e2fd 100644 --- a/packages/stargate/src/modules/vesting/aminomessages.spec.ts +++ b/packages/stargate/src/modules/vesting/aminomessages.spec.ts @@ -1,12 +1,21 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { AminoMsg, coins } from "@cosmjs/amino"; +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("AminoTypes", () => { +describe("VestingExtension Amino", () => { describe("toAmino", () => { it("works for MsgCreateVestingAccount", () => { const msg: MsgCreateVestingAccount = { @@ -61,3 +70,34 @@ describe("AminoTypes", () => { }); }); }); + +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); + }); +}); diff --git a/packages/stargate/src/modules/vesting/messages.spec.ts b/packages/stargate/src/modules/vesting/messages.spec.ts new file mode 100644 index 00000000..54ae1397 --- /dev/null +++ b/packages/stargate/src/modules/vesting/messages.spec.ts @@ -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); + }); +}); From 43b6e99312f85012def1859cdc4e88a85c6afc3a Mon Sep 17 00:00:00 2001 From: Milan Steiner Date: Fri, 8 Apr 2022 10:26:10 +0200 Subject: [PATCH 4/5] Removing Amino Support for Vesting Messages --- .../src/modules/vesting/aminomessages.spec.ts | 103 ------------------ .../src/modules/vesting/aminomessages.ts | 51 +-------- .../stargate/src/signingstargateclient.ts | 4 - 3 files changed, 1 insertion(+), 157 deletions(-) delete mode 100644 packages/stargate/src/modules/vesting/aminomessages.spec.ts diff --git a/packages/stargate/src/modules/vesting/aminomessages.spec.ts b/packages/stargate/src/modules/vesting/aminomessages.spec.ts deleted file mode 100644 index ef31e2fd..00000000 --- a/packages/stargate/src/modules/vesting/aminomessages.spec.ts +++ /dev/null @@ -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); - }); -}); diff --git a/packages/stargate/src/modules/vesting/aminomessages.ts b/packages/stargate/src/modules/vesting/aminomessages.ts index 76b1e64e..b50ba8b2 100644 --- a/packages/stargate/src/modules/vesting/aminomessages.ts +++ b/packages/stargate/src/modules/vesting/aminomessages.ts @@ -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", }; } diff --git a/packages/stargate/src/signingstargateclient.ts b/packages/stargate/src/signingstargateclient.ts index e0e13c5a..5b3e72cf 100644 --- a/packages/stargate/src/signingstargateclient.ts +++ b/packages/stargate/src/signingstargateclient.ts @@ -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(), }; } From f6455bb5d374857902eda7482bcc2898e2f61a85 Mon Sep 17 00:00:00 2001 From: Milan Steiner Date: Fri, 8 Apr 2022 12:31:08 +0200 Subject: [PATCH 5/5] Removed too much by mistake, added again --- packages/stargate/src/modules/index.ts | 6 +----- packages/stargate/src/signingstargateclient.ts | 4 ++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/stargate/src/modules/index.ts b/packages/stargate/src/modules/index.ts index d8ff595a..3358b6a6 100644 --- a/packages/stargate/src/modules/index.ts +++ b/packages/stargate/src/modules/index.ts @@ -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"; diff --git a/packages/stargate/src/signingstargateclient.ts b/packages/stargate/src/signingstargateclient.ts index 5b3e72cf..e0e13c5a 100644 --- a/packages/stargate/src/signingstargateclient.ts +++ b/packages/stargate/src/signingstargateclient.ts @@ -38,6 +38,7 @@ import { MsgUndelegateEncodeObject, MsgWithdrawDelegatorRewardEncodeObject, stakingTypes, + vestingTypes, } from "./modules"; import { createAuthzAminoConverters, @@ -47,6 +48,7 @@ import { createGovAminoConverters, createIbcAminoConverters, createStakingAminoConverters, + createVestingAminoConverters, } from "./modules"; import { DeliverTxResponse, StargateClient, StargateClientOptions } from "./stargateclient"; @@ -59,6 +61,7 @@ export const defaultRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [ ...govTypes, ...stakingTypes, ...ibcTypes, + ...vestingTypes, ]; function createDefaultRegistry(): Registry { @@ -99,6 +102,7 @@ function createDefaultTypes(prefix: string): AminoConverters { ...createStakingAminoConverters(prefix), ...createIbcAminoConverters(), ...createFreegrantAminoConverters(), + ...createVestingAminoConverters(), }; }