Fix fix_msg in AminoMsgInstantiateContract2
This commit is contained in:
parent
3dbc8bca9c
commit
cf1fd0bf2d
@ -20,8 +20,12 @@ and this project adheres to
|
||||
|
||||
- @cosmjs/stargate: Handle key value pairs in tx search correctly if the value
|
||||
is a numeric value. ([#1462])
|
||||
- @cosmjs/cosmwasm-stargate: Make `fix_msg` optional in
|
||||
`AminoMsgInstantiateContract2` and omit default in the Amino JSON converter to
|
||||
fix Amino JSON signing for MsgInstantiateContract2. ([#1509])
|
||||
|
||||
[#1462]: https://github.com/cosmos/cosmjs/issues/1462
|
||||
[#1509]: https://github.com/cosmos/cosmjs/pull/1509
|
||||
|
||||
### Changed
|
||||
|
||||
|
||||
@ -159,7 +159,7 @@ describe("AminoTypes", () => {
|
||||
funds: coins(1234, "ucosm"),
|
||||
admin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
salt: toBase64(toUtf8("salt")),
|
||||
fix_msg: false,
|
||||
fix_msg: undefined,
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
@ -191,7 +191,39 @@ describe("AminoTypes", () => {
|
||||
funds: coins(1234, "ucosm"),
|
||||
admin: undefined,
|
||||
salt: toBase64(toUtf8("salt")),
|
||||
fix_msg: false,
|
||||
fix_msg: undefined,
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
}
|
||||
|
||||
// With fixMsg=true (typically not needed)
|
||||
{
|
||||
const msg: MsgInstantiateContract2 = {
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
codeId: BigInt("12345"),
|
||||
label: "sticky",
|
||||
msg: toUtf8(`{"foo":"bar"}`),
|
||||
funds: coins(1234, "ucosm"),
|
||||
admin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
salt: toUtf8("salt"),
|
||||
fixMsg: true,
|
||||
};
|
||||
const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({
|
||||
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract2",
|
||||
value: msg,
|
||||
});
|
||||
const expected: AminoMsgInstantiateContract2 = {
|
||||
type: "wasm/MsgInstantiateContract2",
|
||||
value: {
|
||||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
code_id: "12345",
|
||||
label: "sticky",
|
||||
msg: { foo: "bar" },
|
||||
funds: coins(1234, "ucosm"),
|
||||
admin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
salt: toBase64(toUtf8("salt")),
|
||||
fix_msg: true,
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { omitDefault } from "@cosmjs/amino";
|
||||
import { fromBase64, fromUtf8, toBase64, toUtf8 } from "@cosmjs/encoding";
|
||||
import { AminoConverters, Coin } from "@cosmjs/stargate";
|
||||
import {
|
||||
@ -141,8 +142,11 @@ export interface AminoMsgInstantiateContract2 {
|
||||
readonly admin?: string;
|
||||
/** Arbitrary Base64-encoded value provided by the sender */
|
||||
readonly salt: string;
|
||||
/** Whether or not to include the msg value into the hash for the address */
|
||||
readonly fix_msg: boolean;
|
||||
/**
|
||||
* Whether or not to include the msg value into the hash for the address.
|
||||
* Unset means false. This should always be unset/false (https://medium.com/cosmwasm/dev-note-3-limitations-of-instantiate2-and-how-to-deal-with-them-a3f946874230).
|
||||
*/
|
||||
readonly fix_msg?: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
@ -248,7 +252,7 @@ export function createWasmAminoConverters(): AminoConverters {
|
||||
label: label,
|
||||
msg: JSON.parse(fromUtf8(msg)),
|
||||
funds: funds,
|
||||
admin: admin || undefined,
|
||||
admin: omitDefault(admin),
|
||||
}),
|
||||
fromAmino: ({
|
||||
sender,
|
||||
@ -283,9 +287,9 @@ export function createWasmAminoConverters(): AminoConverters {
|
||||
label: label,
|
||||
msg: JSON.parse(fromUtf8(msg)),
|
||||
funds: funds,
|
||||
admin: admin || undefined,
|
||||
admin: omitDefault(admin),
|
||||
salt: toBase64(salt),
|
||||
fix_msg: fixMsg,
|
||||
fix_msg: omitDefault(fixMsg),
|
||||
}),
|
||||
fromAmino: ({
|
||||
sender,
|
||||
@ -304,7 +308,7 @@ export function createWasmAminoConverters(): AminoConverters {
|
||||
funds: [...funds],
|
||||
admin: admin ?? "",
|
||||
salt: fromBase64(salt),
|
||||
fixMsg: fix_msg,
|
||||
fixMsg: fix_msg ?? false,
|
||||
}),
|
||||
},
|
||||
"/cosmwasm.wasm.v1.MsgUpdateAdmin": {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user