-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Implement InitGenesis for staking #772
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #772 +/- ##
==========================================
- Coverage 63.28% 63.19% -0.1%
==========================================
Files 62 62
Lines 3315 3323 +8
==========================================
+ Hits 2098 2100 +2
- Misses 1069 1072 +3
- Partials 148 151 +3 |
f1ebd67
to
7d67d00
Compare
Also ref #724 Awaiting consensus on |
just rebased |
382aa7c
to
8fad09a
Compare
Rebased. Awaiting finalization of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lookin' good let's just refine a bit more before merge
x/stake/keeper.go
Outdated
@@ -343,8 +356,7 @@ func (k Keeper) GetParams(ctx sdk.Context) (params Params) { | |||
store := ctx.KVStore(k.storeKey) | |||
b := store.Get(ParamKey) | |||
if b == nil { | |||
k.params = defaultParams() | |||
return k.params | |||
panic(errors.New("Stored params should not have been nil")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not need to use errors.New
here (https://play.golang.org/p/skq8dkMt8fd)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed.
x/stake/keeper.go
Outdated
@@ -374,7 +386,7 @@ func (k Keeper) GetPool(ctx sdk.Context) (gs Pool) { | |||
store := ctx.KVStore(k.storeKey) | |||
b := store.Get(PoolKey) | |||
if b == nil { | |||
return initialPool() | |||
panic(errors.New("Stored pool should not have been nil")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -28,6 +30,17 @@ func NewKeeper(ctx sdk.Context, cdc *wire.Codec, key sdk.StoreKey, ck bank.CoinK | |||
return keeper | |||
} | |||
|
|||
// InitGenesis - store genesis parameters | |||
func (k Keeper) InitGenesis(ctx sdk.Context, data json.RawMessage) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a test function for InitGenesis (which can take a json.RawMessage
defined in test taken from a hardcoded string)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good start to have
encoded, err := json.Marshal(GenesisState{initialPool(), defaultParams()})
if err != nil {
panic(err)
}
if err = keeper.InitGenesis(ctx, encoded); err != nil {
panic(err)
}
But I'd like to see the test with the raw string information (as in the genesis.json file) being turned into the json raw message... this will give us an idea as to what are genesis file will actually look like here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, added test with raw string.
x/stake/test_common.go
Outdated
} | ||
if err = keeper.InitGenesis(ctx, encoded); err != nil { | ||
panic(err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I notice here that the InitGenesis functionality is almost "tested" here... let's move this to a separate explicit test for InitGenesis (aka TestInitGenesis
) in keeper_test.go
and replace lines 152-158 with:
k.setPool(ctx, state.Pool)
k.setParams(ctx, state.Params)
The function createTestInput is not really supposed to a test itself just a helper for other actual tests hence it's not in a _test.go
file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, moved to TestInitGenesis
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, did a minor cleanup on TestInitGenesis
Ref #737
Awaiting rebase of
rigel/tick-tests
ontodevelop
Still need to write initial genesis info on
basecoind init
/democoind init