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

chore(precompiles): disable stake, unstake and moveStake #3010

Merged
merged 7 commits into from
Oct 17, 2024

Conversation

fbac
Copy link
Contributor

@fbac fbac commented Oct 16, 2024

Description

Closes #3005.
Opened #3009.

How Has This Been Tested?

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Summary by CodeRabbit

  • Bug Fixes

    • Commented out specific staking functionalities and associated test cases to prevent execution errors.
  • Tests

    • Removed outdated test functions related to staking while maintaining the integrity of remaining tests.

Copy link
Contributor

coderabbitai bot commented Oct 16, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request primarily involve commenting out functionalities and test cases related to staking within the codebase. Specifically, the Run method in the staking contract has had certain staking-related method handlers disabled, and several corresponding test functions have been commented out in the testing files. This effectively alters the execution of tests and the operational capabilities of the staking functionalities during the initial launch of the precompile.

Changes

File Path Change Summary
cmd/zetae2e/local/local.go Commented out test entries e2etests.TestPrecompilesStakingName and e2etests.TestPrecompilesStakingThroughContractName.
precompiles/staking/staking.go Commented out handling for StakeMethodName, UnstakeMethodName, and MoveStakeMethodName in the Run method.
precompiles/staking/staking_test.go Commented out test functions: Test_Stake, Test_Unstake, and Test_MoveStake. Remaining tests unchanged.

Assessment against linked issues

Objective Addressed Explanation
Disable stake, unstake and moveStake (3005)

Possibly related PRs

Suggested labels

breaking:cli, UPGRADE_TESTS

Suggested reviewers

  • swift1337
  • ws4charlie
  • brewmaster012
  • kingpinXD
  • lumtis
  • gartnera

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ae6ab23 and 4831330.

📒 Files selected for processing (3)
  • cmd/zetae2e/local/local.go (1 hunks)
  • precompiles/staking/staking.go (1 hunks)
  • precompiles/staking/staking_test.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
cmd/zetae2e/local/local.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

precompiles/staking/staking.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

precompiles/staking/staking_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

🔇 Additional comments (2)
precompiles/staking/staking_test.go (2)

Line range hint 1089-1124: LGTM: Test_GetAllValidators function is well-implemented.

The test cases for Test_GetAllValidators are comprehensive, covering both empty and populated validator scenarios. The implementation is correct and follows good testing practices.


Line range hint 1-1288: Overall, the changes align with PR objectives and maintain good test coverage.

The modifications to precompiles/staking/staking_test.go successfully disable the tests for stake, unstake, and moveStake methods as intended. The remaining active tests provide good coverage for the still-active functionalities. With the suggested improvements implemented, this file will be in excellent shape for the initial launch of the precompile.


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.

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.

@fbac fbac added no-changelog Skip changelog CI check stateful-precompile A new stateful precompile contract that is user facing labels Oct 16, 2024
Copy link

codecov bot commented Oct 16, 2024

Codecov Report

Attention: Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 65.64%. Comparing base (920779b) to head (9b67913).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
precompiles/types/errors.go 0.00% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3010      +/-   ##
===========================================
- Coverage    66.29%   65.64%   -0.66%     
===========================================
  Files          406      406              
  Lines        22772    22780       +8     
===========================================
- Hits         15097    14953     -144     
- Misses        6901     7052     +151     
- Partials       774      775       +1     
Files with missing lines Coverage Δ
precompiles/staking/staking.go 46.18% <100.00%> (-47.96%) ⬇️
precompiles/types/errors.go 92.85% <0.00%> (-7.15%) ⬇️

... and 1 file with indirect coverage changes

@fbac fbac changed the title GH3005: disable stake, unstake and moveStake chore(precompiles): disable stake, unstake and moveStake Oct 16, 2024
@fbac fbac force-pushed the GH3005/disable-stake-unstake-movestake branch from 4831330 to 01934cc Compare October 16, 2024 09:16
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.

Caution

Inline review comments failed to post

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (4)
precompiles/staking/staking.go (1)

417-464: Approve changes with a minor suggestion for improved clarity.

The modifications effectively disable the stake, unstake, and moveStake methods as intended, aligning with the PR objectives. The implementation is correct and does not introduce any syntax errors or logical issues.

To enhance code clarity and maintainability, consider the following suggestion:

-	// case StakeMethodName:
-	// 	if readOnly {
-	// 		return nil, ptypes.ErrWriteMethod{
-	// 			Method: method.Name,
-	// 		}
-	// 	}
-
-	// 	var res []byte
-	// 	execErr := stateDB.ExecuteNativeAction(contract.Address(), nil, func(ctx sdk.Context) error {
-	// 		res, err = c.Stake(ctx, evm, contract, method, args)
-	// 		return err
-	// 	})
-	// 	if execErr != nil {
-	// 		return nil, err
-	// 	}
-	// 	return res, nil
-	// case UnstakeMethodName:
-	// 	if readOnly {
-	// 		return nil, ptypes.ErrWriteMethod{
-	// 			Method: method.Name,
-	// 		}
-	// 	}
-
-	// 	var res []byte
-	// 	execErr := stateDB.ExecuteNativeAction(contract.Address(), nil, func(ctx sdk.Context) error {
-	// 		res, err = c.Unstake(ctx, evm, contract, method, args)
-	// 		return err
-	// 	})
-	// 	if execErr != nil {
-	// 		return nil, err
-	// 	}
-	// 	return res, nil
-	// case MoveStakeMethodName:
-	// 	if readOnly {
-	// 		return nil, ptypes.ErrWriteMethod{
-	// 			Method: method.Name,
-	// 		}
-	// 	}
-
-	// 	var res []byte
-	// 	execErr := stateDB.ExecuteNativeAction(contract.Address(), nil, func(ctx sdk.Context) error {
-	// 		res, err = c.MoveStake(ctx, evm, contract, method, args)
-	// 		return err
-	// 	})
-	// 	if execErr != nil {
-	// 		return nil, err
-	// 	}
-	// 	return res, nil
+	// Staking methods temporarily disabled
+	// case StakeMethodName, UnstakeMethodName, MoveStakeMethodName:
+	// 	return nil, ptypes.ErrInvalidMethod{
+	// 		Method: method.Name,
+	// 	}

This refactoring consolidates the disabled methods into a single case statement and returns an ErrInvalidMethod error, clearly indicating that these methods are intentionally disabled. This approach improves code readability and makes it easier to re-enable these methods in the future when needed.

precompiles/staking/staking_test.go (3)

240-1088: Consider adding a TODO comment for future re-enablement of tests.

The test functions for Test_Stake, Test_Unstake, and Test_MoveStake have been commented out, which aligns with the PR objectives. However, to ensure these tests are not forgotten and can be easily re-enabled in the future, consider adding a TODO comment at the beginning of this block.

Add the following comment before line 240:

// TODO: Re-enable these tests when stake, unstake, and moveStake functionality is implemented

Line range hint 1126-1258: Consider enhancing error message assertions in Test_GetShares.

While the test cases in Test_GetShares are comprehensive, the error assertions in the failure scenarios (lines 1186-1258) could be more specific. Instead of just checking for the presence of an error, consider asserting the specific error messages to ensure the correct error is being thrown.

Replace generic error checks with specific error message assertions. For example:

- require.Error(t, err)
+ require.ErrorContains(t, err, "expected error message")

This change will make the tests more robust and easier to debug if they fail in the future.


Line range hint 1260-1288: Consider refactoring the invalid method test for clarity.

The Test_RunInvalidMethod function correctly tests the behavior of calling an invalid method, but it does so by using a method from a different contract (prototype). This approach might be confusing and could potentially break if the prototype contract changes.

Consider refactoring the test to use a non-existent method name instead of borrowing from another contract. This would make the test more clear and less dependent on other contracts. For example:

methodID := abi.Method{Name: "nonExistentMethod", ID: []byte{0x12, 0x34, 0x56, 0x78}}
args := []interface{}{}
mockVMContract.Input = append(methodID.ID, packInputArgs(t, methodID, args...)...)

This change will make the test more robust and easier to understand.

🛑 Comments failed to post (1)
cmd/zetae2e/local/local.go (1)

332-333: 💡 Codebase verification

Additional References to Disabled Staking Tests Detected

The verification revealed active references to TestPrecompilesStaking and TestPrecompilesStakingThroughContract in the following files:

  • e2e/e2etests/test_precompiles_staking_through_contract.go
  • e2e/e2etests/test_precompiles_staking.go
  • e2e/e2etests/e2etests.go

To fully align with the PR objective to disable staking methods:

  1. Comment Out or Remove References:

    • Ensure that all instances of TestPrecompilesStaking and TestPrecompilesStakingThroughContract are commented out or removed to prevent their execution.
  2. Verify Invocation Points:

    • Check if these tests are invoked elsewhere in the testing framework and disable those invocation points accordingly.
  3. Ensure Comprehensive Test Coverage:

    • After disabling, confirm that there are no unintended side effects and that the overall test coverage remains robust.
🔗 Analysis chain

Approval with considerations for test coverage.

The removal of staking-related precompile tests aligns with the PR objective to disable stake, unstake, and moveStake methods for the initial launch. However, to maintain comprehensive test coverage:

  1. Consider adding placeholder tests that verify these methods are indeed disabled.
  2. Implement a mechanism to easily re-enable these tests for future releases.
  3. Ensure any dependent test cases or setup procedures are adjusted accordingly.

To confirm no unintended side effects, please run the following verification:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any remaining references to the disabled staking tests
rg -i "TestPrecompilesStaking(ThroughContract)?" --type go

Length of output: 928

Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

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

I think we can create an issue for enabling the function back and mention it in the commented code

cmd/zetae2e/local/local.go Outdated Show resolved Hide resolved
e2e/e2etests/e2etests.go Show resolved Hide resolved
@fbac fbac enabled auto-merge October 17, 2024 13:26
@fbac fbac added this pull request to the merge queue Oct 17, 2024
Merged via the queue into develop with commit 05c0769 Oct 17, 2024
35 checks passed
@fbac fbac deleted the GH3005/disable-stake-unstake-movestake branch October 17, 2024 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking:cli no-changelog Skip changelog CI check stateful-precompile A new stateful precompile contract that is user facing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disable stake, unstake and moveStake
4 participants