-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add genesis functionality (#87)
* feat: add genesis functionality * fix: set staking index when initializing genesis * test: add test codes for genesis * fix: lint issue Co-authored-by: Hanjun Kim <[email protected]>
- Loading branch information
1 parent
d721098
commit 6dea151
Showing
15 changed files
with
449 additions
and
320 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
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,68 @@ | ||
package keeper_test | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/tendermint/farming/x/farming/types" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestInitGenesis() { | ||
plans := []types.PlanI{ | ||
types.NewFixedAmountPlan( | ||
types.NewBasePlan( | ||
1, | ||
"", | ||
types.PlanTypePrivate, | ||
suite.addrs[0].String(), | ||
suite.addrs[0].String(), | ||
sdk.NewDecCoins( | ||
sdk.NewDecCoinFromDec(denom1, sdk.NewDecWithPrec(3, 1)), | ||
sdk.NewDecCoinFromDec(denom2, sdk.NewDecWithPrec(7, 1))), | ||
mustParseRFC3339("2021-07-30T00:00:00Z"), | ||
mustParseRFC3339("2021-08-30T00:00:00Z"), | ||
), | ||
sdk.NewCoins(sdk.NewInt64Coin(denom3, 1_000_000))), | ||
types.NewRatioPlan( | ||
types.NewBasePlan( | ||
2, | ||
"", | ||
types.PlanTypePublic, | ||
suite.addrs[0].String(), | ||
suite.addrs[0].String(), | ||
sdk.NewDecCoins( | ||
sdk.NewDecCoinFromDec(denom1, sdk.NewDecWithPrec(3, 1)), | ||
sdk.NewDecCoinFromDec(denom2, sdk.NewDecWithPrec(7, 1))), | ||
mustParseRFC3339("2021-07-30T00:00:00Z"), | ||
mustParseRFC3339("2021-08-30T00:00:00Z"), | ||
), | ||
sdk.MustNewDecFromStr("0.01")), | ||
} | ||
//for _, plan := range plans { | ||
// suite.keeper.SetPlan(suite.ctx, plan) | ||
//} | ||
suite.keeper.SetPlan(suite.ctx, plans[1]) | ||
suite.keeper.SetPlan(suite.ctx, plans[0]) | ||
|
||
suite.Stake(suite.addrs[1], sdk.NewCoins( | ||
sdk.NewInt64Coin(denom1, 1_000_000), | ||
sdk.NewInt64Coin(denom2, 1_000_000))) | ||
suite.keeper.ProcessQueuedCoins(suite.ctx) | ||
|
||
suite.ctx = suite.ctx.WithBlockTime(mustParseRFC3339("2021-07-31T00:00:00Z")) | ||
err := suite.keeper.DistributeRewards(suite.ctx) | ||
suite.Require().NoError(err) | ||
|
||
var genState *types.GenesisState | ||
suite.Require().NotPanics(func() { | ||
genState = suite.keeper.ExportGenesis(suite.ctx) | ||
}, | ||
) | ||
err = types.ValidateGenesis(*genState) | ||
suite.Require().NoError(err) | ||
|
||
suite.Require().NotPanics(func() { | ||
suite.keeper.InitGenesis(suite.ctx, *genState) | ||
}, | ||
) | ||
suite.Require().Equal(genState, suite.keeper.ExportGenesis(suite.ctx)) | ||
} |
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
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
Oops, something went wrong.