Skip to content

Commit

Permalink
feat(staking/validator): add fn to generate random SocialHandleURIs
Browse files Browse the repository at this point in the history
  • Loading branch information
ziscky committed Sep 21, 2024
1 parent 05bea00 commit c894be1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
10 changes: 9 additions & 1 deletion x/staking/simulation/msg_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@ func MsgCreateValidatorFactory(k *keeper.Keeper) simsx.SimMsgFactoryFn[*types.Ms
}

selfDelegation := valOper.LiquidBalance().RandSubsetCoin(reporter, bondDenom)

description := types.NewDescription(
r.StringN(10),
r.StringN(10),
r.StringN(10),
r.StringN(10),
r.StringN(10),
types.Metadata{
ProfilePicUri: RandURIOfHostLength(r.Rand, 10),
SocialHandleUris: RandSocialHandles(r.Rand, 2, 10),
},
)

maxCommission := math.LegacyNewDecWithPrec(int64(r.IntInRange(0, 100)), 2)
Expand Down Expand Up @@ -138,7 +143,10 @@ func MsgEditValidatorFactory(k *keeper.Keeper) simsx.SimMsgFactoryFn[*types.MsgE
}
valOpAddrBz := must(k.ValidatorAddressCodec().StringToBytes(val.GetOperator()))
valOper := testData.GetAccountbyAccAddr(reporter, valOpAddrBz)
d := types.NewDescription(r.StringN(10), r.StringN(10), r.StringN(10), r.StringN(10), r.StringN(10))
d := types.NewDescription(r.StringN(10), r.StringN(10), r.StringN(10), r.StringN(10), r.StringN(10), types.Metadata{
ProfilePicUri: RandURIOfHostLength(r.Rand, 10),
SocialHandleUris: RandSocialHandles(r.Rand, 2, 10),
})

msg := types.NewMsgEditValidator(val.GetOperator(), d, &newCommissionRate, nil)
return []simsx.SimAccount{valOper}, msg
Expand Down
12 changes: 12 additions & 0 deletions x/staking/simulation/rand_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@ func RandURIOfHostLength(r *rand.Rand, n int) string {

return uri.String()
}

// RandSocialHandleURIs returns a string array of length num with uris.
func RandSocialHandleURIs(r *rand.Rand, num int, uriHostLength int) []string {
if num == 0 {
return []string{}
}
var socialHandles []string
for i := 0; i < num; i++ {
socialHandles = append(socialHandles, RandURIOfHostLength(r, uriHostLength))
}
return socialHandles
}
21 changes: 21 additions & 0 deletions x/staking/simulation/rand_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,24 @@ func TestRandURIOfHostLength(t *testing.T) {
})
}
}

func TestRandSocialHandleURIs(t *testing.T) {
t.Parallel()
r := rand.New(rand.NewSource(time.Now().Unix()))
tests := []struct {
name string
n int
want int
}{
{"0-handles", 0, 0},
{"10-handles", 10, 10},
{"100-handles", 100, 100},
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
uris := simulation.RandSocialHandleURIs(r, tc.n, 10)
require.Equal(t, tc.want, len(uris))
})
}
}

0 comments on commit c894be1

Please sign in to comment.