Skip to content

Commit

Permalink
Master tests fix
Browse files Browse the repository at this point in the history
See PR #146
  • Loading branch information
leobragaz committed Apr 29, 2020
1 parent aad3dd4 commit b292866
Show file tree
Hide file tree
Showing 9 changed files with 64,439 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2.1
executors:
golang:
docker:
- image: circleci/golang:1.13
- image: circleci/golang:1.14

commands:
make:
Expand Down
2 changes: 2 additions & 0 deletions x/magpie/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (

var (
// functions aliases

DecodeStore = simulation.DecodeStore
RandomizedGenState = simulation.RandomizedGenState
WeightedOperations = simulation.WeightedOperations
Expand All @@ -45,6 +46,7 @@ var (
NewQuerier = keeper.NewQuerier

// variable aliases

SessionLengthKey = types.SessionLengthKey
LastSessionIDStoreKey = types.LastSessionIDStoreKey
SessionStorePrefix = types.SessionStorePrefix
Expand Down
3 changes: 2 additions & 1 deletion x/posts/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const (

var (
// functions aliases

NewHandler = keeper.NewHandler
NewKeeper = keeper.NewKeeper
NewQuerier = keeper.NewQuerier
Expand All @@ -80,7 +81,6 @@ var (
GetAccount = simulation.GetAccount
RandomReactionValue = simulation.RandomReactionValue
RandomReactionShortCode = simulation.RandomReactionShortCode
RandomEmoji = simulation.RandomEmoji
RandomReactionData = simulation.RandomReactionData
RegisteredReactionsData = simulation.RegisteredReactionsData
DecodeStore = simulation.DecodeStore
Expand Down Expand Up @@ -127,6 +127,7 @@ var (
NewMsgRegisterReaction = types.NewMsgRegisterReaction

// variable aliases

RandomMimeTypes = simulation.RandomMimeTypes
RandomHosts = simulation.RandomHosts
Sha256RegEx = types.Sha256RegEx
Expand Down
1 change: 1 addition & 0 deletions x/posts/internal/keeper/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ func Test_handleMsgRegisterReaction(t *testing.T) {
types.EventTypeRegisterReaction,
sdk.NewAttribute(types.AttributeKeyReactionCreator, test.msg.Creator.String()),
sdk.NewAttribute(types.AttributeKeyReactionShortCode, test.msg.ShortCode),
sdk.NewAttribute(types.AttributeKeyPostReactionValue, test.msg.Value),
sdk.NewAttribute(types.AttributeKeyReactionSubSpace, test.msg.Subspace),
))

Expand Down
21 changes: 7 additions & 14 deletions x/posts/internal/simulation/operations_reactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
sim "github.com/cosmos/cosmos-sdk/x/simulation"
emoji "github.com/desmos-labs/Go-Emoji-Utils"
"github.com/desmos-labs/desmos/x/posts/internal/keeper"
"github.com/desmos-labs/desmos/x/posts/internal/types"
"github.com/tendermint/tendermint/crypto"
Expand Down Expand Up @@ -98,11 +97,13 @@ func randomAddPostReactionFields(

k.SavePost(ctx, post)

var reaction types.Reaction
data := RandomReactionData(r, accs)
reaction := types.NewReaction(data.Creator.Address, data.ShortCode, data.Value, post.Subspace)
reaction = types.NewReaction(data.Creator.Address, data.ShortCode, data.Value, post.Subspace)

k.RegisterReaction(ctx, reaction)

reactionData := RandomPostReactionData(r, accs, postID, types.NewReactions(reaction))
reactionData := RandomPostReactionData(r, accs, postID, reaction.ShortCode)
acc := ak.GetAccount(ctx, reactionData.User.Address)

// Skip the operation without error as the account is not valid
Expand All @@ -111,8 +112,8 @@ func randomAddPostReactionFields(
}

// Skip if the reaction already exists
postReactions := k.GetPostReactions(ctx, reactionData.PostID)
if postReactions.ContainsReactionFrom(reactionData.User.Address, reactionData.Value) {
reactions := k.GetPostReactions(ctx, reactionData.PostID)
if reactions.ContainsReactionFrom(reactionData.User.Address, reactionData.Value) {
return nil, true, nil
}

Expand Down Expand Up @@ -193,14 +194,6 @@ func randomRemovePostReactionFields(
}

reaction := reactions[r.Intn(len(reactions))]
reactionValue := reaction.Value

// 50 % of chance of using the shortcode, if it's a valid emoji
if r.Intn(101) <= 50 {
if e, err := emoji.LookupEmojiByCode(reactionValue); err == nil {
reactionValue = e.Value
}
}

acc := ak.GetAccount(ctx, reaction.Owner)

Expand All @@ -210,7 +203,7 @@ func randomRemovePostReactionFields(
}

user := GetAccount(reaction.Owner, accs)
data := PostReactionData{Value: reactionValue, User: *user, PostID: post.PostID}
data := PostReactionData{Value: reaction.Value, User: *user, PostID: post.PostID}
return &data, false, nil
}

Expand Down
37 changes: 4 additions & 33 deletions x/posts/internal/simulation/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
sim "github.com/cosmos/cosmos-sdk/x/simulation"
emoji "github.com/desmos-labs/Go-Emoji-Utils"
"github.com/desmos-labs/desmos/x/posts/internal/types"
)

Expand Down Expand Up @@ -42,7 +41,7 @@ var (
hashtags = []string{"#desmos", "#mooncake", "#test", "#cosmos", "#terra", "#bidDipper"}

shortCodes = []string{":blue_heart:", ":arrow_down:", ":thumbsdown:", ":thumbsup:", ":dog:", ":cat:"}
reactValues = []string{"http://earth.jpg", "https://gph.is/2p19Zai", "https://gph.is/2phybnt"}
reactValues = []string{"http://earth.jpg", "U+1F600", "U+1F605", "U+1F610"}
)

// RandomPost picks and returns a random post from an array and returns its
Expand Down Expand Up @@ -88,21 +87,9 @@ type PostReactionData struct {
}

// RandomPostReactionData returns a randomly generated post reaction data object
func RandomPostReactionData(
r *rand.Rand, accs []sim.Account, postID types.PostID, reactions types.Reactions,
) PostReactionData {
// Get a random reaction
reaction := reactions[r.Intn(len(reactions))]
reactionValue := reaction.ShortCode

// 50% chance of using an emoji
if r.Intn(101) <= 50 {
e := RandomEmoji(r)
reactionValue = e.Value
}

func RandomPostReactionData(r *rand.Rand, accs []sim.Account, postID types.PostID, shortCode string) PostReactionData {
return PostReactionData{
Value: reactionValue,
Value: shortCode,
User: accs[r.Intn(len(accs))],
PostID: postID,
}
Expand Down Expand Up @@ -208,23 +195,7 @@ func RandomReactionValue(r *rand.Rand) string {

// RandomReactionShortCode return a random reaction shortCode
func RandomReactionShortCode(r *rand.Rand) string {
return shortCodes[r.Intn(len(shortCodes))]
}

// RandomEmoji returns a random emoji
func RandomEmoji(r *rand.Rand) emoji.Emoji {
index := r.Intn(len(emoji.Emojis))

var rEmoji emoji.Emoji
var i = 0
for _, v := range emoji.Emojis {
if i == index {
rEmoji = v
break
}
i++
}
return rEmoji
return shortCodes[r.Intn(len(reactValues))]
}

// RandomReactionData returns a randomly generated reaction data object
Expand Down
15 changes: 0 additions & 15 deletions x/posts/internal/simulation/utils_test.go

This file was deleted.

64,421 changes: 64,420 additions & 1 deletion x/posts/legacy/v0.4.0/v030state.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion x/profile/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (

var (
// functions aliases

NewHandler = keeper.NewHandler
GetEditedProfile = keeper.GetEditedProfile
NewKeeper = keeper.NewKeeper
Expand Down Expand Up @@ -70,6 +71,7 @@ var (
RegisterCodec = types.RegisterCodec

// variable aliases

TxHashRegEx = types.TxHashRegEx
URIRegEx = types.URIRegEx
ProfileStorePrefix = types.ProfileStorePrefix
Expand All @@ -86,5 +88,4 @@ type (
Profile = types.Profile
Profiles = types.Profiles
Keeper = keeper.Keeper
ProfileData = simulation.ProfileData
)

0 comments on commit b292866

Please sign in to comment.