Skip to content

Conversation

Vvaradinov
Copy link
Contributor

@Vvaradinov Vvaradinov commented Oct 14, 2024

Description

This PR adds the 3 high priority queries from the list of missing precompiles. There is one TODO left that I couldn't get to work in the integration tests without implementing the deposit transaction as a precompile transaction. Maybe there is a workaround ?

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • tackled an existing issue or discussed with a team member
  • left instructions on how to review the changes
  • targeted the correct branch (see PR Targeting)

Reviewers Checklist

All items are required.
Please add a note if the item is not applicable
and please add your handle next to the items reviewed
if you only reviewed selected items.

I have...

  • added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • confirmed all author checklist items have been addressed
  • confirmed that this PR does not change production code
  • reviewed content
  • tested instructions (if applicable)
  • confirmed all CI checks have passed

Summary by CodeRabbit

  • New Features

    • Enhanced governance interface with new structures for managing deposits and tally results.
    • Added functions to retrieve deposit information and tally results for governance proposals.
  • Bug Fixes

    • Introduced error handling for invalid depositors.
  • Tests

    • Added new integration and unit tests to validate the functionality of the newly implemented methods.
  • Documentation

    • Updated ABI to reflect new functions for improved governance management.
    • Updated CHANGELOG to include significant modifications and improvements.

@Vvaradinov Vvaradinov requested a review from a team as a code owner October 14, 2024 14:14
@Vvaradinov Vvaradinov requested review from hanchon and ramacarlucho and removed request for a team October 14, 2024 14:14
Copy link
Contributor

coderabbitai bot commented Oct 14, 2024

Walkthrough

The pull request enhances the IGov interface and related components within the governance precompile. It introduces new structures, DepositData and TallyResultData, for managing governance deposits and tally results. Additionally, three new functions—getDeposit, getDeposits, and getTallyResult—are added to facilitate data retrieval. The ABI is updated accordingly, and the gov package is modified to support new governance transaction handling. Integration and query tests are also updated to validate the new functionalities.

Changes

File Change Summary
precompiles/gov/IGov.sol Added structs: DepositData, TallyResultData. Added functions: getDeposit, getDeposits, getTallyResult.
precompiles/gov/abi.json Updated ABI to include methods: getDeposit, getDeposits, getTallyResult.
precompiles/gov/errors.go Added constant: ErrInvalidDepositor.
precompiles/gov/gov.go Updated Run function to include: GetDepositMethod, GetDepositsMethod, GetTallyResultMethod.
precompiles/gov/integration_test.go Modified tests to include new context for tally results; added a test for tally result retrieval.
precompiles/gov/query.go Added methods: GetDeposit, GetDeposits, GetTallyResult. Added constants for new methods.
precompiles/gov/query_test.go Added new test functions: TestGetDeposit, TestGetDeposits, TestGetTallyResult. Added new variables and helper functions for tests.
precompiles/gov/setup_test.go Updated import statements and SetupTest method; added variable for the first test proposal.
.github/workflows/e2e-test.yml Modified GitHub Actions workflow for E2E testing, updating job structure, dependencies, and token handling.
CHANGELOG.md Updated to reflect changes across versions, including governance-related modifications and enhancements.

Possibly related PRs

Suggested labels

types

Suggested reviewers

  • 0xstepit
  • ramacarlucho

Poem

In the governance land, where rabbits convene,
New deposits and tallies, a sight to be seen.
With structures so bright, and functions anew,
We hop with delight, for the changes are true!
Let's tally our votes, and make our way clear,
In the world of IGov, we have nothing to fear! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bc1b864 and 8d17616.

📒 Files selected for processing (1)
  • .golangci.yml (0 hunks)
💤 Files with no reviewable changes (1)
  • .golangci.yml

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>, please review it.
    • 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 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.

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

🧹 Outside diff range and nitpick comments (6)
precompiles/gov/gov.go (1)

114-119: LGTM! Consider grouping related methods for improved readability.

The new methods (GetDepositMethod, GetDepositsMethod, and GetTallyResultMethod) have been correctly implemented and align with the PR objectives. The implementation is consistent with the existing code structure and doesn't introduce any breaking changes.

For improved readability, consider grouping related methods together. For example:

case GetVoteMethod:
    bz, err = p.GetVote(ctx, method, contract, args)
case GetVotesMethod:
    bz, err = p.GetVotes(ctx, method, contract, args)
case GetDepositMethod:
    bz, err = p.GetDeposit(ctx, method, contract, args)
case GetDepositsMethod:
    bz, err = p.GetDeposits(ctx, method, contract, args)
case GetTallyResultMethod:
    bz, err = p.GetTallyResult(ctx, method, contract, args)

This grouping makes it easier to see all the "Get" methods together.

precompiles/gov/abi.json (2)

121-217: LGTM: getDeposits function implementation with a minor suggestion

The getDeposits function is well-implemented with proper pagination support. It correctly uses the view modifier and returns both the deposits data and pagination information.

Consider adding a comment or documentation to clarify the purpose of the PageRequest struct, especially for developers who might not be familiar with this pagination pattern. This could include a brief explanation of how to use the pagination parameters effectively.


218-258: LGTM: getTallyResult function implementation with optimization suggestion

The getTallyResult function is well-defined and correctly uses the view modifier. It provides a clear way to retrieve tally results for a specific proposal.

Consider using a more appropriate data type for vote counts in the TallyResultData struct. Currently, the votes (yes, abstain, no, noWithVeto) are stored as strings. For numerical values, using uint256 or a similar integer type would be more efficient and easier to work with in calculations. This change would require updating the struct definition and any related functions. For example:

struct TallyResultData {
    uint256 yes;
    uint256 abstain;
    uint256 no;
    uint256 noWithVeto;
}

This change would improve performance and reduce gas costs when working with vote counts.

precompiles/gov/integration_test.go (3)

366-435: Consider removing commented-out code and tracking TODOs separately

The large block of commented-out code for deposit queries (lines 366-435) clutters the file and may become outdated. Consider the following actions:

  1. Remove the commented-out code to improve readability.
  2. Create a separate GitHub issue to track the pending implementation of deposit queries.
  3. Add a short comment with the issue number for reference, e.g., "// TODO(#issueNumber): Implement deposit queries once precompile transaction is available"

This approach will keep the test file clean while ensuring the pending work is properly tracked.

Would you like me to help create a GitHub issue for tracking the deposit queries implementation?

🧰 Tools
🪛 GitHub Check: Run golangci-lint

[failure] 367-367:
commentFormatting: put a space between // and comment text (gocritic)


437-477: LGTM! Consider adding a comment for clarity

The new tally result query test is well-structured and comprehensive. It correctly sets up the preconditions by submitting a vote before querying the tally result, and the assertions check for the expected values.

To improve clarity, consider adding a brief comment explaining why the expected values are what they are. For example, before line 472:

// Expected values based on the single vote cast in BeforeEach
Expect(out.TallyResult.Yes).To(Equal("3000000000000000000"))

This will help future readers understand the test's expectations more easily.


367-367: Minor: Add space after comment slashes

To improve consistency and adhere to Go style conventions, add a space between the comment slashes and the comment text:

-		// TODO: Can't add deposit manually without the precompile transaction available ?
+		// TODO: Can't add deposit manually without the precompile transaction available?

Also, consider removing the space before the question mark at the end of the comment.

🧰 Tools
🪛 GitHub Check: Run golangci-lint

[failure] 367-367:
commentFormatting: put a space between // and comment text (gocritic)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b523bb1 and e97fa40.

📒 Files selected for processing (9)
  • precompiles/gov/IGov.sol (2 hunks)
  • precompiles/gov/abi.json (1 hunks)
  • precompiles/gov/errors.go (1 hunks)
  • precompiles/gov/gov.go (1 hunks)
  • precompiles/gov/integration_test.go (1 hunks)
  • precompiles/gov/query.go (2 hunks)
  • precompiles/gov/query_test.go (2 hunks)
  • precompiles/gov/setup_test.go (3 hunks)
  • precompiles/gov/types.go (2 hunks)
🧰 Additional context used
🪛 GitHub Check: Run golangci-lint
precompiles/gov/integration_test.go

[failure] 367-367:
commentFormatting: put a space between // and comment text (gocritic)

precompiles/gov/query_test.go

[failure] 236-236:
composites: github.com/evmos/evmos/v20/precompiles/common.Coin struct literal uses unkeyed fields (govet)

precompiles/gov/setup_test.go

[failure] 47-47:
redefines-builtin-id: redefinition of the built-in type any (revive)

precompiles/gov/types.go

[failure] 70-70:
var-naming: struct field ProposalId should be ProposalID (revive)


[failure] 81-81:
var-naming: struct field ProposalId should be ProposalID (revive)


[failure] 98-98:
var-naming: struct field ProposalId should be ProposalID (revive)

🔇 Additional comments (17)
precompiles/gov/errors.go (1)

26-27: LGTM: New error constant added correctly.

The new ErrInvalidDepositor constant is well-implemented and consistent with the existing error message pattern in the file. It aligns with the PR objectives of enhancing governance-related functionality.

precompiles/gov/setup_test.go (2)

7-9: LGTM: New imports are appropriate for the changes.

The added imports for math, types, and sdk from the Cosmos SDK are necessary for the modifications in the SetupTest method. They provide essential functionalities for handling mathematical operations, type management, and SDK features.


63-63: LGTM: Improved minimum deposit setup.

The modification to set the minimum deposit using sdk.NewCoins(sdk.NewCoin("aevmos", math.NewInt(100))) is a good improvement. This change:

  1. Utilizes the math package to create the deposit amount, ensuring precise handling of large integer values.
  2. Provides more explicit and type-safe creation of the coin value.
  3. Aligns with best practices for handling currency amounts in the Cosmos SDK.

This update enhances the accuracy and reliability of the minimum deposit setup in the test environment.

precompiles/gov/gov.go (1)

Line range hint 1-153: Consider updating IsTransaction method and addressing integration test TODO

The implementation of the new methods looks great. However, there are two points to consider:

  1. If any of the new methods (GetDepositMethod, GetDepositsMethod, GetTallyResultMethod) are transactions rather than queries, update the IsTransaction method accordingly.

  2. Remember to address the TODO mentioned in the PR objectives regarding the integration tests, specifically the difficulty in implementing the deposit transaction as a precompile transaction.

To check if there are any TODOs related to integration tests, run:

Would you like assistance in addressing the integration test TODO or updating the IsTransaction method if necessary?

precompiles/gov/abi.json (2)

68-120: LGTM: getDeposit function implementation

The getDeposit function is well-defined with appropriate input parameters and return type. It correctly uses the view modifier, indicating it doesn't modify the contract state. The DepositData struct provides comprehensive information about the deposit, including the proposal ID, depositor address, and the amount as an array of Coin structs.


Line range hint 1-257: Overall assessment: Solid enhancements to the IGov contract

The additions to the IGov contract ABI significantly enhance its functionality by introducing methods to retrieve deposit information and tally results. These new functions (getDeposit, getDeposits, and getTallyResult) are well-implemented and properly use the view modifier for read-only operations.

The changes align well with the PR objectives, addressing the need for high-priority queries that were previously missing from the precompiles list. The new functions provide a comprehensive way to interact with governance-related data, which should improve the overall usability of the contract.

To ensure these changes are properly integrated, please run the following verification script:

This script will help ensure that the new functions are properly integrated into the existing codebase and that there are no conflicts or structural issues with the ABI.

✅ Verification successful

Verification Successful: No conflicts found in IGov ABI changes

All new functions (getDeposit, getDeposits, getTallyResult) are properly integrated into the IGov contract. No duplicate function signatures were found, and the ABI JSON structure is valid. The additions enhance the contract's functionality without introducing any conflicts or issues.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the new functions are properly integrated and there are no conflicts with existing code.

# Test: Check if the new functions are referenced in other parts of the codebase
echo "Checking references to new functions:"
rg --type solidity -e 'getDeposit' -e 'getDeposits' -e 'getTallyResult'

# Test: Verify that there are no duplicate function signatures
echo "Checking for duplicate function signatures:"
jq '.abi | map(.name) | group_by(.) | map(select(length > 1))' precompiles/gov/abi.json

# Test: Ensure that the ABI is valid JSON
echo "Validating ABI JSON structure:"
jq '.' precompiles/gov/abi.json > /dev/null && echo "ABI is valid JSON" || echo "ABI is not valid JSON"

Length of output: 523


Script:

#!/bin/bash
# Description: Verify that the new functions are properly integrated and there are no conflicts with existing code.

# Test: Check if the new functions are referenced in other parts of the codebase
echo "Checking references to new functions in .sol files:"
rg --glob '*.sol' -e 'getDeposit' -e 'getDeposits' -e 'getTallyResult'

# Test: Verify that there are no duplicate function signatures
echo "Checking for duplicate function signatures:"
jq '.abi | map(.name) | group_by(.) | map(select(length > 1))' precompiles/gov/abi.json

# Test: Ensure that the ABI is valid JSON
echo "Validating ABI JSON structure:"
jq '.' precompiles/gov/abi.json > /dev/null && echo "ABI is valid JSON" || echo "ABI is not valid JSON"

Length of output: 976

precompiles/gov/query.go (1)

18-23: Constants are named consistently with existing code

The newly added constants GetDepositMethod, GetDepositsMethod, and GetTallyResultMethod are consistent with the existing naming convention used for method names in this package, ensuring clarity and coherence.

precompiles/gov/IGov.sol (5)

41-46: The DepositData struct is appropriately defined.

The struct accurately captures the necessary information about a deposit on a proposal, including the proposal ID, depositor's address, and the amount.


126-134: The getDeposit function is correctly defined.

The function provides a way to retrieve the deposit information for a specific depositor on a given proposal, which is essential for tracking individual contributions.


135-147: The getDeposits function is well-defined with pagination support.

Incorporating pagination allows efficient retrieval of deposits when dealing with a large number of entries, enhancing scalability and performance.


148-153: The getTallyResult function is properly implemented.

This function enables users to obtain the tally results of a proposal, which is critical for transparency and accountability in governance processes.


49-54: ⚠️ Potential issue

Verify the use of string data types for vote counts in TallyResultData.

The fields yes, abstain, no, and noWithVeto are defined as string. If these fields represent numeric vote counts, consider using numeric types like uint256 or uint64 for mathematical operations and to ensure type safety.

Run the following script to check how vote counts are handled elsewhere in the codebase:

✅ Verification successful

Vote counts are appropriately using string data types. No issues found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find how vote counts are defined and used in the codebase.

# Search for definitions of TallyResultData and examine the data types.
rg --type solidity 'struct TallyResultData' -A 5

# Search for other instances where tally results are defined or used.
rg --type solidity 'tallyResult' -A 5

Length of output: 154


Script:

#!/bin/bash
# Description: Find how vote counts are defined and used in the codebase.

# Search for definitions of TallyResultData and examine the data types.
rg --glob '*.sol' 'struct TallyResultData' -A 5

# Search for other instances where tally results are defined or used.
rg --glob '*.sol' 'tallyResult' -A 5

Length of output: 646


Script:

#!/bin/bash
# Description: Find usages of TallyResultData fields to determine if they are used in mathematical operations.

# Search for usages of tallyResult.yes
rg --glob '*.sol' 'tallyResult\.yes' 

# Search for usages of tallyResult.abstain
rg --glob '*.sol' 'tallyResult\.abstain' 

# Search for usages of tallyResult.no
rg --glob '*.sol' 'tallyResult\.no' 

# Search for usages of tallyResult.noWithVeto
rg --glob '*.sol' 'tallyResult\.noWithVeto' 

Length of output: 165

precompiles/gov/types.go (2)

82-82: Use correct capitalization for 'ProposalID' field name

As previously noted, the field ProposalId should be renamed to ProposalID to follow Go naming conventions.

Apply this diff to fix the naming:

 type DepositsInput struct {
-    ProposalId uint64
+    ProposalID uint64
     Pagination query.PageRequest
 }

98-98: Use correct capitalization for 'ProposalID' field name

As previously noted, the field ProposalId should be renamed to ProposalID to follow Go naming conventions.

Apply this diff to fix the naming:

 type DepositData struct {
-    ProposalId uint64         `abi:"proposalId"`
+    ProposalID uint64         `abi:"proposalId"`
     Depositor  common.Address `abi:"depositor"`
     Amount     []cmn.Coin     `abi:"amount"`
 }
🧰 Tools
🪛 GitHub Check: Run golangci-lint

[failure] 98-98:
var-naming: struct field ProposalId should be ProposalID (revive)

precompiles/gov/query_test.go (3)

179-243: TestGetDeposit function is well-implemented

The TestGetDeposit function appropriately tests both valid and invalid scenarios for retrieving a deposit. The test cases are well-structured, and the use of malleate functions ensures clear setup for each case.

🧰 Tools
🪛 GitHub Check: Run golangci-lint

[failure] 236-236:
composites: github.com/evmos/evmos/v20/precompiles/common.Coin struct literal uses unkeyed fields (govet)


245-302: Comprehensive testing in TestGetDeposits

The TestGetDeposits function provides thorough coverage for fetching multiple deposits, including edge cases with invalid proposal IDs. The clarity in test case definitions enhances maintainability.


304-369: Effective validation in TestGetTallyResult

The TestGetTallyResult function accurately tests the retrieval of tally results for proposals, covering both successful retrievals and error handling for non-existent proposals.

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

🧹 Outside diff range and nitpick comments (5)
precompiles/gov/setup_test.go (1)

62-66: LGTM with a minor suggestion for clarity.

The changes are appropriate:

  1. Using anyMessage in the Messages field is consistent with the earlier type-safe approach.
  2. Updating the minimum deposit parameter with math.NewInt(100) provides more precision.

For improved readability, consider extracting the minimum deposit amount to a named constant:

const minDepositAmount = 100
govGen.Params.MinDeposit = sdk.NewCoins(sdk.NewCoin("aevmos", math.NewInt(minDepositAmount)))

This change would make the code more self-documenting and easier to modify in the future.

precompiles/gov/integration_test.go (1)

456-477: LGTM: Tally result query test implementation

The test for querying tally results is well-implemented:

  1. It correctly calls the contract and checks the logs.
  2. The assertions verify the tally results for all vote options (Yes, Abstain, No, NoWithVeto).
  3. The expected "Yes" count (3000000000000000000) matches the voting power of the single vote cast in the setup.

Consider adding a comment explaining the expected "Yes" count value (3000000000000000000) to improve readability. For example:

// Expected "Yes" count is 3 EVMOS (3e18 in base units), which is the default voting power
Expect(out.TallyResult.Yes).To(Equal("3000000000000000000"))
precompiles/gov/types.go (3)

325-337: Enhance error messages for clarity in 'ParseTallyResultArgs'.

The error messages in ParseTallyResultArgs could be more informative. Providing detailed context in error messages helps with debugging.


283-304: Simplify argument parsing in 'ParseDepositArgs'.

Consider using a structured input or consolidating type assertions to make the code more concise and maintainable.


307-321: Ensure consistent error handling in 'ParseDepositsArgs'.

The function ParseDepositsArgs could benefit from consistent error messages and handling similar to other parsing functions. This improves code readability and maintainability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e97fa40 and db4d16d.

📒 Files selected for processing (4)
  • precompiles/gov/integration_test.go (1 hunks)
  • precompiles/gov/query_test.go (2 hunks)
  • precompiles/gov/setup_test.go (3 hunks)
  • precompiles/gov/types.go (2 hunks)
🧰 Additional context used
🔇 Additional comments (13)
precompiles/gov/setup_test.go (2)

7-10: LGTM: New imports are appropriate for the changes.

The added imports for math, types, and sdk from Cosmos SDK are necessary and align with the modifications in the SetupTest method.


45-50: LGTM: Improved type safety and addressed past comment.

The changes enhance type safety by wrapping the test proposal in an Any type. The error handling is appropriate, and the variable name anyMessage effectively addresses the past comment about shadowing the any built-in type.

precompiles/gov/query_test.go (6)

4-35: LGTM: New imports and variables look good

The new imports, variables, and the getTestProposal() function are well-structured and necessary for the added test cases. They provide the required setup for testing governance-related queries.


180-243: LGTM: TestGetDeposit function is well-structured

The TestGetDeposit function provides good coverage for both successful and error scenarios. It properly uses the PrecompileTestSuite for setup and assertions, and the malleate function effectively sets up the test state.


245-302: LGTM: TestGetDeposits function is well-implemented

The TestGetDeposits function provides comprehensive coverage for both successful and error scenarios. It effectively uses the PrecompileTestSuite for setup and assertions, and the malleate function properly sets up the test state. The assertions correctly check for the expected deposits and page response.


304-369: LGTM: TestGetTallyResult function is well-designed

The TestGetTallyResult function provides thorough coverage for both successful and error scenarios. It effectively uses the PrecompileTestSuite for setup and assertions. The malleate function comprehensively sets up the test state by submitting a proposal, adding a deposit, and casting a vote. The assertions correctly verify the expected tally result.


Line range hint 1-369: Overall, excellent additions to the governance query tests

The new test functions (TestGetDeposit, TestGetDeposits, and TestGetTallyResult) are well-structured and provide comprehensive coverage for the new governance query methods. They effectively use the PrecompileTestSuite for setup and assertions, and the test cases cover both successful and error scenarios. The only minor issue found was the use of unkeyed fields in a struct literal, which has been addressed in a separate comment.

These additions significantly enhance the test coverage for the governance precompile and will help ensure the reliability of the new query methods.


236-236: ⚠️ Potential issue

Use keyed fields in struct literal for cmn.Coin

At line 236, the cmn.Coin struct is initialized using unkeyed fields. This can lead to maintenance issues if the struct's definition changes in the future. It's recommended to use field names when initializing structs for better readability and safety.

Apply this diff to fix the issue:

-s.Require().Equal([]cmn.Coin{{Denom: "aevmos", Amount: big.NewInt(100)}}, out.Deposit.Amount)
+s.Require().Equal([]cmn.Coin{{Denom: "aevmos", Amount: big.NewInt(100)}}, out.Deposit.Amount)
precompiles/gov/integration_test.go (2)

437-454: LGTM: Tally result query test setup

The setup for the tally result query test is well-structured:

  1. It correctly submits a vote before querying the tally results.
  2. The use of Expect statements ensures that the vote is submitted successfully and a new block is created.

This setup provides a good foundation for testing the tally result query functionality.


Line range hint 1-477: Summary of changes and suggestions

  1. The new tests for tally result queries are well-implemented and provide good coverage for this functionality.
  2. The deposit functionality is not yet implemented, as indicated by the commented-out tests and TODO comment.

Main points:

  • Address the TODO for deposit functionality implementation.
  • Once deposit functionality is implemented, uncomment and finalize the deposit tests.
  • Consider adding a clarifying comment for the expected "Yes" count in the tally result test.

Overall, the changes improve the test coverage for the governance precompile, focusing on tally result queries. The next step would be to implement the deposit functionality to complete the feature set.

precompiles/gov/types.go (3)

70-70: Use consistent capitalization for 'ProposalID'.

According to Go naming conventions, acronyms should be capitalized consistently. The field ProposalId should be renamed to ProposalID in both DepositInput and DepositData structs.

Also applies to: 98-98


340-343: Handle errors properly in 'FromResponse' methods.

In DepositOutput.FromResponse and DepositsOutput.FromResponse, if address conversion fails, the methods return nil without any error information. This can make debugging difficult. Consider modifying the function signatures to return an error and handle it appropriately.

Also applies to: 362-365


351-355: Refactor duplicate code in 'FromResponse' methods to eliminate redundancy.

The FromResponse methods for DepositOutput and DepositsOutput share similar code for converting deposits. Refactor this logic into a shared helper function to improve maintainability and reduce code duplication.

Also applies to: 373-377

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

🧹 Outside diff range and nitpick comments (4)
precompiles/gov/query_test.go (3)

180-238: Enhance test cases for TestGetDeposit

While the structure of the test function is good, there are a few areas that could be improved:

  1. The malleate function is empty for both test cases. Consider adding logic to create a deposit for the success case.
  2. The success case doesn't actually verify that a deposit exists before querying it. This might lead to false positives.
  3. Add more test cases to cover different scenarios, such as:
    • A proposal with multiple deposits
    • A proposal with no deposits
    • Edge cases for proposal IDs

Enhancing these areas will provide more robust testing for the GetDeposit functionality.


240-293: LGTM: TestGetDeposits looks good with minor suggestions

The TestGetDeposits function is well-structured and covers important scenarios. The use of malleate to create deposits and the testing of pagination are particularly good. To further improve the test coverage, consider:

  1. Adding a test case for a proposal with multiple deposits to ensure proper handling of multiple results.
  2. Testing edge cases for pagination, such as requesting a page beyond available results.
  3. Verifying the contents of the returned deposits more thoroughly, not just the length.

These additions would make the tests even more robust.


295-360: LGTM: TestGetTallyResult is comprehensive with room for minor enhancements

The TestGetTallyResult function is well-implemented and covers crucial scenarios. The malleate function's comprehensive setup, including proposal creation, deposit, and voting, is particularly commendable. To further strengthen the tests:

  1. Consider adding a test case for a proposal in different stages (e.g., deposit period, voting period, passed, rejected) to ensure correct tally results in various states.
  2. Add a test case with multiple votes from different addresses to verify correct tallying of multiple votes.
  3. Verify that the tally results match the expected values based on the voting power of the accounts used in the test.

These additions would provide even more thorough coverage of the GetTallyResult functionality.

precompiles/gov/integration_test.go (1)

Line range hint 1-478: Overall improvements for governance precompile integration tests

The additions to the integration tests for the governance precompile are valuable and well-structured. However, there are several areas where the tests can be improved:

  1. Address the TODO comment about adding deposits manually (line 367).
  2. Enhance the deposit and deposits query tests:
    • Ensure proper setup of deposits before querying.
    • Test multiple deposits and pagination scenarios.
  3. Improve the tally result query test:
    • Cover multiple voting scenarios (Yes, No, Abstain, NoWithVeto).
    • Make expected results dynamic based on votes cast.
  4. Consider making hardcoded values (like deposit amounts and vote counts) more flexible and easily configurable for different test scenarios.

These improvements will make the tests more robust, comprehensive, and easier to maintain. They will also provide better coverage of edge cases and real-world scenarios for the governance precompile functionality.

As you continue to develop these tests, consider creating helper functions for common setup tasks (like creating deposits or casting votes) to reduce code duplication and improve readability. This will make it easier to add new test scenarios in the future.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between db4d16d and 3705194.

📒 Files selected for processing (3)
  • precompiles/gov/integration_test.go (2 hunks)
  • precompiles/gov/query_test.go (2 hunks)
  • precompiles/gov/setup_test.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • precompiles/gov/setup_test.go
🧰 Additional context used
🔇 Additional comments (2)
precompiles/gov/query_test.go (2)

4-35: LGTM: New imports and variables look good

The new imports, variables, and the getTestProposal() function are well-structured and necessary for the added test cases. They provide the required setup for testing governance-related queries.


Line range hint 1-360: Overall assessment: Good additions with room for enhancement

The new test functions (TestGetDeposit, TestGetDeposits, and TestGetTallyResult) significantly improve the test coverage for governance-related queries. They are well-structured and cover essential scenarios. However, there's room for enhancement:

  1. Increase the variety of test cases to cover more edge cases and scenarios.
  2. Ensure that setup functions (malleate) create necessary data for all test cases.
  3. Add more thorough verification of returned data in success cases.

These improvements will further strengthen the robustness of the test suite. Great job on expanding the test coverage!

@Vvaradinov Vvaradinov requested a review from GAtom22 October 16, 2024 14:24
@GAtom22
Copy link
Contributor

GAtom22 commented Oct 18, 2024

https://github.com/Mergifyio backport rama/release-v20

Copy link
Contributor

mergify bot commented Oct 18, 2024

backport rama/release-v20

✅ Backports have been created

Copy link
Contributor

@GAtom22 GAtom22 left a comment

Choose a reason for hiding this comment

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

LGTM! Great work @Vvaradinov!

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

🧹 Outside diff range and nitpick comments (12)
precompiles/gov/query_test.go (1)

176-234: LGTM with suggestion: TestGetDeposit function is well-structured.

The TestGetDeposit function follows the established pattern and includes appropriate test cases. However, consider enhancing the malleate function in the "valid query" test case to set up the necessary state (e.g., creating a proposal and adding a deposit) to make the test more robust.

Consider updating the "valid query" test case's malleate function:

malleate: func() {
    proposal, err := s.network.App.GovKeeper.SubmitProposal(s.network.GetContext(), TestProposalMsgs, "", "Test Proposal", "description", depositor, false)
    s.Require().NoError(err)
    _, err = s.network.App.GovKeeper.AddDeposit(s.network.GetContext(), proposal.Id, depositor, sdk.NewCoins(sdk.NewCoin(s.network.GetDenom(), math.NewInt(100))))
    s.Require().NoError(err)
},
precompiles/gov/abi.json (2)

121-217: LGTM: getDeposits function implementation with a suggestion

The getDeposits function is well-implemented and aligns with the PR objectives. The use of pagination is a good practice for handling potentially large datasets. The PageRequest and PageResponse structs provide necessary information for paginated results.

However, I have a minor suggestion:

Consider adding a comment or documentation string to explain the purpose and usage of the PageRequest and PageResponse structs. This would improve the clarity and maintainability of the code, especially for developers who might not be familiar with these structures.


218-258: LGTM: getTallyResult function implementation with a suggestion for improvement

The getTallyResult function is well-structured and aligns with the PR objectives. The TallyResultData struct provides a comprehensive representation of the tally results, including yes, abstain, no, and noWithVeto votes.

However, I have a suggestion for improvement:

Consider using a more appropriate data type for vote counts in the TallyResultData struct. Currently, the vote counts are represented as strings, which might be problematic for large numbers or decimal values. Using a fixed-point decimal type or a custom struct that can handle large integers would be more suitable for vote counts. This change would improve the accuracy and efficiency of vote tallying and comparison operations.

CHANGELOG.md (9)

83-83: Consider breaking long line for better readability

The line describing the inflation reduction is quite long (135 characters). Consider breaking it into multiple lines for better readability.

You could format it like this:

- (inflation) [#2137](https://github.com/evmos/evmos/pull/2137) Reduce inflation by 2/3.
  This change significantly alters the token emission rate.
🧰 Tools
🪛 Markdownlint

83-83: Expected: 120; Actual: 135
Line length

(MD013, line-length)


85-86: Clarify the impact of hardcoding WEVMOS address

The changelog entry for the Stride and Osmosis outposts refactor is a bit vague. It would be helpful to explain the reasoning behind this change and its potential impact on users or developers.

Consider expanding the entry to provide more context:

- (outposts) [#2185](https://github.com/evmos/evmos/pull/2185) Refactor `Stride` and `Osmosis` outposts to hardcode WEVMOS address.
  This change improves consistency and reduces potential errors in address handling for these outposts.

Line range hint 87-88: Provide more details on the Burner role addition

The entry about adding the feecollector Burner role in the upgrade handler could benefit from more explanation about its purpose and impact.

Consider expanding this entry to clarify its significance:

- (upgrade) [#2186](https://github.com/evmos/evmos/pull/2186) Add `feecollector` Burner role in upgrade handler.
  This change enables automatic burning of collected fees, contributing to the deflationary mechanism of the token economy.
🧰 Tools
🪛 Markdownlint

80-80: Expected: 120; Actual: 160
Line length

(MD013, line-length)


82-82: Expected: 120; Actual: 135
Line length

(MD013, line-length)


83-83: Expected: 120; Actual: 135
Line length

(MD013, line-length)


Line range hint 89-89: Highlight the significance of burning incentives pool balance

The entry about burning the usage incentives pool balance during the v16 upgrade is important and could be emphasized more.

Consider rephrasing this entry to highlight its importance:

- (incentives) [#2221](https://github.com/evmos/evmos/pull/2221) Implement burning of the usage incentives pool balance during v16 upgrade.
  This is a significant change that affects the token supply and should be noted by validators and token holders.
🧰 Tools
🪛 Markdownlint

80-80: Expected: 120; Actual: 160
Line length

(MD013, line-length)


82-82: Expected: 120; Actual: 135
Line length

(MD013, line-length)


83-83: Expected: 120; Actual: 135
Line length

(MD013, line-length)


Line range hint 93-94: Clarify the impact of renaming the inflation module

The API Breaking change regarding the renaming of the inflation module could use more context about its impact on developers and users.

Consider expanding this entry:

- (inflation) [#2015](https://github.com/evmos/evmos/pull/2015) Rename `inflation` module to `inflation/v1`.
  This change may require updates to queries and transactions that interact with the inflation module.
  Developers should update their code accordingly.
🧰 Tools
🪛 Markdownlint

80-80: Expected: 120; Actual: 160
Line length

(MD013, line-length)


82-82: Expected: 120; Actual: 135
Line length

(MD013, line-length)


83-83: Expected: 120; Actual: 135
Line length

(MD013, line-length)


Line range hint 95-95: Explain the implications of deprecating legacy EIP-712 ante handler

The entry about deprecating the legacy EIP-712 ante handler could benefit from more explanation about its impact and any migration steps required.

Consider expanding this entry:

- (ante) [#2078](https://github.com/evmos/evmos/pull/2078) Deprecate legacy EIP-712 ante handler.
  Users and developers should migrate to the new EIP-712 implementation.
  This change may affect existing transactions that rely on the legacy handler.
🧰 Tools
🪛 Markdownlint

80-80: Expected: 120; Actual: 160
Line length

(MD013, line-length)


82-82: Expected: 120; Actual: 135
Line length

(MD013, line-length)


83-83: Expected: 120; Actual: 135
Line length

(MD013, line-length)


Line range hint 99-100: Clarify the impact of linting tests

The entry about linting tests could benefit from explaining the benefits of this change.

Consider expanding this entry:

- (tests) [#1194](https://github.com/evmos/evmos/pull/1194) Lint tests to ensure consistency with non-test code.
  This improvement enhances code quality and maintainability across the codebase.
🧰 Tools
🪛 Markdownlint

80-80: Expected: 120; Actual: 160
Line length

(MD013, line-length)


82-82: Expected: 120; Actual: 135
Line length

(MD013, line-length)


83-83: Expected: 120; Actual: 135
Line length

(MD013, line-length)


Line range hint 101-101: Highlight the importance of the vulnerability checker

The addition of a Golang dependency vulnerability checker is significant for security and could be emphasized more.

Consider rephrasing this entry:

- (ci) [#1138](https://github.com/evmos/evmos/pull/1138) Implement Golang dependency vulnerability checker in CI pipeline.
  This enhancement improves the overall security of the project by identifying potential vulnerabilities early in the development process.
🧰 Tools
🪛 Markdownlint

80-80: Expected: 120; Actual: 160
Line length

(MD013, line-length)


82-82: Expected: 120; Actual: 135
Line length

(MD013, line-length)


83-83: Expected: 120; Actual: 135
Line length

(MD013, line-length)


Line range hint 102-103: Explain the benefits of adding the File store listener

The entry about adding the default File store listener could use more context about its purpose and benefits.

Consider expanding this entry:

- (app) [#1114](https://github.com/evmos/evmos/pull/1114) Add default File store listener for application, implementing [ADR38](https://docs.cosmos.network/v0.47/architecture/adr-038-state-listening).
  This improvement enables better state tracking and can be used for various purposes such as indexing or real-time data processing.
🧰 Tools
🪛 Markdownlint

80-80: Expected: 120; Actual: 160
Line length

(MD013, line-length)


82-82: Expected: 120; Actual: 135
Line length

(MD013, line-length)


83-83: Expected: 120; Actual: 135
Line length

(MD013, line-length)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3705194 and 1a4103e.

📒 Files selected for processing (6)
  • CHANGELOG.md (1 hunks)
  • precompiles/gov/IGov.sol (2 hunks)
  • precompiles/gov/abi.json (2 hunks)
  • precompiles/gov/integration_test.go (2 hunks)
  • precompiles/gov/query_test.go (2 hunks)
  • precompiles/gov/setup_test.go (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • precompiles/gov/IGov.sol
🧰 Additional context used
🪛 Markdownlint
CHANGELOG.md

83-83: Expected: 120; Actual: 135
Line length

(MD013, line-length)

🔇 Additional comments (13)
precompiles/gov/setup_test.go (5)

7-13: LGTM: New imports are appropriate for the changes.

The added imports from the Cosmos SDK are necessary for the new functionality in the test setup. They enhance the capabilities of the test suite, allowing for more comprehensive testing of the governance precompile.


49-54: LGTM: Improved type safety and error handling.

The changes enhance type safety by wrapping the test proposal message in an Any type. The error handling for NewAnyWithValue is properly implemented. It's good to see that the previous issue of shadowing the built-in any type has been addressed by using the name anyMessage.


66-66: LGTM: Consistent use of type-safe message handling.

The Messages field of the proposal now correctly uses the anyMessage variable, which is consistent with the earlier type-safe approach for handling proposal messages.


69-73: LGTM: Appropriate bank genesis state configuration.

The new bank genesis state configuration correctly sets up an initial balance for the governance module's address. The use of math.NewInt(100) ensures precise handling of the coin amount. This setup is suitable for testing governance-related functionality.


75-80: LGTM: Governance genesis state properly configured with deposit record.

The governance genesis state is well-configured with a new deposit entry and the MinDeposit parameter. These changes align with the bank balance setup and provide a good foundation for testing governance queries. It's great to see that the suggestion from the previous review about adding a deposit record has been implemented.

precompiles/gov/query_test.go (4)

4-15: LGTM: New imports are appropriate for the added functionality.

The new imports, including math/big, cmn, and various Cosmos SDK types, are necessary for the new test functions and appear to be correctly utilized throughout the file.


23-31: LGTM: New variables are well-defined for testing purposes.

The govAcct variable correctly represents the governance module address, and TestProposalMsgs provides a suitable test message for proposal-related tests. These additions enhance the test suite's capabilities.


236-356: LGTM: TestGetDeposits and TestGetTallyResult functions are well-implemented.

Both functions follow the established pattern and include comprehensive test cases. The malleate functions properly set up the test state, which is an improvement over the TestGetDeposit function. These additions enhance the test coverage for the governance precompile.


Line range hint 1-356: LGTM: Comprehensive test coverage added for governance queries.

The changes in this file significantly enhance the test suite for the governance precompile. The new test functions (TestGetDeposit, TestGetDeposits, and TestGetTallyResult) are well-structured and cover important scenarios. The additions are consistent with the existing code style and testing patterns.

Minor suggestion:

  • Consider enhancing the malleate function in the TestGetDeposit "valid query" test case, as mentioned in a previous comment.

Overall, these changes improve the robustness of the governance precompile tests.

precompiles/gov/abi.json (2)

68-120: LGTM: getDeposit function implementation

The getDeposit function is well-structured and aligns with the PR objectives. It correctly uses uint64 for the proposalId, which is consistent with other functions in the ABI. The DepositData struct provides a comprehensive representation of a deposit, including the proposal ID, depositor address, and an array of Coin structs for the deposit amount.


Line range hint 1-258: Overall assessment: ABI enhancements are well-implemented

The additions to the IGov contract ABI are well-structured and align with the PR objectives. The new functions (getDeposit, getDeposits, and getTallyResult) enhance the governance capabilities as intended. The use of appropriate data structures and pagination demonstrates good design practices.

A few minor suggestions have been made to further improve the implementation:

  1. Consider adding documentation for the PageRequest and PageResponse structs in the getDeposits function.
  2. Evaluate the use of a more suitable data type for vote counts in the TallyResultData struct.

These changes will contribute to better clarity, maintainability, and accuracy of the governance precompile.

precompiles/gov/integration_test.go (1)

367-477: Overall assessment of new integration tests

The addition of integration tests for deposit query, deposits query, and tally result query is a positive improvement to the codebase. These tests help ensure the correct functionality of the governance precompile. However, there are some common themes for improvement across all three new contexts:

  1. Increase test coverage by including more diverse scenarios (e.g., multiple deposits, various voting options).
  2. Enhance setup procedures to ensure consistent and reliable test environments.
  3. Make expected values more dynamic and less hardcoded to improve test flexibility and maintainability.
  4. Utilize pagination testing where applicable to ensure proper handling of large data sets.

Implementing these suggestions will significantly improve the robustness and reliability of the integration tests, providing better coverage of the governance precompile functionality.

CHANGELOG.md (1)

Line range hint 1-265: Overall, the changelog is informative but could benefit from some enhancements

The CHANGELOG.md file for v16.0.0 provides a comprehensive list of changes, categorized into State Machine Breaking, API Breaking, Improvements, and Bug Fixes. This structure is helpful for users and developers to understand the impact of the update.

However, some entries could benefit from additional context or explanation, particularly regarding their impact on users, developers, or the overall system. Adding more details to key changes would make the changelog even more valuable.

Consider reviewing the suggested improvements in the previous comments to enhance the clarity and usefulness of the changelog. This will help users and developers better understand the significance of each change and any actions they may need to take when upgrading to v16.0.0.

🧰 Tools
🪛 Markdownlint

80-80: Expected: 120; Actual: 160
Line length

(MD013, line-length)


82-82: Expected: 120; Actual: 135
Line length

(MD013, line-length)


83-83: Expected: 120; Actual: 135
Line length

(MD013, line-length)

@GAtom22 GAtom22 enabled auto-merge (squash) October 18, 2024 08:47
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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1a4103e and bc1b864.

📒 Files selected for processing (1)
  • .github/workflows/e2e-test.yml (1 hunks)
🧰 Additional context used

@GAtom22 GAtom22 merged commit cb53cf0 into main Oct 20, 2024
49 of 51 checks passed
@GAtom22 GAtom22 deleted the Vvaradinov/gov-queries branch October 20, 2024 09:33
mergify bot pushed a commit that referenced this pull request Oct 20, 2024
…ts queries, unit and integration tests. (#2941)

* feat: add getDeposit, getDeposits and getTallyResults

* feat: add the queries, types, unit and integration tests

* run make format

* format and lint

* tests: address comments from code review

* fix: json linter

* Update precompiles/gov/integration_test.go

Signed-off-by: Tom <[email protected]>

* use const for denom in test

* chore: add changelog entry

* Update precompiles/gov/IGov.sol

Co-authored-by: stepit <[email protected]>
Signed-off-by: Guillermo Paoletti <[email protected]>

* refactor prop msgs

---------

Signed-off-by: Tom <[email protected]>
Signed-off-by: Guillermo Paoletti <[email protected]>
Co-authored-by: Vvaradinov <[email protected]>
Co-authored-by: hanchon <[email protected]>
Co-authored-by: Tom <[email protected]>
Co-authored-by: tom <[email protected]>
Co-authored-by: stepit <[email protected]>
(cherry picked from commit cb53cf0)

# Conflicts:
#	.golangci.yml
#	CHANGELOG.md
GAtom22 added a commit that referenced this pull request Oct 21, 2024
…ts queries, unit and integration tests. (backport #2941) (#2947)

* feat(gov-precompile): Added getDeposit, getDeposits and getTallyResults queries, unit and integration tests. (#2941)

* feat: add getDeposit, getDeposits and getTallyResults

* feat: add the queries, types, unit and integration tests

* run make format

* format and lint

* tests: address comments from code review

* fix: json linter

* Update precompiles/gov/integration_test.go

Signed-off-by: Tom <[email protected]>

* use const for denom in test

* chore: add changelog entry

* Update precompiles/gov/IGov.sol

Co-authored-by: stepit <[email protected]>
Signed-off-by: Guillermo Paoletti <[email protected]>

* refactor prop msgs

---------

Signed-off-by: Tom <[email protected]>
Signed-off-by: Guillermo Paoletti <[email protected]>
Co-authored-by: Vvaradinov <[email protected]>
Co-authored-by: hanchon <[email protected]>
Co-authored-by: Tom <[email protected]>
Co-authored-by: tom <[email protected]>
Co-authored-by: stepit <[email protected]>
(cherry picked from commit cb53cf0)

# Conflicts:
#	.golangci.yml
#	CHANGELOG.md

* fix conflicts

* fix import

---------

Co-authored-by: Vladislav Varadinov <[email protected]>
Co-authored-by: tom <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants