Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make prefix required in AminoTypes constructor #1014

Merged
merged 1 commit into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ and this project adheres to

## [Unreleased]

### Changed

- @cosmjs/stargate: The `AminoTypes` now always requires an argument of type
`AminoTypesOptions`. This is an object with a required `prefix` field. Before
the prefix defaulted to "cosmos" but this is almost never the right choice for
CosmJS users that need to add Amino types manually. ([#989])

[#989]: https://github.com/cosmos/cosmjs/issues/989

### Removed

- @cosmjs/crypto: Remove the SHA1 implementation (`Sha1` and `sha1`) as it is
Expand Down
28 changes: 14 additions & 14 deletions packages/cosmwasm-stargate/src/aminotypes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("AminoTypes", () => {
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="),
instantiatePermission: undefined,
};
const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode",
value: msg,
});
Expand All @@ -54,7 +54,7 @@ describe("AminoTypes", () => {
funds: coins(1234, "ucosm"),
admin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
};
const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
value: msg,
});
Expand Down Expand Up @@ -82,7 +82,7 @@ describe("AminoTypes", () => {
funds: coins(1234, "ucosm"),
admin: "",
};
const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
value: msg,
});
Expand All @@ -107,7 +107,7 @@ describe("AminoTypes", () => {
newAdmin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
};
const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
typeUrl: "/cosmwasm.wasm.v1.MsgUpdateAdmin",
value: msg,
});
Expand All @@ -127,7 +127,7 @@ describe("AminoTypes", () => {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
};
const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
typeUrl: "/cosmwasm.wasm.v1.MsgClearAdmin",
value: msg,
});
Expand All @@ -148,7 +148,7 @@ describe("AminoTypes", () => {
msg: toUtf8(`{"foo":"bar"}`),
funds: coins(1234, "ucosm"),
};
const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
value: msg,
});
Expand All @@ -171,7 +171,7 @@ describe("AminoTypes", () => {
codeId: Long.fromString("98765"),
msg: toUtf8(`{"foo":"bar"}`),
};
const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).toAmino({
typeUrl: "/cosmwasm.wasm.v1.MsgMigrateContract",
value: msg,
});
Expand All @@ -197,7 +197,7 @@ describe("AminoTypes", () => {
wasm_byte_code: "WUVMTE9XIFNVQk1BUklORQ==",
},
};
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg);
const expectedValue: MsgStoreCode = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="),
Expand All @@ -223,7 +223,7 @@ describe("AminoTypes", () => {
admin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
},
};
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg);
const expectedValue: MsgInstantiateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
codeId: Long.fromString("12345"),
Expand All @@ -250,7 +250,7 @@ describe("AminoTypes", () => {
funds: coins(1234, "ucosm"),
},
};
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg);
const expectedValue: MsgInstantiateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
codeId: Long.fromString("12345"),
Expand All @@ -275,7 +275,7 @@ describe("AminoTypes", () => {
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
},
};
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg);
const expectedValue: MsgUpdateAdmin = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
newAdmin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
Expand All @@ -295,7 +295,7 @@ describe("AminoTypes", () => {
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
},
};
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg);
const expectedValue: MsgClearAdmin = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
Expand All @@ -316,7 +316,7 @@ describe("AminoTypes", () => {
funds: coins(1234, "ucosm"),
},
};
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg);
const expectedValue: MsgExecuteContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
Expand All @@ -339,7 +339,7 @@ describe("AminoTypes", () => {
msg: { foo: "bar" },
},
};
const msg = new AminoTypes({ additions: cosmWasmTypes }).fromAmino(aminoMsg);
const msg = new AminoTypes({ prefix: "cosmos", additions: cosmWasmTypes }).fromAmino(aminoMsg);
const expectedValue: MsgMigrateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
Expand Down
2 changes: 2 additions & 0 deletions packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ describe("SigningCosmWasmClient", () => {
};
customRegistry.register(msgDelegateTypeUrl, CustomMsgDelegate);
const customAminoTypes = new AminoTypes({
prefix: "cosmos",
additions: {
"/cosmos.staking.v1beta1.MsgDelegate": {
aminoType: "cosmos-sdk/MsgDelegate",
Expand Down Expand Up @@ -1122,6 +1123,7 @@ describe("SigningCosmWasmClient", () => {
};
customRegistry.register(msgDelegateTypeUrl, CustomMsgDelegate);
const customAminoTypes = new AminoTypes({
prefix: "cosmos",
additions: {
"/cosmos.staking.v1beta1.MsgDelegate": {
aminoType: "cosmos-sdk/MsgDelegate",
Expand Down
4 changes: 3 additions & 1 deletion packages/cosmwasm-stargate/src/signingcosmwasmclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,11 @@ export class SigningCosmWasmClient extends CosmWasmClient {
options: SigningCosmWasmClientOptions,
) {
super(tmClient);
// TODO: do we really want to set a default here? Ideally we could get it from the signer such that users only have to set it once.
const prefix = options.prefix ?? "cosmos";
const {
registry = createDefaultRegistry(),
aminoTypes = new AminoTypes({ additions: cosmWasmTypes, prefix: options.prefix }),
aminoTypes = new AminoTypes({ prefix, additions: cosmWasmTypes }),
} = options;
this.registry = registry;
this.aminoTypes = aminoTypes;
Expand Down
Loading