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

add crisis/MsgVerifyInvariant #243

Merged
merged 1 commit into from
Mar 26, 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
25 changes: 25 additions & 0 deletions integration-tests/decodeMsgVerifyInvariant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { LCDClient, MsgSend, MnemonicKey } from '../src';
import { SignMode } from '@terra-money/terra.proto/cosmos/tx/signing/v1beta1/signing';
import { TxBody } from '@terra-money/terra.proto/cosmos/tx/v1beta1/tx';

async function main() {
const bombay = new LCDClient({
chainID: 'bombay-12',
URL: 'https://bombay-lcd.terra.dev',
gasPrices: { uusd: 0.15 },
});

(await bombay.tx.txInfosByHeight(8152638)).
map((tx) => {
console.log(JSON.stringify(tx));
});


(await bombay.tx.txInfosByHeight(8153558)).
map((tx) => {
console.log(JSON.stringify(tx));
});

}

main().catch(console.error);
26 changes: 22 additions & 4 deletions src/core/Msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import {
MsgTimeoutOnClose,
IbcChannelMsg,
} from './ibc/msgs/channel';
import { MsgVerifyInvariant, CrisisMsg } from './crisis';
import { Any } from '@terra-money/terra.proto/google/protobuf/any';

export type Msg =
Expand All @@ -94,7 +95,8 @@ export type Msg =
| IbcTransferMsg
| IbcClientMsg
| IbcConnectionMsg
| IbcChannelMsg;
| IbcChannelMsg
| CrisisMsg;

export namespace Msg {
export type Amino =
Expand All @@ -108,7 +110,8 @@ export namespace Msg {
| SlashingMsg.Amino
| StakingMsg.Amino
| WasmMsg.Amino
| IbcTransferMsg.Amino;
| IbcTransferMsg.Amino
| CrisisMsg.Amino;

export type Data =
| BankMsg.Data
Expand All @@ -124,7 +127,8 @@ export namespace Msg {
| IbcTransferMsg.Data
| IbcClientMsg.Data
| IbcConnectionMsg.Data
| IbcChannelMsg.Data;
| IbcChannelMsg.Data
| CrisisMsg.Data;

export type Proto =
| BankMsg.Proto
Expand All @@ -140,7 +144,8 @@ export namespace Msg {
| IbcTransferMsg.Proto
| IbcClientMsg.Proto
| IbcConnectionMsg.Proto
| IbcChannelMsg.Proto;
| IbcChannelMsg.Proto
| CrisisMsg.Proto;

export function fromAmino(data: Msg.Amino): Msg {
switch (data.type) {
Expand Down Expand Up @@ -233,6 +238,10 @@ export namespace Msg {
// ibc-transfer
case 'cosmos-sdk/MsgTransfer':
return MsgTransfer.fromAmino(data);

// crisis
case 'crisis/MsgVerifyInvariant':
return MsgVerifyInvariant.fromAmino(data);
}
}
export function fromData(data: Msg.Data): Msg {
Expand Down Expand Up @@ -368,6 +377,10 @@ export namespace Msg {
return MsgTimeout.fromData(data);
case '/ibc.core.channel.v1.MsgTimeoutOnClose':
return MsgTimeoutOnClose.fromData(data);

// crisis
case '/cosmos.crisis.v1beta1.MsgVerifyInvariant':
return MsgVerifyInvariant.fromData(data);
}
}

Expand Down Expand Up @@ -502,6 +515,11 @@ export namespace Msg {
return MsgTimeout.unpackAny(proto);
case '/ibc.core.channel.v1.MsgTimeoutOnClose':
return MsgTimeoutOnClose.unpackAny(proto);

// crisis
case '/cosmos.crisis.v1beta1.MsgVerifyInvariant':
return MsgVerifyInvariant.unpackAny(proto);

default:
throw Error(`not supported msg ${proto.typeUrl}`);
}
Expand Down
51 changes: 51 additions & 0 deletions src/core/crisis/MsgVerifyInvariant.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { MsgVerifyInvariant } from './MsgVerifyInvariant';

describe('MsgVerifyInvariant', () => {
it('deserialize correctly', () => {
const send = MsgVerifyInvariant.fromAmino({
type: 'crisis/MsgVerifyInvariant',
value: {
sender: 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
invariantModuleName: 'bank',
invariantRoute: 'nonnegative-outstanding-supply',
},
});

expect(send).toMatchObject({
sender: 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
invariantModuleName: 'bank',
invariantRoute: 'nonnegative-outstanding-supply',
});

expect(send.toAmino()).toMatchObject({
type: 'crisis/MsgVerifyInvariant',
value: {
sender: 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
invariantModuleName: 'bank',
invariantRoute: 'nonnegative-outstanding-supply',
},
});
});

it('deserialize correctly proto', () => {
const send = MsgVerifyInvariant.fromData({
'@type': '/cosmos.crisis.v1beta1.MsgVerifyInvariant',
sender: 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
invariantModuleName: 'bank',
invariantRoute: 'nonnegative-outstanding-supply',
});

expect(send).toMatchObject({
sender: 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
invariantModuleName: 'bank',
invariantRoute: 'nonnegative-outstanding-supply',
});

expect(send.toData()).toMatchObject({
'@type': '/cosmos.crisis.v1beta1.MsgVerifyInvariant',
sender: 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
invariantModuleName: 'bank',
invariantRoute: 'nonnegative-outstanding-supply',
});
});
});
111 changes: 111 additions & 0 deletions src/core/crisis/MsgVerifyInvariant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { JSONSerializable } from '../../util/json';
import { Any } from '@terra-money/terra.proto/google/protobuf/any';
import { MsgVerifyInvariant as MsgVerifyInvariant_pb } from '@terra-money/terra.proto/cosmos/crisis/v1beta1/tx';
import { AccAddress } from '../bech32';

/**
* MsgVerifyInvariant represents a message to verify a particular invariance.
*/
export class MsgVerifyInvariant extends JSONSerializable<
MsgVerifyInvariant.Amino,
MsgVerifyInvariant.Data,
MsgVerifyInvariant.Proto
> {
/**
* @param sender sender's address
* @param invariantModuleName module name to verify invariant
* @param invariantRoute route to verify
*/
constructor(
public sender: AccAddress,
public invariantModuleName: string,
public invariantRoute: string
) {
super();
}

public static fromAmino(data: MsgVerifyInvariant.Amino): MsgVerifyInvariant {
const {
value: { sender, invariantModuleName, invariantRoute },
} = data;
return new MsgVerifyInvariant(sender, invariantModuleName, invariantRoute);
}

public toAmino(): MsgVerifyInvariant.Amino {
const { sender, invariantModuleName, invariantRoute } = this;
return {
type: 'crisis/MsgVerifyInvariant',
value: {
sender,
invariantModuleName,
invariantRoute,
},
};
}

public static fromData(data: MsgVerifyInvariant.Data): MsgVerifyInvariant {
const { sender, invariantModuleName, invariantRoute } = data;

return new MsgVerifyInvariant(sender, invariantModuleName, invariantRoute);
}

public toData(): MsgVerifyInvariant.Data {
const { sender, invariantModuleName, invariantRoute } = this;
return {
'@type': '/cosmos.crisis.v1beta1.MsgVerifyInvariant',
sender,
invariantModuleName,
invariantRoute,
};
}

public static fromProto(proto: MsgVerifyInvariant.Proto): MsgVerifyInvariant {
return new MsgVerifyInvariant(
proto.sender,
proto.invariantModuleName,
proto.invariantRoute
);
}

public toProto(): MsgVerifyInvariant.Proto {
const { sender, invariantModuleName, invariantRoute } = this;
return MsgVerifyInvariant_pb.fromPartial({
sender,
invariantModuleName,
invariantRoute,
});
}

public packAny(): Any {
return Any.fromPartial({
typeUrl: '/cosmos.crisis.v1beta1.MsgVerifyInvariant',
value: MsgVerifyInvariant_pb.encode(this.toProto()).finish(),
});
}

public static unpackAny(msgAny: Any): MsgVerifyInvariant {
return MsgVerifyInvariant.fromProto(
MsgVerifyInvariant_pb.decode(msgAny.value)
);
}
}

export namespace MsgVerifyInvariant {
export interface Amino {
type: 'crisis/MsgVerifyInvariant';
value: {
sender: AccAddress;
invariantModuleName: string;
invariantRoute: string;
};
}

export interface Data {
'@type': '/cosmos.crisis.v1beta1.MsgVerifyInvariant';
sender: AccAddress;
invariantModuleName: string;
invariantRoute: string;
}

export type Proto = MsgVerifyInvariant_pb;
}
10 changes: 10 additions & 0 deletions src/core/crisis/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { MsgVerifyInvariant } from './MsgVerifyInvariant';

export * from './MsgVerifyInvariant';

export type CrisisMsg = MsgVerifyInvariant;
export namespace CrisisMsg {
export type Amino = MsgVerifyInvariant.Amino;
export type Data = MsgVerifyInvariant.Data;
export type Proto = MsgVerifyInvariant.Proto;
}