diff --git a/lib/e2e/transaction.spec.ts b/lib/e2e/transaction.spec.ts index c1404d19..43050262 100644 --- a/lib/e2e/transaction.spec.ts +++ b/lib/e2e/transaction.spec.ts @@ -79,13 +79,13 @@ describe('e2e test suite', function () { const msgSend1 = new cro.bank.MsgSend({ fromAddress: address1.account(), toAddress: randomAddress.account(), - amount: new cro.Coin('100000', Units.BASE), + amount: [new cro.Coin('100000', Units.BASE)], }); const msgSend2 = new cro.bank.MsgSend({ fromAddress: address2.account(), toAddress: address1.account(), - amount: new cro.Coin('20000', Units.BASE), + amount: [new cro.Coin('20000', Units.BASE)], }); const account1 = await client.getAccount(address1.account()); @@ -146,13 +146,13 @@ describe('e2e test suite', function () { const msgSend1 = new cro.bank.MsgSend({ fromAddress: address1.account(), toAddress: randomAddress.account(), - amount: new cro.Coin('100000', Units.BASE), + amount: [new cro.Coin('100000', Units.BASE)], }); const msgSend2 = new cro.bank.MsgSend({ fromAddress: address2.account(), toAddress: address1.account(), - amount: new cro.Coin('20000', Units.BASE), + amount: [new cro.Coin('20000', Units.BASE)], }); const account1 = await client.getAccount(address1.account()); diff --git a/lib/src/core/cro.ts b/lib/src/core/cro.ts index 483b528e..63238dda 100644 --- a/lib/src/core/cro.ts +++ b/lib/src/core/cro.ts @@ -48,7 +48,6 @@ export const CroSDK = function (configs: InitConfigurations) { CancelSoftwareUpgradeProposal: cancelSoftwareUpgradeProposal(), SoftwareUpgradeProposal: softwareUpgradeProposal(), TextProposal: textProposal(), - // TODO : More type of proposals to be added here }, }, bank: { diff --git a/lib/src/transaction/amino.spec.ts b/lib/src/transaction/amino.spec.ts index 1824a675..db78f608 100644 --- a/lib/src/transaction/amino.spec.ts +++ b/lib/src/transaction/amino.spec.ts @@ -36,7 +36,7 @@ describe('Amino JSON sign mode', function () { const msg = new cro.bank.MsgSend({ fromAddress: new cro.Address(keyPair).account(), toAddress: 'tcro1fzcrza3j4f2677jfuxulkg33z6852qsqs8hx50', - amount: cro.Coin.fromBaseUnit('1000'), + amount: [cro.Coin.fromBaseUnit('1000')], }); const rawTx = new cro.RawTransaction(); diff --git a/lib/src/transaction/msg/bank/msgsend.spec.ts b/lib/src/transaction/msg/bank/msgsend.spec.ts index 79402107..280540fd 100644 --- a/lib/src/transaction/msg/bank/msgsend.spec.ts +++ b/lib/src/transaction/msg/bank/msgsend.spec.ts @@ -80,8 +80,8 @@ describe('Testing MsgSend', function () { const msgSend = cro.bank.MsgSend.fromCosmosMsgJSON(json, CroNetwork.Testnet); expect(msgSend.fromAddress).to.eql('tcro1x07kkkepfj2hl8etlcuqhej7jj6myqrp48y4hg'); expect(msgSend.toAddress).to.eql('tcro184lta2lsyu47vwyp2e8zmtca3k5yq85p6c4vp3'); - expect(msgSend.amount.toCosmosCoin().amount).to.eql('3478499933290496'); - expect(msgSend.amount.toCosmosCoin().denom).to.eql('basetcro'); + expect(msgSend.amount[0].toCosmosCoin().amount).to.eql('3478499933290496'); + expect(msgSend.amount[0].toCosmosCoin().denom).to.eql('basetcro'); }); }); @@ -107,7 +107,7 @@ describe('Testing MsgSend', function () { const msgSend = new cro.bank.MsgSend({ fromAddress: 'tcro165tzcrh2yl83g8qeqxueg2g5gzgu57y3fe3kc3', toAddress: 'tcro184lta2lsyu47vwyp2e8zmtca3k5yq85p6c4vp3', - amount: coin, + amount: [coin], }); const rawMsg: Msg = { @@ -136,7 +136,7 @@ describe('Testing MsgSend', function () { const msgSend = new cro.bank.MsgSend({ fromAddress: 'tcro165tzcrh2yl83g8qeqxueg2g5gzgu57y3fe3kc3', toAddress: 'tcro184lta2lsyu47vwyp2e8zmtca3k5yq85p6c4vp3', - amount: coin, + amount: [coin], }); const anySigner = { @@ -163,19 +163,19 @@ describe('Testing MsgSend', function () { const params1 = { fromAddress: 'cro1pndm4ywdf4qtmupa0fqe75krmqed2znjyj6x8f', toAddress: 'tcro184lta2lsyu47vwyp2e8zmtca3k5yq85p6c4vp3', - amount: coin, + amount: [coin], }; const params2 = { fromAddress: 'tcro165tzcrh2yl83g8qeqxueg2g5gzgu57y3fe3kc3', toAddress: 'cro1pndm4ywdf4qtmupa0fqe75krmqed2znjyj6x8f', - amount: coin, + amount: [coin], }; const params3 = { fromAddress: 'tcro1pndm4ywdf4qtmupa0fqe75krmqed2znjyj6x8fzqa', toAddress: 'cro184lta2lsyu47vwyp2e8zmtca3k5yq85p6c4vp3', - amount: coin, + amount: [coin], }; expect(() => new cro.bank.MsgSend(params1)).to.throw('Provided `fromAddress` does not match network selected'); diff --git a/lib/src/transaction/msg/bank/msgsend.ts b/lib/src/transaction/msg/bank/msgsend.ts index b64a1568..65625223 100644 --- a/lib/src/transaction/msg/bank/msgsend.ts +++ b/lib/src/transaction/msg/bank/msgsend.ts @@ -28,7 +28,7 @@ export const msgSend = function (config: InitConfigurations) { public readonly toAddress: string; - public amount: ICoin; + public amount: ICoin[]; /** * Constructor to create a new MsgSend @@ -58,15 +58,14 @@ export const msgSend = function (config: InitConfigurations) { if (parsedMsg['@type'] !== COSMOS_MSG_TYPEURL.MsgSend) { throw new Error(`Expected ${COSMOS_MSG_TYPEURL.MsgSend} but got ${parsedMsg['@type']}`); } - if (!parsedMsg.amount || parsedMsg.amount.length !== 1) { + if (!parsedMsg.amount || parsedMsg.amount.length < 1) { throw new Error('Invalid amount in the Msg.'); } return new MsgSend({ fromAddress: parsedMsg.from_address, toAddress: parsedMsg.to_address, - // TODO: Handle the complete list - amount: cro.Coin.fromCustomAmountDenom(parsedMsg.amount[0].amount, parsedMsg.amount[0].denom), + amount: parsedMsg.amount.map(coin => cro.Coin.fromCustomAmountDenom(coin.amount, coin.denom)), }); } @@ -80,7 +79,7 @@ export const msgSend = function (config: InitConfigurations) { value: { fromAddress: this.fromAddress, toAddress: this.toAddress, - amount: this.amount.toCosmosCoins(), + amount: this.amount.map(coin => coin.toCosmosCoin()), }, }; } @@ -92,7 +91,7 @@ export const msgSend = function (config: InitConfigurations) { value: { from_address: this.fromAddress, to_address: this.toAddress, - amount: this.amount.toCosmosCoins(), + amount: this.amount.map(coin => coin.toCosmosCoin()), }, } as legacyAmino.MsgSend; } @@ -124,6 +123,5 @@ export const msgSend = function (config: InitConfigurations) { export type MsgSendOptions = { fromAddress: string; toAddress: string; - // Todo: It should be ICoin[] - amount: ICoin; + amount: ICoin[]; }; diff --git a/lib/src/transaction/msg/ow.types.ts b/lib/src/transaction/msg/ow.types.ts index 71ae8404..8b5fe9b6 100644 --- a/lib/src/transaction/msg/ow.types.ts +++ b/lib/src/transaction/msg/ow.types.ts @@ -14,7 +14,7 @@ export const owVoteOption = () => ow.number.validate(voteOptionValidator); export const owMsgSendOptions = owStrictObject().exactShape({ fromAddress: ow.string, toAddress: ow.string, - amount: owCoin(), + amount: ow.array.ofType(owCoin()), }); const proposalContentValidatorFn = (val: object) => ({ diff --git a/lib/src/transaction/signable.ts b/lib/src/transaction/signable.ts index 4dee829a..875cfd7b 100644 --- a/lib/src/transaction/signable.ts +++ b/lib/src/transaction/signable.ts @@ -82,7 +82,6 @@ export class SignableTransaction { const { memo } = body; const timeoutHeight = body.timeout_height; - // TODO: If extension_options and non_critical_extension_options length > 0, then throw if ( (body.non_critical_extension_options && body.non_critical_extension_options.length > 0) || (body.extension_options && body.extension_options.length > 0) diff --git a/lib/src/transaction/test.ts b/lib/src/transaction/test.ts index 24675eaf..d88098c2 100644 --- a/lib/src/transaction/test.ts +++ b/lib/src/transaction/test.ts @@ -32,7 +32,7 @@ export const CosmosMsgSuiteFactory = new Factory() new cro.bank.MsgSend({ fromAddress: new cro.Address(keyPair.getPubKey()).account(), toAddress, - amount: cro.Coin.fromBaseUnit(chance.integer({ min: 0 }).toString()), + amount: [cro.Coin.fromBaseUnit(chance.integer({ min: 0 }).toString())], }), ); diff --git a/lib/src/transaction/tx-custom-props.spec.ts b/lib/src/transaction/tx-custom-props.spec.ts index 413930d3..a9570665 100644 --- a/lib/src/transaction/tx-custom-props.spec.ts +++ b/lib/src/transaction/tx-custom-props.spec.ts @@ -66,7 +66,7 @@ describe('Testing Tx signing with custom parameters', function () { const msg = new cro.bank.MsgSend({ fromAddress: new cro.Address(keyPair).account(), toAddress: 'tcro1fzcrza3j4f2677jfuxulkg33z6852qsqs8hx50', - amount: cro.Coin.fromBaseUnit('1000'), + amount: [cro.Coin.fromBaseUnit('1000')], }); const rawTx = new cro.RawTransaction(); @@ -108,7 +108,7 @@ describe('Testing Tx signing with custom parameters', function () { const msg = new cro.bank.MsgSend({ fromAddress: new cro.Address(keyPair).account(), toAddress: 'tcro1fzcrza3j4f2677jfuxulkg33z6852qsqs8hx50', - amount: cro.Coin.fromBaseUnit('1000'), + amount: [cro.Coin.fromBaseUnit('1000')], }); const rawTx = new cro.RawTransaction(); @@ -150,7 +150,7 @@ describe('Testing Tx signing with custom parameters', function () { const msg = new cro.bank.MsgSend({ fromAddress: new cro.Address(keyPair).account(), toAddress: 'tcro1fzcrza3j4f2677jfuxulkg33z6852qsqs8hx50', - amount: cro.Coin.fromBaseUnit('1000'), + amount: [cro.Coin.fromBaseUnit('1000')], }); const rawTx = new cro.RawTransaction(); @@ -204,7 +204,7 @@ describe('Testing Tx signing with custom parameters', function () { const msgSend1 = new cro.bank.MsgSend({ fromAddress: 'tcro165tzcrh2yl83g8qeqxueg2g5gzgu57y3fe3kc3', toAddress: 'tcro165tzcrh2yl83g8qeqxueg2g5gzgu57y3fe3kc3', - amount: new cro.Coin('1210', Units.BASE), + amount: [new cro.Coin('1210', Units.BASE)], }); const signableTx = rawTx @@ -234,7 +234,7 @@ describe('Testing Tx signing with custom parameters', function () { const msg = new cro.bank.MsgSend({ fromAddress: new cro.Address(keyPair).account(), toAddress: 'tcro18tk89ddr4lg32e58sp5kfrm0egldlcfu40ww80', - amount: cro.Coin.fromBaseUnit('990227306075'), + amount: [cro.Coin.fromBaseUnit('990227306075')], }); const rawTx = new cro.RawTransaction(); diff --git a/lib/src/transaction/tx-edgecase.spec.ts b/lib/src/transaction/tx-edgecase.spec.ts index 2ce1e33a..12da7b57 100644 --- a/lib/src/transaction/tx-edgecase.spec.ts +++ b/lib/src/transaction/tx-edgecase.spec.ts @@ -58,7 +58,7 @@ describe('Testing edge case Txs with 0 account numbers or 0 sequence', function const msgSend1 = new cro.bank.MsgSend({ fromAddress: 'tcro15rsn69ze9r7g52tk0u6cyhu4edep88dxgtzm65', toAddress: 'tcro1l4gxejy8qxl3vxcxv7vpk4cqu8qhrz2nfxxr2p', - amount: new cro.Coin('1210', Units.BASE), + amount: [new cro.Coin('1210', Units.BASE)], }); const signableTx = rawTx @@ -92,7 +92,7 @@ describe('Testing edge case Txs with 0 account numbers or 0 sequence', function const msgSend1 = new cro.bank.MsgSend({ fromAddress: 'tcro1l4gxejy8qxl3vxcxv7vpk4cqu8qhrz2nfxxr2p', toAddress: 'tcro12z3awt3kkh0u58hmw85lhtdg67d44pwu62x8sa', - amount: new cro.Coin('2210', Units.BASE), + amount: [new cro.Coin('2210', Units.BASE)], }); const signableTx = rawTx @@ -122,7 +122,7 @@ describe('Testing edge case Txs with 0 account numbers or 0 sequence', function const msg = new cro.bank.MsgSend({ fromAddress: new cro.Address(keyPair).account(), toAddress: 'tcro1ca066afeuj52k3r29je25q0auyr32k4plkh33r', - amount: cro.Coin.fromBaseUnit('1000'), + amount: [cro.Coin.fromBaseUnit('1000')], }); const rawTx = new cro.RawTransaction();