Skip to content

Commit

Permalink
fixing genesis issues
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell committed Jun 21, 2023
1 parent e46b73e commit cb721d2
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 30 deletions.
1 change: 1 addition & 0 deletions proto/canine_chain/storage/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ message GenesisState {
repeated Strays strays_list = 6 [ (gogoproto.nullable) = false ];
repeated FidCid fid_cid_list = 5 [ (gogoproto.nullable) = false ];
repeated StoragePaymentInfo payment_info_list = 7 [ (gogoproto.nullable) = false ];
repeated Collateral collateral_list = 8 [ (gogoproto.nullable) = false ];

// this line is used by starport scaffolding # genesis/proto/state
}
7 changes: 6 additions & 1 deletion x/storage/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
for _, elem := range genState.PaymentInfoList {
k.SetStoragePaymentInfo(ctx, elem)
}

// Set all the collateral
for _, elem := range genState.CollateralList {
k.SetCollateral(ctx, elem)
}
// this line is used by starport scaffolding # genesis/module/init
k.SetParams(ctx, genState.Params)
}
Expand All @@ -50,7 +55,7 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
genesis.StraysList = k.GetAllStrays(ctx)
genesis.FidCidList = k.GetAllFidCid(ctx)
genesis.PaymentInfoList = k.GetAllStoragePaymentInfo(ctx)

genesis.CollateralList = k.GetAllCollateral(ctx)
// this line is used by starport scaffolding # genesis/module/export

return genesis
Expand Down
18 changes: 17 additions & 1 deletion x/storage/simulation/init_miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,27 @@ import (
func SimulateMsgInitProvider(
ak types.AccountKeeper,
bk types.BankKeeper,
_ keeper.Keeper,
k keeper.Keeper,
) simtypes.Operation {
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
simAccount, _ := simtypes.RandomAcc(r, accs)

_, found := k.GetProviders(ctx, simAccount.Address.String())
if found {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgInitProvider, "provider already exists"), nil, nil
}

coins := sdk.NewCoins(sdk.NewInt64Coin("ujkl", 10_000_000_000_000))
err := bk.MintCoins(ctx, types.ModuleName, coins)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgInitProvider, "failed to mint collateral"), nil, err
}
err = bk.SendCoinsFromModuleToAccount(ctx, types.ModuleName, simAccount.Address, coins)
if err != nil {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgInitProvider, "failed to generate collateral"), nil, err
}

msg := &types.MsgInitProvider{
Creator: simAccount.Address.String(),
Ip: RandIPv4Url(r),
Expand Down
119 changes: 91 additions & 28 deletions x/storage/types/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cb721d2

Please sign in to comment.