Skip to content

Commit

Permalink
update required metadata schema
Browse files Browse the repository at this point in the history
  • Loading branch information
larry0x committed Jan 13, 2023
1 parent cc23568 commit b41cb21
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
8 changes: 5 additions & 3 deletions x/gov/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions x/gov/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -54,8 +53,7 @@ func TestProposalMetadataTypeCheck(t *testing.T) {
"extra unexpected fields are accepted",
`{
"title": "Mock Proposal",
"authors": ["Larry Engineer <[email protected]>"],
"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,
Expand Down
14 changes: 5 additions & 9 deletions x/gov/types/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b41cb21

Please sign in to comment.