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: expand apphash test with all state machine msgs #3606

Merged
merged 22 commits into from
Jul 23, 2024

Conversation

ninabarbakadze
Copy link
Member

@ninabarbakadze ninabarbakadze commented Jun 21, 2024

Overview

Resolves #3540 & Resolves #3626

Expected AppHash generated from #3665

@ninabarbakadze ninabarbakadze self-assigned this Jun 21, 2024
@ninabarbakadze ninabarbakadze changed the title test: expand apphash test with more state machine msgs test: expand apphash test with all state machine msgs Jul 4, 2024
@ninabarbakadze ninabarbakadze marked this pull request as ready for review July 5, 2024 11:34
@ninabarbakadze ninabarbakadze requested a review from a team as a code owner July 5, 2024 11:34
@ninabarbakadze ninabarbakadze requested review from ramin and evan-forbes and removed request for a team July 5, 2024 11:34
Copy link
Contributor

coderabbitai bot commented Jul 5, 2024

Walkthrough

Walkthrough

The modifications enhance the TestConsistentAppHash function by incorporating a comprehensive range of SDK message types, greatly improving test coverage. New messages include various transaction types relevant to realistic blockchain operations. The introduction of helper functions simplifies the transaction processing and account creation, while several struct changes were made to support the updated functionalities.

Changes

File Path Change Summary
app/test/consistent_apphash_test.go Enhanced TestConsistentAppHash to cover multiple SDK messages, added helper functions, updated application hash validation.
test/util/common.go Introduced fixed private keys and mnemonics for testing purposes.
test/util/test_app.go Added GenesisTime, updated SetupDeterministicGenesisState to utilize it and include slashing parameters, renamed a function.

Sequence Diagram(s)

No sequence diagrams provided as the changes are mostly related to testing and setup rather than a new feature or modifications to control flow.

Assessment against linked issues

Objective Addressed Explanation
Extend consistent appHash test to include all state machine messages (#3540)
Resolve TODO for link in consistent apphash test (#3626) TODO was not explicitly addressed in the changes.

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 66068d9 and bbc177e.

Files selected for processing (3)
  • app/test/consistent_apphash_test.go (2 hunks)
  • test/util/common.go (2 hunks)
  • test/util/test_app.go (8 hunks)
Additional comments not posted (10)
test/util/test_app.go (3)

45-45: LGTM! Standardized genesis time improves maintainability.

The introduction of GenesisTime enhances code consistency and maintainability.


102-109: LGTM! Improved clarity and added slashing parameters.

The use of GenesisTime and the inclusion of slashing parameters enhance code clarity and functionality.


214-253: LGTM! Systematic approach to adding validators.

The function now adds a set of five validators, ensuring a more systematic approach to validator creation.

test/util/common.go (3)

64-70: LGTM! Hardcoded consensus private keys for testing.

The introduction of FixedConsensusPrivKeys provides fixed data for validation processes in tests.


72-78: LGTM! Hardcoded network private keys for testing.

The introduction of FixedNetworkPrivKeys provides fixed data for validation processes in tests.


82-88: LGTM! Hardcoded mnemonic phrases for testing.

The introduction of FixedMnemonics provides fixed data for validation processes in tests.

app/test/consistent_apphash_test.go (4)

48-299: LGTM! Enhanced test coverage and robustness.

The enhancements to TestConsistentAppHash improve test coverage and robustness by including a broader range of transactions.


343-361: LGTM! Encapsulated complex logic for better readability.

The processSdkMessages function encapsulates complex logic, making the test easier to read and maintain.


364-453: LGTM! Simplified transaction execution process.

The executeTxs function simplifies the transaction execution process and ensures robustness.


456-480: LGTM! Enhanced modularity and maintainability.

The createAccounts and convertToABCIValidators functions enhance modularity and maintainability.


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 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.

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: 1

Outside diff range and nitpick comments (1)
app/test/consistent_apphash_test.go (1)

47-53: Add a comment explaining the expectedDataRoot.

The expectedDataRoot is hardcoded without an explanation. Adding a comment would provide clarity on its origin.

+ // Expected data root produced by v1.x - https://github.com/celestiaorg/celestia-app/blob/v1.x/app/consistent_apphash_test.go
expectedDataRoot := []byte{100, 59, 112, 241, 238, 49, 50, 64, 105, 90, 209, 211, 49, 254, 211, 83, 133, 88, 5, 89, 221, 116, 141, 72, 33, 110, 16, 78, 5, 48, 118, 72}

Comment on lines +51 to +53
// Expected app hash produced by v1.x - https://github.com/celestiaorg/celestia-app/blob/v1.x/app/consistent_apphash_test.go
expectedAppHash := []byte{84, 216, 210, 48, 113, 204, 234, 21, 150, 236, 97, 87, 242, 184, 45, 248, 116, 127, 49, 88, 134, 197, 202, 125, 44, 210, 67, 144, 107, 51, 145, 65}
expectedDataRoot := []byte{100, 59, 112, 241, 238, 49, 50, 64, 105, 90, 209, 211, 49, 254, 211, 83, 133, 88, 5, 89, 221, 116, 141, 72, 33, 110, 16, 78, 5, 48, 118, 72}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider making expectedAppHash and expectedDataRoot configurable.

Hardcoding values like expectedAppHash and expectedDataRoot might make future updates cumbersome. Consider externalizing these values or making them configurable.

- expectedAppHash := []byte{84, 216, 210, 48, 113, 204, 234, 21, 150, 236, 97, 87, 242, 184, 45, 248, 116, 127, 49, 88, 134, 197, 202, 125, 44, 210, 67, 144, 107, 51, 145, 65}
- expectedDataRoot := []byte{100, 59, 112, 241, 238, 49, 50, 64, 105, 90, 209, 211, 49, 254, 211, 83, 133, 88, 5, 89, 221, 116, 141, 72, 33, 110, 16, 78, 5, 48, 118, 72}
+ expectedAppHash := getExpectedAppHash()
+ expectedDataRoot := getExpectedDataRoot()

Committable suggestion was skipped due to low confidence.

Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

still digging through the testing logic, but had time for a first look

nice!

twoInt := sdk.NewInt(2)

// ---------------- First Block ------------
var firstBlockSdkMsgs []sdk.Msg
Copy link
Member

Choose a reason for hiding this comment

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

[not blocking]
how much harder / less efficient would it be to use table driven tests? This feels like reading the bible

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 had it in similar format before i changed it to this because i didn't think a super long list of messages was more readable

Copy link
Member Author

Choose a reason for hiding this comment

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

but if you think it is i'm happy to change it back to the similar format

}

// executeTxs executes a set of transactions and returns the data hash and app hash
func executeTxs(testApp *app.App, rawBlobTx []byte, rawSdkTxs [][]byte, validators []abci.Validator, lastCommitHash []byte) ([]byte, []byte, error) {
Copy link
Member

Choose a reason for hiding this comment

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

[non-blocking]

imo, some version of this would be great to add directly to testapp to use elsewhere!

@rootulp rootulp self-requested a review July 12, 2024 09:21
rootulp
rootulp previously approved these changes Jul 12, 2024
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.

LGTM with a few nits

app/test/consistent_apphash_test.go Outdated Show resolved Hide resolved
app/test/consistent_apphash_test.go Outdated Show resolved Hide resolved
app/test/consistent_apphash_test.go Outdated Show resolved Hide resolved
app/test/consistent_apphash_test.go Show resolved Hide resolved
app/test/consistent_apphash_test.go Show resolved Hide resolved
app/test/consistent_apphash_test.go Outdated Show resolved Hide resolved
app/test/consistent_apphash_test.go Outdated Show resolved Hide resolved
app/test/consistent_apphash_test.go Outdated Show resolved Hide resolved
app/test/consistent_apphash_test.go Outdated Show resolved Hide resolved
test/util/common.go Outdated Show resolved Hide resolved
@celestia-bot celestia-bot requested a review from a team July 13, 2024 09:38
rootulp
rootulp previously approved these changes Jul 13, 2024
)

// NewMsgExec - executes the revoke authorization message
msgExec := authz.NewMsgExec(accountAddresses[0], []sdk.Msg{&msgRevoke})
Copy link
Contributor

Choose a reason for hiding this comment

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

This is framed weird.

User A should grant permission to User B
User B should use MsgExec to perform the action
User A should revoke User B's permission

But here I believe you have User B performing an action of User A's behalf to revoke permission to execute messages to themself. Maybe it's not that problematic, it's like User B is saying no thank you, I don't want your authority


// Block 2 height
blockHeight := testApp.LastBlockHeight() + 2
// NewMsgCancelUnbondingDelegation - cancels unbonding delegation from validator-1
Copy link
Contributor

Choose a reason for hiding this comment

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

This cancels the MsgUndelegate right?

Comment on lines +143 to +146
basicAllowance := feegrant.BasicAllowance{
SpendLimit: sdk.NewCoins(sdk.NewCoin(app.BondDenom, sdk.NewIntFromUint64(1000))),
}
feegrantMsg, err := feegrant.NewMsgGrantAllowance(&basicAllowance, accountAddresses[0], accountAddresses[1])
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you have a message in here that actually uses the feegrant allowance?

app/test/consistent_apphash_test.go Show resolved Hide resolved
cmwaters
cmwaters previously approved these changes Jul 15, 2024
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.

I have a few comments but these are not blocking

evan-forbes
evan-forbes previously approved these changes Jul 15, 2024
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

since we need to add to this test over time, it might be worthwhile to add some docs for the standard way of adding to it. For example, if we add a new message type, how can we add it here and create a new app hash? what do we need to do when we get v3?

@ninabarbakadze
Copy link
Member Author

since we need to add to this test over time, it might be worthwhile to add some docs for the standard way of adding to it. For example, if we add a new message type, how can we add it here and create a new app hash? what do we need to do when we get v3?

Good idea! Exporting this into an issue.

@celestia-bot celestia-bot requested review from a team, cmwaters and evan-forbes and removed request for a team July 23, 2024 10:11
@celestia-bot celestia-bot requested a review from a team July 23, 2024 10:14
@ninabarbakadze ninabarbakadze merged commit 891e0d3 into main Jul 23, 2024
34 checks passed
@ninabarbakadze ninabarbakadze deleted the nina/extend-apphash-test branch July 23, 2024 12:12
ninabarbakadze added a commit that referenced this pull request Sep 17, 2024
## Overview

Resolves #3540 & Resolves #3626

Expected AppHash generated from
#3665
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants