Skip to content

Commit

Permalink
initialize staking at genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Oct 24, 2024
1 parent 342a327 commit f4ddc27
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 10 deletions.
2 changes: 1 addition & 1 deletion x/bank/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func _createTestInput(
moduleBytes, err := precompile.ReadStdlib()
require.NoError(t, err)

err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.AllowedPublishers)
err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.AllowedPublishers, bondDenom)
require.NoError(t, err)

faucet := NewTestFaucet(t, ctx, bankKeeper, *moveKeeper, authtypes.Minter, initialTotalSupply()...)
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func _createTestInput(
moduleBytes, err := precompile.ReadStdlib()
require.NoError(t, err)

err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.AllowedPublishers)
err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.AllowedPublishers, bondDenom)
require.NoError(t, err)

faucet := NewTestFaucet(t, ctx, bankKeeper, *moveKeeper, authtypes.Minter, initialTotalSupply()...)
Expand Down
2 changes: 1 addition & 1 deletion x/gov/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func _createTestInput(
moduleBytes, err := precompile.ReadStdlib()
require.NoError(t, err)

err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.AllowedPublishers)
err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.AllowedPublishers, bondDenom)
require.NoError(t, err)

faucet := NewTestFaucet(t, ctx, bankKeeper, *moveKeeper, authtypes.Minter, initialTotalSupply()...)
Expand Down
2 changes: 1 addition & 1 deletion x/ibc-hooks/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func _createTestInput(
moduleBytes, err := precompile.ReadStdlib()
require.NoError(t, err)

err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.AllowedPublishers)
err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.AllowedPublishers, bondDenom)
require.NoError(t, err)

faucet := NewTestFaucet(t, ctx, bankKeeper, *moveKeeper, authtypes.Minter, initialTotalSupply()...)
Expand Down
2 changes: 1 addition & 1 deletion x/ibc-hooks/move-hooks/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func _createTestInput(
if initialize {
stdlib, err := vmprecom.ReadStdlib()
require.NoError(t, err)
require.NoError(t, moveKeeper.Initialize(ctx, stdlib, moveParams.AllowedPublishers))
require.NoError(t, moveKeeper.Initialize(ctx, stdlib, moveParams.AllowedPublishers, bondDenom))
}

faucet := NewTestFaucet(t, ctx, bankKeeper, authtypes.Minter, initialTotalSupply()...)
Expand Down
2 changes: 1 addition & 1 deletion x/move/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func _createTestInput(
// append test module
moduleBytes = append(moduleBytes, basicCoinModule)

err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.AllowedPublishers)
err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.AllowedPublishers, bondDenom)
require.NoError(t, err)

faucet := NewTestFaucet(t, ctx, bankKeeper, *moveKeeper, authtypes.Minter, initialTotalSupply()...)
Expand Down
18 changes: 17 additions & 1 deletion x/move/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func (k Keeper) Initialize(
ctx context.Context,
moduleBytes [][]byte,
allowedPublishers []string,
baseDenom string,
) error {
sdkCtx := sdk.UnwrapSDKContext(ctx)
ctx = sdkCtx.WithTxBytes(make([]byte, 32))
Expand Down Expand Up @@ -53,6 +54,21 @@ func (k Keeper) Initialize(
if err != nil {
return err
}
if err = k.handleExecuteResponse(sdkCtx, sdkCtx.GasMeter(), execRes); err != nil {
return err
}

Check warning on line 59 in x/move/keeper/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/move/keeper/genesis.go#L58-L59

Added lines #L58 - L59 were not covered by tests

// if staking keeper is available, initialize move staking module.
if k.StakingKeeper != nil {
if err := k.moveBankKeeper.InitializeCoin(ctx, baseDenom); err != nil {
return err
}

Check warning on line 65 in x/move/keeper/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/move/keeper/genesis.go#L64-L65

Added lines #L64 - L65 were not covered by tests

// initialize move staking module if staking keeper is available
if err := k.InitializeStaking(ctx, baseDenom); err != nil {
return err
}

Check warning on line 70 in x/move/keeper/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/move/keeper/genesis.go#L69-L70

Added lines #L69 - L70 were not covered by tests
}

return k.handleExecuteResponse(sdkCtx, sdkCtx.GasMeter(), execRes)
}
Expand All @@ -74,7 +90,7 @@ func (k Keeper) InitGenesis(ctx context.Context, moduleNames []string, genState
}

if len(genState.GetModules()) == 0 {
if err := k.Initialize(ctx, genState.GetStdlibs(), params.AllowedPublishers); err != nil {
if err := k.Initialize(ctx, genState.GetStdlibs(), params.AllowedPublishers, params.BaseDenom); err != nil {

Check warning on line 93 in x/move/keeper/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/move/keeper/genesis.go#L93

Added line #L93 was not covered by tests
return err
}
}
Expand Down
42 changes: 42 additions & 0 deletions x/move/keeper/staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,48 @@ func TestInstantUnbondFromBondedValidator(t *testing.T) {
require.True(t, val.IsUnbonding())
}

func TestApplyStakingDeltas_BaseDenom(t *testing.T) {
ctx, input := createDefaultTestInput(t)

// add second BondDenom to staking keeper
input.StakingKeeper.SetBondDenoms(ctx, []string{bondDenom})

// initialize staking
valAddr := createValidatorWithBalance(t, ctx, input, 100_000_000, 100_000)

// mint not possible for lp coin, so transfer from the 0x2
_, _, addr := keyPubAddr()
input.Faucet.Mint(ctx, addr, sdk.NewCoin(bondDenom, math.NewInt(100_000_000)))

// delegate coins via move staking module
valAddrArg, err := vmtypes.SerializeString(valAddr.String())
require.NoError(t, err)

amountArg, err := vmtypes.SerializeUint64(50_000_000)
require.NoError(t, err)

metadataAddr, err := types.MetadataAddressFromDenom(bondDenom)
require.NoError(t, err)

vmAddr, err := vmtypes.NewAccountAddressFromBytes(addr)
require.NoError(t, err)
err = input.MoveKeeper.ExecuteEntryFunction(
ctx,
vmAddr,
vmtypes.StdAddress,
types.MoveModuleNameStaking,
types.FunctionNameStakingDelegateScript,
[]vmtypes.TypeTag{},
[][]byte{metadataAddr[:], valAddrArg, amountArg},
)
require.NoError(t, err)

delModuleAddr := types.GetDelegatorModuleAddress(valAddr)
delegation, err := input.StakingKeeper.GetDelegation(ctx, delModuleAddr, valAddr)
require.NoError(t, err)
require.Equal(t, delegation.Shares, sdk.NewDecCoins(sdk.NewDecCoin(bondDenom, math.NewInt(50_000_000))))
}

func TestApplyStakingDeltas(t *testing.T) {
ctx, input := createDefaultTestInput(t)

Expand Down
2 changes: 1 addition & 1 deletion x/mstaking/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func _createTestInput(
moduleBytes, err := precompile.ReadStdlib()
require.NoError(t, err)

err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.AllowedPublishers)
err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.AllowedPublishers, bondDenom)
require.NoError(t, err)

faucet := NewTestFaucet(t, ctx, bankKeeper, *moveKeeper, authtypes.Minter, initialTotalSupply()...)
Expand Down
2 changes: 1 addition & 1 deletion x/reward/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func _createTestInput(
moduleBytes, err := precompile.ReadStdlib()
require.NoError(t, err)

err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.AllowedPublishers)
err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.AllowedPublishers, bondDenom)
require.NoError(t, err)

faucet := NewTestFaucet(t, ctx, bankKeeper, *moveKeeper, authtypes.Minter, initialTotalSupply()...)
Expand Down
2 changes: 1 addition & 1 deletion x/slashing/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ func _createTestInput(
moduleBytes, err := precompile.ReadStdlib()
require.NoError(t, err)

err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.AllowedPublishers)
err = moveKeeper.Initialize(ctx, moduleBytes, moveParams.AllowedPublishers, bondDenom)
require.NoError(t, err)

faucet := NewTestFaucet(t, ctx, bankKeeper, *moveKeeper, authtypes.Minter, initialTotalSupply()...)
Expand Down

0 comments on commit f4ddc27

Please sign in to comment.