Skip to content

Commit

Permalink
add crisis/MsgVerifyInvariant
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoff Lee authored and hanjukim committed Mar 26, 2022
1 parent 3608415 commit c677df4
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 4 deletions.
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;
}

0 comments on commit c677df4

Please sign in to comment.