-
Notifications
You must be signed in to change notification settings - Fork 607
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
Write test for AddEpochInfo #1895
Changes from 3 commits
cd515c4
59449be
bbb8c18
b862f67
b2a1ec6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,60 @@ import ( | |
"github.com/osmosis-labs/osmosis/v7/x/epochs/types" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestAddEpochInfo() { | ||
defaultIdentifier := "default_add_epoch_info_id" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These might better be consts since these never change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eh, I'm not sure I really buy into the notion that const vs not const matters for variables at the top of a test. If it was file-wide, I'd totally agree |
||
defaultDuration := time.Hour | ||
startBlockHeight := int64(100) | ||
startBlockTime := time.Unix(1656907200, 0).UTC() | ||
tests := map[string]struct { | ||
addedEpochInfo types.EpochInfo | ||
expErr bool | ||
expEpochInfo types.EpochInfo | ||
}{ | ||
"simple_add": {addedEpochInfo: types.EpochInfo{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think formatting might be off here. Should this be on the next line? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah whole tests fields' formatting would be better fixed before merging! |
||
Identifier: defaultIdentifier, | ||
StartTime: time.Time{}, | ||
Duration: defaultDuration, | ||
CurrentEpoch: 0, | ||
CurrentEpochStartHeight: 0, | ||
CurrentEpochStartTime: time.Time{}, | ||
EpochCountingStarted: false, | ||
}, expErr: false, | ||
expEpochInfo: types.EpochInfo{ | ||
Identifier: defaultIdentifier, | ||
StartTime: startBlockTime, | ||
Duration: defaultDuration, | ||
CurrentEpoch: 0, | ||
CurrentEpochStartHeight: startBlockHeight, | ||
CurrentEpochStartTime: time.Time{}, | ||
EpochCountingStarted: false, | ||
}}, | ||
} | ||
for name, test := range tests { | ||
suite.Run(name, func() { | ||
suite.SetupTest() | ||
suite.Ctx = suite.Ctx.WithBlockHeight(startBlockHeight).WithBlockTime(startBlockTime) | ||
err := suite.App.EpochsKeeper.AddEpochInfo(suite.Ctx, test.addedEpochInfo) | ||
if !test.expErr { | ||
suite.Require().NoError(err) | ||
actualEpochInfo := suite.App.EpochsKeeper.GetEpochInfo(suite.Ctx, test.addedEpochInfo.Identifier) | ||
suite.Require().Equal(test.expEpochInfo, actualEpochInfo) | ||
} else { | ||
suite.Require().Error(err) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you planning to add more tests? I don't see one with an error expected There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imo, I think the only notable errror for |
||
}) | ||
} | ||
} | ||
|
||
func (suite *KeeperTestSuite) TestDuplicateAddEpochInfo() { | ||
identifier := "duplicate_add_epoch_info" | ||
epochInfo := types.NewGenesisEpochInfo(identifier, time.Hour*24*30) | ||
err := suite.App.EpochsKeeper.AddEpochInfo(suite.Ctx, epochInfo) | ||
suite.Require().NoError(err) | ||
err = suite.App.EpochsKeeper.AddEpochInfo(suite.Ctx, epochInfo) | ||
suite.Require().Error(err) | ||
} | ||
|
||
func (suite *KeeperTestSuite) TestEpochLifeCycle() { | ||
suite.SetupTest() | ||
|
||
|
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.
InitGenesis basically just shells out to AddEpochInfo. Error on duplicate is tested in its TestEpochsInitGenesis already!