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

refactor: use expResult in acknowledgePacket tests (#4439) #4472

Merged
merged 7 commits into from
Sep 4, 2023

Conversation

damiannolan
Copy link
Member

Description

Cherry-pick 9c54f23 to main, minus the channel-upgradability diffs

closes: #XXXX


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md).
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Provide a commit message to be used for the changelog entry in the PR description for review.
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

* refactor: adapt acknowledgePacket tests to use expResult func

* cleanup: removing redundant stale tests

* fix: assert ErrInvalidProof for verification failure. modify suite.Run tc naming
@damiannolan damiannolan added the testing Testing package and unit/integration tests label Aug 28, 2023
Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

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

Nice! LGTM! See my comments for various improvements that can still be made to the test at some point

expResult: func(commitment []byte, err error) {
suite.Require().Error(err)
suite.Require().ErrorIs(err, types.ErrChannelNotFound)
suite.Require().Nil(commitment)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this test will still need some more love. commitment should be NotNil for this test case (but it is never set)

Copy link
Member Author

@damiannolan damiannolan Aug 31, 2023

Choose a reason for hiding this comment

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

Glad to see you're on your toes this morning! 😛

I was hoping you'd catch this - so, yes, the commitment should not be nil. However, above in malleate() we modify srcPort and srchChannel such that they are invalid IDs and commitment lookup in the test body uses packet.GetSourcePort and packet.GetSourceChannel.

I can look at refactoring the tests some more but I didn't want to change too much logic in this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added more love in 1c5e64b

Comment on lines +723 to +728
suite.Require().NoError(err)
suite.Require().Nil(commitment)

// create packet commitment
sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData)
suite.Require().NoError(err)
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")
Copy link
Contributor

Choose a reason for hiding this comment

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

feels like we could create some helper expResult functions:

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice suggestion! I'm on board, but maybe best in another follow up

Copy link
Member Author

Choose a reason for hiding this comment

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

created #4555

modules/core/04-channel/keeper/packet_test.go Show resolved Hide resolved
modules/core/04-channel/keeper/packet_test.go Outdated Show resolved Hide resolved
@damiannolan
Copy link
Member Author

damiannolan commented Sep 4, 2023

Seems to be odd runner activity at the moment causing random failures.

Error: Can’t use ‘tar -xzf’ extract archive file: /home/runner/work/_actions/_temp_50add5ff-6f54-445d-93ec-b0bfd4e51ce0/023375c1-35f6-4ea6-93f4-19688d311b0c.tar.gz. return code: 2.

Once CI is passing, we can get this merged 👍

edit: spamming rerun got me there in the end

@damiannolan damiannolan enabled auto-merge (squash) September 4, 2023 16:36
@damiannolan damiannolan merged commit 77156e3 into main Sep 4, 2023
21 of 22 checks passed
@damiannolan damiannolan deleted the damian/acknowledge-packet-test-refactor branch September 4, 2023 16:40
@muku314115 muku314115 mentioned this pull request Oct 29, 2023
9 tasks
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants