-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from osmosis-labs/anmol/params-genesis
Add params setting via genesis
- Loading branch information
Showing
9 changed files
with
624 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
syntax = "proto3"; | ||
package osmosis.meshsecurity.v1beta1; | ||
|
||
import "osmosis/meshsecurity/v1beta1/meshsecurity.proto"; | ||
import "gogoproto/gogo.proto"; | ||
import "amino/amino.proto"; | ||
|
||
option go_package = "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/types"; | ||
option (gogoproto.goproto_getters_all) = false; | ||
option (gogoproto.equal_all) = false; | ||
|
||
// GenesisState defines meshsecurity module's genesis state. | ||
message GenesisState { | ||
option (gogoproto.equal) = true; | ||
|
||
Params params = 1 | ||
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/types" | ||
) | ||
|
||
func (k Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) { | ||
if err := k.SetParams(ctx, data.Params); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { | ||
params := k.GetParams(ctx) | ||
return types.NewGenesisState(params) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package keeper | ||
|
||
import ( | ||
"cosmossdk.io/math" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
|
||
"github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/types" | ||
) | ||
|
||
func TestInitGenesis(t *testing.T) { | ||
specs := map[string]struct { | ||
state types.GenesisState | ||
expErr bool | ||
}{ | ||
"custom param, should pass": { | ||
state: types.GenesisState{ | ||
Params: types.Params{ | ||
TotalContractsMaxCap: sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(15_000_000_000)), | ||
EpochLength: 2_000, | ||
MaxGasEndBlocker: 600_000, | ||
}, | ||
}, | ||
expErr: false, | ||
}, | ||
"custom small value param, should pass": { | ||
state: types.GenesisState{ | ||
Params: types.Params{ | ||
TotalContractsMaxCap: sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(1_000_000)), | ||
EpochLength: 20, | ||
MaxGasEndBlocker: 10_000, | ||
}, | ||
}, | ||
expErr: false, | ||
}, | ||
} | ||
|
||
for name, spec := range specs { | ||
t.Run(name, func(t *testing.T) { | ||
pCtx, keepers := CreateDefaultTestInput(t) | ||
k := keepers.MeshKeeper | ||
|
||
k.InitGenesis(pCtx, spec.state) | ||
|
||
p := k.GetParams(pCtx) | ||
assert.Equal(t, spec.state.Params.MaxGasEndBlocker, p.MaxGasEndBlocker) | ||
assert.Equal(t, spec.state.Params.EpochLength, p.EpochLength) | ||
assert.Equal(t, spec.state.Params.TotalContractsMaxCap, p.TotalContractsMaxCap) | ||
}) | ||
} | ||
} | ||
|
||
func TestExportGenesis(t *testing.T) { | ||
pCtx, keepers := CreateDefaultTestInput(t) | ||
k := keepers.MeshKeeper | ||
params := types.DefaultParams(sdk.DefaultBondDenom) | ||
|
||
err := k.SetParams(pCtx, params) | ||
require.NoError(t, err) | ||
|
||
exported := k.ExportGenesis(pCtx) | ||
assert.Equal(t, params.MaxGasEndBlocker, exported.Params.MaxGasEndBlocker) | ||
assert.Equal(t, params.EpochLength, exported.Params.EpochLength) | ||
assert.Equal(t, params.TotalContractsMaxCap, exported.Params.TotalContractsMaxCap) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package types | ||
|
||
func NewGenesisState(params Params) *GenesisState { | ||
return &GenesisState{ | ||
Params: params, | ||
} | ||
} | ||
|
||
func DefaultGenesisState(denom string) *GenesisState { | ||
return NewGenesisState(DefaultParams(denom)) | ||
} | ||
|
||
func ValidateGenesis(gs *GenesisState) error { | ||
return gs.Params.ValidateBasic() | ||
} |
Oops, something went wrong.