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

Refuse and Cancel features for DTag #305

Merged
merged 21 commits into from
Oct 21, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Removed the user_block event attribute key prefix (#291)
- Changed posts' optional data representation (#272)
- Fixed bugs inside the DTag transfer process (#295, #296)
- Implemented the possibility to refuse and cancel DTag requests from both receiver and sender side (#297)

## Bug fixes
- Fixed the possibility of requesting a transfer of an empty DTag (#292)
Expand Down
2 changes: 2 additions & 0 deletions app/params/weights.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const (
DefaultWeightMsgDeleteProfile int = 100
DefaultWeightMsgRequestDTagTransfer int = 100
DefaultWeightMsgAcceptDTagTransfer int = 100
DefaultWeightMsgRefuseDTagTransfer int = 100
DefaultWeightMsgCancelDTagTransfer int = 100
DefaultWeightMsgReportPost int = 100
DefaultWeightMsgCreateRelationship int = 100
DefaultWeightMsgDeleteRelationship int = 100
Expand Down
10 changes: 5 additions & 5 deletions cli_test/cli_posts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,8 @@ func TestDesmosCLIPostsReactions(t *testing.T) {
subspace := "4e188d9c17150037d5199bbdb91ae1eb2a78a15aca04cb35530cccb81494b36e"
reactions := types.Reactions{
types.Reaction{":earth:", "http://earth.jpg", subspace, fooAddr},
types.Reaction{":blush:", "https://gph.is/2p19Zai", subspace, fooAddr},
types.Reaction{":thumbsdown:", "https://gph.is/2phybnt", subspace, fooAddr},
types.Reaction{":plot:", "https://gph.is/2p19Zai", subspace, fooAddr},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we revert all the changes that were made to this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes I made were to fix some errors inside tests to exclude them from the possible causes that make the whole suite fail, should I revert them anyway?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bragaz Yes please, they were part of tests that have always been passing so I don't think they consitute any problem

types.Reaction{":loot:", "https://gph.is/2phybnt", subspace, fooAddr},
}

// Create a post
Expand Down Expand Up @@ -746,11 +746,11 @@ func TestDesmosCLIPostsReactions(t *testing.T) {
require.Equal(t, types.NewPostReaction(":+1:", "👍", fooAddr), storedPost.Reactions[0])

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

// Test --generate-only
success, stdout, stderr := f.TxPostsAddReaction(post.PostID.String(), ":thumbsdown:", fooAddr, "--generate-only=true")
success, stdout, stderr := f.TxPostsAddReaction(post.PostID.String(), ":loot:", fooAddr, "--generate-only=true")
require.Empty(t, stderr)
require.True(t, success)
msg := unmarshalStdTx(f.T, stdout)
Expand All @@ -772,7 +772,7 @@ func TestDesmosCLIPostsReactions(t *testing.T) {
require.True(t, success)

// Test --generate-only
success, stdout, stderr = f.TxPostsRemoveReaction(post.PostID.String(), ":thumbsdown:", fooAddr, "--generate-only=true")
success, stdout, stderr = f.TxPostsRemoveReaction(post.PostID.String(), ":loot:", fooAddr, "--generate-only=true")
require.Empty(t, stderr)
require.True(t, success)
msg = unmarshalStdTx(f.T, stdout)
Expand Down
172 changes: 154 additions & 18 deletions cli_test/cli_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,11 +501,10 @@ func TestDesmosCLIMultipleDTagTransferRequest_receiverWithNoProfile(t *testing.T
require.Empty(t, receiverRequests)

// Make sure that the DTag has been transferred properly and the profile for receiver created
storedProfiles = f.QueryProfiles()
require.NotEmpty(t, storedProfiles)
profile = storedProfiles[0]
require.Equal(t, profile.DTag, "mrPink")
receiverProfile := storedProfiles[1]
fooProfile := f.QueryProfile(fooAddr)
require.NotNil(t, fooProfile)
require.Equal(t, fooProfile.DTag, "mrPink")
receiverProfile := f.QueryProfile(barAddr)
require.Equal(t, receiverProfile.DTag, "mrBrown")

// Create another request
Expand Down Expand Up @@ -542,10 +541,9 @@ func TestDesmosCLIMultipleDTagTransferRequest_receiverWithProfile(t *testing.T)
tests.WaitForNextNBlocksTM(1, f.Port)

// Make sure the profile is saved and the DTag isn't empty
storedProfiles := f.QueryProfiles()
require.NotEmpty(t, storedProfiles)
profile := storedProfiles[0]
require.Equal(t, profile.DTag, "mrBrown")
fooProfile := f.QueryProfile(fooAddr)
require.NotEmpty(t, fooProfile)
require.Equal(t, fooProfile.DTag, "mrBrown")

// Create a profile for the DTag receiver
success, _, sterr = f.TxProfileSave("mrOrange", barAddr, "-y")
Expand All @@ -554,10 +552,9 @@ func TestDesmosCLIMultipleDTagTransferRequest_receiverWithProfile(t *testing.T)
tests.WaitForNextNBlocksTM(1, f.Port)

// Make sure the profile is saved and the DTag isn't empty
storedProfiles = f.QueryProfiles()
require.NotEmpty(t, storedProfiles)
profile = storedProfiles[1]
require.Equal(t, profile.DTag, "mrOrange")
barProfile := f.QueryProfile(barAddr)
require.NotEmpty(t, barProfile)
require.Equal(t, barProfile.DTag, "mrOrange")

// Create a request from a user without a profile
success, _, sterr = f.TxProfileRequestDTagTransfer(fooAddr, barAddr, "-y")
Expand All @@ -583,11 +580,10 @@ func TestDesmosCLIMultipleDTagTransferRequest_receiverWithProfile(t *testing.T)
require.Empty(t, receiverRequests)

// Make sure that the DTag has been transferred properly and the profile for receiver created
storedProfiles = f.QueryProfiles()
require.NotEmpty(t, storedProfiles)
profile = storedProfiles[0]
require.Equal(t, profile.DTag, "mrPink")
receiverProfile := storedProfiles[1]
fooProfile = f.QueryProfile(fooAddr)
require.NotEmpty(t, fooProfile)
require.Equal(t, fooProfile.DTag, "mrPink")
receiverProfile := f.QueryProfile(barAddr)
require.Equal(t, receiverProfile.DTag, "mrBrown")

// Create another request
Expand All @@ -603,3 +599,143 @@ func TestDesmosCLIMultipleDTagTransferRequest_receiverWithProfile(t *testing.T)

f.Cleanup()
}

func TestDesmosCLIRefuseDTagTransfer(t *testing.T) {
t.Parallel()
f := InitFixtures(t)

// Start Desmosd server
proc := f.GDStart()
defer proc.Stop(false)

// Save key addresses for later use
fooAddr := f.KeyAddress(keyFoo)
barAddr := f.KeyAddress(keyBar)
calAddr := f.KeyAddress(keyBaz)
f.TxSend(fooAddr.String(), barAddr, sdk.NewCoin(denom, sdk.NewInt(1000)), "-y")
f.TxSend(fooAddr.String(), calAddr, sdk.NewCoin(denom, sdk.NewInt(1000)), "-y")

// Create the profile of the DTag owner
success, _, sterr := f.TxProfileSave("mrBrown", fooAddr, "-y")
require.True(t, success)
require.Empty(t, sterr)
tests.WaitForNextNBlocksTM(1, f.Port)

// Make sure the profile is saved
storedProfiles := f.QueryProfiles()
require.NotEmpty(t, storedProfiles)
profile := storedProfiles[0]
require.Equal(t, profile.DTag, "mrBrown")

// Create a request
success, _, sterr = f.TxProfileRequestDTagTransfer(fooAddr, barAddr, "-y")
require.True(t, success)
require.Empty(t, sterr)
tests.WaitForNextNBlocksTM(1, f.Port)

// Make sure the request is saved
storedRequests := f.QueryUserDTagRequests(fooAddr)
require.NotEmpty(t, storedRequests)

// Refuse the request
success, _, sterr = f.TxProfileRefuseDTagTransfer(barAddr, fooAddr, "-y")
require.True(t, success)
require.Empty(t, sterr)
tests.WaitForNextNBlocksTM(1, f.Port)

// Test --dry-run

// Create the profile of the dTag owner
success, _, sterr = f.TxProfileSave("mrPink", calAddr, "-y")
require.True(t, success)
require.Empty(t, sterr)
tests.WaitForNextNBlocksTM(1, f.Port)

success, _, _ = f.TxProfileRequestDTagTransfer(calAddr, fooAddr, "-y")
require.True(t, success)
tests.WaitForNextNBlocksTM(1, f.Port)

success, _, sterr = f.TxProfileRefuseDTagTransfer(fooAddr, calAddr, "--dry-run")
require.True(t, success)

// Test --generate-only
success, stdout, stderr := f.TxProfileRefuseDTagTransfer(calAddr, fooAddr, "--generate-only=true")
require.Empty(t, stderr)
require.True(t, success)
msg := unmarshalStdTx(f.T, stdout)
require.NotZero(t, msg.Fee.Gas)
require.Len(t, msg.Msgs, 1)
require.Len(t, msg.GetSignatures(), 0)

f.Cleanup()
}

func TestDesmosCLICancelDTagTransfer(t *testing.T) {
t.Parallel()
f := InitFixtures(t)

// Start Desmosd server
proc := f.GDStart()
defer proc.Stop(false)

// Save key addresses for later use
fooAddr := f.KeyAddress(keyFoo)
barAddr := f.KeyAddress(keyBar)
calAddr := f.KeyAddress(keyBaz)
f.TxSend(fooAddr.String(), barAddr, sdk.NewCoin(denom, sdk.NewInt(1000)), "-y")
f.TxSend(fooAddr.String(), calAddr, sdk.NewCoin(denom, sdk.NewInt(1000)), "-y")

// Create the profile of the DTag owner
success, _, sterr := f.TxProfileSave("mrBrown", fooAddr, "-y")
require.True(t, success)
require.Empty(t, sterr)
tests.WaitForNextNBlocksTM(1, f.Port)

// Make sure the profile is saved
storedProfiles := f.QueryProfiles()
require.NotEmpty(t, storedProfiles)
profile := storedProfiles[0]
require.Equal(t, profile.DTag, "mrBrown")

// Create a request
success, _, sterr = f.TxProfileRequestDTagTransfer(fooAddr, barAddr, "-y")
require.True(t, success)
require.Empty(t, sterr)
tests.WaitForNextNBlocksTM(1, f.Port)

// Make sure the request is saved
storedRequests := f.QueryUserDTagRequests(fooAddr)
require.NotEmpty(t, storedRequests)

// Refuse the request
success, _, sterr = f.TxProfileCancelDTagTransfer(fooAddr, barAddr, "-y")
require.True(t, success)
require.Empty(t, sterr)
tests.WaitForNextNBlocksTM(1, f.Port)

// Test --dry-run

// Create the profile of the dTag owner
success, _, sterr = f.TxProfileSave("mrPink", calAddr, "-y")
require.True(t, success)
require.Empty(t, sterr)
tests.WaitForNextNBlocksTM(1, f.Port)

success, _, _ = f.TxProfileRequestDTagTransfer(calAddr, fooAddr, "-y")
require.True(t, success)
tests.WaitForNextNBlocksTM(1, f.Port)

success, _, sterr = f.TxProfileCancelDTagTransfer(calAddr, fooAddr, "--dry-run")
require.True(t, success)

// Test --generate-only
success, stdout, stderr := f.TxProfileRefuseDTagTransfer(calAddr, fooAddr, "--generate-only=true")
require.Empty(t, stderr)
require.True(t, success)
msg := unmarshalStdTx(f.T, stdout)
require.NotZero(t, msg.Fee.Gas)
require.Len(t, msg.Msgs, 1)
require.Len(t, msg.GetSignatures(), 0)

f.Cleanup()
}
25 changes: 25 additions & 0 deletions cli_test/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,18 @@ func (f *Fixtures) TxProfileAcceptDTagTransfer(newDtag string, receiver, from sd
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}

func (f *Fixtures) TxProfileRefuseDTagTransfer(sender, from sdk.AccAddress, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf(`%s tx profiles refuse-dtag-transfer %s --keyring-backend=test --from=%s %v`,
f.DesmoscliBinary, sender, from, f.Flags())
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}

func (f *Fixtures) TxProfileCancelDTagTransfer(owner, from sdk.AccAddress, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf(`%s tx profiles cancel-dtag-transfer %s --keyring-backend=test --from=%s %v`,
f.DesmoscliBinary, owner, from, f.Flags())
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}

//___________________________________________________________________________________
// desmoscli tx relationships
func (f *Fixtures) TxCreateRelationship(receiver sdk.AccAddress, subspace string, from sdk.AccAddress, flags ...string) (bool, string, string) {
Expand Down Expand Up @@ -841,6 +853,19 @@ func (f *Fixtures) QueryProfiles(flags ...string) profilesTypes.Profiles {
return storedProfile
}

// QueryProfile returns stored profile
func (f *Fixtures) QueryProfile(address sdk.AccAddress, flags ...string) profilesTypes.Profile {
cmd := fmt.Sprintf("%s query profiles profile %s --output=json %s",
f.DesmoscliBinary, address, f.Flags())
res, errStr := tests.ExecuteT(f.T, addFlags(cmd, flags), "")
require.Empty(f.T, errStr)
cdc := app.MakeCodec()
var storedProfile profilesTypes.Profile
err := cdc.UnmarshalJSON([]byte(res), &storedProfile)
require.NoError(f.T, err)
return storedProfile
}

// QueryUserDTagRequests returns the user's stored requests
func (f *Fixtures) QueryUserDTagRequests(user sdk.AccAddress, flags ...string) []profilesTypes.DTagTransferRequest {
cmd := fmt.Sprintf("%s query profiles dtag-requests %s --output=json %s",
Expand Down
20 changes: 10 additions & 10 deletions docs/developers/msgs/profiles/accept-dtag-transfer-request.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# `MsgAcceptDTagTransfer`
This message allows you to accept a `DTag`'s transfer request.
# `MsgAcceptDTagTransferRequest`
This message allows you to accept a `DTag` transfer request.

## Structure
````json
{
"type": "desmos/MsgAcceptDTagTransfer",
"type": "desmos/MsgAcceptDTagTransferRequest",
"value": {
"new_dtag": "<The new DTag for the current owner's profile>",
"current_owner": "<Desmos address of the DTag owner>",
"receiving_user": "<Desmos address that's making the DTag's request>"
"receiver": "<Desmos address of the DTag owner>",
"sender": "<Desmos address that's making the DTag's request>"
}
}
````
Expand All @@ -17,17 +17,17 @@ This message allows you to accept a `DTag`'s transfer request.
| Attribute | Type | Description |
| :-------: | :----: | :-------- |
| `new_dtag` | String | The new `DTag` for the current owner profile that will replace the traded one |
| `current_owner` | String | Desmos address of the user that is the owner of the requested `DTag` |
| `receiving_user`| String | Desmos address of the user that request the `DTag` |
| `receiver` | String | Desmos address of the user that is the owner of the requested `DTag` |
| `sender`| String | Desmos address of the user that request the `DTag` |

## Example
````json
{
"type": "desmos/MsgAcceptDTagTransfer",
"type": "desmos/MsgAcceptDTagTransferRequest",
"value": {
"new_dtag": "newDTag",
"current_owner": "desmos1k99c8htyk32srx78efzg7sxm965prtz0j9qrc7",
"receiving_user": "desmos1nhgk008jvrxwa9tufr9tcr6zfrhe2uz0v90r2a"
"receiver": "desmos1k99c8htyk32srx78efzg7sxm965prtz0j9qrc7",
"sender": "desmos1nhgk008jvrxwa9tufr9tcr6zfrhe2uz0v90r2a"
}
}
````
Expand Down
37 changes: 37 additions & 0 deletions docs/developers/msgs/profiles/cancel-dtag-transfer-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# `MsgCancelDTagTransferRequest`
This message allows you to cancel a `DTag` transfer request made by yourself.

## Structure
````json
{
"type": "desmos/MsgCancelDTagTransferRequest",
"value": {
"sender": "<Desmos address that sent the DTag's request>",
"receiver": "<Desmos address of the DTag owner>"
}
}
````

### Attributes
| Attribute | Type | Description |
| :-------: | :----: | :-------- |
| `sender`| String | Desmos address of the user that request the `DTag` |
| `receiver` | String | Desmos address of the user that is the owner of the requested `DTag` |

## Example
````json
{
"type": "desmos/MsgCancelDTagTransferRequest",
"value": {
"sender": "desmos1nhgk008jvrxwa9tufr9tcr6zfrhe2uz0v90r2a",
"receiver": "desmos1k99c8htyk32srx78efzg7sxm965prtz0j9qrc7"
}
}
````

## Message action
The action associated to this message is the following:

```
cancel_dtag_request
```
Loading