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

Post ID improvement #132

Merged
merged 23 commits into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from 16 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
@@ -1,5 +1,6 @@
# Version 0.4.0
## Changes
- Improved `postID` generation (#131)
RiccardoM marked this conversation as resolved.
Show resolved Hide resolved
- Improved `alias.go` files (#103)
- Added the support for posting empty-message posts with medias (#110)
- Implemented the support for hashtags in posts (#96)
Expand Down
81 changes: 51 additions & 30 deletions cli_test/cli_posts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ func TestDesmosCLIPostsCreateNoMediasNoPollData(t *testing.T) {
storedPosts := f.QueryPosts()
require.NotEmpty(t, storedPosts)
post := storedPosts[0]
require.Equal(t, posts.PostID(1), post.PostID)
computedID := posts.ComputeID(post.Created, post.Creator, post.Subspace)
require.Equal(t, computedID, post.PostID)
require.Nil(t, post.PollData)
require.Nil(t, post.Medias)

Expand Down Expand Up @@ -94,7 +95,8 @@ func TestDesmosCLIPostsCreateAllowsCommentFalse(t *testing.T) {
storedPosts := f.QueryPosts()
require.NotEmpty(t, storedPosts)
post := storedPosts[0]
require.Equal(t, posts.PostID(1), post.PostID)
computedID := posts.ComputeID(post.Created, post.Creator, post.Subspace)
require.Equal(t, computedID, post.PostID)
require.False(t, post.AllowsComments)
require.Nil(t, post.PollData)
require.Nil(t, post.Medias)
Expand Down Expand Up @@ -151,7 +153,8 @@ func TestDesmosCLIPostsCreateWithMediasAndEmptyMessage(t *testing.T) {
storedPosts := f.QueryPosts()
require.NotEmpty(t, storedPosts)
post := storedPosts[0]
require.Equal(t, posts.PostID(1), post.PostID)
computedID := posts.ComputeID(post.Created, post.Creator, post.Subspace)
require.Equal(t, computedID, post.PostID)
require.Nil(t, post.PollData)
require.Len(t, post.Medias, 2)
require.Equal(t, post.Medias, posts.NewPostMedias(
Expand Down Expand Up @@ -212,7 +215,8 @@ func TestDesmosCLIPostsCreateWithMediasAndNonEmptyMessage(t *testing.T) {
storedPosts := f.QueryPosts()
require.NotEmpty(t, storedPosts)
post := storedPosts[0]
require.Equal(t, posts.PostID(1), post.PostID)
computedID := posts.ComputeID(post.Created, post.Creator, post.Subspace)
require.Equal(t, computedID, post.PostID)
require.Nil(t, post.PollData)
require.Len(t, post.Medias, 2)
require.Equal(t, post.Medias, posts.NewPostMedias(
Expand Down Expand Up @@ -271,7 +275,8 @@ func TestDesmosCLIPostsCreateWithNoMediasAndNonEmptyMessage(t *testing.T) {
storedPosts := f.QueryPosts()
require.NotEmpty(t, storedPosts)
post := storedPosts[0]
require.Equal(t, posts.PostID(1), post.PostID)
computedID := posts.ComputeID(post.Created, post.Creator, post.Subspace)
require.Equal(t, computedID, post.PostID)
require.Nil(t, post.PollData)
require.Len(t, post.Medias, 0)

Expand Down Expand Up @@ -327,7 +332,8 @@ func TestDesmosCLIPostsCreateWithPoll(t *testing.T) {
storedPosts := f.QueryPosts()
require.NotEmpty(t, storedPosts)
post := storedPosts[0]
require.Equal(t, posts.PostID(1), post.PostID)
computedID := posts.ComputeID(post.Created, post.Creator, post.Subspace)
require.Equal(t, computedID, post.PostID)
require.Nil(t, post.Medias)
require.NotNil(t, post.PollData)

Expand Down Expand Up @@ -403,24 +409,29 @@ func TestDesmosCLIPostsAnswerPoll(t *testing.T) {
require.Empty(t, sterr)
tests.WaitForNextNBlocksTM(1, f.Port)

// Make sure the post is saved
storedPosts := f.QueryPosts()
require.NotEmpty(t, storedPosts)
post := storedPosts[0]

// Insert an answer
success, _, sterr = f.TxPostsAnswerPoll(posts.PostID(1), []posts.AnswerID{posts.AnswerID(1)}, fooAddr, "-y")
success, _, sterr = f.TxPostsAnswerPoll(post.PostID, []posts.AnswerID{posts.AnswerID(1)}, fooAddr, "-y")
require.True(t, success)
require.Empty(t, sterr)
tests.WaitForNextNBlocksTM(1, f.Port)

// Check that answers have been inserted
post := f.QueryPost(1)
require.NotEmpty(t, post.PollAnswers)
require.Equal(t, posts.NewUserAnswer([]posts.AnswerID{posts.AnswerID(1)}, fooAddr), post.PollAnswers[0])
postQueryResponse := f.QueryPost(post.PostID.String())
require.NotEmpty(t, postQueryResponse.PollAnswers)
require.Equal(t, posts.NewUserAnswer([]posts.AnswerID{posts.AnswerID(1)}, fooAddr), postQueryResponse.PollAnswers[0])

// Test --dry-run
success, _, stderr := f.TxPostsAnswerPoll(posts.PostID(1), []posts.AnswerID{posts.AnswerID(1)}, fooAddr, "--dry-run")
success, _, stderr := f.TxPostsAnswerPoll(post.PostID, []posts.AnswerID{posts.AnswerID(1)}, fooAddr, "--dry-run")
require.Empty(t, sterr)
require.True(t, success)

// Test --generate-only
success, stdout, stderr := f.TxPostsAnswerPoll(posts.PostID(1), []posts.AnswerID{posts.AnswerID(1)}, fooAddr, "--generate-only")
success, stdout, stderr := f.TxPostsAnswerPoll(post.PostID, []posts.AnswerID{posts.AnswerID(1)}, fooAddr, "--generate-only")
require.Empty(t, stderr)
require.True(t, success)
msg := unmarshalStdTx(f.T, stdout)
Expand All @@ -429,8 +440,8 @@ func TestDesmosCLIPostsAnswerPoll(t *testing.T) {
require.Len(t, msg.GetSignatures(), 0)

// Check state didn't change
post = f.QueryPost(1)
require.Len(t, post.PollAnswers, 1)
postQueryResponse = f.QueryPost(post.PostID.String())
require.Len(t, postQueryResponse.PollAnswers, 1)

f.Cleanup()
}
Expand All @@ -452,23 +463,28 @@ func TestDesmosCLIPostsEdit(t *testing.T) {
require.Empty(t, sterr)
tests.WaitForNextNBlocksTM(1, f.Port)

// Make sure the post is saved
storedPosts := f.QueryPosts()
require.NotEmpty(t, storedPosts)
post := storedPosts[0]

// Edit the message
success, _, sterr = f.TxPostsEdit(1, "NewMessage", fooAddr, "-y")
success, _, sterr = f.TxPostsEdit(post.PostID.String(), "NewMessage", fooAddr, "-y")
require.True(t, success)
require.Empty(t, sterr)
tests.WaitForNextNBlocksTM(1, f.Port)

// Make sure the message is edited
storedPost := f.QueryPost(1)
require.Equal(t, posts.PostID(1), storedPost.PostID)
storedPost := f.QueryPost(post.PostID.String())
require.Equal(t, post.PostID, storedPost.PostID)
require.Equal(t, "NewMessage", storedPost.Message)

// Test --dry-run
success, _, _ = f.TxPostsEdit(1, "OtherMessage", fooAddr, "--dry-run")
success, _, _ = f.TxPostsEdit(post.PostID.String(), "OtherMessage", fooAddr, "--dry-run")
require.True(t, success)

// Test --generate-only
success, stdout, stderr := f.TxPostsEdit(1, "OtherMessage", fooAddr, "--generate-only=true")
success, stdout, stderr := f.TxPostsEdit(post.PostID.String(), "OtherMessage", fooAddr, "--generate-only=true")
require.Empty(t, stderr)
require.True(t, success)
msg := unmarshalStdTx(f.T, stdout)
Expand All @@ -477,7 +493,7 @@ func TestDesmosCLIPostsEdit(t *testing.T) {
require.Len(t, msg.GetSignatures(), 0)

// Check state didn't change
storedPosts := f.QueryPosts()
storedPosts = f.QueryPosts()
require.Len(t, storedPosts, 1)

f.Cleanup()
Expand Down Expand Up @@ -508,6 +524,11 @@ func TestDesmosCLIPostsReactions(t *testing.T) {
require.Empty(t, sterr)
tests.WaitForNextNBlocksTM(1, f.Port)

// Make sure the post is saved
storedPosts := f.QueryPosts()
require.NotEmpty(t, storedPosts)
post := storedPosts[0]

// Register reactions
for _, reaction := range reactions {
success, _, sterr = f.TxPostsRegisterReaction(reaction.ShortCode, reaction.Value, reaction.Subspace, reaction.Creator, "-y")
Expand All @@ -520,22 +541,22 @@ func TestDesmosCLIPostsReactions(t *testing.T) {
// add-reaction

// Add a reaction
success, _, sterr = f.TxPostsAddReaction(1, ":thumbsup:", fooAddr, "-y")
success, _, sterr = f.TxPostsAddReaction(post.PostID.String(), ":thumbsup:", fooAddr, "-y")
require.True(t, success)
require.Empty(t, sterr)
tests.WaitForNextNBlocksTM(1, f.Port)

// Make sure the reaction is added
storedPost := f.QueryPost(1)
storedPost := f.QueryPost(post.PostID.String())
require.Len(t, storedPost.Reactions, 1)
require.Equal(t, storedPost.Reactions[0], posts.NewPostReaction(":thumbsup:", fooAddr))

// Test --dry-run
success, _, _ = f.TxPostsAddReaction(1, ":blush:", fooAddr, "--dry-run")
success, _, _ = f.TxPostsAddReaction(post.PostID.String(), ":blush:", fooAddr, "--dry-run")
require.True(t, success)

// Test --generate-only
success, stdout, stderr := f.TxPostsAddReaction(1, ":thumbsdown:", fooAddr, "--generate-only=true")
success, stdout, stderr := f.TxPostsAddReaction(post.PostID.String(), ":thumbsdown:", fooAddr, "--generate-only=true")
require.Empty(t, stderr)
require.True(t, success)
msg := unmarshalStdTx(f.T, stdout)
Expand All @@ -544,28 +565,28 @@ func TestDesmosCLIPostsReactions(t *testing.T) {
require.Len(t, msg.GetSignatures(), 0)

// Check state didn't change
storedPost = f.QueryPost(1)
storedPost = f.QueryPost(post.PostID.String())
require.Len(t, storedPost.Reactions, 1)

// __________________________________________________________________________________
// remove-reaction

// Remove a reaction
success, _, sterr = f.TxPostsRemoveReaction(1, ":thumbsup:", fooAddr, "-y")
success, _, sterr = f.TxPostsRemoveReaction(post.PostID.String(), ":thumbsup:", fooAddr, "-y")
require.True(t, success)
require.Empty(t, sterr)
tests.WaitForNextNBlocksTM(1, f.Port)

// Make sure the reaction has been removed
storedPost = f.QueryPost(1)
storedPost = f.QueryPost(post.PostID.String())
require.Empty(t, storedPost.Reactions)

// Test --dry-run
success, _, _ = f.TxPostsRemoveReaction(1, ":blush:", fooAddr, "--dry-run")
success, _, _ = f.TxPostsRemoveReaction(post.PostID.String(), ":blush:", fooAddr, "--dry-run")
require.True(t, success)

// Test --generate-only
success, stdout, stderr = f.TxPostsRemoveReaction(1, ":thumbsdown:", fooAddr, "--generate-only=true")
success, stdout, stderr = f.TxPostsRemoveReaction(post.PostID.String(), ":thumbsdown:", fooAddr, "--generate-only=true")
require.Empty(t, stderr)
require.True(t, success)
msg = unmarshalStdTx(f.T, stdout)
Expand All @@ -574,7 +595,7 @@ func TestDesmosCLIPostsReactions(t *testing.T) {
require.Len(t, msg.GetSignatures(), 0)

// Check state didn't change
storedPost = f.QueryPost(1)
storedPost = f.QueryPost(post.PostID.String())
require.Empty(t, storedPost.Reactions)

f.Cleanup()
Expand Down
16 changes: 8 additions & 8 deletions cli_test/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,22 +428,22 @@ func (f *Fixtures) TxPostsAnswerPoll(pollID posts.PostID, answers []posts.Answer
}

// TxPostsEdit is desmoscli tx posts edit
func (f *Fixtures) TxPostsEdit(id int, message string, from sdk.AccAddress, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf(`%s tx posts edit %d %s --keyring-backend=test --from=%s %v`,
func (f *Fixtures) TxPostsEdit(id string, message string, from sdk.AccAddress, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf(`%s tx posts edit %s %s --keyring-backend=test --from=%s %v`,
f.DesmosliBinary, id, message, from, f.Flags())
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}

// TxPostsAddReaction is desmoscli tx posts add-reaction
func (f *Fixtures) TxPostsAddReaction(id int, reaction string, from sdk.AccAddress, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf(`%s tx posts add-reaction %d %s --keyring-backend=test --from=%s %v`,
func (f *Fixtures) TxPostsAddReaction(id string, reaction string, from sdk.AccAddress, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf(`%s tx posts add-reaction %s %s --keyring-backend=test --from=%s %v`,
f.DesmosliBinary, id, reaction, from, f.Flags())
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}

// TxPostsRemoveReaction is desmoscli tx posts remove-reaction
func (f *Fixtures) TxPostsRemoveReaction(id int, reaction string, from sdk.AccAddress, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf(`%s tx posts remove-reaction %d %s --keyring-backend=test --from=%s %v`,
func (f *Fixtures) TxPostsRemoveReaction(id string, reaction string, from sdk.AccAddress, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf(`%s tx posts remove-reaction %s %s --keyring-backend=test --from=%s %v`,
f.DesmosliBinary, id, reaction, from, f.Flags())
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}
Expand Down Expand Up @@ -763,8 +763,8 @@ func (f *Fixtures) QueryPosts(flags ...string) posts.Posts {
}

// QueryPost returns a specific stored post
func (f *Fixtures) QueryPost(id int, flags ...string) posts.PostQueryResponse {
cmd := fmt.Sprintf("%s query posts post %d --output=json %s", f.DesmosliBinary, id, f.Flags())
func (f *Fixtures) QueryPost(id string, flags ...string) posts.PostQueryResponse {
cmd := fmt.Sprintf("%s query posts post %s --output=json %s", f.DesmosliBinary, id, f.Flags())
res, errStr := tests.ExecuteT(f.T, addFlags(cmd, flags), "")
require.Empty(f.T, errStr)
cdc := app.MakeCodec()
Expand Down
2 changes: 1 addition & 1 deletion docs/developers/msgs/add-post-reaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This message allows you to add a reaction to a post that is already existing on
"value": {
"value": "like",
"liker": "desmos1w3fe8zq5jrxd4nz49hllg75sw7m24qyc7tnaax",
"post_id": "12"
"post_id": "a4469741bb0c0622627810082a5f2e4e54fbbb888f25a4771a5eebc697d30cfc"
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion docs/developers/msgs/answer-poll.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This message allows you to answer to a post's poll.
{
"type": "desmos/MsgAnswerPoll",
"value": {
"post_id": "1",
"post_id": "a4469741bb0c0622627810082a5f2e4e54fbbb888f25a4771a5eebc697d30cfc",
"answers": [
"1",
"2"
Expand Down
4 changes: 2 additions & 2 deletions docs/developers/msgs/create-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ This message allows you to create a new public post. If you want to know more ab
{
"type": "desmos/MsgCreatePost",
"value": {
"parent_id": "0",
"parent_id": "",
"message": "Desmos is great!",
"allows_comments": true,
"subspace": "4e188d9c17150037d5199bbdb91ae1eb2a78a15aca04cb35530cccb81494b36e",
Expand Down Expand Up @@ -87,7 +87,7 @@ This message allows you to create a new public post. If you want to know more ab
{
"type": "desmos/MsgCreatePost",
"value": {
"parent_id": "0",
"parent_id": "",
"message": "Desmos is great!",
"allows_comments": true,
"subspace": "4e188d9c17150037d5199bbdb91ae1eb2a78a15aca04cb35530cccb81494b36e",
Expand Down
2 changes: 1 addition & 1 deletion docs/developers/msgs/edit-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This message allows you to edit the message of a previously published public pos
{
"type": "desmos/MsgEditPost",
"value": {
"post_id": "1",
"post_id": "a4469741bb0c0622627810082a5f2e4e54fbbb888f25a4771a5eebc697d30cfc",
"message": "Desmos you rock!",
"editor": "desmos1w3fe8zq5jrxd4nz49hllg75sw7m24qyc7tnaax",
"edit_date": "2020-02-05T01:00:00"
Expand Down
2 changes: 1 addition & 1 deletion docs/developers/msgs/remove-post-reaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ With this message you can remove a reaction from a post you have previously reac
"value": {
"value": "like",
"liker": "desmos1w3fe8zq5jrxd4nz49hllg75sw7m24qyc7tnaax",
"post_id": "12"
"post_id": "a4469741bb0c0622627810082a5f2e4e54fbbb888f25a4771a5eebc697d30cfc"
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions docs/developers/queries/poll-answers.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ This query endpoint allows you to retrieve the details of answers made to a post
desmoscli query posts poll-answers [id]

# Example
# desmoscli query posts poll-answers 1
# desmoscli query posts poll-answers a4469741bb0c0622627810082a5f2e4e54fbbb888f25a4771a5eebc697d30cfc
```

**REST**
```
/posts/{postId}/poll-answers

# Example
# curl https://morpheus1000.desmos.network/posts/10/poll-answers
# curl https://morpheus4000.desmos.network/posts/10/poll-answers
RiccardoM marked this conversation as resolved.
Show resolved Hide resolved
```
4 changes: 2 additions & 2 deletions docs/developers/queries/post.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ This query endpoint allows you to retrieve the details of a single post having i
desmoscli query posts post [id]

# Example
# desmoscli query posts post 12
# desmoscli query posts post a4469741bb0c0622627810082a5f2e4e54fbbb888f25a4771a5eebc697d30cfc
```

**REST**
```
/posts/{postId}

# Example
# curl https://morpheus1000.desmos.network/posts/10
# curl https://morpheus4000.desmos.network/posts/a4469741bb0c0622627810082a5f2e4e54fbbb888f25a4771a5eebc697d30cfc
RiccardoM marked this conversation as resolved.
Show resolved Hide resolved
```
8 changes: 4 additions & 4 deletions docs/developers/queries/posts.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ desmoscli query posts [--flags]
```

Available flags:
- `--parent-id` (e.g. `--parent-id=5`)
- `--parent-id` (e.g. `--parent-id=a4469741bb0c0622627810082a5f2e4e54fbbb888f25a4771a5eebc697d30cfc`)
- `--creation-time` (e.g. `--creation-time=2020-01-01T12:00:00`)
- `--allows-comments` (e.g. `--allows-comments=true`)
- `--subspace` (e.g. `--subspace=desmos`)
Expand All @@ -23,7 +23,7 @@ Available flags:

```bash
# Example
# desmoscli query posts --parent-id=1 --allows-comments=true --subspace=desmos --sort=created --sort-order=descending
# desmoscli query posts --parent-id=a4469741bb0c0622627810082a5f2e4e54fbbb888f25a4771a5eebc697d30cfc --allows-comments=true --subspace=desmos --sort=created --sort-order=descending
```

**REST**
Expand All @@ -32,7 +32,7 @@ Available flags:
```

Available parameters:
- `parent_id` (e.g. `parent_id=5`)
- `parent_id` (e.g. `parent_id=a4469741bb0c0622627810082a5f2e4e54fbbb888f25a4771a5eebc697d30cfc`)
- `creation_time` (e.g. `creation_time=2020-01-01T12:00:00`)
- `allows_comments` (e.g. `allows_comments=true`)
- `subspace` (e.g. `subspace=desmos`)
Expand All @@ -42,5 +42,5 @@ Available parameters:

```bash
# Example
# curl https://morpheus1000.desmos.network/posts?parent_id=1&allows_comments=true&subspace=desmos&sort_by=created&sort_order=descending
# curl https://morpheus4000.desmos.network/posts?parent_id=a4469741bb0c0622627810082a5f2e4e54fbbb888f25a4771a5eebc697d30cfc&allows_comments=true&subspace=desmos&sort_by=created&sort_order=descending
RiccardoM marked this conversation as resolved.
Show resolved Hide resolved
```
Loading