Skip to content

Commit

Permalink
Merge pull request #385 from cdc-Hitesh/fix/#316/MsgCreateValidator-C…
Browse files Browse the repository at this point in the history
…ommission-conversion

Fix wrong commission decoding for `MsgCreateValidator` and `MsgEditValidator`
  • Loading branch information
crypto-matto authored Nov 11, 2022
2 parents bf8a207 + 2b2c745 commit 90b89d8
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 70 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to this project will be documented in this file.

## v1.0.8
- Fix wrong commission tx decoding for `MsgCreateValidator` and `MsgEditValidator`

## v1.0.7
- Fix incorrect `proposal_id` type of `MsgDeposit` in Amino format

Expand Down
38 changes: 19 additions & 19 deletions lib/src/transaction/msg/staking/MsgCreateValidator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ describe('Testing MsgCreateValidator', function () {
moniker: 'hiteshTest',
},
commission: {
rate: '0.1',
maxRate: '0.2',
maxChangeRate: '0.01',
rate: '10000000000',
maxRate: '20000000000',
maxChangeRate: '10000000000',
},
minSelfDelegation: '1',
delegatorAddress: 'tcro1j7pej8kplem4wt50p4hfvndhuw5jprxxn5625q',
Expand Down Expand Up @@ -67,9 +67,9 @@ describe('Testing MsgCreateValidator', function () {
securityContact: '[email protected]',
},
commission: {
rate: '0.1',
maxRate: '0.2',
maxChangeRate: '0.01',
rate: '10000000000',
maxRate: '20000000000',
maxChangeRate: '10000000000',
},
pubkey: 'ykxjs+cxozHiNuptXIHESIVKQcj1Dwgo7swOXs3HaTM=',
minSelfDelegation: '1',
Expand All @@ -85,9 +85,9 @@ describe('Testing MsgCreateValidator', function () {
securityContact: '[email protected]',
},
commission: {
rate: '0.1',
maxRate: '0.2',
maxChangeRate: '0.01',
rate: '10000000000',
maxRate: '20000000000',
maxChangeRate: '10000000000',
},
pubkey: protoEncodeEd25519PubKey(
Bytes.fromBase64String('ykxjs+cxozHiNuptXIHESIVKQcj1Dwgo7swOXs3HaTM='),
Expand All @@ -111,9 +111,9 @@ describe('Testing MsgCreateValidator', function () {
securityContact: '[email protected]',
},
commission: {
rate: '0.1',
maxRate: '0.2',
maxChangeRate: '0.01',
rate: '10000000000',
maxRate: '20000000000',
maxChangeRate: '10000000000',
},
pubkey: 'ykxjs+cxozHiNuptXIHESIVKQcj1Dwgo7swOXs3HaTM=',
minSelfDelegation: '1',
Expand All @@ -130,9 +130,9 @@ describe('Testing MsgCreateValidator', function () {
securityContact: '[email protected]',
},
commission: {
rate: '0.1',
maxRate: '0.2',
maxChangeRate: '0.01',
rate: '10000000000',
maxRate: '20000000000',
maxChangeRate: '10000000000',
},
pubkey,
minSelfDelegation: '1',
Expand Down Expand Up @@ -160,9 +160,9 @@ describe('Testing MsgCreateValidator', function () {
details: '',
},
commission: {
rate: '0.1',
maxRate: '0.2',
maxChangeRate: '0.01',
rate: '10000000000',
maxRate: '20000000000',
maxChangeRate: '10000000000',
},
pubkey: 'ykxjs+cxozHiNuptXIHESIVKQcj1Dwgo7swOXs3HaTM=',
minSelfDelegation: '1',
Expand All @@ -183,7 +183,7 @@ describe('Testing MsgCreateValidator', function () {
const signedTxHex = signedTx.encode().toHexString();

expect(signedTxHex).to.be.eql(
'0ab4020ab1020a2a2f636f736d6f732e7374616b696e672e763162657461312e4d736743726561746556616c696461746f721282020a2a0a0a6869746573685465737412001a0022166869746573682e676f656c4063727970746f2e636f6d2a0012100a03302e311203302e321a04302e30311a0131222b7463726f313635747a63726832796c3833673871657178756567326735677a6775353779336665336b63332a2f7463726f636e636c316a3770656a386b706c656d347774353070346866766e64687577356a707278787874656e767232430a1d2f636f736d6f732e63727970746f2e656432353531392e5075624b657912220a20ca4c63b3e731a331e236ea6d5c81c448854a41c8f50f0828eecc0e5ecdc769333a1c0a08626173657463726f12103132303030353030303030303030303012580a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103fd0d560b6c4aa1ca16721d039a192867c3457e19dad553edb98e7ba88b159c2712040a0208011802120410c09a0c1a40f659741d05e997666313a98b545398937b6aa40d884f1f2bf5aed8a281b5118d1123d11e98db388a6cf303a2c41341b6602b685d967aebf4b74af67d767dbd45',
'0acb020ac8020a2a2f636f736d6f732e7374616b696e672e763162657461312e4d736743726561746556616c696461746f721299020a2a0a0a6869746573685465737412001a0022166869746573682e676f656c4063727970746f2e636f6d2a0012270a0b3130303030303030303030120b32303030303030303030301a0b31303030303030303030301a0131222b7463726f313635747a63726832796c3833673871657178756567326735677a6775353779336665336b63332a2f7463726f636e636c316a3770656a386b706c656d347774353070346866766e64687577356a707278787874656e767232430a1d2f636f736d6f732e63727970746f2e656432353531392e5075624b657912220a20ca4c63b3e731a331e236ea6d5c81c448854a41c8f50f0828eecc0e5ecdc769333a1c0a08626173657463726f12103132303030353030303030303030303012580a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103fd0d560b6c4aa1ca16721d039a192867c3457e19dad553edb98e7ba88b159c2712040a0208011802120410c09a0c1a404ba43f9ddac81dec3325d20d6b31deb67be19d7d331cc5504009b68bca76d7ff57620f93ebe9f0fed44f0a56f01e812b9b8f6dc97b81c60c2a32a21e4415f34a',
);
});

Expand Down
16 changes: 8 additions & 8 deletions lib/src/transaction/msg/staking/MsgEditValidator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('Testing MsgEditValidator', function () {
details: 'HiteshTest',
},
validatorAddress: 'tcrocncl16mmzexp3zqfpgqtnn927m5ph560qgxrs52a3wx',
commissionRate: '0.100000000000000000',
commissionRate: '100000000000000000',
minSelfDelegation: '2',
});

Expand All @@ -77,7 +77,7 @@ describe('Testing MsgEditValidator', function () {
details: 'HiteshTest',
},
validatorAddress: 'tcrocncl16mmzexp3zqfpgqtnn927m5ph560qgxrs52a3wx',
commissionRate: '0.100000000000000000',
commissionRate: '100000000000000000',
minSelfDelegation: '2',
},
};
Expand All @@ -89,7 +89,7 @@ describe('Testing MsgEditValidator', function () {
const msgSend = new cro.staking.MsgEditValidator({
description: {},
validatorAddress: 'tcrocncl16mmzexp3zqfpgqtnn927m5ph560qgxrs52a3wx',
commissionRate: '0.100000000000000000',
commissionRate: '100000000000000000',
minSelfDelegation: '2',
});

Expand All @@ -98,7 +98,7 @@ describe('Testing MsgEditValidator', function () {
value: {
description: {},
validatorAddress: 'tcrocncl16mmzexp3zqfpgqtnn927m5ph560qgxrs52a3wx',
commissionRate: '0.100000000000000000',
commissionRate: '100000000000000000',
minSelfDelegation: '2',
},
};
Expand All @@ -119,7 +119,7 @@ describe('Testing MsgEditValidator', function () {
securityContact: '[email protected]',
details: '',
},
commissionRate: '0.100000000000000000',
commissionRate: '100000000000000000',
minSelfDelegation: '1.0',
validatorAddress: 'tcrocncl1j7pej8kplem4wt50p4hfvndhuw5jprxxxtenvr',
});
Expand All @@ -135,7 +135,7 @@ describe('Testing MsgEditValidator', function () {
const signedTx = signableTx.setSignature(0, anyKeyPair.sign(signableTx.toSignDocumentHash(0))).toSigned();
const signedTxHex = signedTx.encode().toHexString();
expect(signedTxHex).to.be.eql(
'0aa7010aa4010a282f636f736d6f732e7374616b696e672e763162657461312e4d73674564697456616c696461746f7212780a2a0a0a6869746573685465737412001a0022166869746573682e676f656c4063727970746f2e636f6d2a00122f7463726f636e636c316a3770656a386b706c656d347774353070346866766e64687577356a707278787874656e76721a14302e3130303030303030303030303030303030302203312e3012580a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103fd0d560b6c4aa1ca16721d039a192867c3457e19dad553edb98e7ba88b159c2712040a0208011802120410c09a0c1a4087e81b3b9706a35520778ed9099560c86b3ce8aaec3b384cc9720c89d3e044ab2601240a0d83f6a2e683e370c828b27dca8117de53eea269065c034e45e820f3',
'0aa5010aa2010a282f636f736d6f732e7374616b696e672e763162657461312e4d73674564697456616c696461746f7212760a2a0a0a6869746573685465737412001a0022166869746573682e676f656c4063727970746f2e636f6d2a00122f7463726f636e636c316a3770656a386b706c656d347774353070346866766e64687577356a707278787874656e76721a123130303030303030303030303030303030302203312e3012580a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103fd0d560b6c4aa1ca16721d039a192867c3457e19dad553edb98e7ba88b159c2712040a0208011802120410c09a0c1a40fe79a59e66813e4848d3c807ccf4a8f8b4cb91e0a4db97aa2e61dba4db2b4c9b100e4ebbc20dc7a08015a0bd6b1ef040be4a3e9584edb5f66b843d8c6b389432',
);
});

Expand All @@ -149,7 +149,7 @@ describe('Testing MsgEditValidator', function () {
details: 'HiteshTest',
},
validatorAddress: 'tcro1j7pej8kplem4wt50p4hfvndhuw5jprxxn5625q',
commissionRate: '0.100000000000000000',
commissionRate: '100000000000000000',
minSelfDelegation: '2',
};

Expand All @@ -162,7 +162,7 @@ describe('Testing MsgEditValidator', function () {
details: 'HiteshTest',
},
validatorAddress: 'tcrocncl16mmzexp3zqfpgqtnn927m5ph560qgxrs52a3w',
commissionRate: '0.100000000000000000',
commissionRate: '100000000000000000',
minSelfDelegation: '2',
};

Expand Down
6 changes: 3 additions & 3 deletions lib/src/utils/txDecoder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('TxDecoder', function () {
'0ab4020ab1020a2a2f636f736d6f732e7374616b696e672e763162657461312e4d736743726561746556616c696461746f721282020a2a0a0a6869746573685465737412001a0022166869746573682e676f656c4063727970746f2e636f6d2a0012100a03302e311203302e321a04302e30311a0131222b7463726f313635747a63726832796c3833673871657178756567326735677a6775353779336665336b63332a2f7463726f636e636c316a3770656a386b706c656d347774353070346866766e64687577356a707278787874656e767232430a1d2f636f736d6f732e63727970746f2e656432353531392e5075624b657912220a20ca4c63b3e731a331e236ea6d5c81c448854a41c8f50f0828eecc0e5ecdc769333a1c0a08626173657463726f12103132303030353030303030303030303012580a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103fd0d560b6c4aa1ca16721d039a192867c3457e19dad553edb98e7ba88b159c2712040a0208011802120410c09a0c1a40f659741d05e997666313a98b545398937b6aa40d884f1f2bf5aed8a281b5118d1123d11e98db388a6cf303a2c41341b6602b685d967aebf4b74af67d767dbd45',
)
.toCosmosJSON(),
).to.deep.equal(JSON.stringify({ "body": { "messages": [{ "@type": "/cosmos.staking.v1beta1.MsgCreateValidator", "description": { "moniker": "hiteshTest", "identity": "", "website": "", "security_contact": "[email protected]", "details": "" }, "commission": { "rate": "0.100000000000000000", "max_rate": "0.200000000000000000", "max_change_rate": "0.010000000000000000" }, "min_self_delegation": "1", "delegator_address": "tcro165tzcrh2yl83g8qeqxueg2g5gzgu57y3fe3kc3", "validator_address": "tcrocncl1j7pej8kplem4wt50p4hfvndhuw5jprxxxtenvr", "pubkey": { "@type": "/cosmos.crypto.ed25519.PubKey", "key": "ykxjs+cxozHiNuptXIHESIVKQcj1Dwgo7swOXs3HaTM=" }, "value": { "denom": "basetcro", "amount": "1200050000000000" } }], "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": ["9ll0HQXpl2ZjE6mLVFOYk3tqpA2ITx8r9a7YooG1EY0RI9EemNs4imzzA6LEE0G2YCtoXZZ66/S3SvZ9dn29RQ=="] }));
).to.deep.equal(JSON.stringify({ "body": { "messages": [{ "@type": "/cosmos.staking.v1beta1.MsgCreateValidator", "description": { "moniker": "hiteshTest", "identity": "", "website": "", "security_contact": "[email protected]", "details": "" }, "commission": { "rate": "0.1", "max_rate": "0.2", "max_change_rate": "0.01" }, "min_self_delegation": "1", "delegator_address": "tcro165tzcrh2yl83g8qeqxueg2g5gzgu57y3fe3kc3", "validator_address": "tcrocncl1j7pej8kplem4wt50p4hfvndhuw5jprxxxtenvr", "pubkey": { "@type": "/cosmos.crypto.ed25519.PubKey", "key": "ykxjs+cxozHiNuptXIHESIVKQcj1Dwgo7swOXs3HaTM=" }, "value": { "denom": "basetcro", "amount": "1200050000000000" } }], "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": ["9ll0HQXpl2ZjE6mLVFOYk3tqpA2ITx8r9a7YooG1EY0RI9EemNs4imzzA6LEE0G2YCtoXZZ66/S3SvZ9dn29RQ=="] }));
});

it('should decode `MsgCreateValidator` with no-decimal commission rates', function () {
Expand All @@ -139,7 +139,7 @@ describe('TxDecoder', function () {
,
)
.toCosmosJSON(),
).to.deep.equal(JSON.stringify({ "body": { "messages": [{ "@type": "/cosmos.staking.v1beta1.MsgCreateValidator", "description": { "moniker": "hiteshTest" }, "commission": { "rate": "0.100000000000000000", "max_rate": "0.200000000000000000", "max_change_rate": "0.010000000000000000" }, "min_self_delegation": "1", "delegator_address": "tcro165tzcrh2yl83g8qeqxueg2g5gzgu57y3fe3kc3", "validator_address": "tcrocncl1j7pej8kplem4wt50p4hfvndhuw5jprxxxtenvr", "pubkey": { "@type": "/cosmos.crypto.ed25519.PubKey", "key": "ykxjs+cxozHiNuptXIHESIVKQcj1Dwgo7swOXs3HaTM=" }, "value": { "denom": "basetcro", "amount": "1200050000000000" } }], "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": ["qe7YZd/7lau8YzUS8X55k9nlRnjyBbjpBDESKF0ZZcYudd0Kw/UDBao10m0/ouqKSwMC4Eqcvo/emU3xFNpG1Q=="] }));
).to.deep.equal(JSON.stringify({ "body": { "messages": [{ "@type": "/cosmos.staking.v1beta1.MsgCreateValidator", "description": { "moniker": "hiteshTest" }, "commission": { "rate": "100000000000000000", "max_rate": "200000000000000000", "max_change_rate": "10000000000000000" }, "min_self_delegation": "1", "delegator_address": "tcro165tzcrh2yl83g8qeqxueg2g5gzgu57y3fe3kc3", "validator_address": "tcrocncl1j7pej8kplem4wt50p4hfvndhuw5jprxxxtenvr", "pubkey": { "@type": "/cosmos.crypto.ed25519.PubKey", "key": "ykxjs+cxozHiNuptXIHESIVKQcj1Dwgo7swOXs3HaTM=" }, "value": { "denom": "basetcro", "amount": "1200050000000000" } }], "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": ["qe7YZd/7lau8YzUS8X55k9nlRnjyBbjpBDESKF0ZZcYudd0Kw/UDBao10m0/ouqKSwMC4Eqcvo/emU3xFNpG1Q=="] }));
});
})

Expand All @@ -162,7 +162,7 @@ describe('TxDecoder', function () {
'0aa5010aa2010a282f636f736d6f732e7374616b696e672e763162657461312e4d73674564697456616c696461746f7212760a2a0a0a6869746573685465737412001a0022166869746573682e676f656c4063727970746f2e636f6d2a00122f7463726f636e636c316a3770656a386b706c656d347774353070346866766e64687577356a707278787874656e76721a123130303030303030303030303030303030302203312e3012580a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103fd0d560b6c4aa1ca16721d039a192867c3457e19dad553edb98e7ba88b159c2712040a0208011802120410c09a0c1a40fe79a59e66813e4848d3c807ccf4a8f8b4cb91e0a4db97aa2e61dba4db2b4c9b100e4ebbc20dc7a08015a0bd6b1ef040be4a3e9584edb5f66b843d8c6b389432',
)
.toCosmosJSON(),
).to.deep.equal(JSON.stringify({ "body": { "messages": [{ "@type": "/cosmos.staking.v1beta1.MsgEditValidator", "description": { "moniker": "hiteshTest", "identity": "", "website": "", "security_contact": "[email protected]", "details": "" }, "validator_address": "tcrocncl1j7pej8kplem4wt50p4hfvndhuw5jprxxxtenvr", "commission_rate": "0.100000000000000000", "min_self_delegation": "1.0" }], "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": ["/nmlnmaBPkhI08gHzPSo+LTLkeCk25eqLmHbpNsrTJsQDk67wg3HoIAVoL1rHvBAvko+lYTttfZrhD2MaziUMg=="] }));
).to.deep.equal(JSON.stringify({ "body": { "messages": [{ "@type": "/cosmos.staking.v1beta1.MsgEditValidator", "description": { "moniker": "hiteshTest", "identity": "", "website": "", "security_contact": "[email protected]", "details": "" }, "validator_address": "tcrocncl1j7pej8kplem4wt50p4hfvndhuw5jprxxxtenvr", "commission_rate": "100000000000000000", "min_self_delegation": "1.0" }], "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": ["/nmlnmaBPkhI08gHzPSo+LTLkeCk25eqLmHbpNsrTJsQDk67wg3HoIAVoL1rHvBAvko+lYTttfZrhD2MaziUMg=="] }));
});
it('should decode `MsgEditValidator` with `null` commissionRate', function () {
const txDecoder = new TxDecoder();
Expand Down
Loading

0 comments on commit 90b89d8

Please sign in to comment.