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

Add x/rollup unit tests #161

Merged
merged 3 commits into from
Aug 21, 2024
Merged

Add x/rollup unit tests #161

merged 3 commits into from
Aug 21, 2024

Conversation

natebeauregard
Copy link
Collaborator

@natebeauregard natebeauregard commented Aug 21, 2024

Closes: #134

This PR is heavily influenced by the Cosmos SDK testing docs and existing Cosmos SDK/Osmosis unit tests.

  • Use expected keeper interface for x/rollup bankkeeper
  • Generate expected keeper mocks with mockgen
    • Adds new makefile commands to install mockgen and to generate expected keeper mocks for use in x/rollup unit tests.
  • Adds unit test coverage to assert behavior for the x/rollup messages and the related helper functions involved in the deposit and withdrawal flow.

Summary by CodeRabbit

  • New Features

    • Introduced install-mockgen and gen-mocks targets in the build process to facilitate mock generation for testing.
    • Added a BankKeeper interface to define methods for managing coin transfers, minting, and burning within the rollup module.
    • Implemented comprehensive unit tests for the Keeper component and its methods, enhancing the reliability of transaction processing and withdrawals.
    • Refactored the GenerateEthTxs function to encapsulate block generation logic, improving modularity and readability.
    • Introduced a mock implementation of the BankKeeper interface to streamline testing processes.
  • Bug Fixes

    • Enhanced error handling in transaction processing functions to ensure proper responses to invalid inputs.
  • Documentation

    • Updated comments and naming conventions for functions to improve clarity and consistency across the codebase.

Copy link
Contributor

coderabbitai bot commented Aug 21, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes enhance the x/rollup module in a Cosmos SDK application by introducing new functionality, including the implementation of mock generation and the addition of comprehensive unit tests. Refactoring improves code clarity and organization, while updated method names ensure better integration with the module's operations. Together, these modifications bolster the module's robustness and maintainability, particularly for handling deposits and withdrawals.

Changes

Files Change Summary
Makefile, x/rollup/testutil/expected_keepers_mocks.go Added targets in Makefile for installing mockgen and generating mocks. Introduced a mock implementation of the BankKeeper interface to streamline testing for banking operations.
testutils/utils.go, x/rollup/keeper/deposits.go, x/rollup/keeper/msg_server.go Refactored functions for clarity and encapsulation. Changed function names to follow Go's naming conventions, improving code readability. Introduced a new helper function for block generation and updated transaction processing method names to reflect their new functionality.
x/rollup/keeper/keeper_test.go, x/rollup/keeper/msg_server_test.go Added comprehensive unit tests for the Keeper component, validating the behavior of key functions related to transaction applications and withdrawals, ensuring robust error handling and success scenarios.
x/rollup/types/expected_keepers.go Defined the BankKeeper interface with required methods, establishing a contract for interactions with the bank module, enhancing modularity.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MsgServer
    participant Keeper
    participant MockBankKeeper

    User->>MsgServer: Submit L1 Transaction
    MsgServer->>Keeper: ApplyL1Txs
    Keeper->>MockBankKeeper: Process Transactions
    MockBankKeeper-->>Keeper: Return Results
    Keeper-->>MsgServer: Transaction Status
    MsgServer-->>User: Notify User
Loading

Assessment against linked issues

Objective Addressed Explanation
Add unit tests for deposits and withdrawals (#134)
Ensure proper function visibility and naming conventions (#134)
Validate behavior of msg_server functions (#134)

Poem

🐰 In the rollup's land, where coins do play,
New tests hop in, brightening the day.
Functions renamed, clear as a bell,
With mocks in the mix, all's going quite well!
Hooray for the code, it dances and sings,
Celebrating the joy that good testing brings! 🎉


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 testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 testing code 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 and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coin := sdk.NewCoin(types.ETH, amount)
if err := k.bankkeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(coin)); err != nil {
return fmt.Errorf("failed to mint deposit coins to the rollup module: %v", err)
}
if err := k.bankkeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, addr, sdk.NewCoins(coin)); err != nil {
return fmt.Errorf("failed to send deposit coins from rollup module to user account %v: %v", addr, err)
}

// TODO: move event emission to msg_server.go
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Created issue #162

return types.WrapError(err, "set")
}
return nil
}

// TODO: include the logic to also store the L1 block info by blockhash in setL1BlockInfo and remove setL1BlockHistory
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Created issue #163

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.

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
x/rollup/keeper/deposits.go (1)

33-40: Update References to Exported Method Name

The method setL1BlockHistory is still referenced with its old name in the following locations:

  • x/rollup/keeper/msg_server.go: Update the method call to use the new exported name.
  • x/rollup/keeper/deposits.go: Revise comments to reflect the new method name for clarity.

Please ensure these references are updated to maintain consistency with the exported method naming convention.

Analysis chain

Ensure Consistency with Exported Method Names.

The method setL1BlockHistory is now exported. Verify that all references to this method across the codebase are updated to use the new name.

Run the following script to check for references to the old method name:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all references to `setL1BlockHistory` are updated.

# Test: Search for the old method name. Expect: No occurrences.
rg --type go 'setL1BlockHistory'

Length of output: 549

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dc1d726 and a6fd94a.

Files selected for processing (12)
  • Makefile (2 hunks)
  • testutils/utils.go (2 hunks)
  • x/rollup/keeper/deposits.go (4 hunks)
  • x/rollup/keeper/deposits_test.go (1 hunks)
  • x/rollup/keeper/keeper.go (1 hunks)
  • x/rollup/keeper/keeper_test.go (1 hunks)
  • x/rollup/keeper/msg_server.go (3 hunks)
  • x/rollup/keeper/msg_server_test.go (1 hunks)
  • x/rollup/keeper/withdrawals.go (1 hunks)
  • x/rollup/keeper/withdrawals_test.go (1 hunks)
  • x/rollup/testutil/expected_keepers_mocks.go (1 hunks)
  • x/rollup/types/expected_keepers.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • x/rollup/keeper/withdrawals.go
Additional comments not posted (20)
x/rollup/keeper/keeper.go (1)

14-14: Verify the impact of changing bankkeeper type.

The bankkeeper field in the Keeper struct and the bankKeeper parameter in the NewKeeper function have been updated to use types.BankKeeper. Ensure that all interactions with bankkeeper in the codebase are compatible with this new interface.

Run the following script to verify the usage of bankkeeper in the codebase:

Also applies to: 21-21

Verification successful

Change to bankkeeper Type is Compatible

The bankkeeper field's change to types.BankKeeper is compatible with the existing codebase. The required methods (BurnCoins, MintCoins, SendCoinsFromAccountToModule, and SendCoinsFromModuleToAccount) are defined in the BankKeeper interface in x/rollup/types/expected_keepers.go, ensuring compatibility.

  • x/rollup/types/expected_keepers.go: Defines the BankKeeper interface with necessary methods.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `bankkeeper` in the codebase to ensure compatibility with `types.BankKeeper`.

# Test: Search for `bankkeeper` usage. Expect: Compatibility with `types.BankKeeper`.
rg --type go -A 5 'bankkeeper'

Length of output: 3441


Script:

#!/bin/bash
# Search for the definition of `types.BankKeeper` and its methods to ensure compatibility.
ast-grep --lang go --pattern 'interface BankKeeper { $$$ }' --json

Length of output: 416


Script:

#!/bin/bash
# Use ripgrep to search for the definition or references of `BankKeeper` in the codebase.
rg 'BankKeeper'

Length of output: 3852

x/rollup/types/expected_keepers.go (1)

9-16: LGTM! The BankKeeper interface is well-defined.

The interface encapsulates necessary methods for bank operations, promoting modularity and ease of testing.

x/rollup/keeper/withdrawals_test.go (1)

11-52: LGTM! Comprehensive test coverage for BurnETH.

The tests effectively cover both successful and error scenarios using mocks.

However, ensure that all edge cases are considered in the test scenarios.

Run the following script to verify the coverage of edge cases in the test scenarios:

x/rollup/keeper/keeper_test.go (1)

18-52: LGTM! Well-structured test suite for Keeper.

The use of testify/suite and mocks provides a robust framework for testing.

Ensure that all necessary mock setups are included for comprehensive test coverage.

Run the following script to verify the completeness of mock setups:

Verification successful

Mocks are comprehensively set up across multiple test files. The mockBurnETH and mockMintETH methods are utilized in various test scenarios, ensuring robust test coverage for the BankKeeper interface.

  • keeper_test.go: Uses mockBurnETH and mockMintETH.
  • withdrawals_test.go: Includes additional mock setups for error scenarios.
  • msg_server_test.go: Utilizes mockBurnETH for testing message server interactions.
  • deposits_test.go: Employs mockMintETH for deposit-related tests.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify completeness of mock setups in `KeeperTestSuite`.

# Test: Search for additional mock setups. Expect: Comprehensive coverage.
rg --type go -A 5 'mock'

Length of output: 18514

Makefile (1)

54-57: LGTM! New Makefile targets for mock management.

The install-mockgen and gen-mocks targets enhance the build process by supporting mock generation.

Ensure these targets are integrated and functioning correctly within the build process.

Run the following script to verify the integration of new Makefile targets:

Also applies to: 66-69

x/rollup/keeper/msg_server.go (3)

32-32: Ensure Consistency with Exported Method Names.

The method ProcessL1SystemDepositTx is now exported. Verify that all references to this method across the codebase are updated to use the new name.

Run the following script to check for references to the old method name:

Verification successful

All references to processL1SystemDepositTx have been updated.

The search did not find any occurrences of the old method name, indicating that all references have been correctly updated to use the new exported name ProcessL1SystemDepositTx. No further action is needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all references to `processL1SystemDepositTx` are updated.

# Test: Search for the old method name. Expect: No occurrences.
rg --type go 'processL1SystemDepositTx'

Length of output: 39


76-76: Ensure Consistency with Exported Method Names.

The method BurnETH is now exported. Verify that all references to this method across the codebase are updated to use the new name.

Run the following script to check for references to the old method name:

Verification successful

All references to burnETH have been updated. The search did not find any occurrences of the old method name, confirming that the codebase is consistent with the exported method name BurnETH.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all references to `burnETH` are updated.

# Test: Search for the old method name. Expect: No occurrences.
rg --type go 'burnETH'

Length of output: 22


Script:

#!/bin/bash
# Re-run the search for the old method name `burnETH` to ensure no occurrences exist.
rg 'burnETH' --type go -A 2

Length of output: 27


55-55: Ensure Consistency with Exported Method Names.

The method ProcessL1UserDepositTxs is now exported. Verify that all references to this method across the codebase are updated to use the new name.

Run the following script to check for references to the old method name:

Verification successful

Method Renaming Verified Successfully

The method ProcessL1UserDepositTxs is consistently used across the codebase, and no references to the old method name processL1UserDepositTxs were found. The renaming has been correctly applied.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all references to `processL1UserDepositTxs` are updated.

# Test: Search for the old method name. Expect: No occurrences.
rg --type go 'processL1UserDepositTxs'

Length of output: 38


Script:

#!/bin/bash
# Description: Verify all references to `ProcessL1UserDepositTxs` are correctly updated.

# Search for the new method name to ensure it is used consistently across the codebase.
rg --type go 'ProcessL1UserDepositTxs' -A 2

Length of output: 1565

x/rollup/testutil/expected_keepers_mocks.go (2)

1-5: Auto-generated Mock File.

This file is auto-generated by MockGen and should not be manually edited. Ensure that the mock generation process is correctly integrated into the build or test setup.


15-31: Verify Mock Interface Alignment.

Ensure that MockBankKeeper correctly implements the BankKeeper interface. This is crucial for the accuracy of tests relying on these mocks.

If there are changes to the BankKeeper interface, regenerate the mocks to ensure alignment.

testutils/utils.go (2)

68-72: Refactor Improves Modularity.

The refactoring of GenerateEthTxs to use GenerateL1Block enhances modularity and readability. Ensure that GenerateL1Block is correctly implemented and returns the expected block structure.


129-135: Ensure Correctness of Block Generation.

The GenerateL1Block function creates a new block with fixed parameters. Verify that these parameters are appropriate for the tests and adjust if necessary.

Check the usage of GenerateL1Block in tests to ensure it meets the test requirements.

x/rollup/keeper/msg_server_test.go (2)

16-89: Comprehensive Test Coverage for ApplyL1Txs.

The tests for ApplyL1Txs cover multiple scenarios, including successful and error cases. Ensure that the mock setup and assertions accurately reflect the expected behavior.


91-157: Comprehensive Test Coverage for InitiateWithdrawal.

The tests for InitiateWithdrawal cover various scenarios, including invalid inputs and expected errors. Ensure that the mock expectations are correctly set up and that the assertions validate the expected outcomes.

x/rollup/keeper/deposits.go (3)

Line range hint 46-64: Ensure Consistency with Exported Method Names.

The method ProcessL1SystemDepositTx is now exported. Verify that all references to this method across the codebase are updated to use the new name.


Line range hint 65-100: Ensure Consistency with Exported Method Names.

The method ProcessL1UserDepositTxs is now exported. Verify that all references to this method across the codebase are updated to use the new name.


Line range hint 101-120: Ensure Consistency with Exported Method Names.

The method MintETH is now exported. Verify that all references to this method across the codebase are updated to use the new name.

Run the following script to check for references to the old method name:

Verification successful

All references to MintETH are correctly updated.

The search results show that the new method name MintETH is consistently used across the codebase. There are no occurrences of the old method name mintETH, confirming that all references have been updated appropriately.

  • MintETH is used in x/rollup/keeper/keeper_test.go, x/rollup/keeper/deposits_test.go, x/rollup/keeper/deposits.go, and other relevant files.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all references to `mintETH` are updated.

# Test: Search for the old method name. Expect: No occurrences.
rg --type go 'mintETH'

Length of output: 22


Script:

#!/bin/bash
# Description: Verify all references to `MintETH` are correctly used.

# Test: Search for the new method name. Expect: Occurrences where it is used.
rg --type go 'MintETH'

Length of output: 1175

x/rollup/keeper/deposits_test.go (3)

15-67: LGTM! Verify MintETH method implementation.

The TestMintETH function is well-structured and covers multiple scenarios effectively.

Ensure that the MintETH method in the rollupKeeper is implemented correctly and handles errors as expected.

Run the following script to verify the MintETH method implementation:

Verification successful

The MintETH method is implemented correctly and handles errors as expected.

The method in x/rollup/keeper/deposits.go properly checks for errors during the minting and sending of coins, aligning with the test scenarios in TestMintETH.

  • File: x/rollup/keeper/deposits.go
  • Method: MintETH
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of the `MintETH` method in the `rollupKeeper`.

# Test: Search for the `MintETH` method implementation. Expect: Proper error handling and logic.
ast-grep --lang go --pattern $'func (k *RollupKeeper) MintETH($_, $_, $_) error {
  $$$
}'

Length of output: 91


Script:

#!/bin/bash
# Search for the `MintETH` method in the codebase using ripgrep.
rg 'func \(.*\) MintETH\(' --context 5

Length of output: 883


69-121: LGTM! Verify ProcessL1SystemDepositTx method implementation.

The TestProcessL1SystemDepositTx function is comprehensive and covers various scenarios effectively.

Ensure that the ProcessL1SystemDepositTx method in the rollupKeeper is implemented correctly and handles errors as expected.

Run the following script to verify the ProcessL1SystemDepositTx method implementation:

Verification successful

Verification Successful: ProcessL1SystemDepositTx Method Implementation

The ProcessL1SystemDepositTx method is implemented in x/rollup/keeper/deposits.go and includes appropriate error handling for transaction unmarshalling, which aligns with the test cases. The implementation appears correct and consistent with the test expectations.

  • Location: x/rollup/keeper/deposits.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of the `ProcessL1SystemDepositTx` method in the `rollupKeeper`.

# Test: Search for the `ProcessL1SystemDepositTx` method implementation. Expect: Proper error handling and logic.
ast-grep --lang go --pattern $'func (k *RollupKeeper) ProcessL1SystemDepositTx($_, $_) (*derive.L1BlockInfo, error) {
  $$$
}'

Length of output: 127


Script:

#!/bin/bash
# Use ripgrep to search for the `ProcessL1SystemDepositTx` method in the codebase.
rg 'ProcessL1SystemDepositTx' --context 5

Length of output: 4128


123-194: LGTM! Verify ProcessL1UserDepositTxs method implementation.

The TestProcessL1UserDepositTxs function is well-structured and covers multiple scenarios effectively.

Ensure that the ProcessL1UserDepositTxs method in the rollupKeeper is implemented correctly and handles errors as expected.

Run the following script to verify the ProcessL1UserDepositTxs method implementation:

Verification successful

ProcessL1UserDepositTxs Method Verified

The ProcessL1UserDepositTxs method is implemented in x/rollup/keeper/deposits.go and is referenced appropriately in the codebase. The test cases in deposits_test.go effectively cover its functionality, including error scenarios.

  • Location: x/rollup/keeper/deposits.go
  • References: x/rollup/keeper/msg_server.go, x/rollup/types/errors.go

The method processes L1 user deposit transactions and handles errors as expected. No further issues were found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of the `ProcessL1UserDepositTxs` method in the `rollupKeeper`.

# Test: Search for the `ProcessL1UserDepositTxs` method implementation. Expect: Proper error handling and logic.
ast-grep --lang go --pattern $'func (k *RollupKeeper) ProcessL1UserDepositTxs($_, $_) error {
  $$$
}'

Length of output: 103


Script:

#!/bin/bash
# Description: Search for the `ProcessL1UserDepositTxs` method across the codebase to verify its implementation or references.

# Use ripgrep to search for the method name in the codebase.
rg 'ProcessL1UserDepositTxs' --context 5

Length of output: 3925

@joshklop
Copy link
Collaborator

joshklop commented Aug 21, 2024

Instead of using our own mock, what do you think about these options:

I tend to prefer just testing the actual behavior rather than mocking (I guess the SDK calls that an "integration test" and not a unit test, oh well). But I can be persuaded otherwise if the integration test utils are too cumbersome.

My thinking is that we might as well just go straight to the integration test if it isn't too much effort, rather than having an extra unit test that involves a lot of mocking.

@natebeauregard
Copy link
Collaborator Author

Instead of using our own mock, what do you think about these options:

I tend to prefer just testing the actual behavior rather than mocking (I guess the SDK calls that an "integration test" and not a unit test, oh well). But I can be persuaded otherwise if the integration test utils are too cumbersome.

My thinking is that we might as well just go straight to the integration test if it isn't too much effort, rather than having an extra unit test that involves a lot of mocking.

@joshklop

Bank module mock from the SDK
I'm a little confused by this option, the linked x/bank/testutil/expected_keepers_mocks.go is not meant to be used externally for mocking the bank keeper. It's instead used by the bank keeper unit tests to mock the account keeper so it's easy to get full test coverage without needing to implement every single account keeper error/edge case in integration tests.

Integration test utils
Yeah it would be nice to have integration tests as well to assert the rollup and bank modules interact together correctly, but I don't think that all of our testing for the x/rollup module should be in an integration test. Unit tests are nice since they're only scoped to the rollup module and are easy to get full test coverage for through mocks. As you mentioned in your comment however, the main drawback of unit tests is not being able to look at the full picture of any related modules interacting with each other in a test app.

After re-reviewing the added unit tests in this PR and re-reading through the Testing docs and ADR 059, I don't think that any of them would qualify to split out into integration tests. I'll start working on a separate PR to add a rollup module integration test to the /tests/integration/ directory that has the full deposit -> withdrawal flow with a real bank keeper and a few scattered error cases. Please lmk if you want to sync up to discuss this in case there was any misunderstanding.

@joshklop
Copy link
Collaborator

@natebeauregard Sounds good, appreciate the descriptions. Let's go with what you suggested.

@natebeauregard
Copy link
Collaborator Author

@natebeauregard Sounds good, appreciate the descriptions. Let's go with what you suggested.

To close the loop, I brought up #165 to add the integration test highlighting the rollup keeper/bank keeper interaction.

x/rollup/types/expected_keepers.go Show resolved Hide resolved
testutils/utils.go Outdated Show resolved Hide resolved
x/rollup/keeper/deposits.go Outdated 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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a6fd94a and 3a8b7e0.

Files selected for processing (1)
  • testutils/utils.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • testutils/utils.go

@@ -108,7 +108,7 @@ func (k *Keeper) MintETH(ctx sdk.Context, addr sdk.AccAddress, amount sdkmath.In
return fmt.Errorf("failed to send deposit coins from rollup module to user account %v: %v", addr, err)
}

// TODO: move event emission to msg_server.go
// TODO: only emit sdk.EventTypeMessage once per message
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Noticed a bug with the message emission for ApplyL1Txs, I updated #162 to reflect this

Copy link
Collaborator

@joshklop joshklop left a comment

Choose a reason for hiding this comment

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

LGTM! Approving optimistically.

Comment on lines 125 to 126
var resp *types.MsgApplyL1TxsResponse
resp, err = keeper.NewMsgServerImpl(s.rollupKeeper).ApplyL1Txs(s.ctx, test.msg)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why the extra var and not :=?

Copy link
Collaborator Author

@natebeauregard natebeauregard Aug 21, 2024

Choose a reason for hiding this comment

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

I was getting the following IDE warning and figured I'd remove the shadowed declaration and just reassign the previously initialized err field: Declaration of 'err' shadows declaration at msg_server_test.go

It's kind of unfortunate you can't conditionally initialize vars in go when assigning multiple vars. Lmk if you feel strongly about changing this, otherwise I'll leave it in

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It'll be removed in the integration test PR too since now err isn't declared above it :)

x/rollup/keeper/msg_server_test.go Outdated Show resolved Hide resolved
x/rollup/keeper/msg_server_test.go Outdated Show resolved Hide resolved

// Verify that the l1 block info and l1 block history are saved to the store
expectedBlockInfo := eth.BlockToInfo(testutils.GenerateL1Block())
store := sdk.UnwrapSDKContext(s.ctx).KVStore(s.storeKey)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this how the store is retrieved in other Cosmos SDK unit tests? Is the store ever kept on the keeper suite struct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Most cosmos sdk unit tests just use pre-existing query endpoints instead of accessing the store directly, however since we don't have any for asserting the l1 block info I opted to just check the store directly. I like your idea of keeping the store in the keeper suite so we can access it directly from the suite, I'll update that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Once we figure out #160, we'll probably add query endpoints. At that point, it would be better to use the query endpoints in tests than directly accessing the store.

This works for now.

- Adds new makefile commands to install mockgen and to
generate expected keeper mocks for use in x/rollup
unit tests.
- Generates expected keeper mocks for the x/rollup module
Adds unit test coverage to assert behavior for the
x/rollup messages and the related helper functions
involved in the deposit and withdrawal flow.
@natebeauregard natebeauregard merged commit 1315787 into main Aug 21, 2024
15 checks passed
@natebeauregard natebeauregard deleted the nkb.add-rollup-module-tests branch August 21, 2024 19:29
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.

Add unit tests for the x/rollup module
2 participants