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: e2e add withdraw emissions #3151

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open

Conversation

kingpinXD
Copy link
Contributor

@kingpinXD kingpinXD commented Nov 13, 2024

Description

This pr adds withdrawal of emissions to the e2e .

The withdrawal uses the following mechanism.

  • We create authz grants from each operator/observer to the UserEmissionsWithdraw, this is done to try to simulate the mainnet/testnet govops process as much as possible
  • At the end of e2e, the UserEmissionsWithdraw withdraws all available emissions by signing the withdraw tx.

Closes : #3146

Summary by CodeRabbit

  • New Features

    • Introduced a new account for emissions withdrawal, enhancing account management.
    • Added functionality for funding and withdrawing emissions within the application.
  • Bug Fixes

    • Improved error handling for emissions withdrawal processes.
  • Documentation

    • Updated comments and documentation for new methods and account configurations.
  • Chores

    • Minor formatting adjustments and code clean-up for consistency across the codebase.

Copy link
Contributor

coderabbitai bot commented Nov 13, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces updates across several configuration and script files to enhance account management related to emissions withdrawal. A new account named user_emissions_withdraw is added to the local.yml and localnet.yml configuration files, along with corresponding details. Modifications to the localE2ETest function and the introduction of new methods in the ZetaTxServer and E2ERunner facilitate the management and withdrawal of emissions. Additionally, scripts for initializing the environment and managing authorizations are updated to incorporate this new functionality.

Changes

File Path Change Summary
cmd/zetae2e/config/local.yml Added new account user_emissions_withdraw with bech32_address, evm_address, and private_key under additional_accounts.
cmd/zetae2e/config/localnet.yml Added new account user_emissions_withdraw with bech32_address, evm_address, and private_key under additional_accounts.
cmd/zetae2e/local/local.go Updated localE2ETest to include utils.UserEmissionsWithdrawName and added noError(deployerRunner.WithdrawEmissions()) call at the end of the function.
contrib/localnet/orchestrator/start-zetae2e.sh Added call to fund_eth_from_config for user_emissions_withdraw to unlock emissions withdraw test accounts.
contrib/localnet/scripts/start-zetacored.sh Introduced add_emissions_withdraw_authorizations function and updated add_v17_message_authorizations to include authorization for MsgWithdrawEmissionsss.
e2e/config/config.go Added new field UserEmissionsWithdraw to AdditionalAccounts, updated AsSlice and GenerateKeys methods to include this new account.
e2e/runner/emissions.go Introduced FundEmissionsPool and WithdrawEmissions methods for managing emissions in the E2ERunner struct.
e2e/runner/runner.go Added EmissionsClient field to E2ERunner struct and initialized it in NewE2ERunner.
e2e/runner/setup_zeta.go Removed FundEmissionsPool method from E2ERunner.
e2e/txserver/zeta_tx_server.go Added WithdrawAllEmissions method to ZetaTxServer for handling emissions withdrawal.
e2e/utils/zetacore.go Added new constant UserEmissionsWithdrawName and reformatted existing constants for consistency.
pkg/rpc/clients.go Added Emissions field to Clients struct, initialized in the newClients function.

Possibly related PRs

Suggested labels

breaking:cli, TON_TESTS, nosec, UPGRADE_LIGHT_TESTS

Suggested reviewers

  • skosito
  • lumtis
  • fbac
  • brewmaster012
  • swift1337

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.

@kingpinXD kingpinXD changed the title add withdraw emissions to e2e test: add withdraw emissions to e2e Nov 13, 2024
@kingpinXD kingpinXD changed the title test: add withdraw emissions to e2e test: e2e add withdraw emissions Nov 13, 2024
Copy link

codecov bot commented Nov 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 62.64%. Comparing base (e217ec4) to head (2d16a1d).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #3151   +/-   ##
========================================
  Coverage    62.64%   62.64%           
========================================
  Files          424      424           
  Lines        30115    30116    +1     
========================================
+ Hits         18866    18867    +1     
  Misses       10408    10408           
  Partials       841      841           
Files with missing lines Coverage Δ
pkg/rpc/clients.go 69.44% <100.00%> (+0.87%) ⬆️

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

🧹 Outside diff range and nitpick comments (10)
pkg/rpc/clients.go (1)

55-56: Maintain consistency in field documentation

The comment format should match the established pattern used for other fields.

Apply this change to maintain consistency:

-	// EmissionsClient is a github.com/zeta-chain/zetacore/x/emissions/types QueryClient
+	// Emissions is a github.com/zeta-chain/zetacore/x/emissions/types QueryClient
e2e/utils/zetacore.go (1)

19-22: Consider grouping related constants together.

The constants look good and follow consistent naming conventions. However, consider grouping policy-related constants separately from other constants for better organization.

Consider reorganizing the constants like this:

 const (
+	// Policy names
 	EmergencyPolicyName       = "emergency"
 	AdminPolicyName           = "admin"
 	OperationalPolicyName     = "operational"
 	UserEmissionsWithdrawName = "emissions_withdraw"
+
+	// Timeouts
+	DefaultCctxTimeout = 8 * time.Minute
 )
contrib/localnet/orchestrator/start-zetae2e.sh (2)

Line range hint 1-139: Consider enhancing script security and error handling

The script could benefit from some security and maintainability improvements:

  1. Add error handling for the fund_eth_from_config calls
  2. Set safe shell options at the start

Apply this diff to enhance script security:

 #!/bin/bash

+# Exit on error, undefined vars, and pipe failures
+set -euo pipefail
+# For debugging
+set -x
+
 # shellcheck disable=SC2317

Also, consider wrapping the funding calls with error handling:

-fund_eth_from_config '.additional_accounts.user_emissions_withdraw.evm_address' 10000 "emissions withdraw tester"
+if ! fund_eth_from_config '.additional_accounts.user_emissions_withdraw.evm_address' 10000 "emissions withdraw tester"; then
+    echo "Failed to fund emissions withdraw tester account"
+    exit 1
+fi

Line range hint 28-55: Enhance the fund_eth function with input validation

The fund_eth function should validate its inputs to prevent potential issues with malformed addresses or negative amounts.

Consider this enhanced implementation:

 fund_eth() {
     local address=$1
     local ether=$2
     local comment=${3:-}
 
+    # Validate ethereum address format
+    if [[ ! "$address" =~ ^0x[a-fA-F0-9]{40}$ ]]; then
+        echo "Error: Invalid Ethereum address format: $address"
+        return 1
+    fi
+
+    # Validate ether amount is positive
+    if ! [[ "$ether" =~ ^[0-9]+$ ]] || [ "$ether" -le 0 ]; then
+        echo "Error: Invalid ether amount: $ether"
+        return 1
+    fi
+
     if [ -z "$comment" ]; then
         echo "funding eth address $address with $ether eth"
     else
         echo "funding eth address $address ($comment) with $ether eth"
     fi
e2e/runner/runner.go (1)

Missing e2e test implementation for emissions withdrawal functionality

The codebase has the necessary infrastructure for emissions withdrawal (helper functions, client setup, etc.) but lacks actual e2e test implementation. This is evidenced by:

  • Presence of emissions-related helper functions in e2e/runner/emissions.go
  • Recent commit "1c77e10 add withdraw emissions to e2e"
  • No matching test file in e2e/e2etests/ directory for emissions withdrawal functionality

Required actions:

  • Add a new test file e2e/e2etests/test_emissions_withdrawal.go implementing comprehensive test scenarios
  • Include test cases for both successful and failed withdrawal scenarios
  • Verify withdrawal amounts and balance changes
  • Test authorization and permission scenarios
🔗 Analysis chain

Line range hint 102-214: Verify test coverage for emissions functionality

While the EmissionsClient is properly integrated, ensure that comprehensive e2e tests are implemented to verify the emissions withdrawal functionality mentioned in the PR objectives.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for emissions-related test implementations

# Search for emissions-related test files and functions
echo "Searching for emissions test implementations..."
rg -t go -l "emissions.*test" e2e/
rg -t go "func.*(Test|test).*[Ee]missions" e2e/

# Check for emissions-related test helper functions
echo "Searching for emissions test helper functions..."
ast-grep --pattern 'func $_(runner *E2ERunner) $_($$$) {
  $$$
  $_.EmissionsClient.$$$
  $$$
}'

Length of output: 397


Script:

#!/bin/bash
# Let's search more broadly for any emissions-related code and tests
echo "Searching for emissions-related code..."
rg -g '*.go' -B 2 -A 2 'emissions' e2e/

# Look for any test files that might contain emissions testing
echo "Searching for test files in e2e..."
fd -e go -e test test e2e/

# Check for any pending or recently added emissions test files
echo "Checking git status for emissions-related files..."
git status | grep -i emissions

# Look for emissions-related changes in recent commits
echo "Checking recent commits for emissions-related changes..."
git log --grep="emissions" --since="1 month ago" --oneline

Length of output: 15599

contrib/localnet/scripts/start-zetacored.sh (1)

317-319: Validate genesis account balance

Consider adding validation for the balance amount to prevent potential issues with extremely large or small values. Also, consider extracting the balance amount to a configuration variable for better maintainability.

+# Define standard genesis account balance
+GENESIS_ACCOUNT_BALANCE="100000000000000000000000000azeta"
+
+# Validate balance format
+validate_balance() {
+    local balance=$1
+    if [[ ! "$balance" =~ ^[0-9]+azeta$ ]]; then
+        echo "Error: Invalid balance format: $balance"
+        return 1
+    fi
+}
+
 # emissions withdraw tester
 address=$(yq -r '.additional_accounts.user_emissions_withdraw.bech32_address' /root/config.yml)
-zetacored add-genesis-account "$address" 100000000000000000000000000azeta
+validate_balance "$GENESIS_ACCOUNT_BALANCE" && \
+zetacored add-genesis-account "$address" "$GENESIS_ACCOUNT_BALANCE"
e2e/runner/emissions.go (4)

35-35: Use Structured Logging for Clarity

The logging statement uses r.Logger.Print, which may not provide structured logging capabilities. To enhance log clarity and facilitate log parsing, consider using structured logging methods.

Refactor the logging statement to include structured fields:

-r.Logger.Print("🏃 withdrawing emissions from the emissions pool on ZetaChain for observer %s", observer)
+r.Logger.With(
+    "observer", observer,
+).Info("Withdrawing emissions from the emissions pool on ZetaChain.")

This provides better log management and easier debugging.


69-72: Handle Zero Emissions Without Logging

Logging a message for observers with zero emissions may clutter the logs if many observers have no emissions. Consider omitting the log statement for zero emissions to keep logs concise.

You may simply continue without logging:

-if amountInt.IsZero() {
-    r.Logger.Print("no emissions to withdraw for observer %s", observer)
+if amountInt.IsZero() {
     continue
 }

74-77: Propagate Error Context in WithdrawAllEmissions

When WithdrawAllEmissions returns an error, additional context can help diagnose issues. Wrap the error with contextual information.

Modify the error handling as follows:

-if err = r.ZetaTxServer.WithdrawAllEmissions(amountInt, e2eutils.UserEmissionsWithdrawName, observer); err != nil {
-    return err
+if err := r.ZetaTxServer.WithdrawAllEmissions(amountInt, e2eutils.UserEmissionsWithdrawName, observer); err != nil {
+    return fmt.Errorf("failed to withdraw emissions for observer %s: %w", observer, err)
 }

This provides clarity on which observer's emission withdrawal failed.


79-82: Consistent Error Wrapping with %w Verb

In the error message, use the %w verb for wrapping errors to maintain consistency with error handling best practices.

Update the error formatting:

-if err != nil {
-    return errors.Wrapf(err, "failed to get balance for observer after withdrawing emissions %s", observer)
+if err != nil {
+    return fmt.Errorf("failed to get balance for observer %s after withdrawing emissions: %w", observer, err)
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e217ec4 and 1c77e10.

📒 Files selected for processing (12)
  • cmd/zetae2e/config/local.yml (1 hunks)
  • cmd/zetae2e/config/localnet.yml (1 hunks)
  • cmd/zetae2e/local/local.go (2 hunks)
  • contrib/localnet/orchestrator/start-zetae2e.sh (1 hunks)
  • contrib/localnet/scripts/start-zetacored.sh (4 hunks)
  • e2e/config/config.go (3 hunks)
  • e2e/runner/emissions.go (1 hunks)
  • e2e/runner/runner.go (3 hunks)
  • e2e/runner/setup_zeta.go (0 hunks)
  • e2e/txserver/zeta_tx_server.go (2 hunks)
  • e2e/utils/zetacore.go (1 hunks)
  • pkg/rpc/clients.go (3 hunks)
💤 Files with no reviewable changes (1)
  • e2e/runner/setup_zeta.go
🧰 Additional context used
📓 Path-based instructions (9)
cmd/zetae2e/local/local.go (1)

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

contrib/localnet/orchestrator/start-zetae2e.sh (1)

Pattern **/*.sh: Review the shell scripts, point out issues relative to security, performance, and maintainability.

contrib/localnet/scripts/start-zetacored.sh (1)

Pattern **/*.sh: Review the shell scripts, point out issues relative to security, performance, and maintainability.

e2e/config/config.go (1)

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

e2e/runner/emissions.go (1)

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

e2e/runner/runner.go (1)

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

e2e/txserver/zeta_tx_server.go (1)

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

e2e/utils/zetacore.go (1)

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

pkg/rpc/clients.go (1)

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

🪛 Gitleaks
cmd/zetae2e/config/local.yml

71-71: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

cmd/zetae2e/config/localnet.yml

71-71: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

🔇 Additional comments (16)
pkg/rpc/clients.go (3)

20-20: LGTM: Import follows Go conventions

The new import is correctly placed and follows the established pattern for internal package imports.


85-85: LGTM: Client initialization is consistent

The emissions client is properly initialized and correctly grouped under ZetaCore specific clients.


55-56: Verify emissions client capabilities

Let's ensure the emissions client provides all necessary query methods for the withdrawal functionality mentioned in the PR objectives.

Also applies to: 85-85

✅ Verification successful

Let me gather more specific information about the emissions query methods.


Let me search for the emissions proto definitions more specifically.


Emissions client provides all necessary query methods

Based on the proto definitions, the emissions client provides all required query methods for withdrawal functionality:

  • Params: For querying module parameters
  • ListPoolAddresses: For retrieving emission pool addresses
  • ShowAvailableEmissions: For checking withdrawable emission amounts

The client implementation aligns with the withdrawal functionality mentioned in the PR objectives.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the emissions client has all required query methods

# Search for query method definitions in the emissions types
ast-grep --pattern 'rpc $_ ($_) returns ($_) {
  option (google.api.http).$$$
}'  | grep -A 5 'x/emissions/types'

# Search for any existing usage patterns
rg -A 3 'Emissions\.' 

Length of output: 2633


Script:

#!/bin/bash
# Search for query service definition in proto files
fd '\.proto$' | xargs grep -l "service Query" | xargs cat

# Search for query client usage in the codebase
rg "Emissions\." -A 5 -g '!*.pb.go' -g '!*.pb.gw.go'

Length of output: 35153


Script:

#!/bin/bash
# Search for emissions proto file
fd '\.proto$' | xargs grep -l "package.*emissions" | xargs cat

# Search for emissions client usage in go files
rg "Emissions\." -g '*.go' -A 3

Length of output: 8658

cmd/zetae2e/config/localnet.yml (2)

68-71: LGTM - Configuration follows established patterns

The new account configuration is well-structured and consistent with other test accounts in the file. The credentials are appropriately scoped for the e2e testing environment.

🧰 Tools
🪛 Gitleaks

71-71: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


68-71: Verify account configuration consistency

The new user_emissions_withdraw account configuration follows the established pattern. Let's verify its integration with other components:

✅ Verification successful

Account configuration verified and properly integrated

The user_emissions_withdraw account configuration is correctly implemented and consistent across the codebase:

  • Present in both localnet.yml and local.yml with identical configuration
  • Properly defined in the configuration struct (e2e/config/config.go)
  • Follows the established pattern of other test accounts
  • Valid bech32 address format confirmed
  • Consistent with the e2e testing infrastructure
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the consistency of the new account configuration across related files

# Check if the account is properly referenced in the e2e test setup
rg -l "user_emissions_withdraw" --type yaml
rg -l "0x9945724EBc9B3B9cc724abedE379349EE5E1657a" --type go

# Verify the bech32 address format
echo "zeta1n9zhyn4unvaee3ey40k7x7f5nmj7zet6qr5kl7" | gawk '/^zeta1[a-zA-Z0-9]{38}$/ {print "Valid bech32 address"}'

Length of output: 302


Script:

#!/bin/bash
# Let's examine the content of local.yml to ensure configuration consistency
cat cmd/zetae2e/config/local.yml

# Check for any e2e tests that might be using this account
rg "user_emissions_withdraw" --type go -A 3

Length of output: 6859

🧰 Tools
🪛 Gitleaks

71-71: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

cmd/zetae2e/config/local.yml (1)

68-71: LGTM! Verify address formats for consistency.

The new user_emissions_withdraw account follows the established pattern and aligns with the PR's objective for e2e testing of emissions withdrawal functionality.

✅ Verification successful

Address formats verified successfully

All address formats in the new user_emissions_withdraw account configuration follow the expected patterns:

  • Bech32 address matches zeta1 prefix with correct length
  • EVM address is a valid 40-character hex string with 0x prefix
  • Private key is a valid 64-character hex string
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify address format consistency

# Verify bech32 address format
echo "zeta1n9zhyn4unvaee3ey40k7x7f5nmj7zet6qr5kl7" | grep -E "^zeta1[a-zA-Z0-9]{38}$"

# Verify EVM address format (should be 40 hex chars)
echo "0x9945724EBc9B3B9cc724abedE379349EE5E1657a" | grep -E "^0x[a-fA-F0-9]{40}$"

# Verify private key format (should be 64 hex chars)
echo "9d524fe318c0eb5f80d8b246993a9f15f924db24d4b8b873839b13bc30040d03" | grep -E "^[a-fA-F0-9]{64}$"

Length of output: 421

🧰 Tools
🪛 Gitleaks

71-71: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

contrib/localnet/orchestrator/start-zetae2e.sh (1)

137-139: LGTM: Emissions withdraw account funding follows established patterns

The addition follows the consistent pattern used throughout the script for funding test accounts, maintaining the same funding amount and config key structure.

e2e/config/config.go (3)

64-79: LGTM! Clean addition of UserEmissionsWithdraw account.

The new account field is well-structured and follows the established pattern, with proper YAML tagging for configuration management.


252-252: LGTM! Proper integration in AsSlice method.

The new account is correctly added to the slice, maintaining consistency with the existing implementation pattern.


369-372: LGTM! Consistent implementation in GenerateKeys.

The account generation and error handling follow the established pattern, ensuring reliable key generation for the emissions withdrawal functionality.

e2e/runner/runner.go (3)

47-47: LGTM: Import statement follows conventions

The emissions types import is properly grouped with other internal package imports and follows consistent aliasing patterns.


102-102: LGTM: Field addition follows struct organization

The EmissionsClient field is properly typed and consistently placed with other client fields in the E2ERunner struct.


214-214: LGTM: Client initialization follows constructor pattern

The EmissionsClient is properly initialized from the clients parameter, maintaining consistency with other client initializations in the constructor.

cmd/zetae2e/local/local.go (2)

163-168: LGTM: Policy configuration looks good!

The addition of UserEmissionsWithdrawName and its corresponding private key follows the established pattern and maintains consistency with the existing policy configuration.

Also applies to: 173-173


501-502: Verify emissions withdrawal timing and dependencies.

The placement of emissions withdrawal needs verification to ensure it doesn't affect:

  1. Subsequent TSS migration tests (if enabled)
  2. Network report validation
  3. Zero balance checks on restricted addresses
✅ Verification successful

Let me gather more context about the withdrawal implementation and its dependencies.


Emissions withdrawal placement is correctly positioned

The current placement of emissions withdrawal is optimal as it:

  • Executes after all core tests are completed, ensuring no interference with test scenarios
  • Runs before the optional TSS migration test, which has no emissions balance dependencies
  • Precedes the final balance validations, allowing proper verification of:
    • Zero balance checks on restricted addresses
    • Network report validation that explicitly verifies emissions pool balance reduction
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any dependencies on emissions balance in tests and subsequent operations

# Check for emissions balance usage in test files
rg -A 5 "emissions" "e2e/e2etests/"

# Check for emissions balance usage in TSS migration
rg -A 5 "emissions" -g "**/*tss*.go"

# Check for emissions balance in network report validation
rg -A 5 "emissions" -g "**/report*.go"

Length of output: 2065


Script:

#!/bin/bash
# Check the implementation of WithdrawEmissions
ast-grep --pattern 'func $_ WithdrawEmissions() $_ {
  $$$
}'

# Check for any balance checks or validations after emissions withdrawal
rg -B 5 -A 10 "WithdrawEmissions" cmd/zetae2e/local/local.go

# Check for any TSS migration dependencies
rg -B 5 -A 10 "TSSMigration" cmd/zetae2e/local/local.go

Length of output: 3556

e2e/txserver/zeta_tx_server.go (1)

13-13: LGTM: Import addition is well-structured

The new import for sdkmath is correctly aliased and appropriately placed within the import block.

contrib/localnet/scripts/start-zetacored.sh Outdated Show resolved Hide resolved
contrib/localnet/scripts/start-zetacored.sh Outdated Show resolved Hide resolved
contrib/localnet/scripts/start-zetacored.sh Outdated Show resolved Hide resolved
cmd/zetae2e/local/local.go Outdated Show resolved Hide resolved
e2e/txserver/zeta_tx_server.go Outdated Show resolved Hide resolved
e2e/runner/emissions.go Show resolved Hide resolved
e2e/runner/emissions.go Outdated Show resolved Hide resolved
e2e/runner/emissions.go Outdated Show resolved Hide resolved
changeInBalance,
)
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is difficult to check the emissions pool balance or available emissions here, as there can be some emissions in the blocks in between the tx's.

Copy link
Member

Choose a reason for hiding this comment

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

Why not withdraw all emissions by default? No need to specify a certain amount.

That's how the commission withdrawal works for validators and I can't imagine a situation in which someone needs to withdraw some but not all emission rewards.

Copy link
Contributor Author

@kingpinXD kingpinXD Nov 14, 2024

Choose a reason for hiding this comment

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

We are withdrawing all the available emissions.
But there might be emissions added after we withdraw, so available emissions would not be zero, similar reason for emissions pool balance as well

Copy link
Member

Choose a reason for hiding this comment

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

We can update the emissions params to set percentage to 0 before withdrawing.
So no emission happens after

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I considered that, but we would have to unset it after the check so that tss migration and upgrade tests are successful,
It seemed to me a bit unnecessary to do that just for this check, considering we also have unit tests .
Happy to add it though , if needed . Its trivial effort

@@ -65,6 +65,10 @@ additional_accounts:
bech32_address: "zeta1nry9yeg6njhjrp2ctppa8558vqxal9fxk69zxg"
evm_address: "0x98c852651A9CAF2185585843d3D287600Ddf9526"
private_key: "bf9456c679bb5a952a9a137fcfc920e0413efdb97c36de1e57455763084230cb"
user_emissions_withdraw:
Copy link
Member

Choose a reason for hiding this comment

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

Isn't one of the observer? I would rather call it user_observer (or observer_hot_key to be more precise), might be used for other purpose in the future

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's not an observer; it's a new account used just for withdrawal.
This tries to simulate the mainnet system in which all our validators grant authorization to an address, which then withdraws on their behalf

@@ -67,6 +67,55 @@ add_v17_message_authorizations() {
' $json_file > temp.json && mv temp.json $json_file
}


add_emissions_withdraw_authorizations() {
Copy link
Member

Choose a reason for hiding this comment

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

Small note here: any alternative that could work in Go?

Ideally we want to reduce the shell codebase and have everything in Go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, we can just use the same logic in Go a function ,
or a command similar to add-observer-list

But I guess it's okay for now since we are adding just one authorization for now. If we need to modify more items in the genesis file, we can consider baking that into Zetacored in the future

Comment on lines +68 to +69
err = r.ZetaTxServer.WithdrawAllEmissions(availableCoin.Amount, e2eutils.UserEmissionsWithdrawName, observer)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
err = r.ZetaTxServer.WithdrawAllEmissions(availableCoin.Amount, e2eutils.UserEmissionsWithdrawName, observer)
if err != nil {
if err := r.ZetaTxServer.WithdrawAllEmissions(availableCoin.Amount, e2eutils.UserEmissionsWithdrawName, observer); err != nil {

changeInBalance,
)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

We can update the emissions params to set percentage to 0 before withdrawing.
So no emission happens after

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.

zetacore : emissions : Add e2e test for emissions withdraw
3 participants