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

feat: implement AllPools query in x/poolmanager #4659

Merged
merged 8 commits into from
Mar 20, 2023
Merged

Conversation

p0mvn
Copy link
Member

@p0mvn p0mvn commented Mar 17, 2023

Closes: #XXX

What is the purpose of the change

This PR introduces the AllPools function in x/poolmanager and a corresponding test suite to ensure its proper functionality. The AllPools function retrieves a sorted list of all pools from different pool modules in the Osmosis chain.

Key changes:

  • Implement the AllPools function, which returns a sorted list of all pools from different pool modules, sorted by their ids.
  • Add a LessFunc type for generic less functions and a MergeSlices utility function to efficiently merge two sorted slices into a single sorted slice.
  • Create a comprehensive test suite with table-driven tests to cover various scenarios, such as no pool modules, single pool modules, multiple pool modules with varying numbers of pools, and overlapping and duplicate pool ids.
  • Utilize GoMock to generate mocks for the PoolModuleI interface and inject them into the pool manager for testing purposes.

By adding the AllPools function and a corresponding test suite, we ensure the correct and efficient retrieval of pools from different pool modules in the Osmosis chain. This will allow FE to integrate the concentrated liquidity feature, as well as provide developers and users with the ability to query all available pools in a single, unified manner.

Testing and Verifying

This change added tests.

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes? yes
  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.md? yes
  • How is the feature or change documented? not applicable

@github-actions github-actions bot added C:app-wiring Changes to the app folder C:CLI C:simulator Edits simulator or simulations C:x/concentrated-liquidity C:x/gamm Changes, features and bugs related to the gamm module. C:x/poolmanager labels Mar 17, 2023
@p0mvn p0mvn added the V:state/breaking State machine breaking PR label Mar 17, 2023
@p0mvn p0mvn marked this pull request as ready for review March 17, 2023 23:31
@p0mvn p0mvn marked this pull request as draft March 17, 2023 23:32
@p0mvn p0mvn marked this pull request as ready for review March 17, 2023 23:55
Copy link
Member

@mattverse mattverse left a comment

Choose a reason for hiding this comment

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

Core logic LGTM, ACK once my comment / question on the all pools test have been addressed / answered!

x/poolmanager/types/routes.go Show resolved Hide resolved
// and overlapping and duplicate pool ids. The expected results and potential errors are defined for each test case.
// The test suite sets up mock pool modules and configures their behavior for the GetPools method, injecting them into the pool manager for testing.
// The actual results of the AllPools function are then compared to the expected results, ensuring the function behaves as intended in each scenario.
func (suite *KeeperTestSuite) TestAllPools() {
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason we test with mock here? On the first look, it seems like something that could be tested by real pools (Also personally would prefer real pools testing if compared with mock testings, although I agree with using mock testings if unevitable or testing setup gets too hard)

Copy link
Member Author

Choose a reason for hiding this comment

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

The mocks are used for the ease of setting up the test case in such a way as to verify all the edge cases.

Mocks are useful for testing code that has side effects. By using a mock object to simulate the side effect of returning pools with IDs in a desired sequence, I can test the code's behavior without actually setting up the pools in such an order.

What we want to test is that no matter how many pool modules we have, and the spread of the pool ids across them, we get pools sorted by IDs in the end.

The pool type used is irrelevant for testing the correctness of this method.

Independent of this test, I think that using mock is an elegant approach. It allows for easily maximizing test coverage by mocking out all of the dependencies within it to return many if not all combinations of the output. These combinations can test out all the edge cases.

The reason we cannot use it more across SDK is that the dependency inversion principle is commonly violated. What I mean is interfaces are rarely used and, instead, concrete implementations are relied upon, complicating the use of mocks. Without having interfaces, we cannot create mocks and have to use concrete implementations.

CC: @czarcas7ic

Copy link
Member

Choose a reason for hiding this comment

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

The pool type used is irrelevant for testing the correctness of this method.

I guess this was one of the main reasons I was requesting for a test that does not use mock. I do agree with you in the sense that mockings have great advantage when it comes to maximizing test coverage of this method. Meanwhile, I think it is also important for us to have a test that tests this logic addition via the app wiring that we use instead of mocked values. Let me know if you have any opinions on this!

Copy link
Member

Choose a reason for hiding this comment

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

The only reason I don't have a strong opinion on this is that its just a query, so the risk is negligible. So I am fine with mocks (and Roman explained offline why we don't need to test various pool types)

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 added the requested test: 4b185f9 to unblock this PR for FE.

However, I would like to continue discussing the mocks so that we come to a common agreement to avoid getting blocked on discussions when mocks are used in the future.

I guess this was one of the main reasons I was requesting for a test that does not use mock. I do agree with you in the sense that mockings have great advantage when it comes to maximizing test coverage of this method. Meanwhile, I think it is also important for us to have a test that tests this logic addition via the app wiring that we use instead of mocked values. Let me know if you have any opinions on this!

What are you referring to by this? I have no problem with adding tests but I have trouble seeing the value being justified.

The mocks allow for achieving maximum test coverage of the system under test. Each pool's underlying implementation should be tested individually by a direct test. Testing the internals of each pool implementation at the poolmanager (higher level of abstraction) only introduces additional complexity with negligible benefit.

x/poolmanager/router_test.go Show resolved Hide resolved
osmoutils/slice_helper.go Show resolved Hide resolved
tests/mocks/pool_module.go Show resolved Hide resolved
p0mvn and others added 2 commits March 18, 2023 23:14
Co-authored-by: Matt, Park <45252226+mattverse@users.noreply.github.com>
@p0mvn
Copy link
Member Author

p0mvn commented Mar 19, 2023

Closing and reopening to trigger CI

@p0mvn p0mvn closed this Mar 19, 2023
@p0mvn p0mvn reopened this Mar 19, 2023
Copy link
Member

@czarcas7ic czarcas7ic left a comment

Choose a reason for hiding this comment

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

Approving after our offline discussion on mocks / pool types

@p0mvn
Copy link
Member Author

p0mvn commented Mar 20, 2023

Merging this change since the requested test was added.

@mattverse @czarcas7ic I'm going to follow up offline on the mocks discussion

@p0mvn p0mvn merged commit 931ed16 into main Mar 20, 2023
@p0mvn p0mvn deleted the roman/all-pools-query branch March 20, 2023 20:07
@github-actions github-actions bot mentioned this pull request Feb 15, 2024
@github-actions github-actions bot mentioned this pull request Mar 15, 2024
@github-actions github-actions bot mentioned this pull request Apr 15, 2024
@github-actions github-actions bot mentioned this pull request May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:app-wiring Changes to the app folder C:CLI C:simulator Edits simulator or simulations C:x/concentrated-liquidity C:x/gamm Changes, features and bugs related to the gamm module. C:x/poolmanager V:state/breaking State machine breaking PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants