Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: core refact app #204

Merged
merged 3 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
943 changes: 77 additions & 866 deletions app/app.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/app_test/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func TestSimAppEnforceStakingForVestingTokens(t *testing.T) {
ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})

genesisState[authtypes.ModuleName] = app.GetAppCodec().MustMarshalJSON(authtypes.NewGenesisState(authtypes.DefaultParams(), genAccounts))
delegations := app.StakingKeeper.GetAllDelegations(ctx)
delegations := app.Keepers.StakingKeeper.GetAllDelegations(ctx)
sharePerValidators := make(map[string]sdk.Dec)

for _, del := range delegations {
Expand Down
14 changes: 7 additions & 7 deletions app/app_test/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@ func (s *AppTestSuite) Setup() {
GRPCQueryRouter: s.App.GRPCQueryRouter(),
Ctx: s.Ctx,
}
err := s.App.BankKeeper.SetParams(s.Ctx, banktypes.NewParams(true))
err := s.App.Keepers.BankKeeper.SetParams(s.Ctx, banktypes.NewParams(true))
s.Require().NoError(err)

err = s.App.WasmKeeper.SetParams(s.Ctx, wasmtypes.DefaultParams())
err = s.App.Keepers.WasmKeeper.SetParams(s.Ctx, wasmtypes.DefaultParams())
s.Require().NoError(err)

err = s.App.FeeShareKeeper.SetParams(s.Ctx, feesharetypes.DefaultParams())
err = s.App.Keepers.FeeShareKeeper.SetParams(s.Ctx, feesharetypes.DefaultParams())
s.Require().NoError(err)

err = s.App.TokenFactoryKeeper.SetParams(s.Ctx, tokenfactorytypes.DefaultParams())
err = s.App.Keepers.TokenFactoryKeeper.SetParams(s.Ctx, tokenfactorytypes.DefaultParams())
s.Require().NoError(err)

s.App.DistrKeeper.SetFeePool(s.Ctx, distrtypes.InitialFeePool())
s.App.Keepers.DistrKeeper.SetFeePool(s.Ctx, distrtypes.InitialFeePool())

s.TestAccs = s.CreateRandomAccounts(3)
}
Expand Down Expand Up @@ -114,11 +114,11 @@ func (s *AppTestSuite) CreateRandomAccounts(numAccts int) []sdk.AccAddress {
// FundAcc funds target address with specified amount.
func (s *AppTestSuite) FundAcc(acc sdk.AccAddress, amounts sdk.Coins) (err error) {
s.Require().NoError(err)
if err := s.App.BankKeeper.MintCoins(s.Ctx, minttypes.ModuleName, amounts); err != nil {
if err := s.App.Keepers.BankKeeper.MintCoins(s.Ctx, minttypes.ModuleName, amounts); err != nil {
return err
}

return s.App.BankKeeper.SendCoinsFromModuleToAccount(s.Ctx, minttypes.ModuleName, acc, amounts)
return s.App.Keepers.BankKeeper.SendCoinsFromModuleToAccount(s.Ctx, minttypes.ModuleName, acc, amounts)
}

func SetupGenesisValSet(
Expand Down
48 changes: 24 additions & 24 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
return servertypes.ExportedApp{}, err
}

validators, err := staking.WriteValidators(ctx, app.StakingKeeper)
validators, err := staking.WriteValidators(ctx, app.Keepers.StakingKeeper)

Check warning on line 40 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L40

Added line #L40 was not covered by tests
if err != nil {
return servertypes.ExportedApp{}, err
}
Expand Down Expand Up @@ -72,47 +72,47 @@
}

/* Just to be safe, assert the invariants on current state. */
app.CrisisKeeper.AssertInvariants(ctx)
app.Keepers.CrisisKeeper.AssertInvariants(ctx)

Check warning on line 75 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L75

Added line #L75 was not covered by tests

/* Handle fee distribution state. */

// withdraw all validator commission
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
_, err := app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
app.Keepers.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
_, err := app.Keepers.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())

Check warning on line 81 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L80-L81

Added lines #L80 - L81 were not covered by tests
if err != nil {
panic(err)
}
return false
})

// withdraw all delegator rewards
dels := app.StakingKeeper.GetAllDelegations(ctx)
dels := app.Keepers.StakingKeeper.GetAllDelegations(ctx)

Check warning on line 89 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L89

Added line #L89 was not covered by tests
for _, delegation := range dels {
_, err := app.DistrKeeper.WithdrawDelegationRewards(ctx, delegation.GetDelegatorAddr(), delegation.GetValidatorAddr())
_, err := app.Keepers.DistrKeeper.WithdrawDelegationRewards(ctx, delegation.GetDelegatorAddr(), delegation.GetValidatorAddr())

Check warning on line 91 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L91

Added line #L91 was not covered by tests
if err != nil {
panic(err)
}
}

// clear validator slash events
app.DistrKeeper.DeleteAllValidatorSlashEvents(ctx)
app.Keepers.DistrKeeper.DeleteAllValidatorSlashEvents(ctx)

Check warning on line 98 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L98

Added line #L98 was not covered by tests

// clear validator historical rewards
app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx)
app.Keepers.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx)

Check warning on line 101 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L101

Added line #L101 was not covered by tests

// set context height to zero
height := ctx.BlockHeight()
ctx = ctx.WithBlockHeight(0)

// reinitialize all validators
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
app.Keepers.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {

Check warning on line 108 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L108

Added line #L108 was not covered by tests
// donate any unwithdrawn outstanding reward fraction tokens to the community pool
scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator())
feePool := app.DistrKeeper.GetFeePool(ctx)
scraps := app.Keepers.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator())
feePool := app.Keepers.DistrKeeper.GetFeePool(ctx)

Check warning on line 111 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L110-L111

Added lines #L110 - L111 were not covered by tests
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
app.DistrKeeper.SetFeePool(ctx, feePool)
app.Keepers.DistrKeeper.SetFeePool(ctx, feePool)

Check warning on line 113 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L113

Added line #L113 was not covered by tests

err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
err := app.Keepers.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())

Check warning on line 115 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L115

Added line #L115 was not covered by tests
if err != nil {
panic(err)
}
Expand All @@ -121,11 +121,11 @@

// reinitialize all delegations
for _, del := range dels {
err := app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
err := app.Keepers.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())

Check warning on line 124 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L124

Added line #L124 was not covered by tests
if err != nil {
panic(err)
}
err = app.DistrKeeper.Hooks().AfterDelegationModified(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
err = app.Keepers.DistrKeeper.Hooks().AfterDelegationModified(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())

Check warning on line 128 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L128

Added line #L128 was not covered by tests
if err != nil {
panic(err)
}
Expand All @@ -137,20 +137,20 @@
/* Handle staking state. */

// iterate through redelegations, reset creation height
app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) {
app.Keepers.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) {

Check warning on line 140 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L140

Added line #L140 was not covered by tests
for i := range red.Entries {
red.Entries[i].CreationHeight = 0
}
app.StakingKeeper.SetRedelegation(ctx, red)
app.Keepers.StakingKeeper.SetRedelegation(ctx, red)

Check warning on line 144 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L144

Added line #L144 was not covered by tests
return false
})

// iterate through unbonding delegations, reset creation height
app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) {
app.Keepers.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) {

Check warning on line 149 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L149

Added line #L149 was not covered by tests
for i := range ubd.Entries {
ubd.Entries[i].CreationHeight = 0
}
app.StakingKeeper.SetUnbondingDelegation(ctx, ubd)
app.Keepers.StakingKeeper.SetUnbondingDelegation(ctx, ubd)

Check warning on line 153 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L153

Added line #L153 was not covered by tests
return false
})

Expand All @@ -162,7 +162,7 @@

for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(iter.Key()[1:])
validator, found := app.StakingKeeper.GetValidator(ctx, addr)
validator, found := app.Keepers.StakingKeeper.GetValidator(ctx, addr)

Check warning on line 165 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L165

Added line #L165 was not covered by tests
if !found {
panic("expected validator, not found")
}
Expand All @@ -172,7 +172,7 @@
validator.Jailed = true
}

app.StakingKeeper.SetValidator(ctx, validator)
app.Keepers.StakingKeeper.SetValidator(ctx, validator)

Check warning on line 175 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L175

Added line #L175 was not covered by tests
counter++
}

Expand All @@ -181,18 +181,18 @@
panic(err)
}

if _, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx); err != nil {
if _, err := app.Keepers.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx); err != nil {

Check warning on line 184 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L184

Added line #L184 was not covered by tests
panic(err)
}

/* Handle slashing state. */

// reset start height on signing infos
app.SlashingKeeper.IterateValidatorSigningInfos(
app.Keepers.SlashingKeeper.IterateValidatorSigningInfos(

Check warning on line 191 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L191

Added line #L191 was not covered by tests
ctx,
func(addr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) {
info.StartHeight = 0
app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info)
app.Keepers.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info)

Check warning on line 195 in app/export.go

View check run for this annotation

Codecov / codecov/patch

app/export.go#L195

Added line #L195 was not covered by tests
return false
},
)
Expand Down
Loading
Loading