-
Notifications
You must be signed in to change notification settings - Fork 123
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
switch to use the helper method to create positions #1787
Conversation
WalkthroughThe updates across multiple test files in this refactor primarily involve standardizing the creation of asset and perpetual positions using helper functions from a utility package ( Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (28)
- protocol/daemons/liquidation/client/sub_task_runner_test.go (5 hunks)
- protocol/x/clob/client/cli/liquidations_cli_test.go (4 hunks)
- protocol/x/clob/e2e/app_test.go (4 hunks)
- protocol/x/clob/e2e/conditional_orders_test.go (7 hunks)
- protocol/x/clob/e2e/isolated_subaccount_orders_test.go (6 hunks)
- protocol/x/clob/e2e/liquidation_deleveraging_test.go (19 hunks)
- protocol/x/clob/e2e/long_term_orders_test.go (12 hunks)
- protocol/x/clob/e2e/reduce_only_orders_test.go (5 hunks)
- protocol/x/clob/e2e/short_term_orders_test.go (8 hunks)
- protocol/x/clob/e2e/withdrawal_gating_test.go (4 hunks)
- protocol/x/clob/keeper/deleveraging_test.go (10 hunks)
- protocol/x/clob/keeper/liquidations_test.go (25 hunks)
- protocol/x/clob/keeper/msg_server_place_order_test.go (3 hunks)
- protocol/x/clob/keeper/process_operations_liquidations_test.go (7 hunks)
- protocol/x/clob/keeper/process_operations_long_term_test.go (4 hunks)
- protocol/x/clob/keeper/process_operations_test.go (29 hunks)
- protocol/x/sending/app_test.go (3 hunks)
- protocol/x/subaccounts/keeper/isolated_subaccount_test.go (6 hunks)
- protocol/x/subaccounts/keeper/subaccount_test.go (73 hunks)
- protocol/x/subaccounts/lib/oimf_test.go (7 hunks)
- protocol/x/subaccounts/lib/updates_test.go (5 hunks)
- protocol/x/subaccounts/types/genesis_test.go (6 hunks)
- protocol/x/subaccounts/types/subaccount_test.go (6 hunks)
- protocol/x/vault/keeper/grpc_query_vault_test.go (3 hunks)
- protocol/x/vault/keeper/msg_server_deposit_to_vault_test.go (2 hunks)
- protocol/x/vault/keeper/orders_test.go (4 hunks)
- protocol/x/vault/keeper/shares_test.go (2 hunks)
- protocol/x/vault/keeper/vault_test.go (2 hunks)
Files not summarized due to errors (1)
- protocol/x/subaccounts/keeper/subaccount_test.go: Error: Message exceeds token limit
Files not reviewed due to errors (4)
- protocol/x/sending/app_test.go (no review received)
- protocol/x/clob/e2e/liquidation_deleveraging_test.go (no review received)
- protocol/x/clob/keeper/deleveraging_test.go (no review received)
- protocol/x/clob/keeper/process_operations_test.go (no review received)
Files skipped from review due to trivial changes (6)
- protocol/x/clob/e2e/app_test.go
- protocol/x/clob/keeper/process_operations_liquidations_test.go
- protocol/x/subaccounts/keeper/isolated_subaccount_test.go
- protocol/x/subaccounts/lib/updates_test.go
- protocol/x/subaccounts/types/subaccount_test.go
- protocol/x/vault/keeper/grpc_query_vault_test.go
Additional comments not posted (52)
protocol/x/vault/keeper/vault_test.go (1)
102-105
: Refactoring Approved: Use of centralized asset position creation method.The replacement of direct asset position instantiation with
testutil.CreateSingleAssetPosition
centralizes the creation logic, enhancing maintainability and consistency.protocol/x/subaccounts/types/genesis_test.go (1)
131-132
: Refactor Approved: Centralized creation methods for asset and perpetual positions.Using
testutil.CreateSingleAssetPosition
andtestutil.CreateSinglePerpetualPosition
improves the consistency and maintainability of position creation in tests. These changes are beneficial for handling complex data structures likebig.Int
more effectively.Also applies to: 149-152, 168-171, 191-200, 216-220
protocol/x/subaccounts/lib/oimf_test.go (1)
202-206
: Refactoring Approved: Centralized perpetual position creation in tests.The use of
testutil.CreateSinglePerpetualPosition
in test cases standardizes the creation of perpetual positions, enhancing the clarity and maintainability of the tests.Also applies to: 244-248, 280-284, 298-302, 325-329, 343-347
protocol/x/vault/keeper/msg_server_deposit_to_vault_test.go (1)
271-274
: Refactoring Approved: Centralized asset position creation in depositor setup.Utilizing
testutil.CreateSingleAssetPosition
for initial depositor balances in the genesis state setup enhances the consistency and maintainability of the test setup.protocol/x/clob/client/cli/liquidations_cli_test.go (4)
12-12
: Ensure consistency in import aliasing.The import alias
appflags
is introduced for clarity. This is a good practice as it helps in distinguishing similar imports and enhances code readability.
19-19
: Good use of centralized utility functions.Switching to
testutil
for common test functionalities is a positive change. It centralizes common logic, thereby reducing redundancy and potential errors.
151-161
: Refactor: Use helper functions for position creation.Using
testutil.CreateSingleAssetPosition
andtestutil.CreateSinglePerpetualPosition
to create positions is an excellent refactor. It ensures that position creation is consistent and potentially reduces the chance of errors.
216-216
: Check integration of new order placement function.The function
MsgPlaceOrderExec
fromclob_testutil
is used here. Ensure it integrates well with the existing system and that all its dependencies (like error handling and transaction finality) are properly managed.protocol/x/vault/keeper/shares_test.go (4)
324-327
: Optimize asset position creation using test utility functions.The
CreateSingleAssetPosition
function is used correctly to create asset positions with specific values. This centralizes the creation logic and ensures consistency across tests.
Line range hint
25-56
: Thorough testing of total shares management.The function
TestGetSetTotalShares
effectively tests various scenarios for managing total shares, including edge cases such as setting shares to zero and negative values. The use ofrequire
statements is appropriate for unit tests.
Line range hint
58-103
: Comprehensive testing of owner shares functionality.The function
TestGetSetOwnerShares
is well-structured and thoroughly tests the functionality for setting and getting owner shares, including handling of negative values. The use of assertions is correctly implemented.
Line range hint
105-123
: Effectively tests retrieval of all owner shares.The
TestGetAllOwnerShares
function correctly tests the retrieval of all owner shares from a vault, usingrequire.ElementsMatch
to assert the correctness of the returned slice of shares.protocol/x/clob/e2e/reduce_only_orders_test.go (2)
65-91
: Consistent use of test utility functions for position creation.The use of
CreateSingleAssetPosition
andCreateSinglePerpetualPosition
functions ensures consistent and centralized logic for creating positions in test cases, which enhances maintainability and readability.
Line range hint
6-283
: Thorough testing of reduce-only orders across multiple scenarios.The
TestReduceOnlyOrders
function effectively tests various scenarios for reduce-only orders, including partial and full matches across different blocks. The use oftestutil
functions for setting up test cases is appropriate and enhances test reliability.protocol/x/clob/keeper/msg_server_place_order_test.go (3)
6-6
: Approved addition ofmath/big
import.The import of
math/big
is necessary for handling large integers, which aligns with the use ofbig.NewInt
in the subsequent code.
20-20
: Approved addition oftestutil
import.The import of
testutil
is necessary for accessing helper functions likeCreateSingleAssetPosition
, which is used to create asset positions in a standardized way throughout the tests.
509-512
: Refactor to use helper method for asset position creation.The use of
testutil.CreateSingleAssetPosition
is a good practice as it standardizes the creation of asset positions across tests, ensuring consistency and reducing redundancy.protocol/x/clob/e2e/withdrawal_gating_test.go (4)
4-4
: Approved addition ofmath/big
import.The import of
math/big
is necessary for handling large integers, which aligns with the use ofbig.NewInt
in the subsequent code.
21-21
: Approved addition oftestutil
import.The import of
testutil
is necessary for accessing helper functions likeCreateSingleAssetPosition
, which is used to create asset positions in a standardized way throughout the tests.
36-39
: Refactor to use helper method for asset position creation.The use of
testutil.CreateSingleAssetPosition
is a good practice as it standardizes the creation of asset positions across tests, ensuring consistency and reducing redundancy.
264-274
: Refactor to use helper methods for asset and perpetual position creation.Using
testutil.CreateSingleAssetPosition
andtestutil.CreateSinglePerpetualPosition
standardizes the creation of positions, which is beneficial for maintainability and readability.protocol/daemons/liquidation/client/sub_task_runner_test.go (2)
5-5
: Approved use ofmath/big
:The import of the
math/big
package is appropriate given the use ofbig.NewInt
for handling large integer values in the test setup. This aligns well with the PR's objective to standardize the handling of large numbers.
16-16
: Approved updated import fortestutil
:The change from a more general import to a specific utility import (
testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/util"
) is a good practice. It makes the import more explicit and potentially avoids conflicts or ambiguity in large projects.protocol/x/clob/e2e/isolated_subaccount_orders_test.go (3)
19-19
: Good use of utility imports for enhanced test modularity.The addition of
testutil
helps centralize the creation of test entities, improving readability and maintainability.
73-78
: Refactored position creation using utility functions.The use of
testutil.CreateSingleAssetPosition
andtestutil.CreateSinglePerpetualPosition
ensures consistent and error-free creation of positions. This change enhances the readability and maintainability of the test code.Also applies to: 82-86, 95-100, 104-108, 117-122, 126-131, 140-145
Line range hint
160-652
: Comprehensive test coverage for various trading scenarios.The test cases are well-structured and cover a wide range of scenarios, including edge cases and error handling. This thorough testing ensures that the system behaves as expected under different conditions.
protocol/x/vault/keeper/orders_test.go (4)
133-136
: Correct use of the helper method for position creation.
The refactoring to usetestutil.CreateSingleAssetPosition
is correctly implemented and improves code readability by abstracting the position creation logic.
279-282
: Proper implementation of the helper method for asset position creation.
The use oftestutil.CreateSingleAssetPosition
here is consistent with other test functions, ensuring uniformity across the test suite.
653-657
: Effective use of helper methods for both asset and perpetual position creation.
The refactoring to usetestutil.CreateSinglePerpetualPosition
alongsidetestutil.CreateSingleAssetPosition
is correctly implemented, enhancing modularity and maintainability of the test code.
Line range hint
1-1
: Logic review for client ID generation.
The functionTestGetVaultClobOrderClientId
correctly implements the logic for generating client IDs based on various parameters. The test cases are comprehensive and cover a wide range of scenarios.protocol/x/clob/keeper/process_operations_long_term_test.go (6)
456-460
: Refactor to use utility function for position creation is appropriate.Using
testutil.CreateSinglePerpetualPosition
centralizes position creation logic, which is a good practice as it enhances maintainability and ensures consistency across tests. This change is in line with the PR's objective to use helper methods for creating positions.
463-467
: Refactor to use utility function for position creation is appropriate.Using
testutil.CreateSinglePerpetualPosition
centralizes position creation logic, which is a good practice as it enhances maintainability and ensures consistency across tests. This change is in line with the PR's objective to use helper methods for creating positions.
810-814
: Refactor to use utility function for position creation is appropriate.Using
testutil.CreateSinglePerpetualPosition
centralizes position creation logic, which is a good practice as it enhances maintainability and ensures consistency across tests. This change is in line with the PR's objective to use helper methods for creating positions.
817-821
: Refactor to use utility function for position creation is appropriate.Using
testutil.CreateSinglePerpetualPosition
centralizes position creation logic, which is a good practice as it enhances maintainability and ensures consistency across tests. This change is in line with the PR's objective to use helper methods for creating positions.
902-906
: Refactor to use utility function for position creation is appropriate.Using
testutil.CreateSinglePerpetualPosition
centralizes position creation logic, which is a good practice as it enhances maintainability and ensures consistency across tests. This change is in line with the PR's objective to use helper methods for creating positions.
909-913
: Refactor to use utility function for position creation is appropriate.Using
testutil.CreateSinglePerpetualPosition
centralizes position creation logic, which is a good practice as it enhances maintainability and ensures consistency across tests. This change is in line with the PR's objective to use helper methods for creating positions.protocol/x/clob/e2e/short_term_orders_test.go (5)
23-23
: Approved import addition for utility functions.The addition of the
testutil
import is consistent with the PR's objectives and is used appropriately throughout the test file.
157-162
: Refactor using utility function for perpetual position creation approved.The use of
testutil.CreateSinglePerpetualPosition
enhances code maintainability by centralizing the position creation logic. The parameters and their types are correctly applied.
166-169
: Refactor using utility function for asset position creation approved.The use of
testutil.CreateSingleAssetPosition
is consistent with the PR's objectives to centralize and standardize position creation. The implementation and parameter usage are correct.
184-196
: Consistent use of utility functions for position creation in different scenarios approved.The repeated use of
testutil.CreateSinglePerpetualPosition
andtestutil.CreateSingleAssetPosition
across various test cases demonstrates a consistent approach to refactoring, which aligns with the PR's goals.
Line range hint
334-373
: Continued approval for the use of utility functions in complex test scenarios.The consistent application of
testutil.CreateSinglePerpetualPosition
andtestutil.CreateSingleAssetPosition
in complex test scenarios further demonstrates the benefits of this refactoring approach.protocol/x/clob/e2e/long_term_orders_test.go (4)
26-26
: Approved import changes.The switch from
dtypes
totestutil/util
aligns with the PR's aim to use helper methods for position creation, enhancing maintainability.
622-661
: Refactor approved for position creation using helper functions.The use of
testutil.CreateSinglePerpetualPosition
andtestutil.CreateSingleAssetPosition
improves code readability and reduces redundancy by centralizing position creation logic.
622-661
: Consistency in using helper functions for position creation.The consistent use of helper functions across different test cases ensures uniformity and maintains the integrity of test setups.
Line range hint
1542-1698
: Correct application of helper methods in regression tests.Using helper methods for position creation in regression tests ensures that the tests are robust and maintainable. The tests correctly handle orders with invalid time-in-force settings.
protocol/x/clob/e2e/conditional_orders_test.go (1)
562-572
: Refactoring to usetestutil
helper functions for position creationThe changes correctly utilize the
testutil.CreateSingleAssetPosition
andtestutil.CreateSinglePerpetualPosition
functions to create asset and perpetual positions. This centralizes the creation logic, which enhances maintainability and consistency across tests.Ensure that the parameters passed to these functions match the expected types and values, particularly the use of
big.NewInt
for quantities, to maintain precision in financial calculations.Also applies to: 604-614, 684-694
protocol/x/clob/keeper/liquidations_test.go (4)
488-503
: Refactoring to use helper methods is implemented correctly.
573-588
: Consistent use of helper methods enhances maintainability.
703-718
: Ensure that the modified values in the test scenarios are as intended.
1103-1118
: New test scenario added. Verify the correctness of specific values used.protocol/x/subaccounts/keeper/subaccount_test.go (2)
140-144
: Refactored Perpetual Position Creation ApprovedThe replacement of direct instantiation with
testutil.CreateSinglePerpetualPosition
correctly centralizes the creation logic. The parameters passed are appropriate for the context ofIsoUsd_IsolatedMarket
.
411-436
: Review of Perpetual and Asset Position CreationRefactoring to use
testutil.CreateSinglePerpetualPosition
andtestutil.CreateSingleAssetPosition
is consistent with the PR's goal. Ensure that the parameters, especially the negative values, are intended as they significantly impact the business logic.
assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" | ||
"github.com/dydxprotocol/v4-chain/protocol/x/clob/client/testutil" | ||
clob_testutil "github.com/dydxprotocol/v4-chain/protocol/x/clob/client/testutil" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
Codebase Verification
Clarify the specific utility of clob_testutil
.
The review comment is valid. There are no comments or documentation explaining the specific utility of clob_testutil
in the liquidations_cli_test.go
file. Adding such explanations would help maintain clarity and prevent confusion.
- File:
protocol/x/clob/client/cli/liquidations_cli_test.go
- Lines: 21
Analysis chain
Clarify the specific utility of clob_testutil
.
It's important to maintain clear documentation or comments explaining the specific utilities provided by clob_testutil
as opposed to testutil
, especially since both are used in this file. This helps maintain clarity and prevents confusion.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for documentation or comments regarding `clob_testutil` usage.
rg --type python --files-with-matches 'clob_testutil' | xargs rg 'clob_testutil' --context 5
Length of output: 3231
Script:
#!/bin/bash
# Description: Check for documentation or comments regarding `clob_testutil` usage in Go files.
rg --type go --files-with-matches 'clob_testutil' | xargs rg 'clob_testutil' --context 5
Length of output: 1480
testutil.CreateSingleAssetPosition( | ||
0, | ||
big.NewInt(55_000_000_000), // $55,000 | ||
), | ||
}, | ||
PerpetualPositions: []*satypes.PerpetualPosition{ | ||
{ | ||
PerpetualId: 0, | ||
Quantums: dtypes.NewInt(-100_000_000), // -1 BTC | ||
FundingIndex: dtypes.NewInt(10_000), | ||
}, | ||
testutil.CreateSinglePerpetualPosition( | ||
0, | ||
big.NewInt(-100_000_000), // -1 BTC | ||
big.NewInt(10_000), | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor using testutil
functions for position creation:
The replacement of direct instantiation with testutil.CreateSingleAssetPosition
and testutil.CreateSinglePerpetualPosition
is a significant improvement. This change not only reduces redundancy but also enhances the maintainability and readability of the test code by centralizing the creation logic.
Consider adding a brief comment above these utility function calls to explain what each parameter represents, especially for magic numbers like 0
or large integers like 55_000_000_000
, to enhance code readability.
+ // Create a single asset position with specified parameters
testutil.CreateSingleAssetPosition(
0, // Asset ID
big.NewInt(55_000_000_000), // Position value in USD
),
+ // Create a single perpetual position with specified parameters
testutil.CreateSinglePerpetualPosition(
0, // Perpetual ID
big.NewInt(-100_000_000), // Position size in BTC
big.NewInt(10_000), // Funding index
),
Also applies to: 368-378, 448-458, 526-536
Changelist
[Describe or list the changes made in this PR]
Test Plan
[Describe how this PR was tested (if applicable)]
Author/Reviewer Checklist
state-breaking
label.indexer-postgres-breaking
label.PrepareProposal
orProcessProposal
, manually add the labelproposal-breaking
.feature:[feature-name]
.backport/[branch-name]
.refactor
,chore
,bug
.Summary by CodeRabbit