From b41cb21299129869fafa2a7d9b81e759f7ca434d Mon Sep 17 00:00:00 2001 From: larry <26318510+larry0x@users.noreply.github.com> Date: Fri, 13 Jan 2023 01:10:05 +0000 Subject: [PATCH] update required metadata schema --- x/gov/README.md | 8 +++++--- x/gov/keeper/msg_server_test.go | 6 ++---- x/gov/types/metadata.go | 14 +++++--------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/x/gov/README.md b/x/gov/README.md index 9c30712b..a0700b56 100644 --- a/x/gov/README.md +++ b/x/gov/README.md @@ -40,14 +40,16 @@ In Mars `customgov`, we want to storage the metadata on-chain. In order for this ```typescript type ProposalMetadata = { title: string; - authors: string[]; - summary?: string; - details: string; + authors?: string[]; + summary: string; + details?: string; proposal_forum_url?: string; vote_option_context?: string; }; ``` + We make `title` and `summary` mandatory and the other fields optional, because from sdk 0.47 [proposals will have mandatory title and summary fields](https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/gov/v1/gov.proto#L85-L93). Once Mars Hub upgrades to sdk 0.47, we can make these two fields optional as well. + - For vote metadata, we assert that it is either an empty string (it's ok if a voter doesn't want to provide a rationale for their vote), or if it's not empty, conforms to this schema: ```typescript diff --git a/x/gov/keeper/msg_server_test.go b/x/gov/keeper/msg_server_test.go index 86521ba9..e7453eff 100644 --- a/x/gov/keeper/msg_server_test.go +++ b/x/gov/keeper/msg_server_test.go @@ -37,8 +37,7 @@ func TestProposalMetadataTypeCheck(t *testing.T) { "a valid metadata with missing optional fields", `{ "title": "Mock Proposal", - "authors": [], - "details": "This is a mock-up proposal for use in the unit tests of Mars Hub's gov module." + "summary": "Mock proposal for testing purposes" }`, true, }, @@ -54,8 +53,7 @@ func TestProposalMetadataTypeCheck(t *testing.T) { "extra unexpected fields are accepted", `{ "title": "Mock Proposal", - "authors": ["Larry Engineer "], - "details": "This is a mock-up proposal for use in the unit tests of Mars Hub's gov module.", + "summary": "Mock proposal for testing purposes", "foo": "bar" }`, true, diff --git a/x/gov/types/metadata.go b/x/gov/types/metadata.go index aae84b34..8c52b425 100644 --- a/x/gov/types/metadata.go +++ b/x/gov/types/metadata.go @@ -7,9 +7,9 @@ import ( // ProposalMetadata defines the required schema for proposal metadata. type ProposalMetadata struct { Title string `json:"title"` - Authors []string `json:"authors"` - Summary string `json:"summary,omitempty"` - Details string `json:"details"` + Authors []string `json:"authors,omitempty"` + Summary string `json:"summary"` + Details string `json:"details,omitempty"` ProposalForumURL string `json:"proposal_forum_url,omitempty"` VoteOptionContext string `json:"vote_option_context,omitempty"` } @@ -43,12 +43,8 @@ func UnmarshalProposalMetadata(metadataStr string) (*ProposalMetadata, error) { return nil, ErrInvalidMetadata.Wrap("missing field `title`") } - if metadata.Authors == nil { - return nil, ErrInvalidMetadata.Wrap("missing field `authors`") - } - - if metadata.Details == "" { - return nil, ErrInvalidMetadata.Wrap("missing field `details`") + if metadata.Summary == "" { + return nil, ErrInvalidMetadata.Wrap("missing field `summary`") } return &metadata, nil