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 tests for callback execution when forwarding a packet #6805

Merged
merged 5 commits into from
Jul 18, 2024

Conversation

bznein
Copy link
Contributor

@bznein bznein commented Jul 11, 2024

Description

ref: #6578


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/).
  • Added relevant godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Include a descriptive changelog entry when appropriate. This may be left to the discretion of the PR reviewers. (e.g. chores should be omitted from changelog)
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

@@ -0,0 +1,182 @@
package ibccallbacks_test
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 had to add a new file here in the callbacks module because it's the only module in which we can check the callbacks counter. This required setting up a new, small test suite that creates 3 chains.

testCases := []struct {
name string
testMemo string
expCallbackMapOnChainB map[callbacktypes.CallbackType]int
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We discussed this with @chatton and our understanding is that when the memo specifies src_callback we expect the callback to be executed on B and not on C. basically when forwarding we ensure that all callbacks are executed on either the last hop (C) or the one immediately before that (B).

If that's not the case, please let me know! I was surprised to see some callbacks executed on B but after some reasoning it started to make sense.

Copy link
Member

Choose a reason for hiding this comment

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

With the current implementation it makes sense that this would be the case.. but it is a little weird imo.

Wonder if we should have a testcase for ensuring that the send_packet callback is never invoked on chainA

Copy link
Contributor

Choose a reason for hiding this comment

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

yea very strange, but I guess not much we can do. Would be great to add into the docs somewhere? With multi packetdata, it should become more explicit when and where callbacks are executed (hopefully 😅)

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 opened #6883 to ensure we document this properly

expCallbackMapOnChainC: map[callbacktypes.CallbackType]int{},
},
{
name: "recv callback",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's still not super clear to me what's the mapping between Memo content and which callbacks are executed. Does anyone have a pointer to learn this better?

Copy link
Contributor

Choose a reason for hiding this comment

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

the main thing is that the special keys in the callback data specify on which chain the callback should be executed.

Which is why that in this test case, it is only being executed on the dest chain. and not the src (which would be chain B in this case)

@bznein bznein marked this pull request as ready for review July 11, 2024 10:50
@crodriguezvega crodriguezvega added the priority PRs that need prompt reviews label Jul 11, 2024
Comment on lines +80 to +85
{
name: "ack callback",
testMemo: fmt.Sprintf(`{"src_callback": {"address": "%s"}}`, simapp.SuccessContract),
expCallbackMapOnChainB: map[callbacktypes.CallbackType]int{callbacktypes.CallbackTypeAcknowledgementPacket: 1},
expCallbackMapOnChainC: map[callbacktypes.CallbackType]int{},
},
Copy link
Contributor

@chatton chatton Jul 15, 2024

Choose a reason for hiding this comment

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

might be worth adding a memo that contains both src_callback and dest_callback, in the happy path I believe we should have

expCallbackMapOnChainB: map[callbacktypes.CallbackType]int{callbacktypes.CallbackTypeAcknowledgementPacket: 1}

expCallbackMapOnChainC: map[callbacktypes.CallbackType]int{callbacktypes.CallbackTypeReceivePacket: 1},

Copy link
Contributor

Choose a reason for hiding this comment

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

		{
			name:                   "ack and recv callback",
			testMemo:               fmt.Sprintf(`{"src_callback": {"address": "%s"}, "dest_callback": {"address": "%s"}}`, simapp.SuccessContract, simapp.SuccessContract),
			expCallbackMapOnChainB: map[callbacktypes.CallbackType]int{callbacktypes.CallbackTypeAcknowledgementPacket: 1},
			expCallbackMapOnChainC: map[callbacktypes.CallbackType]int{callbacktypes.CallbackTypeReceivePacket: 1},
		},

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good one thank you! added!

@bznein bznein requested a review from chatton July 15, 2024 16:08
Copy link

sonarcloud bot commented Jul 15, 2024

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.

Test code looks super clean, nice work.

I do find the flow a bit strange for invoking the source chain callbacks from an intermediary hop, but maybe that's fine. I think that should be documented and well understood tho.

I think it would be easy to assume "source chain callbacks on A" and "dest chain callbacks on C" as well

testCases := []struct {
name string
testMemo string
expCallbackMapOnChainB map[callbacktypes.CallbackType]int
Copy link
Member

Choose a reason for hiding this comment

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

With the current implementation it makes sense that this would be the case.. but it is a little weird imo.

Wonder if we should have a testcase for ensuring that the send_packet callback is never invoked on chainA

s.Require().NoError(err)

// We never expect chainA to have executed any callback
s.Require().Empty(GetSimApp(s.chainA).MockContractKeeper.Counters, "chainA's callbacks counter map is not empty")
Copy link
Member

Choose a reason for hiding this comment

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

maybe this covers my thoughts on any source chain callback being invoked on A!

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! The test looks good to me. It's a good note that the middlehop will now be used for the source callbacks. I don't really see a way to protect against that

@bznein bznein added this pull request to the merge queue Jul 18, 2024
Merged via the queue into main with commit 98183d9 Jul 18, 2024
67 of 69 checks passed
@bznein bznein deleted the bznein/6578/callbacksTest branch July 18, 2024 15:48
mergify bot pushed a commit that referenced this pull request Jul 18, 2024
* Add test for callbacks in forwarding scenario

* Add comments

* Lint

* Added test case.

(cherry picked from commit 98183d9)
crodriguezvega added a commit that referenced this pull request Jul 21, 2024
…kport #6805) (#6884)

* (test) Add tests for callback execution when forwarding a packet (#6805)

* Add test for callbacks in forwarding scenario

* Add comments

* Lint

* Added test case.

(cherry picked from commit 98183d9)

* Update forwarding_test.go

---------

Co-authored-by: Nikolas De Giorgis <nikolas.degiorgis@interchain.io>
Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-to-v9.0.x priority PRs that need prompt reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants