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

Remove default types from AminoTypes #1081

Merged
merged 17 commits into from
Mar 10, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ and this project adheres to
dependencies. This should also reduce the bundle size as only the English
wordlist is shipped. ([#966])
- @cosmjs/cli: Rename binary `cosmwasm-cli` to `cosmjs-cli` ([#1033]).
- @cosmjs/stargate & @cosmjs/cosmwasm-stargate: Removed default types from AminoTypes. ([1079])

[#927]: https://github.com/cosmos/cosmjs/issues/927
[#955]: https://github.com/cosmos/cosmjs/issues/955
Expand All @@ -55,6 +56,7 @@ and this project adheres to
[#1026]: https://github.com/cosmos/cosmjs/issues/1026
[#1033]: https://github.com/cosmos/cosmjs/issues/1033
[#1053]: https://github.com/cosmos/cosmjs/issues/1053
[#1079]: https://github.com/cosmos/cosmjs/issues/1079

### Removed

Expand Down
58 changes: 20 additions & 38 deletions packages/cosmwasm-stargate/src/modules/wasm/aminomessages.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({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino({
const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({
typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode",
value: msg,
});
Expand All @@ -54,12 +54,10 @@ describe("AminoTypes", () => {
funds: coins(1234, "ucosm"),
admin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
};
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino(
{
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
value: msg,
},
);
const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
value: msg,
});
const expected: AminoMsgInstantiateContract = {
type: "wasm/MsgInstantiateContract",
value: {
Expand All @@ -84,12 +82,10 @@ describe("AminoTypes", () => {
funds: coins(1234, "ucosm"),
admin: "",
};
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino(
{
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
value: msg,
},
);
const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({
typeUrl: "/cosmwasm.wasm.v1.MsgInstantiateContract",
value: msg,
});
const expected: AminoMsgInstantiateContract = {
type: "wasm/MsgInstantiateContract",
value: {
Expand All @@ -111,7 +107,7 @@ describe("AminoTypes", () => {
newAdmin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
};
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino({
const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({
typeUrl: "/cosmwasm.wasm.v1.MsgUpdateAdmin",
value: msg,
});
Expand All @@ -131,7 +127,7 @@ describe("AminoTypes", () => {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
};
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino({
const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({
typeUrl: "/cosmwasm.wasm.v1.MsgClearAdmin",
value: msg,
});
Expand All @@ -152,7 +148,7 @@ describe("AminoTypes", () => {
msg: toUtf8(`{"foo":"bar"}`),
funds: coins(1234, "ucosm"),
};
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino({
const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
value: msg,
});
Expand All @@ -175,7 +171,7 @@ describe("AminoTypes", () => {
codeId: Long.fromString("98765"),
msg: toUtf8(`{"foo":"bar"}`),
};
const aminoMsg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).toAmino({
const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({
typeUrl: "/cosmwasm.wasm.v1.MsgMigrateContract",
value: msg,
});
Expand All @@ -201,9 +197,7 @@ describe("AminoTypes", () => {
wasm_byte_code: "WUVMTE9XIFNVQk1BUklORQ==",
},
};
const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino(
aminoMsg,
);
const msg = new AminoTypes(createWasmAminoConverters()).fromAmino(aminoMsg);
const expectedValue: MsgStoreCode = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="),
Expand All @@ -229,9 +223,7 @@ describe("AminoTypes", () => {
admin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
},
};
const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino(
aminoMsg,
);
const msg = new AminoTypes(createWasmAminoConverters()).fromAmino(aminoMsg);
const expectedValue: MsgInstantiateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
codeId: Long.fromString("12345"),
Expand All @@ -258,9 +250,7 @@ describe("AminoTypes", () => {
funds: coins(1234, "ucosm"),
},
};
const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino(
aminoMsg,
);
const msg = new AminoTypes(createWasmAminoConverters()).fromAmino(aminoMsg);
const expectedValue: MsgInstantiateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
codeId: Long.fromString("12345"),
Expand All @@ -285,9 +275,7 @@ describe("AminoTypes", () => {
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
},
};
const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino(
aminoMsg,
);
const msg = new AminoTypes(createWasmAminoConverters()).fromAmino(aminoMsg);
const expectedValue: MsgUpdateAdmin = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
newAdmin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
Expand All @@ -307,9 +295,7 @@ describe("AminoTypes", () => {
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
},
};
const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino(
aminoMsg,
);
const msg = new AminoTypes(createWasmAminoConverters()).fromAmino(aminoMsg);
const expectedValue: MsgClearAdmin = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
Expand All @@ -330,9 +316,7 @@ describe("AminoTypes", () => {
funds: coins(1234, "ucosm"),
},
};
const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino(
aminoMsg,
);
const msg = new AminoTypes(createWasmAminoConverters()).fromAmino(aminoMsg);
const expectedValue: MsgExecuteContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
Expand All @@ -355,9 +339,7 @@ describe("AminoTypes", () => {
msg: { foo: "bar" },
},
};
const msg = new AminoTypes({ prefix: "cosmos", additions: createWasmAminoConverters() }).fromAmino(
aminoMsg,
);
const msg = new AminoTypes(createWasmAminoConverters()).fromAmino(aminoMsg);
const expectedValue: MsgMigrateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
Expand Down
123 changes: 61 additions & 62 deletions packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
assertIsDeliverTxSuccess,
coin,
coins,
createStakingAminoConverters,
MsgDelegateEncodeObject,
MsgSendEncodeObject,
} from "@cosmjs/stargate";
Expand Down Expand Up @@ -736,6 +737,7 @@ describe("SigningCosmWasmClient", () => {
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, {
...defaultSigningClientOptions,
aminoTypes: new AminoTypes(createStakingAminoConverters(wasmd.prefix)),
prefix: wasmd.prefix,
});

Expand Down Expand Up @@ -851,39 +853,36 @@ describe("SigningCosmWasmClient", () => {
};
customRegistry.register(msgDelegateTypeUrl, CustomMsgDelegate);
const customAminoTypes = new AminoTypes({
prefix: "cosmos",
additions: {
"/cosmos.staking.v1beta1.MsgDelegate": {
aminoType: "cosmos-sdk/MsgDelegate",
toAmino: ({
customDelegatorAddress,
customValidatorAddress,
customAmount,
}: CustomMsgDelegate): AminoMsgDelegate["value"] => {
assert(customDelegatorAddress, "missing customDelegatorAddress");
assert(customValidatorAddress, "missing validatorAddress");
assert(customAmount, "missing amount");
assert(customAmount.amount, "missing amount.amount");
assert(customAmount.denom, "missing amount.denom");
return {
delegator_address: customDelegatorAddress,
validator_address: customValidatorAddress,
amount: {
amount: customAmount.amount,
denom: customAmount.denom,
},
};
},
fromAmino: ({
delegator_address,
validator_address,
amount,
}: AminoMsgDelegate["value"]): CustomMsgDelegate => ({
customDelegatorAddress: delegator_address,
customValidatorAddress: validator_address,
customAmount: Coin.fromPartial(amount),
}),
"/cosmos.staking.v1beta1.MsgDelegate": {
aminoType: "cosmos-sdk/MsgDelegate",
toAmino: ({
customDelegatorAddress,
customValidatorAddress,
customAmount,
}: CustomMsgDelegate): AminoMsgDelegate["value"] => {
assert(customDelegatorAddress, "missing customDelegatorAddress");
assert(customValidatorAddress, "missing validatorAddress");
assert(customAmount, "missing amount");
assert(customAmount.amount, "missing amount.amount");
assert(customAmount.denom, "missing amount.denom");
return {
delegator_address: customDelegatorAddress,
validator_address: customValidatorAddress,
amount: {
amount: customAmount.amount,
denom: customAmount.denom,
},
};
},
fromAmino: ({
delegator_address,
validator_address,
amount,
}: AminoMsgDelegate["value"]): CustomMsgDelegate => ({
customDelegatorAddress: delegator_address,
customValidatorAddress: validator_address,
customAmount: Coin.fromPartial(amount),
}),
},
});
const options = {
Expand Down Expand Up @@ -921,6 +920,7 @@ describe("SigningCosmWasmClient", () => {
});
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, {
...defaultSigningClientOptions,
aminoTypes: new AminoTypes(createStakingAminoConverters(wasmd.prefix)),
prefix: wasmd.prefix,
});

Expand Down Expand Up @@ -1067,6 +1067,7 @@ describe("SigningCosmWasmClient", () => {
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix });
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, {
...defaultSigningClientOptions,
aminoTypes: new AminoTypes(createStakingAminoConverters(wasmd.prefix)),
prefix: wasmd.prefix,
});

Expand Down Expand Up @@ -1156,37 +1157,34 @@ describe("SigningCosmWasmClient", () => {
};
customRegistry.register(msgDelegateTypeUrl, CustomMsgDelegate);
const customAminoTypes = new AminoTypes({
prefix: "cosmos",
additions: {
"/cosmos.staking.v1beta1.MsgDelegate": {
aminoType: "cosmos-sdk/MsgDelegate",
toAmino: ({
customDelegatorAddress,
customValidatorAddress,
customAmount,
}: CustomMsgDelegate): AminoMsgDelegate["value"] => {
assert(customDelegatorAddress, "missing customDelegatorAddress");
assert(customValidatorAddress, "missing validatorAddress");
assert(customAmount, "missing amount");
return {
delegator_address: customDelegatorAddress,
validator_address: customValidatorAddress,
amount: {
amount: customAmount.amount,
denom: customAmount.denom,
},
};
},
fromAmino: ({
delegator_address,
validator_address,
amount,
}: AminoMsgDelegate["value"]): CustomMsgDelegate => ({
customDelegatorAddress: delegator_address,
customValidatorAddress: validator_address,
customAmount: Coin.fromPartial(amount),
}),
"/cosmos.staking.v1beta1.MsgDelegate": {
aminoType: "cosmos-sdk/MsgDelegate",
toAmino: ({
customDelegatorAddress,
customValidatorAddress,
customAmount,
}: CustomMsgDelegate): AminoMsgDelegate["value"] => {
assert(customDelegatorAddress, "missing customDelegatorAddress");
assert(customValidatorAddress, "missing validatorAddress");
assert(customAmount, "missing amount");
return {
delegator_address: customDelegatorAddress,
validator_address: customValidatorAddress,
amount: {
amount: customAmount.amount,
denom: customAmount.denom,
},
};
},
fromAmino: ({
delegator_address,
validator_address,
amount,
}: AminoMsgDelegate["value"]): CustomMsgDelegate => ({
customDelegatorAddress: delegator_address,
customValidatorAddress: validator_address,
customAmount: Coin.fromPartial(amount),
}),
},
});
const options = {
Expand Down Expand Up @@ -1226,6 +1224,7 @@ describe("SigningCosmWasmClient", () => {
});
const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, {
...defaultSigningClientOptions,
aminoTypes: new AminoTypes(createStakingAminoConverters(wasmd.prefix)),
prefix: wasmd.prefix,
});

Expand Down
5 changes: 2 additions & 3 deletions packages/cosmwasm-stargate/src/signingcosmwasmclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
AminoTypes,
calculateFee,
Coin,
createBankAminoConverters,
defaultRegistryTypes as defaultStargateTypes,
DeliverTxResponse,
GasPrice,
Expand Down Expand Up @@ -201,11 +202,9 @@ 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({ prefix, additions: createWasmAminoConverters() }),
aminoTypes = new AminoTypes({ ...createWasmAminoConverters(), ...createBankAminoConverters() }),
} = options;
this.registry = registry;
this.aminoTypes = aminoTypes;
Expand Down
8 changes: 0 additions & 8 deletions packages/stargate/src/aminoconverters.ts

This file was deleted.

Loading