Skip to content

Commit

Permalink
Updated profiles' create and edit
Browse files Browse the repository at this point in the history
See PR #180
  • Loading branch information
leobragaz committed May 25, 2020
1 parent 3f849c5 commit c87d64d
Show file tree
Hide file tree
Showing 32 changed files with 372 additions and 1,140 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@
# Version 0.6.1
## Changes
- Updated Cosmos to v0.38.4 (#177)
- Updated the way with which the profiles are created and edited (#170)

## Bug fixes
- Fixed the on-chain events usage (#175)
Expand Down
3 changes: 1 addition & 2 deletions app/params/weights.go
Expand Up @@ -8,7 +8,6 @@ const (
DefaultWeightMsgRemoveReaction int = 100
DefaultWeightMsgAnswerPoll int = 100
DefaultWeightMsgRegisterReaction int = 100
DefaultWeightMsgCreateAccount int = 100
DefaultWeightMsgEditAccount int = 100
DefaultWeightMsgSaveAccount int = 100
DefaultWeightMsgDeleteAccount int = 100
)
44 changes: 27 additions & 17 deletions cli_test/cli_profile_test.go
Expand Up @@ -28,7 +28,8 @@ func TestDesmosCLIProfileCreate_noFlags(t *testing.T) {
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))

// Create a profile
success, _, sterr := f.TxProfileCreate(moniker, fooAddr, "-y")
success, _, sterr := f.TxProfileSave(fooAddr, "-y",
"--moniker mrBrown")
require.True(t, success)
require.Empty(t, sterr)
tests.WaitForNextNBlocksTM(1, f.Port)
Expand All @@ -40,11 +41,13 @@ func TestDesmosCLIProfileCreate_noFlags(t *testing.T) {
require.Equal(t, profile.Moniker, moniker)

// Test --dry-run
success, _, _ = f.TxProfileCreate(moniker, fooAddr, "--dry-run")
success, _, _ = f.TxProfileSave(fooAddr, "--dry-run",
"--moniker mrBrown")
require.True(t, success)

// Test --generate-only
success, stdout, stderr := f.TxProfileCreate(moniker, fooAddr, "--generate-only=true")
success, stdout, stderr := f.TxProfileSave(fooAddr, "--generate-only=true",
"--moniker mrBrown")
require.Empty(t, stderr)
require.True(t, success)
msg := unmarshalStdTx(f.T, stdout)
Expand Down Expand Up @@ -77,7 +80,8 @@ func TestDesmosCLIProfileCreate_withFlags(t *testing.T) {
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))

// Create a profile
success, _, sterr := f.TxProfileCreate(moniker, fooAddr, "-y",
success, _, sterr := f.TxProfileSave(fooAddr, "-y",
"--moniker mrBrown",
"--name Leonardo",
"--surname DiCaprio",
"--bio biography",
Expand All @@ -94,7 +98,8 @@ func TestDesmosCLIProfileCreate_withFlags(t *testing.T) {
require.Equal(t, profile.Moniker, moniker)

// Test --dry-run
success, _, _ = f.TxProfileCreate(moniker, fooAddr, "--dry-run",
success, _, _ = f.TxProfileSave(fooAddr, "--dry-run",
"--moniker mrBrown",
"--name Leonardo",
"--surname DiCaprio",
"--bio biography",
Expand All @@ -103,7 +108,8 @@ func TestDesmosCLIProfileCreate_withFlags(t *testing.T) {
require.True(t, success)

// Test --generate-only
success, stdout, stderr := f.TxProfileCreate(moniker, fooAddr, "--generate-only=true",
success, stdout, stderr := f.TxProfileSave(fooAddr, "--generate-only=true",
"--moniker mrBrown",
"--name Leonardo",
"--surname DiCaprio",
"--bio biography",
Expand Down Expand Up @@ -142,7 +148,8 @@ func TestDesmosCLIProfileEdit_noFlags(t *testing.T) {
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))

// Create an profile
success, _, sterr := f.TxProfileCreate(moniker, fooAddr, "-y",
success, _, sterr := f.TxProfileSave(fooAddr, "-y",
"--moniker mrBrown",
"--name Leonardo",
"--surname DiCaprio",
"--bio biography",
Expand All @@ -159,7 +166,7 @@ func TestDesmosCLIProfileEdit_noFlags(t *testing.T) {
require.Equal(t, profile.Moniker, moniker)

// Edit the profile
success, _, sterr = f.TxProfileEdit(fooAddr, "-y",
success, _, sterr = f.TxProfileSave(fooAddr, "-y",
"--moniker mrPink")
require.True(t, success)
require.Empty(t, sterr)
Expand All @@ -172,16 +179,17 @@ func TestDesmosCLIProfileEdit_noFlags(t *testing.T) {
require.Equal(t, editedProfile.Moniker, newMoniker)

//Make sure the profile has been edited
require.Equal(t, storedProfiles[0].Name, editedProfiles[0].Name)
require.Equal(t, storedProfiles[0].Surname, editedProfiles[0].Surname)
var emptyField *string
require.Equal(t, emptyField, editedProfiles[0].Name)
require.Equal(t, emptyField, editedProfiles[0].Surname)

// Test --dry-run
success, _, _ = f.TxProfileEdit(fooAddr, "--dry-run",
success, _, _ = f.TxProfileSave(fooAddr, "--dry-run",
"--moniker mrPink")
require.True(t, success)

// Test --generate-only
success, stdout, stderr := f.TxProfileEdit(fooAddr, "--generate-only=true",
success, stdout, stderr := f.TxProfileSave(fooAddr, "--generate-only=true",
"--moniker mrPink")
require.Empty(t, stderr)
require.True(t, success)
Expand Down Expand Up @@ -216,7 +224,8 @@ func TestDesmosCLIProfileEdit_withFlags(t *testing.T) {
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))

// Create an profile
success, _, sterr := f.TxProfileCreate(moniker, fooAddr, "-y",
success, _, sterr := f.TxProfileSave(fooAddr, "-y",
"--moniker mrBrown",
"--name Leonardo",
"--surname DiCaprio",
"--bio biography",
Expand All @@ -233,7 +242,7 @@ func TestDesmosCLIProfileEdit_withFlags(t *testing.T) {
require.Equal(t, profile.Moniker, moniker)

// Edit the profile
success, _, sterr = f.TxProfileEdit(fooAddr, "-y",
success, _, sterr = f.TxProfileSave(fooAddr, "-y",
"--moniker mrPink",
"--name Leo",
"--surname DiCap",
Expand All @@ -255,7 +264,7 @@ func TestDesmosCLIProfileEdit_withFlags(t *testing.T) {
require.NotEqual(t, storedProfiles[0].Surname, editedProfiles[0].Surname)

// Test --dry-run
success, _, _ = f.TxProfileEdit(fooAddr, "--dry-run",
success, _, _ = f.TxProfileSave(fooAddr, "--dry-run",
"--moniker mrPink",
"--name Leo",
"--surname DiCap",
Expand All @@ -265,7 +274,7 @@ func TestDesmosCLIProfileEdit_withFlags(t *testing.T) {
require.True(t, success)

// Test --generate-only
success, stdout, stderr := f.TxProfileEdit(fooAddr, "--generate-only=true",
success, stdout, stderr := f.TxProfileSave(fooAddr, "--generate-only=true",
"--moniker mrPink",
"--name Leo",
"--surname DiCap",
Expand Down Expand Up @@ -304,7 +313,8 @@ func TestDesmosCLIProfileDelete(t *testing.T) {
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(denom))

// Create an profile
success, _, sterr := f.TxProfileCreate(moniker, fooAddr, "-y")
success, _, sterr := f.TxProfileSave(fooAddr, "-y",
"--moniker mrBrown")
require.True(t, success)
require.Empty(t, sterr)
tests.WaitForNextNBlocksTM(1, f.Port)
Expand Down
10 changes: 2 additions & 8 deletions cli_test/test_helpers.go
Expand Up @@ -457,14 +457,8 @@ func (f *Fixtures) TxPostsRegisterReaction(shortCode, value, subspace string, fr

//___________________________________________________________________________________
// desmoscli tx profile
func (f *Fixtures) TxProfileCreate(moniker string, from sdk.AccAddress, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf(`%s tx profiles create %s --keyring-backend=test --from=%s %v`,
f.DesmosliBinary, moniker, from, f.Flags())
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}

func (f *Fixtures) TxProfileEdit(from sdk.AccAddress, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf(`%s tx profiles edit --keyring-backend=test --from=%s %v`,
func (f *Fixtures) TxProfileSave(from sdk.AccAddress, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf(`%s tx profiles save --keyring-backend=test --from=%s %v`,
f.DesmosliBinary, from, f.Flags())
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), clientkeys.DefaultKeyPass)
}
Expand Down
56 changes: 0 additions & 56 deletions docs/developers/msgs/create-profile.md

This file was deleted.

@@ -1,12 +1,12 @@
# `MsgEditProfile`
This message allows you to edit a previously created profile.
# `MsgSaveProfile`
This message allows you to save a new profile or edit an existent one.

## Structure
````json
{
"type": "desmos/MsgEditProfile",
"type": "desmos/MsgSaveProfile",
"value": {
"new_moniker": "<Profile new moniker>",
"moniker": "<Profile moniker>",
"name": "<Profile name>",
"surname": "<Profile surname>",
"bio": "<Profile biography>",
Expand All @@ -22,22 +22,21 @@ This message allows you to edit a previously created profile.
### Attributes
| Attribute | Type | Description |
| :-------: | :----: | :-------- |
| `new_moniker` | String | (Optional) New moniker of the user's profile |
| `moniker` | String | Moniker of the user's profile |
| `name` | String | (Optional) Name of the user |
| `surname` | String | (Optional) Surname of the user |
| `bio` | String | (Optional) Biography of the user |
| `pictures` | Object | (Optional) Object containing all the information related to the profile's pictures |
| `creator` | String | Desmos address of the user that is editing the profile |

All the attributes will not accept the string `default` as a value because it's reserved for internal operations.

If you are editing an existing profile you should fill all the existent fields otherwise they will be set as nil.

## Example
````json
{
"type": "desmos/MsgEditProfile",
"type": "desmos/MsgSaveProfile",
"value": {
"new_moniker": "Eva00",
"moniker": "Eva00",
"name": "Rei",
"surname": "Ayanami",
"bio": "evaPilot",
Expand All @@ -54,6 +53,6 @@ All the attributes will not accept the string `default` as a value because it's
The action associated to this message is the following:

```
edit_profile
save_profile
```

3 changes: 1 addition & 2 deletions docs/developers/perform-transactions.md
Expand Up @@ -17,6 +17,5 @@ Here is the list of currently available [messages](developer-faq.md#what-is-a-me
* [`MsgRegisterReaction`](msgs/register-reaction.md): allows you to register a reaction.

### Profile
* [`MsgCreateProfile`](msgs/create-profile.md): allows you to create a new profile for a user.
* [`MsgEditProfile`](msgs/edit-profile.md): allows you to edit an existing profile.
* [`MsgSaveProfile`](docs/developers/msgs/save-profile.md): allows you to create or edit an existing profile.
* [`MsgDeleteProfile`](msgs/delete-profile.md): allows you to delete an existing profile.
36 changes: 17 additions & 19 deletions x/magpie/alias.go
Expand Up @@ -13,53 +13,51 @@ import (
const (
QuerySessions = keeper.QuerySessions
OpWeightMsgCreatePost = simulation.OpWeightMsgCreatePost
ModuleName = types.ModuleName
RouterKey = types.RouterKey
StoreKey = types.StoreKey
ActionCreationSession = types.ActionCreationSession
EventTypeCreateSession = types.EventTypeCreateSession
AttributeKeySessionID = types.AttributeKeySessionID
AttributeKeyNamespace = types.AttributeKeyNamespace
AttributeKeyExternalOwner = types.AttributeKeyExternalOwner
AttributeKeyExpiry = types.AttributeKeyExpiry
AttributeValueCategory = types.AttributeValueCategory
ModuleName = types.ModuleName
RouterKey = types.RouterKey
StoreKey = types.StoreKey
ActionCreationSession = types.ActionCreationSession
)

var (
// functions aliases

NewHandler = keeper.NewHandler
NewKeeper = keeper.NewKeeper
NewQuerier = keeper.NewQuerier
DecodeStore = simulation.DecodeStore
RandomizedGenState = simulation.RandomizedGenState
NewHandler = keeper.NewHandler
RandomSessionData = simulation.RandomSessionData
WeightedOperations = simulation.WeightedOperations
SimulateMsgCreateSession = simulation.SimulateMsgCreateSession
RandomSessionData = simulation.RandomSessionData
RegisterCodec = types.RegisterCodec
RandomizedGenState = simulation.RandomizedGenState
DecodeStore = simulation.DecodeStore
SessionStoreKey = types.SessionStoreKey
ParseSessionID = types.ParseSessionID
NewSession = types.NewSession
NewGenesisState = types.NewGenesisState
DefaultGenesisState = types.DefaultGenesisState
ValidateGenesis = types.ValidateGenesis
SessionStoreKey = types.SessionStoreKey
RegisterCodec = types.RegisterCodec
NewMsgCreateSession = types.NewMsgCreateSession
ParseSessionID = types.ParseSessionID
NewSession = types.NewSession

// variable aliases

RandomNamespaces = simulation.RandomNamespaces
ModuleCdc = types.ModuleCdc
SessionLengthKey = types.SessionLengthKey
LastSessionIDStoreKey = types.LastSessionIDStoreKey
SessionStorePrefix = types.SessionStorePrefix
ModuleCdc = types.ModuleCdc
)

type (
Keeper = keeper.Keeper
SessionData = simulation.SessionData
GenesisState = types.GenesisState
MsgCreateSession = types.MsgCreateSession
SessionID = types.SessionID
Session = types.Session
Sessions = types.Sessions
GenesisState = types.GenesisState
MsgCreateSession = types.MsgCreateSession
Keeper = keeper.Keeper
SessionData = simulation.SessionData
)

0 comments on commit c87d64d

Please sign in to comment.