Skip to content

Commit

Permalink
minimum refactor to build
Browse files Browse the repository at this point in the history
  • Loading branch information
sainoe committed Nov 28, 2023
1 parent c96df01 commit cf3d174
Show file tree
Hide file tree
Showing 20 changed files with 3,483 additions and 122 deletions.
6 changes: 6 additions & 0 deletions tests/integration/staking/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,9 @@ func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers

return addrs, valAddrs, vals
}

func delegateCoinsFromAccount(ctx sdk.Context, app *simapp.SimApp, addr sdk.AccAddress, amount sdk.Int, val types.Validator) error {
_, err := app.StakingKeeper.Delegate(ctx, addr, amount, types.Unbonded, val, true)

return err
}
44 changes: 44 additions & 0 deletions tests/integration/staking/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper_test
import (
"fmt"
"testing"
"time"

"cosmossdk.io/math"
abci "github.com/cometbft/cometbft/abci/types"
Expand Down Expand Up @@ -218,3 +219,46 @@ func TestInitGenesisLargeValidatorSet(t *testing.T) {
vals = vals[:100]
require.Equal(t, abcivals, vals)
}

func TestInitExportLiquidStakingGenesis(t *testing.T) {
app, ctx, addrs := bootstrapGenesisTest(t, 2)
address1, address2 := addrs[0], addrs[1]

// Mock out a genesis state
inGenesisState := types.GenesisState{
Params: types.DefaultParams(),
TokenizeShareRecords: []types.TokenizeShareRecord{
{Id: 1, Owner: address1.String(), ModuleAccount: "module1", Validator: "val1"},
{Id: 2, Owner: address2.String(), ModuleAccount: "module2", Validator: "val2"},
},
LastTokenizeShareRecordId: 2,
TotalLiquidStakedTokens: sdk.NewInt(1_000_000),
TokenizeShareLocks: []types.TokenizeShareLock{
{
Address: address1.String(),
Status: types.TOKENIZE_SHARE_LOCK_STATUS_LOCKED.String(),
},
{
Address: address2.String(),
Status: types.TOKENIZE_SHARE_LOCK_STATUS_LOCK_EXPIRING.String(),
CompletionTime: time.Date(2023, 1, 1, 1, 0, 0, 0, time.UTC),
},
},
}

// Call init and then export genesis - confirming the same state is returned
staking.InitGenesis(ctx, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, &inGenesisState)
outGenesisState := *staking.ExportGenesis(ctx, app.StakingKeeper)

require.ElementsMatch(t, inGenesisState.TokenizeShareRecords, outGenesisState.TokenizeShareRecords,
"tokenize share records")

require.Equal(t, inGenesisState.LastTokenizeShareRecordId, outGenesisState.LastTokenizeShareRecordId,
"last tokenize share record ID")

require.Equal(t, inGenesisState.TotalLiquidStakedTokens.Int64(), outGenesisState.TotalLiquidStakedTokens.Int64(),
"total liquid staked")

require.ElementsMatch(t, inGenesisState.TokenizeShareLocks, outGenesisState.TokenizeShareLocks,
"tokenize share locks")
}
114 changes: 57 additions & 57 deletions x/distribution/testutil/expected_keepers_mocks.go

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

4 changes: 4 additions & 0 deletions x/slashing/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,7 @@ func (h Hooks) BeforeValidatorSlashed(_ sdk.Context, _ sdk.ValAddress, _ sdk.Dec
func (h Hooks) AfterUnbondingInitiated(_ sdk.Context, _ uint64) error {
return nil
}

func (h Hooks) BeforeTokenizeShareRecordRemoved(ctx sdk.Context, recordID uint64) error {
return nil
}
1 change: 1 addition & 0 deletions x/staking/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func BeginBlocker(ctx sdk.Context, k *keeper.Keeper) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)

k.TrackHistoricalInfo(ctx)
k.RemoveExpiredTokenizeShareLocks(ctx, ctx.BlockTime())

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
}

// Called every block, update validator set
Expand Down
Loading

0 comments on commit cf3d174

Please sign in to comment.