feat: add unittest for MsgCancelUnbondingDelegation

This commit is contained in:
fibonacci998 2023-12-26 11:03:52 +07:00
parent 9712967d50
commit 1b05778342
2 changed files with 53 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import { coin } from "@cosmjs/proto-signing";
import { PubKey as CosmosCryptoSecp256k1Pubkey } from "cosmjs-types/cosmos/crypto/secp256k1/keys";
import {
MsgBeginRedelegate,
MsgCancelUnbondingDelegation,
MsgCreateValidator,
MsgDelegate,
MsgEditValidator,
@ -13,6 +14,7 @@ import {
import { AminoTypes } from "../../aminotypes";
import {
AminoMsgBeginRedelegate,
AminoMsgCancelUnbondingDelegation,
AminoMsgCreateValidator,
AminoMsgDelegate,
AminoMsgEditValidator,
@ -199,6 +201,30 @@ describe("AminoTypes", () => {
};
expect(aminoMsg).toEqual(expected);
});
it("works for MsgCancelUnbondingDelegation", () => {
const msg: MsgCancelUnbondingDelegation = {
delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
amount: coin(1234, "ucosm"),
creationHeight: BigInt("1"),
};
const aminoTypes = new AminoTypes(createStakingAminoConverters());
const aminoMsg = aminoTypes.toAmino({
typeUrl: "/cosmos.staking.v1beta1.MsgCancelUnbondingDelegation",
value: msg,
});
const expected: AminoMsgCancelUnbondingDelegation = {
type: "cosmos-sdk/MsgCancelUnbondingDelegation",
value: {
delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
validator_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
amount: coin(1234, "ucosm"),
creation_height: BigInt("1"),
},
};
expect(aminoMsg).toEqual(expected);
});
});
describe("fromAmino", () => {
@ -362,5 +388,28 @@ describe("AminoTypes", () => {
value: expectedValue,
});
});
it("works for MsgCancelUnbondingDelegation", () => {
const aminoMsg: AminoMsgCancelUnbondingDelegation = {
type: "cosmos-sdk/MsgCancelUnbondingDelegation",
value: {
delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
validator_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
amount: coin(1234, "ucosm"),
creation_height: BigInt("1"),
},
};
const msg = new AminoTypes(createStakingAminoConverters()).fromAmino(aminoMsg);
const expectedValue: MsgCancelUnbondingDelegation = {
delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
amount: coin(1234, "ucosm"),
creationHeight: BigInt("1"),
};
expect(msg).toEqual({
typeUrl: "/cosmos.staking.v1beta1.MsgCancelUnbondingDelegation",
value: expectedValue,
});
});
});
});

View File

@ -150,7 +150,7 @@ export interface AminoMsgCancelUnbondingDelegation extends AminoMsg {
readonly delegator_address: string;
readonly validator_address: string;
readonly amount: Coin;
readonly creation_height: string;
readonly creation_height: bigint;
};
}
@ -363,10 +363,10 @@ export function createStakingAminoConverters(): Record<string, AminoConverter> {
amount,
creation_height,
}: AminoMsgCancelUnbondingDelegation["value"]): MsgCancelUnbondingDelegation => ({
delegator_address: delegator_address,
validator_address: validator_address,
delegatorAddress: delegator_address,
validatorAddress: validator_address,
amount: amount,
creation_height: creation_height,
creationHeight: creation_height,
}),
},
};