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

feat: add MsgUpdateCensorship msg and Censorship query of x/foundation API #105

Merged
merged 9 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- [\#98](https://github.com/Finschia/finschia-js/pull/98) bumpup cosmjs to 0.31.0
- [\#105](https://github.com/Finschia/finschia-js/pull/105) add `MsgUpdateCensorship` msg and `Censorship` query apis of x/foundation

### Changed

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@cosmjs/encoding": "^0.31.0",
"@cosmjs/proto-signing": "^0.31.0",
"@cosmjs/stargate": "^0.31.0",
"@finschia/finschia": "0.9.0-rc2",
"@finschia/finschia": "0.9.0",
"eslint": "^7.5",
"karma-chrome-launcher": "^3.1.0",
"karma-jasmine": "^4.0.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/finschia/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@finschia/finschia",
"version": "0.9.0-rc2",
"version": "0.9.0",
"description": "Utilities for FINSCHIA v2.0.0",
"contributors": [
"zemyblue <zemyblue@users.noreply.github.com>",
Expand Down Expand Up @@ -47,7 +47,7 @@
"@cosmjs/stargate": "^0.31.0",
"@cosmjs/tendermint-rpc": "^0.31.0",
"@cosmjs/utils": "^0.31.0",
"@finschia/finschia-proto": "^2.0.0-rc5",
"@finschia/finschia-proto": "^2.0.0",
"cosmjs-types": "^0.8.0",
"long": "^4.0.0",
"pako": "^2.0.2",
Expand Down
3 changes: 3 additions & 0 deletions packages/finschia/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export {
createMsgGrant,
createMsgRevoke,
createMsgSubmitProposal,
createMsgUpdateCensorship,
createMsgUpdateDecisionPolicy,
createMsgUpdateMembers,
createMsgWithdrawFromTreasury,
Expand All @@ -69,6 +70,7 @@ export {
isMsgLeaveFoundationEncodeObject,
isMsgRevokeEncodeObject,
isMsgSubmitProposalEncodeObject,
isMsgUpdateCensorshipEncodeObject,
isMsgUpdateDecisionPolicyEncodeObject,
isMsgUpdateMembersEncodeObject,
isMsgVoteEncodeObject,
Expand All @@ -82,6 +84,7 @@ export {
MsgLeaveFoundationEncodeObject,
MsgRevokeEncodeObject,
MsgSubmitProposalEncodeObject,
MsgUpdateCensorshipEncodeObject,
MsgUpdateDecisionPolicyEncodeObject,
MsgUpdateMembersEncodeObject,
MsgVoteEncodeObject,
Expand Down
2 changes: 1 addition & 1 deletion packages/finschia/src/modules/collection/queries.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createProtobufRpcClient, QueryClient } from "@cosmjs/stargate";
import { assert } from "@cosmjs/utils";
import { Any } from "cosmjs-types/google/protobuf/any";
import { Coin, Contract, Grant, NFT, TokenType } from "@finschia/finschia-proto/lbm/collection/v1/collection";
import { QueryClientImpl } from "@finschia/finschia-proto/lbm/collection/v1/query";
import { Any } from "cosmjs-types/google/protobuf/any";
tkxkd0159 marked this conversation as resolved.
Show resolved Hide resolved

export interface CollectionExtension {
readonly collection: {
Expand Down
2 changes: 1 addition & 1 deletion packages/finschia/src/modules/feegrant/queries.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { createPagination, createProtobufRpcClient, QueryClient } from "@cosmjs/stargate";
import { QueryAllowanceResponse, QueryAllowancesResponse } from "cosmjs-types/cosmos/feegrant/v1beta1/query";
import {
QueryAllowancesByGranterResponse,
QueryClientImpl,
} from "@finschia/finschia-proto/cosmos/feegrant/v1beta1/query";
import { QueryAllowanceResponse, QueryAllowancesResponse } from "cosmjs-types/cosmos/feegrant/v1beta1/query";
zemyblue marked this conversation as resolved.
Show resolved Hide resolved

export interface FeeGrantExtension {
readonly feegrant: {
Expand Down
88 changes: 82 additions & 6 deletions packages/finschia/src/modules/foundation/aminomessages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AminoTypes, assertIsDeliverTxSuccess, coins, logs } from "@cosmjs/starg
import { sleep } from "@cosmjs/utils";
import { ReceiveFromTreasuryAuthorization } from "@finschia/finschia-proto/lbm/foundation/v1/authz";
import {
CensorshipAuthority,
PercentageDecisionPolicy,
ThresholdDecisionPolicy,
VoteOption,
Expand All @@ -16,6 +17,7 @@ import {
MsgGrant,
MsgLeaveFoundation,
MsgRevoke,
MsgUpdateCensorship,
MsgUpdateDecisionPolicy,
MsgUpdateMembers,
MsgVote,
Expand Down Expand Up @@ -45,6 +47,7 @@ import {
AminoMsgLeaveFoundation,
AminoMsgRevoke,
AminoMsgSubmitProposal,
AminoMsgUpdateCensorship,
AminoMsgUpdateDecisionPolicy,
AminoMsgUpdateMembers,
AminoMsgVote,
Expand All @@ -56,8 +59,13 @@ import {
} from "./aminomessages";
import {
createMsgGrant,
createMsgSubmitProposal,
createMsgUpdateCensorship,
createMsgUpdateDecisionPolicy,
createMsgWithdrawFromTreasury,
createPercentageDecisionPolicy,
createThresholdDecisionPolicy,
foundationTypes,
MsgExecEncodeObject,
MsgGrantEncodeObject,
MsgLeaveFoundationEncodeObject,
Expand All @@ -66,12 +74,6 @@ import {
MsgWithdrawFromTreasuryEncodeObject,
MsgWithdrawProposalEncodeObject,
} from "./messages";
import {
createMsgSubmitProposal,
createMsgWithdrawFromTreasury,
createThresholdDecisionPolicy,
foundationTypes,
} from "./messages";
import { makeClientWithFoundation } from "./queries.spec";

describe("Amino sign", () => {
Expand Down Expand Up @@ -315,6 +317,28 @@ describe("Amino sign", () => {
assertIsDeliverTxSuccess(result);
});

it("MsgUpdateCensorship", async () => {
pendingWithoutSimapp();
const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic, {
hdPaths: [makeLinkPath(0)],
prefix: simapp.prefix,
});
const signingFinschiaClient2 = await SigningFinschiaClient.connectWithSigner(
simapp.tendermintUrl,
wallet,
defaultSigningClientOptions,
);

const foundationModuleAddr = "link190vt0vxc8c8vj24a7mm3fjsenfu8f5yxxj76cp";
const msgUpdateCensorship = createMsgUpdateCensorship(foundationModuleAddr, {
msgTypeUrl: "/lbm.foundation.v1.MsgWithdrawFromTreasury",
authority: CensorshipAuthority.CENSORSHIP_AUTHORITY_GOVERNANCE,
});
const msg1 = createMsgSubmitProposal([faucet.address0], [msgUpdateCensorship]);
const result1 = await signingFinschiaClient2.signAndBroadcast(faucet.address0, [msg1], defaultFee);
assertIsDeliverTxSuccess(result1);
});

it("MsgUpdateDecisionPolicy ThresholdDecisionPolicy", async () => {
pendingWithoutSimapp();
const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic, {
Expand Down Expand Up @@ -643,6 +667,32 @@ describe("AminoTypes", () => {
expect(aminoMsg).toEqual(expected);
});

it("MsgUpdateCensorship", () => {
tkxkd0159 marked this conversation as resolved.
Show resolved Hide resolved
const msg: MsgUpdateCensorship = {
authority: faucet.address0,
censorship: {
msgTypeUrl: "/lbm.foundation.v1.MsgWithdrawFromTreasury",
authority: CensorshipAuthority.CENSORSHIP_AUTHORITY_GOVERNANCE,
},
};
const aminoTypes = new AminoTypes(createFoundationAminoConverters());
const aminoMsg = aminoTypes.toAmino({
typeUrl: "/lbm.foundation.v1.MsgUpdateCensorship",
value: msg,
});
const expected: AminoMsgUpdateCensorship = {
type: "lbm-sdk/MsgUpdateCensorship",
value: {
authority: faucet.address0,
censorship: {
msg_type_url: "/lbm.foundation.v1.MsgWithdrawFromTreasury",
authority: 1,
},
},
};
expect(aminoMsg).toEqual(expected);
});

it("MsgGrant", () => {
const msg: MsgGrant = {
authority: faucet.address0,
Expand Down Expand Up @@ -944,6 +994,32 @@ describe("AminoTypes", () => {
});
});

it("MsgUpdateCensorship", () => {
tkxkd0159 marked this conversation as resolved.
Show resolved Hide resolved
const aminoMsg: AminoMsgUpdateCensorship = {
type: "lbm-sdk/MsgUpdateCensorship",
value: {
authority: faucet.address0,
censorship: {
msg_type_url: "/lbm.foundation.v1.MsgWithdrawFromTreasury",
authority: 1,
},
},
};
const aminoTypes = new AminoTypes(createFoundationAminoConverters());
const msg = aminoTypes.fromAmino(aminoMsg);
const expectedValue: MsgUpdateCensorship = {
authority: faucet.address0,
censorship: {
msgTypeUrl: "/lbm.foundation.v1.MsgWithdrawFromTreasury",
authority: CensorshipAuthority.CENSORSHIP_AUTHORITY_GOVERNANCE,
},
};
expect(msg).toEqual({
typeUrl: "/lbm.foundation.v1.MsgUpdateCensorship",
value: expectedValue,
});
});

it("MsgGrant", () => {
const aminoMsg: AminoMsgGrant = {
type: "lbm-sdk/MsgGrant",
Expand Down
44 changes: 43 additions & 1 deletion packages/finschia/src/modules/foundation/aminomessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AminoConverter, AminoConverters, AminoTypes } from "@cosmjs/stargate";
import { assertDefinedAndNotNull } from "@cosmjs/utils";
import { ReceiveFromTreasuryAuthorization } from "@finschia/finschia-proto/lbm/foundation/v1/authz";
import {
censorshipAuthorityFromJSON,
PercentageDecisionPolicy,
ThresholdDecisionPolicy,
voteOptionFromJSON,
Expand All @@ -18,6 +19,7 @@ import {
MsgLeaveFoundation,
MsgRevoke,
MsgSubmitProposal,
MsgUpdateCensorship,
MsgUpdateDecisionPolicy,
MsgUpdateMembers,
MsgVote,
Expand All @@ -28,6 +30,7 @@ import { CreateValidatorAuthorization } from "@finschia/finschia-proto/lbm/staki
import { Any } from "cosmjs-types/google/protobuf/any";
import Long from "long";

// eslint-disable-next-line import/no-cycle
import { createDefaultRegistry, createDefaultTypesWithoutFoundation } from "../../types";
import {
jsonDecimalToProto,
Expand All @@ -46,6 +49,11 @@ interface MemberRequest {
metadata?: string;
}

interface Censorship {
msg_type_url: string;
authority: number;
}

export interface AminoMsgFundTreasury extends AminoMsg {
readonly type: "lbm-sdk/MsgFundTreasury";
readonly value: {
Expand All @@ -54,7 +62,7 @@ export interface AminoMsgFundTreasury extends AminoMsg {
};
}

export function isAminoMsgFundTreasurys(msg: AminoMsg): msg is AminoMsgFundTreasury {
export function isAminoMsgFundTreasury(msg: AminoMsg): msg is AminoMsgFundTreasury {
return msg.type === "lbm-sdk/MsgFundTreasury";
}

Expand Down Expand Up @@ -191,6 +199,18 @@ export function isAminoMsgLeaveFoundation(msg: AminoMsg): msg is AminoMsgLeaveFo
return msg.type === "lbm-sdk/MsgLeaveFoundation";
}

export interface AminoMsgUpdateCensorship extends AminoMsg {
readonly type: "lbm-sdk/MsgUpdateCensorship";
readonly value: {
readonly authority: string;
readonly censorship: Censorship;
};
}

export function isAminoMsgUpdateCensorship(msg: AminoMsg): msg is AminoMsgUpdateCensorship {
return msg.type === "lbm-sdk/MsgUpdateCensorship";
}

export interface AminoMsgGrant extends AminoMsg {
readonly type: "lbm-sdk/MsgGrant";
readonly value: {
Expand Down Expand Up @@ -493,6 +513,28 @@ export function createFoundationAminoConvertersWithoutSubmitProposal(): AminoCon
};
},
},
"/lbm.foundation.v1.MsgUpdateCensorship": {
aminoType: "lbm-sdk/MsgUpdateCensorship",
toAmino: ({ authority, censorship }: MsgUpdateCensorship): AminoMsgUpdateCensorship["value"] => {
assertDefinedAndNotNull(censorship);
return {
authority: authority,
censorship: {
msg_type_url: censorship.msgTypeUrl,
authority: censorship.authority,
},
};
},
fromAmino: ({ authority, censorship }: AminoMsgUpdateCensorship["value"]): MsgUpdateCensorship => {
return {
authority: authority,
censorship: {
msgTypeUrl: censorship.msg_type_url,
authority: censorshipAuthorityFromJSON(censorship.authority),
},
};
},
},
"/lbm.foundation.v1.MsgGrant": {
aminoType: "lbm-sdk/MsgGrant",
toAmino: ({ authority, grantee, authorization }: MsgGrant): AminoMsgGrant["value"] => {
Expand Down
27 changes: 27 additions & 0 deletions packages/finschia/src/modules/foundation/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Decimal } from "@cosmjs/math";
import { EncodeObject, GeneratedType, Registry } from "@cosmjs/proto-signing";
import { ReceiveFromTreasuryAuthorization } from "@finschia/finschia-proto/lbm/foundation/v1/authz";
import {
Censorship,
DecisionPolicyWindows,
MemberRequest,
PercentageDecisionPolicy,
Expand All @@ -16,6 +17,7 @@ import {
MsgLeaveFoundation,
MsgRevoke,
MsgSubmitProposal,
MsgUpdateCensorship,
MsgUpdateDecisionPolicy,
MsgUpdateMembers,
MsgVote,
Expand All @@ -37,6 +39,7 @@ export const foundationTypes: ReadonlyArray<[string, GeneratedType]> = [
["/lbm.foundation.v1.MsgVote", MsgVote],
["/lbm.foundation.v1.MsgExec", MsgExec],
["/lbm.foundation.v1.MsgLeaveFoundation", MsgLeaveFoundation],
["/lbm.foundation.v1.MsgUpdateCensorship", MsgUpdateCensorship],
["/lbm.foundation.v1.MsgGrant", MsgGrant],
["/lbm.foundation.v1.MsgRevoke", MsgRevoke],
["/lbm.foundation.v1.ReceiveFromTreasuryAuthorization", ReceiveFromTreasuryAuthorization],
Expand Down Expand Up @@ -140,6 +143,17 @@ export function isMsgLeaveFoundationEncodeObject(
return (object as MsgLeaveFoundationEncodeObject).typeUrl === "/lbm.foundation.v1.MsgLeaveFoundation";
}

export interface MsgUpdateCensorshipEncodeObject extends EncodeObject {
readonly typeUrl: "/lbm.foundation.v1.MsgUpdateCensorship";
readonly value: Partial<MsgUpdateCensorship>;
}

export function isMsgUpdateCensorshipEncodeObject(
object: EncodeObject,
): object is MsgUpdateCensorshipEncodeObject {
return (object as MsgUpdateCensorshipEncodeObject).typeUrl === "/lbm.foundation.v1.MsgUpdateCensorship";
}

export interface MsgGrantEncodeObject extends EncodeObject {
readonly typeUrl: "/lbm.foundation.v1.MsgGrant";
readonly value: Partial<MsgGrant>;
Expand Down Expand Up @@ -203,6 +217,19 @@ export function createMsgSubmitProposal(
};
}

export function createMsgUpdateCensorship(
authority: string,
censorship: Censorship,
): MsgUpdateCensorshipEncodeObject {
return {
typeUrl: "/lbm.foundation.v1.MsgUpdateCensorship",
value: {
authority: authority,
censorship: censorship,
},
};
}

export function createMsgGrant(authority: string, grantee: string): MsgGrantEncodeObject {
const registry = new Registry(foundationTypes);
return {
Expand Down
Loading