Skip to content

Commit

Permalink
test: add tests for types (#157)
Browse files Browse the repository at this point in the history
* test: add TestPlanI

* test: add TestBasePlanValidate

* test: add TestIsPlanActiveAt

* fix: fix proposal validation logic

- fix nil pointer dereference issue

* test: add TestValidateStakingCoinTotalWeights

* test: add tests for proposal validation

* test: change expected error messages
  • Loading branch information
hallazzang authored Oct 6, 2021
1 parent d70949c commit cac3415
Show file tree
Hide file tree
Showing 5 changed files with 823 additions and 24 deletions.
8 changes: 4 additions & 4 deletions x/farming/keeper/proposal_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (suite *KeeperTestSuite) TestValidateAddPublicPlanProposal() {
sdk.NewCoins(sdk.NewInt64Coin(denom3, 1)),
sdk.NewDec(1),
)},
sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "either epoch amount or epoch ratio should be provided"),
sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "only one of epoch amount or epoch ratio must be provided"),
},
{
"epoch amount & epoch ratio case #2",
Expand All @@ -142,7 +142,7 @@ func (suite *KeeperTestSuite) TestValidateAddPublicPlanProposal() {
sdk.NewCoins(),
sdk.ZeroDec(),
)},
sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "either epoch amount or epoch ratio must not be zero"),
sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "only one of epoch amount or epoch ratio must be provided"),
},
} {
suite.Run(tc.name, func() {
Expand Down Expand Up @@ -320,7 +320,7 @@ func (suite *KeeperTestSuite) TestValidateUpdatePublicPlanProposal() {
sdk.NewCoins(sdk.NewInt64Coin("stake", 100_000)),
plan.(*types.RatioPlan).EpochRatio,
)},
sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "either epoch amount or epoch ratio should be provided"),
sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "only one of epoch amount or epoch ratio must be provided"),
},
{
"epoch amount & epoch ratio case #2",
Expand All @@ -336,7 +336,7 @@ func (suite *KeeperTestSuite) TestValidateUpdatePublicPlanProposal() {
sdk.NewCoins(sdk.NewInt64Coin("stake", 0)),
sdk.ZeroDec(),
)},
sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "either epoch amount or epoch ratio must not be zero"),
sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "only one of epoch amount or epoch ratio must be provided"),
},
} {
suite.Run(tc.name, func() {
Expand Down
6 changes: 3 additions & 3 deletions x/farming/types/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ func (plan BasePlan) Validate() error {
if !plan.EndTime.After(plan.StartTime) {
return sdkerrors.Wrapf(ErrInvalidPlanEndTime, "end time %s must be greater than start time %s", plan.EndTime, plan.StartTime)
}
if plan.DistributedCoins.IsAnyNegative() {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "distributed coins must not be negative")
if err := plan.DistributedCoins.Validate(); err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "invalid distributed coins: %v", err)
}
return nil
}
Expand All @@ -201,7 +201,7 @@ func (plan BasePlan) String() string {
return out.(string)
}

// MarshalYAML returns the YAML representation of an Plan.
// MarshalYAML returns the YAML representation of a Plan.
func (plan BasePlan) MarshalYAML() (interface{}, error) {
bz, err := codec.MarshalYAML(codec.NewProtoCodec(codectypes.NewInterfaceRegistry()), &plan)
if err != nil {
Expand Down
Loading

0 comments on commit cac3415

Please sign in to comment.