Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Dec 1, 2024
1 parent 23efb7a commit be099a5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func MsgCreate<%= TypeName.UpperCamel %>Factory(k keeper.Keeper) simsx.SimMsgFac
func MsgUpdate<%= TypeName.UpperCamel %>Factory(k keeper.Keeper) simsx.SimMsgFactoryFn[*types.MsgUpdate<%= TypeName.UpperCamel %>] {
return func(ctx context.Context, testData *simsx.ChainDataSource, reporter simsx.SimulationReporter) ([]simsx.SimAccount, *types.MsgUpdate<%= TypeName.UpperCamel %>) {
var (
simAccount = simtypes.Account{}
<%= TypeName.LowerCamel %> = types.<%= TypeName.UpperCamel %>{}
msg = &types.MsgUpdate<%= TypeName.UpperCamel %>{}
found = false
Expand All @@ -40,32 +39,32 @@ func MsgUpdate<%= TypeName.UpperCamel %>Factory(k keeper.Keeper) simsx.SimMsgFac
return nil, nil
}

simAccount := simsx.SimAccount{}
for _, obj := range all<%= TypeName.UpperCamel %> {
simAccount, found = FindAccount(accs, obj.<%= MsgSigner.UpperCamel %>)
if found {
<%= TypeName.LowerCamel %> = obj
if ok := testData.HasAccount(obj.<%= MsgSigner.UpperCamel %>); ok {
simAccount = testData.GetAccount(reporter, obj.<%= MsgSigner.UpperCamel %>)
break
}
}
if !found {
if simAccount.Address.Empty() {
reporter.Skip("<%= TypeName.LowerCamel %> <%= MsgSigner.LowerCamel %> not found")
return nil, nil
}
msg.<%= MsgSigner.UpperCamel %> = simAccount.Address.String()

msg.<%= MsgSigner.UpperCamel %> = simAccount.AddressBech32
msg.Id = <%= TypeName.LowerCamel %>.Id

return []simsx.SimAccount{}, msg
return []simsx.SimAccount{simAccount}, msg
}
}

func MsgDelete<%= TypeName.UpperCamel %>Factory(k keeper.Keeper) simsx.SimMsgFactoryFn[*types.MsgDelete<%= TypeName.UpperCamel %>] {
return func(ctx context.Context, testData *simsx.ChainDataSource, reporter simsx.SimulationReporter) ([]simsx.SimAccount, *types.MsgDelete<%= TypeName.UpperCamel %>) {
var (
simAccount = simtypes.Account{}
<%= TypeName.LowerCamel %> = types.<%= TypeName.UpperCamel %>{}
msg = &types.MsgDelete<%= TypeName.UpperCamel %>{}
found = false
)

var all<%= TypeName.UpperCamel %> []types.<%= TypeName.UpperCamel %>
err := k.<%= TypeName.UpperCamel %>.Walk(ctx, nil, func(key uint64, value types.<%= TypeName.UpperCamel %>) (stop bool, err error) {
all<%= TypeName.UpperCamel %> = append(all<%= TypeName.UpperCamel %>, value)
Expand All @@ -75,20 +74,22 @@ func MsgDelete<%= TypeName.UpperCamel %>Factory(k keeper.Keeper) simsx.SimMsgFac
reporter.Skip(err.Error())
return nil, nil
}

simAccount := simsx.SimAccount{}
for _, obj := range all<%= TypeName.UpperCamel %> {
simAccount, found = FindAccount(accs, obj.<%= MsgSigner.UpperCamel %>)
if found {
<%= TypeName.LowerCamel %> = obj
if ok := testData.HasAccount(obj.<%= MsgSigner.UpperCamel %>); ok {
simAccount = testData.GetAccount(reporter, obj.<%= MsgSigner.UpperCamel %>)
break
}
}
if !found {
if simAccount.Address.Empty() {
reporter.Skip("<%= TypeName.LowerCamel %> <%= MsgSigner.LowerCamel %> not found")
return nil, nil
}
msg.<%= MsgSigner.UpperCamel %> = simAccount.Address.String()

msg.<%= MsgSigner.UpperCamel %> = simAccount.AddressBech32
msg.Id = <%= TypeName.LowerCamel %>.Id

return []simsx.SimAccount{}, msg
return []simsx.SimAccount{simAccount}, msg
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func MsgCreate<%= TypeName.UpperCamel %>Factory(k keeper.Keeper) simsx.SimMsgFac
func MsgUpdate<%= TypeName.UpperCamel %>Factory(k keeper.Keeper) simsx.SimMsgFactoryFn[*types.MsgUpdate<%= TypeName.UpperCamel %>] {
return func(ctx context.Context, testData *simsx.ChainDataSource, reporter simsx.SimulationReporter) ([]simsx.SimAccount, *types.MsgUpdate<%= TypeName.UpperCamel %>) {
var (
simAccount = simtypes.Account{}
<%= TypeName.LowerCamel %> = types.<%= TypeName.UpperCamel %>{}
msg = &types.MsgUpdate<%= TypeName.UpperCamel %>{}
found = false
Expand All @@ -47,32 +46,33 @@ func MsgUpdate<%= TypeName.UpperCamel %>Factory(k keeper.Keeper) simsx.SimMsgFac
reporter.Skip(err.Error())
return nil, nil
}

simAccount := simsx.SimAccount{}
for _, obj := range all<%= TypeName.UpperCamel %> {
simAccount, found = FindAccount(accs, obj.<%= MsgSigner.UpperCamel %>)
if found {
<%= TypeName.LowerCamel %> = obj
if ok := testData.HasAccount(obj.<%= MsgSigner.UpperCamel %>); ok {
simAccount = testData.GetAccount(reporter, obj.<%= MsgSigner.UpperCamel %>)
break
}
}
if !found {
if simAccount.Address.Empty() {
reporter.Skip("<%= TypeName.LowerCamel %> <%= MsgSigner.LowerCamel %> not found")
return nil, nil
}
msg.<%= MsgSigner.UpperCamel %> = simAccount.Address.String()

msg.<%= MsgSigner.UpperCamel %> = simAccount.AddressBech32
msg.<%= Index.Name.UpperCamel %> = <%= TypeName.LowerCamel %>.<%= Index.Name.UpperCamel %>

return []simsx.SimAccount{}, msg
return []simsx.SimAccount{simAccount}, msg
}
}

func MsgDelete<%= TypeName.UpperCamel %>Factory(k keeper.Keeper) simsx.SimMsgFactoryFn[*types.MsgDelete<%= TypeName.UpperCamel %>] {
return func(ctx context.Context, testData *simsx.ChainDataSource, reporter simsx.SimulationReporter) ([]simsx.SimAccount, *types.MsgDelete<%= TypeName.UpperCamel %>) {
var (
simAccount = simtypes.Account{}
<%= TypeName.LowerCamel %> = types.<%= TypeName.UpperCamel %>{}
msg = &types.MsgUpdate<%= TypeName.UpperCamel %>{}
found = false
msg = &types.MsgDelete<%= TypeName.UpperCamel %>{}
)

var all<%= TypeName.UpperCamel %> []types.<%= TypeName.UpperCamel %>
err := k.<%= TypeName.UpperCamel %>.Walk(ctx, nil, func(key <%= Index.DataType() %>, value types.<%= TypeName.UpperCamel %>) (stop bool, err error) {
all<%= TypeName.UpperCamel %> = append(all<%= TypeName.UpperCamel %>, value)
Expand All @@ -82,20 +82,22 @@ func MsgDelete<%= TypeName.UpperCamel %>Factory(k keeper.Keeper) simsx.SimMsgFac
reporter.Skip(err.Error())
return nil, nil
}

simAccount := simsx.SimAccount{}
for _, obj := range all<%= TypeName.UpperCamel %> {
simAccount, found = FindAccount(accs, obj.<%= MsgSigner.UpperCamel %>)
if found {
<%= TypeName.LowerCamel %> = obj
if ok := testData.HasAccount(obj.<%= MsgSigner.UpperCamel %>); ok {
simAccount = testData.GetAccount(reporter, obj.<%= MsgSigner.UpperCamel %>)
break
}
}
if !found {
if simAccount.Address.Empty() {
reporter.Skip("<%= TypeName.LowerCamel %> <%= MsgSigner.LowerCamel %> not found")
return nil, nil
}
msg.<%= MsgSigner.UpperCamel %> = simAccount.Address.String()

msg.<%= MsgSigner.UpperCamel %> = simAccount.AddressBech32
msg.<%= Index.Name.UpperCamel %> = <%= TypeName.LowerCamel %>.<%= Index.Name.UpperCamel %>

return []simsx.SimAccount{}, msg
return []simsx.SimAccount{simAccount}, msg
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
func MsgCreate<%= TypeName.UpperCamel %>Factory(k keeper.Keeper) simsx.SimMsgFactoryFn[*types.MsgCreate<%= TypeName.UpperCamel %>] {
return func(ctx context.Context, testData *simsx.ChainDataSource, reporter simsx.SimulationReporter) ([]simsx.SimAccount, *types.MsgCreate<%= TypeName.UpperCamel %>) {
from := testData.AnyAccount(reporter)

msg := &types.MsgCreate<%= TypeName.UpperCamel %>{
<%= MsgSigner.UpperCamel %>: from.AddressBech32,
}

found, err := k.<%= TypeName.UpperCamel %>.Has(ctx)
if err == nil && found {
reporter.Skip("<%= TypeName.UpperCamel %> already exist")
Expand All @@ -30,43 +30,37 @@ func MsgCreate<%= TypeName.UpperCamel %>Factory(k keeper.Keeper) simsx.SimMsgFac
func MsgUpdate<%= TypeName.UpperCamel %>Factory(k keeper.Keeper) simsx.SimMsgFactoryFn[*types.MsgUpdate<%= TypeName.UpperCamel %>] {
return func(ctx context.Context, testData *simsx.ChainDataSource, reporter simsx.SimulationReporter) ([]simsx.SimAccount, *types.MsgUpdate<%= TypeName.UpperCamel %>) {
var (
simAccount = simtypes.Account{}
msg = &types.MsgUpdate<%= TypeName.UpperCamel %>{}
<%= TypeName.LowerCamel %>, err = k.<%= TypeName.UpperCamel %>.Get(ctx)
)

<%= TypeName.LowerCamel %>, err := k.<%= TypeName.UpperCamel %>.Get(ctx)
if err != nil {
reporter.Skip("<%= TypeName.LowerCamel %> store is empty")
return nil, nil
}
simAccount, found := FindAccount(accs, <%= TypeName.LowerCamel %>.<%= MsgSigner.UpperCamel %>)
if !found {
reporter.Skip("<%= TypeName.LowerCamel %> <%= MsgSigner.LowerCamel %> not found")
return nil, nil
}
msg.<%= MsgSigner.UpperCamel %> = simAccount.Address.String()

return []simsx.SimAccount{}, msg
simAccount := testData.GetAccount(reporter, <%= TypeName.LowerCamel %>.<%= MsgSigner.UpperCamel %>)
msg.<%= MsgSigner.UpperCamel %> = simAccount.AddressBech32

return []simsx.SimAccount{simAccount}, msg
}
}

func MsgDelete<%= TypeName.UpperCamel %>Factory(k keeper.Keeper) simsx.SimMsgFactoryFn[*types.MsgDelete<%= TypeName.UpperCamel %>] {
return func(ctx context.Context, testData *simsx.ChainDataSource, reporter simsx.SimulationReporter) ([]simsx.SimAccount, *types.MsgDelete<%= TypeName.UpperCamel %>) {
var (
simAccount = simtypes.Account{}
msg = &types.MsgUpdate<%= TypeName.UpperCamel %>{}
<%= TypeName.LowerCamel %>, err = k.<%= TypeName.UpperCamel %>.Get(ctx)
msg = &types.MsgDelete<%= TypeName.UpperCamel %>{}
)

<%= TypeName.LowerCamel %>, err := k.<%= TypeName.UpperCamel %>.Get(ctx)
if err != nil {
reporter.Skip("<%= TypeName.LowerCamel %> store is empty")
return nil, nil
}
simAccount, found := FindAccount(accs, <%= TypeName.LowerCamel %>.<%= MsgSigner.UpperCamel %>)
if !found {
reporter.Skip("<%= TypeName.LowerCamel %> <%= MsgSigner.LowerCamel %> not found")
return nil, nil
}
msg.<%= MsgSigner.UpperCamel %> = simAccount.Address.String()

return []simsx.SimAccount{}, msg
simAccount := testData.GetAccount(reporter, <%= TypeName.LowerCamel %>.<%= MsgSigner.UpperCamel %>)
msg.<%= MsgSigner.UpperCamel %> = simAccount.AddressBech32

return []simsx.SimAccount{simAccount}, msg
}
}

0 comments on commit be099a5

Please sign in to comment.