Merge pull request #1081 from cosmos/remove-default-aminotypes
Remove default types from AminoTypes
This commit is contained in:
commit
0fe5c0c6f6
@ -44,6 +44,7 @@ and this project adheres to
|
||||
dependencies. This should also reduce the bundle size as only the English
|
||||
wordlist is shipped. ([#966])
|
||||
- @cosmjs/cli: Rename binary `cosmwasm-cli` to `cosmjs-cli` ([#1033]).
|
||||
- @cosmjs/stargate & @cosmjs/cosmwasm-stargate: Removed default types from AminoTypes. ([1079])
|
||||
|
||||
[#927]: https://github.com/cosmos/cosmjs/issues/927
|
||||
[#955]: https://github.com/cosmos/cosmjs/issues/955
|
||||
@ -55,6 +56,7 @@ and this project adheres to
|
||||
[#1026]: https://github.com/cosmos/cosmjs/issues/1026
|
||||
[#1033]: https://github.com/cosmos/cosmjs/issues/1033
|
||||
[#1053]: https://github.com/cosmos/cosmjs/issues/1053
|
||||
[#1079]: https://github.com/cosmos/cosmjs/issues/1079
|
||||
|
||||
### Removed
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ describe("AminoTypes", () => {
|
||||
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="),
|
||||
instantiatePermission: undefined,
|
||||
};
|
||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino({
|
||||
const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode",
|
||||
value: msg,
|
||||
});
|
||||
@ -54,12 +54,10 @@ describe("AminoTypes", () => {
|
||||
funds: coins(1234, "ucosm"),
|
||||
admin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
};
|
||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino(
|
||||
{
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
|
||||
value: msg,
|
||||
},
|
||||
);
|
||||
const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
|
||||
value: msg,
|
||||
});
|
||||
const expected: AminoMsgInstantiateContract = {
|
||||
type: "wasm/MsgInstantiateContract",
|
||||
value: {
|
||||
@ -84,12 +82,10 @@ describe("AminoTypes", () => {
|
||||
funds: coins(1234, "ucosm"),
|
||||
admin: "",
|
||||
};
|
||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino(
|
||||
{
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
|
||||
value: msg,
|
||||
},
|
||||
);
|
||||
const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
|
||||
value: msg,
|
||||
});
|
||||
const expected: AminoMsgInstantiateContract = {
|
||||
type: "wasm/MsgInstantiateContract",
|
||||
value: {
|
||||
@ -111,7 +107,7 @@ describe("AminoTypes", () => {
|
||||
newAdmin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
};
|
||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino({
|
||||
const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgUpdateAdmin",
|
||||
value: msg,
|
||||
});
|
||||
@ -131,7 +127,7 @@ describe("AminoTypes", () => {
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
};
|
||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino({
|
||||
const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgClearAdmin",
|
||||
value: msg,
|
||||
});
|
||||
@ -152,7 +148,7 @@ describe("AminoTypes", () => {
|
||||
msg: toUtf8(`{"foo":"bar"}`),
|
||||
funds: coins(1234, "ucosm"),
|
||||
};
|
||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino({
|
||||
const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
||||
value: msg,
|
||||
});
|
||||
@ -175,7 +171,7 @@ describe("AminoTypes", () => {
|
||||
codeId: Long.fromString("98765"),
|
||||
msg: toUtf8(`{"foo":"bar"}`),
|
||||
};
|
||||
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino({
|
||||
const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgMigrateContract",
|
||||
value: msg,
|
||||
});
|
||||
@ -201,9 +197,7 @@ describe("AminoTypes", () => {
|
||||
wasm_byte_code: "WUVMTE9XIFNVQk1BUklORQ==",
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino(
|
||||
aminoMsg,
|
||||
);
|
||||
const msg = new AminoTypes(createWasmAminoConverters()).fromAmino(aminoMsg);
|
||||
const expectedValue: MsgStoreCode = {
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="),
|
||||
@ -229,9 +223,7 @@ describe("AminoTypes", () => {
|
||||
admin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino(
|
||||
aminoMsg,
|
||||
);
|
||||
const msg = new AminoTypes(createWasmAminoConverters()).fromAmino(aminoMsg);
|
||||
const expectedValue: MsgInstantiateContract = {
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
codeId: Long.fromString("12345"),
|
||||
@ -258,9 +250,7 @@ describe("AminoTypes", () => {
|
||||
funds: coins(1234, "ucosm"),
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino(
|
||||
aminoMsg,
|
||||
);
|
||||
const msg = new AminoTypes(createWasmAminoConverters()).fromAmino(aminoMsg);
|
||||
const expectedValue: MsgInstantiateContract = {
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
codeId: Long.fromString("12345"),
|
||||
@ -285,9 +275,7 @@ describe("AminoTypes", () => {
|
||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino(
|
||||
aminoMsg,
|
||||
);
|
||||
const msg = new AminoTypes(createWasmAminoConverters()).fromAmino(aminoMsg);
|
||||
const expectedValue: MsgUpdateAdmin = {
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
newAdmin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
@ -307,9 +295,7 @@ describe("AminoTypes", () => {
|
||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino(
|
||||
aminoMsg,
|
||||
);
|
||||
const msg = new AminoTypes(createWasmAminoConverters()).fromAmino(aminoMsg);
|
||||
const expectedValue: MsgClearAdmin = {
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
@ -330,9 +316,7 @@ describe("AminoTypes", () => {
|
||||
funds: coins(1234, "ucosm"),
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino(
|
||||
aminoMsg,
|
||||
);
|
||||
const msg = new AminoTypes(createWasmAminoConverters()).fromAmino(aminoMsg);
|
||||
const expectedValue: MsgExecuteContract = {
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
@ -355,9 +339,7 @@ describe("AminoTypes", () => {
|
||||
msg: { foo: "bar" },
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino(
|
||||
aminoMsg,
|
||||
);
|
||||
const msg = new AminoTypes(createWasmAminoConverters()).fromAmino(aminoMsg);
|
||||
const expectedValue: MsgMigrateContract = {
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
|
||||
@ -9,6 +9,7 @@ import {
|
||||
assertIsDeliverTxSuccess,
|
||||
coin,
|
||||
coins,
|
||||
createStakingAminoConverters,
|
||||
MsgDelegateEncodeObject,
|
||||
MsgSendEncodeObject,
|
||||
} from "@cosmjs/stargate";
|
||||
@ -736,6 +737,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
|
||||
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, {
|
||||
...defaultSigningClientOptions,
|
||||
aminoTypes: new AminoTypes(createStakingAminoConverters(wasmd.prefix)),
|
||||
prefix: wasmd.prefix,
|
||||
});
|
||||
|
||||
@ -851,39 +853,36 @@ describe("SigningCosmWasmClient", () => {
|
||||
};
|
||||
customRegistry.register(msgDelegateTypeUrl, CustomMsgDelegate);
|
||||
const customAminoTypes = new AminoTypes({
|
||||
prefix: "cosmos",
|
||||
additions: {
|
||||
"/cosmos.staking.v1beta1.MsgDelegate": {
|
||||
aminoType: "cosmos-sdk/MsgDelegate",
|
||||
toAmino: ({
|
||||
customDelegatorAddress,
|
||||
customValidatorAddress,
|
||||
customAmount,
|
||||
}: CustomMsgDelegate): AminoMsgDelegate["value"] => {
|
||||
assert(customDelegatorAddress, "missing customDelegatorAddress");
|
||||
assert(customValidatorAddress, "missing validatorAddress");
|
||||
assert(customAmount, "missing amount");
|
||||
assert(customAmount.amount, "missing amount.amount");
|
||||
assert(customAmount.denom, "missing amount.denom");
|
||||
return {
|
||||
delegator_address: customDelegatorAddress,
|
||||
validator_address: customValidatorAddress,
|
||||
amount: {
|
||||
amount: customAmount.amount,
|
||||
denom: customAmount.denom,
|
||||
},
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
delegator_address,
|
||||
validator_address,
|
||||
amount,
|
||||
}: AminoMsgDelegate["value"]): CustomMsgDelegate => ({
|
||||
customDelegatorAddress: delegator_address,
|
||||
customValidatorAddress: validator_address,
|
||||
customAmount: Coin.fromPartial(amount),
|
||||
}),
|
||||
"/cosmos.staking.v1beta1.MsgDelegate": {
|
||||
aminoType: "cosmos-sdk/MsgDelegate",
|
||||
toAmino: ({
|
||||
customDelegatorAddress,
|
||||
customValidatorAddress,
|
||||
customAmount,
|
||||
}: CustomMsgDelegate): AminoMsgDelegate["value"] => {
|
||||
assert(customDelegatorAddress, "missing customDelegatorAddress");
|
||||
assert(customValidatorAddress, "missing validatorAddress");
|
||||
assert(customAmount, "missing amount");
|
||||
assert(customAmount.amount, "missing amount.amount");
|
||||
assert(customAmount.denom, "missing amount.denom");
|
||||
return {
|
||||
delegator_address: customDelegatorAddress,
|
||||
validator_address: customValidatorAddress,
|
||||
amount: {
|
||||
amount: customAmount.amount,
|
||||
denom: customAmount.denom,
|
||||
},
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
delegator_address,
|
||||
validator_address,
|
||||
amount,
|
||||
}: AminoMsgDelegate["value"]): CustomMsgDelegate => ({
|
||||
customDelegatorAddress: delegator_address,
|
||||
customValidatorAddress: validator_address,
|
||||
customAmount: Coin.fromPartial(amount),
|
||||
}),
|
||||
},
|
||||
});
|
||||
const options = {
|
||||
@ -921,6 +920,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
});
|
||||
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, {
|
||||
...defaultSigningClientOptions,
|
||||
aminoTypes: new AminoTypes(createStakingAminoConverters(wasmd.prefix)),
|
||||
prefix: wasmd.prefix,
|
||||
});
|
||||
|
||||
@ -1067,6 +1067,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
|
||||
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, {
|
||||
...defaultSigningClientOptions,
|
||||
aminoTypes: new AminoTypes(createStakingAminoConverters(wasmd.prefix)),
|
||||
prefix: wasmd.prefix,
|
||||
});
|
||||
|
||||
@ -1156,37 +1157,34 @@ describe("SigningCosmWasmClient", () => {
|
||||
};
|
||||
customRegistry.register(msgDelegateTypeUrl, CustomMsgDelegate);
|
||||
const customAminoTypes = new AminoTypes({
|
||||
prefix: "cosmos",
|
||||
additions: {
|
||||
"/cosmos.staking.v1beta1.MsgDelegate": {
|
||||
aminoType: "cosmos-sdk/MsgDelegate",
|
||||
toAmino: ({
|
||||
customDelegatorAddress,
|
||||
customValidatorAddress,
|
||||
customAmount,
|
||||
}: CustomMsgDelegate): AminoMsgDelegate["value"] => {
|
||||
assert(customDelegatorAddress, "missing customDelegatorAddress");
|
||||
assert(customValidatorAddress, "missing validatorAddress");
|
||||
assert(customAmount, "missing amount");
|
||||
return {
|
||||
delegator_address: customDelegatorAddress,
|
||||
validator_address: customValidatorAddress,
|
||||
amount: {
|
||||
amount: customAmount.amount,
|
||||
denom: customAmount.denom,
|
||||
},
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
delegator_address,
|
||||
validator_address,
|
||||
amount,
|
||||
}: AminoMsgDelegate["value"]): CustomMsgDelegate => ({
|
||||
customDelegatorAddress: delegator_address,
|
||||
customValidatorAddress: validator_address,
|
||||
customAmount: Coin.fromPartial(amount),
|
||||
}),
|
||||
"/cosmos.staking.v1beta1.MsgDelegate": {
|
||||
aminoType: "cosmos-sdk/MsgDelegate",
|
||||
toAmino: ({
|
||||
customDelegatorAddress,
|
||||
customValidatorAddress,
|
||||
customAmount,
|
||||
}: CustomMsgDelegate): AminoMsgDelegate["value"] => {
|
||||
assert(customDelegatorAddress, "missing customDelegatorAddress");
|
||||
assert(customValidatorAddress, "missing validatorAddress");
|
||||
assert(customAmount, "missing amount");
|
||||
return {
|
||||
delegator_address: customDelegatorAddress,
|
||||
validator_address: customValidatorAddress,
|
||||
amount: {
|
||||
amount: customAmount.amount,
|
||||
denom: customAmount.denom,
|
||||
},
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
delegator_address,
|
||||
validator_address,
|
||||
amount,
|
||||
}: AminoMsgDelegate["value"]): CustomMsgDelegate => ({
|
||||
customDelegatorAddress: delegator_address,
|
||||
customValidatorAddress: validator_address,
|
||||
customAmount: Coin.fromPartial(amount),
|
||||
}),
|
||||
},
|
||||
});
|
||||
const options = {
|
||||
@ -1226,6 +1224,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
});
|
||||
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, {
|
||||
...defaultSigningClientOptions,
|
||||
aminoTypes: new AminoTypes(createStakingAminoConverters(wasmd.prefix)),
|
||||
prefix: wasmd.prefix,
|
||||
});
|
||||
|
||||
|
||||
@ -17,6 +17,7 @@ import {
|
||||
AminoTypes,
|
||||
calculateFee,
|
||||
Coin,
|
||||
createBankAminoConverters,
|
||||
defaultRegistryTypes as defaultStargateTypes,
|
||||
DeliverTxResponse,
|
||||
GasPrice,
|
||||
@ -201,11 +202,9 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
options: SigningCosmWasmClientOptions,
|
||||
) {
|
||||
super(tmClient);
|
||||
// TODO: do we really want to set a default here? Ideally we could get it from the signer such that users only have to set it once.
|
||||
const prefix = options.prefix ?? "cosmos";
|
||||
const {
|
||||
registry = createDefaultRegistry(),
|
||||
aminoTypes = new AminoTypes({ prefix, additions: createWasmAminoConverters() }),
|
||||
aminoTypes = new AminoTypes({ ...createWasmAminoConverters(), ...createBankAminoConverters() }),
|
||||
} = options;
|
||||
this.registry = registry;
|
||||
this.aminoTypes = aminoTypes;
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
export interface AminoConverter {
|
||||
readonly aminoType: string;
|
||||
readonly toAmino: (value: any) => any;
|
||||
readonly fromAmino: (value: any) => any;
|
||||
}
|
||||
|
||||
/** A map from protobuf type URL to the AminoConverter implementation if supported on chain */
|
||||
export type AminoConverters = Record<string, AminoConverter | "not_supported_by_chain">;
|
||||
File diff suppressed because it is too large
Load Diff
@ -2,36 +2,14 @@
|
||||
import { AminoMsg } from "@cosmjs/amino";
|
||||
import { EncodeObject } from "@cosmjs/proto-signing";
|
||||
|
||||
import { AminoConverter, AminoConverters } from "./aminoconverters";
|
||||
import {
|
||||
createAuthzAminoConverters,
|
||||
createBankAminoConverters,
|
||||
createDistributionAminoConverters,
|
||||
createFreegrantAminoConverters,
|
||||
createGovAminoConverters,
|
||||
createIbcAminoConverters,
|
||||
createStakingAminoConverters,
|
||||
} from "./modules";
|
||||
|
||||
function createDefaultTypes(prefix: string): AminoConverters {
|
||||
return {
|
||||
...createAuthzAminoConverters(),
|
||||
...createBankAminoConverters(),
|
||||
...createDistributionAminoConverters(),
|
||||
...createGovAminoConverters(),
|
||||
...createStakingAminoConverters(prefix),
|
||||
...createIbcAminoConverters(),
|
||||
...createFreegrantAminoConverters(),
|
||||
};
|
||||
export interface AminoConverter {
|
||||
readonly aminoType: string;
|
||||
readonly toAmino: (value: any) => any;
|
||||
readonly fromAmino: (value: any) => any;
|
||||
}
|
||||
|
||||
export interface AminoTypesOptions {
|
||||
/**
|
||||
* The Bech32 address prefix of the chain you work with (also called Bech32 human-readable part).
|
||||
*/
|
||||
readonly prefix: string;
|
||||
readonly additions?: AminoConverters;
|
||||
}
|
||||
/** A map from protobuf type URL to the AminoConverter implementation if supported on chain */
|
||||
export type AminoConverters = Record<string, AminoConverter | "not_supported_by_chain">;
|
||||
|
||||
function isAminoConverter(
|
||||
converter: [string, AminoConverter | "not_supported_by_chain"],
|
||||
@ -50,9 +28,8 @@ export class AminoTypes {
|
||||
// there is no overlap when fromAmino is called.
|
||||
private readonly register: Record<string, AminoConverter | "not_supported_by_chain">;
|
||||
|
||||
public constructor({ prefix, additions = {} }: AminoTypesOptions) {
|
||||
const defaultTypes = createDefaultTypes(prefix);
|
||||
this.register = { ...defaultTypes, ...additions };
|
||||
public constructor(types: AminoConverters) {
|
||||
this.register = types;
|
||||
}
|
||||
|
||||
public toAmino({ typeUrl, value }: EncodeObject): AminoMsg {
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
export { Account, accountFromAny } from "./accounts";
|
||||
export { AminoConverter, AminoConverters } from "./aminoconverters";
|
||||
export { AminoTypes, AminoTypesOptions } from "./aminotypes";
|
||||
export { AminoConverter, AminoConverters, AminoTypes } from "./aminotypes";
|
||||
export { calculateFee, GasPrice } from "./fee";
|
||||
export * as logs from "./logs";
|
||||
export {
|
||||
@ -74,6 +73,15 @@ export {
|
||||
StakingExtension,
|
||||
TxExtension,
|
||||
} from "./modules";
|
||||
export {
|
||||
createAuthzAminoConverters,
|
||||
createBankAminoConverters,
|
||||
createDistributionAminoConverters,
|
||||
createFreegrantAminoConverters,
|
||||
createGovAminoConverters,
|
||||
createIbcAminoConverters,
|
||||
createStakingAminoConverters,
|
||||
} from "./modules";
|
||||
export { makeMultisignedTx } from "./multisignature";
|
||||
export {
|
||||
createPagination,
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { AminoConverters } from "../../aminoconverters";
|
||||
import { AminoConverters } from "../../aminotypes";
|
||||
|
||||
export function createAuthzAminoConverters(): AminoConverters {
|
||||
return {
|
||||
|
||||
118
packages/stargate/src/modules/bank/aminomessages.spec.ts
Normal file
118
packages/stargate/src/modules/bank/aminomessages.spec.ts
Normal file
@ -0,0 +1,118 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { coins } from "@cosmjs/proto-signing";
|
||||
import { MsgMultiSend, MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
|
||||
|
||||
import { AminoTypes } from "../../aminotypes";
|
||||
import { AminoMsgMultiSend, AminoMsgSend, createBankAminoConverters } from "./aminomessages";
|
||||
|
||||
describe("AminoTypes", () => {
|
||||
describe("toAmino", () => {
|
||||
it("works for MsgSend", () => {
|
||||
const msg: MsgSend = {
|
||||
fromAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
toAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
amount: coins(1234, "ucosm"),
|
||||
};
|
||||
const aminoTypes = new AminoTypes(createBankAminoConverters());
|
||||
const aminoMsg = aminoTypes.toAmino({
|
||||
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
|
||||
value: msg,
|
||||
});
|
||||
const expected: AminoMsgSend = {
|
||||
type: "cosmos-sdk/MsgSend",
|
||||
value: {
|
||||
from_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
to_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
amount: coins(1234, "ucosm"),
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
});
|
||||
|
||||
it("works for MsgMultiSend", () => {
|
||||
const msg: MsgMultiSend = {
|
||||
inputs: [
|
||||
{ address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", coins: coins(1234, "ucosm") },
|
||||
{ address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", coins: coins(5678, "ucosm") },
|
||||
],
|
||||
outputs: [
|
||||
{ address: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k", coins: coins(6000, "ucosm") },
|
||||
{ address: "cosmos142u9fgcjdlycfcez3lw8x6x5h7rfjlnfhpw2lx", coins: coins(912, "ucosm") },
|
||||
],
|
||||
};
|
||||
const aminoTypes = new AminoTypes(createBankAminoConverters());
|
||||
const aminoMsg = aminoTypes.toAmino({
|
||||
typeUrl: "/cosmos.bank.v1beta1.MsgMultiSend",
|
||||
value: msg,
|
||||
});
|
||||
const expected: AminoMsgMultiSend = {
|
||||
type: "cosmos-sdk/MsgMultiSend",
|
||||
value: {
|
||||
inputs: [
|
||||
{ address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", coins: coins(1234, "ucosm") },
|
||||
{ address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", coins: coins(5678, "ucosm") },
|
||||
],
|
||||
outputs: [
|
||||
{ address: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k", coins: coins(6000, "ucosm") },
|
||||
{ address: "cosmos142u9fgcjdlycfcez3lw8x6x5h7rfjlnfhpw2lx", coins: coins(912, "ucosm") },
|
||||
],
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe("fromAmino", () => {
|
||||
it("works for MsgSend", () => {
|
||||
const aminoMsg: AminoMsgSend = {
|
||||
type: "cosmos-sdk/MsgSend",
|
||||
value: {
|
||||
from_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
to_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
amount: coins(1234, "ucosm"),
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes(createBankAminoConverters()).fromAmino(aminoMsg);
|
||||
const expectedValue: MsgSend = {
|
||||
fromAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
toAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
amount: coins(1234, "ucosm"),
|
||||
};
|
||||
expect(msg).toEqual({
|
||||
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
|
||||
value: expectedValue,
|
||||
});
|
||||
});
|
||||
|
||||
it("works for MsgMultiSend", () => {
|
||||
const aminoMsg: AminoMsgMultiSend = {
|
||||
type: "cosmos-sdk/MsgMultiSend",
|
||||
value: {
|
||||
inputs: [
|
||||
{ address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", coins: coins(1234, "ucosm") },
|
||||
{ address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", coins: coins(5678, "ucosm") },
|
||||
],
|
||||
outputs: [
|
||||
{ address: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k", coins: coins(6000, "ucosm") },
|
||||
{ address: "cosmos142u9fgcjdlycfcez3lw8x6x5h7rfjlnfhpw2lx", coins: coins(912, "ucosm") },
|
||||
],
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes(createBankAminoConverters()).fromAmino(aminoMsg);
|
||||
const expectedValue: MsgMultiSend = {
|
||||
inputs: [
|
||||
{ address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", coins: coins(1234, "ucosm") },
|
||||
{ address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", coins: coins(5678, "ucosm") },
|
||||
],
|
||||
outputs: [
|
||||
{ address: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k", coins: coins(6000, "ucosm") },
|
||||
{ address: "cosmos142u9fgcjdlycfcez3lw8x6x5h7rfjlnfhpw2lx", coins: coins(912, "ucosm") },
|
||||
],
|
||||
};
|
||||
expect(msg).toEqual({
|
||||
typeUrl: "/cosmos.bank.v1beta1.MsgMultiSend",
|
||||
value: expectedValue,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -3,7 +3,7 @@ import { AminoMsg, Coin } from "@cosmjs/amino";
|
||||
import { MsgMultiSend, MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
|
||||
|
||||
// eslint-disable-next-line import/no-cycle
|
||||
import { AminoConverters } from "../../aminoconverters";
|
||||
import { AminoConverters } from "../../aminotypes";
|
||||
|
||||
/** A high level transaction of the coin module */
|
||||
export interface AminoMsgSend extends AminoMsg {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { AminoMsg } from "@cosmjs/amino";
|
||||
|
||||
import { AminoConverters } from "../../aminoconverters";
|
||||
import { AminoConverters } from "../../aminotypes";
|
||||
|
||||
// See https://github.com/cosmos/cosmos-sdk/blob/v0.45.1/proto/cosmos/crisis/v1beta1/tx.proto
|
||||
|
||||
|
||||
106
packages/stargate/src/modules/distribution/aminomessages.spec.ts
Normal file
106
packages/stargate/src/modules/distribution/aminomessages.spec.ts
Normal file
@ -0,0 +1,106 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { coins } from "@cosmjs/proto-signing";
|
||||
import {
|
||||
MsgFundCommunityPool,
|
||||
MsgSetWithdrawAddress,
|
||||
MsgWithdrawDelegatorReward,
|
||||
MsgWithdrawValidatorCommission,
|
||||
} from "cosmjs-types/cosmos/distribution/v1beta1/tx";
|
||||
|
||||
import { AminoTypes } from "../../aminotypes";
|
||||
import {
|
||||
AminoMsgFundCommunityPool,
|
||||
AminoMsgSetWithdrawAddress,
|
||||
AminoMsgWithdrawDelegatorReward,
|
||||
AminoMsgWithdrawValidatorCommission,
|
||||
createDistributionAminoConverters,
|
||||
} from "./aminomessages";
|
||||
|
||||
describe("AminoTypes", () => {
|
||||
describe("toAmino", () => {
|
||||
it("works for MsgFundCommunityPool", async () => {
|
||||
const msg: MsgFundCommunityPool = {
|
||||
amount: coins(1234, "ucosm"),
|
||||
depositor: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
};
|
||||
const aminoTypes = new AminoTypes(createDistributionAminoConverters());
|
||||
const aminoMsg = aminoTypes.toAmino({
|
||||
typeUrl: "/cosmos.distribution.v1beta1.MsgFundCommunityPool",
|
||||
value: msg,
|
||||
});
|
||||
const expected: AminoMsgFundCommunityPool = {
|
||||
type: "cosmos-sdk/MsgFundCommunityPool",
|
||||
value: {
|
||||
amount: coins(1234, "ucosm"),
|
||||
depositor: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
});
|
||||
|
||||
it("works for MsgSetWithdrawAddress", async () => {
|
||||
const msg: MsgSetWithdrawAddress = {
|
||||
delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
withdrawAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
};
|
||||
const aminoTypes = new AminoTypes(createDistributionAminoConverters());
|
||||
const aminoMsg = aminoTypes.toAmino({
|
||||
typeUrl: "/cosmos.distribution.v1beta1.MsgSetWithdrawAddress",
|
||||
value: msg,
|
||||
});
|
||||
const expected: AminoMsgSetWithdrawAddress = {
|
||||
type: "cosmos-sdk/MsgModifyWithdrawAddress",
|
||||
value: {
|
||||
delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
withdraw_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
});
|
||||
|
||||
it("works for MsgWithdrawDelegatorReward", async () => {
|
||||
const msg: MsgWithdrawDelegatorReward = {
|
||||
delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
};
|
||||
const aminoTypes = new AminoTypes(createDistributionAminoConverters());
|
||||
const aminoMsg = aminoTypes.toAmino({
|
||||
typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
|
||||
value: msg,
|
||||
});
|
||||
const expected: AminoMsgWithdrawDelegatorReward = {
|
||||
type: "cosmos-sdk/MsgWithdrawDelegationReward",
|
||||
value: {
|
||||
delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
validator_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
});
|
||||
|
||||
it("works for MsgWithdrawValidatorCommission", async () => {
|
||||
const msg: MsgWithdrawValidatorCommission = {
|
||||
validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
};
|
||||
const aminoTypes = new AminoTypes(createDistributionAminoConverters());
|
||||
const aminoMsg = aminoTypes.toAmino({
|
||||
typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission",
|
||||
value: msg,
|
||||
});
|
||||
const expected: AminoMsgWithdrawValidatorCommission = {
|
||||
type: "cosmos-sdk/MsgWithdrawValidatorCommission",
|
||||
value: {
|
||||
validator_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe("fromAmino", () => {
|
||||
// TODO: MsgFundCommunityPool
|
||||
// TODO: MsgSetWithdrawAddress
|
||||
// TODO: MsgWithdrawDelegatorReward
|
||||
// TODO: MsgWithdrawValidatorCommission
|
||||
});
|
||||
});
|
||||
@ -1,7 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { AminoMsg } from "@cosmjs/amino";
|
||||
|
||||
import { AminoConverters } from "../../aminoconverters";
|
||||
import { AminoConverters } from "../../aminotypes";
|
||||
|
||||
// See https://github.com/cosmos/cosmos-sdk/blob/v0.45.1/proto/cosmos/evidence/v1beta1/tx.proto
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { AminoConverters } from "../../aminoconverters";
|
||||
import { AminoConverters } from "../../aminotypes";
|
||||
|
||||
export function createFreegrantAminoConverters(): AminoConverters {
|
||||
return {
|
||||
|
||||
171
packages/stargate/src/modules/gov/aminomessages.spec.ts
Normal file
171
packages/stargate/src/modules/gov/aminomessages.spec.ts
Normal file
@ -0,0 +1,171 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { TextProposal, VoteOption } from "cosmjs-types/cosmos/gov/v1beta1/gov";
|
||||
import { MsgDeposit, MsgSubmitProposal, MsgVote } from "cosmjs-types/cosmos/gov/v1beta1/tx";
|
||||
import Long from "long";
|
||||
|
||||
import { AminoTypes } from "../../aminotypes";
|
||||
import {
|
||||
AminoMsgDeposit,
|
||||
AminoMsgSubmitProposal,
|
||||
AminoMsgVote,
|
||||
createGovAminoConverters,
|
||||
} from "./aminomessages";
|
||||
|
||||
describe("AminoTypes", () => {
|
||||
describe("toAmino", () => {
|
||||
it("works for MsgDeposit", () => {
|
||||
const msg: MsgDeposit = {
|
||||
amount: [{ amount: "12300000", denom: "ustake" }],
|
||||
depositor: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
proposalId: Long.fromNumber(5),
|
||||
};
|
||||
const aminoTypes = new AminoTypes(createGovAminoConverters());
|
||||
const aminoMsg = aminoTypes.toAmino({
|
||||
typeUrl: "/cosmos.gov.v1beta1.MsgDeposit",
|
||||
value: msg,
|
||||
});
|
||||
const expected: AminoMsgDeposit = {
|
||||
type: "cosmos-sdk/MsgDeposit",
|
||||
value: {
|
||||
amount: [{ amount: "12300000", denom: "ustake" }],
|
||||
depositor: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
proposal_id: "5",
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
});
|
||||
|
||||
it("works for MsgSubmitProposal", () => {
|
||||
const msg: MsgSubmitProposal = {
|
||||
initialDeposit: [{ amount: "12300000", denom: "ustake" }],
|
||||
proposer: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
content: {
|
||||
typeUrl: "/cosmos.gov.v1beta1.TextProposal",
|
||||
value: TextProposal.encode({
|
||||
description: "This proposal proposes to test whether this proposal passes",
|
||||
title: "Test Proposal",
|
||||
}).finish(),
|
||||
},
|
||||
};
|
||||
const aminoTypes = new AminoTypes(createGovAminoConverters());
|
||||
const aminoMsg = aminoTypes.toAmino({
|
||||
typeUrl: "/cosmos.gov.v1beta1.MsgSubmitProposal",
|
||||
value: msg,
|
||||
});
|
||||
const expected: AminoMsgSubmitProposal = {
|
||||
type: "cosmos-sdk/MsgSubmitProposal",
|
||||
value: {
|
||||
initial_deposit: [{ amount: "12300000", denom: "ustake" }],
|
||||
proposer: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
content: {
|
||||
type: "cosmos-sdk/TextProposal",
|
||||
value: {
|
||||
description: "This proposal proposes to test whether this proposal passes",
|
||||
title: "Test Proposal",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
});
|
||||
|
||||
it("works for MsgVote", () => {
|
||||
const msg: MsgVote = {
|
||||
option: VoteOption.VOTE_OPTION_NO_WITH_VETO,
|
||||
proposalId: Long.fromNumber(5),
|
||||
voter: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
};
|
||||
const aminoTypes = new AminoTypes(createGovAminoConverters());
|
||||
const aminoMsg = aminoTypes.toAmino({
|
||||
typeUrl: "/cosmos.gov.v1beta1.MsgVote",
|
||||
value: msg,
|
||||
});
|
||||
const expected: AminoMsgVote = {
|
||||
type: "cosmos-sdk/MsgVote",
|
||||
value: {
|
||||
option: 4,
|
||||
proposal_id: "5",
|
||||
voter: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe("fromAmino", () => {
|
||||
it("works for MsgDeposit", () => {
|
||||
const aminoMsg: AminoMsgDeposit = {
|
||||
type: "cosmos-sdk/MsgDeposit",
|
||||
value: {
|
||||
amount: [{ amount: "12300000", denom: "ustake" }],
|
||||
depositor: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
proposal_id: "5",
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes(createGovAminoConverters()).fromAmino(aminoMsg);
|
||||
const expectedValue: MsgDeposit = {
|
||||
amount: [{ amount: "12300000", denom: "ustake" }],
|
||||
depositor: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
proposalId: Long.fromNumber(5),
|
||||
};
|
||||
expect(msg).toEqual({
|
||||
typeUrl: "/cosmos.gov.v1beta1.MsgDeposit",
|
||||
value: expectedValue,
|
||||
});
|
||||
});
|
||||
|
||||
it("works for MsgSubmitProposal", () => {
|
||||
const aminoMsg: AminoMsgSubmitProposal = {
|
||||
type: "cosmos-sdk/MsgSubmitProposal",
|
||||
value: {
|
||||
initial_deposit: [{ amount: "12300000", denom: "ustake" }],
|
||||
proposer: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
content: {
|
||||
type: "cosmos-sdk/TextProposal",
|
||||
value: {
|
||||
description: "This proposal proposes to test whether this proposal passes",
|
||||
title: "Test Proposal",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes(createGovAminoConverters()).fromAmino(aminoMsg);
|
||||
const expectedValue: MsgSubmitProposal = {
|
||||
initialDeposit: [{ amount: "12300000", denom: "ustake" }],
|
||||
proposer: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
content: {
|
||||
typeUrl: "/cosmos.gov.v1beta1.TextProposal",
|
||||
value: TextProposal.encode({
|
||||
description: "This proposal proposes to test whether this proposal passes",
|
||||
title: "Test Proposal",
|
||||
}).finish(),
|
||||
},
|
||||
};
|
||||
expect(msg).toEqual({
|
||||
typeUrl: "/cosmos.gov.v1beta1.MsgSubmitProposal",
|
||||
value: expectedValue,
|
||||
});
|
||||
});
|
||||
|
||||
it("works for MsgVote", () => {
|
||||
const aminoMsg: AminoMsgVote = {
|
||||
type: "cosmos-sdk/MsgVote",
|
||||
value: {
|
||||
option: 4,
|
||||
proposal_id: "5",
|
||||
voter: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes(createGovAminoConverters()).fromAmino(aminoMsg);
|
||||
const expectedValue: MsgVote = {
|
||||
option: VoteOption.VOTE_OPTION_NO_WITH_VETO,
|
||||
proposalId: Long.fromNumber(5),
|
||||
voter: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
};
|
||||
expect(msg).toEqual({
|
||||
typeUrl: "/cosmos.gov.v1beta1.MsgVote",
|
||||
value: expectedValue,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -6,7 +6,7 @@ import { MsgDeposit, MsgSubmitProposal, MsgVote } from "cosmjs-types/cosmos/gov/
|
||||
import { Any } from "cosmjs-types/google/protobuf/any";
|
||||
import Long from "long";
|
||||
|
||||
import { AminoConverters } from "../../aminoconverters";
|
||||
import { AminoConverters } from "../../aminotypes";
|
||||
|
||||
/** Supports submitting arbitrary proposal content. */
|
||||
export interface AminoMsgSubmitProposal extends AminoMsg {
|
||||
|
||||
184
packages/stargate/src/modules/ibc/aminomessages.spec.ts
Normal file
184
packages/stargate/src/modules/ibc/aminomessages.spec.ts
Normal file
@ -0,0 +1,184 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { coin } from "@cosmjs/proto-signing";
|
||||
import { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx";
|
||||
import Long from "long";
|
||||
|
||||
import { AminoTypes } from "../../aminotypes";
|
||||
import { AminoMsgTransfer, createIbcAminoConverters } from "./aminomessages";
|
||||
|
||||
describe("AminoTypes", () => {
|
||||
describe("toAmino", () => {
|
||||
it("works for MsgTransfer", () => {
|
||||
const msg: MsgTransfer = {
|
||||
sourcePort: "testport",
|
||||
sourceChannel: "testchannel",
|
||||
token: coin(1234, "utest"),
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
timeoutHeight: {
|
||||
revisionHeight: Long.fromString("123", true),
|
||||
revisionNumber: Long.fromString("456", true),
|
||||
},
|
||||
timeoutTimestamp: Long.fromString("789", true),
|
||||
};
|
||||
const aminoTypes = new AminoTypes(createIbcAminoConverters());
|
||||
const aminoMsg = aminoTypes.toAmino({
|
||||
typeUrl: "/ibc.applications.transfer.v1.MsgTransfer",
|
||||
value: msg,
|
||||
});
|
||||
const expected: AminoMsgTransfer = {
|
||||
type: "cosmos-sdk/MsgTransfer",
|
||||
value: {
|
||||
source_port: "testport",
|
||||
source_channel: "testchannel",
|
||||
token: coin(1234, "utest"),
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
timeout_height: {
|
||||
revision_height: "123",
|
||||
revision_number: "456",
|
||||
},
|
||||
timeout_timestamp: "789",
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
});
|
||||
|
||||
it("works for MsgTransfer with empty values", () => {
|
||||
const msg: MsgTransfer = {
|
||||
sourcePort: "testport",
|
||||
sourceChannel: "testchannel",
|
||||
token: coin(1234, "utest"),
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
timeoutHeight: {
|
||||
revisionHeight: Long.UZERO,
|
||||
revisionNumber: Long.UZERO,
|
||||
},
|
||||
timeoutTimestamp: Long.UZERO,
|
||||
};
|
||||
const aminoTypes = new AminoTypes(createIbcAminoConverters());
|
||||
const aminoMsg = aminoTypes.toAmino({
|
||||
typeUrl: "/ibc.applications.transfer.v1.MsgTransfer",
|
||||
value: msg,
|
||||
});
|
||||
const expected: AminoMsgTransfer = {
|
||||
type: "cosmos-sdk/MsgTransfer",
|
||||
value: {
|
||||
source_port: "testport",
|
||||
source_channel: "testchannel",
|
||||
token: coin(1234, "utest"),
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
timeout_height: {
|
||||
revision_height: undefined,
|
||||
revision_number: undefined,
|
||||
},
|
||||
timeout_timestamp: undefined,
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
});
|
||||
|
||||
it("works for MsgTransfer with no height timeout", () => {
|
||||
const msg: MsgTransfer = {
|
||||
sourcePort: "testport",
|
||||
sourceChannel: "testchannel",
|
||||
token: coin(1234, "utest"),
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
timeoutHeight: undefined,
|
||||
timeoutTimestamp: Long.UZERO,
|
||||
};
|
||||
const aminoMsg = new AminoTypes(createIbcAminoConverters()).toAmino({
|
||||
typeUrl: "/ibc.applications.transfer.v1.MsgTransfer",
|
||||
value: msg,
|
||||
});
|
||||
const expected: AminoMsgTransfer = {
|
||||
type: "cosmos-sdk/MsgTransfer",
|
||||
value: {
|
||||
source_port: "testport",
|
||||
source_channel: "testchannel",
|
||||
token: coin(1234, "utest"),
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
timeout_height: {},
|
||||
timeout_timestamp: undefined,
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe("fromAmino", () => {
|
||||
it("works for MsgTransfer", () => {
|
||||
const aminoMsg: AminoMsgTransfer = {
|
||||
type: "cosmos-sdk/MsgTransfer",
|
||||
value: {
|
||||
source_port: "testport",
|
||||
source_channel: "testchannel",
|
||||
token: coin(1234, "utest"),
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
timeout_height: {
|
||||
revision_height: "123",
|
||||
revision_number: "456",
|
||||
},
|
||||
timeout_timestamp: "789",
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes(createIbcAminoConverters()).fromAmino(aminoMsg);
|
||||
const expectedValue: MsgTransfer = {
|
||||
sourcePort: "testport",
|
||||
sourceChannel: "testchannel",
|
||||
token: coin(1234, "utest"),
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
timeoutHeight: {
|
||||
revisionHeight: Long.fromString("123", true),
|
||||
revisionNumber: Long.fromString("456", true),
|
||||
},
|
||||
timeoutTimestamp: Long.fromString("789", true),
|
||||
};
|
||||
expect(msg).toEqual({
|
||||
typeUrl: "/ibc.applications.transfer.v1.MsgTransfer",
|
||||
value: expectedValue,
|
||||
});
|
||||
});
|
||||
|
||||
it("works for MsgTransfer with default values", () => {
|
||||
const aminoMsg: AminoMsgTransfer = {
|
||||
type: "cosmos-sdk/MsgTransfer",
|
||||
value: {
|
||||
source_port: "testport",
|
||||
source_channel: "testchannel",
|
||||
token: coin(1234, "utest"),
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
timeout_height: {
|
||||
// revision_height omitted
|
||||
// revision_number omitted
|
||||
},
|
||||
// timeout_timestamp omitted
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes(createIbcAminoConverters()).fromAmino(aminoMsg);
|
||||
const expectedValue: MsgTransfer = {
|
||||
sourcePort: "testport",
|
||||
sourceChannel: "testchannel",
|
||||
token: coin(1234, "utest"),
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
timeoutHeight: {
|
||||
revisionHeight: Long.UZERO,
|
||||
revisionNumber: Long.UZERO,
|
||||
},
|
||||
timeoutTimestamp: Long.UZERO,
|
||||
};
|
||||
expect(msg).toEqual({
|
||||
typeUrl: "/ibc.applications.transfer.v1.MsgTransfer",
|
||||
value: expectedValue,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -3,7 +3,7 @@ import { AminoMsg, Coin } from "@cosmjs/amino";
|
||||
import { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx";
|
||||
import Long from "long";
|
||||
|
||||
import { AminoConverters } from "../../aminoconverters";
|
||||
import { AminoConverters } from "../../aminotypes";
|
||||
|
||||
// https://github.com/cosmos/ibc-go/blob/07b6a97b67d17fd214a83764cbdb2c2c3daef445/modules/core/02-client/types/client.pb.go#L297-L312
|
||||
interface AminoHeight {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { AminoMsg } from "@cosmjs/amino";
|
||||
|
||||
import { AminoConverters } from "../../aminoconverters";
|
||||
import { AminoConverters } from "../../aminotypes";
|
||||
|
||||
// See https://github.com/cosmos/cosmos-sdk/blob/v0.45.1/proto/cosmos/slashing/v1beta1/tx.proto
|
||||
|
||||
|
||||
342
packages/stargate/src/modules/staking/aminomessages.spec.ts
Normal file
342
packages/stargate/src/modules/staking/aminomessages.spec.ts
Normal file
@ -0,0 +1,342 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { encodeBech32Pubkey } from "@cosmjs/amino";
|
||||
import { fromBase64 } from "@cosmjs/encoding";
|
||||
import { coin } from "@cosmjs/proto-signing";
|
||||
import {
|
||||
MsgBeginRedelegate,
|
||||
MsgCreateValidator,
|
||||
MsgDelegate,
|
||||
MsgEditValidator,
|
||||
MsgUndelegate,
|
||||
} from "cosmjs-types/cosmos/staking/v1beta1/tx";
|
||||
|
||||
import { AminoTypes } from "../../aminotypes";
|
||||
import {
|
||||
AminoMsgBeginRedelegate,
|
||||
AminoMsgCreateValidator,
|
||||
AminoMsgDelegate,
|
||||
AminoMsgEditValidator,
|
||||
AminoMsgUndelegate,
|
||||
createStakingAminoConverters,
|
||||
} from "./aminomessages";
|
||||
|
||||
describe("AminoTypes", () => {
|
||||
describe("toAmino", () => {
|
||||
it("works for MsgBeginRedelegate", () => {
|
||||
const msg: MsgBeginRedelegate = {
|
||||
delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
validatorSrcAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
validatorDstAddress: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
amount: coin(1234, "ucosm"),
|
||||
};
|
||||
const aminoTypes = new AminoTypes(createStakingAminoConverters("cosmos"));
|
||||
const aminoMsg = aminoTypes.toAmino({
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgBeginRedelegate",
|
||||
value: msg,
|
||||
});
|
||||
const expected: AminoMsgBeginRedelegate = {
|
||||
type: "cosmos-sdk/MsgBeginRedelegate",
|
||||
value: {
|
||||
delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
validator_src_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
validator_dst_address: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
amount: coin(1234, "ucosm"),
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
});
|
||||
|
||||
it("works for MsgCreateValidator", () => {
|
||||
const msg: MsgCreateValidator = {
|
||||
description: {
|
||||
moniker: "validator",
|
||||
identity: "me",
|
||||
website: "valid.com",
|
||||
securityContact: "Hamburglar",
|
||||
details: "...",
|
||||
},
|
||||
commission: {
|
||||
rate: "0.2",
|
||||
maxRate: "0.3",
|
||||
maxChangeRate: "0.1",
|
||||
},
|
||||
minSelfDelegation: "123",
|
||||
delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
pubkey: {
|
||||
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
|
||||
value: fromBase64("A08EGB7ro1ORuFhjOnZcSgwYlpe0DSFjVNUIkNNQxwKQ"),
|
||||
},
|
||||
value: coin(1234, "ucosm"),
|
||||
};
|
||||
const aminoTypes = new AminoTypes(createStakingAminoConverters("cosmos"));
|
||||
const aminoMsg = aminoTypes.toAmino({
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgCreateValidator",
|
||||
value: msg,
|
||||
});
|
||||
const expected: AminoMsgCreateValidator = {
|
||||
type: "cosmos-sdk/MsgCreateValidator",
|
||||
value: {
|
||||
description: {
|
||||
moniker: "validator",
|
||||
identity: "me",
|
||||
website: "valid.com",
|
||||
security_contact: "Hamburglar",
|
||||
details: "...",
|
||||
},
|
||||
commission: {
|
||||
rate: "0.2",
|
||||
max_rate: "0.3",
|
||||
max_change_rate: "0.1",
|
||||
},
|
||||
min_self_delegation: "123",
|
||||
delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
validator_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
pubkey: encodeBech32Pubkey(
|
||||
{ type: "tendermint/PubKeySecp256k1", value: "A08EGB7ro1ORuFhjOnZcSgwYlpe0DSFjVNUIkNNQxwKQ" },
|
||||
"cosmos",
|
||||
),
|
||||
value: coin(1234, "ucosm"),
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
});
|
||||
|
||||
it("works for MsgDelegate", () => {
|
||||
const msg: MsgDelegate = {
|
||||
delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
amount: coin(1234, "ucosm"),
|
||||
};
|
||||
const aminoTypes = new AminoTypes(createStakingAminoConverters("cosmos"));
|
||||
const aminoMsg = aminoTypes.toAmino({
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
|
||||
value: msg,
|
||||
});
|
||||
const expected: AminoMsgDelegate = {
|
||||
type: "cosmos-sdk/MsgDelegate",
|
||||
value: {
|
||||
delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
validator_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
amount: coin(1234, "ucosm"),
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
});
|
||||
|
||||
it("works for MsgEditValidator", () => {
|
||||
const msg: MsgEditValidator = {
|
||||
description: {
|
||||
moniker: "validator",
|
||||
identity: "me",
|
||||
website: "valid.com",
|
||||
securityContact: "Hamburglar",
|
||||
details: "...",
|
||||
},
|
||||
commissionRate: "0.2",
|
||||
minSelfDelegation: "123",
|
||||
validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
};
|
||||
const aminoTypes = new AminoTypes(createStakingAminoConverters("cosmos"));
|
||||
const aminoMsg = aminoTypes.toAmino({
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgEditValidator",
|
||||
value: msg,
|
||||
});
|
||||
const expected: AminoMsgEditValidator = {
|
||||
type: "cosmos-sdk/MsgEditValidator",
|
||||
value: {
|
||||
description: {
|
||||
moniker: "validator",
|
||||
identity: "me",
|
||||
website: "valid.com",
|
||||
security_contact: "Hamburglar",
|
||||
details: "...",
|
||||
},
|
||||
commission_rate: "0.2",
|
||||
min_self_delegation: "123",
|
||||
validator_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
});
|
||||
|
||||
it("works for MsgUndelegate", () => {
|
||||
const msg: MsgUndelegate = {
|
||||
delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
amount: coin(1234, "ucosm"),
|
||||
};
|
||||
const aminoTypes = new AminoTypes(createStakingAminoConverters("cosmos"));
|
||||
const aminoMsg = aminoTypes.toAmino({
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgUndelegate",
|
||||
value: msg,
|
||||
});
|
||||
const expected: AminoMsgUndelegate = {
|
||||
type: "cosmos-sdk/MsgUndelegate",
|
||||
value: {
|
||||
delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
validator_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
amount: coin(1234, "ucosm"),
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe("fromAmino", () => {
|
||||
it("works for MsgBeginRedelegate", () => {
|
||||
const aminoMsg: AminoMsgBeginRedelegate = {
|
||||
type: "cosmos-sdk/MsgBeginRedelegate",
|
||||
value: {
|
||||
delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
validator_src_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
validator_dst_address: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
amount: coin(1234, "ucosm"),
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes(createStakingAminoConverters("cosmos")).fromAmino(aminoMsg);
|
||||
const expectedValue: MsgBeginRedelegate = {
|
||||
delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
validatorSrcAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
validatorDstAddress: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
amount: coin(1234, "ucosm"),
|
||||
};
|
||||
expect(msg).toEqual({
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgBeginRedelegate",
|
||||
value: expectedValue,
|
||||
});
|
||||
});
|
||||
|
||||
it("works for MsgCreateValidator", () => {
|
||||
const aminoMsg: AminoMsgCreateValidator = {
|
||||
type: "cosmos-sdk/MsgCreateValidator",
|
||||
value: {
|
||||
description: {
|
||||
moniker: "validator",
|
||||
identity: "me",
|
||||
website: "valid.com",
|
||||
security_contact: "Hamburglar",
|
||||
details: "...",
|
||||
},
|
||||
commission: {
|
||||
rate: "0.2",
|
||||
max_rate: "0.3",
|
||||
max_change_rate: "0.1",
|
||||
},
|
||||
min_self_delegation: "123",
|
||||
delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
validator_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
pubkey: encodeBech32Pubkey(
|
||||
{ type: "tendermint/PubKeySecp256k1", value: "A08EGB7ro1ORuFhjOnZcSgwYlpe0DSFjVNUIkNNQxwKQ" },
|
||||
"cosmos",
|
||||
),
|
||||
value: coin(1234, "ucosm"),
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes(createStakingAminoConverters("cosmos")).fromAmino(aminoMsg);
|
||||
const expectedValue: MsgCreateValidator = {
|
||||
description: {
|
||||
moniker: "validator",
|
||||
identity: "me",
|
||||
website: "valid.com",
|
||||
securityContact: "Hamburglar",
|
||||
details: "...",
|
||||
},
|
||||
commission: {
|
||||
rate: "0.2",
|
||||
maxRate: "0.3",
|
||||
maxChangeRate: "0.1",
|
||||
},
|
||||
minSelfDelegation: "123",
|
||||
delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
pubkey: {
|
||||
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
|
||||
value: fromBase64("A08EGB7ro1ORuFhjOnZcSgwYlpe0DSFjVNUIkNNQxwKQ"),
|
||||
},
|
||||
value: coin(1234, "ucosm"),
|
||||
};
|
||||
expect(msg).toEqual({
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgCreateValidator",
|
||||
value: expectedValue,
|
||||
});
|
||||
});
|
||||
|
||||
it("works for MsgDelegate", () => {
|
||||
const aminoMsg: AminoMsgDelegate = {
|
||||
type: "cosmos-sdk/MsgDelegate",
|
||||
value: {
|
||||
delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
validator_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
amount: coin(1234, "ucosm"),
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes(createStakingAminoConverters("cosmos")).fromAmino(aminoMsg);
|
||||
const expectedValue: MsgDelegate = {
|
||||
delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
amount: coin(1234, "ucosm"),
|
||||
};
|
||||
expect(msg).toEqual({
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
|
||||
value: expectedValue,
|
||||
});
|
||||
});
|
||||
|
||||
it("works for MsgEditValidator", () => {
|
||||
const aminoMsg: AminoMsgEditValidator = {
|
||||
type: "cosmos-sdk/MsgEditValidator",
|
||||
value: {
|
||||
description: {
|
||||
moniker: "validator",
|
||||
identity: "me",
|
||||
website: "valid.com",
|
||||
security_contact: "Hamburglar",
|
||||
details: "...",
|
||||
},
|
||||
commission_rate: "0.2",
|
||||
min_self_delegation: "123",
|
||||
validator_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes(createStakingAminoConverters("cosmos")).fromAmino(aminoMsg);
|
||||
const expectedValue: MsgEditValidator = {
|
||||
description: {
|
||||
moniker: "validator",
|
||||
identity: "me",
|
||||
website: "valid.com",
|
||||
securityContact: "Hamburglar",
|
||||
details: "...",
|
||||
},
|
||||
commissionRate: "0.2",
|
||||
minSelfDelegation: "123",
|
||||
validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
};
|
||||
expect(msg).toEqual({
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgEditValidator",
|
||||
value: expectedValue,
|
||||
});
|
||||
});
|
||||
|
||||
it("works for MsgUndelegate", () => {
|
||||
const aminoMsg: AminoMsgUndelegate = {
|
||||
type: "cosmos-sdk/MsgUndelegate",
|
||||
value: {
|
||||
delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
validator_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
amount: coin(1234, "ucosm"),
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes(createStakingAminoConverters("cosmos")).fromAmino(aminoMsg);
|
||||
const expectedValue: MsgUndelegate = {
|
||||
delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
amount: coin(1234, "ucosm"),
|
||||
};
|
||||
expect(msg).toEqual({
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgUndelegate",
|
||||
value: expectedValue,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -483,37 +483,34 @@ describe("SigningStargateClient", () => {
|
||||
};
|
||||
customRegistry.register(msgDelegateTypeUrl, CustomMsgDelegate);
|
||||
const customAminoTypes = new AminoTypes({
|
||||
prefix: "cosmos",
|
||||
additions: {
|
||||
"/cosmos.staking.v1beta1.MsgDelegate": {
|
||||
aminoType: "cosmos-sdk/MsgDelegate",
|
||||
toAmino: ({
|
||||
customDelegatorAddress,
|
||||
customValidatorAddress,
|
||||
customAmount,
|
||||
}: CustomMsgDelegate): AminoMsgDelegate["value"] => {
|
||||
assert(customDelegatorAddress, "missing customDelegatorAddress");
|
||||
assert(customValidatorAddress, "missing validatorAddress");
|
||||
assert(customAmount, "missing amount");
|
||||
return {
|
||||
delegator_address: customDelegatorAddress,
|
||||
validator_address: customValidatorAddress,
|
||||
amount: {
|
||||
amount: customAmount.amount,
|
||||
denom: customAmount.denom,
|
||||
},
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
delegator_address,
|
||||
validator_address,
|
||||
amount,
|
||||
}: AminoMsgDelegate["value"]): CustomMsgDelegate => ({
|
||||
customDelegatorAddress: delegator_address,
|
||||
customValidatorAddress: validator_address,
|
||||
customAmount: Coin.fromPartial(amount),
|
||||
}),
|
||||
"/cosmos.staking.v1beta1.MsgDelegate": {
|
||||
aminoType: "cosmos-sdk/MsgDelegate",
|
||||
toAmino: ({
|
||||
customDelegatorAddress,
|
||||
customValidatorAddress,
|
||||
customAmount,
|
||||
}: CustomMsgDelegate): AminoMsgDelegate["value"] => {
|
||||
assert(customDelegatorAddress, "missing customDelegatorAddress");
|
||||
assert(customValidatorAddress, "missing validatorAddress");
|
||||
assert(customAmount, "missing amount");
|
||||
return {
|
||||
delegator_address: customDelegatorAddress,
|
||||
validator_address: customValidatorAddress,
|
||||
amount: {
|
||||
amount: customAmount.amount,
|
||||
denom: customAmount.denom,
|
||||
},
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
delegator_address,
|
||||
validator_address,
|
||||
amount,
|
||||
}: AminoMsgDelegate["value"]): CustomMsgDelegate => ({
|
||||
customDelegatorAddress: delegator_address,
|
||||
customValidatorAddress: validator_address,
|
||||
customAmount: Coin.fromPartial(amount),
|
||||
}),
|
||||
},
|
||||
});
|
||||
const options = {
|
||||
@ -774,37 +771,34 @@ describe("SigningStargateClient", () => {
|
||||
};
|
||||
customRegistry.register(msgDelegateTypeUrl, CustomMsgDelegate);
|
||||
const customAminoTypes = new AminoTypes({
|
||||
prefix: "cosmos",
|
||||
additions: {
|
||||
"/cosmos.staking.v1beta1.MsgDelegate": {
|
||||
aminoType: "cosmos-sdk/MsgDelegate",
|
||||
toAmino: ({
|
||||
customDelegatorAddress,
|
||||
customValidatorAddress,
|
||||
customAmount,
|
||||
}: CustomMsgDelegate): AminoMsgDelegate["value"] => {
|
||||
assert(customDelegatorAddress, "missing customDelegatorAddress");
|
||||
assert(customValidatorAddress, "missing validatorAddress");
|
||||
assert(customAmount, "missing amount");
|
||||
return {
|
||||
delegator_address: customDelegatorAddress,
|
||||
validator_address: customValidatorAddress,
|
||||
amount: {
|
||||
amount: customAmount.amount,
|
||||
denom: customAmount.denom,
|
||||
},
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
delegator_address,
|
||||
validator_address,
|
||||
amount,
|
||||
}: AminoMsgDelegate["value"]): CustomMsgDelegate => ({
|
||||
customDelegatorAddress: delegator_address,
|
||||
customValidatorAddress: validator_address,
|
||||
customAmount: Coin.fromPartial(amount),
|
||||
}),
|
||||
"/cosmos.staking.v1beta1.MsgDelegate": {
|
||||
aminoType: "cosmos-sdk/MsgDelegate",
|
||||
toAmino: ({
|
||||
customDelegatorAddress,
|
||||
customValidatorAddress,
|
||||
customAmount,
|
||||
}: CustomMsgDelegate): AminoMsgDelegate["value"] => {
|
||||
assert(customDelegatorAddress, "missing customDelegatorAddress");
|
||||
assert(customValidatorAddress, "missing validatorAddress");
|
||||
assert(customAmount, "missing amount");
|
||||
return {
|
||||
delegator_address: customDelegatorAddress,
|
||||
validator_address: customValidatorAddress,
|
||||
amount: {
|
||||
amount: customAmount.amount,
|
||||
denom: customAmount.denom,
|
||||
},
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
delegator_address,
|
||||
validator_address,
|
||||
amount,
|
||||
}: AminoMsgDelegate["value"]): CustomMsgDelegate => ({
|
||||
customDelegatorAddress: delegator_address,
|
||||
customValidatorAddress: validator_address,
|
||||
customAmount: Coin.fromPartial(amount),
|
||||
}),
|
||||
},
|
||||
});
|
||||
const options = {
|
||||
|
||||
@ -23,7 +23,7 @@ import { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx";
|
||||
import { Height } from "cosmjs-types/ibc/core/client/v1/client";
|
||||
import Long from "long";
|
||||
|
||||
import { AminoTypes } from "./aminotypes";
|
||||
import { AminoConverters, AminoTypes } from "./aminotypes";
|
||||
import { calculateFee, GasPrice } from "./fee";
|
||||
import {
|
||||
authzTypes,
|
||||
@ -39,6 +39,15 @@ import {
|
||||
MsgWithdrawDelegatorRewardEncodeObject,
|
||||
stakingTypes,
|
||||
} from "./modules";
|
||||
import {
|
||||
createAuthzAminoConverters,
|
||||
createBankAminoConverters,
|
||||
createDistributionAminoConverters,
|
||||
createFreegrantAminoConverters,
|
||||
createGovAminoConverters,
|
||||
createIbcAminoConverters,
|
||||
createStakingAminoConverters,
|
||||
} from "./modules";
|
||||
import { DeliverTxResponse, StargateClient } from "./stargateclient";
|
||||
|
||||
export const defaultRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [
|
||||
@ -81,6 +90,18 @@ export interface SigningStargateClientOptions {
|
||||
readonly gasPrice?: GasPrice;
|
||||
}
|
||||
|
||||
function createDefaultTypes(prefix: string): AminoConverters {
|
||||
return {
|
||||
...createAuthzAminoConverters(),
|
||||
...createBankAminoConverters(),
|
||||
...createDistributionAminoConverters(),
|
||||
...createGovAminoConverters(),
|
||||
...createStakingAminoConverters(prefix),
|
||||
...createIbcAminoConverters(),
|
||||
...createFreegrantAminoConverters(),
|
||||
};
|
||||
}
|
||||
|
||||
export class SigningStargateClient extends StargateClient {
|
||||
public readonly registry: Registry;
|
||||
public readonly broadcastTimeoutMs: number | undefined;
|
||||
@ -123,7 +144,8 @@ export class SigningStargateClient extends StargateClient {
|
||||
super(tmClient);
|
||||
// TODO: do we really want to set a default here? Ideally we could get it from the signer such that users only have to set it once.
|
||||
const prefix = options.prefix ?? "cosmos";
|
||||
const { registry = createDefaultRegistry(), aminoTypes = new AminoTypes({ prefix }) } = options;
|
||||
const { registry = createDefaultRegistry(), aminoTypes = new AminoTypes(createDefaultTypes(prefix)) } =
|
||||
options;
|
||||
this.registry = registry;
|
||||
this.aminoTypes = aminoTypes;
|
||||
this.signer = signer;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user