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

Cleanup mock context for ICS3 #298

Merged
merged 12 commits into from
Oct 12, 2020
Merged

Cleanup mock context for ICS3 #298

merged 12 commits into from
Oct 12, 2020

Conversation

adizere
Copy link
Member

@adizere adizere commented Oct 8, 2020

Closes: #295

Description


For contributor use:

  • Unit tests written
  • Added test to CI if applicable
  • Updated CHANGELOG_PENDING.md
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Updated relevant documentation (docs/) and code comments
  • Re-reviewed Files changed in the Github PR explorer

@adizere adizere changed the title Cleanup mock context for ICS2 Cleanup mock context for ICS3 Oct 8, 2020
@adizere adizere self-assigned this Oct 8, 2020
@codecov-io
Copy link

Codecov Report

Merging #298 into master will increase coverage by 23.3%.
The diff coverage is 61.1%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #298      +/-   ##
=========================================
+ Coverage    13.6%   37.0%   +23.3%     
=========================================
  Files          69     121      +52     
  Lines        3752    7828    +4076     
  Branches     1374    2761    +1387     
=========================================
+ Hits          513    2897    +2384     
- Misses       2618    4625    +2007     
+ Partials      621     306     -315     
Impacted Files Coverage Δ
modules/src/events.rs 0.0% <0.0%> (ø)
modules/src/ics02_client/events.rs 0.0% <ø> (ø)
modules/src/ics02_client/raw.rs 0.0% <0.0%> (ø)
modules/src/ics03_connection/context.rs 0.0% <0.0%> (ø)
modules/src/ics03_connection/error.rs 16.6% <0.0%> (-16.7%) ⬇️
modules/src/ics04_channel/error.rs 75.0% <ø> (+50.0%) ⬆️
modules/src/ics04_channel/packet.rs 0.0% <0.0%> (ø)
modules/src/ics07_tendermint/client_def.rs 0.0% <0.0%> (ø)
modules/src/ics07_tendermint/error.rs 75.0% <ø> (+75.0%) ⬆️
modules/src/ics18_relayer/error.rs 0.0% <0.0%> (ø)
... and 220 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6fe7366...f87826f. Read the comment docs.

@adizere adizere marked this pull request as ready for review October 9, 2020 09:48
@romac
Copy link
Member

romac commented Oct 9, 2020

Aside from the build failing, this looks good!

Copy link
Collaborator

@ancazamfir ancazamfir left a comment

Choose a reason for hiding this comment

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

Looks good! A few comments but we can also make changes later.

modules/src/mock_context.rs Outdated Show resolved Hide resolved
Comment on lines 57 to 69
pub fn with_connection(
self,
connection_id: ConnectionId,
connection_end: ConnectionEnd,
) -> Self {
let mut connections = self.connections.clone();
connections.insert(connection_id, connection_end);
Self {
connections,
..self
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Wondering if we should check for sanity for the context, even if it's mock, just to make sure the tests don't initialize with a bad context. For example check that the client of a connection is present. Could also add the connection to client here.
I am also wondering if we should allow for a vector of connections, i.e. call it with_connections().

Copy link
Member Author

Choose a reason for hiding this comment

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

I am also wondering if we should allow for a vector of connections, i.e. call it with_connections().

I'm slowly expanding the mocks to support more and more capabilities. So it's quite likely that we'll have such a function with_connections, which will enable more complex test cases. I can do that in the next iteration of mock refurbishing (i.e., for #296).

Wondering if we should check for sanity for the context, even if it's mock, just to make sure the tests don't initialize with a bad context. For example check that the client of a connection is present. Could also add the connection to client here.

Hmm, not sure I understand. Maybe this would be a good use case, indeed, but as I understand the mock context, its purpose is to support testing of handlers (and not more than that at the moment). So I would not add too much logic, validation, or any kind of support, unless it is to exercise more paths in the codebase.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, not sure I understand. Maybe this would be a good use case, indeed, but as I understand the mock context, its purpose is to support testing of handlers (and not more than that at the moment). So I would not add too much logic, validation, or any kind of support, unless it is to exercise more paths in the codebase.

Exactly, but in tests we always want to start with a correct context. This becomes harder to setup correctly with a more complex initial state.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm slowly expanding the mocks to support more and more capabilities. So it's quite likely that we'll have such a function with_connections, ....

This is would be the same as with_connection, just pass a slice and do a loop.

Copy link
Member Author

Choose a reason for hiding this comment

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

Now I understand! Will track these two suggestions in the other iteration on this work (#297 (comment)).

modules/src/mock_context.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@ancazamfir ancazamfir left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks Adi!

Comment on lines +51 to +53
connections: Default::default(),
clients: Default::default(),
client_connections: Default::default(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
connections: Default::default(),
clients: Default::default(),
client_connections: Default::default(),
clients: Default::default(),
client_connections: Default::default(),
connections: Default::default(),

@adizere adizere merged commit a8ffca2 into master Oct 12, 2020
@adizere adizere deleted the adi/295_ics3_cleanup branch October 12, 2020 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cleaner context mocks for ICS3
4 participants