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

fix: remove position validation from post entities and references #941

Merged
merged 4 commits into from
Jun 28, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: fix
module: x/posts
pull_request: 941
description: Allow to specify start and end indexes of tags and post references even when a post text is stored outside the chain
backward_compatible: true
date: 2022-06-27T12:29:24.898824942Z
16 changes: 0 additions & 16 deletions x/posts/types/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,6 @@ func (p Post) Validate() error {
if err != nil {
return fmt.Errorf("invalid entities: %s", err)
}

// Make sure that no entity has a start or end index that is greater to the text length
maxIndexAllowed := uint64(0)
if len(strings.TrimSpace(p.Text)) > 0 {
maxIndexAllowed = uint64(len(strings.TrimSpace(p.Text)) - 1)
}

for _, segment := range p.Entities.getSegments() {
if segment.start > maxIndexAllowed || segment.end > maxIndexAllowed {
return fmt.Errorf("entity cannot have start/end index greater than text length")
}
}
}

_, err := sdk.AccAddressFromBech32(p.Author)
Expand All @@ -104,10 +92,6 @@ func (p Post) Validate() error {
if reference.PostID >= p.ID {
return fmt.Errorf("invalid referenced post id: %d", reference.PostID)
}

if reference.Position > uint64(len(p.Text)) {
return fmt.Errorf("invalid reference position: %d", reference.Position)
}
}

if p.ReplySettings == REPLY_SETTING_UNSPECIFIED {
Expand Down
88 changes: 0 additions & 88 deletions x/posts/types/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,66 +106,6 @@ func TestPost_Validate(t *testing.T) {
),
shouldErr: true,
},
{
name: "invalid hashtag index returns error",
post: types.NewPost(
1,
0,
2,
"External id",
"Text",
"cosmos1eqpa6mv2jgevukaqtjmx5535vhc3mm3cf458zg",
1,
types.NewEntities([]types.Tag{
types.NewTag(1, 10, "tag"),
}, nil, nil),
nil,
types.REPLY_SETTING_EVERYONE,
time.Date(2020, 1, 1, 12, 00, 00, 000, time.UTC),
nil,
),
shouldErr: true,
},
{
name: "invalid mention index returns error",
post: types.NewPost(
1,
0,
2,
"External id",
"Text",
"cosmos1eqpa6mv2jgevukaqtjmx5535vhc3mm3cf458zg",
1,
types.NewEntities(nil, []types.Tag{
types.NewTag(10, 1, "tag"),
}, nil),
nil,
types.REPLY_SETTING_EVERYONE,
time.Date(2020, 1, 1, 12, 00, 00, 000, time.UTC),
nil,
),
shouldErr: true,
},
{
name: "invalid url index returns error",
post: types.NewPost(
1,
0,
2,
"External id",
"Text",
"cosmos1eqpa6mv2jgevukaqtjmx5535vhc3mm3cf458zg",
1,
types.NewEntities(nil, nil, []types.Url{
types.NewURL(10, 1, "URL", "Display URL"),
}),
nil,
types.REPLY_SETTING_EVERYONE,
time.Date(2020, 1, 1, 12, 00, 00, 000, time.UTC),
nil,
),
shouldErr: true,
},
{
name: "invalid author address returns error",
post: types.NewPost(
Expand Down Expand Up @@ -278,34 +218,6 @@ func TestPost_Validate(t *testing.T) {
),
shouldErr: true,
},
{
name: "invalid reference position returns error",
post: types.NewPost(
1,
0,
2,
"External id",
"Text",
"cosmos1eqpa6mv2jgevukaqtjmx5535vhc3mm3cf458zg",
1,
types.NewEntities(
[]types.Tag{
types.NewTag(1, 1, "tag"),
},
[]types.Tag{
types.NewTag(2, 3, "tag"),
},
nil,
),
[]types.PostReference{
types.NewPostReference(types.POST_REFERENCE_TYPE_QUOTE, 1, 1000),
},
types.REPLY_SETTING_EVERYONE,
time.Date(2020, 1, 1, 12, 00, 00, 000, time.UTC),
nil,
),
shouldErr: true,
},
{
name: "invalid reply setting returns error",
post: types.NewPost(
Expand Down