mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-11 14:09:15 +00:00
Fix message encoding in AminoMsgMigrateContract
This commit is contained in:
parent
fa9004b5ea
commit
3593b405c9
@ -181,9 +181,7 @@ describe("AminoTypes", () => {
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
code_id: "98765",
|
||||
msg: {
|
||||
foo: "bar",
|
||||
},
|
||||
msg: toBase64(toUtf8(`{"foo":"bar"}`)),
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
@ -338,9 +336,7 @@ describe("AminoTypes", () => {
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
code_id: "98765",
|
||||
msg: {
|
||||
foo: "bar",
|
||||
},
|
||||
msg: toBase64(toUtf8(`{"foo":"bar"}`)),
|
||||
},
|
||||
};
|
||||
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
|
||||
@ -348,11 +344,7 @@ describe("AminoTypes", () => {
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
|
||||
codeId: Long.fromString("98765"),
|
||||
msg: toUtf8(
|
||||
JSON.stringify({
|
||||
foo: "bar",
|
||||
}),
|
||||
),
|
||||
msg: toUtf8(`{"foo":"bar"}`),
|
||||
};
|
||||
expect(msg).toEqual({
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgMigrateContract",
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { fromBase64, fromUtf8, toBase64, toUtf8 } from "@cosmjs/encoding";
|
||||
import { fromBase64, toBase64 } from "@cosmjs/encoding";
|
||||
import { AminoConverter, Coin } from "@cosmjs/stargate";
|
||||
import {
|
||||
MsgClearAdmin,
|
||||
@ -87,8 +87,8 @@ export interface AminoMsgMigrateContract {
|
||||
readonly contract: string;
|
||||
/** The new code */
|
||||
readonly code_id: string;
|
||||
/** Migrate message as JavaScript object */
|
||||
readonly msg: any;
|
||||
/** Migrate message as base64 encoded JSON */
|
||||
readonly msg: string;
|
||||
};
|
||||
}
|
||||
|
||||
@ -215,7 +215,7 @@ export const cosmWasmTypes: Record<string, AminoConverter> = {
|
||||
sender: sender,
|
||||
contract: contract,
|
||||
code_id: codeId.toString(),
|
||||
msg: JSON.parse(fromUtf8(msg)),
|
||||
msg: toBase64(msg),
|
||||
}),
|
||||
fromAmino: ({
|
||||
sender,
|
||||
@ -226,7 +226,7 @@ export const cosmWasmTypes: Record<string, AminoConverter> = {
|
||||
sender: sender,
|
||||
contract: contract,
|
||||
codeId: Long.fromString(code_id),
|
||||
msg: toUtf8(JSON.stringify(msg)),
|
||||
msg: fromBase64(msg),
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
@ -282,7 +282,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
});
|
||||
|
||||
describe("migrate", () => {
|
||||
it("can can migrate from one code ID to another", async () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
|
||||
const options = { ...defaultSigningClientOptions, prefix: wasmd.prefix };
|
||||
@ -325,6 +325,48 @@ describe("SigningCosmWasmClient", () => {
|
||||
|
||||
client.disconnect();
|
||||
});
|
||||
|
||||
it("works with legacy Amino signer", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
|
||||
const options = { ...defaultSigningClientOptions, prefix: wasmd.prefix };
|
||||
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, options);
|
||||
const { codeId: codeId1 } = await client.upload(alice.address0, getHackatom().data, defaultUploadFee);
|
||||
const { codeId: codeId2 } = await client.upload(alice.address0, getHackatom().data, defaultUploadFee);
|
||||
const beneficiaryAddress = makeRandomAddress();
|
||||
const { contractAddress } = await client.instantiate(
|
||||
alice.address0,
|
||||
codeId1,
|
||||
{
|
||||
verifier: alice.address0,
|
||||
beneficiary: beneficiaryAddress,
|
||||
},
|
||||
"My cool label",
|
||||
defaultInstantiateFee,
|
||||
{ admin: alice.address0 },
|
||||
);
|
||||
const wasmClient = await makeWasmClient(wasmd.endpoint);
|
||||
const { contractInfo: contractInfo1 } = await wasmClient.wasm.getContractInfo(contractAddress);
|
||||
assert(contractInfo1);
|
||||
expect(contractInfo1.admin).toEqual(alice.address0);
|
||||
|
||||
const newVerifier = makeRandomAddress();
|
||||
await client.migrate(
|
||||
alice.address0,
|
||||
contractAddress,
|
||||
codeId2,
|
||||
{ verifier: newVerifier },
|
||||
defaultMigrateFee,
|
||||
);
|
||||
const { contractInfo: contractInfo2 } = await wasmClient.wasm.getContractInfo(contractAddress);
|
||||
assert(contractInfo2);
|
||||
expect({ ...contractInfo2 }).toEqual({
|
||||
...contractInfo1,
|
||||
codeId: Long.fromNumber(codeId2, true),
|
||||
});
|
||||
|
||||
client.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("execute", () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user