Skip to content

Commit

Permalink
crypto-org-chain#278: Feedback improvement, change name
Browse files Browse the repository at this point in the history
  • Loading branch information
cdc-Hitesh committed Jun 28, 2021
1 parent 615af59 commit 450ccc2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
4 changes: 2 additions & 2 deletions lib/e2e/transaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ describe('e2e test suite', function () {
const randomAddress = new cro.Address(randomKeyPair.getPubKey());
const client = await cro.CroClient.connect();

const msgSend1 = new cro.v2.bank.MsgSend({
const msgSend1 = new cro.v2.bank.MsgSendV2({
fromAddress: address1.account(),
toAddress: randomAddress.account(),
amount: [new cro.Coin('100000', Units.BASE)],
});

const msgSend2 = new cro.v2.bank.MsgSend({
const msgSend2 = new cro.v2.bank.MsgSendV2({
fromAddress: address2.account(),
toAddress: address1.account(),
amount: [new cro.Coin('20000', Units.BASE)],
Expand Down
2 changes: 1 addition & 1 deletion lib/src/core/cro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const CroSDK = function (configs: InitConfigurations) {
},
v2: {
bank: {
MsgSend: msgSendV2(configs),
MsgSendV2: msgSendV2(configs),
},
},
Options: configs,
Expand Down
30 changes: 17 additions & 13 deletions lib/src/transaction/msg/v2/bank/v2.msgsend.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,51 +33,51 @@ describe('Testing MsgSend', function () {
it('should throw Error if the JSON is not a MsgSend', function () {
const json =
'{ "@type": "/cosmos.bank.v1beta1.MsgCreateValidator", "amount": [{ "denom": "basetcro", "amount": "3478499933290496" }], "from_address": "tcro1x07kkkepfj2hl8etlcuqhej7jj6myqrp48y4hg", "to_address": "tcro184lta2lsyu47vwyp2e8zmtca3k5yq85p6c4vp3" }';
expect(() => cro.v2.bank.MsgSend.fromCosmosMsgJSON(json, CroNetwork.Testnet)).to.throw(
expect(() => cro.v2.bank.MsgSendV2.fromCosmosMsgJSON(json, CroNetwork.Testnet)).to.throw(
'Expected /cosmos.bank.v1beta1.MsgSend but got /cosmos.bank.v1beta1.MsgCreateValidator',
);
});
it('should throw Error when the from field is missing', function () {
const json =
'{ "@type": "/cosmos.bank.v1beta1.MsgSend", "amount": [{ "denom": "basetcro", "amount": "3478499933290496" }], "to_address": "tcro184lta2lsyu47vwyp2e8zmtca3k5yq85p6c4vp3" }';
expect(() => cro.v2.bank.MsgSend.fromCosmosMsgJSON(json, CroNetwork.Testnet)).to.throw(
expect(() => cro.v2.bank.MsgSendV2.fromCosmosMsgJSON(json, CroNetwork.Testnet)).to.throw(
'Expected property `fromAddress` to be of type `string` but received type `undefined` in object `options`',
);
});
it('should throw Error when the to field is missing', function () {
const json =
'{ "@type": "/cosmos.bank.v1beta1.MsgSend", "amount": [{ "denom": "basetcro", "amount": "3478499933290496" }], "from_address": "tcro1x07kkkepfj2hl8etlcuqhej7jj6myqrp48y4hg" }';
expect(() => cro.v2.bank.MsgSend.fromCosmosMsgJSON(json, CroNetwork.Testnet)).to.throw(
expect(() => cro.v2.bank.MsgSendV2.fromCosmosMsgJSON(json, CroNetwork.Testnet)).to.throw(
'Expected property `toAddress` to be of type `string` but received type `undefined` in object `options`',
);
});
it('should throw Error when the amount field is missing', function () {
const json =
'{ "@type": "/cosmos.bank.v1beta1.MsgSend", "from_address": "tcro1x07kkkepfj2hl8etlcuqhej7jj6myqrp48y4hg" , "to_address": "tcro184lta2lsyu47vwyp2e8zmtca3k5yq85p6c4vp3" }';
expect(() => cro.v2.bank.MsgSend.fromCosmosMsgJSON(json, CroNetwork.Testnet)).to.throw(
expect(() => cro.v2.bank.MsgSendV2.fromCosmosMsgJSON(json, CroNetwork.Testnet)).to.throw(
'Invalid amount in the Msg.',
);
});
it('should throw on invalid `fromAddress`', function () {
const json =
'{ "@type": "/cosmos.bank.v1beta1.MsgSend", "amount": [{ "denom": "basetcro", "amount": "3478499933290496" }], "from_address": "cro1pndm4ywdf4qtmupa0fqe75krmqed2znjyj6x8f", "to_address": "tcro184lta2lsyu47vwyp2e8zmtca3k5yq85p6c4vp3" }';

expect(() => cro.v2.bank.MsgSend.fromCosmosMsgJSON(json, CroNetwork.Testnet)).to.throw(
expect(() => cro.v2.bank.MsgSendV2.fromCosmosMsgJSON(json, CroNetwork.Testnet)).to.throw(
'Provided `fromAddress` does not match network selected',
);
});
it('should throw on invalid `toAddress`', function () {
const json =
'{ "@type": "/cosmos.bank.v1beta1.MsgSend", "amount": [{ "denom": "basetcro", "amount": "3478499933290496" }], "from_address": "tcro184lta2lsyu47vwyp2e8zmtca3k5yq85p6c4vp3", "to_address": "cro1pndm4ywdf4qtmupa0fqe75krmqed2znjyj6x8f" }';

expect(() => cro.v2.bank.MsgSend.fromCosmosMsgJSON(json, CroNetwork.Testnet)).to.throw(
expect(() => cro.v2.bank.MsgSendV2.fromCosmosMsgJSON(json, CroNetwork.Testnet)).to.throw(
'Provided `toAddress` does not match network selected',
);
});
it('should return the MsgSend corresponding to the JSON', function () {
const json =
'{ "@type": "/cosmos.bank.v1beta1.MsgSend", "amount": [{ "denom": "basetcro", "amount": "3478499933290496" }], "from_address": "tcro1x07kkkepfj2hl8etlcuqhej7jj6myqrp48y4hg", "to_address": "tcro184lta2lsyu47vwyp2e8zmtca3k5yq85p6c4vp3" }';
const msgSend = cro.v2.bank.MsgSend.fromCosmosMsgJSON(json, CroNetwork.Testnet);
const msgSend = cro.v2.bank.MsgSendV2.fromCosmosMsgJSON(json, CroNetwork.Testnet);
expect(msgSend.fromAddress).to.eql('tcro1x07kkkepfj2hl8etlcuqhej7jj6myqrp48y4hg');
expect(msgSend.toAddress).to.eql('tcro184lta2lsyu47vwyp2e8zmtca3k5yq85p6c4vp3');
expect(msgSend.amount[0].toCosmosCoin().amount).to.eql('3478499933290496');
Expand All @@ -97,14 +97,16 @@ describe('Testing MsgSend', function () {
if (options.valid) {
return;
}
expect(() => new cro.v2.bank.MsgSend(options.value)).to.throw('Expected `options` to be of type `object`');
expect(() => new cro.v2.bank.MsgSendV2(options.value)).to.throw(
'Expected `options` to be of type `object`',
);
});
});

it('Test MsgSend conversion', function () {
const coin = new cro.Coin('12000500', Units.BASE);

const msgSend = new cro.v2.bank.MsgSend({
const msgSend = new cro.v2.bank.MsgSendV2({
fromAddress: 'tcro165tzcrh2yl83g8qeqxueg2g5gzgu57y3fe3kc3',
toAddress: 'tcro184lta2lsyu47vwyp2e8zmtca3k5yq85p6c4vp3',
amount: [coin],
Expand Down Expand Up @@ -133,7 +135,7 @@ describe('Testing MsgSend', function () {
);
const coin = new cro.Coin('12000500', Units.CRO);

const msgSend = new cro.v2.bank.MsgSend({
const msgSend = new cro.v2.bank.MsgSendV2({
fromAddress: 'tcro165tzcrh2yl83g8qeqxueg2g5gzgu57y3fe3kc3',
toAddress: 'tcro184lta2lsyu47vwyp2e8zmtca3k5yq85p6c4vp3',
amount: [coin],
Expand Down Expand Up @@ -178,11 +180,13 @@ describe('Testing MsgSend', function () {
amount: [coin],
};

expect(() => new cro.v2.bank.MsgSend(params1)).to.throw(
expect(() => new cro.v2.bank.MsgSendV2(params1)).to.throw(
'Provided `fromAddress` does not match network selected',
);
expect(() => new cro.v2.bank.MsgSend(params2)).to.throw('Provided `toAddress` does not match network selected');
expect(() => new cro.v2.bank.MsgSend(params3)).to.throw(
expect(() => new cro.v2.bank.MsgSendV2(params2)).to.throw(
'Provided `toAddress` does not match network selected',
);
expect(() => new cro.v2.bank.MsgSendV2(params3)).to.throw(
'Invalid checksum for tcro1pndm4ywdf4qtmupa0fqe75krmqed2znjyj6x8fzqa',
);
});
Expand Down
10 changes: 5 additions & 5 deletions lib/src/transaction/msg/v2/bank/v2.msgsend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as legacyAmino from '../../../../cosmos/amino';
import { Network } from '../../../../network/network';

export const msgSendV2 = function (config: InitConfigurations) {
return class MsgSend implements CosmosMsg {
return class MsgSendV2 implements CosmosMsg {
public readonly fromAddress: string;

public readonly toAddress: string;
Expand All @@ -21,7 +21,7 @@ export const msgSendV2 = function (config: InitConfigurations) {
/**
* Constructor to create a new MsgSend
* @param {MsgSendOptions} options
* @returns {MsgSend}
* @returns {MsgSendV2}
* @throws {Error} when options is invalid
*/
constructor(options: MsgSendOptions) {
Expand All @@ -38,9 +38,9 @@ export const msgSendV2 = function (config: InitConfigurations) {
* Returns an instance of MsgSend
* @param {string} msgJsonStr
* @param {Network} network
* @returns {MsgSend}
* @returns {MsgSendV2}
*/
public static fromCosmosMsgJSON(msgJsonStr: string, network: Network): MsgSend {
public static fromCosmosMsgJSON(msgJsonStr: string, network: Network): MsgSendV2 {
const parsedMsg = JSON.parse(msgJsonStr) as MsgSendRaw;
const cro = CroSDK({ network });
if (parsedMsg['@type'] !== COSMOS_MSG_TYPEURL.MsgSend) {
Expand All @@ -50,7 +50,7 @@ export const msgSendV2 = function (config: InitConfigurations) {
throw new Error('Invalid amount in the Msg.');
}

return new MsgSend({
return new MsgSendV2({
fromAddress: parsedMsg.from_address,
toAddress: parsedMsg.to_address,
amount: parsedMsg.amount.map((coin) => cro.Coin.fromCustomAmountDenom(coin.amount, coin.denom)),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/transaction/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const CosmosMsgSuiteFactoryV2 = new Factory<MessageSuite>()
'message',
['network', 'keyPair', 'toAddress'],
(_: Network, keyPair: Secp256k1KeyPair, toAddress: string): CosmosMsg =>
new cro.v2.bank.MsgSend({
new cro.v2.bank.MsgSendV2({
fromAddress: new cro.Address(keyPair.getPubKey()).account(),
toAddress,
amount: [cro.Coin.fromBaseUnit(chance.integer({ min: 0 }).toString())],
Expand Down

0 comments on commit 450ccc2

Please sign in to comment.