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

[CLOB-636] - update e2e stateful cancellations tests #750

Merged
merged 5 commits into from
Nov 7, 2023

Conversation

jakob-dydx
Copy link
Contributor

No description provided.

Copy link

linear bot commented Nov 3, 2023

CLOB-636 Write end-to-end tests for order cancellations

We should write end-to-end tests that have better coverage of order cancellations, at a minimum we should cover the following cases:

  • Canceling a partially-matched Short-Term order.
  • Canceling a partially-matched stateful order.
  • Canceling an unmatched stateful order.
  • Canceling a non-existent stateful order.

Copy link
Contributor

coderabbitai bot commented Nov 3, 2023

Walkthrough

The recent changes involve the addition of a new utility function for comparing slices, enhancements to the testing utilities, and updates to the blockchain application tests. A new function SlicesAreEqual has been added to the lib package. The testing utilities have been expanded with new imports. The blockchain application tests have been updated with a new variable and a new test case for stateful order cancellation. Existing test cases have also been modified to include expected results.

Changes

File(s) Change Summary
protocol/lib/slices.go Added a new function SlicesAreEqual that compares two slices of any comparable type and returns a boolean indicating whether they are equal.
protocol/testutil/app/app.go Added imports for math, math/rand, os, path/filepath, sync, and testing. No changes to function signatures, global data structures, variables, interfaces, return values, or exceptions.
protocol/x/clob/e2e/app_test.go Added a new variable PlaceOrder_Bob_Num0_Id0_Clob0_Sell4_Price10_GTB20 of type clobtypes.MsgPlaceOrder with specific values for various fields. Also added an import for clobtypes.
protocol/x/clob/e2e/long_term_orders_test.go Added a new test function for the scenario where a stateful cancellation fails because the order was fully filled in the same block. Modified existing test functions to include a new struct checkResults for storing expected test results.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4bd3c34 and 7b7502d.
Files selected for processing (4)
  • protocol/lib/slices.go (1 hunks)
  • protocol/testutil/app/app.go (2 hunks)
  • protocol/x/clob/e2e/app_test.go (1 hunks)
  • protocol/x/clob/e2e/long_term_orders_test.go (8 hunks)
Files skipped from review due to trivial changes (1)
  • protocol/testutil/app/app.go
Additional comments: 6
protocol/lib/slices.go (1)
  • 1-13: The function SlicesAreEqual is correctly implemented. It first checks if the lengths of the two slices are equal. If they are not, it immediately returns false. Then it iterates over the elements of the first slice and checks if each element is equal to the corresponding element in the second slice. If it finds any pair of elements that are not equal, it immediately returns false. If it doesn't find any unequal pairs, it returns true after the loop, indicating that the slices are equal. This is a good and efficient way to compare slices.
protocol/x/clob/e2e/long_term_orders_test.go (4)
  • 10-11: New imports have been added. Ensure that these packages are used in the code and that they are necessary for the functionality of the code.

  • 74-78: A new struct checkResults has been introduced to store the expected results of the tests. This is a good practice as it improves the readability and maintainability of the code.

  • 80-147: A new test function TestCancelFullyFilledStatefulOrderInSameBlockItIsFilled has been added. This function tests the scenario where a stateful cancellation fails because the order was fully filled in the same block. The test function seems to be well-structured and covers the necessary assertions.

  • 250-285: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [149-306]

Existing test functions have been modified to use the new struct checkResults for storing and checking expected test results. This is a good practice as it improves the readability and maintainability of the code.

protocol/x/clob/e2e/app_test.go (1)
  • 179-188: The new variable PlaceOrder_Bob_Num0_Id0_Clob0_Sell4_Price10_GTB20 is correctly initialized with specific order values. Ensure that this new order is used correctly in the tests where it is needed.

@jakob-dydx jakob-dydx force-pushed the jakob-dydx/stateful-cancellation-e2e branch from 7b7502d to 23cf401 Compare November 3, 2023 19:57
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4bd3c34 and 23cf401.
Files selected for processing (4)
  • protocol/lib/slices.go (1 hunks)
  • protocol/testutil/app/app.go (2 hunks)
  • protocol/x/clob/e2e/app_test.go (1 hunks)
  • protocol/x/clob/e2e/long_term_orders_test.go (8 hunks)
Files skipped from review due to trivial changes (1)
  • protocol/testutil/app/app.go
Additional comments: 5
protocol/lib/slices.go (1)
  • 1-13: The function SlicesAreEqual is correctly implemented. It first checks if the lengths of the two slices are equal. If they are not, it immediately returns false. Then it iterates over the elements of the first slice and checks if each element is equal to the corresponding element in the second slice. If it finds any pair of elements that are not equal, it immediately returns false. If it doesn't find any unequal pairs, it returns true after the loop, indicating that the slices are equal. This is a good and efficient way to compare slices.
protocol/x/clob/e2e/long_term_orders_test.go (3)
  • 10-11: The new imports are not used in the provided hunks. Ensure they are used elsewhere in the file or remove them to avoid unnecessary imports.

  • 74-141: The new test function TestCancelFullyFilledStatefulOrderInSameBlockItIsFilled is well-structured and follows the Arrange-Act-Assert pattern. It tests the scenario where a stateful cancellation fails because the order was fully filled in the same block. The test case is clear and the assertions are well defined.

  • 143-150: The new struct checkResults is used to store and check expected test results. This is a good practice as it improves readability and maintainability of the test cases.

protocol/x/clob/e2e/app_test.go (1)
  • 179-188: The new variable PlaceOrder_Bob_Num0_Id0_Clob0_Sell4_Price10_GTB20 is correctly initialized with a new order. Ensure that this new order is used correctly in the tests where it is needed.

protocol/x/clob/e2e/long_term_orders_test.go Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 23cf401 and 2cb7b12.
Files selected for processing (1)
  • protocol/x/clob/e2e/long_term_orders_test.go (8 hunks)
Additional comments: 3
protocol/x/clob/e2e/long_term_orders_test.go (3)
  • 74-141: The new test case TestCancelFullyFilledStatefulOrderInSameBlockItIsFilled is well written and covers a specific scenario. It checks the cancellation of an order that was fully filled in the same block. The test case is clear and easy to understand.

  • 143-147: The checkResults struct is used to store the expected results of the test cases. It includes the order id and a boolean indicating whether the order exists in the state.

  • 249-284: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [149-303]

The test cases in the TestCancelStatefulOrder function have been updated to use the checkResults struct for storing and checking the expected results. This is a good practice as it improves the readability and maintainability of the test cases.

protocol/x/clob/e2e/long_term_orders_test.go Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2cb7b12 and aaf4dbf.
Files selected for processing (1)
  • protocol/x/clob/e2e/long_term_orders_test.go (8 hunks)
Additional comments: 2
protocol/x/clob/e2e/long_term_orders_test.go (2)
  • 10-11: The imports are indeed used in the code. No changes needed.

  • 74-144: The new test function TestCancelFullyFilledStatefulOrderInSameBlockItIsFilled is well-structured and covers a specific scenario. It checks the case where a stateful cancellation fails because the order was fully filled in the same block. The test function is clear and easy to understand.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between aaf4dbf and 8f23110.
Files selected for processing (1)
  • protocol/x/clob/e2e/long_term_orders_test.go (8 hunks)
Additional comments: 2
protocol/x/clob/e2e/long_term_orders_test.go (2)
  • 10-11: The imports are indeed used in the code. No changes needed.

  • 74-145: The new test function TestCancelFullyFilledStatefulOrderInSameBlockItIsFilled is well-structured and covers a specific scenario. It checks the scenario where a stateful cancellation fails because the order was fully filled in the same block. The test case is well-structured and covers all the necessary assertions.

Comment on lines +148 to +151
type checkResults struct {
orderId clobtypes.OrderId
existsInState bool
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The checkResults struct is a good addition to the test cases. It improves readability and maintainability. However, it might be beneficial to include the expected fill amount and existence in the fill in the struct. This would allow for more flexible and comprehensive test cases.

- type checkResults struct {
- 	orderId       clobtypes.OrderId
- 	existsInState bool
- }
+ type checkResults struct {
+ 	orderId       clobtypes.OrderId
+ 	existsInState bool
+ 	existsInFill  bool
+ 	fillAmount    uint64
+ }

Commitable suggestion

[!IMPORTANT]
Carefully review the code before committing. Make sure it correctly replaces the highlighted code, has no missing lines and indentaion issues.

Suggested change
type checkResults struct {
orderId clobtypes.OrderId
existsInState bool
}
type checkResults struct {
orderId clobtypes.OrderId
existsInState bool
existsInFill bool
fillAmount uint64
}

Comment on lines +303 to +307
_, exists := tApp.App.ClobKeeper.GetLongTermOrderPlacement(ctx, tc.expectations.orderId)
require.Equal(t, exists, tc.expectations.existsInState)
exists, fillAmount, _ := tApp.App.ClobKeeper.GetOrderFillAmount(
ctx,
tc.checkCancelledPlaceOrder.Order.OrderId,
tc.expectations.orderId,
Copy link
Contributor

Choose a reason for hiding this comment

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

The test case always expects the order fill amount to be 0 and its existence to be false. This might not be the case for all tests. Consider updating the checkResults struct to include these expectations and use them in the assertions.

- type checkResults struct {
- 	orderId       clobtypes.OrderId
- 	existsInState bool
- }
+ type checkResults struct {
+ 	orderId       clobtypes.OrderId
+ 	existsInState bool
+ 	existsInFill  bool
+ 	fillAmount    uint64
+ }

Commitable suggestion

[!IMPORTANT]
Carefully review the code before committing. Make sure it correctly replaces the highlighted code, has no missing lines and indentaion issues.

Suggested change
_, exists := tApp.App.ClobKeeper.GetLongTermOrderPlacement(ctx, tc.expectations.orderId)
require.Equal(t, exists, tc.expectations.existsInState)
exists, fillAmount, _ := tApp.App.ClobKeeper.GetOrderFillAmount(
ctx,
tc.checkCancelledPlaceOrder.Order.OrderId,
tc.expectations.orderId,
type checkResults struct {
orderId clobtypes.OrderId
existsInState bool
existsInFill bool
fillAmount uint64
}
check := func(tc testCase, results checkResults) {
_, exists := tApp.App.ClobKeeper.GetLongTermOrderPlacement(ctx, results.orderId)
require.Equal(t, results.existsInState, exists)
exists, fillAmount, _ := tApp.App.ClobKeeper.GetOrderFillAmount(
ctx,
results.orderId,
)
require.Equal(t, results.existsInFill, exists)
require.Equal(t, results.fillAmount, fillAmount)
}
results := checkResults{
orderId: tc.expectations.orderId,
existsInState: tc.expectations.existsInState,
existsInFill: false,
fillAmount: 0,
}
check(tc, results)

@jakob-dydx jakob-dydx merged commit 0385e41 into main Nov 7, 2023
14 of 15 checks passed
@jakob-dydx jakob-dydx deleted the jakob-dydx/stateful-cancellation-e2e branch November 7, 2023 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants