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

Write test for AddEpochInfo #1895

merged 5 commits into from
Jun 30, 2022

Conversation

ValarDragon
Copy link
Member

Closes: #1834

What is the purpose of the change

Adds a table driven test for AddEpochInfo functionality, and a unit test for its behavior on duplicates.

This is part of followup from #1893

Testing and Verifying

This change added tests

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes? no
  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.md?no
  • How is the feature or change documented? not applicable

@ValarDragon ValarDragon requested a review from a team June 29, 2022 14:25
Comment on lines -20 to -21
//
// TODO: Make a new test for init genesis logic
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!

Copy link
Member

@p0mvn p0mvn left a comment

Choose a reason for hiding this comment

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

LGTM overall, just some nits and a question about more tests for table-driven setup

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!

x/epochs/keeper/epoch_test.go Outdated Show resolved Hide resolved
@@ -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

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

Copy link
Member

@mattverse mattverse left a comment

Choose a reason for hiding this comment

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

I think a check before merging on the testing format would help, but other than that LGTM!

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.

yeah whole tests fields' formatting would be better fixed before merging!

suite.Require().Equal(test.expEpochInfo, actualEpochInfo)
} else {
suite.Require().Error(err)
}
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

@ValarDragon
Copy link
Member Author

Fixed formatting, added a zero duration test

@ValarDragon ValarDragon merged commit 76344cd into main Jun 30, 2022
@ValarDragon ValarDragon deleted the dev/add_epoch_info_test branch June 30, 2022 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

x/Epochs - internal audit & documentation
4 participants