From 7d9618f8f92460ca581aca182755e4be28943599 Mon Sep 17 00:00:00 2001 From: "riccardo.montagnin" Date: Mon, 15 Mar 2021 14:00:00 +0100 Subject: [PATCH 01/11] Started the conversion of how profiles are stored Signed-off-by: riccardo.montagnin --- Makefile | 7 +- app/app.go | 1 + .../profiles/v1beta1/keeper/types.proto | 9 - proto/desmos/profiles/v1beta1/models.proto | 26 +- .../proto/cosmos/auth/v1beta1/auth.proto | 50 ++++ x/profiles/client/cli/cli_test.go | 12 +- x/profiles/keeper/alias_functions.go | 61 +++++ ...ctions_test.go => alias_functions_test.go} | 23 +- x/profiles/keeper/common_test.go | 70 +++-- x/profiles/keeper/grpc_query.go | 8 +- x/profiles/keeper/invariants.go | 2 +- x/profiles/keeper/invariants_test.go | 10 +- x/profiles/keeper/keeper.go | 121 +++----- x/profiles/keeper/keeper_test.go | 97 ++++--- x/profiles/keeper/msgs_server.go | 52 +++- x/profiles/keeper/msgs_server_test.go | 63 +++-- x/profiles/keeper/querier.go | 8 +- x/profiles/keeper/types.go | 5 - x/profiles/keeper/types.pb.go | 225 +-------------- x/profiles/keeper/utils_functions.go | 24 -- x/profiles/legacy/v0.15.0/types.go | 17 +- x/profiles/simulation/decoder.go | 12 - x/profiles/simulation/decoder_test.go | 31 +-- x/profiles/simulation/genesis.go | 22 +- .../simulation/operations_dtag_transfer.go | 14 +- x/profiles/simulation/operations_profile.go | 24 +- x/profiles/simulation/utils.go | 6 +- x/profiles/types/codec.go | 8 + x/profiles/types/genesis.go | 4 +- x/profiles/types/genesis_test.go | 23 +- x/profiles/types/keys.go | 12 - x/profiles/types/models.go | 32 ++- x/profiles/types/models.pb.go | 259 +++++++----------- x/profiles/types/models_test.go | 56 ++-- x/profiles/types/msgs_test.go | 13 +- 35 files changed, 663 insertions(+), 744 deletions(-) create mode 100644 third_party/proto/cosmos/auth/v1beta1/auth.proto create mode 100644 x/profiles/keeper/alias_functions.go rename x/profiles/keeper/{utils_functions_test.go => alias_functions_test.go} (61%) delete mode 100644 x/profiles/keeper/utils_functions.go diff --git a/Makefile b/Makefile index 54e54a85a2..8fb24f0096 100644 --- a/Makefile +++ b/Makefile @@ -295,9 +295,9 @@ proto-lint: proto-check-breaking: @$(DOCKER_BUF) check breaking --against $(HTTPS_GIT)#branch=master -TM_URL = https://raw.githubusercontent.com/tendermint/tendermint/v0.34.7/proto/tendermint +TM_URL = https://raw.githubusercontent.com/tendermint/tendermint/v0.34.8/proto/tendermint GOGO_PROTO_URL = https://raw.githubusercontent.com/regen-network/protobuf/cosmos -COSMOS_URL = https://raw.githubusercontent.com/cosmos/cosmos-sdk/v0.41.3/proto/cosmos +COSMOS_URL = https://raw.githubusercontent.com/cosmos/cosmos-sdk/v0.42.1/proto/cosmos COSMOS_PROTO_URL = https://raw.githubusercontent.com/regen-network/cosmos-proto/master CONFIO_URL = https://raw.githubusercontent.com/confio/ics23/v0.6.3 @@ -316,6 +316,9 @@ proto-update-deps: @mkdir -p $(COSMOS_TYPES)/base/query/v1beta1 @curl -sSL $(COSMOS_URL)/base/query/v1beta1/pagination.proto > $(COSMOS_TYPES)/base/query/v1beta1/pagination.proto + @mkdir -p $(COSMOS_TYPES)/auth/v1beta1 + @curl -sSL $(COSMOS_URL)/auth/v1beta1/auth.proto > $(COSMOS_TYPES)/auth/v1beta1/auth.proto + @mkdir -p $(GOGO_PROTO_TYPES) @curl -sSL $(GOGO_PROTO_URL)/gogoproto/gogo.proto > $(GOGO_PROTO_TYPES)/gogo.proto diff --git a/app/app.go b/app/app.go index 47af39095a..f898997cd8 100644 --- a/app/app.go +++ b/app/app.go @@ -316,6 +316,7 @@ func NewDesmosApp( keys[profilestypes.StoreKey], app.GetSubspace(profilestypes.ModuleName), app.RelationshipsKeeper, + app.AccountKeeper, ) app.ReportsKeeper = reportsKeeper.NewKeeper( app.appCodec, diff --git a/proto/desmos/profiles/v1beta1/keeper/types.proto b/proto/desmos/profiles/v1beta1/keeper/types.proto index 2535c39528..5b6a199a06 100644 --- a/proto/desmos/profiles/v1beta1/keeper/types.proto +++ b/proto/desmos/profiles/v1beta1/keeper/types.proto @@ -6,15 +6,6 @@ import "desmos/profiles/v1beta1/models.proto"; option go_package = "github.com/desmos-labs/desmos/x/profiles/keeper"; -// DTagOwner represents the owner of a specific DTag -message WrappedDTagOwner { - option (gogoproto.equal) = true; - option (gogoproto.goproto_stringer) = true; - - // Address of the user owning a Dtag - string address = 1; -} - // DtagRequests contains the DTag transfer requests made towards a user message WrappedDTagTransferRequests { option (gogoproto.equal) = true; diff --git a/proto/desmos/profiles/v1beta1/models.proto b/proto/desmos/profiles/v1beta1/models.proto index 2bdd32df46..25cf21a19c 100644 --- a/proto/desmos/profiles/v1beta1/models.proto +++ b/proto/desmos/profiles/v1beta1/models.proto @@ -3,6 +3,7 @@ package desmos.profiles.v1beta1; import "gogoproto/gogo.proto"; import "google/protobuf/timestamp.proto"; +import "cosmos/auth/v1beta1/auth.proto"; option go_package = "github.com/desmos-labs/desmos/x/profiles/types"; @@ -20,22 +21,17 @@ message Pictures { // Profile represents a generic first on Desmos, containing the information of a // single user message Profile { - option (gogoproto.equal) = true; - option (gogoproto.goproto_stringer) = true; - - string dtag = 1 [ (gogoproto.moretags) = "yaml:\"dtag\"" ]; - - string moniker = 2 [ (gogoproto.moretags) = "yaml:\"moniker\"" ]; - - string bio = 3 [ (gogoproto.moretags) = "yaml:\"bio\"" ]; - - Pictures pictures = 4 [ + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + + cosmos.auth.v1beta1.BaseAccount base_account = 1 [(gogoproto.embed) = true]; + string dtag = 2 [(gogoproto.moretags) = "yaml:\"dtag\""]; + string moniker = 3 [(gogoproto.moretags) = "yaml:\"moniker\""]; + string bio = 4 [(gogoproto.moretags) = "yaml:\"bio\""]; + Pictures pictures = 5 [ (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"pictures\"" ]; - - string creator = 5 [ (gogoproto.moretags) = "yaml:\"creator\"" ]; - google.protobuf.Timestamp creation_date = 6 [ (gogoproto.stdtime) = true, (gogoproto.moretags) = "yaml:\"creation_date\"", @@ -52,9 +48,7 @@ message DTagTransferRequest { option (gogoproto.goproto_stringer) = true; string dtag_to_trade = 1 [(gogoproto.moretags) = "yaml:\"dtag_to_trade\""]; - - string sender = 2 [ (gogoproto.moretags) = "yaml:\"sender\"" ]; - + string sender = 2 [(gogoproto.moretags) = "yaml:\"sender\""]; string receiver = 3 [ (gogoproto.moretags) = "yaml:\"receiver\"" ]; } diff --git a/third_party/proto/cosmos/auth/v1beta1/auth.proto b/third_party/proto/cosmos/auth/v1beta1/auth.proto new file mode 100644 index 0000000000..b988fd8dcf --- /dev/null +++ b/third_party/proto/cosmos/auth/v1beta1/auth.proto @@ -0,0 +1,50 @@ +syntax = "proto3"; +package cosmos.auth.v1beta1; + +import "cosmos_proto/cosmos.proto"; +import "gogoproto/gogo.proto"; +import "google/protobuf/any.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/x/auth/types"; + +// BaseAccount defines a base account type. It contains all the necessary fields +// for basic account functionality. Any custom account type should extend this +// type for additional functionality (e.g. vesting). +message BaseAccount { + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + option (gogoproto.equal) = false; + + option (cosmos_proto.implements_interface) = "AccountI"; + + string address = 1; + google.protobuf.Any pub_key = 2 + [(gogoproto.jsontag) = "public_key,omitempty", (gogoproto.moretags) = "yaml:\"public_key\""]; + uint64 account_number = 3 [(gogoproto.moretags) = "yaml:\"account_number\""]; + uint64 sequence = 4; +} + +// ModuleAccount defines an account for modules that holds coins on a pool. +message ModuleAccount { + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + option (cosmos_proto.implements_interface) = "ModuleAccountI"; + + BaseAccount base_account = 1 [(gogoproto.embed) = true, (gogoproto.moretags) = "yaml:\"base_account\""]; + string name = 2; + repeated string permissions = 3; +} + +// Params defines the parameters for the auth module. +message Params { + option (gogoproto.equal) = true; + option (gogoproto.goproto_stringer) = false; + + uint64 max_memo_characters = 1 [(gogoproto.moretags) = "yaml:\"max_memo_characters\""]; + uint64 tx_sig_limit = 2 [(gogoproto.moretags) = "yaml:\"tx_sig_limit\""]; + uint64 tx_size_cost_per_byte = 3 [(gogoproto.moretags) = "yaml:\"tx_size_cost_per_byte\""]; + uint64 sig_verify_cost_ed25519 = 4 + [(gogoproto.customname) = "SigVerifyCostED25519", (gogoproto.moretags) = "yaml:\"sig_verify_cost_ed25519\""]; + uint64 sig_verify_cost_secp256k1 = 5 + [(gogoproto.customname) = "SigVerifyCostSecp256k1", (gogoproto.moretags) = "yaml:\"sig_verify_cost_secp256k1\""]; +} diff --git a/x/profiles/client/cli/cli_test.go b/x/profiles/client/cli/cli_test.go index 34593a2c2d..c04de7b66a 100644 --- a/x/profiles/client/cli/cli_test.go +++ b/x/profiles/client/cli/cli_test.go @@ -7,6 +7,8 @@ import ( "testing" "time" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/client/flags" clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/cosmos/cosmos-sdk/testutil/network" @@ -41,6 +43,9 @@ func (s *IntegrationTestSuite) SetupSuite() { var profilesData types.GenesisState s.Require().NoError(cfg.Codec.UnmarshalJSON(genesisState[types.ModuleName], &profilesData)) + addr, err := sdk.AccAddressFromBech32("cosmos1ftkjv8njvkekk00ehwdfl5sst8zgdpenjfm4hs") + s.Require().NoError(err) + profilesData.Profiles = []types.Profile{ types.NewProfile( "dtag", @@ -48,7 +53,7 @@ func (s *IntegrationTestSuite) SetupSuite() { "bio", types.Pictures{}, time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), - "cosmos1ftkjv8njvkekk00ehwdfl5sst8zgdpenjfm4hs", + authtypes.NewBaseAccountWithAddress(addr), ), } profilesData.DtagTransferRequests = []types.DTagTransferRequest{ @@ -82,6 +87,9 @@ func (s *IntegrationTestSuite) TearDownSuite() { func (s *IntegrationTestSuite) TestCmdQueryProfile() { val := s.network.Validators[0] + addr, err := sdk.AccAddressFromBech32("cosmos1ftkjv8njvkekk00ehwdfl5sst8zgdpenjfm4hs") + s.Require().NoError(err) + testCases := []struct { name string args []string @@ -109,7 +117,7 @@ func (s *IntegrationTestSuite) TestCmdQueryProfile() { "bio", types.Pictures{}, time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), - "cosmos1ftkjv8njvkekk00ehwdfl5sst8zgdpenjfm4hs", + authtypes.NewBaseAccountWithAddress(addr), ), }, }, diff --git a/x/profiles/keeper/alias_functions.go b/x/profiles/keeper/alias_functions.go new file mode 100644 index 0000000000..be4786acd1 --- /dev/null +++ b/x/profiles/keeper/alias_functions.go @@ -0,0 +1,61 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + + "github.com/desmos-labs/desmos/x/profiles/types" +) + +// IterateProfiles iterates through the profiles set and performs the provided function +func (k Keeper) IterateProfiles(ctx sdk.Context, fn func(index int64, profile types.Profile) (stop bool)) { + i := int64(0) + k.ak.IterateAccounts(ctx, func(account authtypes.AccountI) (stop bool) { + profile, ok := account.(*types.Profile) + + stop = false + if ok { + stop = fn(i, *profile) + i++ + } + + return stop + }) +} + +func (k Keeper) GetProfiles(ctx sdk.Context) []types.Profile { + var profiles []types.Profile + k.IterateProfiles(ctx, func(_ int64, profile types.Profile) (stop bool) { + profiles = append(profiles, profile) + return false + }) + return profiles +} + +// GetDtagFromAddress returns the dtag associated with the given address or an empty string if no dtag exists +func (k Keeper) GetDtagFromAddress(ctx sdk.Context, addr string) (dtag string, err error) { + profile, found, err := k.GetProfile(ctx, addr) + if err != nil { + return "", err + } + + if !found { + return "", nil + } + + return profile.Dtag, nil +} + +// GetAddressFromDtag returns the address associated to the given dtag or an empty string if it does not exists +func (k Keeper) GetAddressFromDtag(ctx sdk.Context, dtag string) (addr string) { + var address = "" + k.IterateProfiles(ctx, func(_ int64, profile types.Profile) (stop bool) { + equals := profile.Dtag == dtag + if equals { + address = profile.BaseAccount.Address + } + + return equals + }) + return address +} diff --git a/x/profiles/keeper/utils_functions_test.go b/x/profiles/keeper/alias_functions_test.go similarity index 61% rename from x/profiles/keeper/utils_functions_test.go rename to x/profiles/keeper/alias_functions_test.go index 68608a2612..87827787d8 100644 --- a/x/profiles/keeper/utils_functions_test.go +++ b/x/profiles/keeper/alias_functions_test.go @@ -3,6 +3,9 @@ package keeper_test import ( "time" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/desmos-labs/desmos/x/profiles/types" ) @@ -10,6 +13,18 @@ func (suite *KeeperTestSuite) TestKeeper_IterateProfile() { date, err := time.Parse(time.RFC3339, "2010-10-02T12:10:00.000Z") suite.Require().NoError(err) + addr1, err := sdk.AccAddressFromBech32("cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns") + suite.Require().NoError(err) + + addr2, err := sdk.AccAddressFromBech32("cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47") + suite.Require().NoError(err) + + addr3, err := sdk.AccAddressFromBech32("cosmos1s3nh6tafl4amaxkke9kdejhp09lk93g9ev39r4") + suite.Require().NoError(err) + + addr4, err := sdk.AccAddressFromBech32("cosmos15lt0mflt6j9a9auj7yl3p20xec4xvljge0zhae") + suite.Require().NoError(err) + profiles := []types.Profile{ types.NewProfile( "first", @@ -17,7 +32,7 @@ func (suite *KeeperTestSuite) TestKeeper_IterateProfile() { "", types.NewPictures("", ""), date, - "cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns", + authtypes.NewBaseAccountWithAddress(addr1), ), types.NewProfile( "second", @@ -25,7 +40,7 @@ func (suite *KeeperTestSuite) TestKeeper_IterateProfile() { "", types.NewPictures("", ""), date, - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + authtypes.NewBaseAccountWithAddress(addr2), ), types.NewProfile( "not", @@ -33,7 +48,7 @@ func (suite *KeeperTestSuite) TestKeeper_IterateProfile() { "", types.NewPictures("", ""), date, - "cosmos1s3nh6tafl4amaxkke9kdejhp09lk93g9ev39r4", + authtypes.NewBaseAccountWithAddress(addr3), ), types.NewProfile( "third", @@ -41,7 +56,7 @@ func (suite *KeeperTestSuite) TestKeeper_IterateProfile() { "", types.NewPictures("", ""), date, - "cosmos15lt0mflt6j9a9auj7yl3p20xec4xvljge0zhae", + authtypes.NewBaseAccountWithAddress(addr4), ), } diff --git a/x/profiles/keeper/common_test.go b/x/profiles/keeper/common_test.go index fb9b04556c..8227a2e1f6 100644 --- a/x/profiles/keeper/common_test.go +++ b/x/profiles/keeper/common_test.go @@ -2,6 +2,13 @@ package keeper_test import ( "testing" + "time" + + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + + relationshipstypes "github.com/desmos-labs/desmos/x/relationships/types" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -33,6 +40,7 @@ type KeeperTestSuite struct { ctx sdk.Context storeKey sdk.StoreKey k keeper.Keeper + ak authkeeper.AccountKeeper rk relationshipskeeper.Keeper paramsKeeper paramskeeper.Keeper testData TestData @@ -45,21 +53,21 @@ type TestData struct { } func (suite *KeeperTestSuite) SetupTest() { - // define store keys - profileKey := sdk.NewKVStoreKey("profiles") - suite.storeKey = profileKey + // Define the store keys + keys := sdk.NewKVStoreKeys(types.StoreKey, authtypes.StoreKey, paramstypes.StoreKey, relationshipstypes.StoreKey) + tKeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) - paramsKey := sdk.NewKVStoreKey("params") - paramsTKey := sdk.NewTransientStoreKey("transient_params") - relationshipsKey := sdk.NewKVStoreKey("relationships") + suite.storeKey = keys[types.StoreKey] - // create an in-memory db + // Create an in-memory db memDB := db.NewMemDB() ms := store.NewCommitMultiStore(memDB) - ms.MountStoreWithDB(profileKey, sdk.StoreTypeIAVL, memDB) - ms.MountStoreWithDB(paramsKey, sdk.StoreTypeIAVL, memDB) - ms.MountStoreWithDB(paramsTKey, sdk.StoreTypeTransient, memDB) - ms.MountStoreWithDB(relationshipsKey, sdk.StoreTypeIAVL, memDB) + for _, key := range keys { + ms.MountStoreWithDB(key, sdk.StoreTypeIAVL, memDB) + } + for _, tKey := range tKeys { + ms.MountStoreWithDB(tKey, sdk.StoreTypeTransient, memDB) + } if err := ms.LoadLatestVersion(); err != nil { panic(err) @@ -68,28 +76,48 @@ func (suite *KeeperTestSuite) SetupTest() { suite.ctx = sdk.NewContext(ms, tmproto.Header{ChainID: "test-chain-id"}, false, log.NewNopLogger()) suite.cdc, suite.legacyAminoCdc = app.MakeCodecs() - suite.rk = relationshipskeeper.NewKeeper(suite.cdc, relationshipsKey) - suite.paramsKeeper = paramskeeper.NewKeeper(suite.cdc, suite.legacyAminoCdc, paramsKey, paramsTKey) + suite.rk = relationshipskeeper.NewKeeper(suite.cdc, keys[relationshipstypes.StoreKey]) + suite.paramsKeeper = paramskeeper.NewKeeper( + suite.cdc, suite.legacyAminoCdc, keys[paramstypes.StoreKey], tKeys[paramstypes.TStoreKey], + ) + + suite.ak = authkeeper.NewAccountKeeper( + suite.cdc, + keys[authtypes.StoreKey], + suite.paramsKeeper.Subspace(authtypes.ModuleName), + authtypes.ProtoBaseAccount, + app.GetMaccPerms(), + ) + suite.k = keeper.NewKeeper( suite.cdc, suite.storeKey, suite.paramsKeeper.Subspace(types.DefaultParamspace), suite.rk, + suite.ak, ) - // setup Data - // nolint - errcheck + // Set test data suite.testData.user = "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47" suite.testData.otherUser = "cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns" - suite.testData.profile = types.Profile{ - Dtag: "dtag", - Bio: "biography", - Pictures: types.NewPictures( + + addr, err := sdk.AccAddressFromBech32("cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47") + suite.Require().NoError(err) + + baseAcc := authtypes.NewBaseAccountWithAddress(addr) + suite.ak.SetAccount(suite.ctx, baseAcc) + + suite.testData.profile = types.NewProfile( + "dtag", + "test-user", + "biography", + types.NewPictures( "https://shorturl.at/adnX3", "https://shorturl.at/cgpyF", ), - Creator: suite.testData.user, - } + time.Time{}, + baseAcc, + ) } func (suite *KeeperTestSuite) RequireErrorsEqual(expected, actual error) { diff --git a/x/profiles/keeper/grpc_query.go b/x/profiles/keeper/grpc_query.go index 11cd6a5e47..8a7c056e2c 100644 --- a/x/profiles/keeper/grpc_query.go +++ b/x/profiles/keeper/grpc_query.go @@ -23,7 +23,7 @@ func (k Keeper) Profile(ctx context.Context, request *types.QueryProfileRequest) sdkAddress, err := sdk.AccAddressFromBech32(dTagOrAddress) if err != nil { - addr := k.GetDTagRelatedAddress(sdkCtx, dTagOrAddress) + addr := k.GetAddressFromDtag(sdkCtx, dTagOrAddress) if addr == "" { return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "No address related to this DTag: %s", dTagOrAddress) @@ -35,7 +35,11 @@ func (k Keeper) Profile(ctx context.Context, request *types.QueryProfileRequest) } } - account, found := k.GetProfile(sdkCtx, sdkAddress.String()) + account, found, err := k.GetProfile(sdkCtx, sdkAddress.String()) + if err != nil { + return nil, err + } + if !found { return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "Profile with sdkAddress %s doesn't exists", dTagOrAddress) diff --git a/x/profiles/keeper/invariants.go b/x/profiles/keeper/invariants.go index 5e0ce82337..f387764adb 100644 --- a/x/profiles/keeper/invariants.go +++ b/x/profiles/keeper/invariants.go @@ -31,7 +31,7 @@ func formatOutputProfiles(invalidProfiles []types.Profile) (outputProfiles strin outputProfiles += fmt.Sprintf( "[DTag]: %s, [Creator]: %s\n", invalidProfile.Dtag, - invalidProfile.Creator, + invalidProfile.BaseAccount.Address, ) } return outputProfiles diff --git a/x/profiles/keeper/invariants_test.go b/x/profiles/keeper/invariants_test.go index 8796a05146..825c7a59a0 100644 --- a/x/profiles/keeper/invariants_test.go +++ b/x/profiles/keeper/invariants_test.go @@ -1,11 +1,17 @@ package keeper_test import ( + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/desmos-labs/desmos/x/profiles/keeper" "github.com/desmos-labs/desmos/x/profiles/types" ) func (suite *KeeperTestSuite) TestInvariants() { + address, err := sdk.AccAddressFromBech32("cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47") + suite.Require().NoError(err) + tests := []struct { name string profile types.Profile @@ -20,7 +26,7 @@ func (suite *KeeperTestSuite) TestInvariants() { "", types.NewPictures("", ""), suite.testData.profile.CreationDate, - suite.testData.user, + authtypes.NewBaseAccountWithAddress(address), ), expResponse: "Every invariant condition is fulfilled correctly", expBool: true, @@ -33,7 +39,7 @@ func (suite *KeeperTestSuite) TestInvariants() { "", types.NewPictures("", ""), suite.testData.profile.CreationDate, - suite.testData.user, + authtypes.NewBaseAccountWithAddress(address), ), expResponse: "profiles: invalid profiles invariant\nThe following list contains invalid profiles:\n Invalid profiles:\n[DTag]: , [Creator]: cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47\n\n", expBool: true, diff --git a/x/profiles/keeper/keeper.go b/x/profiles/keeper/keeper.go index 1661531db4..899ee5266f 100644 --- a/x/profiles/keeper/keeper.go +++ b/x/profiles/keeper/keeper.go @@ -4,6 +4,8 @@ import ( "fmt" "regexp" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" relationshipskeeper "github.com/desmos-labs/desmos/x/relationships/keeper" @@ -18,11 +20,12 @@ import ( // Keeper maintains the link to data storage and exposes getter/setter methods for the various parts of the state machine type Keeper struct { - storeKey sdk.StoreKey - cdc codec.BinaryMarshaler - - relKeeper relationshipskeeper.Keeper + storeKey sdk.StoreKey + cdc codec.BinaryMarshaler paramSubspace paramstypes.Subspace + + ak authkeeper.AccountKeeper + rk relationshipskeeper.Keeper } // NewKeeper creates new instances of the profiles Keeper. @@ -32,134 +35,74 @@ type Keeper struct { // 2. DTag -> Address // This is used to get the address of a user based on a DTag func NewKeeper( - cdc codec.BinaryMarshaler, storeKey sdk.StoreKey, - paramSpace paramstypes.Subspace, relKeeper relationshipskeeper.Keeper, + cdc codec.BinaryMarshaler, storeKey sdk.StoreKey, paramSpace paramstypes.Subspace, + rk relationshipskeeper.Keeper, ak authkeeper.AccountKeeper, ) Keeper { if !paramSpace.HasKeyTable() { paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable()) } return Keeper{ - paramSubspace: paramSpace, - relKeeper: relKeeper, storeKey: storeKey, cdc: cdc, + paramSubspace: paramSpace, + rk: rk, + ak: ak, } } // IsUserBlocked tells if the given blocker has blocked the given blocked user func (k Keeper) IsUserBlocked(ctx sdk.Context, blocker, blocked string) bool { - return k.relKeeper.HasUserBlocked(ctx, blocker, blocked, "") -} - -// associateDtagWithAddress save the relation of dtag and address on chain -func (k Keeper) associateDtagWithAddress(ctx sdk.Context, dtag string, address string) { - store := ctx.KVStore(k.storeKey) - wrapped := WrappedDTagOwner{Address: address} - store.Set(types.DtagStoreKey(dtag), k.cdc.MustMarshalBinaryBare(&wrapped)) -} - -// GetDTagRelatedAddress returns the address associated to the given dtag or an empty string if it does not exists -func (k Keeper) GetDTagRelatedAddress(ctx sdk.Context, dtag string) (addr string) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.DtagStoreKey(dtag)) - if bz == nil { - return "" - } - - var owner WrappedDTagOwner - k.cdc.MustUnmarshalBinaryBare(bz, &owner) - return owner.Address -} - -// GetDtagFromAddress returns the dtag associated with the given address or an empty string if no dtag exists -func (k Keeper) GetDtagFromAddress(ctx sdk.Context, addr string) (dtag string) { - profile, found := k.GetProfile(ctx, addr) - if !found { - return "" - } - - return profile.Dtag -} - -// deleteDtagAddressAssociation delete the given dtag association with an address -func (k Keeper) deleteDtagAddressAssociation(ctx sdk.Context, dtag string) { - store := ctx.KVStore(k.storeKey) - store.Delete(types.DtagStoreKey(dtag)) -} - -// replaceDtag delete the oldDtag related to the creator address and associate the new one to it -func (k Keeper) replaceDtag(ctx sdk.Context, oldDtag, newDtag string, creator string) { - k.deleteDtagAddressAssociation(ctx, oldDtag) - k.associateDtagWithAddress(ctx, newDtag, creator) + return k.rk.HasUserBlocked(ctx, blocker, blocked, "") } // StoreProfile stores the given profile inside the current context. // It assumes that the given profile has already been validated. // It returns an error if a profile with the same dtag from a different creator already exists func (k Keeper) StoreProfile(ctx sdk.Context, profile types.Profile) error { - - addr := k.GetDTagRelatedAddress(ctx, profile.Dtag) - if addr != "" && addr != profile.Creator { + addr := k.GetAddressFromDtag(ctx, profile.Dtag) + if addr != "" && addr != profile.BaseAccount.Address { return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "a profile with dtag %s has already been created", profile.Dtag) } - oldDtag := k.GetDtagFromAddress(ctx, profile.Creator) - k.replaceDtag(ctx, oldDtag, profile.Dtag, profile.Creator) - - store := ctx.KVStore(k.storeKey) - key := types.ProfileStoreKey(profile.Creator) - store.Set(key, k.cdc.MustMarshalBinaryBare(&profile)) - + k.ak.SetAccount(ctx, &profile) return nil } // GetProfile returns the profile corresponding to the given address inside the current context. -func (k Keeper) GetProfile(ctx sdk.Context, address string) (profile types.Profile, found bool) { - store := ctx.KVStore(k.storeKey) +func (k Keeper) GetProfile(ctx sdk.Context, address string) (profile types.Profile, found bool, err error) { + sdkAcc, err := sdk.AccAddressFromBech32(address) + if err != nil { + return types.Profile{}, false, err + } - bz := store.Get(types.ProfileStoreKey(address)) - if bz != nil { - k.cdc.MustUnmarshalBinaryBare(bz, &profile) - return profile, true + stored, ok := k.ak.GetAccount(ctx, sdkAcc).(*types.Profile) + if !ok { + return types.Profile{}, false, nil } - return types.Profile{}, false + return *stored, true, nil } // RemoveProfile allows to delete a profile associated with the given address inside the current context. // It assumes that the address-related profile exists. func (k Keeper) RemoveProfile(ctx sdk.Context, address string) error { - profile, found := k.GetProfile(ctx, address) + profile, found, err := k.GetProfile(ctx, address) + if err != nil { + return err + } + if !found { return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "no profile associated with the following address found: %s", address) } - store := ctx.KVStore(k.storeKey) - store.Delete(types.ProfileStoreKey(address)) - k.deleteDtagAddressAssociation(ctx, profile.Dtag) + // Delete the profile data by replacing the stored account + k.ak.SetAccount(ctx, profile.BaseAccount) return nil } -// GetProfiles returns all the created profiles inside the current context. -func (k Keeper) GetProfiles(ctx sdk.Context) []types.Profile { - var profiles []types.Profile - - store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.ProfileStorePrefix) - defer iterator.Close() - - for ; iterator.Valid(); iterator.Next() { - var profile types.Profile - k.cdc.MustUnmarshalBinaryBare(iterator.Value(), &profile) - profiles = append(profiles, profile) - } - - return profiles -} - // ValidateProfile checks if the given profile is valid according to the current profile's module params func (k Keeper) ValidateProfile(ctx sdk.Context, profile types.Profile) error { params := k.GetParams(ctx) diff --git a/x/profiles/keeper/keeper_test.go b/x/profiles/keeper/keeper_test.go index d2587159e2..524669ad9b 100644 --- a/x/profiles/keeper/keeper_test.go +++ b/x/profiles/keeper/keeper_test.go @@ -4,6 +4,9 @@ import ( "fmt" "strings" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" relationshipstypes "github.com/desmos-labs/desmos/x/relationships/types" @@ -61,23 +64,32 @@ func (suite *KeeperTestSuite) TestKeeper_GetDtagFromAddress() { name string storedProfiles []types.Profile address string + shouldErr bool expDTag string }{ + { + name: "invalid address", + storedProfiles: nil, + address: "", + shouldErr: true, + }, { name: "found right dtag", storedProfiles: []types.Profile{ suite.testData.profile, }, - address: suite.testData.profile.Creator, - expDTag: suite.testData.profile.Dtag, + address: suite.testData.profile.BaseAccount.Address, + shouldErr: false, + expDTag: suite.testData.profile.Dtag, }, { name: "no dtag found", storedProfiles: []types.Profile{ suite.testData.profile, }, - address: "non_existent", - expDTag: "", + address: "cosmos1ppkr0c0x6jvx9e4e48mfvhq2wzzsrync8qrt2m", + shouldErr: false, + expDTag: "", }, } @@ -90,13 +102,22 @@ func (suite *KeeperTestSuite) TestKeeper_GetDtagFromAddress() { suite.Require().NoError(err) } - dTag := suite.k.GetDtagFromAddress(suite.ctx, test.address) - suite.Require().Equal(test.expDTag, dTag) + dTag, err := suite.k.GetDtagFromAddress(suite.ctx, test.address) + + if test.shouldErr { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + suite.Require().Equal(test.expDTag, dTag) + } }) } } func (suite *KeeperTestSuite) TestKeeper_StoreProfile() { + addr, err := sdk.AccAddressFromBech32("cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns") + suite.Require().NoError(err) + tests := []struct { name string account types.Profile @@ -112,10 +133,10 @@ func (suite *KeeperTestSuite) TestKeeper_StoreProfile() { { name: "Existent account with different creator returns error", account: types.Profile{ - Dtag: suite.testData.profile.Dtag, - Bio: suite.testData.profile.Bio, - Pictures: suite.testData.profile.Pictures, - Creator: "cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns", + Dtag: suite.testData.profile.Dtag, + Bio: suite.testData.profile.Bio, + Pictures: suite.testData.profile.Pictures, + BaseAccount: authtypes.NewBaseAccountWithAddress(addr), }, storedProfiles: []types.Profile{suite.testData.profile}, expError: sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, @@ -142,22 +163,30 @@ func (suite *KeeperTestSuite) TestKeeper_GetProfile() { name string storedProfiles []types.Profile address string + shouldErr bool expFound bool expProfile *types.Profile }{ { - name: "Profile founded", + name: "Invalid address", + storedProfiles: nil, + address: "", + shouldErr: true, + }, + { + name: "Profile found", storedProfiles: []types.Profile{ suite.testData.profile, }, - address: suite.testData.profile.Creator, + address: suite.testData.profile.BaseAccount.Address, + shouldErr: false, expFound: true, expProfile: &suite.testData.profile, }, { name: "Profile not found", storedProfiles: []types.Profile{}, - address: suite.testData.profile.Creator, + address: suite.testData.profile.BaseAccount.Address, expFound: false, }, } @@ -172,11 +201,16 @@ func (suite *KeeperTestSuite) TestKeeper_GetProfile() { suite.Require().NoError(err) } - res, found := suite.k.GetProfile(suite.ctx, test.address) - suite.Require().Equal(test.expFound, found) + res, found, err := suite.k.GetProfile(suite.ctx, test.address) + if test.shouldErr { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + suite.Require().Equal(test.expFound, found) - if found { - suite.Require().True(res.Equal(test.expProfile)) + if found { + suite.Require().Equal(*test.expProfile, res) + } } }) } @@ -186,13 +220,13 @@ func (suite *KeeperTestSuite) TestKeeper_RemoveProfile() { err := suite.k.StoreProfile(suite.ctx, suite.testData.profile) suite.Require().Nil(err) - _, found := suite.k.GetProfile(suite.ctx, suite.testData.profile.Creator) + _, found, _ := suite.k.GetProfile(suite.ctx, suite.testData.profile.BaseAccount.Address) suite.True(found) - err = suite.k.RemoveProfile(suite.ctx, suite.testData.profile.Creator) + err = suite.k.RemoveProfile(suite.ctx, suite.testData.profile.BaseAccount.Address) suite.Require().NoError(err) - _, found = suite.k.GetProfile(suite.ctx, suite.testData.profile.Creator) + _, found, _ = suite.k.GetProfile(suite.ctx, suite.testData.profile.BaseAccount.Address) suite.Require().False(found) } @@ -216,10 +250,9 @@ func (suite *KeeperTestSuite) TestKeeper_GetProfiles() { suite.Run(test.name, func() { suite.SetupTest() - if len(test.accounts) != 0 { - store := suite.ctx.KVStore(suite.storeKey) - key := types.ProfileStoreKey(test.accounts[0].Creator) - store.Set(key, suite.cdc.MustMarshalBinaryBare(&test.accounts[0])) + for _, profile := range test.accounts { + err := suite.k.StoreProfile(suite.ctx, profile) + suite.Require().NoError(err) } res := suite.k.GetProfiles(suite.ctx) @@ -245,7 +278,7 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() { "https://test.com/cover-pic", ), suite.testData.profile.CreationDate, - suite.testData.profile.Creator, + suite.testData.profile.BaseAccount, ), expErr: fmt.Errorf("profile moniker cannot exceed 1000 characters"), }, @@ -261,7 +294,7 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() { ), suite.testData.profile.CreationDate, - suite.testData.profile.Creator, + suite.testData.profile.BaseAccount, ), expErr: fmt.Errorf("profile moniker cannot be less than 2 characters"), }, @@ -277,7 +310,7 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() { ), suite.testData.profile.CreationDate, - suite.testData.profile.Creator, + suite.testData.profile.BaseAccount, ), expErr: fmt.Errorf("profile biography cannot exceed 1000 characters"), }, @@ -292,7 +325,7 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() { "https://test.com/cover-pic", ), suite.testData.profile.CreationDate, - suite.testData.profile.Creator, + suite.testData.profile.BaseAccount, ), expErr: fmt.Errorf("invalid profile dtag, it should match the following regEx ^[A-Za-z0-9_]+$"), }, @@ -308,7 +341,7 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() { ), suite.testData.profile.CreationDate, - suite.testData.profile.Creator, + suite.testData.profile.BaseAccount, ), expErr: fmt.Errorf("profile dtag cannot be less than 3 characters"), }, @@ -323,7 +356,7 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() { "https://test.com/cover-pic", ), suite.testData.profile.CreationDate, - suite.testData.profile.Creator, + suite.testData.profile.BaseAccount, ), expErr: fmt.Errorf("profile dtag cannot exceed 30 characters"), }, @@ -338,7 +371,7 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() { "htts://test.com/cover-pic", ), suite.testData.profile.CreationDate, - suite.testData.profile.Creator, + suite.testData.profile.BaseAccount, ), expErr: fmt.Errorf("invalid profile picture uri provided"), }, @@ -354,7 +387,7 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() { ), suite.testData.profile.CreationDate, - suite.testData.profile.Creator, + suite.testData.profile.BaseAccount, ), expErr: nil, }, diff --git a/x/profiles/keeper/msgs_server.go b/x/profiles/keeper/msgs_server.go index 1972de9263..3a0ad709f0 100644 --- a/x/profiles/keeper/msgs_server.go +++ b/x/profiles/keeper/msgs_server.go @@ -4,6 +4,8 @@ import ( "context" "time" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -23,17 +25,25 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer { func (k msgServer) SaveProfile(goCtx context.Context, msg *types.MsgSaveProfile) (*types.MsgSaveProfileResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - profile, found := k.GetProfile(ctx, msg.Creator) + profile, found, err := k.GetProfile(ctx, msg.Creator) + if err != nil { + return nil, err + } // Create a new profile if not found if !found { + addr, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + return nil, err + } + profile = types.NewProfile( msg.Dtag, "", "", types.NewPictures("", ""), ctx.BlockTime(), - msg.Creator, + k.ak.GetAccount(ctx, addr), ) } @@ -49,7 +59,7 @@ func (k msgServer) SaveProfile(goCtx context.Context, msg *types.MsgSaveProfile) msg.Bio, types.NewPictures(msg.ProfilePicture, msg.CoverPicture), time.Time{}, - types.DoNotModify, + nil, )) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error()) @@ -69,7 +79,7 @@ func (k msgServer) SaveProfile(goCtx context.Context, msg *types.MsgSaveProfile) ctx.EventManager().EmitEvent(sdk.NewEvent( types.EventTypeProfileSaved, sdk.NewAttribute(types.AttributeProfileDtag, updated.Dtag), - sdk.NewAttribute(types.AttributeProfileCreator, updated.Creator), + sdk.NewAttribute(types.AttributeProfileCreator, updated.BaseAccount.Address), sdk.NewAttribute(types.AttributeProfileCreationTime, updated.CreationDate.Format(time.RFC3339Nano)), )) @@ -100,7 +110,11 @@ func (k msgServer) RequestDTagTransfer(goCtx context.Context, msg *types.MsgRequ return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "the user with address %s has blocked you", msg.Receiver) } - dtagToTrade := k.GetDtagFromAddress(ctx, msg.Receiver) + dtagToTrade, err := k.GetDtagFromAddress(ctx, msg.Receiver) + if err != nil { + return nil, err + } + if len(dtagToTrade) == 0 { return nil, sdkerrors.Wrapf( sdkerrors.ErrInvalidRequest, @@ -110,7 +124,7 @@ func (k msgServer) RequestDTagTransfer(goCtx context.Context, msg *types.MsgRequ } transferRequest := types.NewDTagTransferRequest(dtagToTrade, msg.Sender, msg.Receiver) - err := k.SaveDTagTransferRequest(ctx, transferRequest) + err = k.SaveDTagTransferRequest(ctx, transferRequest) if err != nil { return nil, err } @@ -163,7 +177,11 @@ func (k msgServer) AcceptDTagTransfer(goCtx context.Context, msg *types.MsgAccep } // Get the current owner profile - currentOwnerProfile, exist := k.GetProfile(ctx, msg.Receiver) + currentOwnerProfile, exist, err := k.GetProfile(ctx, msg.Receiver) + if err != nil { + return nil, err + } + if !exist { return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "profile of %s doesn't exist", msg.Receiver) } @@ -176,7 +194,7 @@ func (k msgServer) AcceptDTagTransfer(goCtx context.Context, msg *types.MsgAccep // Change the DTag and validate the profile currentOwnerProfile.Dtag = msg.NewDtag - err := k.ValidateProfile(ctx, currentOwnerProfile) + err = k.ValidateProfile(ctx, currentOwnerProfile) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error()) } @@ -188,15 +206,29 @@ func (k msgServer) AcceptDTagTransfer(goCtx context.Context, msg *types.MsgAccep } // Check for an existent profile of the receiving user - receiverProfile, exist := k.GetProfile(ctx, msg.Sender) + receiverProfile, exist, err := k.GetProfile(ctx, msg.Sender) + if err != nil { + return nil, err + } + if !exist { + add, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { + return nil, err + } + + senderAcc := k.ak.GetAccount(ctx, add) + if senderAcc == nil { + senderAcc = authtypes.NewBaseAccountWithAddress(add) + } + receiverProfile = types.NewProfile( dTagToTrade, "", "", types.NewPictures("", ""), ctx.BlockTime(), - msg.Sender, + senderAcc, ) } else { receiverProfile.Dtag = dTagToTrade diff --git a/x/profiles/keeper/msgs_server_test.go b/x/profiles/keeper/msgs_server_test.go index 50038ccfed..6d47c40199 100644 --- a/x/profiles/keeper/msgs_server_test.go +++ b/x/profiles/keeper/msgs_server_test.go @@ -3,6 +3,8 @@ package keeper_test import ( "time" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + relationshipstypes "github.com/desmos-labs/desmos/x/relationships/types" "github.com/desmos-labs/desmos/x/profiles/keeper" @@ -31,7 +33,7 @@ func (suite *KeeperTestSuite) Test_handleMsgSaveProfile() { "my-bio", "https://test.com/profile-picture", "https://test.com/cover-pic", - suite.testData.profile.Creator, + suite.testData.profile.BaseAccount.Address, ), expStoredProfiles: []types.Profile{ types.NewProfile( @@ -43,14 +45,14 @@ func (suite *KeeperTestSuite) Test_handleMsgSaveProfile() { "https://test.com/cover-pic", ), suite.testData.profile.CreationDate, - suite.testData.profile.Creator, + suite.testData.profile.BaseAccount, ), }, expEvents: sdk.Events{ sdk.NewEvent( types.EventTypeProfileSaved, sdk.NewAttribute(types.AttributeProfileDtag, "custom_dtag"), - sdk.NewAttribute(types.AttributeProfileCreator, suite.testData.profile.Creator), + sdk.NewAttribute(types.AttributeProfileCreator, suite.testData.profile.BaseAccount.Address), sdk.NewAttribute(types.AttributeProfileCreationTime, suite.testData.profile.CreationDate.Format(time.RFC3339)), ), }, @@ -68,7 +70,7 @@ func (suite *KeeperTestSuite) Test_handleMsgSaveProfile() { "https://test.com/old-cover-pic", ), suite.testData.profile.CreationDate, - suite.testData.profile.Creator, + suite.testData.profile.BaseAccount, ), }, msg: types.NewMsgSaveProfile( @@ -77,13 +79,13 @@ func (suite *KeeperTestSuite) Test_handleMsgSaveProfile() { "biography", "https://test.com/profile-pic", "https://test.com/cover-pic", - suite.testData.profile.Creator, + suite.testData.profile.BaseAccount.Address, ), expEvents: sdk.Events{ sdk.NewEvent( types.EventTypeProfileSaved, sdk.NewAttribute(types.AttributeProfileDtag, "other_dtag"), - sdk.NewAttribute(types.AttributeProfileCreator, suite.testData.profile.Creator), + sdk.NewAttribute(types.AttributeProfileCreator, suite.testData.profile.BaseAccount.Address), sdk.NewAttribute(types.AttributeProfileCreationTime, suite.testData.profile.CreationDate.Format(time.RFC3339)), ), }, @@ -97,7 +99,7 @@ func (suite *KeeperTestSuite) Test_handleMsgSaveProfile() { "https://test.com/cover-pic", ), suite.testData.profile.CreationDate, - suite.testData.profile.Creator, + suite.testData.profile.BaseAccount, ), }, }, @@ -111,7 +113,7 @@ func (suite *KeeperTestSuite) Test_handleMsgSaveProfile() { "", types.NewPictures("", ""), suite.testData.profile.CreationDate, - suite.testData.profile.Creator, + suite.testData.profile.BaseAccount, ), }, msg: types.NewMsgSaveProfile( @@ -120,7 +122,7 @@ func (suite *KeeperTestSuite) Test_handleMsgSaveProfile() { "", "invalid-pic", "", - suite.testData.profile.Creator, + suite.testData.profile.BaseAccount.Address, ), expEvents: sdk.EmptyEvents(), expErr: sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid profile picture uri provided"), @@ -131,7 +133,7 @@ func (suite *KeeperTestSuite) Test_handleMsgSaveProfile() { "", types.NewPictures("", ""), suite.testData.profile.CreationDate, - suite.testData.profile.Creator, + suite.testData.profile.BaseAccount, ), }, }, @@ -175,7 +177,7 @@ func (suite *KeeperTestSuite) Test_handleMsgDeleteProfile() { { name: "Profile doesn't exists", storedProfiles: nil, - msg: types.NewMsgDeleteProfile(suite.testData.profile.Creator), + msg: types.NewMsgDeleteProfile(suite.testData.profile.BaseAccount.Address), expErr: sdkerrors.Wrap( sdkerrors.ErrInvalidRequest, "no profile associated with the following address found: cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", @@ -187,11 +189,11 @@ func (suite *KeeperTestSuite) Test_handleMsgDeleteProfile() { storedProfiles: []types.Profile{ suite.testData.profile, }, - msg: types.NewMsgDeleteProfile(suite.testData.profile.Creator), + msg: types.NewMsgDeleteProfile(suite.testData.profile.BaseAccount.Address), expEvents: sdk.Events{ sdk.NewEvent( types.EventTypeProfileDeleted, - sdk.NewAttribute(types.AttributeProfileCreator, suite.testData.profile.Creator), + sdk.NewAttribute(types.AttributeProfileCreator, suite.testData.profile.BaseAccount.Address), ), }, }, @@ -221,6 +223,9 @@ func (suite *KeeperTestSuite) Test_handleMsgDeleteProfile() { } func (suite *KeeperTestSuite) Test_handleMsgRequestDTagTransfer() { + otherAddr, err := sdk.AccAddressFromBech32(suite.testData.otherUser) + suite.Require().NoError(err) + tests := []struct { name string storedProfiles []types.Profile @@ -263,19 +268,19 @@ func (suite *KeeperTestSuite) Test_handleMsgRequestDTagTransfer() { storedProfiles: []types.Profile{ suite.testData.profile, { - Dtag: "test-dtag", - Creator: suite.testData.otherUser, + Dtag: "test-dtag", + BaseAccount: authtypes.NewBaseAccountWithAddress(otherAddr), }, }, storedDTagReqs: []types.DTagTransferRequest{ - types.NewDTagTransferRequest("dtag", suite.testData.profile.Creator, suite.testData.otherUser), + types.NewDTagTransferRequest("dtag", suite.testData.profile.BaseAccount.Address, suite.testData.otherUser), }, - msg: types.NewMsgRequestDTagTransfer(suite.testData.profile.Creator, suite.testData.otherUser), + msg: types.NewMsgRequestDTagTransfer(suite.testData.profile.BaseAccount.Address, suite.testData.otherUser), expEvents: sdk.EmptyEvents(), expErr: sdkerrors.Wrapf( sdkerrors.ErrInvalidRequest, "the transfer request from %s to %s has already been made", - suite.testData.profile.Creator, suite.testData.otherUser, + suite.testData.profile.BaseAccount.Address, suite.testData.otherUser, ), }, { @@ -283,13 +288,13 @@ func (suite *KeeperTestSuite) Test_handleMsgRequestDTagTransfer() { storedProfiles: []types.Profile{ suite.testData.profile, }, - msg: types.NewMsgRequestDTagTransfer(suite.testData.user, suite.testData.profile.Creator), + msg: types.NewMsgRequestDTagTransfer(suite.testData.user, suite.testData.profile.BaseAccount.Address), expEvents: sdk.Events{ sdk.NewEvent( types.EventTypeDTagTransferRequest, sdk.NewAttribute(types.AttributeDTagToTrade, "dtag"), sdk.NewAttribute(types.AttributeRequestSender, suite.testData.user), - sdk.NewAttribute(types.AttributeRequestReceiver, suite.testData.profile.Creator), + sdk.NewAttribute(types.AttributeRequestReceiver, suite.testData.profile.BaseAccount.Address), ), }, }, @@ -323,6 +328,12 @@ func (suite *KeeperTestSuite) Test_handleMsgRequestDTagTransfer() { } func (suite *KeeperTestSuite) Test_handleMsgAcceptDTagTransfer() { + otherAddr, err := sdk.AccAddressFromBech32(suite.testData.otherUser) + suite.Require().NoError(err) + + newAddr, err := sdk.AccAddressFromBech32("cosmos1lkqrqrns0ekttzrs678thh5f4prcgasthqcxph") + suite.Require().NoError(err) + tests := []struct { name string storedDTagReqs []types.DTagTransferRequest @@ -356,7 +367,7 @@ func (suite *KeeperTestSuite) Test_handleMsgAcceptDTagTransfer() { "", types.NewPictures("", ""), suite.ctx.BlockTime(), - suite.testData.otherUser, + authtypes.NewBaseAccountWithAddress(otherAddr), ), types.NewProfile( "newDtag", @@ -364,7 +375,7 @@ func (suite *KeeperTestSuite) Test_handleMsgAcceptDTagTransfer() { "", types.NewPictures("", ""), suite.ctx.BlockTime(), - "cosmos1lkqrqrns0ekttzrs678thh5f4prcgasthqcxph", + authtypes.NewBaseAccountWithAddress(newAddr), ), }, storedDTagReqs: []types.DTagTransferRequest{ @@ -383,7 +394,7 @@ func (suite *KeeperTestSuite) Test_handleMsgAcceptDTagTransfer() { "", types.NewPictures("", ""), suite.ctx.BlockTime(), - suite.testData.otherUser, + authtypes.NewBaseAccountWithAddress(otherAddr), ), }, storedDTagReqs: []types.DTagTransferRequest{ @@ -403,7 +414,7 @@ func (suite *KeeperTestSuite) Test_handleMsgAcceptDTagTransfer() { "", types.NewPictures("", ""), suite.ctx.BlockTime(), - suite.testData.otherUser, + authtypes.NewBaseAccountWithAddress(otherAddr), ), }, storedDTagReqs: []types.DTagTransferRequest{ @@ -429,7 +440,7 @@ func (suite *KeeperTestSuite) Test_handleMsgAcceptDTagTransfer() { "", types.NewPictures("", ""), suite.ctx.BlockTime(), - suite.testData.user, + suite.testData.profile.BaseAccount, ), types.NewProfile( "previous", @@ -437,7 +448,7 @@ func (suite *KeeperTestSuite) Test_handleMsgAcceptDTagTransfer() { "", types.NewPictures("", ""), suite.ctx.BlockTime(), - suite.testData.otherUser, + authtypes.NewBaseAccountWithAddress(otherAddr), ), }, storedDTagReqs: []types.DTagTransferRequest{ diff --git a/x/profiles/keeper/querier.go b/x/profiles/keeper/querier.go index 931aa866d9..e9fe4daf46 100644 --- a/x/profiles/keeper/querier.go +++ b/x/profiles/keeper/querier.go @@ -43,7 +43,7 @@ func queryProfile( sdkAddress, err := sdk.AccAddressFromBech32(dTagOrAddress) if err != nil { - addr := keeper.GetDTagRelatedAddress(ctx, dTagOrAddress) + addr := keeper.GetAddressFromDtag(ctx, dTagOrAddress) if addr == "" { return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "No address related to this DTag: %s", dTagOrAddress) @@ -55,7 +55,11 @@ func queryProfile( } } - account, found := keeper.GetProfile(ctx, sdkAddress.String()) + account, found, err := keeper.GetProfile(ctx, sdkAddress.String()) + if err != nil { + return nil, err + } + if !found { return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "Profile with address %s doesn't exists", dTagOrAddress) diff --git a/x/profiles/keeper/types.go b/x/profiles/keeper/types.go index 9f4093784f..c5c8cacf70 100644 --- a/x/profiles/keeper/types.go +++ b/x/profiles/keeper/types.go @@ -2,11 +2,6 @@ package keeper import "github.com/desmos-labs/desmos/x/profiles/types" -// NewWrappedDTagOwner returns a DTagOwner instance wrapping the given address -func NewWrappedDTagOwner(address string) WrappedDTagOwner { - return WrappedDTagOwner{Address: address} -} - // NewWrappedDTagTransferRequests returns a DTagRequests instance wrapping the given requests func NewWrappedDTagTransferRequests(requests []types.DTagTransferRequest) WrappedDTagTransferRequests { return WrappedDTagTransferRequests{Requests: requests} diff --git a/x/profiles/keeper/types.pb.go b/x/profiles/keeper/types.pb.go index 58a82ec12c..7813db7c91 100644 --- a/x/profiles/keeper/types.pb.go +++ b/x/profiles/keeper/types.pb.go @@ -24,52 +24,6 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// DTagOwner represents the owner of a specific DTag -type WrappedDTagOwner struct { - // Address of the user owning a Dtag - Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` -} - -func (m *WrappedDTagOwner) Reset() { *m = WrappedDTagOwner{} } -func (m *WrappedDTagOwner) String() string { return proto.CompactTextString(m) } -func (*WrappedDTagOwner) ProtoMessage() {} -func (*WrappedDTagOwner) Descriptor() ([]byte, []int) { - return fileDescriptor_732b728428b8b385, []int{0} -} -func (m *WrappedDTagOwner) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *WrappedDTagOwner) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_WrappedDTagOwner.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *WrappedDTagOwner) XXX_Merge(src proto.Message) { - xxx_messageInfo_WrappedDTagOwner.Merge(m, src) -} -func (m *WrappedDTagOwner) XXX_Size() int { - return m.Size() -} -func (m *WrappedDTagOwner) XXX_DiscardUnknown() { - xxx_messageInfo_WrappedDTagOwner.DiscardUnknown(m) -} - -var xxx_messageInfo_WrappedDTagOwner proto.InternalMessageInfo - -func (m *WrappedDTagOwner) GetAddress() string { - if m != nil { - return m.Address - } - return "" -} - // DtagRequests contains the DTag transfer requests made towards a user type WrappedDTagTransferRequests struct { Requests []types.DTagTransferRequest `protobuf:"bytes,1,rep,name=requests,proto3" json:"requests"` @@ -79,7 +33,7 @@ func (m *WrappedDTagTransferRequests) Reset() { *m = WrappedDTagTransfer func (m *WrappedDTagTransferRequests) String() string { return proto.CompactTextString(m) } func (*WrappedDTagTransferRequests) ProtoMessage() {} func (*WrappedDTagTransferRequests) Descriptor() ([]byte, []int) { - return fileDescriptor_732b728428b8b385, []int{1} + return fileDescriptor_732b728428b8b385, []int{0} } func (m *WrappedDTagTransferRequests) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -116,7 +70,6 @@ func (m *WrappedDTagTransferRequests) GetRequests() []types.DTagTransferRequest } func init() { - proto.RegisterType((*WrappedDTagOwner)(nil), "desmos.profiles.v1beta1.keeper.WrappedDTagOwner") proto.RegisterType((*WrappedDTagTransferRequests)(nil), "desmos.profiles.v1beta1.keeper.WrappedDTagTransferRequests") } @@ -125,50 +78,24 @@ func init() { } var fileDescriptor_732b728428b8b385 = []byte{ - // 271 bytes of a gzipped FileDescriptorProto + // 238 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x4a, 0x49, 0x2d, 0xce, 0xcd, 0x2f, 0xd6, 0x2f, 0x28, 0xca, 0x4f, 0xcb, 0xcc, 0x49, 0x2d, 0xd6, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0xcf, 0x4e, 0x4d, 0x2d, 0x48, 0x2d, 0xd2, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x83, 0xa8, 0xd5, 0x83, 0xa9, 0xd5, 0x83, 0xaa, 0xd5, 0x83, 0xa8, 0x95, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0x2b, 0xd5, 0x07, 0xb1, 0x20, 0xba, - 0xa4, 0x54, 0x70, 0xd9, 0x90, 0x9b, 0x9f, 0x92, 0x9a, 0x03, 0x35, 0x5b, 0xc9, 0x8c, 0x4b, 0x20, - 0xbc, 0x28, 0xb1, 0xa0, 0x20, 0x35, 0xc5, 0x25, 0x24, 0x31, 0xdd, 0xbf, 0x3c, 0x2f, 0xb5, 0x48, - 0x48, 0x82, 0x8b, 0x3d, 0x31, 0x25, 0xa5, 0x28, 0xb5, 0xb8, 0x58, 0x82, 0x51, 0x81, 0x51, 0x83, - 0x33, 0x08, 0xc6, 0xb5, 0xe2, 0x98, 0xb1, 0x40, 0x9e, 0xf1, 0xc5, 0x02, 0x79, 0x46, 0xa5, 0x72, - 0x2e, 0x69, 0x24, 0x7d, 0x21, 0x45, 0x89, 0x79, 0xc5, 0x69, 0xa9, 0x45, 0x41, 0xa9, 0x85, 0xa5, - 0xa9, 0xc5, 0x25, 0xc5, 0x42, 0x7e, 0x5c, 0x1c, 0x45, 0x50, 0xb6, 0x04, 0xa3, 0x02, 0xb3, 0x06, - 0xb7, 0x91, 0x8e, 0x1e, 0x2e, 0x5f, 0x60, 0x31, 0xc0, 0x89, 0xe5, 0xc4, 0x3d, 0x79, 0x86, 0x20, - 0xb8, 0x19, 0x08, 0x8b, 0x9d, 0x3c, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, - 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, - 0x4a, 0x3f, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x1f, 0x62, 0x97, 0x6e, - 0x4e, 0x62, 0x52, 0x31, 0x94, 0xad, 0x5f, 0x81, 0x08, 0x09, 0x48, 0xb8, 0x25, 0xb1, 0x81, 0x83, - 0xc0, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0xec, 0xe9, 0xd6, 0x0a, 0x8c, 0x01, 0x00, 0x00, + 0xa4, 0x54, 0x70, 0xd9, 0x90, 0x9b, 0x9f, 0x92, 0x9a, 0x03, 0x35, 0x5b, 0xa9, 0x9c, 0x4b, 0x3a, + 0xbc, 0x28, 0xb1, 0xa0, 0x20, 0x35, 0xc5, 0x25, 0x24, 0x31, 0x3d, 0xa4, 0x28, 0x31, 0xaf, 0x38, + 0x2d, 0xb5, 0x28, 0x28, 0xb5, 0xb0, 0x34, 0xb5, 0xb8, 0xa4, 0x58, 0xc8, 0x8f, 0x8b, 0xa3, 0x08, + 0xca, 0x96, 0x60, 0x54, 0x60, 0xd6, 0xe0, 0x36, 0xd2, 0xd1, 0xc3, 0xe5, 0x1a, 0x2c, 0x06, 0x38, + 0xb1, 0x9c, 0xb8, 0x27, 0xcf, 0x10, 0x04, 0x37, 0xc3, 0x8a, 0x63, 0xc6, 0x02, 0x79, 0xc6, 0x17, + 0x0b, 0xe4, 0x19, 0x9d, 0x3c, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, + 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, + 0x3f, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x1f, 0x62, 0x97, 0x6e, 0x4e, + 0x62, 0x52, 0x31, 0x94, 0xad, 0x5f, 0x81, 0xf0, 0x11, 0xc4, 0xff, 0x49, 0x6c, 0x60, 0xaf, 0x18, + 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x05, 0x21, 0x73, 0x8c, 0x54, 0x01, 0x00, 0x00, } -func (this *WrappedDTagOwner) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*WrappedDTagOwner) - if !ok { - that2, ok := that.(WrappedDTagOwner) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Address != that1.Address { - return false - } - return true -} func (this *WrappedDTagTransferRequests) Equal(that interface{}) bool { if that == nil { return this == nil @@ -198,36 +125,6 @@ func (this *WrappedDTagTransferRequests) Equal(that interface{}) bool { } return true } -func (m *WrappedDTagOwner) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *WrappedDTagOwner) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *WrappedDTagOwner) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Address) > 0 { - i -= len(m.Address) - copy(dAtA[i:], m.Address) - i = encodeVarintTypes(dAtA, i, uint64(len(m.Address))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - func (m *WrappedDTagTransferRequests) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -276,19 +173,6 @@ func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *WrappedDTagOwner) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Address) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) - } - return n -} - func (m *WrappedDTagTransferRequests) Size() (n int) { if m == nil { return 0 @@ -310,91 +194,6 @@ func sovTypes(x uint64) (n int) { func sozTypes(x uint64) (n int) { return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *WrappedDTagOwner) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: WrappedDTagOwner: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: WrappedDTagOwner: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Address = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *WrappedDTagTransferRequests) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/profiles/keeper/utils_functions.go b/x/profiles/keeper/utils_functions.go deleted file mode 100644 index 279b37e725..0000000000 --- a/x/profiles/keeper/utils_functions.go +++ /dev/null @@ -1,24 +0,0 @@ -package keeper - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/desmos-labs/desmos/x/profiles/types" -) - -// IterateProfiles iterates through the profiles set and performs the provided function -func (k Keeper) IterateProfiles(ctx sdk.Context, fn func(index int64, profile types.Profile) (stop bool)) { - store := ctx.KVStore(k.storeKey) - iterator := sdk.KVStorePrefixIterator(store, types.ProfileStorePrefix) - defer iterator.Close() - i := int64(0) - for ; iterator.Valid(); iterator.Next() { - var profile types.Profile - k.cdc.MustUnmarshalBinaryBare(iterator.Value(), &profile) - stop := fn(i, profile) - if stop { - break - } - i++ - } -} diff --git a/x/profiles/legacy/v0.15.0/types.go b/x/profiles/legacy/v0.15.0/types.go index 92a17202ed..44bae72ee7 100644 --- a/x/profiles/legacy/v0.15.0/types.go +++ b/x/profiles/legacy/v0.15.0/types.go @@ -1,16 +1,29 @@ package v0150 import ( + "time" + v0130profiles "github.com/desmos-labs/desmos/x/profiles/legacy/v0.13.0" v0150profiles "github.com/desmos-labs/desmos/x/profiles/types" ) // GenesisState contains the data of a v0.15.0 genesis state for the profiles module -type GenesisState = v0150profiles.GenesisState +type GenesisState struct { + Profiles []Profile `protobuf:"bytes,1,rep,name=profiles,proto3" json:"profiles" yaml:"profiles"` + DtagTransferRequests []DTagTransferRequest `protobuf:"bytes,2,rep,name=dtag_transfer_requests,json=dtagTransferRequests,proto3" json:"dtag_transfer_requests" yaml:"dtag_transfer_requests"` + Params Params `protobuf:"bytes,3,opt,name=params,proto3" json:"params" yaml:"params"` +} // ---------------------------------------------------------------------------------------------------------------- -type Profile = v0150profiles.Profile +type Profile struct { + Dtag string `protobuf:"bytes,1,opt,name=dtag,proto3" json:"dtag,omitempty" yaml:"dtag"` + Moniker string `protobuf:"bytes,2,opt,name=moniker,proto3" json:"moniker,omitempty" yaml:"moniker"` + Bio string `protobuf:"bytes,3,opt,name=bio,proto3" json:"bio,omitempty" yaml:"bio"` + Pictures Pictures `protobuf:"bytes,4,opt,name=pictures,proto3" json:"pictures" yaml:"pictures"` + Creator string `protobuf:"bytes,5,opt,name=creator,proto3" json:"creator,omitempty" yaml:"creator"` + CreationDate time.Time `protobuf:"bytes,6,opt,name=creation_date,json=creationDate,proto3,stdtime" json:"creation_date" yaml:"creation_date"` +} func newProfile(profile v0130profiles.Profile) Profile { moniker := "" diff --git a/x/profiles/simulation/decoder.go b/x/profiles/simulation/decoder.go index 158ce7f9ee..d80aed8ef4 100644 --- a/x/profiles/simulation/decoder.go +++ b/x/profiles/simulation/decoder.go @@ -17,18 +17,6 @@ import ( func NewDecodeStore(cdc codec.Marshaler) func(kvA, kvB kv.Pair) string { return func(kvA, kvB kv.Pair) string { switch { - case bytes.HasPrefix(kvA.Key, types.ProfileStorePrefix): - var profileA, profileB types.Profile - cdc.MustUnmarshalBinaryBare(kvA.Value, &profileA) - cdc.MustUnmarshalBinaryBare(kvB.Value, &profileB) - return fmt.Sprintf("ProfileA: %s\nProfileB: %s\n", profileA, profileB) - - case bytes.HasPrefix(kvA.Key, types.DtagStorePrefix): - var addressA, addressB keeper.WrappedDTagOwner - cdc.MustUnmarshalBinaryBare(kvA.Value, &addressA) - cdc.MustUnmarshalBinaryBare(kvB.Value, &addressB) - return fmt.Sprintf("AddressA: %s\nAddressB: %s\n", addressA.Address, addressB.Address) - case bytes.HasPrefix(kvA.Key, types.DTagTransferRequestsPrefix): var requestsA, requestsB keeper.WrappedDTagTransferRequests cdc.MustUnmarshalBinaryBare(kvA.Value, &requestsA) diff --git a/x/profiles/simulation/decoder_test.go b/x/profiles/simulation/decoder_test.go index 2bd59ba30e..10dee74962 100644 --- a/x/profiles/simulation/decoder_test.go +++ b/x/profiles/simulation/decoder_test.go @@ -3,7 +3,6 @@ package simulation_test import ( "fmt" "testing" - "time" "github.com/cosmos/cosmos-sdk/types/kv" @@ -11,7 +10,6 @@ import ( "github.com/desmos-labs/desmos/x/profiles/keeper" "github.com/stretchr/testify/require" - "github.com/tendermint/tendermint/crypto/ed25519" "github.com/desmos-labs/desmos/x/profiles/simulation" "github.com/desmos-labs/desmos/x/profiles/types" @@ -21,32 +19,17 @@ func TestDecodeStore(t *testing.T) { cdc, _ := app.MakeCodecs() dec := simulation.NewDecodeStore(cdc) - profile := types.NewProfile( - "leoDiCap", - "", - "Hollywood Actor. Proud environmentalist", - types.NewPictures("", ""), - time.Time{}, - ed25519.GenPrivKey().PubKey().Address().String(), - ) - requests := keeper.NewWrappedDTagTransferRequests([]types.DTagTransferRequest{ - types.NewDTagTransferRequest("dtag", profile.Creator, profile.Creator), + types.NewDTagTransferRequest( + "dtag", + "cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns", + "cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns", + ), }) - owner := keeper.NewWrappedDTagOwner(profile.Creator) - kvPairs := kv.Pairs{Pairs: []kv.Pair{ { - Key: types.ProfileStoreKey(profile.Creator), - Value: cdc.MustMarshalBinaryBare(&profile), - }, - { - Key: types.DtagStoreKey(profile.Dtag), - Value: cdc.MustMarshalBinaryBare(&owner), - }, - { - Key: types.DtagTransferRequestStoreKey(profile.Creator), + Key: types.DtagTransferRequestStoreKey("cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns"), Value: cdc.MustMarshalBinaryBare(&requests), }, }} @@ -55,8 +38,6 @@ func TestDecodeStore(t *testing.T) { name string expectedLog string }{ - {"Profile", fmt.Sprintf("ProfileA: %s\nProfileB: %s\n", profile, profile)}, - {"Address", fmt.Sprintf("AddressA: %s\nAddressB: %s\n", profile.Creator, profile.Creator)}, {"Requests", fmt.Sprintf("RequestsA: %s\nRequestsB: %s\n", requests.Requests, requests.Requests)}, {"other", ""}, } diff --git a/x/profiles/simulation/genesis.go b/x/profiles/simulation/genesis.go index 330d86d44f..024282e5c7 100644 --- a/x/profiles/simulation/genesis.go +++ b/x/profiles/simulation/genesis.go @@ -5,6 +5,8 @@ package simulation import ( "fmt" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/types/module" @@ -53,13 +55,21 @@ func randomDTagTransferRequests(simState *module.SimulationState) []types.DTagTr } // randomProfiles returns randomly generated genesis profiles -func randomProfiles(simState *module.SimulationState) (accounts []types.Profile) { - accountsNumber := simState.Rand.Intn(50) +func randomProfiles(simState *module.SimulationState) []types.Profile { + var authstate authtypes.GenesisState + simState.Cdc.MustUnmarshalJSON(simState.GenState[authtypes.ModuleName], &authstate) - accounts = make([]types.Profile, accountsNumber) - for i := 0; i < accountsNumber; i++ { - simAccount, _ := simtypes.RandomAcc(simState.Rand, simState.Accounts) - accounts[i] = NewRandomProfile(simState.Rand, simAccount.Address) + genAccounts, err := authtypes.UnpackAccounts(authstate.Accounts) + if err != nil { + panic(err) + } + genAccounts = authtypes.SanitizeGenesisAccounts(genAccounts) + + var accounts []types.Profile + var accountsNumber = simState.Rand.Intn(len(genAccounts)) + for len(accounts) < accountsNumber { + authAccount := genAccounts[simState.Rand.Intn(len(genAccounts))] + accounts = append(accounts, NewRandomProfile(simState.Rand, authAccount)) } return accounts diff --git a/x/profiles/simulation/operations_dtag_transfer.go b/x/profiles/simulation/operations_dtag_transfer.go index 76ad6a6a2a..f6a7e500ee 100644 --- a/x/profiles/simulation/operations_dtag_transfer.go +++ b/x/profiles/simulation/operations_dtag_transfer.go @@ -29,7 +29,7 @@ func SimulateMsgRequestDTagTransfer( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (OperationMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) { - sender, request, skip := randomDtagRequestTransferFields(r, ctx, accs, k) + sender, request, skip := randomDtagRequestTransferFields(r, ctx, accs, k, ak) if skip { return simtypes.NoOpMsg(types.RouterKey, types.ModuleName, ""), nil, nil } @@ -84,7 +84,7 @@ func sendMsgRequestDTagTransfer( // randomDtagRequestTransferFields returns random dTagRequest data func randomDtagRequestTransferFields( - r *rand.Rand, ctx sdk.Context, accs []simtypes.Account, k keeper.Keeper, + r *rand.Rand, ctx sdk.Context, accs []simtypes.Account, k keeper.Keeper, ak authkeeper.AccountKeeper, ) (simtypes.Account, types.DTagTransferRequest, bool) { if len(accs) == 0 { return simtypes.Account{}, types.DTagTransferRequest{}, true @@ -94,7 +94,7 @@ func randomDtagRequestTransferFields( receiver, _ := simtypes.RandomAcc(r, accs) sender, _ := simtypes.RandomAcc(r, accs) - // skip if the two addresses are equals + // Skip if the two addresses are equals if receiver.Equals(sender) { return simtypes.Account{}, types.DTagTransferRequest{}, true } @@ -111,7 +111,7 @@ func randomDtagRequestTransferFields( "", types.NewPictures("", ""), ctx.BlockTime(), - receiver.Address.String(), + ak.GetAccount(ctx, receiver.Address), )) // skip if requests already exists @@ -135,7 +135,7 @@ func SimulateMsgAcceptDTagTransfer( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (OperationMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) { - acc, request, dtag, skip := randomDtagAcceptRequestTransferFields(r, ctx, accs, k) + acc, request, dtag, skip := randomDtagAcceptRequestTransferFields(r, ctx, accs, k, ak) if skip { return simtypes.NoOpMsg(types.RouterKey, types.ModuleName, ""), nil, nil } @@ -194,7 +194,7 @@ func sendMsgMsgAcceptDTagTransfer( // randomDtagAcceptRequestTransferFields returns random dTagRequest data and a random dTag func randomDtagAcceptRequestTransferFields( - r *rand.Rand, ctx sdk.Context, accs []simtypes.Account, k keeper.Keeper, + r *rand.Rand, ctx sdk.Context, accs []simtypes.Account, k keeper.Keeper, ak authkeeper.AccountKeeper, ) (simtypes.Account, types.DTagTransferRequest, string, bool) { if len(accs) == 0 { return simtypes.Account{}, types.DTagTransferRequest{}, "", true @@ -229,7 +229,7 @@ func randomDtagAcceptRequestTransferFields( return simtypes.Account{}, types.DTagTransferRequest{}, "", true } - profile := NewRandomProfile(r, sender.Address) + profile := NewRandomProfile(r, ak.GetAccount(ctx, sender.Address)) profile.Dtag = "dtag" err := k.ValidateProfile(ctx, profile) diff --git a/x/profiles/simulation/operations_profile.go b/x/profiles/simulation/operations_profile.go index 44bf2c812d..07df29ea84 100644 --- a/x/profiles/simulation/operations_profile.go +++ b/x/profiles/simulation/operations_profile.go @@ -30,7 +30,7 @@ func SimulateMsgSaveProfile( accs []simtypes.Account, chainID string, ) (OperationMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) { - acc, data, skip := randomProfileSaveFields(r, ctx, accs, k) + acc, data, skip := randomProfileSaveFields(r, ctx, accs, k, ak) if skip { return simtypes.NoOpMsg(types.RouterKey, types.ModuleName, ""), nil, nil } @@ -91,7 +91,7 @@ func sendMsgSaveProfile( // randomProfileSaveFields returns random profile data func randomProfileSaveFields( - r *rand.Rand, ctx sdk.Context, accs []simtypes.Account, k keeper.Keeper, + r *rand.Rand, ctx sdk.Context, accs []simtypes.Account, k keeper.Keeper, ak authkeeper.AccountKeeper, ) (simtypes.Account, types.Profile, bool) { if len(accs) == 0 { return simtypes.Account{}, types.Profile{}, true @@ -99,14 +99,19 @@ func randomProfileSaveFields( // Get a random account account, _ := simtypes.RandomAcc(r, accs) + acc := ak.GetAccount(ctx, account.Address) // See if there is already the profile, otherwise create it from scratch var profile types.Profile - existing, found := k.GetProfile(ctx, account.Address.String()) + existing, found, err := k.GetProfile(ctx, account.Address.String()) + if err != nil { + return simtypes.Account{}, types.Profile{}, true + } + if found { profile = existing } else { - profile = NewRandomProfile(r, account.Address) + profile = NewRandomProfile(r, acc) } // 50% chance of changing something @@ -117,9 +122,8 @@ func randomProfileSaveFields( RandomBio(r), types.NewPictures(RandomProfilePic(r), RandomProfileCover(r)), profile.CreationDate, - profile.Creator, + acc, )) - } return account, profile, false @@ -197,14 +201,18 @@ func randomProfileDeleteFields( return simtypes.Account{}, true } - accounts := k.GetProfiles(ctx) + var accounts []types.Profile + k.IterateProfiles(ctx, func(index int64, profile types.Profile) (stop bool) { + accounts = append(accounts, profile) + return false + }) if len(accounts) == 0 { return simtypes.Account{}, true } account := RandomProfile(r, accounts) - addr, _ := sdk.AccAddressFromBech32(account.Creator) + addr, _ := sdk.AccAddressFromBech32(account.BaseAccount.Address) acc := GetSimAccount(addr, accs) // Skip the operation without error as the profile is not valid diff --git a/x/profiles/simulation/utils.go b/x/profiles/simulation/utils.go index e0e76f2192..0fd8abfc97 100644 --- a/x/profiles/simulation/utils.go +++ b/x/profiles/simulation/utils.go @@ -6,6 +6,8 @@ import ( "math/rand" "time" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" sdk "github.com/cosmos/cosmos-sdk/types" @@ -46,14 +48,14 @@ var ( // NewRandomProfile return a random ProfileData from random data and the given account // nolint:interfacer -func NewRandomProfile(r *rand.Rand, account sdk.AccAddress) types.Profile { +func NewRandomProfile(r *rand.Rand, account authtypes.AccountI) types.Profile { return types.NewProfile( RandomDTag(r), RandomMoniker(r), RandomBio(r), types.NewPictures(RandomProfilePic(r), RandomProfileCover(r)), time.Now(), - account.String(), + account, ) } diff --git a/x/profiles/types/codec.go b/x/profiles/types/codec.go index c833129b6c..b820343633 100644 --- a/x/profiles/types/codec.go +++ b/x/profiles/types/codec.go @@ -6,6 +6,7 @@ import ( cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { @@ -15,9 +16,16 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(MsgCancelDTagTransfer{}, "desmos/MsgCancelDTagTransfer", nil) cdc.RegisterConcrete(MsgAcceptDTagTransfer{}, "desmos/MsgAcceptDTagTransfer", nil) cdc.RegisterConcrete(MsgRefuseDTagTransfer{}, "desmos/MsgRefuseDTagTransfer", nil) + + cdc.RegisterConcrete(&Profile{}, "desmos/Profile", nil) } func RegisterInterfaces(registry types.InterfaceRegistry) { + registry.RegisterImplementations( + (*authtypes.AccountI)(nil), + &Profile{}, + ) + registry.RegisterImplementations((*sdk.Msg)(nil), &MsgSaveProfile{}, &MsgDeleteProfile{}, diff --git a/x/profiles/types/genesis.go b/x/profiles/types/genesis.go index 5fbc305a51..2be7f7010e 100644 --- a/x/profiles/types/genesis.go +++ b/x/profiles/types/genesis.go @@ -59,7 +59,7 @@ func ValidateGenesis(data *GenesisState) error { func containDuplicates(profiles []Profile, profile Profile) bool { var count = 0 for _, p := range profiles { - if p.Equal(profile) { + if p.Address == profile.Address || p.Dtag == profile.Dtag { count++ } } @@ -69,7 +69,7 @@ func containDuplicates(profiles []Profile, profile Profile) bool { // profileExists tells whether the given profiles slice contain a profile associated to the given address func profileExists(profiles []Profile, address string) bool { for _, profile := range profiles { - if profile.Creator == address { + if profile.BaseAccount.Address == address { return true } } diff --git a/x/profiles/types/genesis_test.go b/x/profiles/types/genesis_test.go index d1535f15db..c587cdc91a 100644 --- a/x/profiles/types/genesis_test.go +++ b/x/profiles/types/genesis_test.go @@ -4,6 +4,8 @@ import ( "testing" "time" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" @@ -14,6 +16,9 @@ func TestValidateGenesis(t *testing.T) { date, err := time.Parse(time.RFC3339, "2010-10-02T12:10:00.000Z") require.NoError(t, err) + addr1, _ := sdk.AccAddressFromBech32("cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47") + addr2, _ := sdk.AccAddressFromBech32("cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns") + tests := []struct { name string genesis *types.GenesisState @@ -34,7 +39,7 @@ func TestValidateGenesis(t *testing.T) { "", types.NewPictures("", ""), date, - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + authtypes.NewBaseAccountWithAddress(addr1), ), // An empty tag should return an error }, nil, @@ -52,7 +57,7 @@ func TestValidateGenesis(t *testing.T) { "biography", types.NewPictures("https://test.com/profile-pic", "https://test.com/cover-pic"), date, - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + authtypes.NewBaseAccountWithAddress(addr1), ), }, nil, @@ -77,14 +82,14 @@ func TestValidateGenesis(t *testing.T) { "https://test.com/cover-pic", ), date, - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + authtypes.NewBaseAccountWithAddress(addr1), ), }, []types.DTagTransferRequest{ types.NewDTagTransferRequest( "dtag", "", - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + addr1.String(), ), }, types.DefaultParams(), @@ -104,7 +109,7 @@ func TestValidateGenesis(t *testing.T) { "https://test.com/cover-pic", ), date, - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + authtypes.NewBaseAccountWithAddress(addr1), ), types.NewProfile( "custom_dtag2", @@ -115,13 +120,13 @@ func TestValidateGenesis(t *testing.T) { "https://test.com/cover-pic", ), date, - "cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns", + authtypes.NewBaseAccountWithAddress(addr2), ), }, []types.DTagTransferRequest{ types.NewDTagTransferRequest( "dtag", - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + addr1.String(), "cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns", ), }, @@ -142,13 +147,13 @@ func TestValidateGenesis(t *testing.T) { "https://test.com/cover-pic", ), date, - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + authtypes.NewBaseAccountWithAddress(addr1), ), }, []types.DTagTransferRequest{ types.NewDTagTransferRequest( "dtag", - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + addr1.String(), "cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns", ), }, diff --git a/x/profiles/types/keys.go b/x/profiles/types/keys.go index 9727a3057f..20eb4e6eba 100644 --- a/x/profiles/types/keys.go +++ b/x/profiles/types/keys.go @@ -23,21 +23,9 @@ const ( ) var ( - ProfileStorePrefix = []byte("profile") - DtagStorePrefix = []byte("dtag") DTagTransferRequestsPrefix = []byte("transfer_requests") ) -// ProfileStoreKey turns an address to a key used to store a profile into the profiles store -func ProfileStoreKey(address string) []byte { - return append(ProfileStorePrefix, address...) -} - -// DtagStoreKey turns a dtag to a key used to store a dtag -> address couple -func DtagStoreKey(dtag string) []byte { - return append(DtagStorePrefix, []byte(dtag)...) -} - // DtagTransferRequestStoreKey turns an address to a key used to store a transfer request into the profiles store func DtagTransferRequestStoreKey(address string) []byte { return append(DTagTransferRequestsPrefix, address...) diff --git a/x/profiles/types/models.go b/x/profiles/types/models.go index 47744fe43b..43a80b9e70 100644 --- a/x/profiles/types/models.go +++ b/x/profiles/types/models.go @@ -5,6 +5,8 @@ import ( "strings" "time" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/desmos-labs/desmos/x/commons" @@ -40,14 +42,23 @@ func (pic Pictures) Validate() error { // ___________________________________________________________________________________________________________________ // NewProfile builds a new profile having the given dtag, creator and creation date -func NewProfile(dtag string, moniker, bio string, pictures Pictures, creationDate time.Time, creator string) Profile { +func NewProfile( + dtag string, moniker, bio string, pictures Pictures, creationDate time.Time, account authtypes.AccountI, +) Profile { + // TODO: We should remove this when the following Cosmos issues is resolved + // https://github.com/cosmos/cosmos-sdk/issues/8876 + baseAcc, ok := account.(*authtypes.BaseAccount) + if baseAcc != nil && !ok { + panic(fmt.Errorf("invalid account type")) + } + return Profile{ Dtag: dtag, Moniker: moniker, Bio: bio, Pictures: pictures, - Creator: creator, CreationDate: creationDate, + BaseAccount: baseAcc, } } @@ -78,11 +89,11 @@ func (profile Profile) Update(p2 Profile) (Profile, error) { p2.CreationDate = profile.CreationDate } - if p2.Creator == DoNotModify { - p2.Creator = profile.Creator + if p2.BaseAccount == nil { + p2.BaseAccount = profile.BaseAccount } - newProfile := NewProfile(p2.Dtag, p2.Moniker, p2.Bio, p2.Pictures, p2.CreationDate, p2.Creator) + newProfile := NewProfile(p2.Dtag, p2.Moniker, p2.Bio, p2.Pictures, p2.CreationDate, p2.BaseAccount) err := newProfile.Validate() if err != nil { return Profile{}, err @@ -92,7 +103,7 @@ func (profile Profile) Update(p2 Profile) (Profile, error) { } // Validate check the validity of the Profile -func (profile Profile) Validate() error { +func (profile *Profile) Validate() error { if strings.TrimSpace(profile.Dtag) == "" || profile.Dtag == DoNotModify { return fmt.Errorf("invalid profile DTag: %s", profile.Dtag) } @@ -113,9 +124,14 @@ func (profile Profile) Validate() error { return fmt.Errorf("invalid profile cover: %s", profile.Pictures.Cover) } - _, err := sdk.AccAddressFromBech32(profile.Creator) + _, err := sdk.AccAddressFromBech32(profile.BaseAccount.Address) + if err != nil { + return fmt.Errorf("invalid address: %s", profile.BaseAccount.Address) + } + + err = profile.BaseAccount.Validate() if err != nil { - return fmt.Errorf("invalid creator address: %s", profile.Creator) + return fmt.Errorf("invalid account: %s", err.Error()) } return profile.Pictures.Validate() diff --git a/x/profiles/types/models.pb.go b/x/profiles/types/models.pb.go index 5c5eadd7e0..a256bac6b3 100644 --- a/x/profiles/types/models.pb.go +++ b/x/profiles/types/models.pb.go @@ -5,6 +5,7 @@ package types import ( fmt "fmt" + types "github.com/cosmos/cosmos-sdk/x/auth/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" @@ -83,17 +84,16 @@ func (m *Pictures) GetCover() string { // Profile represents a generic first on Desmos, containing the information of a // single user type Profile struct { - Dtag string `protobuf:"bytes,1,opt,name=dtag,proto3" json:"dtag,omitempty" yaml:"dtag"` - Moniker string `protobuf:"bytes,2,opt,name=moniker,proto3" json:"moniker,omitempty" yaml:"moniker"` - Bio string `protobuf:"bytes,3,opt,name=bio,proto3" json:"bio,omitempty" yaml:"bio"` - Pictures Pictures `protobuf:"bytes,4,opt,name=pictures,proto3" json:"pictures" yaml:"pictures"` - Creator string `protobuf:"bytes,5,opt,name=creator,proto3" json:"creator,omitempty" yaml:"creator"` - CreationDate time.Time `protobuf:"bytes,6,opt,name=creation_date,json=creationDate,proto3,stdtime" json:"creation_date" yaml:"creation_date"` + *types.BaseAccount `protobuf:"bytes,1,opt,name=base_account,json=baseAccount,proto3,embedded=base_account" json:"base_account,omitempty"` + Dtag string `protobuf:"bytes,2,opt,name=dtag,proto3" json:"dtag,omitempty" yaml:"dtag"` + Moniker string `protobuf:"bytes,3,opt,name=moniker,proto3" json:"moniker,omitempty" yaml:"moniker"` + Bio string `protobuf:"bytes,4,opt,name=bio,proto3" json:"bio,omitempty" yaml:"bio"` + Pictures Pictures `protobuf:"bytes,5,opt,name=pictures,proto3" json:"pictures" yaml:"pictures"` + CreationDate time.Time `protobuf:"bytes,6,opt,name=creation_date,json=creationDate,proto3,stdtime" json:"creation_date" yaml:"creation_date"` } -func (m *Profile) Reset() { *m = Profile{} } -func (m *Profile) String() string { return proto.CompactTextString(m) } -func (*Profile) ProtoMessage() {} +func (m *Profile) Reset() { *m = Profile{} } +func (*Profile) ProtoMessage() {} func (*Profile) Descriptor() ([]byte, []int) { return fileDescriptor_dcbf89d5cd53a9ca, []int{1} } @@ -124,48 +124,6 @@ func (m *Profile) XXX_DiscardUnknown() { var xxx_messageInfo_Profile proto.InternalMessageInfo -func (m *Profile) GetDtag() string { - if m != nil { - return m.Dtag - } - return "" -} - -func (m *Profile) GetMoniker() string { - if m != nil { - return m.Moniker - } - return "" -} - -func (m *Profile) GetBio() string { - if m != nil { - return m.Bio - } - return "" -} - -func (m *Profile) GetPictures() Pictures { - if m != nil { - return m.Pictures - } - return Pictures{} -} - -func (m *Profile) GetCreator() string { - if m != nil { - return m.Creator - } - return "" -} - -func (m *Profile) GetCreationDate() time.Time { - if m != nil { - return m.CreationDate - } - return time.Time{} -} - // DTagTransferRequest represent a dtag transfer request between two users type DTagTransferRequest struct { DtagToTrade string `protobuf:"bytes,1,opt,name=dtag_to_trade,json=dtagToTrade,proto3" json:"dtag_to_trade,omitempty" yaml:"dtag_to_trade"` @@ -238,40 +196,43 @@ func init() { } var fileDescriptor_dcbf89d5cd53a9ca = []byte{ - // 522 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x93, 0x31, 0x6f, 0x13, 0x3f, - 0x18, 0xc6, 0x73, 0xff, 0xb4, 0x69, 0xfe, 0x4e, 0xd3, 0xc2, 0xb5, 0x52, 0x4f, 0x19, 0xce, 0xc1, - 0x20, 0x54, 0x24, 0xf0, 0x29, 0xb0, 0x55, 0x4c, 0x51, 0x07, 0xc6, 0xca, 0x8a, 0x18, 0x58, 0x22, - 0x5f, 0xce, 0x39, 0x0e, 0x72, 0xf1, 0x61, 0x3b, 0x15, 0x5d, 0xf9, 0x04, 0x1d, 0x19, 0xfb, 0x35, - 0xf8, 0x06, 0x1d, 0x3b, 0x32, 0x1d, 0x28, 0x59, 0x10, 0xe3, 0x7d, 0x02, 0xe4, 0xb3, 0x9d, 0xa4, - 0x48, 0x6c, 0xf6, 0xfb, 0xfc, 0xde, 0x7b, 0x9f, 0xbc, 0x8f, 0x03, 0x9e, 0x24, 0x4c, 0xe6, 0x5c, - 0x46, 0x85, 0xe0, 0xd3, 0x6c, 0xc6, 0x64, 0x74, 0x39, 0x88, 0x99, 0xa2, 0x83, 0x28, 0xe7, 0x09, - 0x9b, 0x49, 0x5c, 0x08, 0xae, 0xb8, 0x7f, 0x62, 0x28, 0xec, 0x28, 0x6c, 0xa9, 0xde, 0x71, 0xca, - 0x53, 0x5e, 0x33, 0x91, 0x3e, 0x19, 0xbc, 0x07, 0x53, 0xce, 0xd3, 0x19, 0x8b, 0xea, 0x5b, 0xbc, - 0x98, 0x46, 0x2a, 0xcb, 0x99, 0x54, 0x34, 0x2f, 0x0c, 0x80, 0x3e, 0x80, 0xf6, 0x45, 0x36, 0x51, - 0x0b, 0xc1, 0xa4, 0xff, 0x1c, 0xec, 0xd9, 0xcf, 0x06, 0x5e, 0xdf, 0x3b, 0xfd, 0x7f, 0xe8, 0x57, - 0x25, 0x3c, 0xb8, 0xa2, 0xf9, 0xec, 0x0c, 0x59, 0x01, 0x11, 0x87, 0xf8, 0x4f, 0xc1, 0xee, 0x84, - 0x5f, 0x32, 0x11, 0xfc, 0x57, 0xb3, 0x0f, 0xaa, 0x12, 0xee, 0x1b, 0xb6, 0x2e, 0x23, 0x62, 0xe4, - 0xb3, 0xf6, 0xd7, 0x1b, 0xe8, 0xfd, 0xba, 0x81, 0x1e, 0xfa, 0xd2, 0x04, 0x7b, 0x17, 0xb6, 0xfb, - 0x31, 0xd8, 0x49, 0x14, 0x4d, 0xed, 0xa0, 0xc3, 0xaa, 0x84, 0x1d, 0xd3, 0xac, 0xab, 0x88, 0xd4, - 0xa2, 0x36, 0x94, 0xf3, 0x79, 0xf6, 0x71, 0x3d, 0x64, 0xcb, 0x90, 0x15, 0x10, 0x71, 0x88, 0xdf, - 0x07, 0xcd, 0x38, 0xe3, 0x41, 0xb3, 0x26, 0x0f, 0xaa, 0x12, 0x02, 0x43, 0xc6, 0x19, 0x47, 0x44, - 0x4b, 0xfe, 0x5b, 0xd0, 0x2e, 0xec, 0x8f, 0x0d, 0x76, 0xfa, 0xde, 0x69, 0xe7, 0xe5, 0x23, 0xfc, - 0x8f, 0x7d, 0x62, 0xb7, 0x95, 0xe1, 0xc9, 0x6d, 0x09, 0x1b, 0x55, 0x09, 0x0f, 0xed, 0x22, 0x6c, - 0x1d, 0x91, 0xf5, 0xb7, 0xb4, 0xcf, 0x89, 0x60, 0x54, 0x71, 0x11, 0xec, 0xfe, 0xed, 0xd3, 0x0a, - 0x88, 0x38, 0xc4, 0x17, 0xa0, 0x5b, 0x1f, 0x33, 0x3e, 0x1f, 0x27, 0x54, 0xb1, 0xa0, 0x55, 0x5b, - 0xe9, 0x61, 0x93, 0x15, 0x76, 0x59, 0xe1, 0x91, 0xcb, 0x6a, 0x38, 0xd0, 0x1e, 0x7e, 0x97, 0xf0, - 0x7e, 0x63, 0x55, 0xc2, 0xe3, 0xad, 0x21, 0xae, 0x8c, 0xae, 0x7f, 0x40, 0x8f, 0xec, 0xbb, 0xda, - 0x39, 0x55, 0x6c, 0x2b, 0x84, 0x6f, 0x1e, 0x38, 0x3a, 0x1f, 0xd1, 0x74, 0x24, 0xe8, 0x5c, 0x4e, - 0x99, 0x20, 0xec, 0xd3, 0x82, 0x49, 0xe5, 0xbf, 0x06, 0x5d, 0xbd, 0xf3, 0xb1, 0xe2, 0x63, 0x25, - 0x68, 0xe2, 0x9e, 0x40, 0xb0, 0x19, 0x72, 0x4f, 0x46, 0xa4, 0xa3, 0xef, 0x23, 0x3e, 0xd2, 0x37, - 0xff, 0x19, 0x68, 0x49, 0x36, 0x4f, 0xd6, 0x41, 0x3d, 0xac, 0x4a, 0xd8, 0x35, 0x6d, 0xa6, 0x8e, - 0x88, 0x05, 0xfc, 0x08, 0xb4, 0x05, 0x9b, 0xb0, 0x4c, 0x3f, 0x1d, 0x93, 0xd5, 0xd1, 0x66, 0xbb, - 0x4e, 0x41, 0x64, 0x0d, 0x6d, 0xbc, 0x0f, 0xdf, 0xdc, 0x2e, 0x43, 0xef, 0x6e, 0x19, 0x7a, 0x3f, - 0x97, 0xa1, 0x77, 0xbd, 0x0a, 0x1b, 0x77, 0xab, 0xb0, 0xf1, 0x7d, 0x15, 0x36, 0xde, 0xe1, 0x34, - 0x53, 0xef, 0x17, 0x31, 0x9e, 0xf0, 0x3c, 0x32, 0x89, 0xbe, 0x98, 0xd1, 0x58, 0xda, 0x73, 0xf4, - 0x79, 0xf3, 0xaf, 0x52, 0x57, 0x05, 0x93, 0x71, 0xab, 0x5e, 0xf2, 0xab, 0x3f, 0x01, 0x00, 0x00, - 0xff, 0xff, 0x80, 0xa2, 0xf5, 0x9a, 0x75, 0x03, 0x00, 0x00, + // 564 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x93, 0x3f, 0x8f, 0xd3, 0x30, + 0x18, 0xc6, 0x13, 0xee, 0x5f, 0x71, 0xef, 0x0f, 0xe4, 0x4e, 0xba, 0xa8, 0x43, 0x5c, 0x0c, 0x42, + 0x20, 0x81, 0xa3, 0xc2, 0x56, 0xb1, 0x10, 0xdd, 0x00, 0xdb, 0xc9, 0xaa, 0x18, 0x58, 0x2a, 0x27, + 0x71, 0x73, 0x81, 0xa6, 0x2e, 0xb1, 0x53, 0x71, 0xdf, 0x80, 0xf1, 0xc6, 0xdb, 0xe8, 0xd7, 0xe0, + 0x1b, 0xdc, 0xd8, 0x91, 0x29, 0xa0, 0x76, 0x41, 0x8c, 0xf9, 0x04, 0x28, 0xb6, 0xd3, 0x72, 0x48, + 0x6c, 0xf1, 0xf3, 0xfc, 0xec, 0xf7, 0xf5, 0xfb, 0x38, 0xe0, 0x51, 0xcc, 0x44, 0xc6, 0x85, 0x3f, + 0xcd, 0xf9, 0x28, 0x1d, 0x33, 0xe1, 0xcf, 0x7a, 0x21, 0x93, 0xb4, 0xe7, 0x67, 0x3c, 0x66, 0x63, + 0x81, 0xa7, 0x39, 0x97, 0xdc, 0x39, 0xd5, 0x14, 0x6e, 0x28, 0x6c, 0xa8, 0xce, 0x49, 0xc2, 0x13, + 0xae, 0x18, 0xbf, 0xfe, 0xd2, 0x78, 0x07, 0x26, 0x9c, 0x27, 0x63, 0xe6, 0xab, 0x55, 0x58, 0x8c, + 0x7c, 0x99, 0x66, 0x4c, 0x48, 0x9a, 0x4d, 0x0d, 0xe0, 0x45, 0x5c, 0x55, 0xa5, 0x85, 0xbc, 0x58, + 0x57, 0xac, 0x17, 0xda, 0x47, 0x1f, 0x40, 0xeb, 0x3c, 0x8d, 0x64, 0x91, 0x33, 0xe1, 0x3c, 0x03, + 0x7b, 0xa6, 0xac, 0x6b, 0x77, 0xed, 0x27, 0x77, 0x03, 0xa7, 0x2a, 0xe1, 0xe1, 0x25, 0xcd, 0xc6, + 0x7d, 0x64, 0x0c, 0x44, 0x1a, 0xc4, 0x79, 0x0c, 0x76, 0x22, 0x3e, 0x63, 0xb9, 0x7b, 0x47, 0xb1, + 0xf7, 0xaa, 0x12, 0xee, 0x6b, 0x56, 0xc9, 0x88, 0x68, 0xbb, 0xdf, 0xba, 0x9e, 0x43, 0xfb, 0xd7, + 0x1c, 0xda, 0xe8, 0xeb, 0x16, 0xd8, 0x3b, 0x37, 0xbb, 0xdf, 0x82, 0xfd, 0x90, 0x0a, 0x36, 0xa4, + 0x51, 0xc4, 0x8b, 0x89, 0x54, 0x05, 0xdb, 0x2f, 0xba, 0x58, 0xb7, 0x8b, 0x55, 0x87, 0xa6, 0x5d, + 0x1c, 0x50, 0xc1, 0x5e, 0x6b, 0x2e, 0xd8, 0x5e, 0x94, 0xd0, 0x26, 0xed, 0x70, 0x23, 0x39, 0x0f, + 0xc1, 0x76, 0x2c, 0x69, 0x62, 0xfa, 0x38, 0xaa, 0x4a, 0xd8, 0xd6, 0x7d, 0xd4, 0x2a, 0x22, 0xca, + 0xac, 0xef, 0x96, 0xf1, 0x49, 0xfa, 0x91, 0xe5, 0xee, 0xd6, 0xbf, 0x77, 0x33, 0x06, 0x22, 0x0d, + 0xe2, 0x74, 0xc1, 0x56, 0x98, 0x72, 0x77, 0x5b, 0x91, 0x87, 0x55, 0x09, 0x81, 0x26, 0xc3, 0x94, + 0x23, 0x52, 0x5b, 0xce, 0x3b, 0xd0, 0x9a, 0x9a, 0xb9, 0xb9, 0x3b, 0xaa, 0xf7, 0x07, 0xf8, 0x3f, + 0xd1, 0xe1, 0x66, 0xc0, 0xc1, 0xe9, 0x4d, 0x09, 0xad, 0xaa, 0x84, 0x47, 0x66, 0xa6, 0x46, 0x47, + 0x64, 0x7d, 0x96, 0x93, 0x83, 0x83, 0x28, 0x67, 0x54, 0xa6, 0x7c, 0x32, 0x8c, 0xa9, 0x64, 0xee, + 0xae, 0x3a, 0xbc, 0x83, 0x75, 0xd0, 0xb8, 0x09, 0x1a, 0x0f, 0x9a, 0xa0, 0x83, 0x5e, 0x7d, 0xea, + 0xef, 0x12, 0xde, 0xde, 0x58, 0x95, 0xf0, 0xc4, 0xc4, 0xf1, 0xb7, 0x8c, 0xae, 0x7e, 0x40, 0x9b, + 0xec, 0x37, 0xda, 0x19, 0x95, 0xac, 0xdf, 0xfa, 0x32, 0x87, 0xd6, 0xf5, 0x1c, 0x5a, 0xe8, 0x9b, + 0x0d, 0x8e, 0xcf, 0x06, 0x34, 0x19, 0xe4, 0x74, 0x22, 0x46, 0x2c, 0x27, 0xec, 0x53, 0xc1, 0x84, + 0x74, 0x5e, 0x81, 0x83, 0x7a, 0x8a, 0x43, 0xc9, 0x87, 0x32, 0xa7, 0x71, 0xf3, 0x3e, 0xdc, 0x4d, + 0x91, 0x5b, 0x36, 0x22, 0xed, 0x7a, 0x3d, 0xe0, 0x83, 0x7a, 0xe5, 0x3c, 0x05, 0xbb, 0x82, 0x4d, + 0xe2, 0xf5, 0x53, 0xb9, 0x5f, 0x95, 0xf0, 0x40, 0x6f, 0xd3, 0x3a, 0x22, 0x06, 0x70, 0x7c, 0xd0, + 0xca, 0x59, 0xc4, 0xd2, 0xd9, 0x3a, 0xa7, 0xe3, 0xcd, 0xbc, 0x1a, 0x07, 0x91, 0x35, 0xb4, 0x79, + 0x5d, 0xc1, 0x9b, 0x9b, 0xa5, 0x67, 0x2f, 0x96, 0x9e, 0xfd, 0x73, 0xe9, 0xd9, 0x57, 0x2b, 0xcf, + 0x5a, 0xac, 0x3c, 0xeb, 0xfb, 0xca, 0xb3, 0xde, 0xe3, 0x24, 0x95, 0x17, 0x45, 0x88, 0x23, 0x9e, + 0xf9, 0x3a, 0xa3, 0xe7, 0x63, 0x1a, 0x0a, 0xf3, 0xed, 0x7f, 0xde, 0xfc, 0x92, 0xf2, 0x72, 0xca, + 0x44, 0xb8, 0xab, 0x86, 0xfc, 0xf2, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xd3, 0x97, 0x9b, 0xd3, + 0xb2, 0x03, 0x00, 0x00, } func (this *Pictures) Equal(that interface{}) bool { @@ -301,45 +262,6 @@ func (this *Pictures) Equal(that interface{}) bool { } return true } -func (this *Profile) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*Profile) - if !ok { - that2, ok := that.(Profile) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Dtag != that1.Dtag { - return false - } - if this.Moniker != that1.Moniker { - return false - } - if this.Bio != that1.Bio { - return false - } - if !this.Pictures.Equal(&that1.Pictures) { - return false - } - if this.Creator != that1.Creator { - return false - } - if !this.CreationDate.Equal(that1.CreationDate) { - return false - } - return true -} func (this *DTagTransferRequest) Equal(that interface{}) bool { if that == nil { return this == nil @@ -435,13 +357,6 @@ func (m *Profile) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintModels(dAtA, i, uint64(n1)) i-- dAtA[i] = 0x32 - if len(m.Creator) > 0 { - i -= len(m.Creator) - copy(dAtA[i:], m.Creator) - i = encodeVarintModels(dAtA, i, uint64(len(m.Creator))) - i-- - dAtA[i] = 0x2a - } { size, err := m.Pictures.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -451,26 +366,38 @@ func (m *Profile) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintModels(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x22 + dAtA[i] = 0x2a if len(m.Bio) > 0 { i -= len(m.Bio) copy(dAtA[i:], m.Bio) i = encodeVarintModels(dAtA, i, uint64(len(m.Bio))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x22 } if len(m.Moniker) > 0 { i -= len(m.Moniker) copy(dAtA[i:], m.Moniker) i = encodeVarintModels(dAtA, i, uint64(len(m.Moniker))) i-- - dAtA[i] = 0x12 + dAtA[i] = 0x1a } if len(m.Dtag) > 0 { i -= len(m.Dtag) copy(dAtA[i:], m.Dtag) i = encodeVarintModels(dAtA, i, uint64(len(m.Dtag))) i-- + dAtA[i] = 0x12 + } + if m.BaseAccount != nil { + { + size, err := m.BaseAccount.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintModels(dAtA, i, uint64(size)) + } + i-- dAtA[i] = 0xa } return len(dAtA) - i, nil @@ -554,6 +481,10 @@ func (m *Profile) Size() (n int) { } var l int _ = l + if m.BaseAccount != nil { + l = m.BaseAccount.Size() + n += 1 + l + sovModels(uint64(l)) + } l = len(m.Dtag) if l > 0 { n += 1 + l + sovModels(uint64(l)) @@ -568,10 +499,6 @@ func (m *Profile) Size() (n int) { } l = m.Pictures.Size() n += 1 + l + sovModels(uint64(l)) - l = len(m.Creator) - if l > 0 { - n += 1 + l + sovModels(uint64(l)) - } l = github_com_gogo_protobuf_types.SizeOfStdTime(m.CreationDate) n += 1 + l + sovModels(uint64(l)) return n @@ -752,9 +679,9 @@ func (m *Profile) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Dtag", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field BaseAccount", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowModels @@ -764,27 +691,31 @@ func (m *Profile) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthModels } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthModels } if postIndex > l { return io.ErrUnexpectedEOF } - m.Dtag = string(dAtA[iNdEx:postIndex]) + if m.BaseAccount == nil { + m.BaseAccount = &types.BaseAccount{} + } + if err := m.BaseAccount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Moniker", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Dtag", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -812,11 +743,11 @@ func (m *Profile) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Moniker = string(dAtA[iNdEx:postIndex]) + m.Dtag = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Bio", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Moniker", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -844,13 +775,13 @@ func (m *Profile) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Bio = string(dAtA[iNdEx:postIndex]) + m.Moniker = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Pictures", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Bio", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowModels @@ -860,30 +791,29 @@ func (m *Profile) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthModels } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthModels } if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Pictures.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.Bio = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 5: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Pictures", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowModels @@ -893,23 +823,24 @@ func (m *Profile) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthModels } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthModels } if postIndex > l { return io.ErrUnexpectedEOF } - m.Creator = string(dAtA[iNdEx:postIndex]) + if err := m.Pictures.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 6: if wireType != 2 { diff --git a/x/profiles/types/models_test.go b/x/profiles/types/models_test.go index ba508d6d4d..57bef144b7 100644 --- a/x/profiles/types/models_test.go +++ b/x/profiles/types/models_test.go @@ -5,6 +5,9 @@ import ( "testing" "time" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/desmos-labs/desmos/x/profiles/types" "github.com/stretchr/testify/require" @@ -42,6 +45,12 @@ func TestPictures_Validate(t *testing.T) { // ___________________________________________________________________________________________________________________ func TestProfile_Update(t *testing.T) { + addr1, err := sdk.AccAddressFromBech32("cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47") + require.NoError(t, err) + + addr2, err := sdk.AccAddressFromBech32("cosmos1pqcac4w0k8z4elysqppgce5vauzu5krew7jegg") + require.NoError(t, err) + tests := []struct { name string original types.Profile @@ -60,7 +69,7 @@ func TestProfile_Update(t *testing.T) { "https://example.com", ), time.Unix(100, 0), - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + authtypes.NewBaseAccountWithAddress(addr1), ), update: types.NewProfile( types.DoNotModify, @@ -68,7 +77,7 @@ func TestProfile_Update(t *testing.T) { types.DoNotModify, types.NewPictures(types.DoNotModify, types.DoNotModify), time.Time{}, - types.DoNotModify, + nil, ), expError: false, expProfile: types.NewProfile( @@ -80,7 +89,7 @@ func TestProfile_Update(t *testing.T) { "https://example.com", ), time.Unix(100, 0), - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + authtypes.NewBaseAccountWithAddress(addr1), ), }, { @@ -94,7 +103,7 @@ func TestProfile_Update(t *testing.T) { "https://example.com", ), time.Unix(100, 0), - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + authtypes.NewBaseAccountWithAddress(addr1), ), update: types.NewProfile( "dtag-2", @@ -105,7 +114,7 @@ func TestProfile_Update(t *testing.T) { "https://example.com/2", ), time.Unix(200, 0), - "cosmos1pqcac4w0k8z4elysqppgce5vauzu5krew7jegg", + authtypes.NewBaseAccountWithAddress(addr2), ), expError: false, expProfile: types.NewProfile( @@ -117,7 +126,7 @@ func TestProfile_Update(t *testing.T) { "https://example.com/2", ), time.Unix(200, 0), - "cosmos1pqcac4w0k8z4elysqppgce5vauzu5krew7jegg", + authtypes.NewBaseAccountWithAddress(addr2), ), }, { @@ -131,7 +140,7 @@ func TestProfile_Update(t *testing.T) { "https://example.com", ), time.Unix(100, 0), - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + authtypes.NewBaseAccountWithAddress(addr1), ), update: types.NewProfile( "dtag-2", @@ -139,7 +148,7 @@ func TestProfile_Update(t *testing.T) { "", types.NewPictures("", ""), time.Time{}, - "invalid-address", + authtypes.NewBaseAccountWithAddress(nil), ), expError: true, }, @@ -154,7 +163,7 @@ func TestProfile_Update(t *testing.T) { "https://example.com", ), time.Unix(100, 0), - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + authtypes.NewBaseAccountWithAddress(addr1), ), update: types.NewProfile( types.DoNotModify, @@ -162,7 +171,7 @@ func TestProfile_Update(t *testing.T) { "", types.NewPictures("", ""), time.Time{}, - types.DoNotModify, + nil, ), expError: false, expProfile: types.NewProfile( @@ -171,7 +180,7 @@ func TestProfile_Update(t *testing.T) { "", types.NewPictures("", ""), time.Unix(100, 0), - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + authtypes.NewBaseAccountWithAddress(addr1), ), }, } @@ -192,6 +201,9 @@ func TestProfile_Update(t *testing.T) { } func TestProfile_Validate(t *testing.T) { + addr1, err := sdk.AccAddressFromBech32("cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47") + require.NoError(t, err) + tests := []struct { name string account types.Profile @@ -208,9 +220,9 @@ func TestProfile_Validate(t *testing.T) { "https://shorturl.at/cgpyF", ), time.Now(), - "", + authtypes.NewBaseAccountWithAddress(nil), ), - expErr: fmt.Errorf("invalid creator address: "), + expErr: fmt.Errorf("invalid address: "), }, { name: "Empty profile DTag returns error", @@ -223,7 +235,7 @@ func TestProfile_Validate(t *testing.T) { "https://shorturl.at/cgpyF", ), time.Now(), - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + authtypes.NewBaseAccountWithAddress(addr1), ), expErr: fmt.Errorf("invalid profile DTag: "), }, @@ -235,7 +247,7 @@ func TestProfile_Validate(t *testing.T) { "bio", types.NewPictures("pic", "https://example.com"), time.Now(), - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + authtypes.NewBaseAccountWithAddress(addr1), ), expErr: fmt.Errorf("invalid profile picture uri provided"), }, @@ -247,7 +259,7 @@ func TestProfile_Validate(t *testing.T) { "bio", types.NewPictures("https://example.com", "cov"), time.Now(), - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + authtypes.NewBaseAccountWithAddress(addr1), ), expErr: fmt.Errorf("invalid profile cover uri provided"), }, @@ -259,7 +271,7 @@ func TestProfile_Validate(t *testing.T) { "", types.Pictures{}, time.Now(), - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + authtypes.NewBaseAccountWithAddress(addr1), ), expErr: fmt.Errorf("invalid profile moniker: %s", types.DoNotModify), }, @@ -271,7 +283,7 @@ func TestProfile_Validate(t *testing.T) { types.DoNotModify, types.Pictures{}, time.Now(), - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + authtypes.NewBaseAccountWithAddress(addr1), ), expErr: fmt.Errorf("invalid profile bio: %s", types.DoNotModify), }, @@ -283,7 +295,7 @@ func TestProfile_Validate(t *testing.T) { "", types.NewPictures(types.DoNotModify, ""), time.Now(), - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + authtypes.NewBaseAccountWithAddress(addr1), ), expErr: fmt.Errorf("invalid profile picture: %s", types.DoNotModify), }, @@ -295,7 +307,7 @@ func TestProfile_Validate(t *testing.T) { "", types.NewPictures("", types.DoNotModify), time.Now(), - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + authtypes.NewBaseAccountWithAddress(addr1), ), expErr: fmt.Errorf("invalid profile cover: %s", types.DoNotModify), }, @@ -307,7 +319,7 @@ func TestProfile_Validate(t *testing.T) { "", types.Pictures{}, time.Now(), - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + authtypes.NewBaseAccountWithAddress(addr1), ), expErr: nil, }, @@ -319,7 +331,7 @@ func TestProfile_Validate(t *testing.T) { "bio", types.NewPictures("https://shorturl.at/adnX3", "https://shorturl.at/cgpyF"), time.Now(), - "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + authtypes.NewBaseAccountWithAddress(addr1), ), expErr: nil, }, diff --git a/x/profiles/types/msgs_test.go b/x/profiles/types/msgs_test.go index d94a3a460b..dd704ce5f0 100644 --- a/x/profiles/types/msgs_test.go +++ b/x/profiles/types/msgs_test.go @@ -4,6 +4,8 @@ import ( "testing" "time" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/desmos-labs/desmos/x/profiles/types" @@ -12,6 +14,7 @@ import ( "github.com/stretchr/testify/require" ) +var addr, _ = sdk.AccAddressFromBech32("cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns") var testProfile = types.NewProfile( "dtag", "moniker", @@ -21,7 +24,7 @@ var testProfile = types.NewProfile( "https://shorturl.at/cgpyF", ), time.Unix(100, 0), - "cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns", + authtypes.NewBaseAccountWithAddress(addr), ) // ___________________________________________________________________________________________________________________ @@ -32,7 +35,7 @@ var msgEditProfile = types.NewMsgSaveProfile( testProfile.Bio, testProfile.Pictures.Profile, testProfile.Pictures.Cover, - testProfile.Creator, + testProfile.BaseAccount.Address, ) func TestMsgSaveProfile_Route(t *testing.T) { @@ -65,7 +68,7 @@ func TestMsgSaveProfile_ValidateBasic(t *testing.T) { }, { name: "Invalid empty dtag returns error", - msg: types.NewMsgSaveProfile("", "", "", "", "", testProfile.Creator), + msg: types.NewMsgSaveProfile("", "", "", "", "", testProfile.BaseAccount.Address), error: sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "profile dtag cannot be empty or blank"), }, { @@ -110,7 +113,7 @@ func TestMsgSaveProfile_GetSigners(t *testing.T) { // ___________________________________________________________________________________________________________________ var msgDeleteProfile = types.NewMsgDeleteProfile( - testProfile.Creator, + testProfile.BaseAccount.Address, ) func TestMsgDeleteProfile_Route(t *testing.T) { @@ -136,7 +139,7 @@ func TestMsgDeleteProfile_ValidateBasic(t *testing.T) { }, { name: "Valid message returns no error", - msg: types.NewMsgDeleteProfile(testProfile.Creator), + msg: types.NewMsgDeleteProfile(testProfile.BaseAccount.Address), error: nil, }, } From d833886f2c189b5f43b415829e0b6e55dce2e0f7 Mon Sep 17 00:00:00 2001 From: "riccardo.montagnin" Date: Fri, 19 Mar 2021 11:40:18 +0100 Subject: [PATCH 02/11] Changed the profile implementations Changed how the profiles are implemented, by including an *Any inside the Profile object, and making it implement the AccountI interface Signed-off-by: riccardo.montagnin --- go.mod | 2 + go.sum | 16 +- proto/desmos/profiles/v1beta1/genesis.proto | 13 +- proto/desmos/profiles/v1beta1/models.proto | 7 +- proto/desmos/profiles/v1beta1/query.proto | 5 +- x/profiles/client/cli/cli_test.go | 63 ++-- x/profiles/keeper/alias_functions.go | 14 +- x/profiles/keeper/alias_functions_test.go | 24 +- x/profiles/keeper/common_test.go | 14 +- x/profiles/keeper/genesis.go | 13 - x/profiles/keeper/grpc_query.go | 9 +- x/profiles/keeper/invariants.go | 8 +- x/profiles/keeper/invariants_test.go | 12 +- x/profiles/keeper/keeper.go | 18 +- x/profiles/keeper/keeper_test.go | 103 +++--- x/profiles/keeper/msgs_server.go | 16 +- x/profiles/keeper/msgs_server_test.go | 125 +++---- x/profiles/keeper/querier_test.go | 2 +- x/profiles/simulation/genesis.go | 24 -- .../simulation/operations_dtag_transfer.go | 14 +- x/profiles/simulation/operations_profile.go | 22 +- x/profiles/simulation/utils.go | 10 +- x/profiles/types/account.go | 246 ++++++++++++++ x/profiles/types/account_test.go | 310 ++++++++++++++++++ x/profiles/types/codec.go | 6 +- x/profiles/types/genesis.go | 30 +- x/profiles/types/genesis.pb.go | 102 ++---- x/profiles/types/genesis_test.go | 103 +----- x/profiles/types/models.go | 101 ------ x/profiles/types/models.pb.go | 106 +++--- x/profiles/types/models_test.go | 307 ----------------- x/profiles/types/msgs_test.go | 10 +- x/profiles/types/query.pb.go | 100 +++--- 33 files changed, 967 insertions(+), 988 deletions(-) create mode 100644 x/profiles/types/account.go create mode 100644 x/profiles/types/account_test.go diff --git a/go.mod b/go.mod index 8238fab588..28fda477de 100644 --- a/go.mod +++ b/go.mod @@ -6,12 +6,14 @@ require ( github.com/btcsuite/btcd v0.21.0-beta github.com/cosmos/cosmos-sdk v0.42.1 github.com/desmos-labs/Go-Emoji-Utils v1.1.1-0.20200515063516-9c493b11de3e + github.com/ghodss/yaml v1.0.0 github.com/gogo/protobuf v1.3.3 github.com/golang/protobuf v1.4.3 github.com/google/go-cmp v0.5.2 // indirect github.com/gorilla/mux v1.8.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/rakyll/statik v0.1.7 + github.com/regen-network/cosmos-proto v0.3.1 github.com/spf13/cast v1.3.1 github.com/spf13/cobra v1.1.1 github.com/spf13/viper v1.7.1 diff --git a/go.sum b/go.sum index 3667bb65da..1fa3509f0b 100644 --- a/go.sum +++ b/go.sum @@ -106,12 +106,10 @@ github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfc github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cosmos/cosmos-sdk v0.42.1 h1:/0SqvXdxbHBRUFRTLdiL4VYE18DMNXd2ONhC5d90EBQ= github.com/cosmos/cosmos-sdk v0.42.1/go.mod h1:xiLp1G8mumj82S5KLJGCAyeAlD+7VNomg/aRSJV12yk= -github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fjHb6JFYmeUnDORVwHNkDxaQ0ctCVU= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= github.com/cosmos/iavl v0.15.0-rc3.0.20201009144442-230e9bdf52cd/go.mod h1:3xOIaNNX19p0QrX0VqWa6voPRoJRGGYtny+DH8NEPvE= -github.com/cosmos/iavl v0.15.0-rc5 h1:AMKgaAjXwGANWv56NL4q4hV+a0puSkLYD6cCQAv3i44= github.com/cosmos/iavl v0.15.0-rc5/go.mod h1:WqoPL9yPTQ85QBMT45OOUzPxG/U/JcJoN7uMjgxke/I= github.com/cosmos/iavl v0.15.3 h1:xE9r6HW8GeKeoYJN4zefpljZ1oukVScP/7M8oj6SUts= github.com/cosmos/iavl v0.15.3/go.mod h1:OLjQiAQ4fGD2KDZooyJG9yz+p2ao2IAYSbke8mVvSA4= @@ -176,6 +174,7 @@ github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2 github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -230,7 +229,6 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= @@ -383,7 +381,6 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb github.com/mtibben/percent v0.2.1 h1:5gssi8Nqo8QU/r2pynCm+hBQHpkB/uNK7BJCFogWdzs= github.com/mtibben/percent v0.2.1/go.mod h1:KG9uO+SZkUp+VkRHsCdYQV3XSZrrSpR3O9ibNBTZrns= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= @@ -472,7 +469,6 @@ github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y8 github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= -github.com/prometheus/common v0.14.0 h1:RHRyE8UocrbjU+6UvRzwi6HjiDfxrrBU91TtbKzkGp4= github.com/prometheus/common v0.14.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= github.com/prometheus/common v0.15.0 h1:4fgOnadei3EZvgRwxJ7RMpG1k1pOZth5Pc13tyspaKM= github.com/prometheus/common v0.15.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= @@ -506,7 +502,6 @@ github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= -github.com/sasha-s/go-deadlock v0.2.0 h1:lMqc+fUb7RrFS3gQLtoQsJ7/6TV/pAIFvBsqX73DK8Y= github.com/sasha-s/go-deadlock v0.2.0/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZqiDbRupzT10= github.com/sasha-s/go-deadlock v0.2.1-0.20190427202633-1595213edefa h1:0U2s5loxrTy6/VgfVoLuVLFJcURKLH49ie0zSch7gh4= github.com/sasha-s/go-deadlock v0.2.1-0.20190427202633-1595213edefa/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM= @@ -559,7 +554,6 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -576,15 +570,11 @@ github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15/go.mod h1:z4YtwM github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E= github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= github.com/tendermint/tendermint v0.34.0-rc4/go.mod h1:yotsojf2C1QBOw4dZrTcxbyxmPUrT4hNuOQWX9XUwB4= -github.com/tendermint/tendermint v0.34.0-rc6 h1:SVuKGvvE22KxfuK8QUHctUrmOWJsncZSYXIYtcnoKN0= github.com/tendermint/tendermint v0.34.0-rc6/go.mod h1:ugzyZO5foutZImv0Iyx/gOFCX6mjJTgbLHTwi17VDVg= -github.com/tendermint/tendermint v0.34.0 h1:eXCfMgoqVSzrjzOj6clI9GAejcHH0LvOlRjpCmMJksU= github.com/tendermint/tendermint v0.34.0/go.mod h1:Aj3PIipBFSNO21r+Lq3TtzQ+uKESxkbA3yo/INM4QwQ= github.com/tendermint/tendermint v0.34.8 h1:PMWgUx47FrNTsfhxCWzoiIlVAC1SE9+WBlnsF9oQW0I= github.com/tendermint/tendermint v0.34.8/go.mod h1:JVuu3V1ZexOaZG8VJMRl8lnfrGw6hEB2TVnoUwKRbss= -github.com/tendermint/tm-db v0.6.2 h1:DOn8jwCdjJblrCFJbtonEIPD1IuJWpbRUUdR8GWE4RM= github.com/tendermint/tm-db v0.6.2/go.mod h1:GYtQ67SUvATOcoY8/+x6ylk8Qo02BQyLrAs+yAcLvGI= -github.com/tendermint/tm-db v0.6.3 h1:ZkhQcKnB8/2jr5EaZwGndN4owkPsGezW2fSisS9zGbg= github.com/tendermint/tm-db v0.6.3/go.mod h1:lfA1dL9/Y/Y8wwyPp2NMLyn5P5Ptr/gvDFNWtrCWSf8= github.com/tendermint/tm-db v0.6.4 h1:3N2jlnYQkXNQclQwd/eKV/NzlqPlfK21cpRRIx80XXQ= github.com/tendermint/tm-db v0.6.4/go.mod h1:dptYhIpJ2M5kUuenLr+Yyf3zQOv1SgBZcl8/BmWlMBw= @@ -634,7 +624,6 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 h1:pLI5jrR7OSLijeIDcmRxNmw2api+jEfxLoykJVice/E= golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY= @@ -810,7 +799,6 @@ google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfG google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20201111145450-ac7456db90a6 h1:iRN4+t0lvZX/l9gH14ARF9i58tsVa5a97k6aH95rC3Y= google.golang.org/genproto v0.0.0-20201111145450-ac7456db90a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20201119123407-9b1e624d6bc4/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210114201628-6edceaf6022f h1:izedQ6yVIc5mZsRuXzmSreCOlzI0lCU1HpG8yEdMiKw= @@ -834,7 +822,6 @@ google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= -google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.35.0 h1:TwIQcH3es+MojMVojxxfQ3l3OF2KzlRxML2xZq0kRo8= google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= @@ -873,7 +860,6 @@ gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/proto/desmos/profiles/v1beta1/genesis.proto b/proto/desmos/profiles/v1beta1/genesis.proto index 0c1cdae55e..36eb5b1394 100644 --- a/proto/desmos/profiles/v1beta1/genesis.proto +++ b/proto/desmos/profiles/v1beta1/genesis.proto @@ -9,18 +9,13 @@ option go_package = "github.com/desmos-labs/desmos/x/profiles/types"; // GenesisState defines the profiles module's genesis state. message GenesisState { - repeated desmos.profiles.v1beta1.Profile profiles = 1 [ + repeated desmos.profiles.v1beta1.DTagTransferRequest dtag_transfer_requests = + 1 [ (gogoproto.nullable) = false, - (gogoproto.moretags) = "yaml:\"profiles\"" + (gogoproto.moretags) = "yaml:\"dtag_transfer_requests\"" ]; - repeated desmos.profiles.v1beta1.DTagTransferRequest dtag_transfer_requests = - 2 [ - (gogoproto.nullable) = false, - (gogoproto.moretags) = "yaml:\"dtag_transfer_requests\"" - ]; - - desmos.profiles.v1beta1.Params params = 3 [ + desmos.profiles.v1beta1.Params params = 2 [ (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"params\"" ]; diff --git a/proto/desmos/profiles/v1beta1/models.proto b/proto/desmos/profiles/v1beta1/models.proto index 25cf21a19c..21b9dcadcb 100644 --- a/proto/desmos/profiles/v1beta1/models.proto +++ b/proto/desmos/profiles/v1beta1/models.proto @@ -2,8 +2,10 @@ syntax = "proto3"; package desmos.profiles.v1beta1; import "gogoproto/gogo.proto"; +import "google/protobuf/any.proto"; import "google/protobuf/timestamp.proto"; import "cosmos/auth/v1beta1/auth.proto"; +import "cosmos_proto/cosmos.proto"; option go_package = "github.com/desmos-labs/desmos/x/profiles/types"; @@ -24,7 +26,8 @@ message Profile { option (gogoproto.goproto_getters) = false; option (gogoproto.goproto_stringer) = false; - cosmos.auth.v1beta1.BaseAccount base_account = 1 [(gogoproto.embed) = true]; + google.protobuf.Any account = 1 + [(cosmos_proto.accepts_interface) = "AccountI"]; string dtag = 2 [(gogoproto.moretags) = "yaml:\"dtag\""]; string moniker = 3 [(gogoproto.moretags) = "yaml:\"moniker\""]; string bio = 4 [(gogoproto.moretags) = "yaml:\"bio\""]; @@ -49,7 +52,7 @@ message DTagTransferRequest { string dtag_to_trade = 1 [(gogoproto.moretags) = "yaml:\"dtag_to_trade\""]; string sender = 2 [(gogoproto.moretags) = "yaml:\"sender\""]; - string receiver = 3 [ (gogoproto.moretags) = "yaml:\"receiver\"" ]; + string receiver = 3 [(gogoproto.moretags) = "yaml:\"receiver\""]; } // ___________________________________________________________________________________________________________________ diff --git a/proto/desmos/profiles/v1beta1/query.proto b/proto/desmos/profiles/v1beta1/query.proto index f61c698a6f..67c0f8d961 100644 --- a/proto/desmos/profiles/v1beta1/query.proto +++ b/proto/desmos/profiles/v1beta1/query.proto @@ -3,8 +3,10 @@ package desmos.profiles.v1beta1; import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; +import "google/protobuf/any.proto"; import "desmos/profiles/v1beta1/params.proto"; import "desmos/profiles/v1beta1/models.proto"; +import "cosmos_proto/cosmos.proto"; option go_package = "github.com/desmos-labs/desmos/x/profiles/types"; @@ -40,7 +42,8 @@ message QueryProfileRequest { // QueryProfileResponse is the response type for the Query/Profile RPC method. message QueryProfileResponse { - desmos.profiles.v1beta1.Profile profile = 1 [ (gogoproto.nullable) = false ]; + google.protobuf.Any profile = 1 + [(cosmos_proto.accepts_interface) = "AccountI"]; } // ___________________________________________________________________________________________________________________ diff --git a/x/profiles/client/cli/cli_test.go b/x/profiles/client/cli/cli_test.go index c04de7b66a..7a0c9d4945 100644 --- a/x/profiles/client/cli/cli_test.go +++ b/x/profiles/client/cli/cli_test.go @@ -1,5 +1,3 @@ -// +build norace - package cli_test import ( @@ -7,6 +5,8 @@ import ( "testing" "time" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/client/flags" @@ -40,22 +40,35 @@ func (s *IntegrationTestSuite) SetupSuite() { genesisState := cfg.GenesisState cfg.NumValidators = 2 - var profilesData types.GenesisState - s.Require().NoError(cfg.Codec.UnmarshalJSON(genesisState[types.ModuleName], &profilesData)) + // Store a profile account inside the auth genesis data + var authData authtypes.GenesisState + s.Require().NoError(cfg.Codec.UnmarshalJSON(genesisState[authtypes.ModuleName], &authData)) addr, err := sdk.AccAddressFromBech32("cosmos1ftkjv8njvkekk00ehwdfl5sst8zgdpenjfm4hs") s.Require().NoError(err) - profilesData.Profiles = []types.Profile{ - types.NewProfile( - "dtag", - "moniker", - "bio", - types.Pictures{}, - time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), - authtypes.NewBaseAccountWithAddress(addr), - ), - } + account, err := types.NewProfile( + "dtag", + "moniker", + "bio", + types.Pictures{}, + time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), + authtypes.NewBaseAccountWithAddress(addr), + ) + s.Require().NoError(err) + + accountAny, err := codectypes.NewAnyWithValue(account) + s.Require().NoError(err) + + authData.Accounts = append(authData.Accounts, accountAny) + authDataBz, err := cfg.Codec.MarshalJSON(&authData) + s.Require().NoError(err) + genesisState[authtypes.ModuleName] = authDataBz + + // Store the profiles genesis state + var profilesData types.GenesisState + s.Require().NoError(cfg.Codec.UnmarshalJSON(genesisState[types.ModuleName], &profilesData)) + profilesData.DtagTransferRequests = []types.DTagTransferRequest{ types.NewDTagTransferRequest( "dtag", @@ -90,6 +103,19 @@ func (s *IntegrationTestSuite) TestCmdQueryProfile() { addr, err := sdk.AccAddressFromBech32("cosmos1ftkjv8njvkekk00ehwdfl5sst8zgdpenjfm4hs") s.Require().NoError(err) + profile, err := types.NewProfile( + "dtag", + "moniker", + "bio", + types.Pictures{}, + time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), + authtypes.NewBaseAccountWithAddress(addr), + ) + s.Require().NoError(err) + + profileAny, err := codectypes.NewAnyWithValue(profile) + s.Require().NoError(err) + testCases := []struct { name string args []string @@ -111,14 +137,7 @@ func (s *IntegrationTestSuite) TestCmdQueryProfile() { }, expectErr: false, expectedOutput: types.QueryProfileResponse{ - Profile: types.NewProfile( - "dtag", - "moniker", - "bio", - types.Pictures{}, - time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), - authtypes.NewBaseAccountWithAddress(addr), - ), + Profile: profileAny, }, }, } diff --git a/x/profiles/keeper/alias_functions.go b/x/profiles/keeper/alias_functions.go index be4786acd1..8795b13580 100644 --- a/x/profiles/keeper/alias_functions.go +++ b/x/profiles/keeper/alias_functions.go @@ -8,14 +8,14 @@ import ( ) // IterateProfiles iterates through the profiles set and performs the provided function -func (k Keeper) IterateProfiles(ctx sdk.Context, fn func(index int64, profile types.Profile) (stop bool)) { +func (k Keeper) IterateProfiles(ctx sdk.Context, fn func(index int64, profile *types.Profile) (stop bool)) { i := int64(0) k.ak.IterateAccounts(ctx, func(account authtypes.AccountI) (stop bool) { profile, ok := account.(*types.Profile) stop = false if ok { - stop = fn(i, *profile) + stop = fn(i, profile) i++ } @@ -23,9 +23,9 @@ func (k Keeper) IterateProfiles(ctx sdk.Context, fn func(index int64, profile ty }) } -func (k Keeper) GetProfiles(ctx sdk.Context) []types.Profile { - var profiles []types.Profile - k.IterateProfiles(ctx, func(_ int64, profile types.Profile) (stop bool) { +func (k Keeper) GetProfiles(ctx sdk.Context) []*types.Profile { + var profiles []*types.Profile + k.IterateProfiles(ctx, func(_ int64, profile *types.Profile) (stop bool) { profiles = append(profiles, profile) return false }) @@ -49,10 +49,10 @@ func (k Keeper) GetDtagFromAddress(ctx sdk.Context, addr string) (dtag string, e // GetAddressFromDtag returns the address associated to the given dtag or an empty string if it does not exists func (k Keeper) GetAddressFromDtag(ctx sdk.Context, dtag string) (addr string) { var address = "" - k.IterateProfiles(ctx, func(_ int64, profile types.Profile) (stop bool) { + k.IterateProfiles(ctx, func(_ int64, profile *types.Profile) (stop bool) { equals := profile.Dtag == dtag if equals { - address = profile.BaseAccount.Address + address = profile.GetAddress().String() } return equals diff --git a/x/profiles/keeper/alias_functions_test.go b/x/profiles/keeper/alias_functions_test.go index 87827787d8..ea17e6a0c6 100644 --- a/x/profiles/keeper/alias_functions_test.go +++ b/x/profiles/keeper/alias_functions_test.go @@ -25,42 +25,42 @@ func (suite *KeeperTestSuite) TestKeeper_IterateProfile() { addr4, err := sdk.AccAddressFromBech32("cosmos15lt0mflt6j9a9auj7yl3p20xec4xvljge0zhae") suite.Require().NoError(err) - profiles := []types.Profile{ - types.NewProfile( + profiles := []*types.Profile{ + suite.CheckProfileNoError(types.NewProfile( "first", "", "", types.NewPictures("", ""), date, authtypes.NewBaseAccountWithAddress(addr1), - ), - types.NewProfile( + )), + suite.CheckProfileNoError(types.NewProfile( "second", "", "", types.NewPictures("", ""), date, authtypes.NewBaseAccountWithAddress(addr2), - ), - types.NewProfile( + )), + suite.CheckProfileNoError(types.NewProfile( "not", "", "", types.NewPictures("", ""), date, authtypes.NewBaseAccountWithAddress(addr3), - ), - types.NewProfile( + )), + suite.CheckProfileNoError(types.NewProfile( "third", "", "", types.NewPictures("", ""), date, authtypes.NewBaseAccountWithAddress(addr4), - ), + )), } - expProfiles := []types.Profile{ + expProfiles := []*types.Profile{ profiles[0], profiles[1], profiles[3], @@ -71,8 +71,8 @@ func (suite *KeeperTestSuite) TestKeeper_IterateProfile() { suite.Require().NoError(err) } - var validProfiles []types.Profile - suite.k.IterateProfiles(suite.ctx, func(_ int64, profile types.Profile) (stop bool) { + var validProfiles []*types.Profile + suite.k.IterateProfiles(suite.ctx, func(_ int64, profile *types.Profile) (stop bool) { if profile.Dtag == "not" { return false } diff --git a/x/profiles/keeper/common_test.go b/x/profiles/keeper/common_test.go index 8227a2e1f6..e1e020846b 100644 --- a/x/profiles/keeper/common_test.go +++ b/x/profiles/keeper/common_test.go @@ -49,7 +49,7 @@ type KeeperTestSuite struct { type TestData struct { user string otherUser string - profile types.Profile + profile *types.Profile } func (suite *KeeperTestSuite) SetupTest() { @@ -104,10 +104,14 @@ func (suite *KeeperTestSuite) SetupTest() { addr, err := sdk.AccAddressFromBech32("cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47") suite.Require().NoError(err) + // Create the base account and set inside the auth keeper. + // This is done in order to make sure that when we try to create a profile using the above address, the profile + // can be created properly. Not storing the base account would end up in the following error since it's null: + // "the given account cannot be serialized using Protobuf" baseAcc := authtypes.NewBaseAccountWithAddress(addr) suite.ak.SetAccount(suite.ctx, baseAcc) - suite.testData.profile = types.NewProfile( + suite.testData.profile, err = types.NewProfile( "dtag", "test-user", "biography", @@ -118,6 +122,7 @@ func (suite *KeeperTestSuite) SetupTest() { time.Time{}, baseAcc, ) + suite.Require().NoError(err) } func (suite *KeeperTestSuite) RequireErrorsEqual(expected, actual error) { @@ -128,3 +133,8 @@ func (suite *KeeperTestSuite) RequireErrorsEqual(expected, actual error) { suite.Require().NoError(actual) } } + +func (suite *KeeperTestSuite) CheckProfileNoError(profile *types.Profile, err error) *types.Profile { + suite.Require().NoError(err) + return profile +} diff --git a/x/profiles/keeper/genesis.go b/x/profiles/keeper/genesis.go index 3c1fe076ce..a7220b71a9 100644 --- a/x/profiles/keeper/genesis.go +++ b/x/profiles/keeper/genesis.go @@ -10,7 +10,6 @@ import ( // ExportGenesis returns the GenesisState associated with the given context func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { return types.NewGenesisState( - k.GetProfiles(ctx), k.GetDTagTransferRequests(ctx), k.GetParams(ctx), ) @@ -20,18 +19,6 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { func (k Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) []abci.ValidatorUpdate { k.SetParams(ctx, data.Params) - for _, profile := range data.Profiles { - err := k.ValidateProfile(ctx, profile) - if err != nil { - panic(err) - } - - err = k.StoreProfile(ctx, profile) - if err != nil { - panic(err) - } - } - for _, request := range data.DtagTransferRequests { err := k.SaveDTagTransferRequest(ctx, request) if err != nil { diff --git a/x/profiles/keeper/grpc_query.go b/x/profiles/keeper/grpc_query.go index 8a7c056e2c..efeb656773 100644 --- a/x/profiles/keeper/grpc_query.go +++ b/x/profiles/keeper/grpc_query.go @@ -4,6 +4,8 @@ import ( "context" "strings" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -45,7 +47,12 @@ func (k Keeper) Profile(ctx context.Context, request *types.QueryProfileRequest) "Profile with sdkAddress %s doesn't exists", dTagOrAddress) } - return &types.QueryProfileResponse{Profile: account}, nil + accountAny, err := codectypes.NewAnyWithValue(account) + if err != nil { + return nil, err + } + + return &types.QueryProfileResponse{Profile: accountAny}, nil } // DTagTransfers implements the Query/DTagTransfers gRPC method diff --git a/x/profiles/keeper/invariants.go b/x/profiles/keeper/invariants.go index f387764adb..609348a2db 100644 --- a/x/profiles/keeper/invariants.go +++ b/x/profiles/keeper/invariants.go @@ -25,13 +25,13 @@ func AllInvariants(k Keeper) sdk.Invariant { } // formatOutputProfiles prepare invalid profiles to be displayed correctly -func formatOutputProfiles(invalidProfiles []types.Profile) (outputProfiles string) { +func formatOutputProfiles(invalidProfiles []*types.Profile) (outputProfiles string) { outputProfiles = "Invalid profiles:\n" for _, invalidProfile := range invalidProfiles { outputProfiles += fmt.Sprintf( "[DTag]: %s, [Creator]: %s\n", invalidProfile.Dtag, - invalidProfile.BaseAccount.Address, + invalidProfile.GetAddress().String(), ) } return outputProfiles @@ -40,8 +40,8 @@ func formatOutputProfiles(invalidProfiles []types.Profile) (outputProfiles strin // ValidProfileInvariant checks that all registered profiles have a non-empty dtag and a non-empty creator func ValidProfileInvariant(k Keeper) sdk.Invariant { return func(ctx sdk.Context) (string, bool) { - var invalidProfiles []types.Profile - k.IterateProfiles(ctx, func(_ int64, profile types.Profile) (stop bool) { + var invalidProfiles []*types.Profile + k.IterateProfiles(ctx, func(_ int64, profile *types.Profile) (stop bool) { if err := profile.Validate(); err != nil { invalidProfiles = append(invalidProfiles, profile) } diff --git a/x/profiles/keeper/invariants_test.go b/x/profiles/keeper/invariants_test.go index 825c7a59a0..492a52fca2 100644 --- a/x/profiles/keeper/invariants_test.go +++ b/x/profiles/keeper/invariants_test.go @@ -14,33 +14,33 @@ func (suite *KeeperTestSuite) TestInvariants() { tests := []struct { name string - profile types.Profile + profile *types.Profile expResponse string expBool bool }{ { name: "Invariants not violated", - profile: types.NewProfile( + profile: suite.CheckProfileNoError(types.NewProfile( "dtag", "", "", types.NewPictures("", ""), suite.testData.profile.CreationDate, authtypes.NewBaseAccountWithAddress(address), - ), + )), expResponse: "Every invariant condition is fulfilled correctly", expBool: true, }, { - name: "ValidProfile invariant violated", - profile: types.NewProfile( + name: "ValidProfileInvariant violated", + profile: suite.CheckProfileNoError(types.NewProfile( "", "", "", types.NewPictures("", ""), suite.testData.profile.CreationDate, authtypes.NewBaseAccountWithAddress(address), - ), + )), expResponse: "profiles: invalid profiles invariant\nThe following list contains invalid profiles:\n Invalid profiles:\n[DTag]: , [Creator]: cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47\n\n", expBool: true, }, diff --git a/x/profiles/keeper/keeper.go b/x/profiles/keeper/keeper.go index 899ee5266f..26afb469ae 100644 --- a/x/profiles/keeper/keeper.go +++ b/x/profiles/keeper/keeper.go @@ -59,30 +59,30 @@ func (k Keeper) IsUserBlocked(ctx sdk.Context, blocker, blocked string) bool { // StoreProfile stores the given profile inside the current context. // It assumes that the given profile has already been validated. // It returns an error if a profile with the same dtag from a different creator already exists -func (k Keeper) StoreProfile(ctx sdk.Context, profile types.Profile) error { +func (k Keeper) StoreProfile(ctx sdk.Context, profile *types.Profile) error { addr := k.GetAddressFromDtag(ctx, profile.Dtag) - if addr != "" && addr != profile.BaseAccount.Address { + if addr != "" && addr != profile.GetAddress().String() { return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "a profile with dtag %s has already been created", profile.Dtag) } - k.ak.SetAccount(ctx, &profile) + k.ak.SetAccount(ctx, profile) return nil } // GetProfile returns the profile corresponding to the given address inside the current context. -func (k Keeper) GetProfile(ctx sdk.Context, address string) (profile types.Profile, found bool, err error) { +func (k Keeper) GetProfile(ctx sdk.Context, address string) (profile *types.Profile, found bool, err error) { sdkAcc, err := sdk.AccAddressFromBech32(address) if err != nil { - return types.Profile{}, false, err + return nil, false, err } stored, ok := k.ak.GetAccount(ctx, sdkAcc).(*types.Profile) if !ok { - return types.Profile{}, false, nil + return nil, false, nil } - return *stored, true, nil + return stored, true, nil } // RemoveProfile allows to delete a profile associated with the given address inside the current context. @@ -99,12 +99,12 @@ func (k Keeper) RemoveProfile(ctx sdk.Context, address string) error { } // Delete the profile data by replacing the stored account - k.ak.SetAccount(ctx, profile.BaseAccount) + k.ak.SetAccount(ctx, profile.GetAccount()) return nil } // ValidateProfile checks if the given profile is valid according to the current profile's module params -func (k Keeper) ValidateProfile(ctx sdk.Context, profile types.Profile) error { +func (k Keeper) ValidateProfile(ctx sdk.Context, profile *types.Profile) error { params := k.GetParams(ctx) minMonikerLen := params.MonikerParams.MinMonikerLength.Int64() diff --git a/x/profiles/keeper/keeper_test.go b/x/profiles/keeper/keeper_test.go index 524669ad9b..8c76996217 100644 --- a/x/profiles/keeper/keeper_test.go +++ b/x/profiles/keeper/keeper_test.go @@ -4,6 +4,8 @@ import ( "fmt" "strings" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -62,7 +64,7 @@ func (suite *KeeperTestSuite) TestKeeper_IsUserBlocked() { func (suite *KeeperTestSuite) TestKeeper_GetDtagFromAddress() { tests := []struct { name string - storedProfiles []types.Profile + storedProfiles []*types.Profile address string shouldErr bool expDTag string @@ -75,16 +77,16 @@ func (suite *KeeperTestSuite) TestKeeper_GetDtagFromAddress() { }, { name: "found right dtag", - storedProfiles: []types.Profile{ + storedProfiles: []*types.Profile{ suite.testData.profile, }, - address: suite.testData.profile.BaseAccount.Address, + address: suite.testData.profile.GetAddress().String(), shouldErr: false, expDTag: suite.testData.profile.Dtag, }, { name: "no dtag found", - storedProfiles: []types.Profile{ + storedProfiles: []*types.Profile{ suite.testData.profile, }, address: "cosmos1ppkr0c0x6jvx9e4e48mfvhq2wzzsrync8qrt2m", @@ -118,10 +120,13 @@ func (suite *KeeperTestSuite) TestKeeper_StoreProfile() { addr, err := sdk.AccAddressFromBech32("cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns") suite.Require().NoError(err) + accountAny, err := codectypes.NewAnyWithValue(authtypes.NewBaseAccountWithAddress(addr)) + suite.Require().NoError(err) + tests := []struct { name string - account types.Profile - storedProfiles []types.Profile + account *types.Profile + storedProfiles []*types.Profile expError error }{ { @@ -132,13 +137,13 @@ func (suite *KeeperTestSuite) TestKeeper_StoreProfile() { }, { name: "Existent account with different creator returns error", - account: types.Profile{ - Dtag: suite.testData.profile.Dtag, - Bio: suite.testData.profile.Bio, - Pictures: suite.testData.profile.Pictures, - BaseAccount: authtypes.NewBaseAccountWithAddress(addr), + account: &types.Profile{ + Dtag: suite.testData.profile.Dtag, + Bio: suite.testData.profile.Bio, + Pictures: suite.testData.profile.Pictures, + Account: accountAny, }, - storedProfiles: []types.Profile{suite.testData.profile}, + storedProfiles: []*types.Profile{suite.testData.profile}, expError: sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "a profile with dtag dtag has already been created"), }, @@ -161,7 +166,7 @@ func (suite *KeeperTestSuite) TestKeeper_StoreProfile() { func (suite *KeeperTestSuite) TestKeeper_GetProfile() { tests := []struct { name string - storedProfiles []types.Profile + storedProfiles []*types.Profile address string shouldErr bool expFound bool @@ -175,18 +180,18 @@ func (suite *KeeperTestSuite) TestKeeper_GetProfile() { }, { name: "Profile found", - storedProfiles: []types.Profile{ + storedProfiles: []*types.Profile{ suite.testData.profile, }, - address: suite.testData.profile.BaseAccount.Address, + address: suite.testData.profile.GetAddress().String(), shouldErr: false, expFound: true, - expProfile: &suite.testData.profile, + expProfile: suite.testData.profile, }, { name: "Profile not found", - storedProfiles: []types.Profile{}, - address: suite.testData.profile.BaseAccount.Address, + storedProfiles: []*types.Profile{}, + address: suite.testData.profile.GetAddress().String(), expFound: false, }, } @@ -209,7 +214,7 @@ func (suite *KeeperTestSuite) TestKeeper_GetProfile() { suite.Require().Equal(test.expFound, found) if found { - suite.Require().Equal(*test.expProfile, res) + suite.Require().Equal(test.expProfile, res) } } }) @@ -220,24 +225,24 @@ func (suite *KeeperTestSuite) TestKeeper_RemoveProfile() { err := suite.k.StoreProfile(suite.ctx, suite.testData.profile) suite.Require().Nil(err) - _, found, _ := suite.k.GetProfile(suite.ctx, suite.testData.profile.BaseAccount.Address) + _, found, _ := suite.k.GetProfile(suite.ctx, suite.testData.profile.GetAddress().String()) suite.True(found) - err = suite.k.RemoveProfile(suite.ctx, suite.testData.profile.BaseAccount.Address) + err = suite.k.RemoveProfile(suite.ctx, suite.testData.profile.GetAddress().String()) suite.Require().NoError(err) - _, found, _ = suite.k.GetProfile(suite.ctx, suite.testData.profile.BaseAccount.Address) + _, found, _ = suite.k.GetProfile(suite.ctx, suite.testData.profile.GetAddress().String()) suite.Require().False(found) } func (suite *KeeperTestSuite) TestKeeper_GetProfiles() { tests := []struct { name string - accounts []types.Profile + accounts []*types.Profile }{ { name: "Non empty Profiles list returned", - accounts: []types.Profile{suite.testData.profile}, + accounts: []*types.Profile{suite.testData.profile}, }, { name: "Profile not found", @@ -264,12 +269,12 @@ func (suite *KeeperTestSuite) TestKeeper_GetProfiles() { func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() { tests := []struct { name string - profile types.Profile + profile *types.Profile expErr error }{ { name: "Max moniker length exceeded", - profile: types.NewProfile( + profile: suite.CheckProfileNoError(types.NewProfile( "custom_dtag", strings.Repeat("A", 1005), "my-bio", @@ -278,13 +283,13 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() { "https://test.com/cover-pic", ), suite.testData.profile.CreationDate, - suite.testData.profile.BaseAccount, - ), + suite.testData.profile.GetAccount(), + )), expErr: fmt.Errorf("profile moniker cannot exceed 1000 characters"), }, { name: "Min moniker length not reached", - profile: types.NewProfile( + profile: suite.CheckProfileNoError(types.NewProfile( "custom_dtag", "m", "my-bio", @@ -294,13 +299,13 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() { ), suite.testData.profile.CreationDate, - suite.testData.profile.BaseAccount, - ), + suite.testData.profile.GetAccount(), + )), expErr: fmt.Errorf("profile moniker cannot be less than 2 characters"), }, { name: "Max bio length exceeded", - profile: types.NewProfile( + profile: suite.CheckProfileNoError(types.NewProfile( "custom_dtag", "moniker", strings.Repeat("A", 1005), @@ -310,13 +315,13 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() { ), suite.testData.profile.CreationDate, - suite.testData.profile.BaseAccount, - ), + suite.testData.profile.GetAccount(), + )), expErr: fmt.Errorf("profile biography cannot exceed 1000 characters"), }, { name: "Invalid dtag doesn't match regEx", - profile: types.NewProfile( + profile: suite.CheckProfileNoError(types.NewProfile( "custom.", "moniker", strings.Repeat("A", 1000), @@ -325,13 +330,13 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() { "https://test.com/cover-pic", ), suite.testData.profile.CreationDate, - suite.testData.profile.BaseAccount, - ), + suite.testData.profile.GetAccount(), + )), expErr: fmt.Errorf("invalid profile dtag, it should match the following regEx ^[A-Za-z0-9_]+$"), }, { name: "Min dtag length not reached", - profile: types.NewProfile( + profile: suite.CheckProfileNoError(types.NewProfile( "d", "moniker", "my-bio", @@ -341,13 +346,13 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() { ), suite.testData.profile.CreationDate, - suite.testData.profile.BaseAccount, - ), + suite.testData.profile.GetAccount(), + )), expErr: fmt.Errorf("profile dtag cannot be less than 3 characters"), }, { name: "Max dtag length exceeded", - profile: types.NewProfile( + profile: suite.CheckProfileNoError(types.NewProfile( "9YfrVVi3UEI1ymN7n6isSct30xG6Jn1EDxEXxWOn0voSMIKqLhHsBfnZoXEyHNS", "moniker", "my-bio", @@ -356,13 +361,13 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() { "https://test.com/cover-pic", ), suite.testData.profile.CreationDate, - suite.testData.profile.BaseAccount, - ), + suite.testData.profile.GetAccount(), + )), expErr: fmt.Errorf("profile dtag cannot exceed 30 characters"), }, { name: "Invalid profile pictures returns error", - profile: types.NewProfile( + profile: suite.CheckProfileNoError(types.NewProfile( "dtag", "moniker", "my-bio", @@ -371,13 +376,13 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() { "htts://test.com/cover-pic", ), suite.testData.profile.CreationDate, - suite.testData.profile.BaseAccount, - ), + suite.testData.profile.GetAccount(), + )), expErr: fmt.Errorf("invalid profile picture uri provided"), }, { name: "Valid profile returns no error", - profile: types.NewProfile( + profile: suite.CheckProfileNoError(types.NewProfile( "dtag", "moniker", "my-bio", @@ -387,8 +392,8 @@ func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() { ), suite.testData.profile.CreationDate, - suite.testData.profile.BaseAccount, - ), + suite.testData.profile.GetAccount(), + )), expErr: nil, }, } diff --git a/x/profiles/keeper/msgs_server.go b/x/profiles/keeper/msgs_server.go index 3a0ad709f0..9abefb912e 100644 --- a/x/profiles/keeper/msgs_server.go +++ b/x/profiles/keeper/msgs_server.go @@ -37,7 +37,7 @@ func (k msgServer) SaveProfile(goCtx context.Context, msg *types.MsgSaveProfile) return nil, err } - profile = types.NewProfile( + profile, err = types.NewProfile( msg.Dtag, "", "", @@ -45,6 +45,9 @@ func (k msgServer) SaveProfile(goCtx context.Context, msg *types.MsgSaveProfile) ctx.BlockTime(), k.ak.GetAccount(ctx, addr), ) + if err != nil { + return nil, err + } } // If the DTag changes, delete all the previous DTag transfer requests @@ -53,13 +56,11 @@ func (k msgServer) SaveProfile(goCtx context.Context, msg *types.MsgSaveProfile) } // Update the existing profile with the values provided from the user - updated, err := profile.Update(types.NewProfile( + updated, err := profile.Update(types.NewProfileUpdate( msg.Dtag, msg.Moniker, msg.Bio, types.NewPictures(msg.ProfilePicture, msg.CoverPicture), - time.Time{}, - nil, )) if err != nil { return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, err.Error()) @@ -79,7 +80,7 @@ func (k msgServer) SaveProfile(goCtx context.Context, msg *types.MsgSaveProfile) ctx.EventManager().EmitEvent(sdk.NewEvent( types.EventTypeProfileSaved, sdk.NewAttribute(types.AttributeProfileDtag, updated.Dtag), - sdk.NewAttribute(types.AttributeProfileCreator, updated.BaseAccount.Address), + sdk.NewAttribute(types.AttributeProfileCreator, updated.GetAddress().String()), sdk.NewAttribute(types.AttributeProfileCreationTime, updated.CreationDate.Format(time.RFC3339Nano)), )) @@ -222,7 +223,7 @@ func (k msgServer) AcceptDTagTransfer(goCtx context.Context, msg *types.MsgAccep senderAcc = authtypes.NewBaseAccountWithAddress(add) } - receiverProfile = types.NewProfile( + receiverProfile, err = types.NewProfile( dTagToTrade, "", "", @@ -230,6 +231,9 @@ func (k msgServer) AcceptDTagTransfer(goCtx context.Context, msg *types.MsgAccep ctx.BlockTime(), senderAcc, ) + if err != nil { + return nil, err + } } else { receiverProfile.Dtag = dTagToTrade } diff --git a/x/profiles/keeper/msgs_server_test.go b/x/profiles/keeper/msgs_server_test.go index 6d47c40199..57681d5db1 100644 --- a/x/profiles/keeper/msgs_server_test.go +++ b/x/profiles/keeper/msgs_server_test.go @@ -3,6 +3,8 @@ package keeper_test import ( "time" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" relationshipstypes "github.com/desmos-labs/desmos/x/relationships/types" @@ -18,12 +20,12 @@ import ( func (suite *KeeperTestSuite) Test_handleMsgSaveProfile() { tests := []struct { name string - existentProfiles []types.Profile + existentProfiles []*types.Profile blockTime time.Time msg *types.MsgSaveProfile expErr error expEvents sdk.Events - expStoredProfiles []types.Profile + expStoredProfiles []*types.Profile }{ { name: "Profile saved (with no previous profile created)", @@ -33,10 +35,10 @@ func (suite *KeeperTestSuite) Test_handleMsgSaveProfile() { "my-bio", "https://test.com/profile-picture", "https://test.com/cover-pic", - suite.testData.profile.BaseAccount.Address, + suite.testData.profile.GetAddress().String(), ), - expStoredProfiles: []types.Profile{ - types.NewProfile( + expStoredProfiles: []*types.Profile{ + suite.CheckProfileNoError(types.NewProfile( "custom_dtag", "my-moniker", "my-bio", @@ -45,14 +47,14 @@ func (suite *KeeperTestSuite) Test_handleMsgSaveProfile() { "https://test.com/cover-pic", ), suite.testData.profile.CreationDate, - suite.testData.profile.BaseAccount, - ), + suite.testData.profile.GetAccount(), + )), }, expEvents: sdk.Events{ sdk.NewEvent( types.EventTypeProfileSaved, sdk.NewAttribute(types.AttributeProfileDtag, "custom_dtag"), - sdk.NewAttribute(types.AttributeProfileCreator, suite.testData.profile.BaseAccount.Address), + sdk.NewAttribute(types.AttributeProfileCreator, suite.testData.profile.GetAddress().String()), sdk.NewAttribute(types.AttributeProfileCreationTime, suite.testData.profile.CreationDate.Format(time.RFC3339)), ), }, @@ -60,8 +62,8 @@ func (suite *KeeperTestSuite) Test_handleMsgSaveProfile() { { name: "Profile saved (with previous profile created)", blockTime: suite.testData.profile.CreationDate, - existentProfiles: []types.Profile{ - types.NewProfile( + existentProfiles: []*types.Profile{ + suite.CheckProfileNoError(types.NewProfile( "test_dtag", "old-moniker", "old-biography", @@ -70,8 +72,8 @@ func (suite *KeeperTestSuite) Test_handleMsgSaveProfile() { "https://test.com/old-cover-pic", ), suite.testData.profile.CreationDate, - suite.testData.profile.BaseAccount, - ), + suite.testData.profile.GetAccount(), + )), }, msg: types.NewMsgSaveProfile( "other_dtag", @@ -79,18 +81,18 @@ func (suite *KeeperTestSuite) Test_handleMsgSaveProfile() { "biography", "https://test.com/profile-pic", "https://test.com/cover-pic", - suite.testData.profile.BaseAccount.Address, + suite.testData.profile.GetAddress().String(), ), expEvents: sdk.Events{ sdk.NewEvent( types.EventTypeProfileSaved, sdk.NewAttribute(types.AttributeProfileDtag, "other_dtag"), - sdk.NewAttribute(types.AttributeProfileCreator, suite.testData.profile.BaseAccount.Address), + sdk.NewAttribute(types.AttributeProfileCreator, suite.testData.profile.GetAddress().String()), sdk.NewAttribute(types.AttributeProfileCreationTime, suite.testData.profile.CreationDate.Format(time.RFC3339)), ), }, - expStoredProfiles: []types.Profile{ - types.NewProfile( + expStoredProfiles: []*types.Profile{ + suite.CheckProfileNoError(types.NewProfile( "other_dtag", "moniker", "biography", @@ -99,22 +101,22 @@ func (suite *KeeperTestSuite) Test_handleMsgSaveProfile() { "https://test.com/cover-pic", ), suite.testData.profile.CreationDate, - suite.testData.profile.BaseAccount, - ), + suite.testData.profile.GetAccount(), + )), }, }, { name: "Profile not edited because of the invalid profile picture", blockTime: suite.testData.profile.CreationDate, - existentProfiles: []types.Profile{ - types.NewProfile( + existentProfiles: []*types.Profile{ + suite.CheckProfileNoError(types.NewProfile( "custom_dtag", "biography", "", types.NewPictures("", ""), suite.testData.profile.CreationDate, - suite.testData.profile.BaseAccount, - ), + suite.testData.profile.GetAccount(), + )), }, msg: types.NewMsgSaveProfile( "custom_dtag", @@ -122,19 +124,19 @@ func (suite *KeeperTestSuite) Test_handleMsgSaveProfile() { "", "invalid-pic", "", - suite.testData.profile.BaseAccount.Address, + suite.testData.profile.GetAddress().String(), ), expEvents: sdk.EmptyEvents(), expErr: sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid profile picture uri provided"), - expStoredProfiles: []types.Profile{ - types.NewProfile( + expStoredProfiles: []*types.Profile{ + suite.CheckProfileNoError(types.NewProfile( "custom_dtag", "biography", "", types.NewPictures("", ""), suite.testData.profile.CreationDate, - suite.testData.profile.BaseAccount, - ), + suite.testData.profile.GetAccount(), + )), }, }, } @@ -169,7 +171,7 @@ func (suite *KeeperTestSuite) Test_handleMsgSaveProfile() { func (suite *KeeperTestSuite) Test_handleMsgDeleteProfile() { tests := []struct { name string - storedProfiles []types.Profile + storedProfiles []*types.Profile msg *types.MsgDeleteProfile expErr error expEvents sdk.Events @@ -177,7 +179,7 @@ func (suite *KeeperTestSuite) Test_handleMsgDeleteProfile() { { name: "Profile doesn't exists", storedProfiles: nil, - msg: types.NewMsgDeleteProfile(suite.testData.profile.BaseAccount.Address), + msg: types.NewMsgDeleteProfile(suite.testData.profile.GetAddress().String()), expErr: sdkerrors.Wrap( sdkerrors.ErrInvalidRequest, "no profile associated with the following address found: cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", @@ -186,14 +188,14 @@ func (suite *KeeperTestSuite) Test_handleMsgDeleteProfile() { }, { name: "Profile deleted successfully", - storedProfiles: []types.Profile{ + storedProfiles: []*types.Profile{ suite.testData.profile, }, - msg: types.NewMsgDeleteProfile(suite.testData.profile.BaseAccount.Address), + msg: types.NewMsgDeleteProfile(suite.testData.profile.GetAddress().String()), expEvents: sdk.Events{ sdk.NewEvent( types.EventTypeProfileDeleted, - sdk.NewAttribute(types.AttributeProfileCreator, suite.testData.profile.BaseAccount.Address), + sdk.NewAttribute(types.AttributeProfileCreator, suite.testData.profile.GetAddress().String()), ), }, }, @@ -226,9 +228,12 @@ func (suite *KeeperTestSuite) Test_handleMsgRequestDTagTransfer() { otherAddr, err := sdk.AccAddressFromBech32(suite.testData.otherUser) suite.Require().NoError(err) + otherAccAny, err := codectypes.NewAnyWithValue(authtypes.NewBaseAccountWithAddress(otherAddr)) + suite.Require().NoError(err) + tests := []struct { name string - storedProfiles []types.Profile + storedProfiles []*types.Profile storedDTagReqs []types.DTagTransferRequest storedBlocks []relationshipstypes.UserBlock msg *types.MsgRequestDTagTransfer @@ -265,36 +270,36 @@ func (suite *KeeperTestSuite) Test_handleMsgRequestDTagTransfer() { }, { name: "Already present request returns error", - storedProfiles: []types.Profile{ + storedProfiles: []*types.Profile{ suite.testData.profile, { - Dtag: "test-dtag", - BaseAccount: authtypes.NewBaseAccountWithAddress(otherAddr), + Dtag: "test-dtag", + Account: otherAccAny, }, }, storedDTagReqs: []types.DTagTransferRequest{ - types.NewDTagTransferRequest("dtag", suite.testData.profile.BaseAccount.Address, suite.testData.otherUser), + types.NewDTagTransferRequest("dtag", suite.testData.profile.GetAddress().String(), suite.testData.otherUser), }, - msg: types.NewMsgRequestDTagTransfer(suite.testData.profile.BaseAccount.Address, suite.testData.otherUser), + msg: types.NewMsgRequestDTagTransfer(suite.testData.profile.GetAddress().String(), suite.testData.otherUser), expEvents: sdk.EmptyEvents(), expErr: sdkerrors.Wrapf( sdkerrors.ErrInvalidRequest, "the transfer request from %s to %s has already been made", - suite.testData.profile.BaseAccount.Address, suite.testData.otherUser, + suite.testData.profile.GetAddress().String(), suite.testData.otherUser, ), }, { name: "Not already present request saved correctly", - storedProfiles: []types.Profile{ + storedProfiles: []*types.Profile{ suite.testData.profile, }, - msg: types.NewMsgRequestDTagTransfer(suite.testData.user, suite.testData.profile.BaseAccount.Address), + msg: types.NewMsgRequestDTagTransfer(suite.testData.user, suite.testData.profile.GetAddress().String()), expEvents: sdk.Events{ sdk.NewEvent( types.EventTypeDTagTransferRequest, sdk.NewAttribute(types.AttributeDTagToTrade, "dtag"), sdk.NewAttribute(types.AttributeRequestSender, suite.testData.user), - sdk.NewAttribute(types.AttributeRequestReceiver, suite.testData.profile.BaseAccount.Address), + sdk.NewAttribute(types.AttributeRequestReceiver, suite.testData.profile.GetAddress().String()), ), }, }, @@ -337,7 +342,7 @@ func (suite *KeeperTestSuite) Test_handleMsgAcceptDTagTransfer() { tests := []struct { name string storedDTagReqs []types.DTagTransferRequest - storedProfiles []types.Profile + storedProfiles []*types.Profile msg *types.MsgAcceptDTagTransfer expErr error expEvents sdk.Events @@ -360,23 +365,23 @@ func (suite *KeeperTestSuite) Test_handleMsgAcceptDTagTransfer() { }, { name: "Return an error if the new DTag has already been chosen by another user", - storedProfiles: []types.Profile{ - types.NewProfile( + storedProfiles: []*types.Profile{ + suite.CheckProfileNoError(types.NewProfile( "dtag", "", "", types.NewPictures("", ""), suite.ctx.BlockTime(), authtypes.NewBaseAccountWithAddress(otherAddr), - ), - types.NewProfile( + )), + suite.CheckProfileNoError(types.NewProfile( "newDtag", "", "", types.NewPictures("", ""), suite.ctx.BlockTime(), authtypes.NewBaseAccountWithAddress(newAddr), - ), + )), }, storedDTagReqs: []types.DTagTransferRequest{ types.NewDTagTransferRequest("dtag", suite.testData.user, suite.testData.otherUser), @@ -387,15 +392,15 @@ func (suite *KeeperTestSuite) Test_handleMsgAcceptDTagTransfer() { }, { name: "Return an error when current owner DTag is different from the requested one", - storedProfiles: []types.Profile{ - types.NewProfile( + storedProfiles: []*types.Profile{ + suite.CheckProfileNoError(types.NewProfile( "dtag1", "", "", types.NewPictures("", ""), suite.ctx.BlockTime(), authtypes.NewBaseAccountWithAddress(otherAddr), - ), + )), }, storedDTagReqs: []types.DTagTransferRequest{ types.NewDTagTransferRequest("dtag", suite.testData.user, suite.testData.otherUser), @@ -407,15 +412,15 @@ func (suite *KeeperTestSuite) Test_handleMsgAcceptDTagTransfer() { }, { name: "DTag exchanged correctly (not existent sender profile)", - storedProfiles: []types.Profile{ - types.NewProfile( + storedProfiles: []*types.Profile{ + suite.CheckProfileNoError(types.NewProfile( "dtag", "", "", types.NewPictures("", ""), suite.ctx.BlockTime(), authtypes.NewBaseAccountWithAddress(otherAddr), - ), + )), }, storedDTagReqs: []types.DTagTransferRequest{ types.NewDTagTransferRequest("dtag", suite.testData.user, suite.testData.otherUser), @@ -433,23 +438,23 @@ func (suite *KeeperTestSuite) Test_handleMsgAcceptDTagTransfer() { }, { name: "DTag exchanged correctly (already existent sender profile)", - storedProfiles: []types.Profile{ - types.NewProfile( + storedProfiles: []*types.Profile{ + suite.CheckProfileNoError(types.NewProfile( "dtag", "", "", types.NewPictures("", ""), suite.ctx.BlockTime(), - suite.testData.profile.BaseAccount, - ), - types.NewProfile( + suite.testData.profile.GetAccount(), + )), + suite.CheckProfileNoError(types.NewProfile( "previous", "", "", types.NewPictures("", ""), suite.ctx.BlockTime(), authtypes.NewBaseAccountWithAddress(otherAddr), - ), + )), }, storedDTagReqs: []types.DTagTransferRequest{ types.NewDTagTransferRequest("previous", suite.testData.user, suite.testData.otherUser), diff --git a/x/profiles/keeper/querier_test.go b/x/profiles/keeper/querier_test.go index 4732a46b69..a5c56d7cc8 100644 --- a/x/profiles/keeper/querier_test.go +++ b/x/profiles/keeper/querier_test.go @@ -14,7 +14,7 @@ func (suite *KeeperTestSuite) Test_queryProfile() { tests := []struct { name string path []string - storedAccount types.Profile + storedAccount *types.Profile expErr error }{ { diff --git a/x/profiles/simulation/genesis.go b/x/profiles/simulation/genesis.go index 024282e5c7..ef1fddcb91 100644 --- a/x/profiles/simulation/genesis.go +++ b/x/profiles/simulation/genesis.go @@ -5,8 +5,6 @@ package simulation import ( "fmt" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/types/module" @@ -18,7 +16,6 @@ import ( func RandomizedGenState(simsState *module.SimulationState) { profileGenesis := types.NewGenesisState( - randomProfiles(simsState), randomDTagTransferRequests(simsState), types.NewParams( RandomMonikerParams(simsState.Rand), @@ -53,24 +50,3 @@ func randomDTagTransferRequests(simState *module.SimulationState) []types.DTagTr return dtagTransferRequests } - -// randomProfiles returns randomly generated genesis profiles -func randomProfiles(simState *module.SimulationState) []types.Profile { - var authstate authtypes.GenesisState - simState.Cdc.MustUnmarshalJSON(simState.GenState[authtypes.ModuleName], &authstate) - - genAccounts, err := authtypes.UnpackAccounts(authstate.Accounts) - if err != nil { - panic(err) - } - genAccounts = authtypes.SanitizeGenesisAccounts(genAccounts) - - var accounts []types.Profile - var accountsNumber = simState.Rand.Intn(len(genAccounts)) - for len(accounts) < accountsNumber { - authAccount := genAccounts[simState.Rand.Intn(len(genAccounts))] - accounts = append(accounts, NewRandomProfile(simState.Rand, authAccount)) - } - - return accounts -} diff --git a/x/profiles/simulation/operations_dtag_transfer.go b/x/profiles/simulation/operations_dtag_transfer.go index f6a7e500ee..5fd03eeac2 100644 --- a/x/profiles/simulation/operations_dtag_transfer.go +++ b/x/profiles/simulation/operations_dtag_transfer.go @@ -104,17 +104,23 @@ func randomDtagRequestTransferFields( } randomDTag := RandomDTag(r) - req := types.NewDTagTransferRequest(randomDTag, sender.Address.String(), receiver.Address.String()) - _ = k.StoreProfile(ctx, types.NewProfile( + profile, err := types.NewProfile( randomDTag, "", "", types.NewPictures("", ""), ctx.BlockTime(), ak.GetAccount(ctx, receiver.Address), - )) + ) + if err != nil { + return simtypes.Account{}, types.DTagTransferRequest{}, true + } + _ = k.StoreProfile(ctx, profile) + + // Create a request + req := types.NewDTagTransferRequest(randomDTag, sender.Address.String(), receiver.Address.String()) - // skip if requests already exists + // Skip if requests already exists requests := k.GetUserIncomingDTagTransferRequests(ctx, receiver.Address.String()) for _, request := range requests { if request.Sender == req.Sender { diff --git a/x/profiles/simulation/operations_profile.go b/x/profiles/simulation/operations_profile.go index 07df29ea84..249138dd76 100644 --- a/x/profiles/simulation/operations_profile.go +++ b/x/profiles/simulation/operations_profile.go @@ -92,9 +92,9 @@ func sendMsgSaveProfile( // randomProfileSaveFields returns random profile data func randomProfileSaveFields( r *rand.Rand, ctx sdk.Context, accs []simtypes.Account, k keeper.Keeper, ak authkeeper.AccountKeeper, -) (simtypes.Account, types.Profile, bool) { +) (simtypes.Account, *types.Profile, bool) { if len(accs) == 0 { - return simtypes.Account{}, types.Profile{}, true + return simtypes.Account{}, nil, true } // Get a random account @@ -102,10 +102,10 @@ func randomProfileSaveFields( acc := ak.GetAccount(ctx, account.Address) // See if there is already the profile, otherwise create it from scratch - var profile types.Profile + var profile *types.Profile existing, found, err := k.GetProfile(ctx, account.Address.String()) if err != nil { - return simtypes.Account{}, types.Profile{}, true + return simtypes.Account{}, nil, true } if found { @@ -116,13 +116,11 @@ func randomProfileSaveFields( // 50% chance of changing something if r.Intn(101) <= 50 { - profile, _ = profile.Update(types.NewProfile( + profile, _ = profile.Update(types.NewProfileUpdate( RandomDTag(r), RandomMoniker(r), RandomBio(r), types.NewPictures(RandomProfilePic(r), RandomProfileCover(r)), - profile.CreationDate, - acc, )) } @@ -201,19 +199,13 @@ func randomProfileDeleteFields( return simtypes.Account{}, true } - var accounts []types.Profile - k.IterateProfiles(ctx, func(index int64, profile types.Profile) (stop bool) { - accounts = append(accounts, profile) - return false - }) - + accounts := k.GetProfiles(ctx) if len(accounts) == 0 { return simtypes.Account{}, true } account := RandomProfile(r, accounts) - addr, _ := sdk.AccAddressFromBech32(account.BaseAccount.Address) - acc := GetSimAccount(addr, accs) + acc := GetSimAccount(account.GetAddress(), accs) // Skip the operation without error as the profile is not valid if acc == nil { diff --git a/x/profiles/simulation/utils.go b/x/profiles/simulation/utils.go index 0fd8abfc97..ce71e1a011 100644 --- a/x/profiles/simulation/utils.go +++ b/x/profiles/simulation/utils.go @@ -48,8 +48,8 @@ var ( // NewRandomProfile return a random ProfileData from random data and the given account // nolint:interfacer -func NewRandomProfile(r *rand.Rand, account authtypes.AccountI) types.Profile { - return types.NewProfile( +func NewRandomProfile(r *rand.Rand, account authtypes.AccountI) *types.Profile { + profile, err := types.NewProfile( RandomDTag(r), RandomMoniker(r), RandomBio(r), @@ -57,10 +57,14 @@ func NewRandomProfile(r *rand.Rand, account authtypes.AccountI) types.Profile { time.Now(), account, ) + if err != nil { + panic(err) + } + return profile } // RandomProfile picks and returns a random profile from an array -func RandomProfile(r *rand.Rand, accounts []types.Profile) types.Profile { +func RandomProfile(r *rand.Rand, accounts []*types.Profile) *types.Profile { idx := r.Intn(len(accounts)) return accounts[idx] } diff --git a/x/profiles/types/account.go b/x/profiles/types/account.go new file mode 100644 index 0000000000..71b80a86ce --- /dev/null +++ b/x/profiles/types/account.go @@ -0,0 +1,246 @@ +package types + +import ( + "encoding/json" + "fmt" + "strings" + "time" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/ghodss/yaml" + "github.com/gogo/protobuf/proto" +) + +var ( + _ authtypes.AccountI = (*Profile)(nil) +) + +// NewProfile builds a new profile having the given dtag, creator and creation date +func NewProfile( + dtag string, moniker, bio string, pictures Pictures, creationDate time.Time, account authtypes.AccountI, +) (*Profile, error) { + // Make sure myAccount is a proto.Message, e.g. a BaseAccount etc. + protoAccount, ok := account.(proto.Message) + if !ok { + return nil, fmt.Errorf("the given account cannot be serialized using Protobuf") + } + + myAccountAny, err := codectypes.NewAnyWithValue(protoAccount) + if err != nil { + return nil, err + } + + return &Profile{ + Dtag: dtag, + Moniker: moniker, + Bio: bio, + Pictures: pictures, + CreationDate: creationDate, + Account: myAccountAny, + }, nil +} + +// GetAccount returns the underlying account as an authtypes.AccountI instance +func (p *Profile) GetAccount() authtypes.AccountI { + return p.Account.GetCachedValue().(authtypes.AccountI) +} + +// GetAddress implements authtypes.AccountI +func (p *Profile) GetAddress() sdk.AccAddress { + return p.GetAccount().GetAddress() +} + +// SetAddress implements authtypes.AccountI +func (p *Profile) SetAddress(addr sdk.AccAddress) error { + return p.GetAccount().SetAddress(addr) +} + +// GetPubKey implements authtypes.AccountI +func (p *Profile) GetPubKey() cryptotypes.PubKey { + return p.GetAccount().GetPubKey() +} + +// SetPubKey implements authtypes.AccountI +func (p *Profile) SetPubKey(pubKey cryptotypes.PubKey) error { + return p.GetAccount().SetPubKey(pubKey) +} + +// GetAccountNumber implements authtypes.AccountI +func (p *Profile) GetAccountNumber() uint64 { + return p.GetAccount().GetAccountNumber() +} + +// SetAccountNumber implements authtypes.AccountI +func (p *Profile) SetAccountNumber(accountNumber uint64) error { + return p.GetAccount().SetAccountNumber(accountNumber) +} + +// GetSequence implements authtypes.AccountI +func (p *Profile) GetSequence() uint64 { + return p.GetAccount().GetSequence() +} + +// SetSequence implements authtypes.AccountI +func (p *Profile) SetSequence(sequence uint64) error { + return p.GetAccount().SetSequence(sequence) +} + +// UnpackInterfaces implements codectypes.UnpackInterfacesMessage +func (p *Profile) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + if p.Account != nil { + var account authtypes.AccountI + return unpacker.UnpackAny(p.Account, &account) + } + return nil +} + +// Validate check the validity of the Profile +func (p *Profile) Validate() error { + if strings.TrimSpace(p.Dtag) == "" || p.Dtag == DoNotModify { + return fmt.Errorf("invalid profile DTag: %s", p.Dtag) + } + + if p.Moniker == DoNotModify { + return fmt.Errorf("invalid profile moniker: %s", p.Moniker) + } + + if p.Bio == DoNotModify { + return fmt.Errorf("invalid profile bio: %s", p.Bio) + } + + if p.Pictures.Profile == DoNotModify { + return fmt.Errorf("invalid profile picture: %s", p.Pictures.Profile) + } + + if p.Pictures.Cover == DoNotModify { + return fmt.Errorf("invalid profile cover: %s", p.Pictures.Cover) + } + + if len(p.GetAddress()) == 0 { + return fmt.Errorf("invalid address: %s", p.GetAddress().String()) + } + + return p.Pictures.Validate() +} + +// ------------------------------------------------------------------------------------------------------------------- + +type profilePretty struct { + Address sdk.AccAddress `json:"address" yaml:"address"` + PubKey string `json:"public_key" yaml:"public_key"` + AccountNumber uint64 `json:"account_number" yaml:"account_number"` + Sequence uint64 `json:"sequence" yaml:"sequence"` + DTag string `json:"dtag" yaml:"dtag"` + Moniker string `json:"moniker" yaml:"moniker"` + Bio string `json:"bio" yaml:"bio"` + Pictures Pictures `json:"pictures" yaml:"pictures"` + CreationDate time.Time `json:"creation_date" yaml:"creation_date"` +} + +// Ensure that acc +//// String implements authtypes.AccountIount implements stringer +func (p *Profile) String() string { + out, _ := p.MarshalYAML() + return out.(string) +} + +// MarshalYAML returns the YAML representation of a Profile. +func (p *Profile) MarshalYAML() (interface{}, error) { + bs, err := yaml.Marshal(profilePretty{ + Address: p.GetAddress(), + PubKey: p.GetPubKey().String(), + AccountNumber: p.GetAccountNumber(), + Sequence: p.GetSequence(), + DTag: p.Dtag, + Moniker: p.Moniker, + Bio: p.Bio, + Pictures: p.Pictures, + CreationDate: p.CreationDate, + }) + + if err != nil { + return nil, err + } + + return string(bs), nil +} + +// MarshalJSON returns the JSON representation of a Profile. +func (p Profile) MarshalJSON() ([]byte, error) { + var pubKey = "" + if p.GetPubKey() != nil { + pubKey = p.GetPubKey().String() + } + + return json.Marshal(profilePretty{ + Address: p.GetAddress(), + PubKey: pubKey, + AccountNumber: p.GetAccountNumber(), + Sequence: p.GetSequence(), + DTag: p.Dtag, + Moniker: p.Moniker, + Bio: p.Bio, + Pictures: p.Pictures, + CreationDate: p.CreationDate, + }) +} + +// ------------------------------------------------------------------------------------------------------------------- + +// ProfileUpdate contains all the data that can be updated about a profile. +// When performing an update, if a field should not be edited then it must be set to types.DoNotModify +type ProfileUpdate struct { + Dtag string + Moniker string + Bio string + Pictures Pictures +} + +// NewProfileUpdate builds a new ProfileUpdate instance containing the given data +func NewProfileUpdate(dtag, moniker, bio string, pictures Pictures) *ProfileUpdate { + return &ProfileUpdate{ + Dtag: dtag, + Moniker: moniker, + Bio: bio, + Pictures: pictures, + } +} + +// Update updates the fields of a given profile. An error is +// returned if the resulting profile contains invalid values. +func (p *Profile) Update(update *ProfileUpdate) (*Profile, error) { + if update.Dtag == DoNotModify { + update.Dtag = p.Dtag + } + + if update.Moniker == DoNotModify { + update.Moniker = p.Moniker + } + + if update.Bio == DoNotModify { + update.Bio = p.Bio + } + + if update.Pictures.Profile == DoNotModify { + update.Pictures.Profile = p.Pictures.Profile + } + + if update.Pictures.Cover == DoNotModify { + update.Pictures.Cover = p.Pictures.Cover + } + + newProfile, err := NewProfile(update.Dtag, update.Moniker, update.Bio, update.Pictures, p.CreationDate, p.GetAccount()) + if err != nil { + return nil, err + } + + err = newProfile.Validate() + if err != nil { + return nil, err + } + + return newProfile, nil +} diff --git a/x/profiles/types/account_test.go b/x/profiles/types/account_test.go new file mode 100644 index 0000000000..6623a62dfb --- /dev/null +++ b/x/profiles/types/account_test.go @@ -0,0 +1,310 @@ +package types_test + +import ( + "fmt" + "testing" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/stretchr/testify/require" + + "github.com/desmos-labs/desmos/x/profiles/types" +) + +func assertNoProfileError(profile *types.Profile, err error) *types.Profile { + if err != nil { + panic(err) + } + return profile +} + +func TestProfile_Update(t *testing.T) { + addr1, err := sdk.AccAddressFromBech32("cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47") + require.NoError(t, err) + + tests := []struct { + name string + original *types.Profile + update *types.ProfileUpdate + expError bool + expProfile *types.Profile + }{ + { + name: "DoNotModify and empty fields do not update original values", + original: assertNoProfileError(types.NewProfile( + "dtag", + "moniker", + "bio", + types.NewPictures( + "https://example.com", + "https://example.com", + ), + time.Unix(100, 0), + authtypes.NewBaseAccountWithAddress(addr1), + )), + update: types.NewProfileUpdate( + types.DoNotModify, + types.DoNotModify, + types.DoNotModify, + types.NewPictures(types.DoNotModify, types.DoNotModify), + ), + expError: false, + expProfile: assertNoProfileError(types.NewProfile( + "dtag", + "moniker", + "bio", + types.NewPictures( + "https://example.com", + "https://example.com", + ), + time.Unix(100, 0), + authtypes.NewBaseAccountWithAddress(addr1), + )), + }, + { + name: "Update works properly with all fields", + original: assertNoProfileError(types.NewProfile( + "dtag", + "moniker", + "bio", + types.NewPictures( + "https://example.com", + "https://example.com", + ), + time.Unix(100, 0), + authtypes.NewBaseAccountWithAddress(addr1), + )), + update: types.NewProfileUpdate( + "dtag-2", + "moniker-2", + "bio-2", + types.NewPictures( + "https://example.com/2", + "https://example.com/2", + ), + ), + expError: false, + expProfile: assertNoProfileError(types.NewProfile( + "dtag-2", + "moniker-2", + "bio-2", + types.NewPictures( + "https://example.com/2", + "https://example.com/2", + ), + time.Unix(100, 0), + authtypes.NewBaseAccountWithAddress(addr1), + )), + }, + { + name: "Update does not allow setting invalid fields", + original: assertNoProfileError(types.NewProfile( + "dtag", + "moniker", + "bio", + types.NewPictures( + "https://example.com", + "https://example.com", + ), + time.Unix(100, 0), + authtypes.NewBaseAccountWithAddress(addr1), + )), + update: types.NewProfileUpdate( + "", + "", + "", + types.NewPictures("", ""), + ), + expError: true, + }, + { + name: "Update allows to set empty fields", + original: assertNoProfileError(types.NewProfile( + "dtag", + "moniker", + "bio", + types.NewPictures( + "https://example.com", + "https://example.com", + ), + time.Unix(100, 0), + authtypes.NewBaseAccountWithAddress(addr1), + )), + update: types.NewProfileUpdate( + types.DoNotModify, + "", + "", + types.NewPictures("", ""), + ), + expError: false, + expProfile: assertNoProfileError(types.NewProfile( + "dtag", + "", + "", + types.NewPictures("", ""), + time.Unix(100, 0), + authtypes.NewBaseAccountWithAddress(addr1), + )), + }, + } + + for _, test := range tests { + test := test + t.Run(test.name, func(t *testing.T) { + updated, err := test.original.Update(test.update) + + if test.expError { + require.Error(t, err) + } else { + require.NoError(t, err) + require.Equal(t, test.expProfile, updated) + } + }) + } +} + +func TestProfile_Validate(t *testing.T) { + addr1, err := sdk.AccAddressFromBech32("cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47") + require.NoError(t, err) + + tests := []struct { + name string + account *types.Profile + expErr error + }{ + { + name: "Empty profile creator returns error", + account: assertNoProfileError(types.NewProfile( + "dtag", + "", + "bio", + types.NewPictures( + "https://shorturl.at/adnX3", + "https://shorturl.at/cgpyF", + ), + time.Now(), + authtypes.NewBaseAccountWithAddress(nil), + )), + expErr: fmt.Errorf("invalid address: "), + }, + { + name: "Empty profile DTag returns error", + account: assertNoProfileError(types.NewProfile( + "", + "", + "bio", + types.NewPictures( + "https://shorturl.at/adnX3", + "https://shorturl.at/cgpyF", + ), + time.Now(), + authtypes.NewBaseAccountWithAddress(addr1), + )), + expErr: fmt.Errorf("invalid profile DTag: "), + }, + { + name: "Invalid profile picture returns error", + account: assertNoProfileError(types.NewProfile( + "dtag", + "", + "bio", + types.NewPictures("pic", "https://example.com"), + time.Now(), + authtypes.NewBaseAccountWithAddress(addr1), + )), + expErr: fmt.Errorf("invalid profile picture uri provided"), + }, + { + name: "Invalid cover picture returns error", + account: assertNoProfileError(types.NewProfile( + "dtag", + "", + "bio", + types.NewPictures("https://example.com", "cov"), + time.Now(), + authtypes.NewBaseAccountWithAddress(addr1), + )), + expErr: fmt.Errorf("invalid profile cover uri provided"), + }, + { + name: "Do not modify moniker returns error", + account: assertNoProfileError(types.NewProfile( + "dtag", + types.DoNotModify, + "", + types.Pictures{}, + time.Now(), + authtypes.NewBaseAccountWithAddress(addr1), + )), + expErr: fmt.Errorf("invalid profile moniker: %s", types.DoNotModify), + }, + { + name: "Do not modify bio returns error", + account: assertNoProfileError(types.NewProfile( + "dtag", + "", + types.DoNotModify, + types.Pictures{}, + time.Now(), + authtypes.NewBaseAccountWithAddress(addr1), + )), + expErr: fmt.Errorf("invalid profile bio: %s", types.DoNotModify), + }, + { + name: "Do not modify profile picture returns error", + account: assertNoProfileError(types.NewProfile( + "dtag", + "", + "", + types.NewPictures(types.DoNotModify, ""), + time.Now(), + authtypes.NewBaseAccountWithAddress(addr1), + )), + expErr: fmt.Errorf("invalid profile picture: %s", types.DoNotModify), + }, + { + name: "Do not modify profile cover returns error", + account: assertNoProfileError(types.NewProfile( + "dtag", + "", + "", + types.NewPictures("", types.DoNotModify), + time.Now(), + authtypes.NewBaseAccountWithAddress(addr1), + )), + expErr: fmt.Errorf("invalid profile cover: %s", types.DoNotModify), + }, + { + name: "Profile with only DTag does not error", + account: assertNoProfileError(types.NewProfile( + "dtag", + "", + "", + types.Pictures{}, + time.Now(), + authtypes.NewBaseAccountWithAddress(addr1), + )), + expErr: nil, + }, + { + name: "Valid profile returns no error", + account: assertNoProfileError(types.NewProfile( + "dtag", + "", + "bio", + types.NewPictures("https://shorturl.at/adnX3", "https://shorturl.at/cgpyF"), + time.Now(), + authtypes.NewBaseAccountWithAddress(addr1), + )), + expErr: nil, + }, + } + + for _, test := range tests { + test := test + t.Run(test.name, func(t *testing.T) { + require.Equal(t, test.expErr, test.account.Validate()) + }) + } +} diff --git a/x/profiles/types/codec.go b/x/profiles/types/codec.go index b820343633..b6e30fde75 100644 --- a/x/profiles/types/codec.go +++ b/x/profiles/types/codec.go @@ -21,10 +21,8 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { } func RegisterInterfaces(registry types.InterfaceRegistry) { - registry.RegisterImplementations( - (*authtypes.AccountI)(nil), - &Profile{}, - ) + registry.RegisterImplementations((*authtypes.AccountI)(nil), &Profile{}) + registry.RegisterImplementations((*authtypes.GenesisAccount)(nil), &Profile{}) registry.RegisterImplementations((*sdk.Msg)(nil), &MsgSaveProfile{}, diff --git a/x/profiles/types/genesis.go b/x/profiles/types/genesis.go index 2be7f7010e..6699122c3c 100644 --- a/x/profiles/types/genesis.go +++ b/x/profiles/types/genesis.go @@ -1,14 +1,11 @@ package types -import "fmt" - // NewGenesisState creates a new genesis state func NewGenesisState( - profiles []Profile, request []DTagTransferRequest, + request []DTagTransferRequest, params Params, ) *GenesisState { return &GenesisState{ - Profiles: profiles, Params: params, DtagTransferRequests: request, } @@ -16,36 +13,17 @@ func NewGenesisState( // DefaultGenesisState returns a default GenesisState func DefaultGenesisState() *GenesisState { - return NewGenesisState(nil, nil, DefaultParams()) + return NewGenesisState(nil, DefaultParams()) } // ValidateGenesis validates the given genesis state and returns an error if something is invalid func ValidateGenesis(data *GenesisState) error { - for _, profile := range data.Profiles { - if containDuplicates(data.Profiles, profile) { - return fmt.Errorf("duplicated profile: %s", profile) - } - - err := profile.Validate() - if err != nil { - return err - } - } - err := data.Params.Validate() if err != nil { return err } for _, req := range data.DtagTransferRequests { - if !profileExists(data.Profiles, req.Sender) { - return fmt.Errorf("invalid DTag transfer request; sender does not exist: %s", req.Sender) - } - - if !profileExists(data.Profiles, req.Receiver) { - return fmt.Errorf("invalid DTag transfer request; receiver does not exist: %s", req.Receiver) - } - err := req.Validate() if err != nil { return err @@ -59,7 +37,7 @@ func ValidateGenesis(data *GenesisState) error { func containDuplicates(profiles []Profile, profile Profile) bool { var count = 0 for _, p := range profiles { - if p.Address == profile.Address || p.Dtag == profile.Dtag { + if p.GetAddress().Equals(profile.GetAddress()) || p.Dtag == profile.Dtag { count++ } } @@ -69,7 +47,7 @@ func containDuplicates(profiles []Profile, profile Profile) bool { // profileExists tells whether the given profiles slice contain a profile associated to the given address func profileExists(profiles []Profile, address string) bool { for _, profile := range profiles { - if profile.BaseAccount.Address == address { + if profile.GetAddress().String() == address { return true } } diff --git a/x/profiles/types/genesis.pb.go b/x/profiles/types/genesis.pb.go index d2b795cbf3..7c883ff42e 100644 --- a/x/profiles/types/genesis.pb.go +++ b/x/profiles/types/genesis.pb.go @@ -25,9 +25,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the profiles module's genesis state. type GenesisState struct { - Profiles []Profile `protobuf:"bytes,1,rep,name=profiles,proto3" json:"profiles" yaml:"profiles"` - DtagTransferRequests []DTagTransferRequest `protobuf:"bytes,2,rep,name=dtag_transfer_requests,json=dtagTransferRequests,proto3" json:"dtag_transfer_requests" yaml:"dtag_transfer_requests"` - Params Params `protobuf:"bytes,3,opt,name=params,proto3" json:"params" yaml:"params"` + DtagTransferRequests []DTagTransferRequest `protobuf:"bytes,1,rep,name=dtag_transfer_requests,json=dtagTransferRequests,proto3" json:"dtag_transfer_requests" yaml:"dtag_transfer_requests"` + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params" yaml:"params"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -63,13 +62,6 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo -func (m *GenesisState) GetProfiles() []Profile { - if m != nil { - return m.Profiles - } - return nil -} - func (m *GenesisState) GetDtagTransferRequests() []DTagTransferRequest { if m != nil { return m.DtagTransferRequests @@ -93,28 +85,26 @@ func init() { } var fileDescriptor_24f308c1ccf2d582 = []byte{ - // 321 bytes of a gzipped FileDescriptorProto + // 292 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4d, 0x49, 0x2d, 0xce, 0xcd, 0x2f, 0xd6, 0x2f, 0x28, 0xca, 0x4f, 0xcb, 0xcc, 0x49, 0x2d, 0xd6, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x87, 0x28, 0xd3, 0x83, 0x29, 0xd3, 0x83, 0x2a, 0x93, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0xab, 0xd1, 0x07, 0xb1, 0x20, 0xca, 0xa5, 0x54, 0x70, 0x99, 0x5a, 0x90, 0x58, 0x94, - 0x98, 0x5b, 0x4c, 0x48, 0x55, 0x6e, 0x7e, 0x4a, 0x6a, 0x0e, 0x54, 0x95, 0xd2, 0x41, 0x26, 0x2e, - 0x1e, 0x77, 0x88, 0x63, 0x82, 0x4b, 0x12, 0x4b, 0x52, 0x85, 0x42, 0xb9, 0x38, 0x60, 0x3a, 0x24, - 0x18, 0x15, 0x98, 0x35, 0xb8, 0x8d, 0x14, 0xf4, 0x70, 0x38, 0x4f, 0x2f, 0x00, 0x22, 0xe0, 0x24, - 0x7e, 0xe2, 0x9e, 0x3c, 0xc3, 0xa7, 0x7b, 0xf2, 0xfc, 0x95, 0x89, 0xb9, 0x39, 0x56, 0x4a, 0x30, - 0x75, 0x4a, 0x41, 0x70, 0xa3, 0x84, 0x3a, 0x19, 0xb9, 0xc4, 0x52, 0x4a, 0x12, 0xd3, 0xe3, 0x4b, - 0x8a, 0x12, 0xf3, 0x8a, 0xd3, 0x52, 0x8b, 0xe2, 0x8b, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x8a, - 0x25, 0x98, 0xc0, 0xb6, 0xe8, 0xe0, 0xb4, 0xc5, 0x25, 0x24, 0x31, 0x3d, 0x04, 0xaa, 0x2b, 0x08, - 0xa2, 0xc9, 0x49, 0x15, 0x6a, 0xa3, 0x2c, 0xc4, 0x46, 0xec, 0x26, 0x2b, 0x05, 0x89, 0x80, 0x24, - 0xd0, 0xf4, 0x16, 0x0b, 0xf9, 0x71, 0xb1, 0x41, 0x42, 0x4a, 0x82, 0x59, 0x81, 0x51, 0x83, 0xdb, - 0x48, 0x1e, 0xb7, 0x07, 0xc1, 0xca, 0x9c, 0x44, 0xa1, 0xb6, 0xf1, 0x42, 0xfd, 0x07, 0x16, 0x55, - 0x0a, 0x82, 0x9a, 0xe2, 0xe4, 0x71, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, - 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, - 0x7a, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x10, 0x3b, 0x74, 0x73, - 0x12, 0x93, 0x8a, 0xa1, 0x6c, 0xfd, 0x0a, 0x44, 0xe4, 0x94, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, - 0x81, 0x23, 0xc5, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0xfd, 0x83, 0x83, 0x32, 0x38, 0x02, 0x00, - 0x00, + 0x98, 0x5b, 0x4c, 0x48, 0x55, 0x6e, 0x7e, 0x4a, 0x6a, 0x0e, 0x54, 0x95, 0xd2, 0x2b, 0x46, 0x2e, + 0x1e, 0x77, 0x88, 0x63, 0x82, 0x4b, 0x12, 0x4b, 0x52, 0x85, 0x3a, 0x19, 0xb9, 0xc4, 0x52, 0x4a, + 0x12, 0xd3, 0xe3, 0x4b, 0x8a, 0x12, 0xf3, 0x8a, 0xd3, 0x52, 0x8b, 0xe2, 0x8b, 0x52, 0x0b, 0x4b, + 0x53, 0x8b, 0x4b, 0x8a, 0x25, 0x18, 0x15, 0x98, 0x35, 0xb8, 0x8d, 0x74, 0xf4, 0x70, 0xb8, 0x56, + 0xcf, 0x25, 0x24, 0x31, 0x3d, 0x04, 0xaa, 0x2b, 0x08, 0xa2, 0xc9, 0x49, 0xf5, 0xc4, 0x3d, 0x79, + 0x86, 0x4f, 0xf7, 0xe4, 0x65, 0x2b, 0x13, 0x73, 0x73, 0xac, 0x94, 0xb0, 0x9b, 0xac, 0x14, 0x24, + 0x02, 0x92, 0x40, 0xd3, 0x5b, 0x2c, 0xe4, 0xc7, 0xc5, 0x06, 0xf1, 0x92, 0x04, 0x93, 0x02, 0xa3, + 0x06, 0xb7, 0x91, 0x3c, 0x4e, 0xab, 0x03, 0xc0, 0xca, 0x9c, 0x44, 0xa1, 0xb6, 0xf1, 0x42, 0x6c, + 0x83, 0x68, 0x56, 0x0a, 0x82, 0x9a, 0xe2, 0xe4, 0x71, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, + 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, + 0x72, 0x0c, 0x51, 0x7a, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x10, + 0x3b, 0x74, 0x73, 0x12, 0x93, 0x8a, 0xa1, 0x6c, 0xfd, 0x0a, 0x44, 0x28, 0x96, 0x54, 0x16, 0xa4, + 0x16, 0x27, 0xb1, 0x81, 0x43, 0xcf, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x31, 0x28, 0x95, 0xef, + 0xe1, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -146,7 +136,7 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x1a + dAtA[i] = 0x12 if len(m.DtagTransferRequests) > 0 { for iNdEx := len(m.DtagTransferRequests) - 1; iNdEx >= 0; iNdEx-- { { @@ -158,20 +148,6 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x12 - } - } - if len(m.Profiles) > 0 { - for iNdEx := len(m.Profiles) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Profiles[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- dAtA[i] = 0xa } } @@ -195,12 +171,6 @@ func (m *GenesisState) Size() (n int) { } var l int _ = l - if len(m.Profiles) > 0 { - for _, e := range m.Profiles { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - } if len(m.DtagTransferRequests) > 0 { for _, e := range m.DtagTransferRequests { l = e.Size() @@ -248,40 +218,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Profiles", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Profiles = append(m.Profiles, Profile{}) - if err := m.Profiles[len(m.Profiles)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field DtagTransferRequests", wireType) } @@ -315,7 +251,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 3: + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) } diff --git a/x/profiles/types/genesis_test.go b/x/profiles/types/genesis_test.go index c587cdc91a..493ae92e49 100644 --- a/x/profiles/types/genesis_test.go +++ b/x/profiles/types/genesis_test.go @@ -2,9 +2,6 @@ package types_test import ( "testing" - "time" - - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" @@ -13,11 +10,7 @@ import ( ) func TestValidateGenesis(t *testing.T) { - date, err := time.Parse(time.RFC3339, "2010-10-02T12:10:00.000Z") - require.NoError(t, err) - addr1, _ := sdk.AccAddressFromBech32("cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47") - addr2, _ := sdk.AccAddressFromBech32("cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns") tests := []struct { name string @@ -29,37 +22,9 @@ func TestValidateGenesis(t *testing.T) { genesis: types.DefaultGenesisState(), shouldError: false, }, - { - name: "Genesis with invalid profile returns error (empty DTag)", - genesis: types.NewGenesisState( - []types.Profile{ - types.NewProfile( - "", - "", - "", - types.NewPictures("", ""), - date, - authtypes.NewBaseAccountWithAddress(addr1), - ), // An empty tag should return an error - }, - nil, - types.DefaultParams(), - ), - shouldError: true, - }, { name: "Invalid params returns error", genesis: types.NewGenesisState( - []types.Profile{ - types.NewProfile( - "custom_dtag1", - "", - "biography", - types.NewPictures("https://test.com/profile-pic", "https://test.com/cover-pic"), - date, - authtypes.NewBaseAccountWithAddress(addr1), - ), - }, nil, types.NewParams( types.NewMonikerParams(sdk.NewInt(-1), sdk.NewInt(10)), @@ -70,21 +35,8 @@ func TestValidateGenesis(t *testing.T) { shouldError: true, }, { - name: "Invalid dTag requests returns error", + name: "Invalid DTag requests returns error", genesis: types.NewGenesisState( - []types.Profile{ - types.NewProfile( - "custom_dtag1", - "", - "biography", - types.NewPictures( - "https://test.com/profile-pic", - "https://test.com/cover-pic", - ), - date, - authtypes.NewBaseAccountWithAddress(addr1), - ), - }, []types.DTagTransferRequest{ types.NewDTagTransferRequest( "dtag", @@ -97,32 +49,8 @@ func TestValidateGenesis(t *testing.T) { shouldError: true, }, { - name: "Valid Genesis returns no errors", + name: "Valid genesis returns no errors", genesis: types.NewGenesisState( - []types.Profile{ - types.NewProfile( - "custom_dtag1", - "", - "biography", - types.NewPictures( - "https://test.com/profile-pic", - "https://test.com/cover-pic", - ), - date, - authtypes.NewBaseAccountWithAddress(addr1), - ), - types.NewProfile( - "custom_dtag2", - "", - "biography", - types.NewPictures( - "https://test.com/profile-pic", - "https://test.com/cover-pic", - ), - date, - authtypes.NewBaseAccountWithAddress(addr2), - ), - }, []types.DTagTransferRequest{ types.NewDTagTransferRequest( "dtag", @@ -134,33 +62,6 @@ func TestValidateGenesis(t *testing.T) { ), shouldError: false, }, - { - name: "Missing profile should error", - genesis: types.NewGenesisState( - []types.Profile{ - types.NewProfile( - "custom_dtag1", - "", - "biography", - types.NewPictures( - "https://test.com/profile-pic", - "https://test.com/cover-pic", - ), - date, - authtypes.NewBaseAccountWithAddress(addr1), - ), - }, - []types.DTagTransferRequest{ - types.NewDTagTransferRequest( - "dtag", - addr1.String(), - "cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns", - ), - }, - types.DefaultParams(), - ), - shouldError: true, - }, } for _, test := range tests { diff --git a/x/profiles/types/models.go b/x/profiles/types/models.go index 43a80b9e70..ff9a6ce613 100644 --- a/x/profiles/types/models.go +++ b/x/profiles/types/models.go @@ -3,9 +3,6 @@ package types import ( "fmt" "strings" - "time" - - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -41,104 +38,6 @@ func (pic Pictures) Validate() error { // ___________________________________________________________________________________________________________________ -// NewProfile builds a new profile having the given dtag, creator and creation date -func NewProfile( - dtag string, moniker, bio string, pictures Pictures, creationDate time.Time, account authtypes.AccountI, -) Profile { - // TODO: We should remove this when the following Cosmos issues is resolved - // https://github.com/cosmos/cosmos-sdk/issues/8876 - baseAcc, ok := account.(*authtypes.BaseAccount) - if baseAcc != nil && !ok { - panic(fmt.Errorf("invalid account type")) - } - - return Profile{ - Dtag: dtag, - Moniker: moniker, - Bio: bio, - Pictures: pictures, - CreationDate: creationDate, - BaseAccount: baseAcc, - } -} - -// Update updates the fields of a given profile. An error is -// returned if the resulting profile contains invalid values. -func (profile Profile) Update(p2 Profile) (Profile, error) { - if p2.Dtag == DoNotModify { - p2.Dtag = profile.Dtag - } - - if p2.Moniker == DoNotModify { - p2.Moniker = profile.Moniker - } - - if p2.Bio == DoNotModify { - p2.Bio = profile.Bio - } - - if p2.Pictures.Profile == DoNotModify { - p2.Pictures.Profile = profile.Pictures.Profile - } - - if p2.Pictures.Cover == DoNotModify { - p2.Pictures.Cover = profile.Pictures.Cover - } - - if p2.CreationDate.IsZero() { - p2.CreationDate = profile.CreationDate - } - - if p2.BaseAccount == nil { - p2.BaseAccount = profile.BaseAccount - } - - newProfile := NewProfile(p2.Dtag, p2.Moniker, p2.Bio, p2.Pictures, p2.CreationDate, p2.BaseAccount) - err := newProfile.Validate() - if err != nil { - return Profile{}, err - } - - return newProfile, nil -} - -// Validate check the validity of the Profile -func (profile *Profile) Validate() error { - if strings.TrimSpace(profile.Dtag) == "" || profile.Dtag == DoNotModify { - return fmt.Errorf("invalid profile DTag: %s", profile.Dtag) - } - - if profile.Moniker == DoNotModify { - return fmt.Errorf("invalid profile moniker: %s", profile.Moniker) - } - - if profile.Bio == DoNotModify { - return fmt.Errorf("invalid profile bio: %s", profile.Bio) - } - - if profile.Pictures.Profile == DoNotModify { - return fmt.Errorf("invalid profile picture: %s", profile.Pictures.Profile) - } - - if profile.Pictures.Cover == DoNotModify { - return fmt.Errorf("invalid profile cover: %s", profile.Pictures.Cover) - } - - _, err := sdk.AccAddressFromBech32(profile.BaseAccount.Address) - if err != nil { - return fmt.Errorf("invalid address: %s", profile.BaseAccount.Address) - } - - err = profile.BaseAccount.Validate() - if err != nil { - return fmt.Errorf("invalid account: %s", err.Error()) - } - - return profile.Pictures.Validate() -} - -// ___________________________________________________________________________________________________________________ - func NewDTagTransferRequest(dtagToTrade string, sender, receiver string) DTagTransferRequest { return DTagTransferRequest{ DtagToTrade: dtagToTrade, diff --git a/x/profiles/types/models.pb.go b/x/profiles/types/models.pb.go index a256bac6b3..ab3983833a 100644 --- a/x/profiles/types/models.pb.go +++ b/x/profiles/types/models.pb.go @@ -5,11 +5,13 @@ package types import ( fmt "fmt" - types "github.com/cosmos/cosmos-sdk/x/auth/types" + types "github.com/cosmos/cosmos-sdk/codec/types" + _ "github.com/cosmos/cosmos-sdk/x/auth/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" _ "github.com/golang/protobuf/ptypes/timestamp" + _ "github.com/regen-network/cosmos-proto" io "io" math "math" math_bits "math/bits" @@ -84,12 +86,12 @@ func (m *Pictures) GetCover() string { // Profile represents a generic first on Desmos, containing the information of a // single user type Profile struct { - *types.BaseAccount `protobuf:"bytes,1,opt,name=base_account,json=baseAccount,proto3,embedded=base_account" json:"base_account,omitempty"` - Dtag string `protobuf:"bytes,2,opt,name=dtag,proto3" json:"dtag,omitempty" yaml:"dtag"` - Moniker string `protobuf:"bytes,3,opt,name=moniker,proto3" json:"moniker,omitempty" yaml:"moniker"` - Bio string `protobuf:"bytes,4,opt,name=bio,proto3" json:"bio,omitempty" yaml:"bio"` - Pictures Pictures `protobuf:"bytes,5,opt,name=pictures,proto3" json:"pictures" yaml:"pictures"` - CreationDate time.Time `protobuf:"bytes,6,opt,name=creation_date,json=creationDate,proto3,stdtime" json:"creation_date" yaml:"creation_date"` + Account *types.Any `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` + Dtag string `protobuf:"bytes,2,opt,name=dtag,proto3" json:"dtag,omitempty" yaml:"dtag"` + Moniker string `protobuf:"bytes,3,opt,name=moniker,proto3" json:"moniker,omitempty" yaml:"moniker"` + Bio string `protobuf:"bytes,4,opt,name=bio,proto3" json:"bio,omitempty" yaml:"bio"` + Pictures Pictures `protobuf:"bytes,5,opt,name=pictures,proto3" json:"pictures" yaml:"pictures"` + CreationDate time.Time `protobuf:"bytes,6,opt,name=creation_date,json=creationDate,proto3,stdtime" json:"creation_date" yaml:"creation_date"` } func (m *Profile) Reset() { *m = Profile{} } @@ -196,43 +198,43 @@ func init() { } var fileDescriptor_dcbf89d5cd53a9ca = []byte{ - // 564 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x93, 0x3f, 0x8f, 0xd3, 0x30, - 0x18, 0xc6, 0x13, 0xee, 0x5f, 0x71, 0xef, 0x0f, 0xe4, 0x4e, 0xba, 0xa8, 0x43, 0x5c, 0x0c, 0x42, - 0x20, 0x81, 0xa3, 0xc2, 0x56, 0xb1, 0x10, 0xdd, 0x00, 0xdb, 0xc9, 0xaa, 0x18, 0x58, 0x2a, 0x27, - 0x71, 0x73, 0x81, 0xa6, 0x2e, 0xb1, 0x53, 0x71, 0xdf, 0x80, 0xf1, 0xc6, 0xdb, 0xe8, 0xd7, 0xe0, - 0x1b, 0xdc, 0xd8, 0x91, 0x29, 0xa0, 0x76, 0x41, 0x8c, 0xf9, 0x04, 0x28, 0xb6, 0xd3, 0x72, 0x48, - 0x6c, 0xf1, 0xf3, 0xfc, 0xec, 0xf7, 0xf5, 0xfb, 0x38, 0xe0, 0x51, 0xcc, 0x44, 0xc6, 0x85, 0x3f, - 0xcd, 0xf9, 0x28, 0x1d, 0x33, 0xe1, 0xcf, 0x7a, 0x21, 0x93, 0xb4, 0xe7, 0x67, 0x3c, 0x66, 0x63, - 0x81, 0xa7, 0x39, 0x97, 0xdc, 0x39, 0xd5, 0x14, 0x6e, 0x28, 0x6c, 0xa8, 0xce, 0x49, 0xc2, 0x13, - 0xae, 0x18, 0xbf, 0xfe, 0xd2, 0x78, 0x07, 0x26, 0x9c, 0x27, 0x63, 0xe6, 0xab, 0x55, 0x58, 0x8c, - 0x7c, 0x99, 0x66, 0x4c, 0x48, 0x9a, 0x4d, 0x0d, 0xe0, 0x45, 0x5c, 0x55, 0xa5, 0x85, 0xbc, 0x58, - 0x57, 0xac, 0x17, 0xda, 0x47, 0x1f, 0x40, 0xeb, 0x3c, 0x8d, 0x64, 0x91, 0x33, 0xe1, 0x3c, 0x03, - 0x7b, 0xa6, 0xac, 0x6b, 0x77, 0xed, 0x27, 0x77, 0x03, 0xa7, 0x2a, 0xe1, 0xe1, 0x25, 0xcd, 0xc6, - 0x7d, 0x64, 0x0c, 0x44, 0x1a, 0xc4, 0x79, 0x0c, 0x76, 0x22, 0x3e, 0x63, 0xb9, 0x7b, 0x47, 0xb1, - 0xf7, 0xaa, 0x12, 0xee, 0x6b, 0x56, 0xc9, 0x88, 0x68, 0xbb, 0xdf, 0xba, 0x9e, 0x43, 0xfb, 0xd7, - 0x1c, 0xda, 0xe8, 0xeb, 0x16, 0xd8, 0x3b, 0x37, 0xbb, 0xdf, 0x82, 0xfd, 0x90, 0x0a, 0x36, 0xa4, - 0x51, 0xc4, 0x8b, 0x89, 0x54, 0x05, 0xdb, 0x2f, 0xba, 0x58, 0xb7, 0x8b, 0x55, 0x87, 0xa6, 0x5d, - 0x1c, 0x50, 0xc1, 0x5e, 0x6b, 0x2e, 0xd8, 0x5e, 0x94, 0xd0, 0x26, 0xed, 0x70, 0x23, 0x39, 0x0f, - 0xc1, 0x76, 0x2c, 0x69, 0x62, 0xfa, 0x38, 0xaa, 0x4a, 0xd8, 0xd6, 0x7d, 0xd4, 0x2a, 0x22, 0xca, - 0xac, 0xef, 0x96, 0xf1, 0x49, 0xfa, 0x91, 0xe5, 0xee, 0xd6, 0xbf, 0x77, 0x33, 0x06, 0x22, 0x0d, - 0xe2, 0x74, 0xc1, 0x56, 0x98, 0x72, 0x77, 0x5b, 0x91, 0x87, 0x55, 0x09, 0x81, 0x26, 0xc3, 0x94, - 0x23, 0x52, 0x5b, 0xce, 0x3b, 0xd0, 0x9a, 0x9a, 0xb9, 0xb9, 0x3b, 0xaa, 0xf7, 0x07, 0xf8, 0x3f, - 0xd1, 0xe1, 0x66, 0xc0, 0xc1, 0xe9, 0x4d, 0x09, 0xad, 0xaa, 0x84, 0x47, 0x66, 0xa6, 0x46, 0x47, - 0x64, 0x7d, 0x96, 0x93, 0x83, 0x83, 0x28, 0x67, 0x54, 0xa6, 0x7c, 0x32, 0x8c, 0xa9, 0x64, 0xee, - 0xae, 0x3a, 0xbc, 0x83, 0x75, 0xd0, 0xb8, 0x09, 0x1a, 0x0f, 0x9a, 0xa0, 0x83, 0x5e, 0x7d, 0xea, - 0xef, 0x12, 0xde, 0xde, 0x58, 0x95, 0xf0, 0xc4, 0xc4, 0xf1, 0xb7, 0x8c, 0xae, 0x7e, 0x40, 0x9b, - 0xec, 0x37, 0xda, 0x19, 0x95, 0xac, 0xdf, 0xfa, 0x32, 0x87, 0xd6, 0xf5, 0x1c, 0x5a, 0xe8, 0x9b, - 0x0d, 0x8e, 0xcf, 0x06, 0x34, 0x19, 0xe4, 0x74, 0x22, 0x46, 0x2c, 0x27, 0xec, 0x53, 0xc1, 0x84, - 0x74, 0x5e, 0x81, 0x83, 0x7a, 0x8a, 0x43, 0xc9, 0x87, 0x32, 0xa7, 0x71, 0xf3, 0x3e, 0xdc, 0x4d, - 0x91, 0x5b, 0x36, 0x22, 0xed, 0x7a, 0x3d, 0xe0, 0x83, 0x7a, 0xe5, 0x3c, 0x05, 0xbb, 0x82, 0x4d, - 0xe2, 0xf5, 0x53, 0xb9, 0x5f, 0x95, 0xf0, 0x40, 0x6f, 0xd3, 0x3a, 0x22, 0x06, 0x70, 0x7c, 0xd0, - 0xca, 0x59, 0xc4, 0xd2, 0xd9, 0x3a, 0xa7, 0xe3, 0xcd, 0xbc, 0x1a, 0x07, 0x91, 0x35, 0xb4, 0x79, - 0x5d, 0xc1, 0x9b, 0x9b, 0xa5, 0x67, 0x2f, 0x96, 0x9e, 0xfd, 0x73, 0xe9, 0xd9, 0x57, 0x2b, 0xcf, - 0x5a, 0xac, 0x3c, 0xeb, 0xfb, 0xca, 0xb3, 0xde, 0xe3, 0x24, 0x95, 0x17, 0x45, 0x88, 0x23, 0x9e, - 0xf9, 0x3a, 0xa3, 0xe7, 0x63, 0x1a, 0x0a, 0xf3, 0xed, 0x7f, 0xde, 0xfc, 0x92, 0xf2, 0x72, 0xca, - 0x44, 0xb8, 0xab, 0x86, 0xfc, 0xf2, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xd3, 0x97, 0x9b, 0xd3, - 0xb2, 0x03, 0x00, 0x00, + // 570 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x93, 0x3d, 0x6f, 0xd3, 0x40, + 0x18, 0xc7, 0x6d, 0xfa, 0x66, 0x2e, 0x49, 0x0b, 0x6e, 0xa4, 0x9a, 0x0c, 0xbe, 0x72, 0x20, 0x04, + 0x12, 0xb5, 0x15, 0xd8, 0xa2, 0x2e, 0x8d, 0x3a, 0xc0, 0x56, 0x9d, 0x22, 0x06, 0x96, 0xe8, 0x6c, + 0x5f, 0x5c, 0x43, 0xec, 0x0b, 0xf6, 0x39, 0x22, 0xdf, 0x80, 0xb1, 0x62, 0xea, 0x98, 0x0f, 0xc1, + 0xc2, 0x37, 0xa8, 0x98, 0x3a, 0x32, 0x19, 0x94, 0x2c, 0x88, 0xd1, 0x9f, 0x00, 0xd9, 0x77, 0x97, + 0xd0, 0x22, 0x36, 0x3f, 0xcf, 0xff, 0xf7, 0xbc, 0x9f, 0xc1, 0xe3, 0x80, 0x66, 0x31, 0xcb, 0xdc, + 0x49, 0xca, 0x46, 0xd1, 0x98, 0x66, 0xee, 0xb4, 0xeb, 0x51, 0x4e, 0xba, 0x6e, 0xcc, 0x02, 0x3a, + 0xce, 0x9c, 0x49, 0xca, 0x38, 0x33, 0x0f, 0x04, 0xe5, 0x28, 0xca, 0x91, 0x54, 0xa7, 0x1d, 0xb2, + 0x90, 0xd5, 0x8c, 0x5b, 0x7d, 0x09, 0xbc, 0xf3, 0x20, 0x64, 0x2c, 0x1c, 0x53, 0xb7, 0xb6, 0xbc, + 0x7c, 0xe4, 0x92, 0x64, 0x26, 0x25, 0x78, 0x5b, 0xe2, 0x51, 0x4c, 0x33, 0x4e, 0xe2, 0x89, 0x04, + 0x6c, 0x9f, 0xd5, 0x0d, 0x91, 0x9c, 0x9f, 0xaf, 0x9a, 0xa9, 0x0c, 0x95, 0x5b, 0xe8, 0x43, 0x51, + 0x54, 0x18, 0x42, 0x42, 0xef, 0x80, 0x71, 0x16, 0xf9, 0x3c, 0x4f, 0x69, 0x66, 0x3e, 0x07, 0x3b, + 0xb2, 0x59, 0x4b, 0x3f, 0xd4, 0x9f, 0xde, 0xed, 0x9b, 0x65, 0x01, 0x77, 0x67, 0x24, 0x1e, 0xf7, + 0x90, 0x14, 0x10, 0x56, 0x88, 0xf9, 0x04, 0x6c, 0xf9, 0x6c, 0x4a, 0x53, 0xeb, 0x4e, 0xcd, 0xde, + 0x2b, 0x0b, 0xd8, 0x14, 0x6c, 0xed, 0x46, 0x58, 0xc8, 0x3d, 0xe3, 0x72, 0x0e, 0xf5, 0x5f, 0x73, + 0xa8, 0xa3, 0xcf, 0x1b, 0x60, 0xe7, 0x4c, 0x46, 0x1f, 0x83, 0x1d, 0xe2, 0xfb, 0x2c, 0x4f, 0x78, + 0x5d, 0xab, 0xf1, 0xa2, 0xed, 0x88, 0x29, 0x1d, 0x35, 0xa5, 0x73, 0x92, 0xcc, 0xfa, 0xcd, 0x6f, + 0x5f, 0x8e, 0x8c, 0x13, 0x01, 0xbe, 0xc6, 0x2a, 0xc4, 0x7c, 0x04, 0x36, 0x03, 0x4e, 0x42, 0x59, + 0x7a, 0xaf, 0x2c, 0x60, 0x43, 0x94, 0xae, 0xbc, 0x08, 0xd7, 0x62, 0x35, 0x4e, 0xcc, 0x92, 0xe8, + 0x3d, 0x4d, 0xad, 0x8d, 0xdb, 0xe3, 0x48, 0x01, 0x61, 0x85, 0x98, 0x87, 0x60, 0xc3, 0x8b, 0x98, + 0xb5, 0x59, 0x93, 0xbb, 0x65, 0x01, 0x81, 0x20, 0xbd, 0x88, 0x21, 0x5c, 0x49, 0xe6, 0x1b, 0x60, + 0x4c, 0xe4, 0xaa, 0xac, 0xad, 0xba, 0xe7, 0x87, 0xce, 0x7f, 0x6e, 0xec, 0xa8, 0x9d, 0xf6, 0x0f, + 0xae, 0x0a, 0xa8, 0x95, 0x05, 0xdc, 0x93, 0x6b, 0x94, 0x7e, 0x84, 0x57, 0xb9, 0xcc, 0x14, 0xb4, + 0xfc, 0x94, 0x12, 0x1e, 0xb1, 0x64, 0x18, 0x10, 0x4e, 0xad, 0xed, 0x3a, 0x79, 0xe7, 0x9f, 0x85, + 0x0c, 0xd4, 0xd9, 0xfb, 0xdd, 0x2a, 0xeb, 0xef, 0x02, 0xde, 0x0c, 0x2c, 0x0b, 0xd8, 0x96, 0x17, + 0xf8, 0xdb, 0x8d, 0x2e, 0x7e, 0x40, 0x1d, 0x37, 0x95, 0xef, 0x94, 0x70, 0xda, 0x33, 0x3e, 0xcd, + 0xa1, 0x76, 0x39, 0x87, 0x1a, 0xfa, 0xaa, 0x83, 0xfd, 0xd3, 0x01, 0x09, 0x07, 0x29, 0x49, 0xb2, + 0x11, 0x4d, 0x31, 0xfd, 0x90, 0xd3, 0x8c, 0x9b, 0xc7, 0xa0, 0x55, 0x6d, 0x71, 0xc8, 0xd9, 0x90, + 0xa7, 0x24, 0x50, 0x4f, 0xc2, 0x5a, 0x17, 0xb9, 0x21, 0x23, 0xdc, 0xa8, 0xec, 0x01, 0x1b, 0x54, + 0x96, 0xf9, 0x0c, 0x6c, 0x67, 0x34, 0x09, 0x56, 0xaf, 0xe3, 0x7e, 0x59, 0xc0, 0x96, 0x08, 0x13, + 0x7e, 0x84, 0x25, 0x60, 0xba, 0xc0, 0x48, 0xa9, 0x4f, 0xa3, 0xe9, 0xea, 0x4e, 0xfb, 0xeb, 0x7d, + 0x29, 0x05, 0xe1, 0x15, 0xb4, 0x7e, 0x50, 0xfd, 0x57, 0x57, 0x0b, 0x5b, 0xbf, 0x5e, 0xd8, 0xfa, + 0xcf, 0x85, 0xad, 0x5f, 0x2c, 0x6d, 0xed, 0x7a, 0x69, 0x6b, 0xdf, 0x97, 0xb6, 0xf6, 0xd6, 0x09, + 0x23, 0x7e, 0x9e, 0x7b, 0x8e, 0xcf, 0x62, 0x57, 0xdc, 0xe8, 0x68, 0x4c, 0xbc, 0x4c, 0x7e, 0xbb, + 0x1f, 0xd7, 0xff, 0x2e, 0x9f, 0x4d, 0x68, 0xe6, 0x6d, 0xd7, 0x4b, 0x7e, 0xf9, 0x27, 0x00, 0x00, + 0xff, 0xff, 0xd1, 0x78, 0x39, 0xe4, 0xdb, 0x03, 0x00, 0x00, } func (this *Pictures) Equal(that interface{}) bool { @@ -388,9 +390,9 @@ func (m *Profile) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x12 } - if m.BaseAccount != nil { + if m.Account != nil { { - size, err := m.BaseAccount.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Account.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -481,8 +483,8 @@ func (m *Profile) Size() (n int) { } var l int _ = l - if m.BaseAccount != nil { - l = m.BaseAccount.Size() + if m.Account != nil { + l = m.Account.Size() n += 1 + l + sovModels(uint64(l)) } l = len(m.Dtag) @@ -679,7 +681,7 @@ func (m *Profile) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BaseAccount", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Account", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -706,10 +708,10 @@ func (m *Profile) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.BaseAccount == nil { - m.BaseAccount = &types.BaseAccount{} + if m.Account == nil { + m.Account = &types.Any{} } - if err := m.BaseAccount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.Account.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/profiles/types/models_test.go b/x/profiles/types/models_test.go index 57bef144b7..28f268a743 100644 --- a/x/profiles/types/models_test.go +++ b/x/profiles/types/models_test.go @@ -3,10 +3,6 @@ package types_test import ( "fmt" "testing" - "time" - - sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/desmos-labs/desmos/x/profiles/types" @@ -44,309 +40,6 @@ func TestPictures_Validate(t *testing.T) { // ___________________________________________________________________________________________________________________ -func TestProfile_Update(t *testing.T) { - addr1, err := sdk.AccAddressFromBech32("cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47") - require.NoError(t, err) - - addr2, err := sdk.AccAddressFromBech32("cosmos1pqcac4w0k8z4elysqppgce5vauzu5krew7jegg") - require.NoError(t, err) - - tests := []struct { - name string - original types.Profile - update types.Profile - expError bool - expProfile types.Profile - }{ - { - name: "DoNotModify and empty fields do not update original values", - original: types.NewProfile( - "dtag", - "moniker", - "bio", - types.NewPictures( - "https://example.com", - "https://example.com", - ), - time.Unix(100, 0), - authtypes.NewBaseAccountWithAddress(addr1), - ), - update: types.NewProfile( - types.DoNotModify, - types.DoNotModify, - types.DoNotModify, - types.NewPictures(types.DoNotModify, types.DoNotModify), - time.Time{}, - nil, - ), - expError: false, - expProfile: types.NewProfile( - "dtag", - "moniker", - "bio", - types.NewPictures( - "https://example.com", - "https://example.com", - ), - time.Unix(100, 0), - authtypes.NewBaseAccountWithAddress(addr1), - ), - }, - { - name: "Update works properly with all fields", - original: types.NewProfile( - "dtag", - "moniker", - "bio", - types.NewPictures( - "https://example.com", - "https://example.com", - ), - time.Unix(100, 0), - authtypes.NewBaseAccountWithAddress(addr1), - ), - update: types.NewProfile( - "dtag-2", - "moniker-2", - "bio-2", - types.NewPictures( - "https://example.com/2", - "https://example.com/2", - ), - time.Unix(200, 0), - authtypes.NewBaseAccountWithAddress(addr2), - ), - expError: false, - expProfile: types.NewProfile( - "dtag-2", - "moniker-2", - "bio-2", - types.NewPictures( - "https://example.com/2", - "https://example.com/2", - ), - time.Unix(200, 0), - authtypes.NewBaseAccountWithAddress(addr2), - ), - }, - { - name: "Update does not allow setting invalid fields", - original: types.NewProfile( - "dtag", - "moniker", - "bio", - types.NewPictures( - "https://example.com", - "https://example.com", - ), - time.Unix(100, 0), - authtypes.NewBaseAccountWithAddress(addr1), - ), - update: types.NewProfile( - "dtag-2", - "", - "", - types.NewPictures("", ""), - time.Time{}, - authtypes.NewBaseAccountWithAddress(nil), - ), - expError: true, - }, - { - name: "Update allows to set empty fields", - original: types.NewProfile( - "dtag", - "moniker", - "bio", - types.NewPictures( - "https://example.com", - "https://example.com", - ), - time.Unix(100, 0), - authtypes.NewBaseAccountWithAddress(addr1), - ), - update: types.NewProfile( - types.DoNotModify, - "", - "", - types.NewPictures("", ""), - time.Time{}, - nil, - ), - expError: false, - expProfile: types.NewProfile( - "dtag", - "", - "", - types.NewPictures("", ""), - time.Unix(100, 0), - authtypes.NewBaseAccountWithAddress(addr1), - ), - }, - } - - for _, test := range tests { - test := test - t.Run(test.name, func(t *testing.T) { - updated, err := test.original.Update(test.update) - - if test.expError { - require.Error(t, err) - } else { - require.NoError(t, err) - require.Equal(t, test.expProfile, updated) - } - }) - } -} - -func TestProfile_Validate(t *testing.T) { - addr1, err := sdk.AccAddressFromBech32("cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47") - require.NoError(t, err) - - tests := []struct { - name string - account types.Profile - expErr error - }{ - { - name: "Empty profile creator returns error", - account: types.NewProfile( - "dtag", - "", - "bio", - types.NewPictures( - "https://shorturl.at/adnX3", - "https://shorturl.at/cgpyF", - ), - time.Now(), - authtypes.NewBaseAccountWithAddress(nil), - ), - expErr: fmt.Errorf("invalid address: "), - }, - { - name: "Empty profile DTag returns error", - account: types.NewProfile( - "", - "", - "bio", - types.NewPictures( - "https://shorturl.at/adnX3", - "https://shorturl.at/cgpyF", - ), - time.Now(), - authtypes.NewBaseAccountWithAddress(addr1), - ), - expErr: fmt.Errorf("invalid profile DTag: "), - }, - { - name: "Invalid profile picture returns error", - account: types.NewProfile( - "dtag", - "", - "bio", - types.NewPictures("pic", "https://example.com"), - time.Now(), - authtypes.NewBaseAccountWithAddress(addr1), - ), - expErr: fmt.Errorf("invalid profile picture uri provided"), - }, - { - name: "Invalid cover picture returns error", - account: types.NewProfile( - "dtag", - "", - "bio", - types.NewPictures("https://example.com", "cov"), - time.Now(), - authtypes.NewBaseAccountWithAddress(addr1), - ), - expErr: fmt.Errorf("invalid profile cover uri provided"), - }, - { - name: "Do not modify moniker returns error", - account: types.NewProfile( - "dtag", - types.DoNotModify, - "", - types.Pictures{}, - time.Now(), - authtypes.NewBaseAccountWithAddress(addr1), - ), - expErr: fmt.Errorf("invalid profile moniker: %s", types.DoNotModify), - }, - { - name: "Do not modify bio returns error", - account: types.NewProfile( - "dtag", - "", - types.DoNotModify, - types.Pictures{}, - time.Now(), - authtypes.NewBaseAccountWithAddress(addr1), - ), - expErr: fmt.Errorf("invalid profile bio: %s", types.DoNotModify), - }, - { - name: "Do not modify profile picture returns error", - account: types.NewProfile( - "dtag", - "", - "", - types.NewPictures(types.DoNotModify, ""), - time.Now(), - authtypes.NewBaseAccountWithAddress(addr1), - ), - expErr: fmt.Errorf("invalid profile picture: %s", types.DoNotModify), - }, - { - name: "Do not modify profile cover returns error", - account: types.NewProfile( - "dtag", - "", - "", - types.NewPictures("", types.DoNotModify), - time.Now(), - authtypes.NewBaseAccountWithAddress(addr1), - ), - expErr: fmt.Errorf("invalid profile cover: %s", types.DoNotModify), - }, - { - name: "Profile with only DTag does not error", - account: types.NewProfile( - "dtag", - "", - "", - types.Pictures{}, - time.Now(), - authtypes.NewBaseAccountWithAddress(addr1), - ), - expErr: nil, - }, - { - name: "Valid profile returns no error", - account: types.NewProfile( - "dtag", - "", - "bio", - types.NewPictures("https://shorturl.at/adnX3", "https://shorturl.at/cgpyF"), - time.Now(), - authtypes.NewBaseAccountWithAddress(addr1), - ), - expErr: nil, - }, - } - - for _, test := range tests { - test := test - t.Run(test.name, func(t *testing.T) { - require.Equal(t, test.expErr, test.account.Validate()) - }) - } -} - -// ___________________________________________________________________________________________________________________ - func TestDTagTransferRequest_Validate(t *testing.T) { tests := []struct { name string diff --git a/x/profiles/types/msgs_test.go b/x/profiles/types/msgs_test.go index dd704ce5f0..dd13c5eedf 100644 --- a/x/profiles/types/msgs_test.go +++ b/x/profiles/types/msgs_test.go @@ -15,7 +15,7 @@ import ( ) var addr, _ = sdk.AccAddressFromBech32("cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns") -var testProfile = types.NewProfile( +var testProfile, _ = types.NewProfile( "dtag", "moniker", "biography", @@ -35,7 +35,7 @@ var msgEditProfile = types.NewMsgSaveProfile( testProfile.Bio, testProfile.Pictures.Profile, testProfile.Pictures.Cover, - testProfile.BaseAccount.Address, + testProfile.GetAddress().String(), ) func TestMsgSaveProfile_Route(t *testing.T) { @@ -68,7 +68,7 @@ func TestMsgSaveProfile_ValidateBasic(t *testing.T) { }, { name: "Invalid empty dtag returns error", - msg: types.NewMsgSaveProfile("", "", "", "", "", testProfile.BaseAccount.Address), + msg: types.NewMsgSaveProfile("", "", "", "", "", testProfile.GetAddress().String()), error: sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "profile dtag cannot be empty or blank"), }, { @@ -113,7 +113,7 @@ func TestMsgSaveProfile_GetSigners(t *testing.T) { // ___________________________________________________________________________________________________________________ var msgDeleteProfile = types.NewMsgDeleteProfile( - testProfile.BaseAccount.Address, + testProfile.GetAddress().String(), ) func TestMsgDeleteProfile_Route(t *testing.T) { @@ -139,7 +139,7 @@ func TestMsgDeleteProfile_ValidateBasic(t *testing.T) { }, { name: "Valid message returns no error", - msg: types.NewMsgDeleteProfile(testProfile.BaseAccount.Address), + msg: types.NewMsgDeleteProfile(testProfile.GetAddress().String()), error: nil, }, } diff --git a/x/profiles/types/query.pb.go b/x/profiles/types/query.pb.go index 7d5d050c08..cd8b0a4c97 100644 --- a/x/profiles/types/query.pb.go +++ b/x/profiles/types/query.pb.go @@ -6,9 +6,11 @@ package types import ( context "context" fmt "fmt" + types "github.com/cosmos/cosmos-sdk/codec/types" _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" + _ "github.com/regen-network/cosmos-proto" _ "google.golang.org/genproto/googleapis/api/annotations" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" @@ -70,7 +72,7 @@ var xxx_messageInfo_QueryProfileRequest proto.InternalMessageInfo // QueryProfileResponse is the response type for the Query/Profile RPC method. type QueryProfileResponse struct { - Profile Profile `protobuf:"bytes,1,opt,name=profile,proto3" json:"profile"` + Profile *types.Any `protobuf:"bytes,1,opt,name=profile,proto3" json:"profile,omitempty"` } func (m *QueryProfileResponse) Reset() { *m = QueryProfileResponse{} } @@ -106,11 +108,11 @@ func (m *QueryProfileResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QueryProfileResponse proto.InternalMessageInfo -func (m *QueryProfileResponse) GetProfile() Profile { +func (m *QueryProfileResponse) GetProfile() *types.Any { if m != nil { return m.Profile } - return Profile{} + return nil } // QueryDTagTransfersRequest is the request type for the Query/DTagTransfers RPC @@ -296,37 +298,40 @@ func init() { } var fileDescriptor_5e0074f57a59f38d = []byte{ - // 477 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xb1, 0x6f, 0xd3, 0x40, - 0x18, 0xc5, 0x7d, 0xb4, 0xa4, 0xe5, 0x2a, 0x96, 0x23, 0x12, 0xc5, 0x42, 0x76, 0x30, 0x48, 0x0d, - 0xd0, 0xfa, 0xa8, 0x33, 0x81, 0x84, 0x84, 0x2a, 0x06, 0x26, 0x04, 0x51, 0x06, 0xc4, 0x82, 0xce, - 0xe4, 0x6a, 0x2c, 0xd9, 0x3e, 0xf7, 0xee, 0x8c, 0xa8, 0x10, 0x0b, 0x13, 0x03, 0x03, 0x12, 0x0b, - 0x63, 0x57, 0xfe, 0x93, 0x8e, 0x95, 0x58, 0x58, 0x40, 0x28, 0x61, 0xe0, 0xcf, 0x40, 0xb9, 0xfb, - 0x5c, 0x1a, 0x29, 0x4e, 0xc2, 0x76, 0xba, 0xbc, 0xf7, 0xbe, 0x5f, 0xde, 0xe7, 0xc3, 0xd7, 0x87, - 0x5c, 0xe5, 0x42, 0xd1, 0x52, 0x8a, 0xfd, 0x34, 0xe3, 0x8a, 0xbe, 0xde, 0x8d, 0xb9, 0x66, 0xbb, - 0xf4, 0xa0, 0xe2, 0xf2, 0x30, 0x2c, 0xa5, 0xd0, 0x82, 0x5c, 0xb6, 0xa2, 0xb0, 0x16, 0x85, 0x20, - 0x72, 0xdb, 0x89, 0x48, 0x84, 0xd1, 0xd0, 0xc9, 0xc9, 0xca, 0xdd, 0xab, 0x89, 0x10, 0x49, 0xc6, - 0x29, 0x2b, 0x53, 0xca, 0x8a, 0x42, 0x68, 0xa6, 0x53, 0x51, 0x28, 0xf8, 0xf5, 0x46, 0xd3, 0xc4, - 0x92, 0x49, 0x96, 0x2f, 0x54, 0xe5, 0x62, 0xc8, 0x33, 0x50, 0x05, 0x3d, 0x7c, 0xe9, 0xe9, 0x84, - 0xf3, 0x89, 0x55, 0xf5, 0xf9, 0x41, 0xc5, 0x95, 0x26, 0x04, 0xaf, 0x56, 0x8a, 0xcb, 0x4d, 0xd4, - 0x41, 0xdd, 0x0b, 0x7d, 0x73, 0xbe, 0xb7, 0xfe, 0xe1, 0xc8, 0x77, 0xfe, 0x1c, 0xf9, 0x4e, 0xf0, - 0x0c, 0xb7, 0xa7, 0x4d, 0xaa, 0x14, 0x85, 0xe2, 0xe4, 0x01, 0x5e, 0x83, 0x69, 0xc6, 0xb8, 0x11, - 0x75, 0xc2, 0x86, 0xff, 0x1d, 0x82, 0x75, 0x6f, 0xf5, 0xf8, 0xa7, 0xef, 0xf4, 0x6b, 0x5b, 0x70, - 0x17, 0x5f, 0x31, 0xc9, 0x0f, 0x07, 0x2c, 0x19, 0x48, 0x56, 0xa8, 0x7d, 0x2e, 0xd5, 0x72, 0x50, - 0x19, 0x76, 0x67, 0x59, 0x01, 0xed, 0x31, 0x5e, 0x97, 0x36, 0x46, 0x6d, 0xa2, 0xce, 0x4a, 0x77, - 0x23, 0xda, 0x6e, 0x64, 0x3b, 0x9b, 0x00, 0xb3, 0x81, 0xf3, 0x34, 0x23, 0x68, 0x63, 0x62, 0x2b, - 0x30, 0x95, 0x83, 0x2a, 0x18, 0xd4, 0x6d, 0xc2, 0x2d, 0x0c, 0xbf, 0x8f, 0x5b, 0x76, 0x35, 0x50, - 0x8b, 0xdf, 0x5c, 0x8b, 0x91, 0xc1, 0x34, 0x30, 0x45, 0x3f, 0x56, 0xf0, 0x79, 0x13, 0x4b, 0xbe, - 0x20, 0xbc, 0x06, 0xcd, 0x91, 0x66, 0xfe, 0x19, 0x0b, 0x75, 0x77, 0x96, 0x54, 0x5b, 0xe2, 0xe0, - 0xce, 0xfb, 0x6f, 0xbf, 0x3f, 0x9f, 0xbb, 0x45, 0xba, 0xb4, 0xf1, 0x5b, 0xab, 0x2f, 0xde, 0x4e, - 0xf6, 0xf0, 0x8e, 0x7c, 0x45, 0xf8, 0xe2, 0x54, 0xf5, 0x24, 0x9a, 0x3f, 0x72, 0xd6, 0x8a, 0xdd, - 0xde, 0x7f, 0x79, 0x00, 0x96, 0x1a, 0xd8, 0x9b, 0x64, 0xab, 0x11, 0x76, 0xa8, 0x59, 0xf2, 0x42, - 0x9f, 0x92, 0x7d, 0x44, 0xb8, 0x65, 0x9b, 0x26, 0xb7, 0x17, 0xf4, 0x72, 0x76, 0xbd, 0xee, 0xf6, - 0x72, 0x62, 0xc0, 0xda, 0x32, 0x58, 0xd7, 0x88, 0x4f, 0xe7, 0xbf, 0xd7, 0xbd, 0x47, 0xc7, 0x23, - 0x0f, 0x9d, 0x8c, 0x3c, 0xf4, 0x6b, 0xe4, 0xa1, 0x4f, 0x63, 0xcf, 0x39, 0x19, 0x7b, 0xce, 0xf7, - 0xb1, 0xe7, 0x3c, 0x0f, 0x93, 0x54, 0xbf, 0xaa, 0xe2, 0xf0, 0xa5, 0xc8, 0x21, 0x64, 0x27, 0x63, - 0xb1, 0xaa, 0x03, 0xdf, 0xfc, 0x8b, 0xd4, 0x87, 0x25, 0x57, 0x71, 0xcb, 0x3c, 0xea, 0xde, 0xdf, - 0x00, 0x00, 0x00, 0xff, 0xff, 0xa1, 0xfa, 0xf0, 0x2b, 0x94, 0x04, 0x00, 0x00, + // 515 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x53, 0x3f, 0x6f, 0xd3, 0x40, + 0x14, 0xf7, 0xd1, 0xd2, 0x86, 0x2b, 0x2c, 0x47, 0x24, 0x5a, 0x0b, 0xd9, 0xc5, 0x20, 0x35, 0x40, + 0x73, 0x47, 0x93, 0x09, 0x04, 0x43, 0x23, 0x06, 0x58, 0x10, 0x44, 0x99, 0x58, 0xaa, 0x73, 0x72, + 0x31, 0x91, 0x1c, 0x9f, 0xeb, 0x3b, 0x23, 0x22, 0xc4, 0xc2, 0xc4, 0xc0, 0x80, 0xc4, 0xc2, 0xd8, + 0x95, 0x9d, 0x0f, 0x51, 0x31, 0x55, 0x62, 0x61, 0x01, 0xa1, 0x84, 0x81, 0x8f, 0x81, 0x72, 0xf7, + 0x1c, 0x5a, 0x29, 0x6e, 0xc3, 0x66, 0xfb, 0x7e, 0xff, 0xde, 0xfb, 0xf9, 0xf0, 0xf5, 0x9e, 0x50, + 0x43, 0xa9, 0x58, 0x9a, 0xc9, 0xfe, 0x20, 0x16, 0x8a, 0xbd, 0xdc, 0x09, 0x85, 0xe6, 0x3b, 0x6c, + 0x3f, 0x17, 0xd9, 0x88, 0xa6, 0x99, 0xd4, 0x92, 0x5c, 0xb1, 0x20, 0x5a, 0x80, 0x28, 0x80, 0xdc, + 0x6a, 0x24, 0x23, 0x69, 0x30, 0x6c, 0xfa, 0x64, 0xe1, 0xee, 0xd5, 0x48, 0xca, 0x28, 0x16, 0x8c, + 0xa7, 0x03, 0xc6, 0x93, 0x44, 0x6a, 0xae, 0x07, 0x32, 0x51, 0x70, 0xba, 0x01, 0xa7, 0xe6, 0x2d, + 0xcc, 0xfb, 0x8c, 0x27, 0xe0, 0xe3, 0xde, 0x28, 0x0b, 0x93, 0xf2, 0x8c, 0x0f, 0xd5, 0x59, 0xa8, + 0xa1, 0xec, 0x89, 0x78, 0x66, 0xd3, 0x95, 0x53, 0xd4, 0x9e, 0x4d, 0x67, 0x5f, 0xec, 0x51, 0xd0, + 0xc4, 0x97, 0x9f, 0x4d, 0xa7, 0x7b, 0x6a, 0x05, 0xda, 0x62, 0x3f, 0x17, 0x4a, 0x13, 0x82, 0x97, + 0x73, 0x25, 0xb2, 0x75, 0xb4, 0x89, 0x6a, 0x17, 0xda, 0xe6, 0xf9, 0x5e, 0xe5, 0xdd, 0x81, 0xef, + 0xfc, 0x39, 0xf0, 0x9d, 0xa0, 0x83, 0xab, 0x27, 0x49, 0x2a, 0x95, 0x89, 0x12, 0xe4, 0x3e, 0x5e, + 0x85, 0x20, 0x86, 0xb8, 0xd6, 0xa8, 0x52, 0x3b, 0x20, 0x2d, 0x06, 0xa4, 0xbb, 0xc9, 0xa8, 0x75, + 0xf1, 0xeb, 0x97, 0x7a, 0x65, 0xb7, 0xdb, 0x95, 0x79, 0xa2, 0x1f, 0xb7, 0x0b, 0x4a, 0x70, 0x17, + 0x6f, 0x18, 0xd5, 0x87, 0x1d, 0x1e, 0x75, 0x32, 0x9e, 0xa8, 0xbe, 0xc8, 0xd4, 0x62, 0x81, 0x62, + 0xec, 0xce, 0xa3, 0x42, 0xac, 0x27, 0xb8, 0x92, 0x59, 0x19, 0xb5, 0x8e, 0x36, 0x97, 0x6a, 0x6b, + 0x8d, 0x6d, 0x5a, 0xd2, 0x22, 0x3d, 0xae, 0x00, 0xde, 0xad, 0xe5, 0xc3, 0x9f, 0xbe, 0xd3, 0x9e, + 0x69, 0x04, 0x55, 0x4c, 0xec, 0xf8, 0xa6, 0x09, 0x40, 0x05, 0x9d, 0x62, 0x93, 0xf0, 0x15, 0xcc, + 0x1f, 0xe0, 0x15, 0xdb, 0x18, 0xac, 0xc4, 0x2f, 0xb5, 0xb6, 0x44, 0x70, 0x03, 0x52, 0xe3, 0xc7, + 0x12, 0x3e, 0x6f, 0x64, 0xc9, 0x27, 0x84, 0x57, 0x61, 0xe1, 0xa4, 0x3c, 0xff, 0x9c, 0x32, 0xdd, + 0xfa, 0x82, 0x68, 0x9b, 0x38, 0xb8, 0xf3, 0xf6, 0xdb, 0xef, 0x8f, 0xe7, 0x6e, 0x91, 0x1a, 0x2b, + 0xfd, 0x05, 0x8b, 0x0f, 0xaf, 0xa7, 0x3d, 0xbc, 0x21, 0x9f, 0x11, 0xbe, 0x74, 0x62, 0xf5, 0xa4, + 0x71, 0xba, 0xe5, 0xbc, 0x8a, 0xdd, 0xe6, 0x7f, 0x71, 0x20, 0x2c, 0x33, 0x61, 0x6f, 0x92, 0xad, + 0xd2, 0xb0, 0x3d, 0xcd, 0xa3, 0x3d, 0x3d, 0x4b, 0xf6, 0x1e, 0xe1, 0x15, 0xbb, 0x69, 0x72, 0xfb, + 0x8c, 0xbd, 0x1c, 0xaf, 0xd7, 0xdd, 0x5e, 0x0c, 0x0c, 0xb1, 0xb6, 0x4c, 0xac, 0x6b, 0xc4, 0x67, + 0xa7, 0x5f, 0xe3, 0xd6, 0xa3, 0xc3, 0xb1, 0x87, 0x8e, 0xc6, 0x1e, 0xfa, 0x35, 0xf6, 0xd0, 0x87, + 0x89, 0xe7, 0x1c, 0x4d, 0x3c, 0xe7, 0xfb, 0xc4, 0x73, 0x9e, 0xd3, 0x68, 0xa0, 0x5f, 0xe4, 0x21, + 0xed, 0xca, 0x21, 0x88, 0xd4, 0x63, 0x1e, 0xaa, 0x42, 0xf0, 0xd5, 0x3f, 0x49, 0x3d, 0x4a, 0x85, + 0x0a, 0x57, 0xcc, 0x1d, 0x6b, 0xfe, 0x0d, 0x00, 0x00, 0xff, 0xff, 0x72, 0x92, 0xdc, 0x7f, 0xc6, + 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -537,16 +542,18 @@ func (m *QueryProfileResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - { - size, err := m.Profile.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err + if m.Profile != nil { + { + size, err := m.Profile.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0xa } - i-- - dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -703,8 +710,10 @@ func (m *QueryProfileResponse) Size() (n int) { } var l int _ = l - l = m.Profile.Size() - n += 1 + l + sovQuery(uint64(l)) + if m.Profile != nil { + l = m.Profile.Size() + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -905,6 +914,9 @@ func (m *QueryProfileResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } + if m.Profile == nil { + m.Profile = &types.Any{} + } if err := m.Profile.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } From 05c8a35d7eadf21bb71dc869f4c2c5475eeb2548 Mon Sep 17 00:00:00 2001 From: "riccardo.montagnin" Date: Fri, 19 Mar 2021 12:52:59 +0100 Subject: [PATCH 03/11] Added back the DTAg -> Address store keys, to make the SaveProfile method execute faster Signed-off-by: riccardo.montagnin --- app/sim_test.go | 3 ++ x/profiles/keeper/alias_functions.go | 28 ----------- x/profiles/keeper/keeper.go | 17 +++++++ x/profiles/keeper/keeper_test.go | 55 --------------------- x/profiles/keeper/msgs_server.go | 7 ++- x/profiles/simulation/operations_profile.go | 33 ++++++------- 6 files changed, 41 insertions(+), 102 deletions(-) diff --git a/app/sim_test.go b/app/sim_test.go index d023bf8227..04f35d5f4c 100644 --- a/app/sim_test.go +++ b/app/sim_test.go @@ -69,6 +69,9 @@ func interBlockCacheOpt() func(*baseapp.BaseApp) { // SetupSimulation wraps simapp.SetupSimulation in order to create any export directory if they do not exist yet func SetupSimulation(dirPrefix, dbName string) (simtypes.Config, dbm.DB, string, log.Logger, bool, error) { config, db, dir, logger, skip, err := simapp.SetupSimulation(dirPrefix, dbName) + if err != nil { + return simtypes.Config{}, nil, "", nil, false, err + } paths := []string{config.ExportParamsPath, config.ExportStatePath, config.ExportStatsPath} for _, path := range paths { diff --git a/x/profiles/keeper/alias_functions.go b/x/profiles/keeper/alias_functions.go index 8795b13580..ac4b3f6f4e 100644 --- a/x/profiles/keeper/alias_functions.go +++ b/x/profiles/keeper/alias_functions.go @@ -31,31 +31,3 @@ func (k Keeper) GetProfiles(ctx sdk.Context) []*types.Profile { }) return profiles } - -// GetDtagFromAddress returns the dtag associated with the given address or an empty string if no dtag exists -func (k Keeper) GetDtagFromAddress(ctx sdk.Context, addr string) (dtag string, err error) { - profile, found, err := k.GetProfile(ctx, addr) - if err != nil { - return "", err - } - - if !found { - return "", nil - } - - return profile.Dtag, nil -} - -// GetAddressFromDtag returns the address associated to the given dtag or an empty string if it does not exists -func (k Keeper) GetAddressFromDtag(ctx sdk.Context, dtag string) (addr string) { - var address = "" - k.IterateProfiles(ctx, func(_ int64, profile *types.Profile) (stop bool) { - equals := profile.Dtag == dtag - if equals { - address = profile.GetAddress().String() - } - - return equals - }) - return address -} diff --git a/x/profiles/keeper/keeper.go b/x/profiles/keeper/keeper.go index 26afb469ae..1b22aaaa72 100644 --- a/x/profiles/keeper/keeper.go +++ b/x/profiles/keeper/keeper.go @@ -66,6 +66,11 @@ func (k Keeper) StoreProfile(ctx sdk.Context, profile *types.Profile) error { "a profile with dtag %s has already been created", profile.Dtag) } + // Store the DTag -> Address association + store := ctx.KVStore(k.storeKey) + store.Set([]byte(profile.Dtag), profile.GetAddress()) + + // Store the account inside the auth keeper k.ak.SetAccount(ctx, profile) return nil } @@ -85,6 +90,18 @@ func (k Keeper) GetProfile(ctx sdk.Context, address string) (profile *types.Prof return stored, true, nil } +// GetAddressFromDtag returns the address associated to the given dtag or an empty string if it does not exists +func (k Keeper) GetAddressFromDtag(ctx sdk.Context, dtag string) (addr string) { + store := ctx.KVStore(k.storeKey) + + bz := store.Get([]byte(dtag)) + if bz == nil { + return "" + } + + return string(bz) +} + // RemoveProfile allows to delete a profile associated with the given address inside the current context. // It assumes that the address-related profile exists. func (k Keeper) RemoveProfile(ctx sdk.Context, address string) error { diff --git a/x/profiles/keeper/keeper_test.go b/x/profiles/keeper/keeper_test.go index 8c76996217..f19aa4c634 100644 --- a/x/profiles/keeper/keeper_test.go +++ b/x/profiles/keeper/keeper_test.go @@ -61,61 +61,6 @@ func (suite *KeeperTestSuite) TestKeeper_IsUserBlocked() { } } -func (suite *KeeperTestSuite) TestKeeper_GetDtagFromAddress() { - tests := []struct { - name string - storedProfiles []*types.Profile - address string - shouldErr bool - expDTag string - }{ - { - name: "invalid address", - storedProfiles: nil, - address: "", - shouldErr: true, - }, - { - name: "found right dtag", - storedProfiles: []*types.Profile{ - suite.testData.profile, - }, - address: suite.testData.profile.GetAddress().String(), - shouldErr: false, - expDTag: suite.testData.profile.Dtag, - }, - { - name: "no dtag found", - storedProfiles: []*types.Profile{ - suite.testData.profile, - }, - address: "cosmos1ppkr0c0x6jvx9e4e48mfvhq2wzzsrync8qrt2m", - shouldErr: false, - expDTag: "", - }, - } - - for _, test := range tests { - suite.SetupTest() //reset - test := test - suite.Run(test.name, func() { - for _, profile := range test.storedProfiles { - err := suite.k.StoreProfile(suite.ctx, profile) - suite.Require().NoError(err) - } - - dTag, err := suite.k.GetDtagFromAddress(suite.ctx, test.address) - - if test.shouldErr { - suite.Require().Error(err) - } else { - suite.Require().NoError(err) - suite.Require().Equal(test.expDTag, dTag) - } - }) - } -} - func (suite *KeeperTestSuite) TestKeeper_StoreProfile() { addr, err := sdk.AccAddressFromBech32("cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns") suite.Require().NoError(err) diff --git a/x/profiles/keeper/msgs_server.go b/x/profiles/keeper/msgs_server.go index 9abefb912e..46e2aa806d 100644 --- a/x/profiles/keeper/msgs_server.go +++ b/x/profiles/keeper/msgs_server.go @@ -111,11 +111,16 @@ func (k msgServer) RequestDTagTransfer(goCtx context.Context, msg *types.MsgRequ return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "the user with address %s has blocked you", msg.Receiver) } - dtagToTrade, err := k.GetDtagFromAddress(ctx, msg.Receiver) + profile, found, err := k.GetProfile(ctx, msg.Receiver) if err != nil { return nil, err } + if !found { + return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "the request recipient does not have a profile yet") + } + + dtagToTrade := profile.Dtag if len(dtagToTrade) == 0 { return nil, sdkerrors.Wrapf( sdkerrors.ErrInvalidRequest, diff --git a/x/profiles/simulation/operations_profile.go b/x/profiles/simulation/operations_profile.go index 249138dd76..a3d0e6212f 100644 --- a/x/profiles/simulation/operations_profile.go +++ b/x/profiles/simulation/operations_profile.go @@ -32,7 +32,7 @@ func SimulateMsgSaveProfile( acc, data, skip := randomProfileSaveFields(r, ctx, accs, k, ak) if skip { - return simtypes.NoOpMsg(types.RouterKey, types.ModuleName, ""), nil, nil + return simtypes.NoOpMsg(types.RouterKey, types.ModuleName, "save profile"), nil, nil } msg := types.NewMsgSaveProfile( @@ -45,10 +45,10 @@ func SimulateMsgSaveProfile( ) err = sendMsgSaveProfile(r, app, ak, bk, msg, ctx, chainID, []cryptotypes.PrivKey{acc.PrivKey}) if err != nil { - return simtypes.NoOpMsg(types.RouterKey, types.ModuleName, ""), nil, err + return simtypes.NoOpMsg(types.RouterKey, types.ModuleName, "save profile"), nil, err } - return simtypes.NewOperationMsg(msg, true, ""), nil, nil + return simtypes.NewOperationMsg(msg, true, "save profile"), nil, nil } } @@ -140,17 +140,17 @@ func SimulateMsgDeleteProfile( ) (OperationMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) { acc, skip := randomProfileDeleteFields(r, ctx, accs, k, ak) if skip { - return simtypes.NoOpMsg(types.RouterKey, types.ModuleName, ""), nil, nil + return simtypes.NoOpMsg(types.RouterKey, types.ModuleName, "delete profile"), nil, nil } msg := types.NewMsgDeleteProfile(acc.Address.String()) err = sendMsgDeleteProfile(r, app, ak, bk, msg, ctx, chainID, []cryptotypes.PrivKey{acc.PrivKey}) if err != nil { - return simtypes.NoOpMsg(types.RouterKey, types.ModuleName, ""), nil, err + return simtypes.NoOpMsg(types.RouterKey, types.ModuleName, "delete profile"), nil, err } - return simtypes.NewOperationMsg(msg, true, ""), nil, nil + return simtypes.NewOperationMsg(msg, true, "delete profile"), nil, nil } } @@ -193,24 +193,21 @@ func sendMsgDeleteProfile( // randomProfileDeleteFields returns random profile data func randomProfileDeleteFields( - r *rand.Rand, ctx sdk.Context, accs []simtypes.Account, k keeper.Keeper, _ authkeeper.AccountKeeper, -) (simtypes.Account, bool) { + r *rand.Rand, ctx sdk.Context, accs []simtypes.Account, k keeper.Keeper, ak authkeeper.AccountKeeper, +) (account simtypes.Account, skip bool) { if len(accs) == 0 { return simtypes.Account{}, true } - accounts := k.GetProfiles(ctx) - if len(accounts) == 0 { - return simtypes.Account{}, true - } - account := RandomProfile(r, accounts) - - acc := GetSimAccount(account.GetAddress(), accs) + // Get a random account + account, _ = simtypes.RandomAcc(r, accs) + acc := ak.GetAccount(ctx, account.Address) - // Skip the operation without error as the profile is not valid - if acc == nil { + // See if the account has a profile, and skip if he does not + _, found, err := k.GetProfile(ctx, acc.GetAddress().String()) + if !found || err != nil { return simtypes.Account{}, true } - return *acc, false + return account, false } From b4d059d73cc1ce74f24d2c4d161ccd8c281c9e32 Mon Sep 17 00:00:00 2001 From: "riccardo.montagnin" Date: Tue, 23 Mar 2021 09:34:22 +0100 Subject: [PATCH 04/11] Fixing simulation tests and updated Cosmos dependency Signed-off-by: riccardo.montagnin --- Makefile | 5 +- app/app.go | 26 ++-- app/sim_test.go | 20 +-- go.mod | 12 +- go.sum | 39 ++++-- proto/desmos/profiles/v1beta1/models.proto | 1 - .../proto/cosmos/auth/v1beta1/auth.proto | 50 -------- x/fees/ante/ante_test.go | 16 +-- x/fees/ante/common_test.go | 4 +- x/fees/simulation/genesis.go | 46 +++---- x/fees/types/genesis.pb.go | 5 +- x/fees/types/min_fee.pb.go | 5 +- x/fees/types/params.pb.go | 5 +- x/fees/types/query.pb.go | 10 +- x/magpie/keeper/types.pb.go | 5 +- x/magpie/types/genesis.pb.go | 5 +- x/magpie/types/models.pb.go | 10 +- x/magpie/types/msgs.pb.go | 10 +- x/magpie/types/query.pb.go | 10 +- x/posts/types/genesis.pb.go | 15 +-- x/posts/types/msgs.pb.go | 60 ++------- x/posts/types/params.pb.go | 5 +- x/posts/types/polls.pb.go | 22 +--- x/posts/types/posts.pb.go | 27 +--- x/posts/types/query.pb.go | 57 ++------- x/posts/types/reactions.pb.go | 20 +-- x/profiles/keeper/alias_functions_test.go | 31 +++++ x/profiles/keeper/genesis.go | 14 +++ x/profiles/keeper/keeper.go | 22 +++- x/profiles/keeper/keeper_test.go | 116 ++++++++++++------ x/profiles/keeper/types.pb.go | 5 +- x/profiles/simulation/decoder.go | 7 ++ x/profiles/simulation/decoder_test.go | 10 ++ x/profiles/simulation/operations_profile.go | 11 +- x/profiles/types/genesis.pb.go | 5 +- x/profiles/types/keys.go | 6 + x/profiles/types/models.pb.go | 92 +++++++------- x/profiles/types/msgs.pb.go | 60 ++------- x/profiles/types/params.pb.go | 15 +-- x/profiles/types/query.pb.go | 30 +---- x/relationships/types/genesis.pb.go | 5 +- x/relationships/types/models.pb.go | 20 +-- x/relationships/types/msgs.pb.go | 40 ++---- x/relationships/types/query.pb.go | 20 +-- x/reports/types/genesis.pb.go | 5 +- x/reports/types/models.go | 4 +- x/reports/types/models.pb.go | 10 +- x/reports/types/msgs.pb.go | 10 +- x/reports/types/query.pb.go | 10 +- 49 files changed, 409 insertions(+), 629 deletions(-) delete mode 100644 third_party/proto/cosmos/auth/v1beta1/auth.proto diff --git a/Makefile b/Makefile index 8fb24f0096..6828480520 100644 --- a/Makefile +++ b/Makefile @@ -297,7 +297,7 @@ proto-check-breaking: TM_URL = https://raw.githubusercontent.com/tendermint/tendermint/v0.34.8/proto/tendermint GOGO_PROTO_URL = https://raw.githubusercontent.com/regen-network/protobuf/cosmos -COSMOS_URL = https://raw.githubusercontent.com/cosmos/cosmos-sdk/v0.42.1/proto/cosmos +COSMOS_URL = https://raw.githubusercontent.com/cosmos/cosmos-sdk/v0.42.2/proto/cosmos COSMOS_PROTO_URL = https://raw.githubusercontent.com/regen-network/cosmos-proto/master CONFIO_URL = https://raw.githubusercontent.com/confio/ics23/v0.6.3 @@ -316,9 +316,6 @@ proto-update-deps: @mkdir -p $(COSMOS_TYPES)/base/query/v1beta1 @curl -sSL $(COSMOS_URL)/base/query/v1beta1/pagination.proto > $(COSMOS_TYPES)/base/query/v1beta1/pagination.proto - @mkdir -p $(COSMOS_TYPES)/auth/v1beta1 - @curl -sSL $(COSMOS_URL)/auth/v1beta1/auth.proto > $(COSMOS_TYPES)/auth/v1beta1/auth.proto - @mkdir -p $(GOGO_PROTO_TYPES) @curl -sSL $(GOGO_PROTO_URL)/gogoproto/gogo.proto > $(GOGO_PROTO_TYPES)/gogo.proto diff --git a/app/app.go b/app/app.go index f898997cd8..79f51233c5 100644 --- a/app/app.go +++ b/app/app.go @@ -59,8 +59,8 @@ import ( feeskeeper "github.com/desmos-labs/desmos/x/fees/keeper" feestypes "github.com/desmos-labs/desmos/x/fees/types" "github.com/desmos-labs/desmos/x/magpie" - magpieKeeper "github.com/desmos-labs/desmos/x/magpie/keeper" - magpieTypes "github.com/desmos-labs/desmos/x/magpie/types" + magpiekeeper "github.com/desmos-labs/desmos/x/magpie/keeper" + magpietypes "github.com/desmos-labs/desmos/x/magpie/types" "github.com/desmos-labs/desmos/x/posts" postskeeper "github.com/desmos-labs/desmos/x/posts/keeper" poststypes "github.com/desmos-labs/desmos/x/posts/types" @@ -70,8 +70,8 @@ import ( relationshipskeeper "github.com/desmos-labs/desmos/x/relationships/keeper" relationshipstypes "github.com/desmos-labs/desmos/x/relationships/types" "github.com/desmos-labs/desmos/x/reports" - reportsKeeper "github.com/desmos-labs/desmos/x/reports/keeper" - reportsTypes "github.com/desmos-labs/desmos/x/reports/types" + reportskeeper "github.com/desmos-labs/desmos/x/reports/keeper" + reportstypes "github.com/desmos-labs/desmos/x/reports/types" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" @@ -179,10 +179,10 @@ type DesmosApp struct { // Custom modules FeesKeeper feeskeeper.Keeper - magpieKeeper magpieKeeper.Keeper + magpieKeeper magpiekeeper.Keeper postsKeeper postskeeper.Keeper ProfileKeeper profileskeeper.Keeper - ReportsKeeper reportsKeeper.Keeper + ReportsKeeper reportskeeper.Keeper RelationshipsKeeper relationshipskeeper.Keeper // Module Manager @@ -226,7 +226,7 @@ func NewDesmosApp( evidencetypes.StoreKey, // Custom modules - magpieTypes.StoreKey, poststypes.StoreKey, profilestypes.StoreKey, reportsTypes.StoreKey, + magpietypes.StoreKey, poststypes.StoreKey, profilestypes.StoreKey, reportstypes.StoreKey, relationshipstypes.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) @@ -297,9 +297,9 @@ func NewDesmosApp( appCodec, app.GetSubspace(feestypes.ModuleName), ) - app.magpieKeeper = magpieKeeper.NewKeeper( + app.magpieKeeper = magpiekeeper.NewKeeper( appCodec, - keys[magpieTypes.StoreKey], + keys[magpietypes.StoreKey], ) app.RelationshipsKeeper = relationshipskeeper.NewKeeper( appCodec, @@ -318,9 +318,9 @@ func NewDesmosApp( app.RelationshipsKeeper, app.AccountKeeper, ) - app.ReportsKeeper = reportsKeeper.NewKeeper( + app.ReportsKeeper = reportskeeper.NewKeeper( app.appCodec, - keys[reportsTypes.StoreKey], + keys[reportstypes.StoreKey], app.postsKeeper, ) @@ -374,8 +374,8 @@ func NewDesmosApp( stakingtypes.ModuleName, banktypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, evidencetypes.ModuleName, - feestypes.ModuleName, magpieTypes.ModuleName, poststypes.ModuleName, profilestypes.ModuleName, - reportsTypes.ModuleName, relationshipstypes.ModuleName, // custom modules + feestypes.ModuleName, magpietypes.ModuleName, poststypes.ModuleName, profilestypes.ModuleName, + reportstypes.ModuleName, relationshipstypes.ModuleName, // custom modules crisistypes.ModuleName, // runs the invariants at genesis - should run after other modules genutiltypes.ModuleName, // genutils must occur after staking so that pools are properly initialized with tokens from genesis accounts. diff --git a/app/sim_test.go b/app/sim_test.go index 04f35d5f4c..5efffc120e 100644 --- a/app/sim_test.go +++ b/app/sim_test.go @@ -16,11 +16,11 @@ import ( slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - magpieTypes "github.com/desmos-labs/desmos/x/magpie/types" - postsTypes "github.com/desmos-labs/desmos/x/posts/types" - profilesTypes "github.com/desmos-labs/desmos/x/profiles/types" - relationshipsTypes "github.com/desmos-labs/desmos/x/relationships/types" - reportsTypes "github.com/desmos-labs/desmos/x/reports/types" + magpietypes "github.com/desmos-labs/desmos/x/magpie/types" + poststypes "github.com/desmos-labs/desmos/x/posts/types" + profilestypes "github.com/desmos-labs/desmos/x/profiles/types" + relationshipstypes "github.com/desmos-labs/desmos/x/relationships/types" + reportstypes "github.com/desmos-labs/desmos/x/reports/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -217,11 +217,11 @@ func TestAppImportExport(t *testing.T) { {app.keys[govtypes.StoreKey], newApp.keys[govtypes.StoreKey], [][]byte{}}, {app.keys[evidencetypes.StoreKey], newApp.keys[evidencetypes.StoreKey], [][]byte{}}, - {app.keys[magpieTypes.StoreKey], newApp.keys[magpieTypes.StoreKey], [][]byte{}}, - {app.keys[postsTypes.StoreKey], newApp.keys[postsTypes.StoreKey], [][]byte{}}, - {app.keys[profilesTypes.StoreKey], newApp.keys[profilesTypes.StoreKey], [][]byte{}}, - {app.keys[reportsTypes.StoreKey], newApp.keys[reportsTypes.StoreKey], [][]byte{}}, - {app.keys[relationshipsTypes.StoreKey], newApp.keys[relationshipsTypes.StoreKey], [][]byte{}}, + {app.keys[magpietypes.StoreKey], newApp.keys[magpietypes.StoreKey], [][]byte{}}, + {app.keys[poststypes.StoreKey], newApp.keys[poststypes.StoreKey], [][]byte{}}, + {app.keys[profilestypes.StoreKey], newApp.keys[profilestypes.StoreKey], [][]byte{}}, + {app.keys[reportstypes.StoreKey], newApp.keys[reportstypes.StoreKey], [][]byte{}}, + {app.keys[relationshipstypes.StoreKey], newApp.keys[relationshipstypes.StoreKey], [][]byte{}}, } for _, skp := range storeKeysPrefixes { diff --git a/go.mod b/go.mod index 28fda477de..f29c55b88d 100644 --- a/go.mod +++ b/go.mod @@ -4,24 +4,24 @@ go 1.15 require ( github.com/btcsuite/btcd v0.21.0-beta - github.com/cosmos/cosmos-sdk v0.42.1 + github.com/cosmos/cosmos-sdk v0.42.2 github.com/desmos-labs/Go-Emoji-Utils v1.1.1-0.20200515063516-9c493b11de3e github.com/ghodss/yaml v1.0.0 github.com/gogo/protobuf v1.3.3 - github.com/golang/protobuf v1.4.3 - github.com/google/go-cmp v0.5.2 // indirect + github.com/golang/protobuf v1.5.1 github.com/gorilla/mux v1.8.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/rakyll/statik v0.1.7 github.com/regen-network/cosmos-proto v0.3.1 github.com/spf13/cast v1.3.1 - github.com/spf13/cobra v1.1.1 + github.com/spf13/cobra v1.1.3 github.com/spf13/viper v1.7.1 github.com/stretchr/testify v1.7.0 github.com/tendermint/tendermint v0.34.8 github.com/tendermint/tm-db v0.6.4 google.golang.org/genproto v0.0.0-20210114201628-6edceaf6022f - google.golang.org/grpc v1.35.0 + google.golang.org/grpc v1.36.0 + google.golang.org/protobuf v1.26.0 ) -replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4 +replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 diff --git a/go.sum b/go.sum index 1fa3509f0b..47048e435f 100644 --- a/go.sum +++ b/go.sum @@ -104,8 +104,8 @@ github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7 github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cosmos/cosmos-sdk v0.42.1 h1:/0SqvXdxbHBRUFRTLdiL4VYE18DMNXd2ONhC5d90EBQ= -github.com/cosmos/cosmos-sdk v0.42.1/go.mod h1:xiLp1G8mumj82S5KLJGCAyeAlD+7VNomg/aRSJV12yk= +github.com/cosmos/cosmos-sdk v0.42.2 h1:t2jIxV5DGN1ynOwuSIvQUUHr7tAePN1AG5ArM7o8qos= +github.com/cosmos/cosmos-sdk v0.42.2/go.mod h1:xiLp1G8mumj82S5KLJGCAyeAlD+7VNomg/aRSJV12yk= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= @@ -216,8 +216,10 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.1 h1:jAbXjIeW2ZSW2AwFxlGTDoc2CjI2XujLkV3ArsZFCvc= +github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.2 h1:aeE13tS0IiQgFjYdoL8qN3K1N2bXXtI6Vi51/y7BpMw= @@ -230,8 +232,8 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= -github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -330,7 +332,7 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d h1:Z+RDyXzjKE0i2sTjZ/b1uxiGtPhFy34Ou/Tk0qwN0kM= github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc= -github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/kkdai/bstream v1.0.0/go.mod h1:FDnDOHt5Yx4p3FaHcioFT0QjDOtgUpvjeZqAs+NVZZA= @@ -488,8 +490,8 @@ github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 h1:MkV+77GLUNo github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/regen-network/cosmos-proto v0.3.1 h1:rV7iM4SSFAagvy8RiyhiACbWEGotmqzywPxOvwMdxcg= github.com/regen-network/cosmos-proto v0.3.1/go.mod h1:jO0sVX6a1B36nmE8C9xBFXpNwWejXC7QqCOnH3O0+YM= -github.com/regen-network/protobuf v1.3.2-alpha.regen.4 h1:c9jEnU+xm6vqyrQe3M94UFWqiXxRIKKnqBOh2EACmBE= -github.com/regen-network/protobuf v1.3.2-alpha.regen.4/go.mod h1:/J8/bR1T/NXyIdQDLUaq15LjNE83nRzkyrLAMcPewig= +github.com/regen-network/protobuf v1.3.3-alpha.regen.1 h1:OHEc+q5iIAXpqiqFKeLpu5NwTIkVXUs48vFMwzqpqY4= +github.com/regen-network/protobuf v1.3.3-alpha.regen.1/go.mod h1:2DjTFR1HhMQhiWC5sZ4OhQ3+NtdbZ6oBDKQwq5Ou+FI= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= @@ -529,8 +531,9 @@ github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkU github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= -github.com/spf13/cobra v1.1.1 h1:KfztREH0tPxJJ+geloSLaAkaPkr4ki2Er5quFV1TDo4= github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI= +github.com/spf13/cobra v1.1.3 h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M= +github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= @@ -587,6 +590,8 @@ github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijb github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/zondax/hid v0.9.0 h1:eiT3P6vNxAEVxXMw66eZUAAnU2zD33JBkfG/EnfAKl8= github.com/zondax/hid v0.9.0/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= @@ -649,6 +654,8 @@ golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKG golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -672,6 +679,7 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= @@ -690,6 +698,7 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -744,7 +753,6 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxb golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= @@ -764,9 +772,11 @@ golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200110213125-a7a6caa82ab2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -823,8 +833,9 @@ google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= -google.golang.org/grpc v1.35.0 h1:TwIQcH3es+MojMVojxxfQ3l3OF2KzlRxML2xZq0kRo8= google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.36.0 h1:o1bcQ6imQMIOpdrO3SWf2z5RV72WbDwdXuK0MDlc8As= +google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -834,8 +845,10 @@ google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= -google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/proto/desmos/profiles/v1beta1/models.proto b/proto/desmos/profiles/v1beta1/models.proto index 21b9dcadcb..b3b413cf74 100644 --- a/proto/desmos/profiles/v1beta1/models.proto +++ b/proto/desmos/profiles/v1beta1/models.proto @@ -4,7 +4,6 @@ package desmos.profiles.v1beta1; import "gogoproto/gogo.proto"; import "google/protobuf/any.proto"; import "google/protobuf/timestamp.proto"; -import "cosmos/auth/v1beta1/auth.proto"; import "cosmos_proto/cosmos.proto"; option go_package = "github.com/desmos-labs/desmos/x/profiles/types"; diff --git a/third_party/proto/cosmos/auth/v1beta1/auth.proto b/third_party/proto/cosmos/auth/v1beta1/auth.proto deleted file mode 100644 index b988fd8dcf..0000000000 --- a/third_party/proto/cosmos/auth/v1beta1/auth.proto +++ /dev/null @@ -1,50 +0,0 @@ -syntax = "proto3"; -package cosmos.auth.v1beta1; - -import "cosmos_proto/cosmos.proto"; -import "gogoproto/gogo.proto"; -import "google/protobuf/any.proto"; - -option go_package = "github.com/cosmos/cosmos-sdk/x/auth/types"; - -// BaseAccount defines a base account type. It contains all the necessary fields -// for basic account functionality. Any custom account type should extend this -// type for additional functionality (e.g. vesting). -message BaseAccount { - option (gogoproto.goproto_getters) = false; - option (gogoproto.goproto_stringer) = false; - option (gogoproto.equal) = false; - - option (cosmos_proto.implements_interface) = "AccountI"; - - string address = 1; - google.protobuf.Any pub_key = 2 - [(gogoproto.jsontag) = "public_key,omitempty", (gogoproto.moretags) = "yaml:\"public_key\""]; - uint64 account_number = 3 [(gogoproto.moretags) = "yaml:\"account_number\""]; - uint64 sequence = 4; -} - -// ModuleAccount defines an account for modules that holds coins on a pool. -message ModuleAccount { - option (gogoproto.goproto_getters) = false; - option (gogoproto.goproto_stringer) = false; - option (cosmos_proto.implements_interface) = "ModuleAccountI"; - - BaseAccount base_account = 1 [(gogoproto.embed) = true, (gogoproto.moretags) = "yaml:\"base_account\""]; - string name = 2; - repeated string permissions = 3; -} - -// Params defines the parameters for the auth module. -message Params { - option (gogoproto.equal) = true; - option (gogoproto.goproto_stringer) = false; - - uint64 max_memo_characters = 1 [(gogoproto.moretags) = "yaml:\"max_memo_characters\""]; - uint64 tx_sig_limit = 2 [(gogoproto.moretags) = "yaml:\"tx_sig_limit\""]; - uint64 tx_size_cost_per_byte = 3 [(gogoproto.moretags) = "yaml:\"tx_size_cost_per_byte\""]; - uint64 sig_verify_cost_ed25519 = 4 - [(gogoproto.customname) = "SigVerifyCostED25519", (gogoproto.moretags) = "yaml:\"sig_verify_cost_ed25519\""]; - uint64 sig_verify_cost_secp256k1 = 5 - [(gogoproto.customname) = "SigVerifyCostSecp256k1", (gogoproto.moretags) = "yaml:\"sig_verify_cost_secp256k1\""]; -} diff --git a/x/fees/ante/ante_test.go b/x/fees/ante/ante_test.go index c6da08cb6b..e6f7bb2aa4 100644 --- a/x/fees/ante/ante_test.go +++ b/x/fees/ante/ante_test.go @@ -3,7 +3,7 @@ package ante_test import ( "time" - feesTypes "github.com/desmos-labs/desmos/x/fees/types" + feestypes "github.com/desmos-labs/desmos/x/fees/types" "github.com/desmos-labs/desmos/x/posts/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -17,7 +17,7 @@ func (suite *AnteTestSuite) TestAnteHandlerFees_MsgCreatePost() { tests := []struct { name string givenFee sdk.Coins - params feesTypes.Params + params feestypes.Params msgs []sdk.Msg privs []cryptotypes.PrivKey accNums []uint64 @@ -28,8 +28,8 @@ func (suite *AnteTestSuite) TestAnteHandlerFees_MsgCreatePost() { { name: "Signer has not specified the fees", givenFee: sdk.NewCoins(), - params: feesTypes.NewParams([]feesTypes.MinFee{ - feesTypes.NewMinFee("create_post", sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10000)))), + params: feestypes.NewParams([]feestypes.MinFee{ + feestypes.NewMinFee("create_post", sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10000)))), }), msgs: []sdk.Msg{ types.NewMsgCreatePost( @@ -61,8 +61,8 @@ func (suite *AnteTestSuite) TestAnteHandlerFees_MsgCreatePost() { { name: "Signer has not specified enough fees", givenFee: sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 9999)), - params: feesTypes.NewParams([]feesTypes.MinFee{ - feesTypes.NewMinFee("create_post", sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10000)))), + params: feestypes.NewParams([]feestypes.MinFee{ + feestypes.NewMinFee("create_post", sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10000)))), }), msgs: []sdk.Msg{ types.NewMsgCreatePost( @@ -94,8 +94,8 @@ func (suite *AnteTestSuite) TestAnteHandlerFees_MsgCreatePost() { { name: "Signer has specified enough fees", givenFee: sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 10000)), - params: feesTypes.NewParams([]feesTypes.MinFee{ - feesTypes.NewMinFee("create_post", sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10000)))), + params: feestypes.NewParams([]feestypes.MinFee{ + feestypes.NewMinFee("create_post", sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10000)))), }), msgs: []sdk.Msg{ types.NewMsgCreatePost( diff --git a/x/fees/ante/common_test.go b/x/fees/ante/common_test.go index 5db923ff23..91cfd53c8f 100644 --- a/x/fees/ante/common_test.go +++ b/x/fees/ante/common_test.go @@ -21,7 +21,7 @@ import ( desmos "github.com/desmos-labs/desmos/app" "github.com/desmos-labs/desmos/x/fees/ante" - feesTypes "github.com/desmos-labs/desmos/x/fees/types" + feestypes "github.com/desmos-labs/desmos/x/fees/types" ) // TestAccount represents an account used in the ante handler tests @@ -51,7 +51,7 @@ func createTestApp(isCheckTx bool) (*desmos.DesmosApp, sdk.Context) { ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{}) app.AccountKeeper.SetParams(ctx, authtypes.DefaultParams()) - app.FeesKeeper.SetParams(ctx, feesTypes.DefaultParams()) + app.FeesKeeper.SetParams(ctx, feestypes.DefaultParams()) return app, ctx } diff --git a/x/fees/simulation/genesis.go b/x/fees/simulation/genesis.go index 512f8e166b..3f5b97f4b7 100644 --- a/x/fees/simulation/genesis.go +++ b/x/fees/simulation/genesis.go @@ -7,11 +7,11 @@ import ( "fmt" "math/rand" - magpieTypes "github.com/desmos-labs/desmos/x/magpie/types" - postsTypes "github.com/desmos-labs/desmos/x/posts/types" - profilesTypes "github.com/desmos-labs/desmos/x/profiles/types" - relationshipsTypes "github.com/desmos-labs/desmos/x/relationships/types" - reportsTypes "github.com/desmos-labs/desmos/x/reports/types" + magpietypes "github.com/desmos-labs/desmos/x/magpie/types" + poststypes "github.com/desmos-labs/desmos/x/posts/types" + profilestypes "github.com/desmos-labs/desmos/x/profiles/types" + relationshipstypes "github.com/desmos-labs/desmos/x/relationships/types" + reportstypes "github.com/desmos-labs/desmos/x/reports/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -25,24 +25,24 @@ const ( ) var msgsTypes = []string{ - magpieTypes.ActionCreationSession, - postsTypes.ActionCreatePost, - postsTypes.ActionEditPost, - postsTypes.ActionAnswerPoll, - postsTypes.ActionAddPostReaction, - postsTypes.ActionRemovePostReaction, - postsTypes.ActionRegisterReaction, - profilesTypes.ActionSaveProfile, - profilesTypes.ActionDeleteProfile, - profilesTypes.ActionRequestDtag, - profilesTypes.ActionAcceptDtagTransfer, - profilesTypes.ActionRefuseDTagTransferRequest, - profilesTypes.ActionCancelDTagTransferRequest, - relationshipsTypes.ActionCreateRelationship, - relationshipsTypes.ActionDeleteRelationship, - relationshipsTypes.ActionBlockUser, - relationshipsTypes.ActionUnblockUser, - reportsTypes.ActionReportPost, + magpietypes.ActionCreationSession, + poststypes.ActionCreatePost, + poststypes.ActionEditPost, + poststypes.ActionAnswerPoll, + poststypes.ActionAddPostReaction, + poststypes.ActionRemovePostReaction, + poststypes.ActionRegisterReaction, + profilestypes.ActionSaveProfile, + profilestypes.ActionDeleteProfile, + profilestypes.ActionRequestDtag, + profilestypes.ActionAcceptDtagTransfer, + profilestypes.ActionRefuseDTagTransferRequest, + profilestypes.ActionCancelDTagTransferRequest, + relationshipstypes.ActionCreateRelationship, + relationshipstypes.ActionDeleteRelationship, + relationshipstypes.ActionBlockUser, + relationshipstypes.ActionUnblockUser, + reportstypes.ActionReportPost, } // RandomizedGenState generates a random GenesisState for the fees module diff --git a/x/fees/types/genesis.pb.go b/x/fees/types/genesis.pb.go index d08b7037bc..874c7d9607 100644 --- a/x/fees/types/genesis.pb.go +++ b/x/fees/types/genesis.pb.go @@ -220,10 +220,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthGenesis - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthGenesis } if (iNdEx + skippy) > l { diff --git a/x/fees/types/min_fee.pb.go b/x/fees/types/min_fee.pb.go index e4174c3642..186a19866b 100644 --- a/x/fees/types/min_fee.pb.go +++ b/x/fees/types/min_fee.pb.go @@ -288,10 +288,7 @@ func (m *MinFee) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMinFee - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMinFee } if (iNdEx + skippy) > l { diff --git a/x/fees/types/params.pb.go b/x/fees/types/params.pb.go index 0acdf9d0c3..bd22b77f20 100644 --- a/x/fees/types/params.pb.go +++ b/x/fees/types/params.pb.go @@ -230,10 +230,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthParams - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthParams } if (iNdEx + skippy) > l { diff --git a/x/fees/types/query.pb.go b/x/fees/types/query.pb.go index 21784a169d..1d8c440c11 100644 --- a/x/fees/types/query.pb.go +++ b/x/fees/types/query.pb.go @@ -350,10 +350,7 @@ func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { @@ -436,10 +433,7 @@ func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { diff --git a/x/magpie/keeper/types.pb.go b/x/magpie/keeper/types.pb.go index 97e5f4cf06..1f46868ce0 100644 --- a/x/magpie/keeper/types.pb.go +++ b/x/magpie/keeper/types.pb.go @@ -228,10 +228,7 @@ func (m *WrappedSessionLength) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthTypes } if (iNdEx + skippy) > l { diff --git a/x/magpie/types/genesis.pb.go b/x/magpie/types/genesis.pb.go index bc31c22269..fb00febdc0 100644 --- a/x/magpie/types/genesis.pb.go +++ b/x/magpie/types/genesis.pb.go @@ -270,10 +270,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthGenesis - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthGenesis } if (iNdEx + skippy) > l { diff --git a/x/magpie/types/models.pb.go b/x/magpie/types/models.pb.go index ada2bc6dfa..27710f8266 100644 --- a/x/magpie/types/models.pb.go +++ b/x/magpie/types/models.pb.go @@ -507,10 +507,7 @@ func (m *SessionID) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthModels - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthModels } if (iNdEx + skippy) > l { @@ -791,10 +788,7 @@ func (m *Session) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthModels - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthModels } if (iNdEx + skippy) > l { diff --git a/x/magpie/types/msgs.pb.go b/x/magpie/types/msgs.pb.go index b448371816..2373cd6c92 100644 --- a/x/magpie/types/msgs.pb.go +++ b/x/magpie/types/msgs.pb.go @@ -555,10 +555,7 @@ func (m *MsgCreateSession) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -608,10 +605,7 @@ func (m *MsgCreateSessionResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { diff --git a/x/magpie/types/query.pb.go b/x/magpie/types/query.pb.go index 0f921d919a..fb18e6d08e 100644 --- a/x/magpie/types/query.pb.go +++ b/x/magpie/types/query.pb.go @@ -402,10 +402,7 @@ func (m *QuerySessionRequest) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { @@ -491,10 +488,7 @@ func (m *QuerySessionResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { diff --git a/x/posts/types/genesis.pb.go b/x/posts/types/genesis.pb.go index ae41ed2464..9f4ca384d4 100644 --- a/x/posts/types/genesis.pb.go +++ b/x/posts/types/genesis.pb.go @@ -718,10 +718,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthGenesis - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthGenesis } if (iNdEx + skippy) > l { @@ -837,10 +834,7 @@ func (m *UserAnswersEntry) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthGenesis - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthGenesis } if (iNdEx + skippy) > l { @@ -956,10 +950,7 @@ func (m *PostReactionsEntry) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthGenesis - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthGenesis } if (iNdEx + skippy) > l { diff --git a/x/posts/types/msgs.pb.go b/x/posts/types/msgs.pb.go index 2c1ab80d5c..cb08a01ae9 100644 --- a/x/posts/types/msgs.pb.go +++ b/x/posts/types/msgs.pb.go @@ -1871,10 +1871,7 @@ func (m *MsgCreatePost) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -1924,10 +1921,7 @@ func (m *MsgCreatePostResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -2143,10 +2137,7 @@ func (m *MsgEditPost) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -2196,10 +2187,7 @@ func (m *MsgEditPostResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -2345,10 +2333,7 @@ func (m *MsgAddPostReaction) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -2398,10 +2383,7 @@ func (m *MsgAddPostReactionResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -2547,10 +2529,7 @@ func (m *MsgRemovePostReaction) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -2600,10 +2579,7 @@ func (m *MsgRemovePostReactionResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -2749,10 +2725,7 @@ func (m *MsgAnswerPoll) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -2802,10 +2775,7 @@ func (m *MsgAnswerPollResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -2983,10 +2953,7 @@ func (m *MsgRegisterReaction) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -3036,10 +3003,7 @@ func (m *MsgRegisterReactionResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { diff --git a/x/posts/types/params.pb.go b/x/posts/types/params.pb.go index 1b7250bc3d..0352136876 100644 --- a/x/posts/types/params.pb.go +++ b/x/posts/types/params.pb.go @@ -315,10 +315,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthParams - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthParams } if (iNdEx + skippy) > l { diff --git a/x/posts/types/polls.pb.go b/x/posts/types/polls.pb.go index 980faf6a8a..8ebe7df944 100644 --- a/x/posts/types/polls.pb.go +++ b/x/posts/types/polls.pb.go @@ -8,7 +8,7 @@ import ( _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" - _ "github.com/golang/protobuf/ptypes/timestamp" + _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" math_bits "math/bits" @@ -783,10 +783,7 @@ func (m *PollAnswer) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthPolls - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthPolls } if (iNdEx + skippy) > l { @@ -975,10 +972,7 @@ func (m *PollData) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthPolls - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthPolls } if (iNdEx + skippy) > l { @@ -1092,10 +1086,7 @@ func (m *UserAnswer) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthPolls - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthPolls } if (iNdEx + skippy) > l { @@ -1179,10 +1170,7 @@ func (m *UserAnswers) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthPolls - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthPolls } if (iNdEx + skippy) > l { diff --git a/x/posts/types/posts.pb.go b/x/posts/types/posts.pb.go index 3423dcfd1e..fd53e12776 100644 --- a/x/posts/types/posts.pb.go +++ b/x/posts/types/posts.pb.go @@ -8,7 +8,7 @@ import ( _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" - _ "github.com/golang/protobuf/ptypes/timestamp" + _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" math_bits "math/bits" @@ -1004,10 +1004,7 @@ func (m *PostIndex) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthPosts - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthPosts } if (iNdEx + skippy) > l { @@ -1407,10 +1404,7 @@ func (m *Post) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthPosts - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthPosts } if (iNdEx + skippy) > l { @@ -1492,10 +1486,7 @@ func (m *CommentIDs) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthPosts - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthPosts } if (iNdEx + skippy) > l { @@ -1641,10 +1632,7 @@ func (m *Attachment) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthPosts - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthPosts } if (iNdEx + skippy) > l { @@ -1758,10 +1746,7 @@ func (m *OptionalDataEntry) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthPosts - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthPosts } if (iNdEx + skippy) > l { diff --git a/x/posts/types/query.pb.go b/x/posts/types/query.pb.go index 39fdfd98e7..0ed49242de 100644 --- a/x/posts/types/query.pb.go +++ b/x/posts/types/query.pb.go @@ -11,11 +11,11 @@ import ( grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" - _ "github.com/golang/protobuf/ptypes/timestamp" _ "google.golang.org/genproto/googleapis/api/annotations" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" + _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" math_bits "math/bits" @@ -2035,10 +2035,7 @@ func (m *QueryPostsParams) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { @@ -2352,10 +2349,7 @@ func (m *QueryPostsRequest) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { @@ -2475,10 +2469,7 @@ func (m *QueryPostsResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { @@ -2560,10 +2551,7 @@ func (m *QueryPostRequest) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { @@ -2746,10 +2734,7 @@ func (m *QueryPostResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { @@ -2831,10 +2816,7 @@ func (m *QueryPollAnswersRequest) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { @@ -2950,10 +2932,7 @@ func (m *QueryPollAnswersResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { @@ -3003,10 +2982,7 @@ func (m *QueryRegisteredReactionsRequest) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { @@ -3090,10 +3066,7 @@ func (m *QueryRegisteredReactionsResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { @@ -3143,10 +3116,7 @@ func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { @@ -3229,10 +3199,7 @@ func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { diff --git a/x/posts/types/reactions.pb.go b/x/posts/types/reactions.pb.go index e9a0deff76..d61b394169 100644 --- a/x/posts/types/reactions.pb.go +++ b/x/posts/types/reactions.pb.go @@ -772,10 +772,7 @@ func (m *RegisteredReaction) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthReactions - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthReactions } if (iNdEx + skippy) > l { @@ -859,10 +856,7 @@ func (m *RegisteredReactions) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthReactions - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthReactions } if (iNdEx + skippy) > l { @@ -1008,10 +1002,7 @@ func (m *PostReaction) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthReactions - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthReactions } if (iNdEx + skippy) > l { @@ -1095,10 +1086,7 @@ func (m *PostReactions) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthReactions - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthReactions } if (iNdEx + skippy) > l { diff --git a/x/profiles/keeper/alias_functions_test.go b/x/profiles/keeper/alias_functions_test.go index ea17e6a0c6..15510eef6c 100644 --- a/x/profiles/keeper/alias_functions_test.go +++ b/x/profiles/keeper/alias_functions_test.go @@ -85,3 +85,34 @@ func (suite *KeeperTestSuite) TestKeeper_IterateProfile() { suite.Contains(expProfiles, profile) } } + +func (suite *KeeperTestSuite) TestKeeper_GetProfiles() { + tests := []struct { + name string + accounts []*types.Profile + }{ + { + name: "Non empty Profiles list returned", + accounts: []*types.Profile{suite.testData.profile}, + }, + { + name: "Profile not found", + accounts: nil, + }, + } + + for _, test := range tests { + test := test + suite.Run(test.name, func() { + suite.SetupTest() + + for _, profile := range test.accounts { + err := suite.k.StoreProfile(suite.ctx, profile) + suite.Require().NoError(err) + } + + res := suite.k.GetProfiles(suite.ctx) + suite.Require().Equal(test.accounts, res) + }) + } +} diff --git a/x/profiles/keeper/genesis.go b/x/profiles/keeper/genesis.go index a7220b71a9..c6b6420ff9 100644 --- a/x/profiles/keeper/genesis.go +++ b/x/profiles/keeper/genesis.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" abci "github.com/tendermint/tendermint/abci/types" "github.com/desmos-labs/desmos/x/profiles/types" @@ -17,8 +18,21 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { // InitGenesis initializes the chain state based on the given GenesisState func (k Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) []abci.ValidatorUpdate { + // Initialize the module params k.SetParams(ctx, data.Params) + // Initialize the profiles + k.ak.IterateAccounts(ctx, func(account authtypes.AccountI) (stop bool) { + if profile, ok := (account).(*types.Profile); ok { + err := k.StoreProfile(ctx, profile) + if err != nil { + panic(err) + } + } + return false + }) + + // Store the transfer requests for _, request := range data.DtagTransferRequests { err := k.SaveDTagTransferRequest(ctx, request) if err != nil { diff --git a/x/profiles/keeper/keeper.go b/x/profiles/keeper/keeper.go index 1b22aaaa72..0d8b0989cd 100644 --- a/x/profiles/keeper/keeper.go +++ b/x/profiles/keeper/keeper.go @@ -66,9 +66,19 @@ func (k Keeper) StoreProfile(ctx sdk.Context, profile *types.Profile) error { "a profile with dtag %s has already been created", profile.Dtag) } - // Store the DTag -> Address association store := ctx.KVStore(k.storeKey) - store.Set([]byte(profile.Dtag), profile.GetAddress()) + + // Remove the previous DTag association (if the profile is being edited) + oldProfile, found, err := k.GetProfile(ctx, profile.GetAddress().String()) + if err != nil { + return err + } + if found { + store.Delete(types.DTagStoreKey(oldProfile.Dtag)) + } + + // Store the DTag -> Address association + store.Set(types.DTagStoreKey(profile.Dtag), profile.GetAddress()) // Store the account inside the auth keeper k.ak.SetAccount(ctx, profile) @@ -94,12 +104,12 @@ func (k Keeper) GetProfile(ctx sdk.Context, address string) (profile *types.Prof func (k Keeper) GetAddressFromDtag(ctx sdk.Context, dtag string) (addr string) { store := ctx.KVStore(k.storeKey) - bz := store.Get([]byte(dtag)) + bz := store.Get(types.DTagStoreKey(dtag)) if bz == nil { return "" } - return string(bz) + return sdk.AccAddress(bz).String() } // RemoveProfile allows to delete a profile associated with the given address inside the current context. @@ -115,6 +125,10 @@ func (k Keeper) RemoveProfile(ctx sdk.Context, address string) error { "no profile associated with the following address found: %s", address) } + // Delete the DTag -> Address association + store := ctx.KVStore(k.storeKey) + store.Delete(types.DTagStoreKey(profile.Dtag)) + // Delete the profile data by replacing the stored account k.ak.SetAccount(ctx, profile.GetAccount()) return nil diff --git a/x/profiles/keeper/keeper_test.go b/x/profiles/keeper/keeper_test.go index f19aa4c634..14128e5ac5 100644 --- a/x/profiles/keeper/keeper_test.go +++ b/x/profiles/keeper/keeper_test.go @@ -68,29 +68,47 @@ func (suite *KeeperTestSuite) TestKeeper_StoreProfile() { accountAny, err := codectypes.NewAnyWithValue(authtypes.NewBaseAccountWithAddress(addr)) suite.Require().NoError(err) + updatedProfile, err := types.NewProfile( + "updated-dtag", + "updated-moniker", + suite.testData.profile.Bio, + suite.testData.profile.Pictures, + suite.testData.profile.CreationDate, + suite.testData.profile.GetAccount(), + ) + suite.Require().NoError(err) + tests := []struct { name string account *types.Profile storedProfiles []*types.Profile - expError error + shouldErr bool }{ { - name: "Non existent Profile saved correctly", - account: suite.testData.profile, - storedProfiles: nil, - expError: nil, + name: "Non existent profile is saved correctly", + account: suite.testData.profile, + shouldErr: false, + }, + { + name: "Edited profile is saved correctly", + storedProfiles: []*types.Profile{ + suite.testData.profile, + }, + account: updatedProfile, + shouldErr: false, }, { name: "Existent account with different creator returns error", + storedProfiles: []*types.Profile{ + suite.testData.profile, + }, account: &types.Profile{ Dtag: suite.testData.profile.Dtag, Bio: suite.testData.profile.Bio, Pictures: suite.testData.profile.Pictures, Account: accountAny, }, - storedProfiles: []*types.Profile{suite.testData.profile}, - expError: sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, - "a profile with dtag dtag has already been created"), + shouldErr: true, }, } @@ -98,12 +116,29 @@ func (suite *KeeperTestSuite) TestKeeper_StoreProfile() { test := test suite.Run(test.name, func() { for _, profile := range test.storedProfiles { - err := suite.k.StoreProfile(suite.ctx, profile) + err = suite.k.StoreProfile(suite.ctx, profile) suite.Require().NoError(err) } - err := suite.k.StoreProfile(suite.ctx, test.account) - suite.RequireErrorsEqual(test.expError, err) + err = suite.k.StoreProfile(suite.ctx, test.account) + if test.shouldErr { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + + // Verify the DTag -> Address association + store := suite.ctx.KVStore(suite.storeKey) + suite.Require().Equal(test.account.GetAddress().Bytes(), store.Get(types.DTagStoreKey(test.account.Dtag)), + "DTag -> Address association not correct") + + for _, stored := range test.storedProfiles { + // Make sure that if the DTag has been edited, the old association has been removed + if stored.GetAddress().Equals(test.account.GetAddress()) && stored.Dtag != test.account.Dtag { + suite.Require().Nil(store.Get(types.DTagStoreKey(stored.Dtag)), + "Old DTag -> Address association still exists") + } + } + } }) } } @@ -166,32 +201,24 @@ func (suite *KeeperTestSuite) TestKeeper_GetProfile() { } } -func (suite *KeeperTestSuite) TestKeeper_RemoveProfile() { - err := suite.k.StoreProfile(suite.ctx, suite.testData.profile) - suite.Require().Nil(err) - - _, found, _ := suite.k.GetProfile(suite.ctx, suite.testData.profile.GetAddress().String()) - suite.True(found) - - err = suite.k.RemoveProfile(suite.ctx, suite.testData.profile.GetAddress().String()) - suite.Require().NoError(err) - - _, found, _ = suite.k.GetProfile(suite.ctx, suite.testData.profile.GetAddress().String()) - suite.Require().False(found) -} - -func (suite *KeeperTestSuite) TestKeeper_GetProfiles() { +func (suite *KeeperTestSuite) TestKeeper_GetAddressFromDTag() { tests := []struct { - name string - accounts []*types.Profile + name string + profile *types.Profile + dTag string + expAddr string }{ { - name: "Non empty Profiles list returned", - accounts: []*types.Profile{suite.testData.profile}, + name: "valid profile returns correct address", + profile: suite.testData.profile, + dTag: suite.testData.profile.Dtag, + expAddr: suite.testData.profile.GetAddress().String(), }, { - name: "Profile not found", - accounts: nil, + name: "non existing profile returns empty address", + profile: nil, + dTag: "test", + expAddr: "", }, } @@ -200,17 +227,34 @@ func (suite *KeeperTestSuite) TestKeeper_GetProfiles() { suite.Run(test.name, func() { suite.SetupTest() - for _, profile := range test.accounts { - err := suite.k.StoreProfile(suite.ctx, profile) + if test.profile != nil { + err := suite.k.StoreProfile(suite.ctx, test.profile) suite.Require().NoError(err) } - res := suite.k.GetProfiles(suite.ctx) - suite.Require().Equal(test.accounts, res) + addr := suite.k.GetAddressFromDtag(suite.ctx, test.dTag) + suite.Require().Equal(test.expAddr, addr) }) } } +func (suite *KeeperTestSuite) TestKeeper_RemoveProfile() { + err := suite.k.StoreProfile(suite.ctx, suite.testData.profile) + suite.Require().Nil(err) + + _, found, _ := suite.k.GetProfile(suite.ctx, suite.testData.profile.GetAddress().String()) + suite.True(found) + + err = suite.k.RemoveProfile(suite.ctx, suite.testData.profile.GetAddress().String()) + suite.Require().NoError(err) + + _, found, _ = suite.k.GetProfile(suite.ctx, suite.testData.profile.GetAddress().String()) + suite.Require().False(found) + + addr := suite.k.GetAddressFromDtag(suite.ctx, suite.testData.profile.Dtag) + suite.Require().Equal("", addr) +} + func (suite *KeeperTestSuite) TestKeeper_ValidateProfile() { tests := []struct { name string diff --git a/x/profiles/keeper/types.pb.go b/x/profiles/keeper/types.pb.go index 7813db7c91..a882e6d3e0 100644 --- a/x/profiles/keeper/types.pb.go +++ b/x/profiles/keeper/types.pb.go @@ -263,10 +263,7 @@ func (m *WrappedDTagTransferRequests) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthTypes } if (iNdEx + skippy) > l { diff --git a/x/profiles/simulation/decoder.go b/x/profiles/simulation/decoder.go index d80aed8ef4..7bf2898cae 100644 --- a/x/profiles/simulation/decoder.go +++ b/x/profiles/simulation/decoder.go @@ -4,6 +4,8 @@ import ( "bytes" "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/desmos-labs/desmos/x/profiles/keeper" "github.com/cosmos/cosmos-sdk/codec" @@ -17,6 +19,11 @@ import ( func NewDecodeStore(cdc codec.Marshaler) func(kvA, kvB kv.Pair) string { return func(kvA, kvB kv.Pair) string { switch { + case bytes.HasPrefix(kvA.Key, types.DTagPrefix): + addressA := sdk.AccAddress(bytes.TrimPrefix(kvA.Value, types.DTagPrefix)).String() + addressB := sdk.AccAddress(bytes.TrimPrefix(kvB.Value, types.DTagPrefix)).String() + return fmt.Sprintf("DTagAddressA: %s\nDTagAddressB: %s\n", addressA, addressB) + case bytes.HasPrefix(kvA.Key, types.DTagTransferRequestsPrefix): var requestsA, requestsB keeper.WrappedDTagTransferRequests cdc.MustUnmarshalBinaryBare(kvA.Value, &requestsA) diff --git a/x/profiles/simulation/decoder_test.go b/x/profiles/simulation/decoder_test.go index 10dee74962..639031882d 100644 --- a/x/profiles/simulation/decoder_test.go +++ b/x/profiles/simulation/decoder_test.go @@ -4,6 +4,8 @@ import ( "fmt" "testing" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/kv" "github.com/desmos-labs/desmos/app" @@ -27,7 +29,14 @@ func TestDecodeStore(t *testing.T) { ), }) + addr, err := sdk.AccAddressFromBech32("cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns") + require.NoError(t, err) + kvPairs := kv.Pairs{Pairs: []kv.Pair{ + { + Key: types.DTagStoreKey("AAkvohxhflhXsuyMg"), + Value: addr, + }, { Key: types.DtagTransferRequestStoreKey("cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns"), Value: cdc.MustMarshalBinaryBare(&requests), @@ -38,6 +47,7 @@ func TestDecodeStore(t *testing.T) { name string expectedLog string }{ + {"DTags", fmt.Sprintf("DTagAddressA: %s\nDTagAddressB: %s\n", "cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns", "cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns")}, {"Requests", fmt.Sprintf("RequestsA: %s\nRequestsB: %s\n", requests.Requests, requests.Requests)}, {"other", ""}, } diff --git a/x/profiles/simulation/operations_profile.go b/x/profiles/simulation/operations_profile.go index a3d0e6212f..7e79c2aea1 100644 --- a/x/profiles/simulation/operations_profile.go +++ b/x/profiles/simulation/operations_profile.go @@ -92,17 +92,16 @@ func sendMsgSaveProfile( // randomProfileSaveFields returns random profile data func randomProfileSaveFields( r *rand.Rand, ctx sdk.Context, accs []simtypes.Account, k keeper.Keeper, ak authkeeper.AccountKeeper, -) (simtypes.Account, *types.Profile, bool) { +) (account simtypes.Account, profile *types.Profile, skip bool) { if len(accs) == 0 { return simtypes.Account{}, nil, true } // Get a random account - account, _ := simtypes.RandomAcc(r, accs) + account, _ = simtypes.RandomAcc(r, accs) acc := ak.GetAccount(ctx, account.Address) // See if there is already the profile, otherwise create it from scratch - var profile *types.Profile existing, found, err := k.GetProfile(ctx, account.Address.String()) if err != nil { return simtypes.Account{}, nil, true @@ -114,6 +113,12 @@ func randomProfileSaveFields( profile = NewRandomProfile(r, acc) } + // Skip if another profile with the same DTag exists + address := k.GetAddressFromDtag(ctx, profile.Dtag) + if address != acc.GetAddress().String() { + return simtypes.Account{}, nil, true + } + // 50% chance of changing something if r.Intn(101) <= 50 { profile, _ = profile.Update(types.NewProfileUpdate( diff --git a/x/profiles/types/genesis.pb.go b/x/profiles/types/genesis.pb.go index 7c883ff42e..82723acd94 100644 --- a/x/profiles/types/genesis.pb.go +++ b/x/profiles/types/genesis.pb.go @@ -290,10 +290,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthGenesis - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthGenesis } if (iNdEx + skippy) > l { diff --git a/x/profiles/types/keys.go b/x/profiles/types/keys.go index 20eb4e6eba..e1cad977cb 100644 --- a/x/profiles/types/keys.go +++ b/x/profiles/types/keys.go @@ -23,9 +23,15 @@ const ( ) var ( + DTagPrefix = []byte("dtag") DTagTransferRequestsPrefix = []byte("transfer_requests") ) +// DTagStoreKey turns a DTag into the key used to store the address associated with it into the store +func DTagStoreKey(dtag string) []byte { + return append(DTagPrefix, dtag...) +} + // DtagTransferRequestStoreKey turns an address to a key used to store a transfer request into the profiles store func DtagTransferRequestStoreKey(address string) []byte { return append(DTagTransferRequestsPrefix, address...) diff --git a/x/profiles/types/models.pb.go b/x/profiles/types/models.pb.go index ab3983833a..157b744de7 100644 --- a/x/profiles/types/models.pb.go +++ b/x/profiles/types/models.pb.go @@ -6,12 +6,11 @@ package types import ( fmt "fmt" types "github.com/cosmos/cosmos-sdk/codec/types" - _ "github.com/cosmos/cosmos-sdk/x/auth/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" - _ "github.com/golang/protobuf/ptypes/timestamp" _ "github.com/regen-network/cosmos-proto" + _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" math_bits "math/bits" @@ -198,43 +197,43 @@ func init() { } var fileDescriptor_dcbf89d5cd53a9ca = []byte{ - // 570 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x93, 0x3d, 0x6f, 0xd3, 0x40, - 0x18, 0xc7, 0x6d, 0xfa, 0x66, 0x2e, 0x49, 0x0b, 0x6e, 0xa4, 0x9a, 0x0c, 0xbe, 0x72, 0x20, 0x04, - 0x12, 0xb5, 0x15, 0xd8, 0xa2, 0x2e, 0x8d, 0x3a, 0xc0, 0x56, 0x9d, 0x22, 0x06, 0x96, 0xe8, 0x6c, - 0x5f, 0x5c, 0x43, 0xec, 0x0b, 0xf6, 0x39, 0x22, 0xdf, 0x80, 0xb1, 0x62, 0xea, 0x98, 0x0f, 0xc1, - 0xc2, 0x37, 0xa8, 0x98, 0x3a, 0x32, 0x19, 0x94, 0x2c, 0x88, 0xd1, 0x9f, 0x00, 0xd9, 0x77, 0x97, - 0xd0, 0x22, 0x36, 0x3f, 0xcf, 0xff, 0xf7, 0xbc, 0x9f, 0xc1, 0xe3, 0x80, 0x66, 0x31, 0xcb, 0xdc, - 0x49, 0xca, 0x46, 0xd1, 0x98, 0x66, 0xee, 0xb4, 0xeb, 0x51, 0x4e, 0xba, 0x6e, 0xcc, 0x02, 0x3a, - 0xce, 0x9c, 0x49, 0xca, 0x38, 0x33, 0x0f, 0x04, 0xe5, 0x28, 0xca, 0x91, 0x54, 0xa7, 0x1d, 0xb2, - 0x90, 0xd5, 0x8c, 0x5b, 0x7d, 0x09, 0xbc, 0xf3, 0x20, 0x64, 0x2c, 0x1c, 0x53, 0xb7, 0xb6, 0xbc, - 0x7c, 0xe4, 0x92, 0x64, 0x26, 0x25, 0x78, 0x5b, 0xe2, 0x51, 0x4c, 0x33, 0x4e, 0xe2, 0x89, 0x04, - 0x6c, 0x9f, 0xd5, 0x0d, 0x91, 0x9c, 0x9f, 0xaf, 0x9a, 0xa9, 0x0c, 0x95, 0x5b, 0xe8, 0x43, 0x51, - 0x54, 0x18, 0x42, 0x42, 0xef, 0x80, 0x71, 0x16, 0xf9, 0x3c, 0x4f, 0x69, 0x66, 0x3e, 0x07, 0x3b, - 0xb2, 0x59, 0x4b, 0x3f, 0xd4, 0x9f, 0xde, 0xed, 0x9b, 0x65, 0x01, 0x77, 0x67, 0x24, 0x1e, 0xf7, - 0x90, 0x14, 0x10, 0x56, 0x88, 0xf9, 0x04, 0x6c, 0xf9, 0x6c, 0x4a, 0x53, 0xeb, 0x4e, 0xcd, 0xde, - 0x2b, 0x0b, 0xd8, 0x14, 0x6c, 0xed, 0x46, 0x58, 0xc8, 0x3d, 0xe3, 0x72, 0x0e, 0xf5, 0x5f, 0x73, - 0xa8, 0xa3, 0xcf, 0x1b, 0x60, 0xe7, 0x4c, 0x46, 0x1f, 0x83, 0x1d, 0xe2, 0xfb, 0x2c, 0x4f, 0x78, - 0x5d, 0xab, 0xf1, 0xa2, 0xed, 0x88, 0x29, 0x1d, 0x35, 0xa5, 0x73, 0x92, 0xcc, 0xfa, 0xcd, 0x6f, - 0x5f, 0x8e, 0x8c, 0x13, 0x01, 0xbe, 0xc6, 0x2a, 0xc4, 0x7c, 0x04, 0x36, 0x03, 0x4e, 0x42, 0x59, - 0x7a, 0xaf, 0x2c, 0x60, 0x43, 0x94, 0xae, 0xbc, 0x08, 0xd7, 0x62, 0x35, 0x4e, 0xcc, 0x92, 0xe8, - 0x3d, 0x4d, 0xad, 0x8d, 0xdb, 0xe3, 0x48, 0x01, 0x61, 0x85, 0x98, 0x87, 0x60, 0xc3, 0x8b, 0x98, - 0xb5, 0x59, 0x93, 0xbb, 0x65, 0x01, 0x81, 0x20, 0xbd, 0x88, 0x21, 0x5c, 0x49, 0xe6, 0x1b, 0x60, - 0x4c, 0xe4, 0xaa, 0xac, 0xad, 0xba, 0xe7, 0x87, 0xce, 0x7f, 0x6e, 0xec, 0xa8, 0x9d, 0xf6, 0x0f, - 0xae, 0x0a, 0xa8, 0x95, 0x05, 0xdc, 0x93, 0x6b, 0x94, 0x7e, 0x84, 0x57, 0xb9, 0xcc, 0x14, 0xb4, - 0xfc, 0x94, 0x12, 0x1e, 0xb1, 0x64, 0x18, 0x10, 0x4e, 0xad, 0xed, 0x3a, 0x79, 0xe7, 0x9f, 0x85, - 0x0c, 0xd4, 0xd9, 0xfb, 0xdd, 0x2a, 0xeb, 0xef, 0x02, 0xde, 0x0c, 0x2c, 0x0b, 0xd8, 0x96, 0x17, - 0xf8, 0xdb, 0x8d, 0x2e, 0x7e, 0x40, 0x1d, 0x37, 0x95, 0xef, 0x94, 0x70, 0xda, 0x33, 0x3e, 0xcd, - 0xa1, 0x76, 0x39, 0x87, 0x1a, 0xfa, 0xaa, 0x83, 0xfd, 0xd3, 0x01, 0x09, 0x07, 0x29, 0x49, 0xb2, - 0x11, 0x4d, 0x31, 0xfd, 0x90, 0xd3, 0x8c, 0x9b, 0xc7, 0xa0, 0x55, 0x6d, 0x71, 0xc8, 0xd9, 0x90, - 0xa7, 0x24, 0x50, 0x4f, 0xc2, 0x5a, 0x17, 0xb9, 0x21, 0x23, 0xdc, 0xa8, 0xec, 0x01, 0x1b, 0x54, - 0x96, 0xf9, 0x0c, 0x6c, 0x67, 0x34, 0x09, 0x56, 0xaf, 0xe3, 0x7e, 0x59, 0xc0, 0x96, 0x08, 0x13, - 0x7e, 0x84, 0x25, 0x60, 0xba, 0xc0, 0x48, 0xa9, 0x4f, 0xa3, 0xe9, 0xea, 0x4e, 0xfb, 0xeb, 0x7d, - 0x29, 0x05, 0xe1, 0x15, 0xb4, 0x7e, 0x50, 0xfd, 0x57, 0x57, 0x0b, 0x5b, 0xbf, 0x5e, 0xd8, 0xfa, - 0xcf, 0x85, 0xad, 0x5f, 0x2c, 0x6d, 0xed, 0x7a, 0x69, 0x6b, 0xdf, 0x97, 0xb6, 0xf6, 0xd6, 0x09, - 0x23, 0x7e, 0x9e, 0x7b, 0x8e, 0xcf, 0x62, 0x57, 0xdc, 0xe8, 0x68, 0x4c, 0xbc, 0x4c, 0x7e, 0xbb, - 0x1f, 0xd7, 0xff, 0x2e, 0x9f, 0x4d, 0x68, 0xe6, 0x6d, 0xd7, 0x4b, 0x7e, 0xf9, 0x27, 0x00, 0x00, - 0xff, 0xff, 0xd1, 0x78, 0x39, 0xe4, 0xdb, 0x03, 0x00, 0x00, + // 564 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x93, 0xb1, 0x6f, 0xd3, 0x4e, + 0x14, 0xc7, 0xed, 0x5f, 0xda, 0xc4, 0xbf, 0x4b, 0xd2, 0x82, 0x1b, 0xa9, 0x26, 0x83, 0xaf, 0x1c, + 0x08, 0x81, 0x44, 0x6d, 0x05, 0xb6, 0xa8, 0x4b, 0xa3, 0x0e, 0xb0, 0x55, 0xa7, 0x88, 0x81, 0x25, + 0x3a, 0xdb, 0x17, 0x63, 0x88, 0x7d, 0xc1, 0xbe, 0x44, 0xe4, 0x3f, 0x60, 0xac, 0x98, 0x3a, 0xe6, + 0x8f, 0x60, 0xe1, 0x3f, 0xa8, 0x98, 0x3a, 0x32, 0x19, 0x94, 0x2c, 0x88, 0xd1, 0x7f, 0x01, 0xb2, + 0xef, 0x2e, 0xa1, 0x45, 0x6c, 0xbe, 0xf7, 0xfd, 0xbc, 0xf7, 0xee, 0x7d, 0xdf, 0x19, 0x3c, 0x0c, + 0x68, 0x16, 0xb3, 0xcc, 0x9d, 0xa6, 0x6c, 0x1c, 0x4d, 0x68, 0xe6, 0xce, 0x7b, 0x1e, 0xe5, 0xa4, + 0xe7, 0xc6, 0x2c, 0xa0, 0x93, 0xcc, 0x99, 0xa6, 0x8c, 0x33, 0xf3, 0x50, 0x50, 0x8e, 0xa2, 0x1c, + 0x49, 0x75, 0x3b, 0x21, 0x0b, 0x59, 0xc5, 0xb8, 0xe5, 0x97, 0xc0, 0xbb, 0xf7, 0x42, 0xc6, 0xc2, + 0x09, 0x75, 0xab, 0x93, 0x37, 0x1b, 0xbb, 0x24, 0x59, 0x48, 0x09, 0xde, 0x96, 0x78, 0x14, 0xd3, + 0x8c, 0x93, 0x78, 0xaa, 0x72, 0x7d, 0x56, 0xb6, 0x1a, 0x89, 0xa2, 0xe2, 0x20, 0x24, 0xf4, 0x16, + 0x18, 0xe7, 0x91, 0xcf, 0x67, 0x29, 0xcd, 0xcc, 0xa7, 0xa0, 0x21, 0x2f, 0x63, 0xe9, 0x47, 0xfa, + 0xe3, 0xff, 0x07, 0x66, 0x91, 0xc3, 0xbd, 0x05, 0x89, 0x27, 0x7d, 0x24, 0x05, 0x84, 0x15, 0x62, + 0x3e, 0x02, 0xbb, 0x3e, 0x9b, 0xd3, 0xd4, 0xfa, 0xaf, 0x62, 0xef, 0x14, 0x39, 0x6c, 0x09, 0xb6, + 0x0a, 0x23, 0x2c, 0xe4, 0xbe, 0x71, 0xb9, 0x84, 0xfa, 0xcf, 0x25, 0xd4, 0xd1, 0xa7, 0x1a, 0x68, + 0x9c, 0xcb, 0xec, 0x13, 0xd0, 0x20, 0xbe, 0xcf, 0x66, 0x09, 0xaf, 0x7a, 0x35, 0x9f, 0x75, 0x1c, + 0x31, 0x85, 0xa3, 0xa6, 0x70, 0x4e, 0x93, 0xc5, 0xa0, 0xf5, 0xf5, 0xf3, 0xb1, 0x71, 0x2a, 0xc0, + 0x97, 0x58, 0xa5, 0x98, 0x0f, 0xc0, 0x4e, 0xc0, 0x49, 0x28, 0x5b, 0xef, 0x17, 0x39, 0x6c, 0x8a, + 0xd6, 0x65, 0x14, 0xe1, 0x4a, 0x2c, 0xc7, 0x89, 0x59, 0x12, 0xbd, 0xa3, 0xa9, 0x55, 0xbb, 0x3d, + 0x8e, 0x14, 0x10, 0x56, 0x88, 0x79, 0x04, 0x6a, 0x5e, 0xc4, 0xac, 0x9d, 0x8a, 0xdc, 0x2b, 0x72, + 0x08, 0x04, 0xe9, 0x45, 0x0c, 0xe1, 0x52, 0x32, 0x5f, 0x01, 0x63, 0x2a, 0xad, 0xb2, 0x76, 0xab, + 0x3b, 0xdf, 0x77, 0xfe, 0xb1, 0x43, 0x47, 0x79, 0x3a, 0x38, 0xbc, 0xca, 0xa1, 0x56, 0xe4, 0x70, + 0x5f, 0xda, 0x28, 0xe3, 0x08, 0x6f, 0x6a, 0x99, 0x29, 0x68, 0xfb, 0x29, 0x25, 0x3c, 0x62, 0xc9, + 0x28, 0x20, 0x9c, 0x5a, 0xf5, 0xaa, 0x78, 0xf7, 0x2f, 0x43, 0x86, 0x6a, 0xad, 0x83, 0x5e, 0x59, + 0xf5, 0x57, 0x0e, 0x6f, 0x26, 0x16, 0x39, 0xec, 0xc8, 0x0d, 0xfc, 0x19, 0x46, 0x17, 0xdf, 0xa1, + 0x8e, 0x5b, 0x2a, 0x76, 0x46, 0x38, 0xed, 0x1b, 0x1f, 0x97, 0x50, 0xbb, 0x5c, 0x42, 0x0d, 0x7d, + 0xd1, 0xc1, 0xc1, 0xd9, 0x90, 0x84, 0xc3, 0x94, 0x24, 0xd9, 0x98, 0xa6, 0x98, 0xbe, 0x9f, 0xd1, + 0x8c, 0x9b, 0x27, 0xa0, 0x5d, 0xba, 0x38, 0xe2, 0x6c, 0xc4, 0x53, 0x12, 0xa8, 0x27, 0x61, 0x6d, + 0x9b, 0xdc, 0x90, 0x11, 0x6e, 0x96, 0xe7, 0x21, 0x1b, 0x96, 0x27, 0xf3, 0x09, 0xa8, 0x67, 0x34, + 0x09, 0x36, 0xaf, 0xe3, 0x6e, 0x91, 0xc3, 0xb6, 0x48, 0x13, 0x71, 0x84, 0x25, 0x60, 0xba, 0xc0, + 0x48, 0xa9, 0x4f, 0xa3, 0xf9, 0x66, 0x4f, 0x07, 0x5b, 0xbf, 0x94, 0x82, 0xf0, 0x06, 0xda, 0x3e, + 0xa8, 0xc1, 0x8b, 0xab, 0x95, 0xad, 0x5f, 0xaf, 0x6c, 0xfd, 0xc7, 0xca, 0xd6, 0x2f, 0xd6, 0xb6, + 0x76, 0xbd, 0xb6, 0xb5, 0x6f, 0x6b, 0x5b, 0x7b, 0xed, 0x84, 0x11, 0x7f, 0x33, 0xf3, 0x1c, 0x9f, + 0xc5, 0xae, 0xd8, 0xd1, 0xf1, 0x84, 0x78, 0x99, 0xfc, 0x76, 0x3f, 0x6c, 0xff, 0x4d, 0xbe, 0x98, + 0xd2, 0xcc, 0xab, 0x57, 0x26, 0x3f, 0xff, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x04, 0x0a, 0xe9, 0x93, + 0xbb, 0x03, 0x00, 0x00, } func (this *Pictures) Equal(that interface{}) bool { @@ -632,10 +631,7 @@ func (m *Pictures) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthModels - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthModels } if (iNdEx + skippy) > l { @@ -883,10 +879,7 @@ func (m *Profile) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthModels - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthModels } if (iNdEx + skippy) > l { @@ -1032,10 +1025,7 @@ func (m *DTagTransferRequest) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthModels - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthModels } if (iNdEx + skippy) > l { diff --git a/x/profiles/types/msgs.pb.go b/x/profiles/types/msgs.pb.go index afff431412..2d08f5406f 100644 --- a/x/profiles/types/msgs.pb.go +++ b/x/profiles/types/msgs.pb.go @@ -1643,10 +1643,7 @@ func (m *MsgSaveProfile) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -1696,10 +1693,7 @@ func (m *MsgSaveProfileResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -1781,10 +1775,7 @@ func (m *MsgDeleteProfile) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -1834,10 +1825,7 @@ func (m *MsgDeleteProfileResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -1951,10 +1939,7 @@ func (m *MsgRequestDTagTransfer) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -2004,10 +1989,7 @@ func (m *MsgRequestDTagTransferResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -2121,10 +2103,7 @@ func (m *MsgCancelDTagTransfer) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -2174,10 +2153,7 @@ func (m *MsgCancelDTagTransferResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -2323,10 +2299,7 @@ func (m *MsgAcceptDTagTransfer) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -2376,10 +2349,7 @@ func (m *MsgAcceptDTagTransferResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -2493,10 +2463,7 @@ func (m *MsgRefuseDTagTransfer) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -2546,10 +2513,7 @@ func (m *MsgRefuseDTagTransferResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { diff --git a/x/profiles/types/params.pb.go b/x/profiles/types/params.pb.go index 94dc1463a0..45a75962d3 100644 --- a/x/profiles/types/params.pb.go +++ b/x/profiles/types/params.pb.go @@ -549,10 +549,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthParams - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthParams } if (iNdEx + skippy) > l { @@ -668,10 +665,7 @@ func (m *MonikerParams) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthParams - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthParams } if (iNdEx + skippy) > l { @@ -819,10 +813,7 @@ func (m *DTagParams) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthParams - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthParams } if (iNdEx + skippy) > l { diff --git a/x/profiles/types/query.pb.go b/x/profiles/types/query.pb.go index cd8b0a4c97..ecd732a060 100644 --- a/x/profiles/types/query.pb.go +++ b/x/profiles/types/query.pb.go @@ -838,10 +838,7 @@ func (m *QueryProfileRequest) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { @@ -927,10 +924,7 @@ func (m *QueryProfileResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { @@ -1012,10 +1006,7 @@ func (m *QueryDTagTransfersRequest) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { @@ -1099,10 +1090,7 @@ func (m *QueryDTagTransfersResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { @@ -1152,10 +1140,7 @@ func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { @@ -1238,10 +1223,7 @@ func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { diff --git a/x/relationships/types/genesis.pb.go b/x/relationships/types/genesis.pb.go index b136e701ed..a582a1c61d 100644 --- a/x/relationships/types/genesis.pb.go +++ b/x/relationships/types/genesis.pb.go @@ -297,10 +297,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthGenesis - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthGenesis } if (iNdEx + skippy) > l { diff --git a/x/relationships/types/models.pb.go b/x/relationships/types/models.pb.go index 987b575bb1..28e83ca1c0 100644 --- a/x/relationships/types/models.pb.go +++ b/x/relationships/types/models.pb.go @@ -741,10 +741,7 @@ func (m *Relationship) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthModels - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthModels } if (iNdEx + skippy) > l { @@ -828,10 +825,7 @@ func (m *Relationships) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthModels - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthModels } if (iNdEx + skippy) > l { @@ -1009,10 +1003,7 @@ func (m *UserBlock) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthModels - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthModels } if (iNdEx + skippy) > l { @@ -1096,10 +1087,7 @@ func (m *UserBlocks) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthModels - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthModels } if (iNdEx + skippy) > l { diff --git a/x/relationships/types/msgs.pb.go b/x/relationships/types/msgs.pb.go index c287e0ffc1..044871bfe9 100644 --- a/x/relationships/types/msgs.pb.go +++ b/x/relationships/types/msgs.pb.go @@ -1205,10 +1205,7 @@ func (m *MsgCreateRelationship) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -1258,10 +1255,7 @@ func (m *CreateRelationshipResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -1407,10 +1401,7 @@ func (m *MsgDeleteRelationship) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -1460,10 +1451,7 @@ func (m *DeleteRelationshipResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -1641,10 +1629,7 @@ func (m *MsgBlockUser) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -1694,10 +1679,7 @@ func (m *BlockUserResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -1843,10 +1825,7 @@ func (m *MsgUnblockUser) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -1896,10 +1875,7 @@ func (m *UnblockUserResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { diff --git a/x/relationships/types/query.pb.go b/x/relationships/types/query.pb.go index 368bb57d29..cb2a95aff1 100644 --- a/x/relationships/types/query.pb.go +++ b/x/relationships/types/query.pb.go @@ -660,10 +660,7 @@ func (m *QueryUserRelationshipsRequest) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { @@ -779,10 +776,7 @@ func (m *QueryUserRelationshipsResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { @@ -864,10 +858,7 @@ func (m *QueryUserBlocksRequest) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { @@ -951,10 +942,7 @@ func (m *QueryUserBlocksResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { diff --git a/x/reports/types/genesis.pb.go b/x/reports/types/genesis.pb.go index 4c367b311d..e66bdedc43 100644 --- a/x/reports/types/genesis.pb.go +++ b/x/reports/types/genesis.pb.go @@ -232,10 +232,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthGenesis - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthGenesis } if (iNdEx + skippy) > l { diff --git a/x/reports/types/models.go b/x/reports/types/models.go index 77e546204a..1702aeb756 100644 --- a/x/reports/types/models.go +++ b/x/reports/types/models.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" - postsTypes "github.com/desmos-labs/desmos/x/posts/types" + poststypes "github.com/desmos-labs/desmos/x/posts/types" ) // NewReport returns a Report @@ -21,7 +21,7 @@ func NewReport(postID string, reportType string, message string, user string) Re // Validate implements validator func (r Report) Validate() error { - if !postsTypes.IsValidPostID(r.PostId) { + if !poststypes.IsValidPostID(r.PostId) { return fmt.Errorf("invalid post id: %s", r.PostId) } diff --git a/x/reports/types/models.pb.go b/x/reports/types/models.pb.go index cf9bbe0919..e871c53b87 100644 --- a/x/reports/types/models.pb.go +++ b/x/reports/types/models.pb.go @@ -514,10 +514,7 @@ func (m *Report) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthModels - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthModels } if (iNdEx + skippy) > l { @@ -601,10 +598,7 @@ func (m *Reports) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthModels - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthModels } if (iNdEx + skippy) > l { diff --git a/x/reports/types/msgs.pb.go b/x/reports/types/msgs.pb.go index 412f2d95c7..5a90e82583 100644 --- a/x/reports/types/msgs.pb.go +++ b/x/reports/types/msgs.pb.go @@ -508,10 +508,7 @@ func (m *MsgReportPost) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { @@ -561,10 +558,7 @@ func (m *MsgReportPostResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthMsgs - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthMsgs } if (iNdEx + skippy) > l { diff --git a/x/reports/types/query.pb.go b/x/reports/types/query.pb.go index 844c49e677..263870a417 100644 --- a/x/reports/types/query.pb.go +++ b/x/reports/types/query.pb.go @@ -412,10 +412,7 @@ func (m *QueryPostReportsRequest) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { @@ -499,10 +496,7 @@ func (m *QueryPostReportsResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthQuery } if (iNdEx + skippy) > l { From 419b66718814643da46644aeaf25bc405bda34ea Mon Sep 17 00:00:00 2001 From: "riccardo.montagnin" Date: Tue, 23 Mar 2021 10:14:50 +0100 Subject: [PATCH 05/11] Fixed lint errors Signed-off-by: riccardo.montagnin --- x/profiles/types/genesis.go | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/x/profiles/types/genesis.go b/x/profiles/types/genesis.go index 6699122c3c..0ada962f43 100644 --- a/x/profiles/types/genesis.go +++ b/x/profiles/types/genesis.go @@ -32,24 +32,3 @@ func ValidateGenesis(data *GenesisState) error { return nil } - -// containDuplicates tells whether or not the profiles slice contain duplicates of the given profile -func containDuplicates(profiles []Profile, profile Profile) bool { - var count = 0 - for _, p := range profiles { - if p.GetAddress().Equals(profile.GetAddress()) || p.Dtag == profile.Dtag { - count++ - } - } - return count > 1 -} - -// profileExists tells whether the given profiles slice contain a profile associated to the given address -func profileExists(profiles []Profile, address string) bool { - for _, profile := range profiles { - if profile.GetAddress().String() == address { - return true - } - } - return false -} From bf5e0f7ff020e2f0b46e94cc3c9742fec697dfe3 Mon Sep 17 00:00:00 2001 From: "riccardo.montagnin" Date: Tue, 23 Mar 2021 10:29:06 +0100 Subject: [PATCH 06/11] Replaced error check with more generic one Signed-off-by: riccardo.montagnin --- x/profiles/keeper/common_test.go | 9 --- x/profiles/keeper/keeper_test.go | 55 ++++++------- x/profiles/keeper/msgs_server_test.go | 108 ++++++++++++++------------ x/profiles/keeper/querier_test.go | 15 ++-- 4 files changed, 89 insertions(+), 98 deletions(-) diff --git a/x/profiles/keeper/common_test.go b/x/profiles/keeper/common_test.go index e1e020846b..fe4f3e286a 100644 --- a/x/profiles/keeper/common_test.go +++ b/x/profiles/keeper/common_test.go @@ -125,15 +125,6 @@ func (suite *KeeperTestSuite) SetupTest() { suite.Require().NoError(err) } -func (suite *KeeperTestSuite) RequireErrorsEqual(expected, actual error) { - if expected != nil { - suite.Require().Error(actual) - suite.Require().Equal(expected.Error(), actual.Error()) - } else { - suite.Require().NoError(actual) - } -} - func (suite *KeeperTestSuite) CheckProfileNoError(profile *types.Profile, err error) *types.Profile { suite.Require().NoError(err) return profile diff --git a/x/profiles/keeper/keeper_test.go b/x/profiles/keeper/keeper_test.go index 14128e5ac5..f6769019d8 100644 --- a/x/profiles/keeper/keeper_test.go +++ b/x/profiles/keeper/keeper_test.go @@ -9,8 +9,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - relationshipstypes "github.com/desmos-labs/desmos/x/relationships/types" "github.com/desmos-labs/desmos/x/profiles/keeper" @@ -407,7 +405,7 @@ func (suite *KeeperTestSuite) TestKeeper_SaveDTagTransferRequest() { name string storedTransferReqs []types.DTagTransferRequest transferReq types.DTagTransferRequest - expErr error + shouldErr bool expStoredTransferReqs []types.DTagTransferRequest }{ { @@ -416,10 +414,7 @@ func (suite *KeeperTestSuite) TestKeeper_SaveDTagTransferRequest() { types.NewDTagTransferRequest("dtag", suite.testData.user, suite.testData.otherUser), }, transferReq: types.NewDTagTransferRequest("dtag", suite.testData.user, suite.testData.otherUser), - expErr: sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, - "the transfer request from %s to %s has already been made", - suite.testData.user, suite.testData.otherUser, - ), + shouldErr: true, expStoredTransferReqs: []types.DTagTransferRequest{ types.NewDTagTransferRequest("dtag", suite.testData.user, suite.testData.otherUser), }, @@ -430,7 +425,7 @@ func (suite *KeeperTestSuite) TestKeeper_SaveDTagTransferRequest() { types.NewDTagTransferRequest("dtag", suite.testData.user, suite.testData.otherUser), }, transferReq: types.NewDTagTransferRequest("dtag", suite.testData.otherUser, suite.testData.user), - expErr: nil, + shouldErr: false, expStoredTransferReqs: []types.DTagTransferRequest{ types.NewDTagTransferRequest("dtag", suite.testData.user, suite.testData.otherUser), types.NewDTagTransferRequest("dtag", suite.testData.otherUser, suite.testData.user), @@ -442,7 +437,7 @@ func (suite *KeeperTestSuite) TestKeeper_SaveDTagTransferRequest() { types.NewDTagTransferRequest("dtag", suite.testData.user, suite.testData.otherUser), }, transferReq: types.NewDTagTransferRequest("dtag", suite.testData.user, suite.testData.user), - expErr: nil, + shouldErr: false, expStoredTransferReqs: []types.DTagTransferRequest{ types.NewDTagTransferRequest("dtag", suite.testData.user, suite.testData.user), types.NewDTagTransferRequest("dtag", suite.testData.user, suite.testData.otherUser), @@ -454,11 +449,7 @@ func (suite *KeeperTestSuite) TestKeeper_SaveDTagTransferRequest() { types.NewDTagTransferRequest("dtag", suite.testData.user, suite.testData.otherUser), }, transferReq: types.NewDTagTransferRequest("dtag1", suite.testData.user, suite.testData.otherUser), - expErr: sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, - "the transfer request from %s to %s has already been made", - suite.testData.user, suite.testData.otherUser, - ), + shouldErr: true, expStoredTransferReqs: []types.DTagTransferRequest{ types.NewDTagTransferRequest("dtag", suite.testData.user, suite.testData.otherUser), }, @@ -467,7 +458,7 @@ func (suite *KeeperTestSuite) TestKeeper_SaveDTagTransferRequest() { name: "Not already present request is saved correctly", storedTransferReqs: nil, transferReq: types.NewDTagTransferRequest("dtag", suite.testData.user, suite.testData.otherUser), - expErr: nil, + shouldErr: false, expStoredTransferReqs: []types.DTagTransferRequest{ types.NewDTagTransferRequest("dtag", suite.testData.user, suite.testData.otherUser), }, @@ -483,7 +474,12 @@ func (suite *KeeperTestSuite) TestKeeper_SaveDTagTransferRequest() { } err := suite.k.SaveDTagTransferRequest(suite.ctx, test.transferReq) - suite.RequireErrorsEqual(test.expErr, err) + + if test.shouldErr { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + } stored := suite.k.GetDTagTransferRequests(suite.ctx) suite.Require().Len(stored, len(test.expStoredTransferReqs)) @@ -614,7 +610,7 @@ func (suite *KeeperTestSuite) TestKeeper_DeleteDTagTransferRequest() { storedReqs []types.DTagTransferRequest sender string receiver string - expErr error + shouldErr bool storedReqsAfter []types.DTagTransferRequest }{ { @@ -622,26 +618,16 @@ func (suite *KeeperTestSuite) TestKeeper_DeleteDTagTransferRequest() { storedReqs: nil, sender: suite.testData.user, receiver: suite.testData.otherUser, - expErr: sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, - "request from %s to %s not found", - suite.testData.user, - suite.testData.otherUser, - ), + shouldErr: true, }, { name: "Deleting non existent request returns an error and doesn't change the store", storedReqs: []types.DTagTransferRequest{ types.NewDTagTransferRequest("dtag", suite.testData.user, suite.testData.user), }, - sender: suite.testData.user, - receiver: suite.testData.otherUser, - expErr: sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, - "request from %s to %s not found", - suite.testData.user, - suite.testData.otherUser, - ), + sender: suite.testData.user, + receiver: suite.testData.otherUser, + shouldErr: true, storedReqsAfter: []types.DTagTransferRequest{ types.NewDTagTransferRequest("dtag", suite.testData.user, suite.testData.user), }, @@ -678,7 +664,12 @@ func (suite *KeeperTestSuite) TestKeeper_DeleteDTagTransferRequest() { } err := suite.k.DeleteDTagTransferRequest(suite.ctx, test.sender, test.receiver) - suite.RequireErrorsEqual(test.expErr, err) + + if test.shouldErr { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + } reqs := suite.k.GetDTagTransferRequests(suite.ctx) suite.Require().Equal(test.storedReqsAfter, reqs) diff --git a/x/profiles/keeper/msgs_server_test.go b/x/profiles/keeper/msgs_server_test.go index 57681d5db1..f95713634b 100644 --- a/x/profiles/keeper/msgs_server_test.go +++ b/x/profiles/keeper/msgs_server_test.go @@ -23,7 +23,7 @@ func (suite *KeeperTestSuite) Test_handleMsgSaveProfile() { existentProfiles []*types.Profile blockTime time.Time msg *types.MsgSaveProfile - expErr error + shouldErr bool expEvents sdk.Events expStoredProfiles []*types.Profile }{ @@ -127,7 +127,7 @@ func (suite *KeeperTestSuite) Test_handleMsgSaveProfile() { suite.testData.profile.GetAddress().String(), ), expEvents: sdk.EmptyEvents(), - expErr: sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid profile picture uri provided"), + shouldErr: true, expStoredProfiles: []*types.Profile{ suite.CheckProfileNoError(types.NewProfile( "custom_dtag", @@ -156,8 +156,12 @@ func (suite *KeeperTestSuite) Test_handleMsgSaveProfile() { server := keeper.NewMsgServerImpl(suite.k) _, err := server.SaveProfile(sdk.WrapSDKContext(suite.ctx), test.msg) - suite.RequireErrorsEqual(test.expErr, err) - suite.Require().Equal(test.expEvents, suite.ctx.EventManager().Events()) + if test.shouldErr { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + suite.Require().Equal(test.expEvents, suite.ctx.EventManager().Events()) + } stored := suite.k.GetProfiles(suite.ctx) suite.Require().Len(stored, len(test.expStoredProfiles)) @@ -237,7 +241,7 @@ func (suite *KeeperTestSuite) Test_handleMsgRequestDTagTransfer() { storedDTagReqs []types.DTagTransferRequest storedBlocks []relationshipstypes.UserBlock msg *types.MsgRequestDTagTransfer - expErr error + shouldErr bool expEvents sdk.Events }{ { @@ -252,21 +256,13 @@ func (suite *KeeperTestSuite) Test_handleMsgRequestDTagTransfer() { }, msg: types.NewMsgRequestDTagTransfer(suite.testData.user, suite.testData.otherUser), expEvents: sdk.EmptyEvents(), - expErr: sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, - "the user with address %s has blocked you", - suite.testData.otherUser, - ), + shouldErr: true, }, { name: "No DTag to transfer returns error", msg: types.NewMsgRequestDTagTransfer(suite.testData.user, suite.testData.otherUser), expEvents: sdk.EmptyEvents(), - expErr: sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, - "the user with address %s doesn't have a profile yet so their DTag cannot be transferred", - suite.testData.otherUser, - ), + shouldErr: true, }, { name: "Already present request returns error", @@ -282,18 +278,15 @@ func (suite *KeeperTestSuite) Test_handleMsgRequestDTagTransfer() { }, msg: types.NewMsgRequestDTagTransfer(suite.testData.profile.GetAddress().String(), suite.testData.otherUser), expEvents: sdk.EmptyEvents(), - expErr: sdkerrors.Wrapf( - sdkerrors.ErrInvalidRequest, - "the transfer request from %s to %s has already been made", - suite.testData.profile.GetAddress().String(), suite.testData.otherUser, - ), + shouldErr: true, }, { name: "Not already present request saved correctly", storedProfiles: []*types.Profile{ suite.testData.profile, }, - msg: types.NewMsgRequestDTagTransfer(suite.testData.user, suite.testData.profile.GetAddress().String()), + msg: types.NewMsgRequestDTagTransfer(suite.testData.user, suite.testData.profile.GetAddress().String()), + shouldErr: false, expEvents: sdk.Events{ sdk.NewEvent( types.EventTypeDTagTransferRequest, @@ -324,10 +317,14 @@ func (suite *KeeperTestSuite) Test_handleMsgRequestDTagTransfer() { } server := keeper.NewMsgServerImpl(suite.k) - _, err := server.RequestDTagTransfer(sdk.WrapSDKContext(suite.ctx), test.msg) + _, err = server.RequestDTagTransfer(sdk.WrapSDKContext(suite.ctx), test.msg) - suite.RequireErrorsEqual(test.expErr, err) - suite.Require().Equal(test.expEvents, suite.ctx.EventManager().Events()) + if test.shouldErr { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + suite.Require().Equal(test.expEvents, suite.ctx.EventManager().Events()) + } }) } } @@ -344,14 +341,14 @@ func (suite *KeeperTestSuite) Test_handleMsgAcceptDTagTransfer() { storedDTagReqs []types.DTagTransferRequest storedProfiles []*types.Profile msg *types.MsgAcceptDTagTransfer - expErr error + shouldErr bool expEvents sdk.Events }{ { name: "No request made from the receiving user returns error", msg: types.NewMsgAcceptDTagTransfer("newDtag", suite.testData.user, suite.testData.otherUser), expEvents: sdk.EmptyEvents(), - expErr: sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "no request made from %s", suite.testData.user), + shouldErr: true, }, { name: "Return an error if the request receiver does not have a profile", @@ -360,8 +357,7 @@ func (suite *KeeperTestSuite) Test_handleMsgAcceptDTagTransfer() { }, msg: types.NewMsgAcceptDTagTransfer("newDtag", suite.testData.user, suite.testData.otherUser), expEvents: sdk.EmptyEvents(), - expErr: sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, - "profile of %s doesn't exist", suite.testData.otherUser), + shouldErr: true, }, { name: "Return an error if the new DTag has already been chosen by another user", @@ -388,7 +384,7 @@ func (suite *KeeperTestSuite) Test_handleMsgAcceptDTagTransfer() { }, msg: types.NewMsgAcceptDTagTransfer("newDtag", suite.testData.user, suite.testData.otherUser), expEvents: sdk.EmptyEvents(), - expErr: sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "a profile with dtag newDtag has already been created"), + shouldErr: true, }, { name: "Return an error when current owner DTag is different from the requested one", @@ -407,8 +403,7 @@ func (suite *KeeperTestSuite) Test_handleMsgAcceptDTagTransfer() { }, msg: types.NewMsgAcceptDTagTransfer("newDtag", suite.testData.user, suite.testData.otherUser), expEvents: sdk.EmptyEvents(), - expErr: sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, - "the owner's DTag is different from the one to be exchanged"), + shouldErr: true, }, { name: "DTag exchanged correctly (not existent sender profile)", @@ -425,7 +420,8 @@ func (suite *KeeperTestSuite) Test_handleMsgAcceptDTagTransfer() { storedDTagReqs: []types.DTagTransferRequest{ types.NewDTagTransferRequest("dtag", suite.testData.user, suite.testData.otherUser), }, - msg: types.NewMsgAcceptDTagTransfer("newDtag", suite.testData.user, suite.testData.otherUser), + msg: types.NewMsgAcceptDTagTransfer("newDtag", suite.testData.user, suite.testData.otherUser), + shouldErr: false, expEvents: sdk.Events{ sdk.NewEvent( types.EventTypeDTagTransferAccept, @@ -488,9 +484,14 @@ func (suite *KeeperTestSuite) Test_handleMsgAcceptDTagTransfer() { } server := keeper.NewMsgServerImpl(suite.k) - _, err := server.AcceptDTagTransfer(sdk.WrapSDKContext(suite.ctx), test.msg) - suite.RequireErrorsEqual(test.expErr, err) - suite.Require().Equal(test.expEvents, suite.ctx.EventManager().Events()) + _, err = server.AcceptDTagTransfer(sdk.WrapSDKContext(suite.ctx), test.msg) + + if test.shouldErr { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + suite.Require().Equal(test.expEvents, suite.ctx.EventManager().Events()) + } }) } } @@ -500,7 +501,7 @@ func (suite *KeeperTestSuite) Test_handleMsgRefuseDTagRequest() { name string msg *types.MsgRefuseDTagTransfer storedDTagReqs []types.DTagTransferRequest - expErr error + shouldErr bool expEvents sdk.Events }{ { @@ -508,15 +509,15 @@ func (suite *KeeperTestSuite) Test_handleMsgRefuseDTagRequest() { storedDTagReqs: nil, msg: types.NewMsgRefuseDTagTransferRequest(suite.testData.user, suite.testData.otherUser), expEvents: sdk.EmptyEvents(), - expErr: sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, - "request from %s to %s not found", suite.testData.user, suite.testData.otherUser), + shouldErr: true, }, { name: "Deletion runs correctly", storedDTagReqs: []types.DTagTransferRequest{ types.NewDTagTransferRequest("dtag", suite.testData.user, suite.testData.otherUser), }, - msg: types.NewMsgRefuseDTagTransferRequest(suite.testData.user, suite.testData.otherUser), + msg: types.NewMsgRefuseDTagTransferRequest(suite.testData.user, suite.testData.otherUser), + shouldErr: false, expEvents: sdk.Events{ sdk.NewEvent( types.EventTypeDTagTransferRefuse, @@ -524,7 +525,6 @@ func (suite *KeeperTestSuite) Test_handleMsgRefuseDTagRequest() { sdk.NewAttribute(types.AttributeRequestReceiver, suite.testData.otherUser), ), }, - expErr: nil, }, } @@ -539,8 +539,12 @@ func (suite *KeeperTestSuite) Test_handleMsgRefuseDTagRequest() { server := keeper.NewMsgServerImpl(suite.k) _, err := server.RefuseDTagTransfer(sdk.WrapSDKContext(suite.ctx), test.msg) - suite.RequireErrorsEqual(test.expErr, err) - suite.Require().Equal(test.expEvents, suite.ctx.EventManager().Events()) + if test.shouldErr { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + suite.Require().Equal(test.expEvents, suite.ctx.EventManager().Events()) + } }) } } @@ -550,7 +554,7 @@ func (suite *KeeperTestSuite) Test_handleMsgCancelDTagRequest() { name string msg *types.MsgCancelDTagTransfer storedDTagReqs []types.DTagTransferRequest - expErr error + shouldErr bool expEvents sdk.Events }{ { @@ -558,17 +562,15 @@ func (suite *KeeperTestSuite) Test_handleMsgCancelDTagRequest() { storedDTagReqs: nil, msg: types.NewMsgCancelDTagTransferRequest(suite.testData.user, suite.testData.otherUser), expEvents: sdk.EmptyEvents(), - expErr: sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, - "request from %s to %s not found", - suite.testData.user, suite.testData.otherUser, - ), + shouldErr: true, }, { name: "Deletion runs correctly", storedDTagReqs: []types.DTagTransferRequest{ types.NewDTagTransferRequest("dtag", suite.testData.user, suite.testData.otherUser), }, - msg: types.NewMsgCancelDTagTransferRequest(suite.testData.user, suite.testData.otherUser), + msg: types.NewMsgCancelDTagTransferRequest(suite.testData.user, suite.testData.otherUser), + shouldErr: false, expEvents: sdk.Events{ sdk.NewEvent( types.EventTypeDTagTransferCancel, @@ -576,7 +578,6 @@ func (suite *KeeperTestSuite) Test_handleMsgCancelDTagRequest() { sdk.NewAttribute(types.AttributeRequestReceiver, suite.testData.otherUser), ), }, - expErr: nil, }, } @@ -590,8 +591,13 @@ func (suite *KeeperTestSuite) Test_handleMsgCancelDTagRequest() { server := keeper.NewMsgServerImpl(suite.k) _, err := server.CancelDTagTransfer(sdk.WrapSDKContext(suite.ctx), test.msg) - suite.RequireErrorsEqual(test.expErr, err) - suite.Require().Equal(test.expEvents, suite.ctx.EventManager().Events()) + + if test.shouldErr { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + suite.Require().Equal(test.expEvents, suite.ctx.EventManager().Events()) + } }) } } diff --git a/x/profiles/keeper/querier_test.go b/x/profiles/keeper/querier_test.go index a5c56d7cc8..6fcc911894 100644 --- a/x/profiles/keeper/querier_test.go +++ b/x/profiles/keeper/querier_test.go @@ -129,21 +129,21 @@ func (suite *KeeperTestSuite) Test_queryDTagRequests() { path []string storedRequests []types.DTagTransferRequest expResult []types.DTagTransferRequest - expErr error + shouldErr bool }{ { name: "Invalid address returns error", path: []string{types.QueryIncomingDTagRequests, "invalid"}, storedRequests: nil, expResult: nil, - expErr: sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "Invalid bech32 address: invalid"), + shouldErr: true, }, { name: "Empty DTag requests returns correctly", path: []string{types.QueryIncomingDTagRequests, suite.testData.user}, storedRequests: nil, expResult: nil, - expErr: nil, + shouldErr: false, }, { name: "Stored dTag requests returns correctly", @@ -154,7 +154,7 @@ func (suite *KeeperTestSuite) Test_queryDTagRequests() { expResult: []types.DTagTransferRequest{ types.NewDTagTransferRequest("dtag", suite.testData.user, suite.testData.otherUser), }, - expErr: nil, + shouldErr: false, }, } @@ -168,9 +168,12 @@ func (suite *KeeperTestSuite) Test_queryDTagRequests() { querier := keeper.NewQuerier(suite.k, suite.legacyAminoCdc) result, err := querier(suite.ctx, test.path, abci.RequestQuery{}) - suite.RequireErrorsEqual(test.expErr, err) - if test.expErr == nil { + if test.shouldErr { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + var requests []types.DTagTransferRequest err = suite.legacyAminoCdc.UnmarshalJSON(result, &requests) suite.Require().NoError(err) From 5db46021d45e29faa407d13bcd8d6ff5a95d8f74 Mon Sep 17 00:00:00 2001 From: "riccardo.montagnin" Date: Tue, 6 Apr 2021 14:26:49 +0200 Subject: [PATCH 07/11] Updated Proto files Signed-off-by: riccardo.montagnin --- x/profiles/keeper/types.pb.go | 222 ++--------------------------- x/profiles/types/models.pb.go | 260 +++++++++++++--------------------- 2 files changed, 108 insertions(+), 374 deletions(-) diff --git a/x/profiles/keeper/types.pb.go b/x/profiles/keeper/types.pb.go index 9daf1c8365..a882e6d3e0 100644 --- a/x/profiles/keeper/types.pb.go +++ b/x/profiles/keeper/types.pb.go @@ -24,52 +24,6 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// DTagOwner represents the owner of a specific DTag -type WrappedDTagOwner struct { - // Address of the user owning a Dtag - Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` -} - -func (m *WrappedDTagOwner) Reset() { *m = WrappedDTagOwner{} } -func (m *WrappedDTagOwner) String() string { return proto.CompactTextString(m) } -func (*WrappedDTagOwner) ProtoMessage() {} -func (*WrappedDTagOwner) Descriptor() ([]byte, []int) { - return fileDescriptor_732b728428b8b385, []int{0} -} -func (m *WrappedDTagOwner) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *WrappedDTagOwner) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_WrappedDTagOwner.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *WrappedDTagOwner) XXX_Merge(src proto.Message) { - xxx_messageInfo_WrappedDTagOwner.Merge(m, src) -} -func (m *WrappedDTagOwner) XXX_Size() int { - return m.Size() -} -func (m *WrappedDTagOwner) XXX_DiscardUnknown() { - xxx_messageInfo_WrappedDTagOwner.DiscardUnknown(m) -} - -var xxx_messageInfo_WrappedDTagOwner proto.InternalMessageInfo - -func (m *WrappedDTagOwner) GetAddress() string { - if m != nil { - return m.Address - } - return "" -} - // DtagRequests contains the DTag transfer requests made towards a user type WrappedDTagTransferRequests struct { Requests []types.DTagTransferRequest `protobuf:"bytes,1,rep,name=requests,proto3" json:"requests"` @@ -79,7 +33,7 @@ func (m *WrappedDTagTransferRequests) Reset() { *m = WrappedDTagTransfer func (m *WrappedDTagTransferRequests) String() string { return proto.CompactTextString(m) } func (*WrappedDTagTransferRequests) ProtoMessage() {} func (*WrappedDTagTransferRequests) Descriptor() ([]byte, []int) { - return fileDescriptor_732b728428b8b385, []int{1} + return fileDescriptor_732b728428b8b385, []int{0} } func (m *WrappedDTagTransferRequests) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -116,7 +70,6 @@ func (m *WrappedDTagTransferRequests) GetRequests() []types.DTagTransferRequest } func init() { - proto.RegisterType((*WrappedDTagOwner)(nil), "desmos.profiles.v1beta1.keeper.WrappedDTagOwner") proto.RegisterType((*WrappedDTagTransferRequests)(nil), "desmos.profiles.v1beta1.keeper.WrappedDTagTransferRequests") } @@ -125,50 +78,24 @@ func init() { } var fileDescriptor_732b728428b8b385 = []byte{ - // 271 bytes of a gzipped FileDescriptorProto + // 238 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x4a, 0x49, 0x2d, 0xce, 0xcd, 0x2f, 0xd6, 0x2f, 0x28, 0xca, 0x4f, 0xcb, 0xcc, 0x49, 0x2d, 0xd6, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0xcf, 0x4e, 0x4d, 0x2d, 0x48, 0x2d, 0xd2, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x83, 0xa8, 0xd5, 0x83, 0xa9, 0xd5, 0x83, 0xaa, 0xd5, 0x83, 0xa8, 0x95, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0x2b, 0xd5, 0x07, 0xb1, 0x20, 0xba, - 0xa4, 0x54, 0x70, 0xd9, 0x90, 0x9b, 0x9f, 0x92, 0x9a, 0x03, 0x35, 0x5b, 0xc9, 0x8c, 0x4b, 0x20, - 0xbc, 0x28, 0xb1, 0xa0, 0x20, 0x35, 0xc5, 0x25, 0x24, 0x31, 0xdd, 0xbf, 0x3c, 0x2f, 0xb5, 0x48, - 0x48, 0x82, 0x8b, 0x3d, 0x31, 0x25, 0xa5, 0x28, 0xb5, 0xb8, 0x58, 0x82, 0x51, 0x81, 0x51, 0x83, - 0x33, 0x08, 0xc6, 0xb5, 0xe2, 0x98, 0xb1, 0x40, 0x9e, 0xf1, 0xc5, 0x02, 0x79, 0x46, 0xa5, 0x72, - 0x2e, 0x69, 0x24, 0x7d, 0x21, 0x45, 0x89, 0x79, 0xc5, 0x69, 0xa9, 0x45, 0x41, 0xa9, 0x85, 0xa5, - 0xa9, 0xc5, 0x25, 0xc5, 0x42, 0x7e, 0x5c, 0x1c, 0x45, 0x50, 0xb6, 0x04, 0xa3, 0x02, 0xb3, 0x06, - 0xb7, 0x91, 0x8e, 0x1e, 0x2e, 0x5f, 0x60, 0x31, 0xc0, 0x89, 0xe5, 0xc4, 0x3d, 0x79, 0x86, 0x20, - 0xb8, 0x19, 0x08, 0x8b, 0x9d, 0x3c, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, - 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, - 0x4a, 0x3f, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x1f, 0x62, 0x97, 0x6e, - 0x4e, 0x62, 0x52, 0x31, 0x94, 0xad, 0x5f, 0x81, 0x08, 0x09, 0x48, 0xb8, 0x25, 0xb1, 0x81, 0x83, - 0xc0, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0xec, 0xe9, 0xd6, 0x0a, 0x8c, 0x01, 0x00, 0x00, + 0xa4, 0x54, 0x70, 0xd9, 0x90, 0x9b, 0x9f, 0x92, 0x9a, 0x03, 0x35, 0x5b, 0xa9, 0x9c, 0x4b, 0x3a, + 0xbc, 0x28, 0xb1, 0xa0, 0x20, 0x35, 0xc5, 0x25, 0x24, 0x31, 0x3d, 0xa4, 0x28, 0x31, 0xaf, 0x38, + 0x2d, 0xb5, 0x28, 0x28, 0xb5, 0xb0, 0x34, 0xb5, 0xb8, 0xa4, 0x58, 0xc8, 0x8f, 0x8b, 0xa3, 0x08, + 0xca, 0x96, 0x60, 0x54, 0x60, 0xd6, 0xe0, 0x36, 0xd2, 0xd1, 0xc3, 0xe5, 0x1a, 0x2c, 0x06, 0x38, + 0xb1, 0x9c, 0xb8, 0x27, 0xcf, 0x10, 0x04, 0x37, 0xc3, 0x8a, 0x63, 0xc6, 0x02, 0x79, 0xc6, 0x17, + 0x0b, 0xe4, 0x19, 0x9d, 0x3c, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, + 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, + 0x3f, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x1f, 0x62, 0x97, 0x6e, 0x4e, + 0x62, 0x52, 0x31, 0x94, 0xad, 0x5f, 0x81, 0xf0, 0x11, 0xc4, 0xff, 0x49, 0x6c, 0x60, 0xaf, 0x18, + 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x05, 0x21, 0x73, 0x8c, 0x54, 0x01, 0x00, 0x00, } -func (this *WrappedDTagOwner) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*WrappedDTagOwner) - if !ok { - that2, ok := that.(WrappedDTagOwner) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Address != that1.Address { - return false - } - return true -} func (this *WrappedDTagTransferRequests) Equal(that interface{}) bool { if that == nil { return this == nil @@ -198,36 +125,6 @@ func (this *WrappedDTagTransferRequests) Equal(that interface{}) bool { } return true } -func (m *WrappedDTagOwner) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *WrappedDTagOwner) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *WrappedDTagOwner) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Address) > 0 { - i -= len(m.Address) - copy(dAtA[i:], m.Address) - i = encodeVarintTypes(dAtA, i, uint64(len(m.Address))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - func (m *WrappedDTagTransferRequests) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -276,19 +173,6 @@ func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *WrappedDTagOwner) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Address) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) - } - return n -} - func (m *WrappedDTagTransferRequests) Size() (n int) { if m == nil { return 0 @@ -310,88 +194,6 @@ func sovTypes(x uint64) (n int) { func sozTypes(x uint64) (n int) { return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *WrappedDTagOwner) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: WrappedDTagOwner: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: WrappedDTagOwner: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Address = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *WrappedDTagTransferRequests) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/profiles/types/models.pb.go b/x/profiles/types/models.pb.go index 1c7cc5a2b6..157b744de7 100644 --- a/x/profiles/types/models.pb.go +++ b/x/profiles/types/models.pb.go @@ -5,9 +5,11 @@ package types import ( fmt "fmt" + types "github.com/cosmos/cosmos-sdk/codec/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "github.com/regen-network/cosmos-proto" _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" @@ -83,17 +85,16 @@ func (m *Pictures) GetCover() string { // Profile represents a generic first on Desmos, containing the information of a // single user type Profile struct { - Dtag string `protobuf:"bytes,1,opt,name=dtag,proto3" json:"dtag,omitempty" yaml:"dtag"` - Moniker string `protobuf:"bytes,2,opt,name=moniker,proto3" json:"moniker,omitempty" yaml:"moniker"` - Bio string `protobuf:"bytes,3,opt,name=bio,proto3" json:"bio,omitempty" yaml:"bio"` - Pictures Pictures `protobuf:"bytes,4,opt,name=pictures,proto3" json:"pictures" yaml:"pictures"` - Creator string `protobuf:"bytes,5,opt,name=creator,proto3" json:"creator,omitempty" yaml:"creator"` - CreationDate time.Time `protobuf:"bytes,6,opt,name=creation_date,json=creationDate,proto3,stdtime" json:"creation_date" yaml:"creation_date"` + Account *types.Any `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"` + Dtag string `protobuf:"bytes,2,opt,name=dtag,proto3" json:"dtag,omitempty" yaml:"dtag"` + Moniker string `protobuf:"bytes,3,opt,name=moniker,proto3" json:"moniker,omitempty" yaml:"moniker"` + Bio string `protobuf:"bytes,4,opt,name=bio,proto3" json:"bio,omitempty" yaml:"bio"` + Pictures Pictures `protobuf:"bytes,5,opt,name=pictures,proto3" json:"pictures" yaml:"pictures"` + CreationDate time.Time `protobuf:"bytes,6,opt,name=creation_date,json=creationDate,proto3,stdtime" json:"creation_date" yaml:"creation_date"` } -func (m *Profile) Reset() { *m = Profile{} } -func (m *Profile) String() string { return proto.CompactTextString(m) } -func (*Profile) ProtoMessage() {} +func (m *Profile) Reset() { *m = Profile{} } +func (*Profile) ProtoMessage() {} func (*Profile) Descriptor() ([]byte, []int) { return fileDescriptor_dcbf89d5cd53a9ca, []int{1} } @@ -124,48 +125,6 @@ func (m *Profile) XXX_DiscardUnknown() { var xxx_messageInfo_Profile proto.InternalMessageInfo -func (m *Profile) GetDtag() string { - if m != nil { - return m.Dtag - } - return "" -} - -func (m *Profile) GetMoniker() string { - if m != nil { - return m.Moniker - } - return "" -} - -func (m *Profile) GetBio() string { - if m != nil { - return m.Bio - } - return "" -} - -func (m *Profile) GetPictures() Pictures { - if m != nil { - return m.Pictures - } - return Pictures{} -} - -func (m *Profile) GetCreator() string { - if m != nil { - return m.Creator - } - return "" -} - -func (m *Profile) GetCreationDate() time.Time { - if m != nil { - return m.CreationDate - } - return time.Time{} -} - // DTagTransferRequest represent a dtag transfer request between two users type DTagTransferRequest struct { DtagToTrade string `protobuf:"bytes,1,opt,name=dtag_to_trade,json=dtagToTrade,proto3" json:"dtag_to_trade,omitempty" yaml:"dtag_to_trade"` @@ -238,40 +197,43 @@ func init() { } var fileDescriptor_dcbf89d5cd53a9ca = []byte{ - // 522 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x93, 0x31, 0x6f, 0x13, 0x3f, - 0x18, 0xc6, 0x73, 0xff, 0xb4, 0x69, 0xfe, 0x4e, 0xd3, 0xc2, 0xb5, 0x52, 0x4f, 0x19, 0xce, 0xc1, - 0x20, 0x54, 0x24, 0xf0, 0x29, 0xb0, 0x55, 0x4c, 0x51, 0x07, 0xc6, 0xca, 0x8a, 0x18, 0x58, 0x22, - 0x5f, 0xce, 0x39, 0x0e, 0x72, 0xf1, 0x61, 0x3b, 0x15, 0x5d, 0xf9, 0x04, 0x1d, 0x19, 0xfb, 0x35, - 0xf8, 0x06, 0x1d, 0x3b, 0x32, 0x1d, 0x28, 0x59, 0x10, 0xe3, 0x7d, 0x02, 0xe4, 0xb3, 0x9d, 0xa4, - 0x48, 0x6c, 0xf6, 0xfb, 0xfc, 0xde, 0x7b, 0x9f, 0xbc, 0x8f, 0x03, 0x9e, 0x24, 0x4c, 0xe6, 0x5c, - 0x46, 0x85, 0xe0, 0xd3, 0x6c, 0xc6, 0x64, 0x74, 0x39, 0x88, 0x99, 0xa2, 0x83, 0x28, 0xe7, 0x09, - 0x9b, 0x49, 0x5c, 0x08, 0xae, 0xb8, 0x7f, 0x62, 0x28, 0xec, 0x28, 0x6c, 0xa9, 0xde, 0x71, 0xca, - 0x53, 0x5e, 0x33, 0x91, 0x3e, 0x19, 0xbc, 0x07, 0x53, 0xce, 0xd3, 0x19, 0x8b, 0xea, 0x5b, 0xbc, - 0x98, 0x46, 0x2a, 0xcb, 0x99, 0x54, 0x34, 0x2f, 0x0c, 0x80, 0x3e, 0x80, 0xf6, 0x45, 0x36, 0x51, - 0x0b, 0xc1, 0xa4, 0xff, 0x1c, 0xec, 0xd9, 0xcf, 0x06, 0x5e, 0xdf, 0x3b, 0xfd, 0x7f, 0xe8, 0x57, - 0x25, 0x3c, 0xb8, 0xa2, 0xf9, 0xec, 0x0c, 0x59, 0x01, 0x11, 0x87, 0xf8, 0x4f, 0xc1, 0xee, 0x84, - 0x5f, 0x32, 0x11, 0xfc, 0x57, 0xb3, 0x0f, 0xaa, 0x12, 0xee, 0x1b, 0xb6, 0x2e, 0x23, 0x62, 0xe4, - 0xb3, 0xf6, 0xd7, 0x1b, 0xe8, 0xfd, 0xba, 0x81, 0x1e, 0xfa, 0xd2, 0x04, 0x7b, 0x17, 0xb6, 0xfb, - 0x31, 0xd8, 0x49, 0x14, 0x4d, 0xed, 0xa0, 0xc3, 0xaa, 0x84, 0x1d, 0xd3, 0xac, 0xab, 0x88, 0xd4, - 0xa2, 0x36, 0x94, 0xf3, 0x79, 0xf6, 0x71, 0x3d, 0x64, 0xcb, 0x90, 0x15, 0x10, 0x71, 0x88, 0xdf, - 0x07, 0xcd, 0x38, 0xe3, 0x41, 0xb3, 0x26, 0x0f, 0xaa, 0x12, 0x02, 0x43, 0xc6, 0x19, 0x47, 0x44, - 0x4b, 0xfe, 0x5b, 0xd0, 0x2e, 0xec, 0x8f, 0x0d, 0x76, 0xfa, 0xde, 0x69, 0xe7, 0xe5, 0x23, 0xfc, - 0x8f, 0x7d, 0x62, 0xb7, 0x95, 0xe1, 0xc9, 0x6d, 0x09, 0x1b, 0x55, 0x09, 0x0f, 0xed, 0x22, 0x6c, - 0x1d, 0x91, 0xf5, 0xb7, 0xb4, 0xcf, 0x89, 0x60, 0x54, 0x71, 0x11, 0xec, 0xfe, 0xed, 0xd3, 0x0a, - 0x88, 0x38, 0xc4, 0x17, 0xa0, 0x5b, 0x1f, 0x33, 0x3e, 0x1f, 0x27, 0x54, 0xb1, 0xa0, 0x55, 0x5b, - 0xe9, 0x61, 0x93, 0x15, 0x76, 0x59, 0xe1, 0x91, 0xcb, 0x6a, 0x38, 0xd0, 0x1e, 0x7e, 0x97, 0xf0, - 0x7e, 0x63, 0x55, 0xc2, 0xe3, 0xad, 0x21, 0xae, 0x8c, 0xae, 0x7f, 0x40, 0x8f, 0xec, 0xbb, 0xda, - 0x39, 0x55, 0x6c, 0x2b, 0x84, 0x6f, 0x1e, 0x38, 0x3a, 0x1f, 0xd1, 0x74, 0x24, 0xe8, 0x5c, 0x4e, - 0x99, 0x20, 0xec, 0xd3, 0x82, 0x49, 0xe5, 0xbf, 0x06, 0x5d, 0xbd, 0xf3, 0xb1, 0xe2, 0x63, 0x25, - 0x68, 0xe2, 0x9e, 0x40, 0xb0, 0x19, 0x72, 0x4f, 0x46, 0xa4, 0xa3, 0xef, 0x23, 0x3e, 0xd2, 0x37, - 0xff, 0x19, 0x68, 0x49, 0x36, 0x4f, 0xd6, 0x41, 0x3d, 0xac, 0x4a, 0xd8, 0x35, 0x6d, 0xa6, 0x8e, - 0x88, 0x05, 0xfc, 0x08, 0xb4, 0x05, 0x9b, 0xb0, 0x4c, 0x3f, 0x1d, 0x93, 0xd5, 0xd1, 0x66, 0xbb, - 0x4e, 0x41, 0x64, 0x0d, 0x6d, 0xbc, 0x0f, 0xdf, 0xdc, 0x2e, 0x43, 0xef, 0x6e, 0x19, 0x7a, 0x3f, - 0x97, 0xa1, 0x77, 0xbd, 0x0a, 0x1b, 0x77, 0xab, 0xb0, 0xf1, 0x7d, 0x15, 0x36, 0xde, 0xe1, 0x34, - 0x53, 0xef, 0x17, 0x31, 0x9e, 0xf0, 0x3c, 0x32, 0x89, 0xbe, 0x98, 0xd1, 0x58, 0xda, 0x73, 0xf4, - 0x79, 0xf3, 0xaf, 0x52, 0x57, 0x05, 0x93, 0x71, 0xab, 0x5e, 0xf2, 0xab, 0x3f, 0x01, 0x00, 0x00, - 0xff, 0xff, 0x80, 0xa2, 0xf5, 0x9a, 0x75, 0x03, 0x00, 0x00, + // 564 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x93, 0xb1, 0x6f, 0xd3, 0x4e, + 0x14, 0xc7, 0xed, 0x5f, 0xda, 0xc4, 0xbf, 0x4b, 0xd2, 0x82, 0x1b, 0xa9, 0x26, 0x83, 0xaf, 0x1c, + 0x08, 0x81, 0x44, 0x6d, 0x05, 0xb6, 0xa8, 0x4b, 0xa3, 0x0e, 0xb0, 0x55, 0xa7, 0x88, 0x81, 0x25, + 0x3a, 0xdb, 0x17, 0x63, 0x88, 0x7d, 0xc1, 0xbe, 0x44, 0xe4, 0x3f, 0x60, 0xac, 0x98, 0x3a, 0xe6, + 0x8f, 0x60, 0xe1, 0x3f, 0xa8, 0x98, 0x3a, 0x32, 0x19, 0x94, 0x2c, 0x88, 0xd1, 0x7f, 0x01, 0xb2, + 0xef, 0x2e, 0xa1, 0x45, 0x6c, 0xbe, 0xf7, 0xfd, 0xbc, 0xf7, 0xee, 0x7d, 0xdf, 0x19, 0x3c, 0x0c, + 0x68, 0x16, 0xb3, 0xcc, 0x9d, 0xa6, 0x6c, 0x1c, 0x4d, 0x68, 0xe6, 0xce, 0x7b, 0x1e, 0xe5, 0xa4, + 0xe7, 0xc6, 0x2c, 0xa0, 0x93, 0xcc, 0x99, 0xa6, 0x8c, 0x33, 0xf3, 0x50, 0x50, 0x8e, 0xa2, 0x1c, + 0x49, 0x75, 0x3b, 0x21, 0x0b, 0x59, 0xc5, 0xb8, 0xe5, 0x97, 0xc0, 0xbb, 0xf7, 0x42, 0xc6, 0xc2, + 0x09, 0x75, 0xab, 0x93, 0x37, 0x1b, 0xbb, 0x24, 0x59, 0x48, 0x09, 0xde, 0x96, 0x78, 0x14, 0xd3, + 0x8c, 0x93, 0x78, 0xaa, 0x72, 0x7d, 0x56, 0xb6, 0x1a, 0x89, 0xa2, 0xe2, 0x20, 0x24, 0xf4, 0x16, + 0x18, 0xe7, 0x91, 0xcf, 0x67, 0x29, 0xcd, 0xcc, 0xa7, 0xa0, 0x21, 0x2f, 0x63, 0xe9, 0x47, 0xfa, + 0xe3, 0xff, 0x07, 0x66, 0x91, 0xc3, 0xbd, 0x05, 0x89, 0x27, 0x7d, 0x24, 0x05, 0x84, 0x15, 0x62, + 0x3e, 0x02, 0xbb, 0x3e, 0x9b, 0xd3, 0xd4, 0xfa, 0xaf, 0x62, 0xef, 0x14, 0x39, 0x6c, 0x09, 0xb6, + 0x0a, 0x23, 0x2c, 0xe4, 0xbe, 0x71, 0xb9, 0x84, 0xfa, 0xcf, 0x25, 0xd4, 0xd1, 0xa7, 0x1a, 0x68, + 0x9c, 0xcb, 0xec, 0x13, 0xd0, 0x20, 0xbe, 0xcf, 0x66, 0x09, 0xaf, 0x7a, 0x35, 0x9f, 0x75, 0x1c, + 0x31, 0x85, 0xa3, 0xa6, 0x70, 0x4e, 0x93, 0xc5, 0xa0, 0xf5, 0xf5, 0xf3, 0xb1, 0x71, 0x2a, 0xc0, + 0x97, 0x58, 0xa5, 0x98, 0x0f, 0xc0, 0x4e, 0xc0, 0x49, 0x28, 0x5b, 0xef, 0x17, 0x39, 0x6c, 0x8a, + 0xd6, 0x65, 0x14, 0xe1, 0x4a, 0x2c, 0xc7, 0x89, 0x59, 0x12, 0xbd, 0xa3, 0xa9, 0x55, 0xbb, 0x3d, + 0x8e, 0x14, 0x10, 0x56, 0x88, 0x79, 0x04, 0x6a, 0x5e, 0xc4, 0xac, 0x9d, 0x8a, 0xdc, 0x2b, 0x72, + 0x08, 0x04, 0xe9, 0x45, 0x0c, 0xe1, 0x52, 0x32, 0x5f, 0x01, 0x63, 0x2a, 0xad, 0xb2, 0x76, 0xab, + 0x3b, 0xdf, 0x77, 0xfe, 0xb1, 0x43, 0x47, 0x79, 0x3a, 0x38, 0xbc, 0xca, 0xa1, 0x56, 0xe4, 0x70, + 0x5f, 0xda, 0x28, 0xe3, 0x08, 0x6f, 0x6a, 0x99, 0x29, 0x68, 0xfb, 0x29, 0x25, 0x3c, 0x62, 0xc9, + 0x28, 0x20, 0x9c, 0x5a, 0xf5, 0xaa, 0x78, 0xf7, 0x2f, 0x43, 0x86, 0x6a, 0xad, 0x83, 0x5e, 0x59, + 0xf5, 0x57, 0x0e, 0x6f, 0x26, 0x16, 0x39, 0xec, 0xc8, 0x0d, 0xfc, 0x19, 0x46, 0x17, 0xdf, 0xa1, + 0x8e, 0x5b, 0x2a, 0x76, 0x46, 0x38, 0xed, 0x1b, 0x1f, 0x97, 0x50, 0xbb, 0x5c, 0x42, 0x0d, 0x7d, + 0xd1, 0xc1, 0xc1, 0xd9, 0x90, 0x84, 0xc3, 0x94, 0x24, 0xd9, 0x98, 0xa6, 0x98, 0xbe, 0x9f, 0xd1, + 0x8c, 0x9b, 0x27, 0xa0, 0x5d, 0xba, 0x38, 0xe2, 0x6c, 0xc4, 0x53, 0x12, 0xa8, 0x27, 0x61, 0x6d, + 0x9b, 0xdc, 0x90, 0x11, 0x6e, 0x96, 0xe7, 0x21, 0x1b, 0x96, 0x27, 0xf3, 0x09, 0xa8, 0x67, 0x34, + 0x09, 0x36, 0xaf, 0xe3, 0x6e, 0x91, 0xc3, 0xb6, 0x48, 0x13, 0x71, 0x84, 0x25, 0x60, 0xba, 0xc0, + 0x48, 0xa9, 0x4f, 0xa3, 0xf9, 0x66, 0x4f, 0x07, 0x5b, 0xbf, 0x94, 0x82, 0xf0, 0x06, 0xda, 0x3e, + 0xa8, 0xc1, 0x8b, 0xab, 0x95, 0xad, 0x5f, 0xaf, 0x6c, 0xfd, 0xc7, 0xca, 0xd6, 0x2f, 0xd6, 0xb6, + 0x76, 0xbd, 0xb6, 0xb5, 0x6f, 0x6b, 0x5b, 0x7b, 0xed, 0x84, 0x11, 0x7f, 0x33, 0xf3, 0x1c, 0x9f, + 0xc5, 0xae, 0xd8, 0xd1, 0xf1, 0x84, 0x78, 0x99, 0xfc, 0x76, 0x3f, 0x6c, 0xff, 0x4d, 0xbe, 0x98, + 0xd2, 0xcc, 0xab, 0x57, 0x26, 0x3f, 0xff, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x04, 0x0a, 0xe9, 0x93, + 0xbb, 0x03, 0x00, 0x00, } func (this *Pictures) Equal(that interface{}) bool { @@ -301,45 +263,6 @@ func (this *Pictures) Equal(that interface{}) bool { } return true } -func (this *Profile) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*Profile) - if !ok { - that2, ok := that.(Profile) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Dtag != that1.Dtag { - return false - } - if this.Moniker != that1.Moniker { - return false - } - if this.Bio != that1.Bio { - return false - } - if !this.Pictures.Equal(&that1.Pictures) { - return false - } - if this.Creator != that1.Creator { - return false - } - if !this.CreationDate.Equal(that1.CreationDate) { - return false - } - return true -} func (this *DTagTransferRequest) Equal(that interface{}) bool { if that == nil { return this == nil @@ -435,13 +358,6 @@ func (m *Profile) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintModels(dAtA, i, uint64(n1)) i-- dAtA[i] = 0x32 - if len(m.Creator) > 0 { - i -= len(m.Creator) - copy(dAtA[i:], m.Creator) - i = encodeVarintModels(dAtA, i, uint64(len(m.Creator))) - i-- - dAtA[i] = 0x2a - } { size, err := m.Pictures.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -451,26 +367,38 @@ func (m *Profile) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintModels(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x22 + dAtA[i] = 0x2a if len(m.Bio) > 0 { i -= len(m.Bio) copy(dAtA[i:], m.Bio) i = encodeVarintModels(dAtA, i, uint64(len(m.Bio))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x22 } if len(m.Moniker) > 0 { i -= len(m.Moniker) copy(dAtA[i:], m.Moniker) i = encodeVarintModels(dAtA, i, uint64(len(m.Moniker))) i-- - dAtA[i] = 0x12 + dAtA[i] = 0x1a } if len(m.Dtag) > 0 { i -= len(m.Dtag) copy(dAtA[i:], m.Dtag) i = encodeVarintModels(dAtA, i, uint64(len(m.Dtag))) i-- + dAtA[i] = 0x12 + } + if m.Account != nil { + { + size, err := m.Account.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintModels(dAtA, i, uint64(size)) + } + i-- dAtA[i] = 0xa } return len(dAtA) - i, nil @@ -554,6 +482,10 @@ func (m *Profile) Size() (n int) { } var l int _ = l + if m.Account != nil { + l = m.Account.Size() + n += 1 + l + sovModels(uint64(l)) + } l = len(m.Dtag) if l > 0 { n += 1 + l + sovModels(uint64(l)) @@ -568,10 +500,6 @@ func (m *Profile) Size() (n int) { } l = m.Pictures.Size() n += 1 + l + sovModels(uint64(l)) - l = len(m.Creator) - if l > 0 { - n += 1 + l + sovModels(uint64(l)) - } l = github_com_gogo_protobuf_types.SizeOfStdTime(m.CreationDate) n += 1 + l + sovModels(uint64(l)) return n @@ -749,9 +677,9 @@ func (m *Profile) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Dtag", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Account", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowModels @@ -761,27 +689,31 @@ func (m *Profile) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthModels } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthModels } if postIndex > l { return io.ErrUnexpectedEOF } - m.Dtag = string(dAtA[iNdEx:postIndex]) + if m.Account == nil { + m.Account = &types.Any{} + } + if err := m.Account.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Moniker", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Dtag", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -809,11 +741,11 @@ func (m *Profile) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Moniker = string(dAtA[iNdEx:postIndex]) + m.Dtag = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Bio", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Moniker", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -841,13 +773,13 @@ func (m *Profile) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Bio = string(dAtA[iNdEx:postIndex]) + m.Moniker = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Pictures", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Bio", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowModels @@ -857,30 +789,29 @@ func (m *Profile) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthModels } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthModels } if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Pictures.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.Bio = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 5: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Pictures", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowModels @@ -890,23 +821,24 @@ func (m *Profile) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthModels } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthModels } if postIndex > l { return io.ErrUnexpectedEOF } - m.Creator = string(dAtA[iNdEx:postIndex]) + if err := m.Pictures.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 6: if wireType != 2 { From 9626b2eec80d2319df114b2a7f7ccd322ace0bf1 Mon Sep 17 00:00:00 2001 From: "riccardo.montagnin" Date: Mon, 12 Apr 2021 14:54:07 +0200 Subject: [PATCH 08/11] Merged master, updated Cosmos version and removed the WrappedDTagRequests type Signed-off-by: riccardo.montagnin --- app/app.go | 1 + app/sim_test.go | 8 +- go.mod | 5 +- go.sum | 10 +- .../profiles/v1beta1/keeper/types.proto | 16 - proto/desmos/profiles/v1beta1/models.proto | 9 +- x/profiles/keeper/common_test.go | 2 +- x/profiles/keeper/keeper.go | 12 +- x/profiles/keeper/keeper_test.go | 8 +- x/profiles/keeper/msgs_server_test.go | 2 +- x/profiles/keeper/types.go | 8 - x/profiles/keeper/types.pb.go | 364 ------------------ x/profiles/simulation/decoder.go | 4 +- x/profiles/simulation/decoder_test.go | 7 +- x/profiles/types/models.go | 5 + x/profiles/types/models.pb.go | 287 ++++++++++++-- x/staging/fees/ante/ante_test.go | 40 +- x/staging/fees/ante/common_test.go | 4 +- x/staging/fees/simulation/genesis.go | 10 +- x/staging/posts/types/polls.pb.go | 2 +- x/staging/posts/types/posts.pb.go | 2 +- x/staging/posts/types/query.pb.go | 2 +- x/staging/reports/types/models.go | 2 +- 23 files changed, 320 insertions(+), 490 deletions(-) delete mode 100644 proto/desmos/profiles/v1beta1/keeper/types.proto delete mode 100644 x/profiles/keeper/types.go delete mode 100644 x/profiles/keeper/types.pb.go diff --git a/app/app.go b/app/app.go index 1eb1bef00d..b7f4733e69 100644 --- a/app/app.go +++ b/app/app.go @@ -358,6 +358,7 @@ func NewDesmosApp( keys[profilestypes.StoreKey], app.GetSubspace(profilestypes.ModuleName), app.RelationshipsKeeper, + app.AccountKeeper, ) app.ReportsKeeper = reportsKeeper.NewKeeper( app.appCodec, diff --git a/app/sim_test.go b/app/sim_test.go index 4e59898831..3d3c998ec0 100644 --- a/app/sim_test.go +++ b/app/sim_test.go @@ -16,11 +16,10 @@ import ( slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - magpietypes "github.com/desmos-labs/desmos/x/magpie/types" - poststypes "github.com/desmos-labs/desmos/x/posts/types" profilestypes "github.com/desmos-labs/desmos/x/profiles/types" - relationshipstypes "github.com/desmos-labs/desmos/x/relationships/types" - reportstypes "github.com/desmos-labs/desmos/x/reports/types" + poststypes "github.com/desmos-labs/desmos/x/staging/posts/types" + relationshipstypes "github.com/desmos-labs/desmos/x/staging/relationships/types" + reportstypes "github.com/desmos-labs/desmos/x/staging/reports/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -221,7 +220,6 @@ func TestAppImportExport(t *testing.T) { {app.keys[govtypes.StoreKey], newApp.keys[govtypes.StoreKey], [][]byte{}}, {app.keys[evidencetypes.StoreKey], newApp.keys[evidencetypes.StoreKey], [][]byte{}}, - {app.keys[magpietypes.StoreKey], newApp.keys[magpietypes.StoreKey], [][]byte{}}, {app.keys[poststypes.StoreKey], newApp.keys[poststypes.StoreKey], [][]byte{}}, {app.keys[profilestypes.StoreKey], newApp.keys[profilestypes.StoreKey], [][]byte{}}, {app.keys[reportstypes.StoreKey], newApp.keys[reportstypes.StoreKey], [][]byte{}}, diff --git a/go.mod b/go.mod index faa722d398..0d47b5c2f2 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,7 @@ module github.com/desmos-labs/desmos go 1.15 require ( - github.com/btcsuite/btcd v0.21.0-beta - github.com/cosmos/cosmos-sdk v0.42.3 + github.com/cosmos/cosmos-sdk v0.42.4 github.com/desmos-labs/Go-Emoji-Utils v1.1.1-0.20200515063516-9c493b11de3e github.com/ghodss/yaml v1.0.0 github.com/gogo/protobuf v1.3.3 @@ -17,7 +16,7 @@ require ( github.com/spf13/cobra v1.1.1 github.com/spf13/viper v1.7.1 github.com/stretchr/testify v1.7.0 - github.com/tendermint/tendermint v0.34.8 + github.com/tendermint/tendermint v0.34.9 github.com/tendermint/tm-db v0.6.4 google.golang.org/genproto v0.0.0-20210114201628-6edceaf6022f google.golang.org/grpc v1.35.0 diff --git a/go.sum b/go.sum index 1c9719846d..8ac4941bfd 100644 --- a/go.sum +++ b/go.sum @@ -104,8 +104,8 @@ github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7 github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cosmos/cosmos-sdk v0.42.3 h1:VFYq7spDBBIlygAxwcI79Xh2JuIrG1ZCPKpvqKghIZs= -github.com/cosmos/cosmos-sdk v0.42.3/go.mod h1:xiLp1G8mumj82S5KLJGCAyeAlD+7VNomg/aRSJV12yk= +github.com/cosmos/cosmos-sdk v0.42.4 h1:yaD4PyOx0LnyfiWasC5egg1U76lT83GRxjJjupPo7Gk= +github.com/cosmos/cosmos-sdk v0.42.4/go.mod h1:I1Zw1zmU4rA/NITaakTb71pXQnQrWyFBhqo3WSeg0vA= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= @@ -238,6 +238,8 @@ github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSN github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/orderedcode v0.0.1 h1:UzfcAexk9Vhv8+9pNOgRu41f16lHq725vPwnSeiG/Us= +github.com/google/orderedcode v0.0.1/go.mod h1:iVyU4/qPKHY5h/wSd6rZZCDcLJNxiWO6dvsYES2Sb20= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= @@ -574,8 +576,8 @@ github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoM github.com/tendermint/tendermint v0.34.0-rc4/go.mod h1:yotsojf2C1QBOw4dZrTcxbyxmPUrT4hNuOQWX9XUwB4= github.com/tendermint/tendermint v0.34.0-rc6/go.mod h1:ugzyZO5foutZImv0Iyx/gOFCX6mjJTgbLHTwi17VDVg= github.com/tendermint/tendermint v0.34.0/go.mod h1:Aj3PIipBFSNO21r+Lq3TtzQ+uKESxkbA3yo/INM4QwQ= -github.com/tendermint/tendermint v0.34.8 h1:PMWgUx47FrNTsfhxCWzoiIlVAC1SE9+WBlnsF9oQW0I= -github.com/tendermint/tendermint v0.34.8/go.mod h1:JVuu3V1ZexOaZG8VJMRl8lnfrGw6hEB2TVnoUwKRbss= +github.com/tendermint/tendermint v0.34.9 h1:9P2MXDEPOcPW0NBcHQ/HDSfvczZm+q5nUUw7AZ6f1Vc= +github.com/tendermint/tendermint v0.34.9/go.mod h1:kl4Z1JwGx1I+u1SXIzMDy7Z3T8LiMeCAOnzNn6AIMT4= github.com/tendermint/tm-db v0.6.2/go.mod h1:GYtQ67SUvATOcoY8/+x6ylk8Qo02BQyLrAs+yAcLvGI= github.com/tendermint/tm-db v0.6.3/go.mod h1:lfA1dL9/Y/Y8wwyPp2NMLyn5P5Ptr/gvDFNWtrCWSf8= github.com/tendermint/tm-db v0.6.4 h1:3N2jlnYQkXNQclQwd/eKV/NzlqPlfK21cpRRIx80XXQ= diff --git a/proto/desmos/profiles/v1beta1/keeper/types.proto b/proto/desmos/profiles/v1beta1/keeper/types.proto deleted file mode 100644 index 5b6a199a06..0000000000 --- a/proto/desmos/profiles/v1beta1/keeper/types.proto +++ /dev/null @@ -1,16 +0,0 @@ -syntax = "proto3"; -package desmos.profiles.v1beta1.keeper; - -import "gogoproto/gogo.proto"; -import "desmos/profiles/v1beta1/models.proto"; - -option go_package = "github.com/desmos-labs/desmos/x/profiles/keeper"; - -// DtagRequests contains the DTag transfer requests made towards a user -message WrappedDTagTransferRequests { - option (gogoproto.equal) = true; - option (gogoproto.goproto_stringer) = true; - - repeated desmos.profiles.v1beta1.DTagTransferRequest requests = 1 - [ (gogoproto.nullable) = false ]; -} diff --git a/proto/desmos/profiles/v1beta1/models.proto b/proto/desmos/profiles/v1beta1/models.proto index b3b413cf74..ca871f55c2 100644 --- a/proto/desmos/profiles/v1beta1/models.proto +++ b/proto/desmos/profiles/v1beta1/models.proto @@ -54,4 +54,11 @@ message DTagTransferRequest { string receiver = 3 [(gogoproto.moretags) = "yaml:\"receiver\""]; } -// ___________________________________________________________________________________________________________________ +// DTagTransferRequests contains a list of DTagTransferRequest +message DTagTransferRequests { + option (gogoproto.equal) = true; + option (gogoproto.goproto_stringer) = true; + + repeated DTagTransferRequest requests = 1 + [(gogoproto.nullable) = false]; +} \ No newline at end of file diff --git a/x/profiles/keeper/common_test.go b/x/profiles/keeper/common_test.go index 71e93b2372..27a41fd23d 100644 --- a/x/profiles/keeper/common_test.go +++ b/x/profiles/keeper/common_test.go @@ -8,7 +8,7 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" - relationshipstypes "github.com/desmos-labs/desmos/x/relationships/types" + relationshipstypes "github.com/desmos-labs/desmos/x/staging/relationships/types" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" diff --git a/x/profiles/keeper/keeper.go b/x/profiles/keeper/keeper.go index 2006fd99f5..aab3778fef 100644 --- a/x/profiles/keeper/keeper.go +++ b/x/profiles/keeper/keeper.go @@ -184,7 +184,7 @@ func (k Keeper) SaveDTagTransferRequest(ctx sdk.Context, request types.DTagTrans store := ctx.KVStore(k.storeKey) key := types.DtagTransferRequestStoreKey(request.Receiver) - var requests WrappedDTagTransferRequests + var requests types.DTagTransferRequests k.cdc.MustUnmarshalBinaryBare(store.Get(key), &requests) for _, req := range requests.Requests { if req.Sender == request.Sender && req.Receiver == request.Receiver { @@ -194,7 +194,7 @@ func (k Keeper) SaveDTagTransferRequest(ctx sdk.Context, request types.DTagTrans } } - requests = NewWrappedDTagTransferRequests(append(requests.Requests, request)) + requests = types.NewDTagTransferRequests(append(requests.Requests, request)) store.Set(key, k.cdc.MustMarshalBinaryBare(&requests)) return nil } @@ -204,7 +204,7 @@ func (k Keeper) GetUserIncomingDTagTransferRequests(ctx sdk.Context, user string store := ctx.KVStore(k.storeKey) key := types.DtagTransferRequestStoreKey(user) - var requests WrappedDTagTransferRequests + var requests types.DTagTransferRequests k.cdc.MustUnmarshalBinaryBare(store.Get(key), &requests) return requests.Requests } @@ -215,7 +215,7 @@ func (k Keeper) GetDTagTransferRequests(ctx sdk.Context) (requests []types.DTagT iterator := sdk.KVStorePrefixIterator(store, types.DTagTransferRequestsPrefix) for ; iterator.Valid(); iterator.Next() { - var userRequests WrappedDTagTransferRequests + var userRequests types.DTagTransferRequests k.cdc.MustUnmarshalBinaryBare(iterator.Value(), &userRequests) requests = append(requests, userRequests.Requests...) } @@ -234,7 +234,7 @@ func (k Keeper) DeleteDTagTransferRequest(ctx sdk.Context, sender, recipient str store := ctx.KVStore(k.storeKey) key := types.DtagTransferRequestStoreKey(recipient) - var wrapped WrappedDTagTransferRequests + var wrapped types.DTagTransferRequests k.cdc.MustUnmarshalBinaryBare(store.Get(key), &wrapped) for index, request := range wrapped.Requests { @@ -243,7 +243,7 @@ func (k Keeper) DeleteDTagTransferRequest(ctx sdk.Context, sender, recipient str if len(requests) == 0 { store.Delete(key) } else { - store.Set(key, k.cdc.MustMarshalBinaryBare(&WrappedDTagTransferRequests{Requests: requests})) + store.Set(key, k.cdc.MustMarshalBinaryBare(&types.DTagTransferRequests{Requests: requests})) } return nil } diff --git a/x/profiles/keeper/keeper_test.go b/x/profiles/keeper/keeper_test.go index 78825da639..a19eb36d2f 100644 --- a/x/profiles/keeper/keeper_test.go +++ b/x/profiles/keeper/keeper_test.go @@ -11,8 +11,6 @@ import ( relationshipstypes "github.com/desmos-labs/desmos/x/staging/relationships/types" - "github.com/desmos-labs/desmos/x/profiles/keeper" - "github.com/desmos-labs/desmos/x/profiles/types" ) @@ -517,7 +515,7 @@ func (suite *KeeperTestSuite) TestKeeper_GetUserDTagTransferRequests() { suite.Run(test.name, func() { store := suite.ctx.KVStore(suite.storeKey) if test.storedReqs != nil { - reqs := keeper.NewWrappedDTagTransferRequests(test.storedReqs) + reqs := types.NewDTagTransferRequests(test.storedReqs) store.Set( types.DtagTransferRequestStoreKey(suite.testData.user), suite.cdc.MustMarshalBinaryBare(&reqs), @@ -558,7 +556,7 @@ func (suite *KeeperTestSuite) TestKeeper_GetDTagTransferRequests() { suite.Run(test.name, func() { store := suite.ctx.KVStore(suite.storeKey) if test.storedReqs != nil { - reqs := keeper.NewWrappedDTagTransferRequests(test.storedReqs) + reqs := types.NewDTagTransferRequests(test.storedReqs) store.Set( types.DtagTransferRequestStoreKey(suite.testData.user), suite.cdc.MustMarshalBinaryBare(&reqs), @@ -591,7 +589,7 @@ func (suite *KeeperTestSuite) TestKeeper_DeleteAllDTagTransferRequests() { suite.Run(test.name, func() { store := suite.ctx.KVStore(suite.storeKey) if test.storedReqs != nil { - reqs := keeper.NewWrappedDTagTransferRequests(test.storedReqs) + reqs := types.NewDTagTransferRequests(test.storedReqs) store.Set( types.DtagTransferRequestStoreKey(suite.testData.user), suite.cdc.MustMarshalBinaryBare(&reqs), diff --git a/x/profiles/keeper/msgs_server_test.go b/x/profiles/keeper/msgs_server_test.go index f95713634b..24caf9806b 100644 --- a/x/profiles/keeper/msgs_server_test.go +++ b/x/profiles/keeper/msgs_server_test.go @@ -7,7 +7,7 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - relationshipstypes "github.com/desmos-labs/desmos/x/relationships/types" + relationshipstypes "github.com/desmos-labs/desmos/x/staging/relationships/types" "github.com/desmos-labs/desmos/x/profiles/keeper" diff --git a/x/profiles/keeper/types.go b/x/profiles/keeper/types.go deleted file mode 100644 index c5c8cacf70..0000000000 --- a/x/profiles/keeper/types.go +++ /dev/null @@ -1,8 +0,0 @@ -package keeper - -import "github.com/desmos-labs/desmos/x/profiles/types" - -// NewWrappedDTagTransferRequests returns a DTagRequests instance wrapping the given requests -func NewWrappedDTagTransferRequests(requests []types.DTagTransferRequest) WrappedDTagTransferRequests { - return WrappedDTagTransferRequests{Requests: requests} -} diff --git a/x/profiles/keeper/types.pb.go b/x/profiles/keeper/types.pb.go deleted file mode 100644 index a882e6d3e0..0000000000 --- a/x/profiles/keeper/types.pb.go +++ /dev/null @@ -1,364 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: desmos/profiles/v1beta1/keeper/types.proto - -package keeper - -import ( - fmt "fmt" - types "github.com/desmos-labs/desmos/x/profiles/types" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// DtagRequests contains the DTag transfer requests made towards a user -type WrappedDTagTransferRequests struct { - Requests []types.DTagTransferRequest `protobuf:"bytes,1,rep,name=requests,proto3" json:"requests"` -} - -func (m *WrappedDTagTransferRequests) Reset() { *m = WrappedDTagTransferRequests{} } -func (m *WrappedDTagTransferRequests) String() string { return proto.CompactTextString(m) } -func (*WrappedDTagTransferRequests) ProtoMessage() {} -func (*WrappedDTagTransferRequests) Descriptor() ([]byte, []int) { - return fileDescriptor_732b728428b8b385, []int{0} -} -func (m *WrappedDTagTransferRequests) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *WrappedDTagTransferRequests) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_WrappedDTagTransferRequests.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *WrappedDTagTransferRequests) XXX_Merge(src proto.Message) { - xxx_messageInfo_WrappedDTagTransferRequests.Merge(m, src) -} -func (m *WrappedDTagTransferRequests) XXX_Size() int { - return m.Size() -} -func (m *WrappedDTagTransferRequests) XXX_DiscardUnknown() { - xxx_messageInfo_WrappedDTagTransferRequests.DiscardUnknown(m) -} - -var xxx_messageInfo_WrappedDTagTransferRequests proto.InternalMessageInfo - -func (m *WrappedDTagTransferRequests) GetRequests() []types.DTagTransferRequest { - if m != nil { - return m.Requests - } - return nil -} - -func init() { - proto.RegisterType((*WrappedDTagTransferRequests)(nil), "desmos.profiles.v1beta1.keeper.WrappedDTagTransferRequests") -} - -func init() { - proto.RegisterFile("desmos/profiles/v1beta1/keeper/types.proto", fileDescriptor_732b728428b8b385) -} - -var fileDescriptor_732b728428b8b385 = []byte{ - // 238 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x4a, 0x49, 0x2d, 0xce, - 0xcd, 0x2f, 0xd6, 0x2f, 0x28, 0xca, 0x4f, 0xcb, 0xcc, 0x49, 0x2d, 0xd6, 0x2f, 0x33, 0x4c, 0x4a, - 0x2d, 0x49, 0x34, 0xd4, 0xcf, 0x4e, 0x4d, 0x2d, 0x48, 0x2d, 0xd2, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, - 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x83, 0xa8, 0xd5, 0x83, 0xa9, 0xd5, 0x83, 0xaa, - 0xd5, 0x83, 0xa8, 0x95, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0x2b, 0xd5, 0x07, 0xb1, 0x20, 0xba, - 0xa4, 0x54, 0x70, 0xd9, 0x90, 0x9b, 0x9f, 0x92, 0x9a, 0x03, 0x35, 0x5b, 0xa9, 0x9c, 0x4b, 0x3a, - 0xbc, 0x28, 0xb1, 0xa0, 0x20, 0x35, 0xc5, 0x25, 0x24, 0x31, 0x3d, 0xa4, 0x28, 0x31, 0xaf, 0x38, - 0x2d, 0xb5, 0x28, 0x28, 0xb5, 0xb0, 0x34, 0xb5, 0xb8, 0xa4, 0x58, 0xc8, 0x8f, 0x8b, 0xa3, 0x08, - 0xca, 0x96, 0x60, 0x54, 0x60, 0xd6, 0xe0, 0x36, 0xd2, 0xd1, 0xc3, 0xe5, 0x1a, 0x2c, 0x06, 0x38, - 0xb1, 0x9c, 0xb8, 0x27, 0xcf, 0x10, 0x04, 0x37, 0xc3, 0x8a, 0x63, 0xc6, 0x02, 0x79, 0xc6, 0x17, - 0x0b, 0xe4, 0x19, 0x9d, 0x3c, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, - 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, - 0x3f, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x1f, 0x62, 0x97, 0x6e, 0x4e, - 0x62, 0x52, 0x31, 0x94, 0xad, 0x5f, 0x81, 0xf0, 0x11, 0xc4, 0xff, 0x49, 0x6c, 0x60, 0xaf, 0x18, - 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x05, 0x21, 0x73, 0x8c, 0x54, 0x01, 0x00, 0x00, -} - -func (this *WrappedDTagTransferRequests) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*WrappedDTagTransferRequests) - if !ok { - that2, ok := that.(WrappedDTagTransferRequests) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if len(this.Requests) != len(that1.Requests) { - return false - } - for i := range this.Requests { - if !this.Requests[i].Equal(&that1.Requests[i]) { - return false - } - } - return true -} -func (m *WrappedDTagTransferRequests) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *WrappedDTagTransferRequests) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *WrappedDTagTransferRequests) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Requests) > 0 { - for iNdEx := len(m.Requests) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Requests[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { - offset -= sovTypes(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *WrappedDTagTransferRequests) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Requests) > 0 { - for _, e := range m.Requests { - l = e.Size() - n += 1 + l + sovTypes(uint64(l)) - } - } - return n -} - -func sovTypes(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozTypes(x uint64) (n int) { - return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *WrappedDTagTransferRequests) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: WrappedDTagTransferRequests: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: WrappedDTagTransferRequests: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Requests", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Requests = append(m.Requests, types.DTagTransferRequest{}) - if err := m.Requests[len(m.Requests)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipTypes(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowTypes - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowTypes - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowTypes - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthTypes - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupTypes - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthTypes - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowTypes = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupTypes = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/profiles/simulation/decoder.go b/x/profiles/simulation/decoder.go index 7bf2898cae..f751e64aaa 100644 --- a/x/profiles/simulation/decoder.go +++ b/x/profiles/simulation/decoder.go @@ -6,8 +6,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/desmos-labs/desmos/x/profiles/keeper" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/kv" @@ -25,7 +23,7 @@ func NewDecodeStore(cdc codec.Marshaler) func(kvA, kvB kv.Pair) string { return fmt.Sprintf("DTagAddressA: %s\nDTagAddressB: %s\n", addressA, addressB) case bytes.HasPrefix(kvA.Key, types.DTagTransferRequestsPrefix): - var requestsA, requestsB keeper.WrappedDTagTransferRequests + var requestsA, requestsB types.DTagTransferRequests cdc.MustUnmarshalBinaryBare(kvA.Value, &requestsA) cdc.MustUnmarshalBinaryBare(kvB.Value, &requestsB) return fmt.Sprintf("RequestsA: %s\nRequestsB: %s\n", requestsA.Requests, requestsB.Requests) diff --git a/x/profiles/simulation/decoder_test.go b/x/profiles/simulation/decoder_test.go index 639031882d..3361f30edc 100644 --- a/x/profiles/simulation/decoder_test.go +++ b/x/profiles/simulation/decoder_test.go @@ -8,11 +8,10 @@ import ( "github.com/cosmos/cosmos-sdk/types/kv" - "github.com/desmos-labs/desmos/app" - "github.com/desmos-labs/desmos/x/profiles/keeper" - "github.com/stretchr/testify/require" + "github.com/desmos-labs/desmos/app" + "github.com/desmos-labs/desmos/x/profiles/simulation" "github.com/desmos-labs/desmos/x/profiles/types" ) @@ -21,7 +20,7 @@ func TestDecodeStore(t *testing.T) { cdc, _ := app.MakeCodecs() dec := simulation.NewDecodeStore(cdc) - requests := keeper.NewWrappedDTagTransferRequests([]types.DTagTransferRequest{ + requests := types.NewDTagTransferRequests([]types.DTagTransferRequest{ types.NewDTagTransferRequest( "dtag", "cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns", diff --git a/x/profiles/types/models.go b/x/profiles/types/models.go index ff9a6ce613..62823e328c 100644 --- a/x/profiles/types/models.go +++ b/x/profiles/types/models.go @@ -68,3 +68,8 @@ func (request DTagTransferRequest) Validate() error { return nil } + +// NewDTagTransferRequests returns a DTagTransferRequests instance wrapping the given requests +func NewDTagTransferRequests(requests []DTagTransferRequest) DTagTransferRequests { + return DTagTransferRequests{Requests: requests} +} diff --git a/x/profiles/types/models.pb.go b/x/profiles/types/models.pb.go index 157b744de7..8d18491246 100644 --- a/x/profiles/types/models.pb.go +++ b/x/profiles/types/models.pb.go @@ -186,10 +186,56 @@ func (m *DTagTransferRequest) GetReceiver() string { return "" } +// DTagTransferRequests contains a list of DTagTransferRequest +type DTagTransferRequests struct { + Requests []DTagTransferRequest `protobuf:"bytes,1,rep,name=requests,proto3" json:"requests"` +} + +func (m *DTagTransferRequests) Reset() { *m = DTagTransferRequests{} } +func (m *DTagTransferRequests) String() string { return proto.CompactTextString(m) } +func (*DTagTransferRequests) ProtoMessage() {} +func (*DTagTransferRequests) Descriptor() ([]byte, []int) { + return fileDescriptor_dcbf89d5cd53a9ca, []int{3} +} +func (m *DTagTransferRequests) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DTagTransferRequests) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DTagTransferRequests.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *DTagTransferRequests) XXX_Merge(src proto.Message) { + xxx_messageInfo_DTagTransferRequests.Merge(m, src) +} +func (m *DTagTransferRequests) XXX_Size() int { + return m.Size() +} +func (m *DTagTransferRequests) XXX_DiscardUnknown() { + xxx_messageInfo_DTagTransferRequests.DiscardUnknown(m) +} + +var xxx_messageInfo_DTagTransferRequests proto.InternalMessageInfo + +func (m *DTagTransferRequests) GetRequests() []DTagTransferRequest { + if m != nil { + return m.Requests + } + return nil +} + func init() { proto.RegisterType((*Pictures)(nil), "desmos.profiles.v1beta1.Pictures") proto.RegisterType((*Profile)(nil), "desmos.profiles.v1beta1.Profile") proto.RegisterType((*DTagTransferRequest)(nil), "desmos.profiles.v1beta1.DTagTransferRequest") + proto.RegisterType((*DTagTransferRequests)(nil), "desmos.profiles.v1beta1.DTagTransferRequests") } func init() { @@ -197,43 +243,45 @@ func init() { } var fileDescriptor_dcbf89d5cd53a9ca = []byte{ - // 564 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x93, 0xb1, 0x6f, 0xd3, 0x4e, - 0x14, 0xc7, 0xed, 0x5f, 0xda, 0xc4, 0xbf, 0x4b, 0xd2, 0x82, 0x1b, 0xa9, 0x26, 0x83, 0xaf, 0x1c, - 0x08, 0x81, 0x44, 0x6d, 0x05, 0xb6, 0xa8, 0x4b, 0xa3, 0x0e, 0xb0, 0x55, 0xa7, 0x88, 0x81, 0x25, - 0x3a, 0xdb, 0x17, 0x63, 0x88, 0x7d, 0xc1, 0xbe, 0x44, 0xe4, 0x3f, 0x60, 0xac, 0x98, 0x3a, 0xe6, - 0x8f, 0x60, 0xe1, 0x3f, 0xa8, 0x98, 0x3a, 0x32, 0x19, 0x94, 0x2c, 0x88, 0xd1, 0x7f, 0x01, 0xb2, - 0xef, 0x2e, 0xa1, 0x45, 0x6c, 0xbe, 0xf7, 0xfd, 0xbc, 0xf7, 0xee, 0x7d, 0xdf, 0x19, 0x3c, 0x0c, - 0x68, 0x16, 0xb3, 0xcc, 0x9d, 0xa6, 0x6c, 0x1c, 0x4d, 0x68, 0xe6, 0xce, 0x7b, 0x1e, 0xe5, 0xa4, - 0xe7, 0xc6, 0x2c, 0xa0, 0x93, 0xcc, 0x99, 0xa6, 0x8c, 0x33, 0xf3, 0x50, 0x50, 0x8e, 0xa2, 0x1c, - 0x49, 0x75, 0x3b, 0x21, 0x0b, 0x59, 0xc5, 0xb8, 0xe5, 0x97, 0xc0, 0xbb, 0xf7, 0x42, 0xc6, 0xc2, - 0x09, 0x75, 0xab, 0x93, 0x37, 0x1b, 0xbb, 0x24, 0x59, 0x48, 0x09, 0xde, 0x96, 0x78, 0x14, 0xd3, - 0x8c, 0x93, 0x78, 0xaa, 0x72, 0x7d, 0x56, 0xb6, 0x1a, 0x89, 0xa2, 0xe2, 0x20, 0x24, 0xf4, 0x16, - 0x18, 0xe7, 0x91, 0xcf, 0x67, 0x29, 0xcd, 0xcc, 0xa7, 0xa0, 0x21, 0x2f, 0x63, 0xe9, 0x47, 0xfa, - 0xe3, 0xff, 0x07, 0x66, 0x91, 0xc3, 0xbd, 0x05, 0x89, 0x27, 0x7d, 0x24, 0x05, 0x84, 0x15, 0x62, - 0x3e, 0x02, 0xbb, 0x3e, 0x9b, 0xd3, 0xd4, 0xfa, 0xaf, 0x62, 0xef, 0x14, 0x39, 0x6c, 0x09, 0xb6, - 0x0a, 0x23, 0x2c, 0xe4, 0xbe, 0x71, 0xb9, 0x84, 0xfa, 0xcf, 0x25, 0xd4, 0xd1, 0xa7, 0x1a, 0x68, - 0x9c, 0xcb, 0xec, 0x13, 0xd0, 0x20, 0xbe, 0xcf, 0x66, 0x09, 0xaf, 0x7a, 0x35, 0x9f, 0x75, 0x1c, - 0x31, 0x85, 0xa3, 0xa6, 0x70, 0x4e, 0x93, 0xc5, 0xa0, 0xf5, 0xf5, 0xf3, 0xb1, 0x71, 0x2a, 0xc0, - 0x97, 0x58, 0xa5, 0x98, 0x0f, 0xc0, 0x4e, 0xc0, 0x49, 0x28, 0x5b, 0xef, 0x17, 0x39, 0x6c, 0x8a, - 0xd6, 0x65, 0x14, 0xe1, 0x4a, 0x2c, 0xc7, 0x89, 0x59, 0x12, 0xbd, 0xa3, 0xa9, 0x55, 0xbb, 0x3d, - 0x8e, 0x14, 0x10, 0x56, 0x88, 0x79, 0x04, 0x6a, 0x5e, 0xc4, 0xac, 0x9d, 0x8a, 0xdc, 0x2b, 0x72, - 0x08, 0x04, 0xe9, 0x45, 0x0c, 0xe1, 0x52, 0x32, 0x5f, 0x01, 0x63, 0x2a, 0xad, 0xb2, 0x76, 0xab, - 0x3b, 0xdf, 0x77, 0xfe, 0xb1, 0x43, 0x47, 0x79, 0x3a, 0x38, 0xbc, 0xca, 0xa1, 0x56, 0xe4, 0x70, - 0x5f, 0xda, 0x28, 0xe3, 0x08, 0x6f, 0x6a, 0x99, 0x29, 0x68, 0xfb, 0x29, 0x25, 0x3c, 0x62, 0xc9, - 0x28, 0x20, 0x9c, 0x5a, 0xf5, 0xaa, 0x78, 0xf7, 0x2f, 0x43, 0x86, 0x6a, 0xad, 0x83, 0x5e, 0x59, - 0xf5, 0x57, 0x0e, 0x6f, 0x26, 0x16, 0x39, 0xec, 0xc8, 0x0d, 0xfc, 0x19, 0x46, 0x17, 0xdf, 0xa1, - 0x8e, 0x5b, 0x2a, 0x76, 0x46, 0x38, 0xed, 0x1b, 0x1f, 0x97, 0x50, 0xbb, 0x5c, 0x42, 0x0d, 0x7d, - 0xd1, 0xc1, 0xc1, 0xd9, 0x90, 0x84, 0xc3, 0x94, 0x24, 0xd9, 0x98, 0xa6, 0x98, 0xbe, 0x9f, 0xd1, - 0x8c, 0x9b, 0x27, 0xa0, 0x5d, 0xba, 0x38, 0xe2, 0x6c, 0xc4, 0x53, 0x12, 0xa8, 0x27, 0x61, 0x6d, - 0x9b, 0xdc, 0x90, 0x11, 0x6e, 0x96, 0xe7, 0x21, 0x1b, 0x96, 0x27, 0xf3, 0x09, 0xa8, 0x67, 0x34, - 0x09, 0x36, 0xaf, 0xe3, 0x6e, 0x91, 0xc3, 0xb6, 0x48, 0x13, 0x71, 0x84, 0x25, 0x60, 0xba, 0xc0, - 0x48, 0xa9, 0x4f, 0xa3, 0xf9, 0x66, 0x4f, 0x07, 0x5b, 0xbf, 0x94, 0x82, 0xf0, 0x06, 0xda, 0x3e, - 0xa8, 0xc1, 0x8b, 0xab, 0x95, 0xad, 0x5f, 0xaf, 0x6c, 0xfd, 0xc7, 0xca, 0xd6, 0x2f, 0xd6, 0xb6, - 0x76, 0xbd, 0xb6, 0xb5, 0x6f, 0x6b, 0x5b, 0x7b, 0xed, 0x84, 0x11, 0x7f, 0x33, 0xf3, 0x1c, 0x9f, - 0xc5, 0xae, 0xd8, 0xd1, 0xf1, 0x84, 0x78, 0x99, 0xfc, 0x76, 0x3f, 0x6c, 0xff, 0x4d, 0xbe, 0x98, - 0xd2, 0xcc, 0xab, 0x57, 0x26, 0x3f, 0xff, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x04, 0x0a, 0xe9, 0x93, - 0xbb, 0x03, 0x00, 0x00, + // 599 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x94, 0xbf, 0x6e, 0xd4, 0x4e, + 0x10, 0xc7, 0xcf, 0xbf, 0xcb, 0x1f, 0xff, 0xf6, 0xf2, 0x07, 0x36, 0x27, 0xc5, 0xa4, 0xf0, 0x86, + 0x05, 0xa1, 0x20, 0x25, 0xb6, 0x12, 0xba, 0x28, 0x4d, 0xac, 0x14, 0xd0, 0xa0, 0x68, 0x75, 0xa2, + 0xa0, 0x39, 0xad, 0xed, 0x8d, 0x31, 0x9c, 0xbd, 0xc6, 0xbb, 0x17, 0x71, 0x6f, 0x40, 0x19, 0x51, + 0xa5, 0xbc, 0x87, 0xa0, 0xe1, 0x0d, 0x22, 0xaa, 0x94, 0x54, 0x06, 0xe5, 0x1a, 0x44, 0xe9, 0x27, + 0x40, 0xf6, 0xae, 0xef, 0x92, 0x90, 0x74, 0x3b, 0xf3, 0xfd, 0xcc, 0xcc, 0xce, 0xcc, 0x6a, 0xc1, + 0xd3, 0x90, 0x89, 0x84, 0x0b, 0x37, 0xcb, 0xf9, 0x49, 0x3c, 0x60, 0xc2, 0x3d, 0xdd, 0xf5, 0x99, + 0xa4, 0xbb, 0x6e, 0xc2, 0x43, 0x36, 0x10, 0x4e, 0x96, 0x73, 0xc9, 0xe1, 0xba, 0xa2, 0x9c, 0x86, + 0x72, 0x34, 0xb5, 0xd1, 0x8d, 0x78, 0xc4, 0x6b, 0xc6, 0xad, 0x4e, 0x0a, 0xdf, 0x78, 0x14, 0x71, + 0x1e, 0x0d, 0x98, 0x5b, 0x5b, 0xfe, 0xf0, 0xc4, 0xa5, 0xe9, 0x48, 0x4b, 0xe8, 0xb6, 0x24, 0xe3, + 0x84, 0x09, 0x49, 0x93, 0xac, 0x89, 0x0d, 0x78, 0x55, 0xaa, 0xaf, 0x92, 0x2a, 0x43, 0x49, 0xf8, + 0x3d, 0x30, 0x8f, 0xe3, 0x40, 0x0e, 0x73, 0x26, 0xe0, 0x36, 0x58, 0xd4, 0x97, 0xb1, 0x8c, 0x4d, + 0x63, 0xeb, 0x7f, 0x0f, 0x96, 0x05, 0x5a, 0x19, 0xd1, 0x64, 0xb0, 0x8f, 0xb5, 0x80, 0x49, 0x83, + 0xc0, 0x67, 0x60, 0x3e, 0xe0, 0xa7, 0x2c, 0xb7, 0xfe, 0xab, 0xd9, 0x07, 0x65, 0x81, 0x96, 0x14, + 0x5b, 0xbb, 0x31, 0x51, 0xf2, 0xbe, 0x79, 0x3e, 0x46, 0xc6, 0xef, 0x31, 0x32, 0xf0, 0x97, 0x36, + 0x58, 0x3c, 0xd6, 0xd1, 0x07, 0x60, 0x91, 0x06, 0x01, 0x1f, 0xa6, 0xb2, 0xae, 0xd5, 0xd9, 0xeb, + 0x3a, 0xaa, 0x0b, 0xa7, 0xe9, 0xc2, 0x39, 0x4c, 0x47, 0xde, 0xd2, 0xf7, 0xaf, 0x3b, 0xe6, 0xa1, + 0x02, 0x5f, 0x91, 0x26, 0x04, 0x3e, 0x01, 0x73, 0xa1, 0xa4, 0x91, 0x2e, 0xbd, 0x5a, 0x16, 0xa8, + 0xa3, 0x4a, 0x57, 0x5e, 0x4c, 0x6a, 0xb1, 0x6a, 0x27, 0xe1, 0x69, 0xfc, 0x81, 0xe5, 0x56, 0xfb, + 0x76, 0x3b, 0x5a, 0xc0, 0xa4, 0x41, 0xe0, 0x26, 0x68, 0xfb, 0x31, 0xb7, 0xe6, 0x6a, 0x72, 0xa5, + 0x2c, 0x10, 0x50, 0xa4, 0x1f, 0x73, 0x4c, 0x2a, 0x09, 0xbe, 0x01, 0x66, 0xa6, 0x47, 0x65, 0xcd, + 0xd7, 0x77, 0x7e, 0xec, 0xdc, 0xb3, 0x43, 0xa7, 0x99, 0xa9, 0xb7, 0x7e, 0x51, 0xa0, 0x56, 0x59, + 0xa0, 0x55, 0x3d, 0x46, 0xed, 0xc7, 0x64, 0x9a, 0x0b, 0xe6, 0x60, 0x39, 0xc8, 0x19, 0x95, 0x31, + 0x4f, 0xfb, 0x21, 0x95, 0xcc, 0x5a, 0xa8, 0x93, 0x6f, 0xfc, 0x33, 0x90, 0x5e, 0xb3, 0x56, 0x6f, + 0xb7, 0xca, 0xfa, 0xa7, 0x40, 0x37, 0x03, 0xcb, 0x02, 0x75, 0xf5, 0x06, 0xae, 0xbb, 0xf1, 0xd9, + 0x4f, 0x64, 0x90, 0xa5, 0xc6, 0x77, 0x44, 0x25, 0xdb, 0x37, 0x3f, 0x8f, 0x51, 0xeb, 0x7c, 0x8c, + 0x5a, 0xf8, 0x9b, 0x01, 0xd6, 0x8e, 0x7a, 0x34, 0xea, 0xe5, 0x34, 0x15, 0x27, 0x2c, 0x27, 0xec, + 0xe3, 0x90, 0x09, 0x09, 0x0f, 0xc0, 0x72, 0x35, 0xc5, 0xbe, 0xe4, 0x7d, 0x99, 0xd3, 0xb0, 0x79, + 0x12, 0xd6, 0xac, 0xc8, 0x0d, 0x19, 0x93, 0x4e, 0x65, 0xf7, 0x78, 0xaf, 0xb2, 0xe0, 0x73, 0xb0, + 0x20, 0x58, 0x1a, 0x4e, 0x5f, 0xc7, 0xc3, 0xb2, 0x40, 0xcb, 0x2a, 0x4c, 0xf9, 0x31, 0xd1, 0x00, + 0x74, 0x81, 0x99, 0xb3, 0x80, 0xc5, 0xa7, 0xd3, 0x3d, 0xad, 0xcd, 0xe6, 0xd5, 0x28, 0x98, 0x4c, + 0xa1, 0x6b, 0x0f, 0x2a, 0x03, 0xdd, 0x3b, 0xae, 0x2e, 0xe0, 0xeb, 0x2a, 0xa5, 0x3a, 0x5b, 0xc6, + 0x66, 0x7b, 0xab, 0xb3, 0xb7, 0x7d, 0xef, 0xa6, 0xee, 0x48, 0xe0, 0xcd, 0x55, 0xe3, 0x25, 0xd3, + 0x1c, 0xb3, 0x8a, 0xde, 0xcb, 0x8b, 0x2b, 0xdb, 0xb8, 0xbc, 0xb2, 0x8d, 0x5f, 0x57, 0xb6, 0x71, + 0x36, 0xb1, 0x5b, 0x97, 0x13, 0xbb, 0xf5, 0x63, 0x62, 0xb7, 0xde, 0x3a, 0x51, 0x2c, 0xdf, 0x0d, + 0x7d, 0x27, 0xe0, 0x89, 0xab, 0x6a, 0xed, 0x0c, 0xa8, 0x2f, 0xf4, 0xd9, 0xfd, 0x34, 0xfb, 0x0d, + 0xe4, 0x28, 0x63, 0xc2, 0x5f, 0xa8, 0xd7, 0xfa, 0xe2, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xb3, + 0xc1, 0x58, 0x65, 0x2d, 0x04, 0x00, 0x00, } func (this *Pictures) Equal(that interface{}) bool { @@ -293,6 +341,35 @@ func (this *DTagTransferRequest) Equal(that interface{}) bool { } return true } +func (this *DTagTransferRequests) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*DTagTransferRequests) + if !ok { + that2, ok := that.(DTagTransferRequests) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.Requests) != len(that1.Requests) { + return false + } + for i := range this.Requests { + if !this.Requests[i].Equal(&that1.Requests[i]) { + return false + } + } + return true +} func (m *Pictures) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -448,6 +525,43 @@ func (m *DTagTransferRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *DTagTransferRequests) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *DTagTransferRequests) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DTagTransferRequests) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Requests) > 0 { + for iNdEx := len(m.Requests) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Requests[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintModels(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + func encodeVarintModels(dAtA []byte, offset int, v uint64) int { offset -= sovModels(v) base := offset @@ -526,6 +640,21 @@ func (m *DTagTransferRequest) Size() (n int) { return n } +func (m *DTagTransferRequests) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Requests) > 0 { + for _, e := range m.Requests { + l = e.Size() + n += 1 + l + sovModels(uint64(l)) + } + } + return n +} + func sovModels(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1040,6 +1169,90 @@ func (m *DTagTransferRequest) Unmarshal(dAtA []byte) error { } return nil } +func (m *DTagTransferRequests) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModels + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: DTagTransferRequests: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DTagTransferRequests: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Requests", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModels + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthModels + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthModels + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Requests = append(m.Requests, DTagTransferRequest{}) + if err := m.Requests[len(m.Requests)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipModels(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthModels + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipModels(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/staging/fees/ante/ante_test.go b/x/staging/fees/ante/ante_test.go index e6f7bb2aa4..afa64c2d61 100644 --- a/x/staging/fees/ante/ante_test.go +++ b/x/staging/fees/ante/ante_test.go @@ -3,8 +3,8 @@ package ante_test import ( "time" - feestypes "github.com/desmos-labs/desmos/x/fees/types" - "github.com/desmos-labs/desmos/x/posts/types" + feestypes "github.com/desmos-labs/desmos/x/staging/fees/types" + poststypes "github.com/desmos-labs/desmos/x/staging/posts/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -32,20 +32,20 @@ func (suite *AnteTestSuite) TestAnteHandlerFees_MsgCreatePost() { feestypes.NewMinFee("create_post", sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10000)))), }), msgs: []sdk.Msg{ - types.NewMsgCreatePost( + poststypes.NewMsgCreatePost( "My new post", "dd065b70feb810a8c6f535cf670fe6e3534085221fa964ed2660ebca93f910d1", false, "4e188d9c17150037d5199bbdb91ae1eb2a78a15aca04cb35530cccb81494b36e", nil, account.acc.GetAddress().String(), - types.NewAttachments(types.NewAttachment("https://uri.com", "text/plain", nil)), - types.NewPollData( + poststypes.NewAttachments(poststypes.NewAttachment("https://uri.com", "text/plain", nil)), + poststypes.NewPollData( "poll?", time.Date(2050, 1, 1, 15, 15, 00, 000, time.UTC), - types.NewPollAnswers( - types.NewPollAnswer("1", "Yes"), - types.NewPollAnswer("2", "No"), + poststypes.NewPollAnswers( + poststypes.NewPollAnswer("1", "Yes"), + poststypes.NewPollAnswer("2", "No"), ), false, true, @@ -65,20 +65,20 @@ func (suite *AnteTestSuite) TestAnteHandlerFees_MsgCreatePost() { feestypes.NewMinFee("create_post", sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10000)))), }), msgs: []sdk.Msg{ - types.NewMsgCreatePost( + poststypes.NewMsgCreatePost( "My new post", "dd065b70feb810a8c6f535cf670fe6e3534085221fa964ed2660ebca93f910d1", false, "4e188d9c17150037d5199bbdb91ae1eb2a78a15aca04cb35530cccb81494b36e", nil, account.acc.GetAddress().String(), - types.NewAttachments(types.NewAttachment("https://uri.com", "text/plain", nil)), - types.NewPollData( + poststypes.NewAttachments(poststypes.NewAttachment("https://uri.com", "text/plain", nil)), + poststypes.NewPollData( "poll?", time.Date(2050, 1, 1, 15, 15, 00, 000, time.UTC), - types.NewPollAnswers( - types.NewPollAnswer("1", "Yes"), - types.NewPollAnswer("2", "No"), + poststypes.NewPollAnswers( + poststypes.NewPollAnswer("1", "Yes"), + poststypes.NewPollAnswer("2", "No"), ), false, true, @@ -98,20 +98,20 @@ func (suite *AnteTestSuite) TestAnteHandlerFees_MsgCreatePost() { feestypes.NewMinFee("create_post", sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10000)))), }), msgs: []sdk.Msg{ - types.NewMsgCreatePost( + poststypes.NewMsgCreatePost( "My new post", "dd065b70feb810a8c6f535cf670fe6e3534085221fa964ed2660ebca93f910d1", false, "4e188d9c17150037d5199bbdb91ae1eb2a78a15aca04cb35530cccb81494b36e", nil, account.acc.GetAddress().String(), - types.NewAttachments(types.NewAttachment("https://uri.com", "text/plain", nil)), - types.NewPollData( + poststypes.NewAttachments(poststypes.NewAttachment("https://uri.com", "text/plain", nil)), + poststypes.NewPollData( "poll?", time.Date(2050, 1, 1, 15, 15, 00, 000, time.UTC), - types.NewPollAnswers( - types.NewPollAnswer("1", "Yes"), - types.NewPollAnswer("2", "No"), + poststypes.NewPollAnswers( + poststypes.NewPollAnswer("1", "Yes"), + poststypes.NewPollAnswer("2", "No"), ), false, true, diff --git a/x/staging/fees/ante/common_test.go b/x/staging/fees/ante/common_test.go index 91cfd53c8f..3b2416a3b4 100644 --- a/x/staging/fees/ante/common_test.go +++ b/x/staging/fees/ante/common_test.go @@ -20,8 +20,8 @@ import ( dbm "github.com/tendermint/tm-db" desmos "github.com/desmos-labs/desmos/app" - "github.com/desmos-labs/desmos/x/fees/ante" - feestypes "github.com/desmos-labs/desmos/x/fees/types" + "github.com/desmos-labs/desmos/x/staging/fees/ante" + feestypes "github.com/desmos-labs/desmos/x/staging/fees/types" ) // TestAccount represents an account used in the ante handler tests diff --git a/x/staging/fees/simulation/genesis.go b/x/staging/fees/simulation/genesis.go index 3f5b97f4b7..3792461db5 100644 --- a/x/staging/fees/simulation/genesis.go +++ b/x/staging/fees/simulation/genesis.go @@ -7,17 +7,16 @@ import ( "fmt" "math/rand" - magpietypes "github.com/desmos-labs/desmos/x/magpie/types" - poststypes "github.com/desmos-labs/desmos/x/posts/types" profilestypes "github.com/desmos-labs/desmos/x/profiles/types" - relationshipstypes "github.com/desmos-labs/desmos/x/relationships/types" - reportstypes "github.com/desmos-labs/desmos/x/reports/types" + poststypes "github.com/desmos-labs/desmos/x/staging/posts/types" + relationshipstypes "github.com/desmos-labs/desmos/x/staging/relationships/types" + reportstypes "github.com/desmos-labs/desmos/x/staging/reports/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/desmos-labs/desmos/x/fees/types" + "github.com/desmos-labs/desmos/x/staging/fees/types" ) const ( @@ -25,7 +24,6 @@ const ( ) var msgsTypes = []string{ - magpietypes.ActionCreationSession, poststypes.ActionCreatePost, poststypes.ActionEditPost, poststypes.ActionAnswerPoll, diff --git a/x/staging/posts/types/polls.pb.go b/x/staging/posts/types/polls.pb.go index 1aec3ece53..450ed80ca0 100644 --- a/x/staging/posts/types/polls.pb.go +++ b/x/staging/posts/types/polls.pb.go @@ -8,7 +8,7 @@ import ( _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" - _ "github.com/golang/protobuf/ptypes/timestamp" + _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" math_bits "math/bits" diff --git a/x/staging/posts/types/posts.pb.go b/x/staging/posts/types/posts.pb.go index ce89cdbfe2..bdd898ad46 100644 --- a/x/staging/posts/types/posts.pb.go +++ b/x/staging/posts/types/posts.pb.go @@ -8,7 +8,7 @@ import ( _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" - _ "github.com/golang/protobuf/ptypes/timestamp" + _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" math_bits "math/bits" diff --git a/x/staging/posts/types/query.pb.go b/x/staging/posts/types/query.pb.go index e35e40416c..53c591523d 100644 --- a/x/staging/posts/types/query.pb.go +++ b/x/staging/posts/types/query.pb.go @@ -11,11 +11,11 @@ import ( grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" - _ "github.com/golang/protobuf/ptypes/timestamp" _ "google.golang.org/genproto/googleapis/api/annotations" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" + _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" math_bits "math/bits" diff --git a/x/staging/reports/types/models.go b/x/staging/reports/types/models.go index 1702aeb756..9bc3ed03ad 100644 --- a/x/staging/reports/types/models.go +++ b/x/staging/reports/types/models.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" - poststypes "github.com/desmos-labs/desmos/x/posts/types" + poststypes "github.com/desmos-labs/desmos/x/staging/posts/types" ) // NewReport returns a Report From e94436ac539e3a7733ad6cfcbd75d58b620c6122 Mon Sep 17 00:00:00 2001 From: "riccardo.montagnin" Date: Tue, 13 Apr 2021 11:58:59 +0200 Subject: [PATCH 09/11] Fixed simulation tests Signed-off-by: riccardo.montagnin --- Makefile | 4 +- go.mod | 2 + go.sum | 4 +- scripts/protocgen.sh | 8 +--- third_party/proto/tendermint/abci/types.proto | 2 +- x/profiles/keeper/keeper.go | 5 ++- x/profiles/keeper/keeper_test.go | 43 +++++++++++++++++++ .../simulation/operations_dtag_transfer.go | 18 ++++++-- x/profiles/types/keys.go | 2 +- x/profiles/types/query.go | 15 +++++++ x/staging/posts/keeper/keeper_polls.go | 3 +- 11 files changed, 87 insertions(+), 19 deletions(-) create mode 100644 x/profiles/types/query.go diff --git a/Makefile b/Makefile index b5988ff74d..9aa793735a 100644 --- a/Makefile +++ b/Makefile @@ -295,9 +295,9 @@ proto-lint: proto-check-breaking: @$(DOCKER_BUF) check breaking --against $(HTTPS_GIT)#branch=master -TM_URL = https://raw.githubusercontent.com/tendermint/tendermint/v0.34.8/proto/tendermint +TM_URL = https://raw.githubusercontent.com/tendermint/tendermint/v0.34.9/proto/tendermint GOGO_PROTO_URL = https://raw.githubusercontent.com/regen-network/protobuf/cosmos -COSMOS_URL = https://raw.githubusercontent.com/cosmos/cosmos-sdk/v0.42.3/proto/cosmos +COSMOS_URL = https://raw.githubusercontent.com/cosmos/cosmos-sdk/v0.42.4/proto/cosmos COSMOS_PROTO_URL = https://raw.githubusercontent.com/regen-network/cosmos-proto/master CONFIO_URL = https://raw.githubusercontent.com/confio/ics23/v0.6.3 diff --git a/go.mod b/go.mod index 0d47b5c2f2..88f9d5c7eb 100644 --- a/go.mod +++ b/go.mod @@ -24,3 +24,5 @@ require ( ) replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 + +replace github.com/cosmos/cosmos-sdk => github.com/RiccardoM/cosmos-sdk v0.40.2-0.20210413061315-e274652f0ed8 diff --git a/go.sum b/go.sum index 8ac4941bfd..923c273f21 100644 --- a/go.sum +++ b/go.sum @@ -26,6 +26,8 @@ github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= +github.com/RiccardoM/cosmos-sdk v0.40.2-0.20210413061315-e274652f0ed8 h1:G7H3ueYhTqqxP9HCJOEx2m4yjBMG/olrR08Um39hnsY= +github.com/RiccardoM/cosmos-sdk v0.40.2-0.20210413061315-e274652f0ed8/go.mod h1:I1Zw1zmU4rA/NITaakTb71pXQnQrWyFBhqo3WSeg0vA= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/VividCortex/gohistogram v1.0.0 h1:6+hBz+qvs0JOrrNhhmR7lFxo5sINxBCGXrdtl/UvroE= @@ -104,8 +106,6 @@ github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7 github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cosmos/cosmos-sdk v0.42.4 h1:yaD4PyOx0LnyfiWasC5egg1U76lT83GRxjJjupPo7Gk= -github.com/cosmos/cosmos-sdk v0.42.4/go.mod h1:I1Zw1zmU4rA/NITaakTb71pXQnQrWyFBhqo3WSeg0vA= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= diff --git a/scripts/protocgen.sh b/scripts/protocgen.sh index e4edd4fbf9..63e5c096c6 100755 --- a/scripts/protocgen.sh +++ b/scripts/protocgen.sh @@ -8,7 +8,7 @@ protoc_gen_gocosmos() { return 1 fi - go get github.com/regen-network/cosmos-proto/protoc-gen-gocosmos 2>/dev/null + go get github.com/regen-network/cosmos-proto/protoc-gen-gocosmos@latest 2>/dev/null } protoc_gen_gocosmos @@ -20,12 +20,6 @@ for dir in $proto_dirs; do -I "third_party/proto" \ --gocosmos_out=plugins=interfacetype+grpc,\ Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:. \ - $(find "${dir}" -maxdepth 1 -name '*.proto') - - # command to generate gRPC gateway (*.pb.gw.go in respective modules) files - buf protoc \ - -I "proto" \ - -I "third_party/proto" \ --grpc-gateway_out=logtostderr=true:. \ $(find "${dir}" -maxdepth 1 -name '*.proto') diff --git a/third_party/proto/tendermint/abci/types.proto b/third_party/proto/tendermint/abci/types.proto index d4978db33e..53a2446111 100644 --- a/third_party/proto/tendermint/abci/types.proto +++ b/third_party/proto/tendermint/abci/types.proto @@ -222,7 +222,7 @@ message ResponseDeliverTx { int64 gas_wanted = 5 [json_name = "gas_wanted"]; int64 gas_used = 6 [json_name = "gas_used"]; repeated Event events = 7 - [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"]; + [(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"]; // nondeterministic string codespace = 8; } diff --git a/x/profiles/keeper/keeper.go b/x/profiles/keeper/keeper.go index aab3778fef..d62661ce5c 100644 --- a/x/profiles/keeper/keeper.go +++ b/x/profiles/keeper/keeper.go @@ -68,12 +68,12 @@ func (k Keeper) StoreProfile(ctx sdk.Context, profile *types.Profile) error { store := ctx.KVStore(k.storeKey) - // Remove the previous DTag association (if the profile is being edited) + // Remove the previous DTag association (if the DTag has changed) oldProfile, found, err := k.GetProfile(ctx, profile.GetAddress().String()) if err != nil { return err } - if found { + if found && oldProfile.Dtag != profile.Dtag { store.Delete(types.DTagStoreKey(oldProfile.Dtag)) } @@ -213,6 +213,7 @@ func (k Keeper) GetUserIncomingDTagTransferRequests(ctx sdk.Context, user string func (k Keeper) GetDTagTransferRequests(ctx sdk.Context) (requests []types.DTagTransferRequest) { store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, types.DTagTransferRequestsPrefix) + defer iterator.Close() for ; iterator.Valid(); iterator.Next() { var userRequests types.DTagTransferRequests diff --git a/x/profiles/keeper/keeper_test.go b/x/profiles/keeper/keeper_test.go index a19eb36d2f..231b6c4932 100644 --- a/x/profiles/keeper/keeper_test.go +++ b/x/profiles/keeper/keeper_test.go @@ -139,6 +139,49 @@ func (suite *KeeperTestSuite) TestKeeper_StoreProfile() { } } +func (suite *KeeperTestSuite) TestKeeper_StoreProfile_Update() { + // Store the initial profile + suite.Require().NoError(suite.k.StoreProfile(suite.ctx, suite.testData.profile)) + + // Verify the store keys + store := suite.ctx.KVStore(suite.storeKey) + suite.Require().Equal( + suite.testData.profile.GetAddress().String(), + sdk.AccAddress(store.Get(types.DTagStoreKey(suite.testData.profile.Dtag))).String(), + ) + + oldAccounts := suite.ak.GetAllAccounts(suite.ctx) + suite.Require().Len(oldAccounts, 1) + + // Update the profile + updatedProfile, err := types.NewProfile( + suite.testData.profile.Dtag+"-update", + "", + "", + types.NewPictures("", ""), + suite.testData.profile.CreationDate, + suite.ak.GetAccount(suite.ctx, suite.testData.profile.GetAddress()), + ) + suite.Require().NoError(err) + suite.Require().NoError(suite.k.StoreProfile(suite.ctx, updatedProfile)) + + // Verify the store keys + suite.Require().Nil( + store.Get(types.DTagStoreKey(suite.testData.profile.Dtag)), + ) + suite.Require().Equal( + suite.testData.profile.GetAddress().String(), + sdk.AccAddress(store.Get(types.DTagStoreKey(suite.testData.profile.Dtag+"-update"))).String(), + ) + + newAccounts := suite.ak.GetAllAccounts(suite.ctx) + suite.Require().Len(newAccounts, 1) + + for _, account := range newAccounts { + suite.Require().NotContains(oldAccounts, account) + } +} + func (suite *KeeperTestSuite) TestKeeper_GetProfile() { tests := []struct { name string diff --git a/x/profiles/simulation/operations_dtag_transfer.go b/x/profiles/simulation/operations_dtag_transfer.go index 5fd03eeac2..136ebb0bb6 100644 --- a/x/profiles/simulation/operations_dtag_transfer.go +++ b/x/profiles/simulation/operations_dtag_transfer.go @@ -99,23 +99,35 @@ func randomDtagRequestTransferFields( return simtypes.Account{}, types.DTagTransferRequest{}, true } + // Skip if the receiver is blocked if k.IsUserBlocked(ctx, receiver.Address.String(), sender.Address.String()) { return simtypes.Account{}, types.DTagTransferRequest{}, true } randomDTag := RandomDTag(r) - profile, err := types.NewProfile( + + // Get the current auth account of the receiver. + // If the receiver already has a profile, we need to first extract the auth account from it. This is done in order + // to avoid later storing a Profile that contains a Profile inside itself (which would cause later bugs in the + // export/import process) + account := ak.GetAccount(ctx, receiver.Address) + if customProfile, ok := account.(*types.Profile); ok { + account = customProfile.GetAccount() + } + + // Create the receiver profile + receiverProfile, err := types.NewProfile( randomDTag, "", "", types.NewPictures("", ""), ctx.BlockTime(), - ak.GetAccount(ctx, receiver.Address), + account, ) if err != nil { return simtypes.Account{}, types.DTagTransferRequest{}, true } - _ = k.StoreProfile(ctx, profile) + _ = k.StoreProfile(ctx, receiverProfile) // Create a request req := types.NewDTagTransferRequest(randomDTag, sender.Address.String(), receiver.Address.String()) diff --git a/x/profiles/types/keys.go b/x/profiles/types/keys.go index e1cad977cb..5d11e77ef0 100644 --- a/x/profiles/types/keys.go +++ b/x/profiles/types/keys.go @@ -29,7 +29,7 @@ var ( // DTagStoreKey turns a DTag into the key used to store the address associated with it into the store func DTagStoreKey(dtag string) []byte { - return append(DTagPrefix, dtag...) + return append(DTagPrefix, []byte(dtag)...) } // DtagTransferRequestStoreKey turns an address to a key used to store a transfer request into the profiles store diff --git a/x/profiles/types/query.go b/x/profiles/types/query.go new file mode 100644 index 0000000000..eb1599d64b --- /dev/null +++ b/x/profiles/types/query.go @@ -0,0 +1,15 @@ +package types + +import ( + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +// UnpackInterfaces implements codectypes.UnpackInterfacesMessage +func (r *QueryProfileResponse) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + if r.Profile != nil { + var profile authtypes.AccountI + return unpacker.UnpackAny(r.Profile, &profile) + } + return nil +} diff --git a/x/staging/posts/keeper/keeper_polls.go b/x/staging/posts/keeper/keeper_polls.go index bd138310bd..de93908ad0 100644 --- a/x/staging/posts/keeper/keeper_polls.go +++ b/x/staging/posts/keeper/keeper_polls.go @@ -32,10 +32,11 @@ func (k Keeper) GetPollAnswers(ctx sdk.Context, postID string) []types.UserAnswe return types.MustUnmarshalUserAnswers(k.cdc, store.Get(types.PollAnswersStoreKey(postID))) } -// GetUserPollAnswersEntries allows to returns the list of answers that have been stored inside the given context +// GetUserAnswersEntries allows to returns the list of answers that have been stored inside the given context func (k Keeper) GetUserAnswersEntries(ctx sdk.Context) []types.UserAnswersEntry { store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, types.PollAnswersStorePrefix) + defer iterator.Close() var usersAnswersData []types.UserAnswersEntry for ; iterator.Valid(); iterator.Next() { From fbd4794eaf4b3685ca8706a880c5aa0a132f137b Mon Sep 17 00:00:00 2001 From: "riccardo.montagnin" Date: Wed, 14 Apr 2021 09:14:32 +0200 Subject: [PATCH 10/11] Added missing test coverage Signed-off-by: riccardo.montagnin --- proto/desmos/profiles/v1beta1/query.proto | 7 +- x/profiles/keeper/genesis_test.go | 186 ++++++++++++++++++++++ x/profiles/keeper/grpc_query.go | 7 +- x/profiles/keeper/grpc_query_test.go | 164 +++++++++++++++++++ x/profiles/types/params.go | 6 +- x/profiles/types/query.go | 14 ++ x/profiles/types/query.pb.go | 8 +- 7 files changed, 377 insertions(+), 15 deletions(-) create mode 100644 x/profiles/keeper/genesis_test.go create mode 100644 x/profiles/keeper/grpc_query_test.go diff --git a/proto/desmos/profiles/v1beta1/query.proto b/proto/desmos/profiles/v1beta1/query.proto index 67c0f8d961..51420b5302 100644 --- a/proto/desmos/profiles/v1beta1/query.proto +++ b/proto/desmos/profiles/v1beta1/query.proto @@ -12,14 +12,13 @@ option go_package = "github.com/desmos-labs/desmos/x/profiles/types"; // Query defines the gRPC querier service. service Query { - // Profile queries the profile of a specific user + // Profile queries the profile of a specific user given their DTag or address rpc Profile(QueryProfileRequest) returns (QueryProfileResponse) { option (google.api.http).get = "/desmos/profiles/v1beta1/profiles/{user}"; } - // DTagTransfers queries all the DTag transfers requests - rpc DTagTransfers(QueryDTagTransfersRequest) - returns (QueryDTagTransfersResponse) { + // DTagTransfers queries all the DTag transfers requests that have been made towards the user with the given address + rpc DTagTransfers(QueryDTagTransfersRequest) returns (QueryDTagTransfersResponse) { option (google.api.http).get = "/desmos/profiles/v1beta1/dtag_transfers"; } diff --git a/x/profiles/keeper/genesis_test.go b/x/profiles/keeper/genesis_test.go new file mode 100644 index 0000000000..0bae05392b --- /dev/null +++ b/x/profiles/keeper/genesis_test.go @@ -0,0 +1,186 @@ +package keeper_test + +import ( + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + + "github.com/desmos-labs/desmos/x/profiles/types" +) + +func (suite *KeeperTestSuite) Test_ExportGenesis() { + usecases := []struct { + name string + state struct { + DTagRequests []types.DTagTransferRequest + Params types.Params + } + expGenesis *types.GenesisState + }{ + { + name: "empty state", + state: struct { + DTagRequests []types.DTagTransferRequest + Params types.Params + }{ + DTagRequests: nil, + Params: types.DefaultParams(), + }, + expGenesis: types.NewGenesisState(nil, types.DefaultParams()), + }, + { + name: "non-empty state", + state: struct { + DTagRequests []types.DTagTransferRequest + Params types.Params + }{ + DTagRequests: []types.DTagTransferRequest{ + types.NewDTagTransferRequest("dtag-1", "sender-1", "receiver-1"), + types.NewDTagTransferRequest("dtag-2", "sender-2", "receiver-2"), + }, + Params: types.NewParams( + types.NewMonikerParams(sdk.NewInt(100), sdk.NewInt(200)), + types.NewDtagParams("regex", sdk.NewInt(100), sdk.NewInt(200)), + sdk.NewInt(1000), + ), + }, + expGenesis: types.NewGenesisState( + []types.DTagTransferRequest{ + types.NewDTagTransferRequest("dtag-1", "sender-1", "receiver-1"), + types.NewDTagTransferRequest("dtag-2", "sender-2", "receiver-2"), + }, + types.NewParams( + types.NewMonikerParams(sdk.NewInt(100), sdk.NewInt(200)), + types.NewDtagParams("regex", sdk.NewInt(100), sdk.NewInt(200)), + sdk.NewInt(1000), + ), + ), + }, + } + + for _, uc := range usecases { + uc := uc + suite.Run(uc.name, func() { + suite.SetupTest() + + for _, req := range uc.state.DTagRequests { + suite.Require().NoError(suite.k.SaveDTagTransferRequest(suite.ctx, req)) + } + suite.k.SetParams(suite.ctx, uc.state.Params) + + exported := suite.k.ExportGenesis(suite.ctx) + suite.Require().Equal(uc.expGenesis, exported) + }) + } +} + +func (suite *KeeperTestSuite) Test_InitGenesis() { + addr1, err := sdk.AccAddressFromBech32("cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47") + suite.Require().NoError(err) + + addr2, err := sdk.AccAddressFromBech32("cosmos1cjf97gpzwmaf30pzvaargfgr884mpp5ak8f7ns") + suite.Require().NoError(err) + + addr3, err := sdk.AccAddressFromBech32("cosmos1s3nh6tafl4amaxkke9kdejhp09lk93g9ev39r4") + suite.Require().NoError(err) + + profile1, err := types.NewProfile( + "dtag-1", + "moniker-1", + "bio-1", + types.NewPictures("profile-1", "cover-1"), + time.Date(2020, 1, 1, 00, 00, 00, 000, time.UTC), + authtypes.NewBaseAccountWithAddress(addr1), + ) + suite.Require().NoError(err) + + profile2, err := types.NewProfile( + "dtag-2", + "moniker-2", + "bio-2", + types.NewPictures("profile-2", "cover-2"), + time.Date(2020, 1, 2, 00, 00, 00, 000, time.UTC), + authtypes.NewBaseAccountWithAddress(addr2), + ) + suite.Require().NoError(err) + + usecases := []struct { + name string + authAccounts []authtypes.AccountI + genesis *types.GenesisState + expState struct { + profiles []*types.Profile + dTagTransferRequests []types.DTagTransferRequest + params types.Params + } + }{ + { + name: "empty genesis", + genesis: types.NewGenesisState(nil, types.DefaultParams()), + expState: struct { + profiles []*types.Profile + dTagTransferRequests []types.DTagTransferRequest + params types.Params + }{ + profiles: nil, + dTagTransferRequests: nil, + params: types.DefaultParams(), + }, + }, + { + name: "non-empty genesis", + authAccounts: []authtypes.AccountI{ + profile1, + profile2, + authtypes.NewBaseAccountWithAddress(addr3), + }, + genesis: types.NewGenesisState( + []types.DTagTransferRequest{ + types.NewDTagTransferRequest("dtag-1", "sender-1", "receiver-1"), + types.NewDTagTransferRequest("dtag-2", "sender-2", "receiver-2"), + }, + types.NewParams( + types.NewMonikerParams(sdk.NewInt(100), sdk.NewInt(200)), + types.NewDtagParams("regex", sdk.NewInt(100), sdk.NewInt(200)), + sdk.NewInt(1000), + ), + ), + expState: struct { + profiles []*types.Profile + dTagTransferRequests []types.DTagTransferRequest + params types.Params + }{ + profiles: []*types.Profile{ + profile1, + profile2, + }, + dTagTransferRequests: []types.DTagTransferRequest{ + types.NewDTagTransferRequest("dtag-1", "sender-1", "receiver-1"), + types.NewDTagTransferRequest("dtag-2", "sender-2", "receiver-2"), + }, + params: types.NewParams( + types.NewMonikerParams(sdk.NewInt(100), sdk.NewInt(200)), + types.NewDtagParams("regex", sdk.NewInt(100), sdk.NewInt(200)), + sdk.NewInt(1000), + ), + }, + }, + } + + for _, uc := range usecases { + uc := uc + suite.Run(uc.name, func() { + suite.SetupTest() + + for _, acc := range uc.authAccounts { + suite.ak.SetAccount(suite.ctx, acc) + } + suite.k.InitGenesis(suite.ctx, *uc.genesis) + + suite.Require().Equal(uc.expState.profiles, suite.k.GetProfiles(suite.ctx)) + suite.Require().Equal(uc.expState.dTagTransferRequests, suite.k.GetDTagTransferRequests(suite.ctx)) + suite.Require().Equal(uc.expState.params, suite.k.GetParams(suite.ctx)) + }) + } +} diff --git a/x/profiles/keeper/grpc_query.go b/x/profiles/keeper/grpc_query.go index efeb656773..bec9f0a3f1 100644 --- a/x/profiles/keeper/grpc_query.go +++ b/x/profiles/keeper/grpc_query.go @@ -14,13 +14,13 @@ import ( var _ types.QueryServer = Keeper{} -// Profiles implements the Query/Profiles gRPC method +// Profile implements the Query/Profile gRPC method func (k Keeper) Profile(ctx context.Context, request *types.QueryProfileRequest) (*types.QueryProfileResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) dTagOrAddress := request.User if strings.TrimSpace(dTagOrAddress) == "" { - return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "DTag or sdkAddress cannot be empty or blank") + return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "DTag or address cannot be empty or blank") } sdkAddress, err := sdk.AccAddressFromBech32(dTagOrAddress) @@ -43,8 +43,7 @@ func (k Keeper) Profile(ctx context.Context, request *types.QueryProfileRequest) } if !found { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, - "Profile with sdkAddress %s doesn't exists", dTagOrAddress) + return &types.QueryProfileResponse{Profile: nil}, nil } accountAny, err := codectypes.NewAnyWithValue(account) diff --git a/x/profiles/keeper/grpc_query_test.go b/x/profiles/keeper/grpc_query_test.go new file mode 100644 index 0000000000..eab468a87a --- /dev/null +++ b/x/profiles/keeper/grpc_query_test.go @@ -0,0 +1,164 @@ +package keeper_test + +import ( + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/desmos-labs/desmos/x/profiles/types" +) + +func (suite *KeeperTestSuite) codeToAny(profile *types.Profile) *codectypes.Any { + accountAny, err := codectypes.NewAnyWithValue(profile) + suite.Require().NoError(err) + return accountAny +} + +func (suite *KeeperTestSuite) Test_Profile() { + usecases := []struct { + name string + storedProfiles []*types.Profile + req *types.QueryProfileRequest + shouldErr bool + expResponse *types.QueryProfileResponse + }{ + { + name: "empty user returns error", + req: types.NewQueryProfileRequest(""), + shouldErr: true, + }, + { + name: "non existing DTag returns error", + req: types.NewQueryProfileRequest("invalid-dtag"), + shouldErr: true, + }, + { + name: "profile not found", + req: types.NewQueryProfileRequest("cosmos19mj6dkd85m84gxvf8d929w572z5h9q0u8d8wpa"), + shouldErr: false, + expResponse: &types.QueryProfileResponse{Profile: nil}, + }, + { + name: "found profile - using dtag", + storedProfiles: []*types.Profile{ + suite.testData.profile, + }, + req: types.NewQueryProfileRequest(suite.testData.profile.Dtag), + shouldErr: false, + expResponse: &types.QueryProfileResponse{ + Profile: suite.codeToAny(suite.testData.profile), + }, + }, + { + name: "found profile - using address", + storedProfiles: []*types.Profile{ + suite.testData.profile, + }, + req: types.NewQueryProfileRequest(suite.testData.profile.GetAddress().String()), + shouldErr: false, + expResponse: &types.QueryProfileResponse{ + Profile: suite.codeToAny(suite.testData.profile), + }, + }, + } + + for _, uc := range usecases { + uc := uc + suite.Run(uc.name, func() { + suite.SetupTest() + + for _, profile := range uc.storedProfiles { + suite.Require().NoError(suite.k.StoreProfile(suite.ctx, profile)) + } + + res, err := suite.k.Profile(sdk.WrapSDKContext(suite.ctx), uc.req) + + if uc.shouldErr { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + suite.Require().NotNil(res) + + suite.Require().Equal(uc.expResponse, res) + + if uc.expResponse.Profile != nil { + // Make sure the cached value is not nil (this is to grant that UnpackInterfaces work properly) + suite.Require().NotNil(res.Profile.GetCachedValue()) + } + } + }) + } +} + +func (suite *KeeperTestSuite) Test_DTagTransfers() { + usecases := []struct { + name string + storedRequests []types.DTagTransferRequest + req *types.QueryDTagTransfersRequest + shouldErr bool + expResponse *types.QueryDTagTransfersResponse + }{ + { + name: "invalid user", + req: types.NewQueryDTagTransfersRequest("invalid-address"), + shouldErr: true, + }, + { + name: "valid request", + storedRequests: []types.DTagTransferRequest{ + types.NewDTagTransferRequest( + "dtag", + "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + "cosmos19mj6dkd85m84gxvf8d929w572z5h9q0u8d8wpa", + ), + types.NewDTagTransferRequest( + "dtag-2", + "cosmos19mj6dkd85m84gxvf8d929w572z5h9q0u8d8wpa", + "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + ), + }, + req: types.NewQueryDTagTransfersRequest("cosmos19mj6dkd85m84gxvf8d929w572z5h9q0u8d8wpa"), + shouldErr: false, + expResponse: &types.QueryDTagTransfersResponse{ + Requests: []types.DTagTransferRequest{ + types.NewDTagTransferRequest( + "dtag", + "cosmos1y54exmx84cqtasvjnskf9f63djuuj68p7hqf47", + "cosmos19mj6dkd85m84gxvf8d929w572z5h9q0u8d8wpa", + ), + }, + }, + }, + } + + for _, uc := range usecases { + uc := uc + suite.Run(uc.name, func() { + suite.SetupTest() + + for _, req := range uc.storedRequests { + suite.Require().NoError(suite.k.SaveDTagTransferRequest(suite.ctx, req)) + } + + res, err := suite.k.DTagTransfers(sdk.WrapSDKContext(suite.ctx), uc.req) + + if uc.shouldErr { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + suite.Require().NotNil(res) + + suite.Require().Equal(uc.expResponse, res) + } + }) + } +} + +func (suite *KeeperTestSuite) Test_Params() { + suite.k.SetParams(suite.ctx, types.DefaultParams()) + + res, err := suite.k.Params(sdk.WrapSDKContext(suite.ctx), &types.QueryParamsRequest{}) + suite.Require().NoError(err) + suite.Require().NotNil(res) + + suite.Require().Equal(types.DefaultParams(), res.Params) +} diff --git a/x/profiles/types/params.go b/x/profiles/types/params.go index 586c037b06..dd3754037d 100644 --- a/x/profiles/types/params.go +++ b/x/profiles/types/params.go @@ -39,10 +39,10 @@ func ParamKeyTable() paramstypes.KeyTable { } // NewParams creates a new ProfileParams obj -func NewParams(monikerLen MonikerParams, dtagLen DTagParams, maxBioLen sdk.Int) Params { +func NewParams(monikerParams MonikerParams, dTagParams DTagParams, maxBioLen sdk.Int) Params { return Params{ - MonikerParams: monikerLen, - DtagParams: dtagLen, + MonikerParams: monikerParams, + DtagParams: dTagParams, MaxBioLength: maxBioLen, } } diff --git a/x/profiles/types/query.go b/x/profiles/types/query.go index eb1599d64b..0f33c8bd0b 100644 --- a/x/profiles/types/query.go +++ b/x/profiles/types/query.go @@ -5,6 +5,20 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) +// NewQueryProfileRequest returns a new QueryProfileRequest containing the given data +func NewQueryProfileRequest(user string) *QueryProfileRequest { + return &QueryProfileRequest{ + User: user, + } +} + +// NewQueryDTagTransfersRequest returns a new QueryDTagTransfersRequest containing the given data +func NewQueryDTagTransfersRequest(user string) *QueryDTagTransfersRequest { + return &QueryDTagTransfersRequest{ + User: user, + } +} + // UnpackInterfaces implements codectypes.UnpackInterfacesMessage func (r *QueryProfileResponse) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { if r.Profile != nil { diff --git a/x/profiles/types/query.pb.go b/x/profiles/types/query.pb.go index ecd732a060..96ac9c638c 100644 --- a/x/profiles/types/query.pb.go +++ b/x/profiles/types/query.pb.go @@ -346,9 +346,9 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type QueryClient interface { - // Profile queries the profile of a specific user + // Profile queries the profile of a specific user given their DTag or address Profile(ctx context.Context, in *QueryProfileRequest, opts ...grpc.CallOption) (*QueryProfileResponse, error) - // DTagTransfers queries all the DTag transfers requests + // DTagTransfers queries all the DTag transfers requests that have been made towards the user with the given address DTagTransfers(ctx context.Context, in *QueryDTagTransfersRequest, opts ...grpc.CallOption) (*QueryDTagTransfersResponse, error) // Params queries the profiles module params Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) @@ -391,9 +391,9 @@ func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts . // QueryServer is the server API for Query service. type QueryServer interface { - // Profile queries the profile of a specific user + // Profile queries the profile of a specific user given their DTag or address Profile(context.Context, *QueryProfileRequest) (*QueryProfileResponse, error) - // DTagTransfers queries all the DTag transfers requests + // DTagTransfers queries all the DTag transfers requests that have been made towards the user with the given address DTagTransfers(context.Context, *QueryDTagTransfersRequest) (*QueryDTagTransfersResponse, error) // Params queries the profiles module params Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) From 8445bc100a0c3ef945d3052d51f03993872e4838 Mon Sep 17 00:00:00 2001 From: "riccardo.montagnin" Date: Thu, 15 Apr 2021 12:33:36 +0200 Subject: [PATCH 11/11] Fixed profile tests Signed-off-by: riccardo.montagnin --- proto/desmos/profiles/v1beta1/models.proto | 3 +-- proto/desmos/profiles/v1beta1/query.proto | 10 +++++++--- x/profiles/client/cli/cli_test.go | 6 +++++- x/profiles/types/account_test.go | 13 ++++++++----- x/profiles/types/query.pb.go | 14 ++++++++++---- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/proto/desmos/profiles/v1beta1/models.proto b/proto/desmos/profiles/v1beta1/models.proto index ca871f55c2..a361a4824a 100644 --- a/proto/desmos/profiles/v1beta1/models.proto +++ b/proto/desmos/profiles/v1beta1/models.proto @@ -59,6 +59,5 @@ message DTagTransferRequests { option (gogoproto.equal) = true; option (gogoproto.goproto_stringer) = true; - repeated DTagTransferRequest requests = 1 - [(gogoproto.nullable) = false]; + repeated DTagTransferRequest requests = 1 [(gogoproto.nullable) = false]; } \ No newline at end of file diff --git a/proto/desmos/profiles/v1beta1/query.proto b/proto/desmos/profiles/v1beta1/query.proto index 51420b5302..e8e3200b3a 100644 --- a/proto/desmos/profiles/v1beta1/query.proto +++ b/proto/desmos/profiles/v1beta1/query.proto @@ -12,13 +12,17 @@ option go_package = "github.com/desmos-labs/desmos/x/profiles/types"; // Query defines the gRPC querier service. service Query { - // Profile queries the profile of a specific user given their DTag or address + // Profile queries the profile of a specific user given their DTag or address. + // If the queried user does not have a profile, the returned response will + // contain a null profile. rpc Profile(QueryProfileRequest) returns (QueryProfileResponse) { option (google.api.http).get = "/desmos/profiles/v1beta1/profiles/{user}"; } - // DTagTransfers queries all the DTag transfers requests that have been made towards the user with the given address - rpc DTagTransfers(QueryDTagTransfersRequest) returns (QueryDTagTransfersResponse) { + // DTagTransfers queries all the DTag transfers requests that have been made + // towards the user with the given address + rpc DTagTransfers(QueryDTagTransfersRequest) + returns (QueryDTagTransfersResponse) { option (google.api.http).get = "/desmos/profiles/v1beta1/dtag_transfers"; } diff --git a/x/profiles/client/cli/cli_test.go b/x/profiles/client/cli/cli_test.go index 7a0c9d4945..7b06ffcfc7 100644 --- a/x/profiles/client/cli/cli_test.go +++ b/x/profiles/client/cli/cli_test.go @@ -126,8 +126,12 @@ func (s *IntegrationTestSuite) TestCmdQueryProfile() { name: "non existing profile", args: []string{ s.network.Validators[1].Address.String(), + fmt.Sprintf("--%s=json", tmcli.OutputFlag), + }, + expectErr: false, + expectedOutput: types.QueryProfileResponse{ + Profile: nil, }, - expectErr: true, }, { name: "existing profile is returned properly", diff --git a/x/profiles/types/account_test.go b/x/profiles/types/account_test.go index 6623a62dfb..e97af7dc1f 100644 --- a/x/profiles/types/account_test.go +++ b/x/profiles/types/account_test.go @@ -31,7 +31,7 @@ func TestProfile_Update(t *testing.T) { expProfile *types.Profile }{ { - name: "DoNotModify and empty fields do not update original values", + name: "DoNotModify do not update original values", original: assertNoProfileError(types.NewProfile( "dtag", "moniker", @@ -45,18 +45,21 @@ func TestProfile_Update(t *testing.T) { )), update: types.NewProfileUpdate( types.DoNotModify, + "", types.DoNotModify, - types.DoNotModify, - types.NewPictures(types.DoNotModify, types.DoNotModify), + types.NewPictures( + types.DoNotModify, + "", + ), ), expError: false, expProfile: assertNoProfileError(types.NewProfile( "dtag", - "moniker", + "", "bio", types.NewPictures( "https://example.com", - "https://example.com", + "", ), time.Unix(100, 0), authtypes.NewBaseAccountWithAddress(addr1), diff --git a/x/profiles/types/query.pb.go b/x/profiles/types/query.pb.go index 96ac9c638c..8145043b5e 100644 --- a/x/profiles/types/query.pb.go +++ b/x/profiles/types/query.pb.go @@ -346,9 +346,12 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type QueryClient interface { - // Profile queries the profile of a specific user given their DTag or address + // Profile queries the profile of a specific user given their DTag or address. + // If the queried user does not have a profile, the returned response will + // contain a null profile. Profile(ctx context.Context, in *QueryProfileRequest, opts ...grpc.CallOption) (*QueryProfileResponse, error) - // DTagTransfers queries all the DTag transfers requests that have been made towards the user with the given address + // DTagTransfers queries all the DTag transfers requests that have been made + // towards the user with the given address DTagTransfers(ctx context.Context, in *QueryDTagTransfersRequest, opts ...grpc.CallOption) (*QueryDTagTransfersResponse, error) // Params queries the profiles module params Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) @@ -391,9 +394,12 @@ func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts . // QueryServer is the server API for Query service. type QueryServer interface { - // Profile queries the profile of a specific user given their DTag or address + // Profile queries the profile of a specific user given their DTag or address. + // If the queried user does not have a profile, the returned response will + // contain a null profile. Profile(context.Context, *QueryProfileRequest) (*QueryProfileResponse, error) - // DTagTransfers queries all the DTag transfers requests that have been made towards the user with the given address + // DTagTransfers queries all the DTag transfers requests that have been made + // towards the user with the given address DTagTransfers(context.Context, *QueryDTagTransfersRequest) (*QueryDTagTransfersResponse, error) // Params queries the profiles module params Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error)