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

test: add unit tests for channel upgrade event emission #5475

Conversation

charleenfei
Copy link
Contributor

Description

closes: #3497

Commit Message / Changelog Entry

type: commit message

see the guidelines for commit messages. (view raw markdown for examples)


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 the 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.

DimitrisJim and others added 30 commits June 28, 2023 16:05
* Add ChanUpgradeOpen core handler.

* Tests tests tests.

* Update upgrade open handler based on feedback.

* Reformat testing approach.

* Move counterpartyhops assignment inline.

* Check err of SetChannelState.

* Address feedback.

* Remove uneeded modification of version.
* chore: adding check for in flight packets in WriteUpgradeAckChannel

* added test for TestWriteUpgradeAckChannel

* linter

* add client update to UpgradeAckChannel test

* mv test

* merge

* fix post-merge

* fix merge issues

* review comment

---------

Co-authored-by: Charly <charly@interchain.berlin>
Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
…3895)

* Add implementation for message server handling of ChanUpgradeOpen.

* Add tests for msg_server.

* Address review feedback.

* Remove setting of flush status.

* Apply suggestions from code review

Co-authored-by: Damian Nolan <damiannolan@gmail.com>

* Address rest of review comments.

---------

Co-authored-by: Damian Nolan <damiannolan@gmail.com>
* chore: update abort upgrade function to panic on error

* apply review suggestions

---------

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
* Amend Ack packet to keep acknowledging if we're in the process of flushing pre-upgrade packets.

* Use handshake to reach correct state before mutating any fields.

* Add test to verify post-ack channel state after last in-flight packet.

* Remove unecessary modifications of version for non initializing channel end.

* Test both cases: final in-flight packet and non-final one.

* Apply suggestions from code review

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>

* Remove manual setting of flush status.

* Update test name, pass mock version to both channels.

---------

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
* Amend timeout to handle in-flight packets.

* Update timeout handler per spec.

* Update tests to test for toggling of flush status.

* Fix small typos in docstring.

---------

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
…UpgradeOpen. (#4052)

* Pass in counterparty portid, channelid.

* use direct check on err.

* Force distinct channel identifiers when testing UpgradeOpen.
…4019)

* WIP: adding fee upgrade cbs and testing

* imp: allow failure expectations when using chain.SendMsgs

* fixing import errors from cherry-pick

* updating tests and rm try code

* rm diff onChanUpgradeTry

* Update modules/apps/29-fee/ibc_middleware.go

* adding MetadataFromVersion func to pkg types

* addressing pr feedback, disable fees on err, rename args, adding testcase

* Update modules/apps/29-fee/ibc_middleware_test.go

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>

* abstract out expIsFeeEnabled check in tests

* adding additional error context to MetadataFromVersion

---------

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
…4023)

* WIP: adding fee upgrade cbs and testing

* imp: allow failure expectations when using chain.SendMsgs

* fixing import errors from cherry-pick

* updating tests and rm try code

* rm diff onChanUpgradeTry

* Update modules/apps/29-fee/ibc_middleware.go

* adding OnChanUpgradeTry implementation for 29-fee, adding tests

* rm CR in test expectation

* remove goconst linter as discussed async

* adding MetadataFromVersion func to pkg types

* addressing pr feedback, disable fees on err, rename args, adding testcase

* Update modules/apps/29-fee/ibc_middleware_test.go

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>

* abstract out expIsFeeEnabled check in tests

* adding additional error context to MetadataFromVersion

* propagate changes from onChanUpgradeInit PR

* addressing test assertion feedback

---------

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
…4028)

* WIP: adding fee upgrade cbs and testing

* imp: allow failure expectations when using chain.SendMsgs

* fixing import errors from cherry-pick

* updating tests and rm try code

* rm diff onChanUpgradeTry

* Update modules/apps/29-fee/ibc_middleware.go

* adding OnChanUpgradeTry implementation for 29-fee, adding tests

* rm CR in test expectation

* remove goconst linter as discussed async

* adding onChanUpgradeAck implementation to 29-fee, adding tests

* adding MetadataFromVersion func to pkg types

* addressing pr feedback, disable fees on err, rename args, adding testcase

* Update modules/apps/29-fee/ibc_middleware_test.go

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>

* abstract out expIsFeeEnabled check in tests

* adding additional error context to MetadataFromVersion

* propagate changes from onChanUpgradeInit PR

* addressing test assertion feedback

* updating to use types.MetadataFromVersion in OnChanUpgradeAck

* updating tests to add additional checks

---------

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
* use counterparty conn hops.

* Clean up tests.

* Amend inline comment slightly.

* Address nits

---------

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
…gradeAck. (#4075)

* Move channel to OPEN if all in-flight packets have been flushed in UpgradeAck.

* Add comment noting that counterparty flush status has been verified before usage.

* Fix failing tests.
* adding transfer checks in upgrade cbs

* adding tests and reduce diff by moving code out

* add additional assertion on upgrade stored in state

* lint: single var declaration instead of block

* rename version -> upgradeVersion

* Update modules/apps/transfer/ibc_module_test.go

* rename sequence -> upgradeSequence

* updating to use NewTranferPath in test func

* address pr comment - reformat error msg
@charleenfei charleenfei changed the base branch from 04-channel-upgrades to main January 4, 2024 21:32
@charleenfei charleenfei marked this pull request as ready for review January 4, 2024 21:56
Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

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

Excellent work, @charleenfei!

modules/core/keeper/msg_server.go Show resolved Hide resolved
Copy link
Contributor

@DimitrisJim DimitrisJim left a comment

Choose a reason for hiding this comment

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

lgtm! ✨ One event I'm noticing isn't checked is the one emitted when writting error receipt. Home for this check could be in msg_server_test and/or in core? Maybe we could move expected events in the malleate for Try (which emits it).

Fine if this is done in follow up or you wanna push it here.

sdk.AttributeKeyModule: channeltypes.AttributeValueCategory,
},
}
ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events)
Copy link
Contributor

Choose a reason for hiding this comment

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

guess this can be follow up at some point but this and AssertEvents are sorta confusing as options and their docustring aren't as helpful, it seems like we should have one way to ideally check for events in tests.

Copy link
Member

Choose a reason for hiding this comment

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

Any ideas on the difference between the two so I don't have to check the code?

It seems also odd to have to pass the Suite as an argument. An instance of testing.T could be passed, or an error return should be fine too.

In any case, I think these event testing functions has been around for a while. We can give them some attention in a follow up as you suggested! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the EventsLegacy function handles sdk.Events, whereas Events handles ABCI events (typed array), we can double check these later agreed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add a follow up PR for error receipt events @DimitrisJim to make reviewing easier! thanks <3

Copy link
Contributor

Choose a reason for hiding this comment

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

AssertEvents was added when we were upgrading to SDK v0.50 to be able to assert the events in this test, if I remember correctly. Now that we are in SDK v0.50 I think we move to AssertEvents and remove AssertEventsLegacy and also the EventsMap type alias.

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for context @crodriguezvega! I'll open an issue to keep track of this.

Copy link
Member

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

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

Thanks @charleenfei!

I can push a commit to remove the upgrade found check.

modules/core/04-channel/keeper/upgrade.go Outdated Show resolved Hide resolved
sdk.AttributeKeyModule: channeltypes.AttributeValueCategory,
},
}
ibctesting.AssertEventsLegacy(&suite.Suite, expEvents, events)
Copy link
Member

Choose a reason for hiding this comment

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

Any ideas on the difference between the two so I don't have to check the code?

It seems also odd to have to pass the Suite as an argument. An instance of testing.T could be passed, or an error return should be fine too.

In any case, I think these event testing functions has been around for a while. We can give them some attention in a follow up as you suggested! :)

modules/core/keeper/msg_server.go Outdated Show resolved Hide resolved
@charleenfei charleenfei merged commit dc99ee4 into main Jan 8, 2024
61 checks passed
@charleenfei charleenfei deleted the charly/issue#3497-add-unit-tests-for-channel-upgrade-event-emission branch January 8, 2024 15:59
mergify bot pushed a commit that referenced this pull request Jan 8, 2024
colin-axner pushed a commit that referenced this pull request Jan 8, 2024
(cherry picked from commit dc99ee4)

Co-authored-by: Charly <charly@interchain.io>
@DimitrisJim DimitrisJim mentioned this pull request Jan 9, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
channel-upgradability Channel upgradability feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Unit Tests for Channel Upgrade Event Emission