func randomRegisterUserFields(
	r *rand.Rand, ctx sdk.Context, accs []simtypes.Account, k keeper.Keeper,
) (simtypes.Account, string, string, bool) {
	if len(accs) == 0 {
		return simtypes.Account{}, "", "", true
	}
	subspaces := k.GetAllSubspaces(ctx)
	if len(subspaces) == 0 {
		return simtypes.Account{}, "", "", true
	}
	subspace, _ := RandomSubspace(r, subspaces)
	user, _ := simtypes.RandomAcc(r, accs)
	if subspace.Owner == user.Address.String() {
		return simtypes.Account{}, "", "", true
	}
	if k.IsRegistered(ctx, subspace.ID, user.Address.String()) {
		return simtypes.Account{}, "", "", true
	}
	acc, _ := sdk.AccAddressFromBech32(subspace.Owner)
	owner := GetAccount(acc, accs)
	return *owner, subspace.ID, user.Address.String(), false
}
randomRegisterUserFields returns random register user fields
package simulation
import (
	"math/rand"
	"github.com/cosmos/cosmos-sdk/baseapp"
	cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
	"github.com/cosmos/cosmos-sdk/simapp/helpers"
	simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
	sdk "github.com/cosmos/cosmos-sdk/types"
	simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
	authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
	bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
	"github.com/desmos-labs/desmos/v2/x/staging/subspaces/keeper"
	"github.com/desmos-labs/desmos/v2/x/staging/subspaces/types"
)
func SimulateMsgRegisterUser(k keeper.Keeper, ak authkeeper.AccountKeeper, bk bankkeeper.Keeper) simtypes.Operation {
	return func(
		r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
	) (OperationMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) {
		owner, subspaceID, address, skip := randomRegisterUserFields(r, ctx, accs, k)
		if skip {
			return simtypes.NoOpMsg(types.RouterKey, types.ModuleName, "MsgRegisterUser"), nil, nil
		}
		msg := types.NewMsgRegisterUser(
			subspaceID,
			address,
			owner.Address.String(),
		)
		err = sendMsgRegisterUser(r, app, ak, bk, msg, ctx, chainID, []cryptotypes.PrivKey{owner.PrivKey})
		if err != nil {
			return simtypes.NoOpMsg(types.QuerierRoute, types.ModuleName, "MsgRegisterUser"), nil, err
		}
		return simtypes.NewOperationMsg(msg, true, "MsgRegisterUser", nil), nil, nil
	}
}
func sendMsgRegisterUser(
	r *rand.Rand, app *baseapp.BaseApp, ak authkeeper.AccountKeeper, bk bankkeeper.Keeper,
	msg *types.MsgRegisterUser, ctx sdk.Context, chainID string, privkeys []cryptotypes.PrivKey,
) error {
	addr, _ := sdk.AccAddressFromBech32(msg.Admin)
	account := ak.GetAccount(ctx, addr)
	coins := bk.SpendableCoins(ctx, account.GetAddress())
	fees, err := simtypes.RandomFees(r, ctx, coins)
	if err != nil {
		return err
	}
	txGen := simappparams.MakeTestEncodingConfig().TxConfig
	tx, err := helpers.GenTx(
		txGen,
		[]sdk.Msg{msg},
		fees,
		DefaultGasValue,
		chainID,
		[]uint64{account.GetAccountNumber()},
		[]uint64{account.GetSequence()},
		privkeys...,
	)
	if err != nil {
		return err
	}
	_, _, err = app.Deliver(txGen.TxEncoder(), tx)
	if err != nil {
		return err
	}
	return nil
}