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

test: consistent app hash on v2 #3879

Merged
merged 12 commits into from
Sep 23, 2024
Merged

test: consistent app hash on v2 #3879

merged 12 commits into from
Sep 23, 2024

Conversation

ninabarbakadze
Copy link
Member

@ninabarbakadze ninabarbakadze commented Sep 16, 2024

Overview

Fixes #3624

@ninabarbakadze ninabarbakadze self-assigned this Sep 16, 2024
@ninabarbakadze ninabarbakadze marked this pull request as ready for review September 17, 2024 14:59
@ninabarbakadze ninabarbakadze requested a review from a team as a code owner September 17, 2024 14:59
@ninabarbakadze ninabarbakadze requested review from rootulp and staheri14 and removed request for a team September 17, 2024 14:59
Copy link
Contributor

coderabbitai bot commented Sep 17, 2024

Walkthrough

Walkthrough

The changes in the pull request enhance the testing framework for application hashes by introducing a structured approach to testing consistency across different versions of the Celestia application. A new appHashTest struct is created to encapsulate test case details, and existing tests are refactored into a table-driven format. Functions for encoding SDK messages are modularized, and the executeTxs function is updated to include application version handling. These modifications aim to improve the organization and maintainability of the test code.

Changes

Files Change Summary
app/test/consistent_apphash_test.go Introduced appHashTest struct and refactored TestConsistentAppHash. Added encoding functions for versions 1 and 2, and modified executeTxs to include appVersion. Created createEncodedBlobTx for transaction creation.

Assessment against linked issues

Objective Addressed Explanation
Consistent apphash test between v2 and main (Issue #3624)
Refactor existing test to table-driven test (Issue #3624)

Possibly related PRs

Suggested labels

WS: V2 ✌️


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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

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 and nitpick comments (1)
app/test/consistent_apphash_test.go (1)

Line range hint 152-323: LGTM with a suggestion!

The encodedSdkMessagesV1 function is responsible for creating and encoding various SDK messages for v1 of the application. The function is well-structured, with a clear separation of messages for each block. It covers a wide range of SDK modules and creates messages with deterministic values.

The function uses appropriate naming conventions for variables and messages, making it easy to understand the purpose of each message.

However, the function is quite large and contains a lot of message creation logic. To improve readability and maintainability, consider refactoring the message creation logic into separate smaller functions for each module or message type. This will make the code more modular and easier to understand and maintain.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 228a32d and 54ff6d8.

Files selected for processing (1)
  • app/test/consistent_apphash_test.go (5 hunks)
Additional comments not posted (5)
app/test/consistent_apphash_test.go (5)

62-135: LGTM!

The TestConsistentAppHash function is well-structured and comprehensive. It covers testing the consistency of app hashes across different versions of the application. The test cases are defined in a clear and organized manner using the appHashTest struct. The test execution flow is logical and easy to follow.

The test cases cover both v1 and v2 of the application, ensuring that the app hashes remain consistent across different versions. The test also verifies the consistency of the data root.

Overall, the changes enhance the testing framework and provide a robust way to ensure the consistency of app hashes.


137-150: LGTM!

The getAccountsAndCreateSigner function is a helper utility that retrieves accounts from the keyring, queries their info, and creates a signer with those accounts. The function is well-named, and its purpose is clear. It takes the necessary parameters and returns the signer and account addresses.

The function does not contain any complex logic and serves as a useful utility for setting up the test environment.


325-338: LGTM!

The encodedSdkMessagesV2 function is responsible for creating and encoding SDK messages specific to v2 of the application. The function is small and focused, creating only the MsgTryUpgrade and MsgSignalVersion messages.

The function follows a similar structure to encodedSdkMessagesV1, using the processSdkMessages function to create encoded transactions. This consistency makes it easy to understand and maintain.

The function is well-named and its purpose is clear.


340-354: LGTM!

The createEncodedBlobTx function is responsible for creating, signing, and returning an encoded blob transaction. The function follows a clear and focused logic.

It takes the necessary parameters, creates a new blob using a fixed namespace and deterministic data, and constructs a blobTx struct with the required fields. It then uses the signer to create a PayForBlobs transaction with the blob and default transaction options.

The function uses appropriate naming conventions and structs to organize the data, making it easy to understand and maintain.


Line range hint 420-512: LGTM!

The executeTxs function is responsible for executing a set of transactions and returning the data hash and app hash. The function is well-structured and follows a clear sequence of steps.

It takes the necessary parameters, including the test app, encoded transactions, validators, last commit hash, and app version. It prepares a proposal, processes it, begins a block, delivers the transactions, ends the block, and commits the state using the appropriate functions of the test app.

The function handles both SDK transactions and blob transactions, performing necessary checks and validations throughout the process. It retrieves the app hash using the LastCommitID function of the test app and returns the data hash and app hash.

The function is well-organized and easy to follow, making it maintainable and understandable.

rootulp
rootulp previously approved these changes Sep 17, 2024
name: "execute sdk messages and blob tx on v2",
version: v2.Version,
encodedSdkMessages: func(t *testing.T, accountAddresses []sdk.AccAddress, genValidators []stakingtypes.Validator, testApp *app.App, signer *user.Signer, valSigner *user.Signer) ([][]byte, [][]byte, [][]byte) {
firstBlockEncodedTxs, secondBlockEncodedTxs, thirdBlockEncodedTxs := encodedSdkMessagesV1(t, accountAddresses, genValidators, testApp, signer, valSigner)
Copy link
Collaborator

Choose a reason for hiding this comment

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

v2 removed x/blobstream so I think the blobstream transactions need to be removed the test case on v2. Alternatively if they aren't removed, maybe this test case should verify that x/blobstream messages are no-ops on v2.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think those messages are supposed to be rejected on v2. I'll investigate.

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the blobstream messages were never part of the v1 test suite anyway so I think doing it like this is fine

Copy link
Collaborator

Choose a reason for hiding this comment

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

If the v1 test doesn't have blobstream messages, is it missing any other messages? Do we have a GH issue to make this test exhaustive of all message types supported by each app version?

Copy link
Member Author

Choose a reason for hiding this comment

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

it covers most of it now. the only message we don't execute is MsgSubmitEvidence and IBC messages that require a different setup. Initially, we wanted to cover as much as possible and we're now extending to cover IBC messages too.

Copy link
Contributor

@cmwaters cmwaters left a comment

Choose a reason for hiding this comment

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

Looks good. Probably a good idea to add ICA and IBC messages as well to expand the surface area of the tests

Copy link
Contributor

@cmwaters cmwaters left a comment

Choose a reason for hiding this comment

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

Don't know why this was not included in my original review 🤷

app/test/consistent_apphash_test.go Outdated Show resolved Hide resolved
@ninabarbakadze
Copy link
Member Author

Looks good. Probably a good idea to add ICA and IBC messages as well to expand the surface area of the tests

I'm extending the test to include all IBC messages for all verisons

@celestia-bot celestia-bot requested review from a team and evan-forbes and removed request for a team September 19, 2024 17:32
@ninabarbakadze ninabarbakadze marked this pull request as draft September 19, 2024 17:32
@ninabarbakadze
Copy link
Member Author

Looks good. Probably a good idea to add ICA and IBC messages as well to expand the surface area of the tests

I'm extending the test to include all IBC messages for all verisons

After looking into adding IBC messages I realised that it would require me to add more test chains, set up relayers, etc. I think it's best if we have a separate test for executing IBC messages and comparing AppHash between versions. Thoughts? @cmwaters @rootulp

@ninabarbakadze ninabarbakadze marked this pull request as ready for review September 21, 2024 10:40
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 and nitpick comments (1)
app/test/consistent_apphash_test.go (1)

Line range hint 154-353: Approved with suggestions

The encodedSdkMessagesV1 function generates and returns encoded SDK messages for v1 of the application. The separation of message creation logic into a separate function improves the readability and maintainability of the test code. The division of messages into three blocks helps in organizing the message creation logic.

However, the function is quite large and contains a lot of message creation logic for different scenarios. Consider breaking down the function further into smaller, more focused functions based on the type of messages being created. This will enhance the readability and maintainability of the code even further.

Additionally, consider adding comments to explain the purpose of each block of messages and the scenarios they cover. This will make it easier for other developers to understand the intent behind each block of messages.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 54ff6d8 and 86a2e63.

Files selected for processing (1)
  • app/test/consistent_apphash_test.go (5 hunks)
Additional comments not posted (14)
app/test/consistent_apphash_test.go (14)

11-12: LGTM!

The imports for v1 and v2 appconsts are necessary to access version-specific constants.


18-19: LGTM!

The imports for blobstreamtypes and signal are necessary to access types from the respective modules.


22-29: LGTM!

The additional imports from the cosmos-sdk are necessary to access various types and modules used in the test.


38-38: LGTM!

The import for gethcommon from go-ethereum is necessary to access the HexToAddress function used in the test.


45-49: LGTM!

The blobTx struct is well-defined with necessary fields to represent a blob transaction.


51-54: LGTM!

The type aliases encodedSdkMessages and encodedBlobTxs provide a cleaner way to define function signatures for generating encoded SDK messages and blob transactions.


56-63: LGTM!

The appHashTest struct is well-defined with necessary fields to represent a test case for the app hash consistency test. The struct provides a clean way to organize test case details.


65-137: LGTM!

The TestConsistentAppHash function is well-structured and comprehensive. It covers the necessary steps to verify app hash consistency across different versions of the application. The use of the appHashTest struct provides a clean and maintainable way to define and iterate over test cases. The modularization of test setup, transaction generation, and execution logic enhances the readability and maintainability of the code. The test performs thorough consistency checks by verifying both the app hash and data root against expected values.


139-152: LGTM!

The getAccountsAndCreateSigner function encapsulates the logic for retrieving accounts from the keyring and creating a signer with the accounts. This promotes code reuse and improves readability. The function takes necessary parameters and returns the signer and account addresses, which can be used in other parts of the test. The separation of concerns and modularization of the signer creation logic is a good practice.


304-313: LGTM!

The code segment demonstrates the creation of a periodic vesting account using the NewMsgCreatePeriodicVestingAccount function. The vesting periods are properly defined using the vestingtypes.Period struct, and the message is appended to the secondBlockSdkMsgs slice to be included in the second block of messages. The usage of the vesting account creation message is correct and follows the expected pattern.


315-318: LGTM!

The code segment demonstrates the creation of a permanent locked account using the NewMsgCreatePermanentLockedAccount function. The usage of the function is correct, and the message is properly appended to the secondBlockSdkMsgs slice to be included in the second block of messages. The creation of a permanent locked account follows the expected pattern.


320-323: LGTM!

The code segment demonstrates the creation of a vesting account using the NewMsgCreateVestingAccount function. The usage of the function is correct, and the necessary parameters such as vesting amount, vesting start time, and vesting end time are provided. The message is properly appended to the secondBlockSdkMsgs slice to be included in the second block of messages. The creation of a vesting account follows the expected pattern.


338-343: LGTM!

The code segment demonstrates the registration of an EVM address using the NewMsgRegisterEVMAddress function. The registration is conditionally performed based on the application version, which is a good practice to ensure compatibility with different versions. The message is properly appended to the thirdBlockSdkMsgs slice to be included in the third block of messages. The usage of the EVM address registration message is correct and follows the expected pattern.


355-368: LGTM!

The encodedSdkMessagesV2 function encapsulates the logic for generating v2-specific SDK messages, promoting code reuse and readability. The separation of v2-specific message creation logic into a separate function improves the organization and maintainability of the test code. The function takes necessary parameters such as validators and a validator signer to create the messages. It returns the encoded transactions, which can be used in other parts

@cmwaters
Copy link
Contributor

Don't we already have tests where we send IBC messages (i.e. ICA and Transfer) can't we just add the app hash test vectors within those tests?

Copy link
Contributor

@cmwaters cmwaters left a comment

Choose a reason for hiding this comment

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

LGTM

@ninabarbakadze
Copy link
Member Author

Don't we already have tests where we send IBC messages (i.e. ICA and Transfer) can't we just add the app hash test vectors within those tests?

yeah we could. I'll open an issue for it.

Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

I'm okay with expanding this test or adding a new test to expand message types that are supported (including IBC message types).

@ninabarbakadze ninabarbakadze merged commit 0e73077 into main Sep 23, 2024
32 checks passed
@ninabarbakadze ninabarbakadze deleted the nina/v2-apphash-test branch September 23, 2024 20:10
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.

AppHash mismatch test between main and v2
3 participants