cosmwasm: Update Cw1CosmWasmClient for review comments

This commit is contained in:
willclarktech 2020-11-26 17:28:58 +00:00
parent a013829460
commit 43b8c154db
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7
3 changed files with 14 additions and 49 deletions

View File

@ -46,7 +46,7 @@ describe("Cw1CosmWasmClient", () => {
);
const result = await client.canSend(defaultMsg);
expect(result).toEqual({ can_send: true });
expect(result).toEqual(true);
});
it("returns false if client signer cannot send", async () => {
@ -62,7 +62,7 @@ describe("Cw1CosmWasmClient", () => {
);
const result = await client.canSend(defaultMsg);
expect(result).toEqual({ can_send: false });
expect(result).toEqual(false);
});
it("returns true if supplied signer can send", async () => {
@ -78,7 +78,7 @@ describe("Cw1CosmWasmClient", () => {
);
const result = await client.canSend(defaultMsg, alice.address0);
expect(result).toEqual({ can_send: true });
expect(result).toEqual(true);
});
it("returns false if supplied signer cannot send", async () => {
@ -94,7 +94,7 @@ describe("Cw1CosmWasmClient", () => {
);
const result = await client.canSend(defaultMsg, alice.address1);
expect(result).toEqual({ can_send: false });
expect(result).toEqual(false);
});
});
@ -114,26 +114,5 @@ describe("Cw1CosmWasmClient", () => {
expect(result.transactionHash).toBeTruthy();
});
it("works with a transfer", async () => {
pendingWithoutLaunchpad();
pendingWithoutCw1();
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic);
const client = new Cw1CosmWasmClient(
launchpad.endpoint,
alice.address0,
wallet,
deployedCw1.instances[0],
);
const balanceBefore = parseInt((await client.getAccount())!.balance[0].amount, 10);
const memo = "This time with coins";
const transferAmount = coins(1000, "ucosm");
const result = await client.executeSubkey([defaultMsg], memo, transferAmount);
const balanceAfter = parseInt((await client.getAccount())!.balance[0].amount, 10);
expect(result.transactionHash).toBeTruthy();
expect(balanceAfter).toEqual(balanceBefore + 999);
});
});
});

View File

@ -1,13 +1,9 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { Account, BroadcastMode, Coin, GasLimits, GasPrice, OfflineSigner } from "@cosmjs/launchpad";
import { Account, BroadcastMode, GasLimits, GasPrice, OfflineSigner } from "@cosmjs/launchpad";
import { CosmosMsg } from "./cosmosmsg";
import { CosmWasmFeeTable, ExecuteResult, SigningCosmWasmClient } from "./signingcosmwasmclient";
export interface CanSendResult {
readonly can_send: boolean;
}
export class Cw1CosmWasmClient extends SigningCosmWasmClient {
public readonly cw1ContractAddress: string;
@ -24,29 +20,26 @@ export class Cw1CosmWasmClient extends SigningCosmWasmClient {
this.cw1ContractAddress = cw1ContractAddress;
}
public getAccount(address?: string): Promise<Account | undefined> {
public async getAccount(address?: string): Promise<Account | undefined> {
return super.getAccount(address || this.cw1ContractAddress);
}
public canSend(msg: CosmosMsg, address = this.senderAddress): Promise<CanSendResult> {
return this.queryContractSmart(this.cw1ContractAddress, {
public async canSend(msg: CosmosMsg, address = this.senderAddress): Promise<boolean> {
const result = await this.queryContractSmart(this.cw1ContractAddress, {
can_send: {
sender: address,
msg: msg,
},
});
return result.can_send;
}
public executeSubkey(
msgs: readonly CosmosMsg[],
memo = "",
transferAmount: readonly Coin[] = [],
): Promise<ExecuteResult> {
public async executeSubkey(msgs: readonly CosmosMsg[], memo = ""): Promise<ExecuteResult> {
const handleMsg = {
execute: {
msgs: msgs,
},
};
return this.execute(this.cw1ContractAddress, handleMsg, memo, transferAmount);
return this.execute(this.cw1ContractAddress, handleMsg, memo);
}
}

View File

@ -1,9 +1,6 @@
import { Account, BroadcastMode, Coin, GasLimits, GasPrice, OfflineSigner } from "@cosmjs/launchpad";
import { Account, BroadcastMode, GasLimits, GasPrice, OfflineSigner } from "@cosmjs/launchpad";
import { CosmosMsg } from "./cosmosmsg";
import { CosmWasmFeeTable, ExecuteResult, SigningCosmWasmClient } from "./signingcosmwasmclient";
export interface CanSendResult {
readonly can_send: boolean;
}
export declare class Cw1CosmWasmClient extends SigningCosmWasmClient {
readonly cw1ContractAddress: string;
constructor(
@ -16,10 +13,6 @@ export declare class Cw1CosmWasmClient extends SigningCosmWasmClient {
broadcastMode?: BroadcastMode,
);
getAccount(address?: string): Promise<Account | undefined>;
canSend(msg: CosmosMsg, address?: string): Promise<CanSendResult>;
executeSubkey(
msgs: readonly CosmosMsg[],
memo?: string,
transferAmount?: readonly Coin[],
): Promise<ExecuteResult>;
canSend(msg: CosmosMsg, address?: string): Promise<boolean>;
executeSubkey(msgs: readonly CosmosMsg[], memo?: string): Promise<ExecuteResult>;
}