From 00b2cc6b870ba44071d5c1937980413c7af1cec4 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 17 May 2021 14:07:10 +0200 Subject: [PATCH 1/2] Prepare the renaming transferAmount -> funds --- .../src/lcdapi/wasm.spec.ts | 27 ++++++++--------- .../src/signingcosmwasmclient.spec.ts | 13 ++++---- .../src/signingcosmwasmclient.ts | 21 +++++++++---- .../src/queries/wasm.spec.ts | 28 ++++++++--------- .../src/signingcosmwasmclient.spec.ts | 16 +++++----- .../src/signingcosmwasmclient.ts | 12 ++++---- .../launchpad/src/lcdapi/lcdclient.spec.ts | 30 ++++--------------- .../launchpad/src/signingcosmosclient.spec.ts | 1 - 8 files changed, 68 insertions(+), 80 deletions(-) diff --git a/packages/cosmwasm-launchpad/src/lcdapi/wasm.spec.ts b/packages/cosmwasm-launchpad/src/lcdapi/wasm.spec.ts index ca9067cf..cc1810d8 100644 --- a/packages/cosmwasm-launchpad/src/lcdapi/wasm.spec.ts +++ b/packages/cosmwasm-launchpad/src/lcdapi/wasm.spec.ts @@ -77,7 +77,7 @@ async function instantiateContract( signer: OfflineSigner, codeId: number, beneficiaryAddress: string, - transferAmount?: readonly Coin[], + funds?: readonly Coin[], ): Promise { const memo = "Create an escrow instance"; const theMsg: MsgInstantiateContract = { @@ -90,7 +90,7 @@ async function instantiateContract( verifier: alice.address0, beneficiary: beneficiaryAddress, }, - init_funds: transferAmount || [], + init_funds: funds || [], }, }; const fee: StdFee = { @@ -191,8 +191,6 @@ describe("WasmExtension", () => { assert(hackatomCodeId); const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = makeWasmClient(launchpad.endpoint); - const beneficiaryAddress = makeRandomAddress(); - const transferAmount = coins(707707, "ucosm"); // create new instance and compare before and after const existingContractsByCode = await client.wasm.listContractsByCodeId(hackatomCodeId); @@ -203,7 +201,9 @@ describe("WasmExtension", () => { expect(contract.label).toMatch(/^.+$/); } - const result = await instantiateContract(wallet, hackatomCodeId, beneficiaryAddress, transferAmount); + const beneficiaryAddress = makeRandomAddress(); + const funds = coins(707707, "ucosm"); + const result = await instantiateContract(wallet, hackatomCodeId, beneficiaryAddress, funds); assertIsBroadcastTxSuccess(result); const parsedLogs = logs.parseLogs(result.logs); const contractAddressAttr = logs.findAttribute(parsedLogs, "message", "contract_address"); @@ -248,11 +248,11 @@ describe("WasmExtension", () => { assert(hackatomCodeId); const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = makeWasmClient(launchpad.endpoint); - const beneficiaryAddress = makeRandomAddress(); - const transferAmount = coins(707707, "ucosm"); // create new instance and compare before and after - const result = await instantiateContract(wallet, hackatomCodeId, beneficiaryAddress, transferAmount); + const beneficiaryAddress = makeRandomAddress(); + const funds = coins(707707, "ucosm"); + const result = await instantiateContract(wallet, hackatomCodeId, beneficiaryAddress, funds); assertIsBroadcastTxSuccess(result); const parsedLogs = logs.parseLogs(result.logs); const contractAddressAttr = logs.findAttribute(parsedLogs, "message", "contract_address"); @@ -486,9 +486,6 @@ describe("WasmExtension", () => { const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = makeWasmClient(launchpad.endpoint); - const transferAmount = [coin(1234, "ucosm"), coin(321, "ustake")]; - const beneficiaryAddress = makeRandomAddress(); - let codeId: number; // upload @@ -504,11 +501,13 @@ describe("WasmExtension", () => { expect(result.data).toEqual(toAscii(`${codeId}`)); } + const funds = [coin(1234, "ucosm"), coin(321, "ustake")]; + const beneficiaryAddress = makeRandomAddress(); let contractAddress: string; // instantiate { - const result = await instantiateContract(wallet, codeId, beneficiaryAddress, transferAmount); + const result = await instantiateContract(wallet, codeId, beneficiaryAddress, funds); assertIsBroadcastTxSuccess(result); // console.log("Raw log:", result.raw_log); const parsedLogs = logs.parseLogs(result.logs); @@ -519,7 +518,7 @@ describe("WasmExtension", () => { expect(result.data).toEqual(Bech32.decode(contractAddress).data); const balance = (await client.auth.account(contractAddress)).result.value.coins; - expect(balance).toEqual(transferAmount); + expect(balance).toEqual(funds); } // execute @@ -539,7 +538,7 @@ describe("WasmExtension", () => { // Verify token transfer from contract to beneficiary const beneficiaryBalance = (await client.auth.account(beneficiaryAddress)).result.value.coins; - expect(beneficiaryBalance).toEqual(transferAmount); + expect(beneficiaryBalance).toEqual(funds); const contractBalance = (await client.auth.account(contractAddress)).result.value.coins; expect(contractBalance).toEqual([]); } diff --git a/packages/cosmwasm-launchpad/src/signingcosmwasmclient.spec.ts b/packages/cosmwasm-launchpad/src/signingcosmwasmclient.spec.ts index d6694533..b102a334 100644 --- a/packages/cosmwasm-launchpad/src/signingcosmwasmclient.spec.ts +++ b/packages/cosmwasm-launchpad/src/signingcosmwasmclient.spec.ts @@ -305,7 +305,7 @@ describe("SigningCosmWasmClient", () => { const client = new SigningCosmWasmClient(launchpad.endpoint, alice.address0, wallet); const { codeId } = await client.upload(getHackatom().data); - const transferAmount = [coin(1234, "ucosm"), coin(321, "ustake")]; + const funds = [coin(1234, "ucosm"), coin(321, "ustake")]; const beneficiaryAddress = makeRandomAddress(); const { contractAddress } = await client.instantiate( codeId, @@ -316,13 +316,13 @@ describe("SigningCosmWasmClient", () => { "My cool label", { memo: "Let's see if the memo is used", - transferAmount, + transferAmount: funds, }, ); const lcdClient = makeWasmClient(launchpad.endpoint); const balance = (await lcdClient.auth.account(contractAddress)).result.value.coins; - expect(balance).toEqual(transferAmount); + expect(balance).toEqual(funds); }); it("works with admin", async () => { @@ -486,7 +486,7 @@ describe("SigningCosmWasmClient", () => { const { codeId } = await client.upload(getHackatom().data); // instantiate - const transferAmount = [coin(233444, "ucosm"), coin(5454, "ustake")]; + const funds = [coin(233444, "ucosm"), coin(5454, "ustake")]; const beneficiaryAddress = makeRandomAddress(); const { contractAddress } = await client.instantiate( codeId, @@ -496,7 +496,7 @@ describe("SigningCosmWasmClient", () => { }, "amazing random contract", { - transferAmount, + transferAmount: funds, }, ); @@ -513,7 +513,7 @@ describe("SigningCosmWasmClient", () => { // Verify token transfer from contract to beneficiary const lcdClient = makeWasmClient(launchpad.endpoint); const beneficiaryBalance = (await lcdClient.auth.account(beneficiaryAddress)).result.value.coins; - expect(beneficiaryBalance).toEqual(transferAmount); + expect(beneficiaryBalance).toEqual(funds); const contractBalance = (await lcdClient.auth.account(contractAddress)).result.value.coins; expect(contractBalance).toEqual([]); }); @@ -525,7 +525,6 @@ describe("SigningCosmWasmClient", () => { const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = new SigningCosmWasmClient(launchpad.endpoint, alice.address0, wallet); - // instantiate const transferAmount = coins(7890, "ucosm"); const beneficiaryAddress = makeRandomAddress(); diff --git a/packages/cosmwasm-launchpad/src/signingcosmwasmclient.ts b/packages/cosmwasm-launchpad/src/signingcosmwasmclient.ts index 693df2a6..e872ea1d 100644 --- a/packages/cosmwasm-launchpad/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm-launchpad/src/signingcosmwasmclient.ts @@ -102,6 +102,15 @@ export interface UploadResult { */ export interface InstantiateOptions { readonly memo?: string; + /** + * The funds that are transferred from the sender to the newly created contract. + * The funds are transferred as part of the message execution after the contract address is + * created and before the instantiation message is executed by the contract. + * + * Only native tokens are supported. + * + * TODO: Rename to `funds` for consistency (https://github.com/cosmos/cosmjs/issues/806) + */ readonly transferAmount?: readonly Coin[]; /** * A bech32 encoded address of an admin account. @@ -218,7 +227,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { public async instantiate( codeId: number, - initMsg: Record, + msg: Record, label: string, options: InstantiateOptions = {}, ): Promise { @@ -228,7 +237,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { sender: this.signerAddress, code_id: new Uint53(codeId).toString(), label: label, - init_msg: initMsg, + init_msg: msg, init_funds: options.transferAmount || [], admin: options.admin, }, @@ -309,17 +318,17 @@ export class SigningCosmWasmClient extends CosmWasmClient { public async execute( contractAddress: string, - handleMsg: Record, + msg: Record, memo = "", - transferAmount?: readonly Coin[], + funds?: readonly Coin[], ): Promise { const executeMsg: MsgExecuteContract = { type: "wasm/MsgExecuteContract", value: { sender: this.signerAddress, contract: contractAddress, - msg: handleMsg, - sent_funds: transferAmount || [], + msg: msg, + sent_funds: funds || [], }, }; const result = await this.signAndBroadcast([executeMsg], this.fees.exec, memo); diff --git a/packages/cosmwasm-stargate/src/queries/wasm.spec.ts b/packages/cosmwasm-stargate/src/queries/wasm.spec.ts index 3cb93eb0..4f825d44 100644 --- a/packages/cosmwasm-stargate/src/queries/wasm.spec.ts +++ b/packages/cosmwasm-stargate/src/queries/wasm.spec.ts @@ -68,7 +68,7 @@ async function instantiateContract( signer: OfflineDirectSigner, codeId: number, beneficiaryAddress: string, - transferAmount?: readonly Coin[], + funds?: readonly Coin[], ): Promise { const memo = "Create an escrow instance"; const theMsg: MsgInstantiateContractEncodeObject = { @@ -83,7 +83,7 @@ async function instantiateContract( beneficiary: beneficiaryAddress, }), ), - funds: transferAmount ? [...transferAmount] : [], + funds: funds ? [...funds] : [], }), }; const fee: StdFee = { @@ -185,8 +185,6 @@ describe("WasmExtension", () => { assert(hackatomCodeId); const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix }); const client = await makeWasmClient(wasmd.endpoint); - const beneficiaryAddress = makeRandomAddress(); - const transferAmount = coins(707707, "ucosm"); // create new instance and compare before and after const { contracts: existingContracts } = await client.wasm.listContractsByCodeId(hackatomCodeId); @@ -195,7 +193,9 @@ describe("WasmExtension", () => { expect(address).toMatch(bech32AddressMatcher); } - const result = await instantiateContract(wallet, hackatomCodeId, beneficiaryAddress, transferAmount); + const beneficiaryAddress = makeRandomAddress(); + const funds = coins(707707, "ucosm"); + const result = await instantiateContract(wallet, hackatomCodeId, beneficiaryAddress, funds); assertIsBroadcastTxSuccess(result); const myAddress = JSON.parse(result.rawLog!)[0] .events.find((event: any) => event.type === "message") @@ -234,11 +234,11 @@ describe("WasmExtension", () => { assert(hackatomCodeId); const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix }); const client = await makeWasmClient(wasmd.endpoint); - const beneficiaryAddress = makeRandomAddress(); - const transferAmount = coins(707707, "ucosm"); // create new instance and compare before and after - const result = await instantiateContract(wallet, hackatomCodeId, beneficiaryAddress, transferAmount); + const beneficiaryAddress = makeRandomAddress(); + const funds = coins(707707, "ucosm"); + const result = await instantiateContract(wallet, hackatomCodeId, beneficiaryAddress, funds); assertIsBroadcastTxSuccess(result); const myAddress = JSON.parse(result.rawLog!)[0] @@ -363,7 +363,7 @@ describe("WasmExtension", () => { const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix }); const client = await makeWasmClient(wasmd.endpoint); - const transferAmount = [coin(1234, "ucosm"), coin(321, "ustake")]; + const funds = [coin(1234, "ucosm"), coin(321, "ustake")]; const beneficiaryAddress = makeRandomAddress(); let codeId: number; @@ -385,7 +385,7 @@ describe("WasmExtension", () => { // instantiate { - const result = await instantiateContract(wallet, codeId, beneficiaryAddress, transferAmount); + const result = await instantiateContract(wallet, codeId, beneficiaryAddress, funds); assertIsBroadcastTxSuccess(result); const parsedLogs = logs.parseLogs(logs.parseRawLog(result.rawLog)); const contractAddressAttr = logs.findAttribute(parsedLogs, "message", "contract_address"); @@ -396,9 +396,9 @@ describe("WasmExtension", () => { expect(actionAttr.value).toEqual("instantiate"); const balanceUcosm = await client.bank.balance(contractAddress, "ucosm"); - expect(balanceUcosm).toEqual(transferAmount[0]); + expect(balanceUcosm).toEqual(funds[0]); const balanceUstake = await client.bank.balance(contractAddress, "ustake"); - expect(balanceUstake).toEqual(transferAmount[1]); + expect(balanceUstake).toEqual(funds[1]); } // execute @@ -416,9 +416,9 @@ describe("WasmExtension", () => { // Verify token transfer from contract to beneficiary const beneficiaryBalanceUcosm = await client.bank.balance(beneficiaryAddress, "ucosm"); - expect(beneficiaryBalanceUcosm).toEqual(transferAmount[0]); + expect(beneficiaryBalanceUcosm).toEqual(funds[0]); const beneficiaryBalanceUstake = await client.bank.balance(beneficiaryAddress, "ustake"); - expect(beneficiaryBalanceUstake).toEqual(transferAmount[1]); + expect(beneficiaryBalanceUstake).toEqual(funds[1]); } }); }); diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts index 8d2d13cf..ec916bc1 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts @@ -266,7 +266,7 @@ describe("SigningCosmWasmClient", () => { const options = { prefix: wasmd.prefix }; const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, options); const { codeId } = await client.upload(alice.address0, getHackatom().data); - const transferAmount = [coin(1234, "ucosm"), coin(321, "ustake")]; + const funds = [coin(1234, "ucosm"), coin(321, "ustake")]; const beneficiaryAddress = makeRandomAddress(); const { contractAddress } = await client.instantiate( alice.address0, @@ -278,14 +278,14 @@ describe("SigningCosmWasmClient", () => { "My cool label", { memo: "Let's see if the memo is used", - transferAmount, + transferAmount: funds, }, ); const wasmClient = await makeWasmClient(wasmd.endpoint); const ucosmBalance = await wasmClient.bank.balance(contractAddress, "ucosm"); - expect(ucosmBalance).toEqual(transferAmount[0]); + expect(ucosmBalance).toEqual(funds[0]); const ustakeBalance = await wasmClient.bank.balance(contractAddress, "ustake"); - expect(ustakeBalance).toEqual(transferAmount[1]); + expect(ustakeBalance).toEqual(funds[1]); }); it("works with admin", async () => { @@ -448,7 +448,7 @@ describe("SigningCosmWasmClient", () => { const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, options); const { codeId } = await client.upload(alice.address0, getHackatom().data); // instantiate - const transferAmount = [coin(233444, "ucosm"), coin(5454, "ustake")]; + const funds = [coin(233444, "ucosm"), coin(5454, "ustake")]; const beneficiaryAddress = makeRandomAddress(); const { contractAddress } = await client.instantiate( alice.address0, @@ -459,7 +459,7 @@ describe("SigningCosmWasmClient", () => { }, "amazing random contract", { - transferAmount, + transferAmount: funds, }, ); // execute @@ -474,9 +474,9 @@ describe("SigningCosmWasmClient", () => { // Verify token transfer from contract to beneficiary const wasmClient = await makeWasmClient(wasmd.endpoint); const beneficiaryBalanceUcosm = await wasmClient.bank.balance(beneficiaryAddress, "ucosm"); - expect(beneficiaryBalanceUcosm).toEqual(transferAmount[0]); + expect(beneficiaryBalanceUcosm).toEqual(funds[0]); const beneficiaryBalanceUstake = await wasmClient.bank.balance(beneficiaryAddress, "ustake"); - expect(beneficiaryBalanceUstake).toEqual(transferAmount[1]); + expect(beneficiaryBalanceUstake).toEqual(funds[1]); const contractBalanceUcosm = await wasmClient.bank.balance(contractAddress, "ucosm"); expect(contractBalanceUcosm).toEqual(coin(0, "ucosm")); const contractBalanceUstake = await wasmClient.bank.balance(contractAddress, "ustake"); diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts index 0cd4e3c2..a5161c67 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts @@ -234,7 +234,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { public async instantiate( senderAddress: string, codeId: number, - initMsg: Record, + msg: Record, label: string, options: InstantiateOptions = {}, ): Promise { @@ -244,7 +244,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { sender: senderAddress, codeId: Long.fromString(new Uint53(codeId).toString()), label: label, - initMsg: toUtf8(JSON.stringify(initMsg)), + initMsg: toUtf8(JSON.stringify(msg)), funds: [...(options.transferAmount || [])], admin: options.admin, }), @@ -342,17 +342,17 @@ export class SigningCosmWasmClient extends CosmWasmClient { public async execute( senderAddress: string, contractAddress: string, - handleMsg: Record, + msg: Record, memo = "", - transferAmount?: readonly Coin[], + funds?: readonly Coin[], ): Promise { const executeContractMsg: MsgExecuteContractEncodeObject = { typeUrl: "/cosmwasm.wasm.v1beta1.MsgExecuteContract", value: MsgExecuteContract.fromPartial({ sender: senderAddress, contract: contractAddress, - msg: toUtf8(JSON.stringify(handleMsg)), - funds: [...(transferAmount || [])], + msg: toUtf8(JSON.stringify(msg)), + funds: [...(funds || [])], }), }; const result = await this.signAndBroadcast(senderAddress, [executeContractMsg], this.fees.exec, memo); diff --git a/packages/launchpad/src/lcdapi/lcdclient.spec.ts b/packages/launchpad/src/lcdapi/lcdclient.spec.ts index c1024991..f9374b92 100644 --- a/packages/launchpad/src/lcdapi/lcdclient.spec.ts +++ b/packages/launchpad/src/lcdapi/lcdclient.spec.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { Coin, makeCosmoshubPath, makeSignDoc, Secp256k1HdWallet, StdFee } from "@cosmjs/amino"; +import { Coin, coins, makeCosmoshubPath, makeSignDoc, Secp256k1HdWallet, StdFee } from "@cosmjs/amino"; import { assert, sleep } from "@cosmjs/utils"; import { isBroadcastTxFailure } from "../cosmosclient"; @@ -195,11 +195,8 @@ describe("LcdClient", () => { { const recipient = makeRandomAddress(); - const transferAmount = { - denom: "ucosm", - amount: "1234567", - }; - const result = await client.sendTokens(recipient, [transferAmount]); + const transferAmount = coins(1234567, "ucosm"); + const result = await client.sendTokens(recipient, transferAmount); successful = { sender: faucet.address0, recipient: recipient, @@ -210,12 +207,7 @@ describe("LcdClient", () => { { const memo = "Sending more than I can afford"; const recipient = makeRandomAddress(); - const transferAmount = [ - { - denom: "ucosm", - amount: "123456700000000", - }, - ]; + const transferAmount = coins(123456700000000, "ucosm"); const sendMsg: MsgSend = { type: "cosmos-sdk/MsgSend", value: { @@ -225,12 +217,7 @@ describe("LcdClient", () => { }, }; const fee = { - amount: [ - { - denom: "ucosm", - amount: "2000", - }, - ], + amount: coins(2000, "ucosm"), gas: "80000", // 80k }; const { accountNumber, sequence } = await client.getSequence(); @@ -319,12 +306,7 @@ describe("LcdClient", () => { const client = new SigningCosmosClient(launchpad.endpoint, faucet.address0, wallet); const recipient = makeRandomAddress(); - const transferAmount = [ - { - denom: "ucosm", - amount: "1234567", - }, - ]; + const transferAmount = coins(1234567, "ucosm"); const result = await client.sendTokens(recipient, transferAmount); await sleep(75); // wait until tx is indexed diff --git a/packages/launchpad/src/signingcosmosclient.spec.ts b/packages/launchpad/src/signingcosmosclient.spec.ts index ffe40dda..81758156 100644 --- a/packages/launchpad/src/signingcosmosclient.spec.ts +++ b/packages/launchpad/src/signingcosmosclient.spec.ts @@ -129,7 +129,6 @@ describe("SigningCosmosClient", () => { const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic); const client = new SigningCosmosClient(launchpad.endpoint, faucet.address0, wallet); - // instantiate const transferAmount: readonly Coin[] = [ { amount: "7890", From 9a1d889742145b3167bd18c36f4796995896e359 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 18 May 2021 14:27:47 +0200 Subject: [PATCH 2/2] Rename transferAmount -> amount for MsgSend --- .../src/cosmwasmclient.searchtx.spec.ts | 16 ++++++---------- .../src/signingcosmwasmclient.spec.ts | 6 +++--- .../src/signingcosmwasmclient.ts | 4 ++-- .../src/signingcosmwasmclient.spec.ts | 12 ++++++------ .../src/signingcosmwasmclient.ts | 4 ++-- .../launchpad/src/cosmosclient.searchtx.spec.ts | 8 ++++---- packages/launchpad/src/lcdapi/lcdclient.spec.ts | 12 ++++++------ .../launchpad/src/signingcosmosclient.spec.ts | 13 ++++--------- packages/launchpad/src/signingcosmosclient.ts | 4 ++-- .../stargate/src/signingstargateclient.spec.ts | 12 ++++++------ packages/stargate/src/signingstargateclient.ts | 4 ++-- 11 files changed, 43 insertions(+), 52 deletions(-) diff --git a/packages/cosmwasm-launchpad/src/cosmwasmclient.searchtx.spec.ts b/packages/cosmwasm-launchpad/src/cosmwasmclient.searchtx.spec.ts index 8884630f..99cfac6d 100644 --- a/packages/cosmwasm-launchpad/src/cosmwasmclient.searchtx.spec.ts +++ b/packages/cosmwasm-launchpad/src/cosmwasmclient.searchtx.spec.ts @@ -1,6 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { - Coin, coins, isBroadcastTxFailure, isMsgSend, @@ -57,8 +56,8 @@ describe("CosmWasmClient.getTx and .searchTx", () => { { const recipient = makeRandomAddress(); - const transferAmount = coins(1234567, "ucosm"); - const result = await client.sendTokens(recipient, transferAmount); + const amount = coins(1234567, "ucosm"); + const result = await client.sendTokens(recipient, amount); await sleep(75); // wait until tx is indexed const txDetails = await new LcdClient(launchpad.endpoint).txById(result.transactionHash); sendSuccessful = { @@ -72,11 +71,8 @@ describe("CosmWasmClient.getTx and .searchTx", () => { { const recipient = alice.address0; - const transferAmount: Coin = { - denom: "ucosm", - amount: "2345678", - }; - const result = await client.sendTokens(recipient, [transferAmount]); + const amount = coins(2345678, "ucosm"); + const result = await client.sendTokens(recipient, amount); await sleep(75); // wait until tx is indexed const txDetails = await new LcdClient(launchpad.endpoint).txById(result.transactionHash); sendSelfSuccessful = { @@ -91,13 +87,13 @@ describe("CosmWasmClient.getTx and .searchTx", () => { { const memo = "Sending more than I can afford"; const recipient = makeRandomAddress(); - const transferAmount = coins(123456700000000, "ucosm"); + const amount = coins(123456700000000, "ucosm"); const sendMsg: MsgSend = { type: "cosmos-sdk/MsgSend", value: { from_address: alice.address0, to_address: recipient, - amount: transferAmount, + amount: amount, }, }; const fee = { diff --git a/packages/cosmwasm-launchpad/src/signingcosmwasmclient.spec.ts b/packages/cosmwasm-launchpad/src/signingcosmwasmclient.spec.ts index b102a334..2cd5c49a 100644 --- a/packages/cosmwasm-launchpad/src/signingcosmwasmclient.spec.ts +++ b/packages/cosmwasm-launchpad/src/signingcosmwasmclient.spec.ts @@ -525,7 +525,7 @@ describe("SigningCosmWasmClient", () => { const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic); const client = new SigningCosmWasmClient(launchpad.endpoint, alice.address0, wallet); - const transferAmount = coins(7890, "ucosm"); + const amount = coins(7890, "ucosm"); const beneficiaryAddress = makeRandomAddress(); // no tokens here @@ -533,7 +533,7 @@ describe("SigningCosmWasmClient", () => { expect(before).toBeUndefined(); // send - const result = await client.sendTokens(beneficiaryAddress, transferAmount, "for dinner"); + const result = await client.sendTokens(beneficiaryAddress, amount, "for dinner"); assertIsBroadcastTxSuccess(result); const [firstLog] = result.logs; expect(firstLog).toBeTruthy(); @@ -541,7 +541,7 @@ describe("SigningCosmWasmClient", () => { // got tokens const after = await client.getAccount(beneficiaryAddress); assert(after); - expect(after.balance).toEqual(transferAmount); + expect(after.balance).toEqual(amount); }); }); diff --git a/packages/cosmwasm-launchpad/src/signingcosmwasmclient.ts b/packages/cosmwasm-launchpad/src/signingcosmwasmclient.ts index e872ea1d..35998fcf 100644 --- a/packages/cosmwasm-launchpad/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm-launchpad/src/signingcosmwasmclient.ts @@ -343,7 +343,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { public async sendTokens( recipientAddress: string, - transferAmount: readonly Coin[], + amount: readonly Coin[], memo = "", ): Promise { const sendMsg: MsgSend = { @@ -351,7 +351,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { value: { from_address: this.signerAddress, to_address: recipientAddress, - amount: transferAmount, + amount: amount, }, }; return this.signAndBroadcast([sendMsg], this.fees.send, memo); diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts index ec916bc1..ff14f70d 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts @@ -491,7 +491,7 @@ describe("SigningCosmWasmClient", () => { const options = { prefix: wasmd.prefix }; const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, options); - const transferAmount = coins(7890, "ucosm"); + const amount = coins(7890, "ucosm"); const beneficiaryAddress = makeRandomAddress(); const memo = "for dinner"; @@ -503,14 +503,14 @@ describe("SigningCosmWasmClient", () => { }); // send - const result = await client.sendTokens(alice.address0, beneficiaryAddress, transferAmount, memo); + const result = await client.sendTokens(alice.address0, beneficiaryAddress, amount, memo); assertIsBroadcastTxSuccess(result); expect(result.rawLog).toBeTruthy(); // got tokens const after = await client.getBalance(beneficiaryAddress, "ucosm"); assert(after); - expect(after).toEqual(transferAmount[0]); + expect(after).toEqual(amount[0]); }); it("works with legacy Amino signer", async () => { @@ -519,7 +519,7 @@ describe("SigningCosmWasmClient", () => { const options = { prefix: wasmd.prefix }; const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, options); - const transferAmount = coins(7890, "ucosm"); + const amount = coins(7890, "ucosm"); const beneficiaryAddress = makeRandomAddress(); const memo = "for dinner"; @@ -531,14 +531,14 @@ describe("SigningCosmWasmClient", () => { }); // send - const result = await client.sendTokens(alice.address0, beneficiaryAddress, transferAmount, memo); + const result = await client.sendTokens(alice.address0, beneficiaryAddress, amount, memo); assertIsBroadcastTxSuccess(result); expect(result.rawLog).toBeTruthy(); // got tokens const after = await client.getBalance(beneficiaryAddress, "ucosm"); assert(after); - expect(after).toEqual(transferAmount[0]); + expect(after).toEqual(amount[0]); }); }); diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts index a5161c67..b1894aeb 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts @@ -368,7 +368,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { public async sendTokens( senderAddress: string, recipientAddress: string, - transferAmount: readonly Coin[], + amount: readonly Coin[], memo = "", ): Promise { const sendMsg: MsgSendEncodeObject = { @@ -376,7 +376,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { value: { fromAddress: senderAddress, toAddress: recipientAddress, - amount: [...transferAmount], + amount: [...amount], }, }; return this.signAndBroadcast(senderAddress, [sendMsg], this.fees.send, memo); diff --git a/packages/launchpad/src/cosmosclient.searchtx.spec.ts b/packages/launchpad/src/cosmosclient.searchtx.spec.ts index e3e6c56f..d4e4c197 100644 --- a/packages/launchpad/src/cosmosclient.searchtx.spec.ts +++ b/packages/launchpad/src/cosmosclient.searchtx.spec.ts @@ -38,13 +38,13 @@ describe("CosmosClient.getTx and .searchTx", () => { { const memo = "Sending more than I can afford"; const recipient = makeRandomAddress(); - const transferAmount = coins(123456700000000, "ucosm"); + const amount = coins(123456700000000, "ucosm"); const sendMsg: MsgSend = { type: "cosmos-sdk/MsgSend", value: { from_address: faucet.address0, to_address: recipient, - amount: transferAmount, + amount: amount, }, }; const fee = { @@ -74,8 +74,8 @@ describe("CosmosClient.getTx and .searchTx", () => { { const recipient = makeRandomAddress(); - const transferAmount = coins(1234567, "ucosm"); - const result = await client.sendTokens(recipient, transferAmount); + const amount = coins(1234567, "ucosm"); + const result = await client.sendTokens(recipient, amount); await sleep(75); // wait until tx is indexed const txDetails = await new LcdClient(launchpad.endpoint).txById(result.transactionHash); sendSuccessful = { diff --git a/packages/launchpad/src/lcdapi/lcdclient.spec.ts b/packages/launchpad/src/lcdapi/lcdclient.spec.ts index f9374b92..a06086fe 100644 --- a/packages/launchpad/src/lcdapi/lcdclient.spec.ts +++ b/packages/launchpad/src/lcdapi/lcdclient.spec.ts @@ -195,8 +195,8 @@ describe("LcdClient", () => { { const recipient = makeRandomAddress(); - const transferAmount = coins(1234567, "ucosm"); - const result = await client.sendTokens(recipient, transferAmount); + const amount = coins(1234567, "ucosm"); + const result = await client.sendTokens(recipient, amount); successful = { sender: faucet.address0, recipient: recipient, @@ -207,13 +207,13 @@ describe("LcdClient", () => { { const memo = "Sending more than I can afford"; const recipient = makeRandomAddress(); - const transferAmount = coins(123456700000000, "ucosm"); + const amount = coins(123456700000000, "ucosm"); const sendMsg: MsgSend = { type: "cosmos-sdk/MsgSend", value: { from_address: faucet.address0, to_address: recipient, - amount: transferAmount, + amount: amount, }, }; const fee = { @@ -306,8 +306,8 @@ describe("LcdClient", () => { const client = new SigningCosmosClient(launchpad.endpoint, faucet.address0, wallet); const recipient = makeRandomAddress(); - const transferAmount = coins(1234567, "ucosm"); - const result = await client.sendTokens(recipient, transferAmount); + const amount = coins(1234567, "ucosm"); + const result = await client.sendTokens(recipient, amount); await sleep(75); // wait until tx is indexed const txDetails = await new LcdClient(launchpad.endpoint).txById(result.transactionHash); diff --git a/packages/launchpad/src/signingcosmosclient.spec.ts b/packages/launchpad/src/signingcosmosclient.spec.ts index 81758156..5878700c 100644 --- a/packages/launchpad/src/signingcosmosclient.spec.ts +++ b/packages/launchpad/src/signingcosmosclient.spec.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { Coin, coin, coins, makeCosmoshubPath, Secp256k1HdWallet } from "@cosmjs/amino"; +import { coin, coins, makeCosmoshubPath, Secp256k1HdWallet } from "@cosmjs/amino"; import { assert } from "@cosmjs/utils"; import { assertIsBroadcastTxSuccess, PrivateCosmosClient } from "./cosmosclient"; @@ -129,12 +129,7 @@ describe("SigningCosmosClient", () => { const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic); const client = new SigningCosmosClient(launchpad.endpoint, faucet.address0, wallet); - const transferAmount: readonly Coin[] = [ - { - amount: "7890", - denom: "ucosm", - }, - ]; + const amount = coins(7890, "ucosm"); const beneficiaryAddress = makeRandomAddress(); // no tokens here @@ -142,7 +137,7 @@ describe("SigningCosmosClient", () => { expect(before).toBeUndefined(); // send - const result = await client.sendTokens(beneficiaryAddress, transferAmount, "for dinner"); + const result = await client.sendTokens(beneficiaryAddress, amount, "for dinner"); assertIsBroadcastTxSuccess(result); const [firstLog] = result.logs; expect(firstLog).toBeTruthy(); @@ -150,7 +145,7 @@ describe("SigningCosmosClient", () => { // got tokens const after = await client.getAccount(beneficiaryAddress); assert(after); - expect(after.balance).toEqual(transferAmount); + expect(after.balance).toEqual(amount); }); }); diff --git a/packages/launchpad/src/signingcosmosclient.ts b/packages/launchpad/src/signingcosmosclient.ts index f97e7da2..125807ec 100644 --- a/packages/launchpad/src/signingcosmosclient.ts +++ b/packages/launchpad/src/signingcosmosclient.ts @@ -67,7 +67,7 @@ export class SigningCosmosClient extends CosmosClient { public async sendTokens( recipientAddress: string, - transferAmount: readonly Coin[], + amount: readonly Coin[], memo = "", ): Promise { const sendMsg: MsgSend = { @@ -75,7 +75,7 @@ export class SigningCosmosClient extends CosmosClient { value: { from_address: this.signerAddress, to_address: recipientAddress, - amount: transferAmount, + amount: amount, }, }; return this.signAndBroadcast([sendMsg], this.fees.send, memo); diff --git a/packages/stargate/src/signingstargateclient.spec.ts b/packages/stargate/src/signingstargateclient.spec.ts index 79214bd7..f882f8cc 100644 --- a/packages/stargate/src/signingstargateclient.spec.ts +++ b/packages/stargate/src/signingstargateclient.spec.ts @@ -273,7 +273,7 @@ describe("SigningStargateClient", () => { const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic); const client = await SigningStargateClient.connectWithSigner(simapp.tendermintUrl, wallet); - const transferAmount = coins(7890, "ucosm"); + const amount = coins(7890, "ucosm"); const beneficiaryAddress = makeRandomAddress(); const memo = "for dinner"; @@ -285,13 +285,13 @@ describe("SigningStargateClient", () => { }); // send - const result = await client.sendTokens(faucet.address0, beneficiaryAddress, transferAmount, memo); + const result = await client.sendTokens(faucet.address0, beneficiaryAddress, amount, memo); assertIsBroadcastTxSuccess(result); expect(result.rawLog).toBeTruthy(); // got tokens const after = await client.getBalance(beneficiaryAddress, "ucosm"); - expect(after).toEqual(transferAmount[0]); + expect(after).toEqual(amount[0]); }); it("works with legacy Amino signer", async () => { @@ -299,7 +299,7 @@ describe("SigningStargateClient", () => { const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic); const client = await SigningStargateClient.connectWithSigner(simapp.tendermintUrl, wallet); - const transferAmount = coins(7890, "ucosm"); + const amount = coins(7890, "ucosm"); const beneficiaryAddress = makeRandomAddress(); const memo = "for dinner"; @@ -311,13 +311,13 @@ describe("SigningStargateClient", () => { }); // send - const result = await client.sendTokens(faucet.address0, beneficiaryAddress, transferAmount, memo); + const result = await client.sendTokens(faucet.address0, beneficiaryAddress, amount, memo); assertIsBroadcastTxSuccess(result); expect(result.rawLog).toBeTruthy(); // got tokens const after = await client.getBalance(beneficiaryAddress, "ucosm"); - expect(after).toEqual(transferAmount[0]); + expect(after).toEqual(amount[0]); }); }); diff --git a/packages/stargate/src/signingstargateclient.ts b/packages/stargate/src/signingstargateclient.ts index 02b80ce6..e2b66329 100644 --- a/packages/stargate/src/signingstargateclient.ts +++ b/packages/stargate/src/signingstargateclient.ts @@ -212,7 +212,7 @@ export class SigningStargateClient extends StargateClient { public async sendTokens( senderAddress: string, recipientAddress: string, - transferAmount: readonly Coin[], + amount: readonly Coin[], memo = "", ): Promise { const sendMsg: MsgSendEncodeObject = { @@ -220,7 +220,7 @@ export class SigningStargateClient extends StargateClient { value: { fromAddress: senderAddress, toAddress: recipientAddress, - amount: [...transferAmount], + amount: [...amount], }, }; return this.signAndBroadcast(senderAddress, [sendMsg], this.fees.send, memo);