Merge pull request #807 from cosmos/prepare-funds
Prepare the renaming transferAmount -> funds
This commit is contained in:
commit
ca4bb8ca89
@ -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 = {
|
||||
|
||||
@ -77,7 +77,7 @@ async function instantiateContract(
|
||||
signer: OfflineSigner,
|
||||
codeId: number,
|
||||
beneficiaryAddress: string,
|
||||
transferAmount?: readonly Coin[],
|
||||
funds?: readonly Coin[],
|
||||
): Promise<BroadcastTxResult> {
|
||||
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([]);
|
||||
}
|
||||
|
||||
@ -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,8 +525,7 @@ 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 amount = coins(7890, "ucosm");
|
||||
const beneficiaryAddress = makeRandomAddress();
|
||||
|
||||
// no tokens here
|
||||
@ -534,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();
|
||||
@ -542,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);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -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<string, unknown>,
|
||||
msg: Record<string, unknown>,
|
||||
label: string,
|
||||
options: InstantiateOptions = {},
|
||||
): Promise<InstantiateResult> {
|
||||
@ -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<string, unknown>,
|
||||
msg: Record<string, unknown>,
|
||||
memo = "",
|
||||
transferAmount?: readonly Coin[],
|
||||
funds?: readonly Coin[],
|
||||
): Promise<ExecuteResult> {
|
||||
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);
|
||||
@ -334,7 +343,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
|
||||
public async sendTokens(
|
||||
recipientAddress: string,
|
||||
transferAmount: readonly Coin[],
|
||||
amount: readonly Coin[],
|
||||
memo = "",
|
||||
): Promise<BroadcastTxResult> {
|
||||
const sendMsg: MsgSend = {
|
||||
@ -342,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);
|
||||
|
||||
@ -68,7 +68,7 @@ async function instantiateContract(
|
||||
signer: OfflineDirectSigner,
|
||||
codeId: number,
|
||||
beneficiaryAddress: string,
|
||||
transferAmount?: readonly Coin[],
|
||||
funds?: readonly Coin[],
|
||||
): Promise<BroadcastTxResponse> {
|
||||
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]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -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");
|
||||
@ -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]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -234,7 +234,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
public async instantiate(
|
||||
senderAddress: string,
|
||||
codeId: number,
|
||||
initMsg: Record<string, unknown>,
|
||||
msg: Record<string, unknown>,
|
||||
label: string,
|
||||
options: InstantiateOptions = {},
|
||||
): Promise<InstantiateResult> {
|
||||
@ -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<string, unknown>,
|
||||
msg: Record<string, unknown>,
|
||||
memo = "",
|
||||
transferAmount?: readonly Coin[],
|
||||
funds?: readonly Coin[],
|
||||
): Promise<ExecuteResult> {
|
||||
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);
|
||||
@ -368,7 +368,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
public async sendTokens(
|
||||
senderAddress: string,
|
||||
recipientAddress: string,
|
||||
transferAmount: readonly Coin[],
|
||||
amount: readonly Coin[],
|
||||
memo = "",
|
||||
): Promise<BroadcastTxResponse> {
|
||||
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);
|
||||
|
||||
@ -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 = {
|
||||
|
||||
@ -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 amount = coins(1234567, "ucosm");
|
||||
const result = await client.sendTokens(recipient, amount);
|
||||
successful = {
|
||||
sender: faucet.address0,
|
||||
recipient: recipient,
|
||||
@ -210,27 +207,17 @@ describe("LcdClient", () => {
|
||||
{
|
||||
const memo = "Sending more than I can afford";
|
||||
const recipient = makeRandomAddress();
|
||||
const transferAmount = [
|
||||
{
|
||||
denom: "ucosm",
|
||||
amount: "123456700000000",
|
||||
},
|
||||
];
|
||||
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 = {
|
||||
amount: [
|
||||
{
|
||||
denom: "ucosm",
|
||||
amount: "2000",
|
||||
},
|
||||
],
|
||||
amount: coins(2000, "ucosm"),
|
||||
gas: "80000", // 80k
|
||||
};
|
||||
const { accountNumber, sequence } = await client.getSequence();
|
||||
@ -319,13 +306,8 @@ describe("LcdClient", () => {
|
||||
const client = new SigningCosmosClient(launchpad.endpoint, faucet.address0, wallet);
|
||||
|
||||
const recipient = makeRandomAddress();
|
||||
const transferAmount = [
|
||||
{
|
||||
denom: "ucosm",
|
||||
amount: "1234567",
|
||||
},
|
||||
];
|
||||
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);
|
||||
|
||||
@ -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,13 +129,7 @@ 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",
|
||||
denom: "ucosm",
|
||||
},
|
||||
];
|
||||
const amount = coins(7890, "ucosm");
|
||||
const beneficiaryAddress = makeRandomAddress();
|
||||
|
||||
// no tokens here
|
||||
@ -143,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();
|
||||
@ -151,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);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -67,7 +67,7 @@ export class SigningCosmosClient extends CosmosClient {
|
||||
|
||||
public async sendTokens(
|
||||
recipientAddress: string,
|
||||
transferAmount: readonly Coin[],
|
||||
amount: readonly Coin[],
|
||||
memo = "",
|
||||
): Promise<BroadcastTxResult> {
|
||||
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);
|
||||
|
||||
@ -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]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -212,7 +212,7 @@ export class SigningStargateClient extends StargateClient {
|
||||
public async sendTokens(
|
||||
senderAddress: string,
|
||||
recipientAddress: string,
|
||||
transferAmount: readonly Coin[],
|
||||
amount: readonly Coin[],
|
||||
memo = "",
|
||||
): Promise<BroadcastTxResponse> {
|
||||
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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user