Merge pull request #546 from cosmos/cw3-multisig-ethan-comments

CW3 Multisig adjustments
This commit is contained in:
Will Clark 2020-11-24 17:46:18 +01:00 committed by GitHub
commit c0b714bc5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 31 deletions

View File

@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { makeCosmoshubPath, Secp256k1HdWallet } from "@cosmjs/launchpad";
import { assert, sleep } from "@cosmjs/utils";
import { assert } from "@cosmjs/utils";
import { Cw3CosmWasmClient, Vote } from "./cw3cosmwasmclient";
import {
@ -257,6 +257,11 @@ describe("Cw3CosmWasmClient", () => {
]);
const { proposals } = await voter.reverseProposals({ limit: 1 });
const proposalId = proposals[0].id;
await expectAsync(proposer.executeMultisigProposal(proposalId)).toBeRejectedWithError(
/proposal must have passed and not yet been executed/i,
);
const voteResult = await voter.voteMultisigProposal(proposalId, Vote.Yes);
expect(voteResult).toBeTruthy();
@ -314,7 +319,9 @@ describe("Cw3CosmWasmClient", () => {
const vote2Result = await voter2.voteMultisigProposal(proposalId, Vote.No);
expect(vote2Result).toBeTruthy();
await sleep(2000);
await expectAsync(proposer.executeMultisigProposal(proposalId)).toBeRejectedWithError(
/proposal must have passed and not yet been executed/i,
);
const closeResult = await proposer.closeMultisigProposal(proposalId);
expect(closeResult).toBeTruthy();

View File

@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { BroadcastMode, GasLimits, GasPrice, OfflineSigner } from "@cosmjs/launchpad";
import { Account } from "./cosmwasmclient";
import { CosmWasmFeeTable, ExecuteResult, SigningCosmWasmClient } from "./signingcosmwasmclient";
export type Expiration =
@ -71,21 +72,25 @@ interface StartAfterStringPaginationOptions {
}
export class Cw3CosmWasmClient extends SigningCosmWasmClient {
private readonly cw3ContractAddress: string;
public readonly cw3ContractAddress: string;
public constructor(
apiUrl: string,
senderAddress: string,
signerAddress: string,
signer: OfflineSigner,
cw3ContractAddress: string,
gasPrice?: GasPrice,
gasLimits?: Partial<GasLimits<CosmWasmFeeTable>>,
broadcastMode?: BroadcastMode,
) {
super(apiUrl, senderAddress, signer, gasPrice, gasLimits, broadcastMode);
super(apiUrl, signerAddress, signer, gasPrice, gasLimits, broadcastMode);
this.cw3ContractAddress = cw3ContractAddress;
}
public getAccount(address?: string): Promise<Account | undefined> {
return super.getAccount(address || this.cw3ContractAddress);
}
public getThreshold(): Promise<ThresholdResult> {
return this.queryContractSmart(this.cw3ContractAddress, { threshold: {} });
}

View File

@ -26,8 +26,6 @@ import {
unused,
} from "./testutils.spec";
const httpUrl = "http://localhost:1317";
function makeWasmClient(apiUrl: string): LcdClient & AuthExtension & WasmExtension {
return LcdClient.withExtensions({ apiUrl }, setupAuthExtension, setupWasmExtension);
}
@ -36,14 +34,14 @@ describe("SigningCosmWasmClient", () => {
describe("makeReadOnly", () => {
it("can be constructed", async () => {
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const client = new SigningCosmWasmClient(launchpad.endpoint, alice.address0, wallet);
expect(client).toBeTruthy();
});
it("can be constructed with custom gas price", async () => {
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic);
const gasPrice = GasPrice.fromString("3.14utest");
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet, gasPrice);
const client = new SigningCosmWasmClient(launchpad.endpoint, alice.address0, wallet, gasPrice);
const openedClient = (client as unknown) as PrivateSigningCosmWasmClient;
expect(openedClient.fees).toEqual({
upload: {
@ -108,7 +106,13 @@ describe("SigningCosmWasmClient", () => {
const gasLimits = {
send: 160000,
};
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet, undefined, gasLimits);
const client = new SigningCosmWasmClient(
launchpad.endpoint,
alice.address0,
wallet,
undefined,
gasLimits,
);
const openedClient = (client as unknown) as PrivateSigningCosmWasmClient;
expect(openedClient.fees).toEqual({
upload: {
@ -174,7 +178,13 @@ describe("SigningCosmWasmClient", () => {
const gasLimits = {
send: 160000,
};
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet, gasPrice, gasLimits);
const client = new SigningCosmWasmClient(
launchpad.endpoint,
alice.address0,
wallet,
gasPrice,
gasLimits,
);
const openedClient = (client as unknown) as PrivateSigningCosmWasmClient;
expect(openedClient.fees).toEqual({
upload: {
@ -239,7 +249,7 @@ describe("SigningCosmWasmClient", () => {
it("always uses authAccount implementation", async () => {
pendingWithoutLaunchpad();
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const client = new SigningCosmWasmClient(launchpad.endpoint, alice.address0, wallet);
const openedClient = (client as unknown) as PrivateCosmWasmClient;
const blockLatestSpy = spyOn(openedClient.lcdClient, "blocksLatest").and.callThrough();
@ -257,7 +267,7 @@ describe("SigningCosmWasmClient", () => {
it("works", async () => {
pendingWithoutLaunchpad();
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const client = new SigningCosmWasmClient(launchpad.endpoint, alice.address0, wallet);
const wasm = getHackatom().data;
const {
codeId,
@ -276,7 +286,7 @@ describe("SigningCosmWasmClient", () => {
it("can set builder and source", async () => {
pendingWithoutLaunchpad();
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const client = new SigningCosmWasmClient(launchpad.endpoint, alice.address0, wallet);
const hackatom = getHackatom();
const meta: UploadMeta = {
@ -295,7 +305,7 @@ describe("SigningCosmWasmClient", () => {
it("works with transfer amount", async () => {
pendingWithoutLaunchpad();
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const client = new SigningCosmWasmClient(launchpad.endpoint, alice.address0, wallet);
const { codeId } = await client.upload(getHackatom().data);
const transferAmount = [coin(1234, "ucosm"), coin(321, "ustake")];
@ -313,7 +323,7 @@ describe("SigningCosmWasmClient", () => {
},
);
const lcdClient = makeWasmClient(httpUrl);
const lcdClient = makeWasmClient(launchpad.endpoint);
const balance = (await lcdClient.auth.account(contractAddress)).result.value.coins;
expect(balance).toEqual(transferAmount);
});
@ -321,7 +331,7 @@ describe("SigningCosmWasmClient", () => {
it("works with admin", async () => {
pendingWithoutLaunchpad();
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const client = new SigningCosmWasmClient(launchpad.endpoint, alice.address0, wallet);
const { codeId } = await client.upload(getHackatom().data);
const beneficiaryAddress = makeRandomAddress();
@ -335,7 +345,7 @@ describe("SigningCosmWasmClient", () => {
{ admin: unused.address },
);
const lcdClient = makeWasmClient(httpUrl);
const lcdClient = makeWasmClient(launchpad.endpoint);
const contract = await lcdClient.wasm.getContractInfo(contractAddress);
assert(contract);
expect(contract.admin).toEqual(unused.address);
@ -344,7 +354,7 @@ describe("SigningCosmWasmClient", () => {
it("can instantiate one code multiple times", async () => {
pendingWithoutLaunchpad();
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const client = new SigningCosmWasmClient(launchpad.endpoint, alice.address0, wallet);
const { codeId } = await client.upload(getHackatom().data);
const contractAddress1 = await client.instantiate(
@ -371,7 +381,7 @@ describe("SigningCosmWasmClient", () => {
it("can update an admin", async () => {
pendingWithoutLaunchpad();
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const client = new SigningCosmWasmClient(launchpad.endpoint, alice.address0, wallet);
const { codeId } = await client.upload(getHackatom().data);
const beneficiaryAddress = makeRandomAddress();
@ -387,7 +397,7 @@ describe("SigningCosmWasmClient", () => {
},
);
const lcdClient = makeWasmClient(httpUrl);
const lcdClient = makeWasmClient(launchpad.endpoint);
const state1 = await lcdClient.wasm.getContractInfo(contractAddress);
assert(state1);
expect(state1.admin).toEqual(alice.address0);
@ -404,7 +414,7 @@ describe("SigningCosmWasmClient", () => {
it("can clear an admin", async () => {
pendingWithoutLaunchpad();
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const client = new SigningCosmWasmClient(launchpad.endpoint, alice.address0, wallet);
const { codeId } = await client.upload(getHackatom().data);
const beneficiaryAddress = makeRandomAddress();
@ -420,7 +430,7 @@ describe("SigningCosmWasmClient", () => {
},
);
const lcdClient = makeWasmClient(httpUrl);
const lcdClient = makeWasmClient(launchpad.endpoint);
const state1 = await lcdClient.wasm.getContractInfo(contractAddress);
assert(state1);
expect(state1.admin).toEqual(alice.address0);
@ -437,7 +447,7 @@ describe("SigningCosmWasmClient", () => {
it("can can migrate from one code ID to another", async () => {
pendingWithoutLaunchpad();
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const client = new SigningCosmWasmClient(launchpad.endpoint, alice.address0, wallet);
const { codeId: codeId1 } = await client.upload(getHackatom().data);
const { codeId: codeId2 } = await client.upload(getHackatom().data);
@ -454,7 +464,7 @@ describe("SigningCosmWasmClient", () => {
},
);
const lcdClient = makeWasmClient(httpUrl);
const lcdClient = makeWasmClient(launchpad.endpoint);
const state1 = await lcdClient.wasm.getContractInfo(contractAddress);
assert(state1);
expect(state1.admin).toEqual(alice.address0);
@ -475,7 +485,7 @@ describe("SigningCosmWasmClient", () => {
it("works", async () => {
pendingWithoutLaunchpad();
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const client = new SigningCosmWasmClient(launchpad.endpoint, alice.address0, wallet);
const { codeId } = await client.upload(getHackatom().data);
// instantiate
@ -504,7 +514,7 @@ describe("SigningCosmWasmClient", () => {
});
// Verify token transfer from contract to beneficiary
const lcdClient = makeWasmClient(httpUrl);
const lcdClient = makeWasmClient(launchpad.endpoint);
const beneficiaryBalance = (await lcdClient.auth.account(beneficiaryAddress)).result.value.coins;
expect(beneficiaryBalance).toEqual(transferAmount);
const contractBalance = (await lcdClient.auth.account(contractAddress)).result.value.coins;
@ -516,7 +526,7 @@ describe("SigningCosmWasmClient", () => {
it("works", async () => {
pendingWithoutLaunchpad();
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const client = new SigningCosmWasmClient(launchpad.endpoint, alice.address0, wallet);
// instantiate
const transferAmount = coins(7890, "ucosm");
@ -543,7 +553,7 @@ describe("SigningCosmWasmClient", () => {
it("works", async () => {
pendingWithoutLaunchpad();
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
const client = new SigningCosmWasmClient(launchpad.endpoint, alice.address0, wallet);
const msg: MsgDelegate = {
type: "cosmos-sdk/MsgDelegate",

View File

@ -1,4 +1,5 @@
import { BroadcastMode, GasLimits, GasPrice, OfflineSigner } from "@cosmjs/launchpad";
import { Account } from "./cosmwasmclient";
import { CosmWasmFeeTable, ExecuteResult, SigningCosmWasmClient } from "./signingcosmwasmclient";
export declare type Expiration =
| {
@ -60,16 +61,17 @@ interface StartAfterStringPaginationOptions {
readonly limit?: number;
}
export declare class Cw3CosmWasmClient extends SigningCosmWasmClient {
private readonly cw3ContractAddress;
readonly cw3ContractAddress: string;
constructor(
apiUrl: string,
senderAddress: string,
signerAddress: string,
signer: OfflineSigner,
cw3ContractAddress: string,
gasPrice?: GasPrice,
gasLimits?: Partial<GasLimits<CosmWasmFeeTable>>,
broadcastMode?: BroadcastMode,
);
getAccount(address?: string): Promise<Account | undefined>;
getThreshold(): Promise<ThresholdResult>;
getProposal(proposalId: number): Promise<ProposalResult>;
listProposals({ startAfter, limit }?: StartAfterNumberPaginationOptions): Promise<ProposalsResult>;