cosmwasm-stargate: Update after manual codec fixes

This commit is contained in:
willclarktech 2021-01-28 14:00:21 +00:00
parent f4bb1ee6f4
commit 8c4f902341
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7
5 changed files with 88 additions and 62 deletions

View File

@ -1,11 +1,11 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {
MsgClearAdmin,
MsgExecuteContract,
MsgInstantiateContract,
MsgMigrateContract,
MsgStoreCode,
MsgUpdateAdmin,
MsgClearAdmin as LaunchpadMsgClearAdmin,
MsgExecuteContract as LaunchpadMsgExecuteContract,
MsgInstantiateContract as LaunchpadMsgInstantiateContract,
MsgMigrateContract as LaunchpadMsgMigrateContract,
MsgStoreCode as LaunchpadMsgStoreCode,
MsgUpdateAdmin as LaunchpadMsgUpdateAdmin,
} from "@cosmjs/cosmwasm-launchpad";
import { fromBase64, toUtf8 } from "@cosmjs/encoding";
import { coins } from "@cosmjs/launchpad";
@ -13,19 +13,19 @@ import { AminoTypes } from "@cosmjs/stargate";
import Long from "long";
import { cosmWasmTypes } from "./aminotypes";
import { cosmwasm } from "./codec";
type IMsgStoreCode = cosmwasm.wasm.v1beta1.IMsgStoreCode;
type IMsgInstantiateContract = cosmwasm.wasm.v1beta1.IMsgInstantiateContract;
type IMsgUpdateAdmin = cosmwasm.wasm.v1beta1.IMsgUpdateAdmin;
type IMsgClearAdmin = cosmwasm.wasm.v1beta1.IMsgClearAdmin;
type IMsgExecuteContract = cosmwasm.wasm.v1beta1.IMsgExecuteContract;
type IMsgMigrateContract = cosmwasm.wasm.v1beta1.IMsgMigrateContract;
import {
MsgClearAdmin,
MsgExecuteContract,
MsgInstantiateContract,
MsgMigrateContract,
MsgStoreCode,
MsgUpdateAdmin,
} from "./codec/x/wasm/internal/types/tx";
describe("AminoTypes", () => {
describe("toAmino", () => {
it("works for MsgStoreCode", () => {
const msg: IMsgStoreCode = {
const msg: MsgStoreCode = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="),
source: "Arrabiata",
@ -35,7 +35,7 @@ describe("AminoTypes", () => {
typeUrl: "/cosmwasm.wasm.v1beta1.MsgStoreCode",
value: msg,
});
const expected: MsgStoreCode = {
const expected: LaunchpadMsgStoreCode = {
type: "wasm/MsgStoreCode",
value: {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
@ -48,7 +48,7 @@ describe("AminoTypes", () => {
});
it("works for MsgInstantiateContract", () => {
const msg: IMsgInstantiateContract = {
const msg: MsgInstantiateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
codeId: Long.fromString("12345"),
label: "sticky",
@ -64,7 +64,7 @@ describe("AminoTypes", () => {
typeUrl: "/cosmwasm.wasm.v1beta1.MsgInstantiateContract",
value: msg,
});
const expected: MsgInstantiateContract = {
const expected: LaunchpadMsgInstantiateContract = {
type: "wasm/MsgInstantiateContract",
value: {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
@ -81,7 +81,7 @@ describe("AminoTypes", () => {
});
it("works for MsgUpdateAdmin", () => {
const msg: IMsgUpdateAdmin = {
const msg: MsgUpdateAdmin = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
newAdmin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
@ -90,7 +90,7 @@ describe("AminoTypes", () => {
typeUrl: "/cosmwasm.wasm.v1beta1.MsgUpdateAdmin",
value: msg,
});
const expected: MsgUpdateAdmin = {
const expected: LaunchpadMsgUpdateAdmin = {
type: "wasm/MsgUpdateAdmin",
value: {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
@ -102,7 +102,7 @@ describe("AminoTypes", () => {
});
it("works for MsgClearAdmin", () => {
const msg: IMsgClearAdmin = {
const msg: MsgClearAdmin = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
};
@ -110,7 +110,7 @@ describe("AminoTypes", () => {
typeUrl: "/cosmwasm.wasm.v1beta1.MsgClearAdmin",
value: msg,
});
const expected: MsgClearAdmin = {
const expected: LaunchpadMsgClearAdmin = {
type: "wasm/MsgClearAdmin",
value: {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
@ -121,7 +121,7 @@ describe("AminoTypes", () => {
});
it("works for MsgExecuteContract", () => {
const msg: IMsgExecuteContract = {
const msg: MsgExecuteContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
msg: toUtf8(
@ -135,7 +135,7 @@ describe("AminoTypes", () => {
typeUrl: "/cosmwasm.wasm.v1beta1.MsgExecuteContract",
value: msg,
});
const expected: MsgExecuteContract = {
const expected: LaunchpadMsgExecuteContract = {
type: "wasm/MsgExecuteContract",
value: {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
@ -150,7 +150,7 @@ describe("AminoTypes", () => {
});
it("works for MsgMigrateContract", () => {
const msg: IMsgMigrateContract = {
const msg: MsgMigrateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
codeId: Long.fromString("98765"),
@ -164,7 +164,7 @@ describe("AminoTypes", () => {
typeUrl: "/cosmwasm.wasm.v1beta1.MsgMigrateContract",
value: msg,
});
const expected: MsgMigrateContract = {
const expected: LaunchpadMsgMigrateContract = {
type: "wasm/MsgMigrateContract",
value: {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
@ -181,7 +181,7 @@ describe("AminoTypes", () => {
describe("fromAmino", () => {
it("works for MsgStoreCode", () => {
const aminoMsg: MsgStoreCode = {
const aminoMsg: LaunchpadMsgStoreCode = {
type: "wasm/MsgStoreCode",
value: {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
@ -191,7 +191,7 @@ describe("AminoTypes", () => {
},
};
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
const expectedValue: IMsgStoreCode = {
const expectedValue: MsgStoreCode = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="),
source: "Arrabiata",
@ -204,7 +204,7 @@ describe("AminoTypes", () => {
});
it("works for MsgInstantiateContract", () => {
const aminoMsg: MsgInstantiateContract = {
const aminoMsg: LaunchpadMsgInstantiateContract = {
type: "wasm/MsgInstantiateContract",
value: {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
@ -218,7 +218,7 @@ describe("AminoTypes", () => {
},
};
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
const expectedValue: IMsgInstantiateContract = {
const expectedValue: MsgInstantiateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
codeId: Long.fromString("12345"),
label: "sticky",
@ -237,7 +237,7 @@ describe("AminoTypes", () => {
});
it("works for MsgUpdateAdmin", () => {
const aminoMsg: MsgUpdateAdmin = {
const aminoMsg: LaunchpadMsgUpdateAdmin = {
type: "wasm/MsgUpdateAdmin",
value: {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
@ -246,7 +246,7 @@ describe("AminoTypes", () => {
},
};
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
const expectedValue: IMsgUpdateAdmin = {
const expectedValue: MsgUpdateAdmin = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
newAdmin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
@ -258,7 +258,7 @@ describe("AminoTypes", () => {
});
it("works for MsgClearAdmin", () => {
const aminoMsg: MsgClearAdmin = {
const aminoMsg: LaunchpadMsgClearAdmin = {
type: "wasm/MsgClearAdmin",
value: {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
@ -266,7 +266,7 @@ describe("AminoTypes", () => {
},
};
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
const expectedValue: IMsgClearAdmin = {
const expectedValue: MsgClearAdmin = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
};
@ -277,7 +277,7 @@ describe("AminoTypes", () => {
});
it("works for MsgExecuteContract", () => {
const aminoMsg: MsgExecuteContract = {
const aminoMsg: LaunchpadMsgExecuteContract = {
type: "wasm/MsgExecuteContract",
value: {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
@ -289,7 +289,7 @@ describe("AminoTypes", () => {
},
};
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
const expectedValue: IMsgExecuteContract = {
const expectedValue: MsgExecuteContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
msg: toUtf8(
@ -306,7 +306,7 @@ describe("AminoTypes", () => {
});
it("works for MsgMigrateContract", () => {
const aminoMsg: MsgMigrateContract = {
const aminoMsg: LaunchpadMsgMigrateContract = {
type: "wasm/MsgMigrateContract",
value: {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
@ -318,7 +318,7 @@ describe("AminoTypes", () => {
},
};
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
const expectedValue: IMsgMigrateContract = {
const expectedValue: MsgMigrateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
codeId: Long.fromString("98765"),

View File

@ -196,6 +196,7 @@ describe("WasmExtension", () => {
assert(existingContractInfos);
for (const { address, contractInfo } of existingContractInfos) {
expect(address).toMatch(bech32AddressMatcher);
assertDefined(contractInfo);
expect(contractInfo.codeId!.toNumber()).toEqual(hackatomCodeId);
expect(contractInfo.creator).toMatch(bech32AddressMatcher);
expect(contractInfo.label).toMatch(/^.+$/);
@ -225,6 +226,7 @@ describe("WasmExtension", () => {
codeId: Long.fromNumber(hackatomCodeId, true),
creator: alice.address0,
label: "my escrow",
admin: "",
});
expect(contractInfo.admin).toEqual("");
});

View File

@ -73,7 +73,14 @@ export function setupWasmExtension(base: QueryClient): WasmExtension {
unverified: {
wasm: {
listCodeInfo: async (paginationKey?: Uint8Array) => {
const request = paginationKey ? { pagination: { key: paginationKey } } : {};
const request = {
pagination: {
key: paginationKey ?? new Uint8Array(),
offset: Long.fromNumber(0),
limit: Long.fromNumber(0),
countTotal: false,
},
};
return queryService.Codes(request);
},
getCode: async (id: number) => {
@ -81,7 +88,14 @@ export function setupWasmExtension(base: QueryClient): WasmExtension {
return queryService.Code(request);
},
listContractsByCodeId: async (id: number, paginationKey?: Uint8Array) => {
const pagination = paginationKey ? { pagination: { key: paginationKey } } : {};
const pagination = {
pagination: {
key: paginationKey ?? new Uint8Array(),
offset: Long.fromNumber(0),
limit: Long.fromNumber(0),
countTotal: false,
},
};
const request = { ...pagination, codeId: Long.fromNumber(id) };
return queryService.ContractsByCode(request);
},
@ -91,13 +105,27 @@ export function setupWasmExtension(base: QueryClient): WasmExtension {
},
getContractCodeHistory: async (address: string, paginationKey?: Uint8Array) => {
const pagination = paginationKey ? { pagination: { key: paginationKey } } : {};
const pagination = {
pagination: {
key: paginationKey ?? new Uint8Array(),
offset: Long.fromNumber(0),
limit: Long.fromNumber(0),
countTotal: false,
},
};
const request = { ...pagination, address: address };
return queryService.ContractHistory(request);
},
getAllContractState: async (address: string, paginationKey?: Uint8Array) => {
const pagination = paginationKey ? { pagination: { key: paginationKey } } : {};
const pagination = {
pagination: {
key: paginationKey ?? new Uint8Array(),
offset: Long.fromNumber(0),
limit: Long.fromNumber(0),
countTotal: false,
},
};
const request = { ...pagination, address: address };
return queryService.AllContractState(request);
},

View File

@ -1,4 +1,3 @@
export * as codec from "./codec";
export { cosmWasmTypes } from "./aminotypes";
export { CosmWasmClient } from "./cosmwasmclient";
export { SigningCosmWasmClient, SigningCosmWasmClientOptions } from "./signingcosmwasmclient";

View File

@ -1,38 +1,39 @@
import { JsonObject } from "@cosmjs/cosmwasm-launchpad";
import { QueryClient } from "@cosmjs/stargate";
import { cosmwasm } from "../codec";
declare type IQueryAllContractStateResponse = cosmwasm.wasm.v1beta1.IQueryAllContractStateResponse;
declare type IQueryCodesResponse = cosmwasm.wasm.v1beta1.IQueryCodesResponse;
declare type IQueryCodeResponse = cosmwasm.wasm.v1beta1.IQueryCodeResponse;
declare type IQueryContractHistoryResponse = cosmwasm.wasm.v1beta1.IQueryContractHistoryResponse;
declare type IQueryContractInfoResponse = cosmwasm.wasm.v1beta1.IQueryContractInfoResponse;
declare type IQueryContractsByCodeResponse = cosmwasm.wasm.v1beta1.IQueryContractsByCodeResponse;
declare type IQueryRawContractStateResponse = cosmwasm.wasm.v1beta1.IQueryRawContractStateResponse;
import {
QueryAllContractStateResponse,
QueryCodeResponse,
QueryCodesResponse,
QueryContractHistoryResponse,
QueryContractInfoResponse,
QueryContractsByCodeResponse,
QueryRawContractStateResponse,
} from "../codec/x/wasm/internal/types/query";
export interface WasmExtension {
readonly unverified: {
readonly wasm: {
readonly listCodeInfo: (paginationKey?: Uint8Array) => Promise<IQueryCodesResponse>;
readonly listCodeInfo: (paginationKey?: Uint8Array) => Promise<QueryCodesResponse>;
/**
* Downloads the original wasm bytecode by code ID.
*
* Throws an error if no code with this id
*/
readonly getCode: (id: number) => Promise<IQueryCodeResponse>;
readonly getCode: (id: number) => Promise<QueryCodeResponse>;
readonly listContractsByCodeId: (
id: number,
paginationKey?: Uint8Array,
) => Promise<IQueryContractsByCodeResponse>;
) => Promise<QueryContractsByCodeResponse>;
/**
* Returns null when contract was not found at this address.
*/
readonly getContractInfo: (address: string) => Promise<IQueryContractInfoResponse>;
readonly getContractInfo: (address: string) => Promise<QueryContractInfoResponse>;
/**
* Returns null when contract history was not found for this address.
*/
readonly getContractCodeHistory: (
address: string,
paginationKey?: Uint8Array,
) => Promise<IQueryContractHistoryResponse>;
) => Promise<QueryContractHistoryResponse>;
/**
* Returns all contract state.
* This is an empty array if no such contract, or contract has no data.
@ -40,15 +41,12 @@ export interface WasmExtension {
readonly getAllContractState: (
address: string,
paginationKey?: Uint8Array,
) => Promise<IQueryAllContractStateResponse>;
) => Promise<QueryAllContractStateResponse>;
/**
* Returns the data at the key if present (unknown decoded json),
* or null if no data at this (contract address, key) pair
*/
readonly queryContractRaw: (
address: string,
key: Uint8Array,
) => Promise<IQueryRawContractStateResponse>;
readonly queryContractRaw: (address: string, key: Uint8Array) => Promise<QueryRawContractStateResponse>;
/**
* Makes a smart query on the contract and parses the response as JSON.
* Throws error if no such contract exists, the query format is invalid or the response is invalid.
@ -58,4 +56,3 @@ export interface WasmExtension {
};
}
export declare function setupWasmExtension(base: QueryClient): WasmExtension;
export {};