Skip to content

Commit

Permalink
Keeping message name consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
cdc-Hitesh committed Nov 22, 2022
1 parent 9571b96 commit a67a7c1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/src/core/cro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { MsgConnectionOpenConfirmIBC } from '../transaction/msg/ibc/core/connect
import { MsgConnectionOpenTryIBC } from '../transaction/msg/ibc/core/connection/MsgConnectionOpenTry';
import { msgCreateVestingAccount } from '../transaction/msg/account/MsgCreateVestingAccount';
import { delayedVestingAccount } from '../transaction/msg/account/DelayedVestingAccount';
import { msgUnjail } from '../transaction/msg/slashing/MsgUnjail';
import { msgUnjailV2 } from '../transaction/msg/slashing/MsgUnjail';

export const CroSDK = function (configs: InitConfigurations) {
ow(configs, 'configs', owCroSDKInitParams);
Expand Down Expand Up @@ -128,7 +128,7 @@ export const CroSDK = function (configs: InitConfigurations) {
},
},
slashing: {
MsgUnjail: msgUnjail(configs),
MsgUnjailV2: msgUnjailV2(configs),
},
RawTransactionV2: rawTransactionV2(configs),
CoinV2: coinv2(configs),
Expand Down
16 changes: 8 additions & 8 deletions lib/src/transaction/msg/slashing/MsgUnjail.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ describe('Testing MsgUnjail', function () {
if (options.valid) {
return;
}
expect(() => new cro.v2.slashing.MsgUnjail(options.value)).to.throw(
expect(() => new cro.v2.slashing.MsgUnjailV2(options.value)).to.throw(
'Expected `options` to be of type `object`',
);
});
});

it('Test MsgUnjail conversion', function () {
const MsgUnjail = new cro.v2.slashing.MsgUnjail({
const MsgUnjail = new cro.v2.slashing.MsgUnjailV2({
validatorAddress: 'tcrocncl1j7pej8kplem4wt50p4hfvndhuw5jprxxxtenvr',
});

Expand All @@ -65,7 +65,7 @@ describe('Testing MsgUnjail', function () {
Bytes.fromHexString('66633d18513bec30dd11a209f1ceb1787aa9e2069d5d47e590174dc9665102b3'),
);

const MsgUnjail = new cro.v2.slashing.MsgUnjail({
const MsgUnjail = new cro.v2.slashing.MsgUnjailV2({
validatorAddress: 'tcrocncl1j7pej8kplem4wt50p4hfvndhuw5jprxxxtenvr',
});

Expand All @@ -92,14 +92,14 @@ describe('Testing MsgUnjail', function () {
validatorAddress: 'tcro165tzcrh2yl83g8qeqxueg2g5gzgu57y3fe3kc3',
};

expect(() => new cro.v2.slashing.MsgUnjail(params2)).to.throw(
expect(() => new cro.v2.slashing.MsgUnjailV2(params2)).to.throw(
'Provided `validatorAddress` doesnt match network selected',
);
});

describe('Testing MsgUnjail Json', function () {
it('Test MsgUnjail conversion for amino json', function () {
const MsgUnjail = new cro.v2.slashing.MsgUnjail({
const MsgUnjail = new cro.v2.slashing.MsgUnjailV2({
validatorAddress: 'tcrocncl1j7pej8kplem4wt50p4hfvndhuw5jprxxxtenvr',
});

Expand All @@ -117,21 +117,21 @@ describe('Testing MsgUnjail', function () {
it('should throw Error if the JSON is not a MsgUnjail', function () {
const json =
'{ "@type": "/cosmos.bank.v1beta1.MsgCreateValidator", "amount": [{ "denom": "basetcro", "amount": "3478499933290496" }], "from_address": "tcro1x07kkkepfj2hl8etlcuqhej7jj6myqrp48y4hg", "to_address": "tcro184lta2lsyu47vwyp2e8zmtca3k5yq85p6c4vp3" }';
expect(() => cro.v2.slashing.MsgUnjail.fromCosmosMsgJSON(json)).to.throw(
expect(() => cro.v2.slashing.MsgUnjailV2.fromCosmosMsgJSON(json)).to.throw(
'Expected /cosmos.slashing.v1beta1.MsgUnjail but got /cosmos.bank.v1beta1.MsgCreateValidator',
);
});
it('should throw Error when the `validator_address` field is missing', function () {
const json = '{"@type":"/cosmos.slashing.v1beta1.MsgUnjail"}';
expect(() => cro.v2.slashing.MsgUnjail.fromCosmosMsgJSON(json)).to.throw(
expect(() => cro.v2.slashing.MsgUnjailV2.fromCosmosMsgJSON(json)).to.throw(
'Expected property `validatorAddress` to be of type `string` but received type `undefined` in object `options`',
);
});

it('should return the MsgUnjail corresponding to the JSON', function () {
const json =
'{"@type":"/cosmos.slashing.v1beta1.MsgUnjail","validator_addr":"tcrocncl1j7pej8kplem4wt50p4hfvndhuw5jprxxxtenvr"}';
const MsgUnjail = cro.v2.slashing.MsgUnjail.fromCosmosMsgJSON(json);
const MsgUnjail = cro.v2.slashing.MsgUnjailV2.fromCosmosMsgJSON(json);
expect(MsgUnjail.validatorAddress).to.eql('tcrocncl1j7pej8kplem4wt50p4hfvndhuw5jprxxxtenvr');
});
});
Expand Down
2 changes: 1 addition & 1 deletion lib/src/transaction/msg/slashing/MsgUnjail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface MsgUnjailRaw {
validator_addr: string;
}

export const msgUnjail = function (config: InitConfigurations) {
export const msgUnjailV2 = function (config: InitConfigurations) {
return class MsgUnjail implements CosmosMsg {
/** MsgUnjail validatorAddress. */
public validatorAddress: string;
Expand Down
13 changes: 13 additions & 0 deletions lib/src/utils/txDecoder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,19 @@ describe('TxDecoder', function () {
});
})

context('`MsgUnjail`', function () {
it('should decode `MsgUnjail` correctly', function () {
const txDecoder = new TxDecoder();
expect(
txDecoder
.fromHex(
'0a590a570a222f636f736d6f732e736c617368696e672e763162657461312e4d7367556e6a61696c12310a2f7463726f636e636c316a3770656a386b706c656d347774353070346866766e64687577356a707278787874656e767212580a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103fd0d560b6c4aa1ca16721d039a192867c3457e19dad553edb98e7ba88b159c2712040a0208011802120410c09a0c1a40186e87b0b41928e69a1211c1fb5ebcb4c11fa6350f5cc830fa5f38f36f37f66e00d062707672b5d4ebf98cd5e3c7c4b40562707321bb9e8f2d3d605d8beb7b13',
)
.toCosmosJSON(),
).to.deep.equal(JSON.stringify({ "body": { "messages": [{ "@type": "/cosmos.slashing.v1beta1.MsgUnjail", "validator_addr": "tcrocncl1j7pej8kplem4wt50p4hfvndhuw5jprxxxtenvr" }], "memo": "", "timeout_height": "0", "extension_options": [], "non_critical_extension_options": [] }, "auth_info": { "signer_infos": [{ "public_key": { "@type": "/cosmos.crypto.secp256k1.PubKey", "key": "A/0NVgtsSqHKFnIdA5oZKGfDRX4Z2tVT7bmOe6iLFZwn" }, "mode_info": { "single": { "mode": "SIGN_MODE_DIRECT" } }, "sequence": "2" }], "fee": { "amount": [], "gas_limit": "200000", "payer": "", "granter": "" } }, "signatures": ["GG6HsLQZKOaaEhHB+168tMEfpjUPXMgw+l8482839m4A0GJwdnK11Ov5jNXjx8S0BWJwcyG7no8tPWBdi+t7Ew=="] }));
});
})

it('should decode the transaction correctly FOR CUSTOM MESSAGE PARAMS', function () {
const txDecoder = new TxDecoder();
expect(
Expand Down

0 comments on commit a67a7c1

Please sign in to comment.