diff --git a/packages/cosmwasm-stargate/src/aminotypes.spec.ts b/packages/cosmwasm-stargate/src/aminotypes.spec.ts index 19a9aafd..ded26a7b 100644 --- a/packages/cosmwasm-stargate/src/aminotypes.spec.ts +++ b/packages/cosmwasm-stargate/src/aminotypes.spec.ts @@ -30,6 +30,7 @@ describe("AminoTypes", () => { wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="), source: "Arrabiata", builder: "Bob", + instantiatePermission: undefined, }; const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({ typeUrl: "/cosmwasm.wasm.v1beta1.MsgStoreCode", @@ -196,6 +197,7 @@ describe("AminoTypes", () => { wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="), source: "Arrabiata", builder: "Bob", + instantiatePermission: undefined, }; expect(msg).toEqual({ typeUrl: "/cosmwasm.wasm.v1beta1.MsgStoreCode", diff --git a/packages/cosmwasm-stargate/src/aminotypes.ts b/packages/cosmwasm-stargate/src/aminotypes.ts index 993396f6..326dffbf 100644 --- a/packages/cosmwasm-stargate/src/aminotypes.ts +++ b/packages/cosmwasm-stargate/src/aminotypes.ts @@ -46,6 +46,7 @@ export const cosmWasmTypes: Record = { wasmByteCode: fromBase64(wasm_byte_code), source: source, builder: builder, + instantiatePermission: undefined, }), }, "/cosmwasm.wasm.v1beta1.MsgInstantiateContract": { diff --git a/packages/cosmwasm-stargate/src/cosmwasmclient.spec.ts b/packages/cosmwasm-stargate/src/cosmwasmclient.spec.ts index 409fc096..25104ebb 100644 --- a/packages/cosmwasm-stargate/src/cosmwasmclient.spec.ts +++ b/packages/cosmwasm-stargate/src/cosmwasmclient.spec.ts @@ -369,8 +369,7 @@ describe("CosmWasmClient", () => { const client = await CosmWasmClient.connect(wasmd.endpoint); const raw = await client.queryContractRaw(contract.address, otherKey); - assert(raw, "must get result"); - expect(Uint8Array.from(raw)).toEqual(new Uint8Array()); + expect(raw).toBeNull(); }); it("errors for non-existent contract", async () => { diff --git a/packages/cosmwasm-stargate/src/queries/wasm.spec.ts b/packages/cosmwasm-stargate/src/queries/wasm.spec.ts index 40a72b1c..407b5926 100644 --- a/packages/cosmwasm-stargate/src/queries/wasm.spec.ts +++ b/packages/cosmwasm-stargate/src/queries/wasm.spec.ts @@ -197,7 +197,7 @@ describe("WasmExtension", () => { for (const { address, contractInfo } of existingContractInfos) { expect(address).toMatch(bech32AddressMatcher); assertDefined(contractInfo); - expect(contractInfo.codeId!.toNumber()).toEqual(hackatomCodeId); + expect(contractInfo.codeId.toNumber()).toEqual(hackatomCodeId); expect(contractInfo.creator).toMatch(bech32AddressMatcher); expect(contractInfo.label).toMatch(/^.+$/); } @@ -218,6 +218,7 @@ describe("WasmExtension", () => { codeId: Long.fromNumber(hackatomCodeId, true), creator: alice.address0, label: "my escrow", + admin: "", }); const { contractInfo } = await client.unverified.wasm.getContractInfo(myAddress); @@ -295,7 +296,7 @@ describe("WasmExtension", () => { expect(models.length).toEqual(1); const data = models[0]; expect(data.key).toEqual(hackatomConfigKey); - const value = JSON.parse(fromAscii(data.value!)); + const value = JSON.parse(fromAscii(data.value)); expect(value.verifier).toMatch(base64Matcher); expect(value.beneficiary).toMatch(base64Matcher); }); @@ -322,15 +323,15 @@ describe("WasmExtension", () => { expect(model.beneficiary).toMatch(base64Matcher); }); - it("returns empty object for missing key", async () => { + it("returns undefined for missing key", async () => { pendingWithoutWasmd(); assert(hackatomContractAddress); const client = await makeWasmClient(wasmd.endpoint); - const response = await client.unverified.wasm.queryContractRaw( + const { data } = await client.unverified.wasm.queryContractRaw( hackatomContractAddress, fromHex("cafe0dad"), ); - expect({ ...response }).toEqual({ data: new Uint8Array() }); + expect(data).toBeUndefined(); }); it("returns null for non-existent address", async () => { @@ -398,7 +399,7 @@ describe("WasmExtension", () => { assertDefined(result.data); const msgData = fromOneElementArray(result.data); expect(msgData.msgType).toEqual("store-code"); - expect(MsgStoreCodeResponse.decode(msgData.data!)).toEqual( + expect(MsgStoreCodeResponse.decode(msgData.data)).toEqual( MsgStoreCodeResponse.fromPartial({ codeId: Long.fromNumber(codeId, true) }), ); } @@ -418,7 +419,7 @@ describe("WasmExtension", () => { assertDefined(result.data); const msgData = fromOneElementArray(result.data); expect(msgData.msgType).toEqual("instantiate"); - expect(MsgInstantiateContractResponse.decode(msgData.data!)).toEqual( + expect(MsgInstantiateContractResponse.decode(msgData.data)).toEqual( MsgInstantiateContractResponse.fromPartial({ address: contractAddress }), ); @@ -444,7 +445,7 @@ describe("WasmExtension", () => { assertDefined(result.data); const msgData = fromOneElementArray(result.data); expect(msgData.msgType).toEqual("execute"); - expect(MsgExecuteContractResponse.decode(msgData.data!)).toEqual( + expect(MsgExecuteContractResponse.decode(msgData.data)).toEqual( MsgExecuteContractResponse.fromPartial({ data: fromHex("F00BAA") }), ); diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts index 978addcd..baf2788e 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts @@ -11,14 +11,14 @@ import { } from "@cosmjs/launchpad"; import { DirectSecp256k1HdWallet, Registry } from "@cosmjs/proto-signing"; import { AminoTypes, assertIsBroadcastTxSuccess } from "@cosmjs/stargate"; -import { MsgSend } from "@cosmjs/stargate/build/codec/cosmos/bank/v1beta1/tx"; +import { DeepPartial, MsgSend } from "@cosmjs/stargate/build/codec/cosmos/bank/v1beta1/tx"; import { Coin } from "@cosmjs/stargate/build/codec/cosmos/base/v1beta1/coin"; import { MsgDelegate } from "@cosmjs/stargate/build/codec/cosmos/staking/v1beta1/tx"; import { Tx } from "@cosmjs/stargate/build/codec/cosmos/tx/v1beta1/tx"; import { assert, sleep } from "@cosmjs/utils"; import Long from "long"; import pako from "pako"; -import { Message } from "protobufjs"; +import protobuf from "protobufjs/minimal"; import { MsgStoreCode } from "./codec/x/wasm/internal/types/tx"; import { PrivateSigningCosmWasmClient, SigningCosmWasmClient } from "./signingcosmwasmclient"; @@ -572,18 +572,6 @@ describe("SigningCosmWasmClient", () => { }); describe("legacy Amino mode", () => { - // NOTE: One custom registry shared between tests - // See https://github.com/protobufjs/protobuf.js#using-decorators - // > Decorated types reside in protobuf.roots["decorated"] using a flat structure, so no duplicate names. - const customRegistry = new Registry(); - const msgDelegateTypeUrl = "/cosmos.staking.v1beta1.MsgDelegate"; - - interface CustomMsgDelegate { - readonly customDelegatorAddress?: string; - readonly customValidatorAddress?: string; - readonly customAmount?: Coin; - } - it("works with bank MsgSend", async () => { pendingWithoutWasmd(); const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, wasmd.prefix); @@ -644,6 +632,7 @@ describe("SigningCosmWasmClient", () => { wasmByteCode: pako.gzip(data), source: source ?? "", builder: builder ?? "", + instantiatePermission: undefined, }; const msgAny = { typeUrl: "/cosmwasm.wasm.v1beta1.MsgStoreCode", @@ -661,8 +650,66 @@ describe("SigningCosmWasmClient", () => { it("works with a custom registry and custom message", async () => { pendingWithoutWasmd(); const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, undefined, wasmd.prefix); + + const customRegistry = new Registry(); + const msgDelegateTypeUrl = "/cosmos.staking.v1beta1.MsgDelegate"; + interface CustomMsgDelegate { + customDelegatorAddress?: string; + customValidatorAddress?: string; + customAmount?: Coin; + } + const baseCustomMsgDelegate: CustomMsgDelegate = { + customDelegatorAddress: "", + customValidatorAddress: "", + }; + const CustomMsgDelegate = { + // Adapted from autogenerated MsgDelegate implementation + encode( + message: CustomMsgDelegate, + writer: protobuf.Writer = protobuf.Writer.create(), + ): protobuf.Writer { + writer.uint32(10).string(message.customDelegatorAddress ?? ""); + writer.uint32(18).string(message.customValidatorAddress ?? ""); + if (message.customAmount !== undefined && message.customAmount !== undefined) { + Coin.encode(message.customAmount, writer.uint32(26).fork()).ldelim(); + } + return writer; + }, + + decode(): CustomMsgDelegate { + throw new Error("decode method should not be required"); + }, + + fromJSON(): CustomMsgDelegate { + throw new Error("fromJSON method should not be required"); + }, + + fromPartial(object: DeepPartial): CustomMsgDelegate { + const message = { ...baseCustomMsgDelegate } as CustomMsgDelegate; + if (object.customDelegatorAddress !== undefined && object.customDelegatorAddress !== null) { + message.customDelegatorAddress = object.customDelegatorAddress; + } else { + message.customDelegatorAddress = ""; + } + if (object.customValidatorAddress !== undefined && object.customValidatorAddress !== null) { + message.customValidatorAddress = object.customValidatorAddress; + } else { + message.customValidatorAddress = ""; + } + if (object.customAmount !== undefined && object.customAmount !== null) { + message.customAmount = Coin.fromPartial(object.customAmount); + } else { + message.customAmount = undefined; + } + return message; + }, + + toJSON(): unknown { + throw new Error("toJSON method should not be required"); + }, + }; + customRegistry.register(msgDelegateTypeUrl, CustomMsgDelegate); const customAminoTypes = new AminoTypes({ - prefix: wasmd.prefix, additions: { "/cosmos.staking.v1beta1.MsgDelegate": { aminoType: "cosmos-sdk/MsgDelegate", @@ -672,7 +719,7 @@ describe("SigningCosmWasmClient", () => { customAmount, }: CustomMsgDelegate): LaunchpadMsgDelegate["value"] => { assert(customDelegatorAddress, "missing customDelegatorAddress"); - assert(customValidatorAddress, "missing validator_address"); + assert(customValidatorAddress, "missing validatorAddress"); assert(customAmount, "missing amount"); assert(customAmount.amount, "missing amount.amount"); assert(customAmount.denom, "missing amount.denom"); @@ -730,7 +777,7 @@ describe("SigningCosmWasmClient", () => { amount: coin(1234, "ustake"), }; const msgAny = { - typeUrl: msgDelegateTypeUrl, + typeUrl: "/cosmos.staking.v1beta1.MsgDelegate", value: msg, }; const fee = { @@ -748,8 +795,8 @@ describe("SigningCosmWasmClient", () => { const tx = Tx.decode(searchResult.tx); // From ModifyingSecp256k1HdWallet expect(tx.body!.memo).toEqual("This was modified"); - expect({ ...tx.authInfo!.fee!.amount![0] }).toEqual(coin(3000, "ucosm")); - expect(tx.authInfo!.fee!.gasLimit!.toNumber()).toEqual(333333); + expect({ ...tx.authInfo!.fee!.amount[0] }).toEqual(coin(3000, "ucosm")); + expect(tx.authInfo!.fee!.gasLimit.toNumber()).toEqual(333333); }); }); });