Skip to content
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

Merged
merged 5 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions x/epochs/keeper/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import (

// This test is responsible for testing how epochs increment based off
// of their initial conditions, and subsequent block height / times.
//
// TODO: Make a new test for init genesis logic
Comment on lines -20 to -21
Copy link
Member Author

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!

func (suite KeeperTestSuite) TestEpochInfoBeginBlockChanges() {
block1Time := time.Unix(1656907200, 0).UTC()
const defaultIdentifier = "hourly"
Expand Down
54 changes: 54 additions & 0 deletions x/epochs/keeper/epoch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,60 @@ import (
"github.com/osmosis-labs/osmosis/v7/x/epochs/types"
)

func (suite *KeeperTestSuite) TestAddEpochInfo() {
defaultIdentifier := "default_add_epoch_info_id"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These might better be consts since these never change

Copy link
Member Author

Choose a reason for hiding this comment

The 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{
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The 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)
}
Copy link
Member

@p0mvn p0mvn Jun 29, 2022

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo, I think the only notable errror for AddEpochInfo is the case for returning an error when there's a duplicate epoch identifier, which is tested in the test below

})
}
}

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()

Expand Down