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

Add anonymous func test helpers to packet tests #4555

Closed
damiannolan opened this issue Sep 4, 2023 · 0 comments · Fixed by #4980
Closed

Add anonymous func test helpers to packet tests #4555

damiannolan opened this issue Sep 4, 2023 · 0 comments · Fixed by #4980
Labels
testing Testing package and unit/integration tests type: code hygiene Clean up code but without changing functionality or interfaces type: refactor Architecture, code or CI improvements that may or may not tackle technical debt.

Comments

@damiannolan
Copy link
Contributor

damiannolan commented Sep 4, 2023

As suggested by @colin-axner in #4472

Introduce test helpers to reduce the amount of boilerplate code used in packet tests.

assertSuccess := func(commitment []byte, err error) {
    suite.Require().NoError(err)
    suite.Require().Nil(commitment)
    
    nextSequenceAck, found := suite.chainA.App.GetIBCKeeper().ChannelKeeper.GetNextSequenceAck(suite.chainA.GetContext(), packet.GetSourcePort(), packet.GetSourceChannel())
	
    suite.Require().True(found)
    suite.Require().Equal(uint64(1), nextSequenceAck, "sequence incremented for UNORDERED channel")
}

assertNoOp := func(commitment []byte, err error) {
    suite.Require().Error(err)
    suite.Require().ErrorIs(err, types.ErrNoOpMsg)
    suite.Require().Nil(commitment)
}

errorIs := func(expError error) func(commitment []byte, err error) {
    return  func(commitment []byte, err error) {
    suite.Require().Error(err)
    suite.Require().ErrorIs(err, types.ErrNoOpMsg)
    suite.Require().NotNil(commitment)
    }
}

// define test cases

expResult: assertSuccess
...

expResult: assertNoOp
...

expResult: errorIs(channeltypes.ErrChannelNotFound)

maybe in another followup if we like

Originally posted by @colin-axner in #4472 (comment)

@damiannolan damiannolan added testing Testing package and unit/integration tests type: code hygiene Clean up code but without changing functionality or interfaces type: refactor Architecture, code or CI improvements that may or may not tackle technical debt. labels Sep 4, 2023
@damiannolan damiannolan moved this to Backlog in ibc-go Sep 4, 2023
@github-project-automation github-project-automation bot moved this from Backlog to Done in ibc-go Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Testing package and unit/integration tests type: code hygiene Clean up code but without changing functionality or interfaces type: refactor Architecture, code or CI improvements that may or may not tackle technical debt.
Projects
Status: Done 🥳
Development

Successfully merging a pull request may close this issue.

1 participant