-
Notifications
You must be signed in to change notification settings - Fork 36
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: improve suite #242
test: improve suite #242
Conversation
WalkthroughThe changes refactor the way application instances are initialized for testing by replacing legacy calls (e.g., using Changes
Sequence Diagram(s)sequenceDiagram
participant TestRunner
participant IntegrationSuite
participant CleanChainFactory as NewCleanChain()
participant AppInstance
TestRunner->>IntegrationSuite: Call SetupApp(startTime)
IntegrationSuite->>CleanChainFactory: Invoke NewCleanChain()
CleanChainFactory->>AppInstance: Initialize and return App instance
IntegrationSuite->>TestRunner: Return AppInstance
sequenceDiagram
participant Validator
participant MsgServer
participant StakerKeeper
Validator->>MsgServer: Send JoinPool request
MsgServer->>StakerKeeper: Request validator details
StakerKeeper->>MsgServer: Return address (via MustAccountAddressFromValAddress)
MsgServer->>Validator: Return error (ErrValidatorNotInActiveSet) if not active
Possibly related PRs
Suggested reviewers
Poem
Tip 🌐 Web search-backed reviews and chat
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
🧹 Nitpick comments (7)
testutil/integration/integration.go (1)
114-163
: Potentially unhandled mint errors.Calls to
MintBaseCoins
ininitDummyAccounts
ignore errors using_ = ...
. This is typical in tests, but it may hide unexpected failures.- _ = suite.MintBaseCoins(ALICE, 1000*KYVE) + if err := suite.MintBaseCoins(ALICE, 1000*KYVE); err != nil { + panic(err) + }x/stakers/keeper/keeper_suite_protocol_bridge_test.go (2)
57-91
: Consider adding more assertions for validator state.While the test verifies pool membership and bonded validators, consider adding assertions for:
- Validator's jailed status
- Validator's voting power after slash
- Detailed slash event verification
184-218
: Consider testing edge cases for unbonded validator.The test could be enhanced by adding cases for:
- Validator with zero delegation
- Validator in unbonding period
- Multiple attempts to join pool
x/bundles/keeper/keeper_suite_inflation_splitting_test.go (4)
17-45
: Well-structured test coverage with comprehensive scenarios!The test suite provides excellent coverage of inflation splitting scenarios. The test cases are logically organized and cover important edge cases.
Consider adding a table in the comments summarizing the test matrix (inflation rates × funder scenarios) to make it easier for other developers to understand the test coverage at a glance.
323-324
: Document reward calculation formulas more clearly.The reward calculations involve complex formulas with multiple factors. While the inline comments show the calculations, they could be more readable.
Consider adding a dedicated section in the comments explaining the reward calculation formulas with:
- Base formula
- Variables and their meanings
- Rounding rules
- Example calculations
Also applies to: 328-329
1847-1853
: Improve assertion documentation for complex calculations.The test includes detailed assertions for inflation calculations, but some expected values could use better documentation.
Consider:
- Adding intermediate calculation steps in comments
- Explaining why specific values are expected
- Documenting any known rounding behaviors
436-448
: Reduce code duplication in test setup.There's significant duplication in the funder setup code across multiple test cases.
Consider extracting common setup patterns into helper functions:
func (s *KeeperTestSuite) setupFunders(poolId uint64, amounts sdk.Coins, amountsPerBundle sdk.Coins) { s.RunTxFundersSuccess(&funderstypes.MsgFundPool{ Creator: i.ALICE, PoolId: poolId, Amounts: amounts, AmountsPerBundle: amountsPerBundle, }) s.RunTxFundersSuccess(&funderstypes.MsgFundPool{ Creator: i.BOB, PoolId: poolId, Amounts: amounts, AmountsPerBundle: amountsPerBundle, }) }Also applies to: 540-552, 638-650, 735-747, 838-850, 936-948, 1034-1046, 1137-1149, 1235-1247, 1333-1345, 1436-1448, 1546-1558
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (22)
interchaintest/global/abci_utils_test.go
(1 hunks)interchaintest/ibc/ibc_utils_test.go
(2 hunks)testutil/integration/integration.go
(10 hunks)testutil/integration/setup.go
(4 hunks)testutil/integration/transactions.go
(0 hunks)testutil/nullify/nullify.go
(0 hunks)testutil/sample/sample.go
(0 hunks)x/bundles/keeper/keeper_suite_inflation_splitting_test.go
(15 hunks)x/bundles/keeper/keeper_suite_valid_bundles_test.go
(5 hunks)x/bundles/keeper/keeper_suite_zero_delegation_test.go
(14 hunks)x/bundles/keeper/logic_round_robin_test.go
(1 hunks)x/funders/types/params.go
(1 hunks)x/global/ante_test.go
(1 hunks)x/pool/keeper/msg_server_disable_pool_test.go
(1 hunks)x/pool/keeper/msg_server_update_pool_test.go
(3 hunks)x/stakers/keeper/keeper.go
(1 hunks)x/stakers/keeper/keeper_suite_effective_stake_test.go
(2 hunks)x/stakers/keeper/keeper_suite_protocol_bridge_test.go
(1 hunks)x/stakers/keeper/msg_server_join_pool.go
(1 hunks)x/stakers/types/errors.go
(1 hunks)x/team/keeper/msg_server_clawback_test.go
(10 hunks)x/team/types/types.go
(1 hunks)
💤 Files with no reviewable changes (3)
- testutil/integration/transactions.go
- testutil/sample/sample.go
- testutil/nullify/nullify.go
✅ Files skipped from review due to trivial changes (2)
- x/global/ante_test.go
- x/team/types/types.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Summary
🔇 Additional comments (35)
testutil/integration/setup.go (6)
1-1
: Confirm package rename references.The package name has changed to
integration
. Ensure that all references to the old package name (app
) have been updated accordingly across the codebase to avoid import-related issues.
7-31
: Imports look consistent.No obvious issues with these newly introduced or modified imports. The dependencies appear necessary and properly referenced.
34-43
: Struct extension acknowledged.The
KeeperTestSuite
struct introduces multiple fields (ctx
,app
,denom
,privateValidatorKey
, etc.). This design is straightforward and promotes clarity in integration tests.
63-127
: Initialize chain config carefully.The
SetupApp
method properly sets up the app with a local in-memory database, configures Bech32 prefixes, and initializes the chain. Consider verifying that:
- The chain ID (“kyve-test”) doesn’t conflict with other concurrent tests.
- Sealing the config doesn’t affect parallel test runs (if any).
Otherwise, the approach is solid.
129-222
: Genesis state customization acknowledged.
DefaultGenesisWithValSet
merges default genesis with a validator set and delegator. The method is comprehensive and aligns with typical test environment setups.
224-226
: No-op app options confirmed.
EmptyAppOptions
is a valid stub for testing environments.testutil/integration/integration.go (12)
5-8
: Verify additions of strconv and Tendermint types imports.These imports look fine. Confirm they’re strictly necessary if minimal dependencies are desired.
60-60
: Validate the updated KYVE constant.
KYVE
is changed to1_000_000
from the previous larger value. Ensure this change doesn’t break existing tests or logic relying on the older magnitude.
104-105
: Refactored chain creation function.Using
NewCleanChainAtTime
insideNewCleanChain
is a clean approach to unify chain creation logic.
109-111
: SetupApp usage.Switching to
SetupApp
is consistent with the new approach in thesetup.go
file, ensuring uniform test context initialization.
166-174
: Mint multiple denominations.
MintBaseCoins
method helpfully streamlines creating multiple denominations in one call. This is well-structured and improves maintainability.
227-238
: Enhanced validator address struct.
TestValidatorAddress
encapsulates validator data cohesively (e.g., moniker, private key, addresses). This is beneficial for test readability.
240-258
: Comprehensive validator creation.
CreateValidatorFromFullAddress
sets up a validator with staking parameters in one step. Panic on error is standard for tests but be sure the moniker or stake logic follows test conventions.
312-329
: Streamlined new validator creation.
CreateNewValidator
and the subsequent minting logic is straightforward. The approach is consistent with the rest of the test suite.
351-361
: Zero delegation override.
SetDelegationToZero
forcibly modifies the validator’s self-delegation to zero for testing scenarios. This is valid for specialized test cases but ensure that no production code references this logic.
378-381
: Voting info usage.
DecidedLastCommit.Votes = suite.VoteInfos
helps replicate real block finalization scenarios. Confirm these hypothetical votes match test scenarios for coverage.
407-427
: Generator function is well defined.
GenerateTestValidatorAddress
neatly packs moniker-based key generation and address creation logic. It’s a neat approach for test data.
429-452
: Vote management.
ResetAbciVotes
,AddAbciCommitVotes
,AddAbciAbsentVote
, andaddAbciVotes
provide flexible vote simulation. Good addition for simulating consensus behavior in tests.x/stakers/types/errors.go (1)
24-24
: Renamed error for clarity.
ErrValidatorNotInActiveSet
is more descriptive than the previousErrValidatorJailed
. Confirm all references reflect this updated naming.x/funders/types/params.go (1)
34-35
: Verify the implications of reducing MinFundingAmount.The minimum funding amount has been significantly reduced from 1,000 $KYVE to 100 $KYVE. While this lowers the barrier to entry for funders, it's important to ensure this aligns with the project's economic model and security considerations.
✅ Verification successful
Economic parameters verified: The reduced MinFundingAmount change aligns with the rest of the codebase.
- The new minimum funding value (set to 100_000_000, representing 100 $KYVE) is now consistently used in the funders’ parameters (see x/funders/types/params.go) and referenced in related modules (such as in pool disable/update tests).
- Test cases across modules—where amounts are set as 100 × i.KYVE—confirm that the new value (interpreting i.KYVE as 1,000,000) matches the intended reduction from 1,000 $KYVE to 100 $KYVE.
- No inconsistencies were found with related economic validations (e.g., funding, delegation, or coin weight checks), implying that lowering the funding amount to reduce the entry barrier is compatible with the project’s economic model and security constraints.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check if this change is consistent with other economic parameters # Search for other minimum amounts in the codebase rg -A 2 "MinFundingAmount|MinDelegation|MinStake" --type go # Search for any related test cases rg -A 5 "TestMinFunding|TestMinDelegation|TestMinStake" --type goLength of output: 56423
interchaintest/ibc/ibc_utils_test.go (1)
7-8
: LGTM! Good improvement in test isolation.Replacing
app.Setup()
withi.NewCleanChain().App()
ensures a clean state for each test, which is a good practice for test reliability and isolation.Also applies to: 28-28
x/stakers/keeper/msg_server_join_pool.go (1)
42-42
: LGTM! Improved error handling.The change simplifies error handling by directly returning
ErrValidatorNotInActiveSet
instead of wrapping it. This makes the error more specific and easier to handle.interchaintest/global/abci_utils_test.go (1)
30-30
: LGTM! Clean initialization approach.The change to use
i.NewCleanChain().App()
improves test isolation and follows modern testing practices.x/stakers/keeper/keeper_suite_protocol_bridge_test.go (1)
16-26
: LGTM! Well-structured test cases with clear documentation.The test cases cover critical scenarios and are well-documented with clear objectives.
x/pool/keeper/msg_server_update_pool_test.go (1)
82-82
: LGTM! Consistent parameter updates.The MinDelegation value has been updated to align with other funding parameters in the codebase, maintaining consistency across the testing framework.
x/bundles/keeper/logic_round_robin_test.go (1)
467-467
: LGTM! Consistent shift value adjustment.The shift calculation has been updated to align with other parameter adjustments in the codebase, maintaining consistency in the testing framework.
x/pool/keeper/msg_server_disable_pool_test.go (1)
72-74
: LGTM! Consistent funding parameter update.The update to set
MinFundingAmount
to 100,000,000 aligns with similar changes in other test files, ensuring consistent funding parameters across the test suite.x/stakers/keeper/keeper_suite_effective_stake_test.go (2)
272-305
: LGTM! Improved validator creation pattern.The refactor to use
CreateNewValidator
improves code maintainability by:
- Returning structured data with validator details
- Making the relationship between validator and pool accounts explicit
- Reducing reliance on hardcoded identifiers
498-502
: Verify the updated stake calculations.The expected stake values have been reduced significantly. Please ensure these new values align with the updated calculation logic.
✅ Verification successful
Stake Calculation Verification: The updated test values are consistent and correct.
The grep results reveal that the new expected values—23333333 for both STAKER_0 and STAKER_1 and 20 × i.KYVE for STAKER_2, summing to a total of 66666666—are used in the effective stake test and match the revised calculation logic. All related tests throughout the codebase reflect similar calculations, confirming that the significant reduction in stake values aligns with the changes.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for other stake calculations to verify consistency rg -A 2 "GetValidatorPoolStake|GetTotalStakeOfPool" --type goLength of output: 52414
x/team/keeper/msg_server_clawback_test.go (1)
51-55
: Verify the precision reduction in vesting calculations.The expected values for vesting amounts have been consistently reduced by three orders of magnitude. Please confirm this aligns with any changes to the vesting calculation logic or precision requirements.
Also applies to: 84-88, 118-122, 167-171, 271-275
✅ Verification successful
Precision reduction confirmed in vesting tests
The repository’s tests and vesting logic confirm that vesting amounts are now computed using a reduced precision – values are scaled down by roughly three orders of magnitude. For example, in
msg_server_clawback_test.go
, the vesting amounts are compared against literal values (e.g.694_444_444_444
) rather than multiplications against the full precision constant (such as1_000_000 * i.KYVE
). This is consistent with the new vesting calculation logic that factors in a precision reduction.
- Vesting amounts in tests (e.g. in
msg_server_clawback_test.go
) use scaled-down literal values.- Other parts of the code (e.g. in
logic_team.go
and related test files) similarly reflect calculations that have shifted to the new precision.This verifies that the change is intentional and that the reduced precision (by three orders of magnitude) aligns with the updated calculation logic.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for other vesting amount calculations rg -A 2 "TotalVestedAmount|TotalUnlockedAmount|RemainingUnvestedAmount|LockedVestedAmount|CurrentClaimableAmount" --type goLength of output: 46981
x/bundles/keeper/keeper_suite_zero_delegation_test.go (2)
301-304
: LGTM! Improved validator setup.The use of
CreateNewValidator
and explicit validator state verification improves test clarity and reliability.
337-339
: LGTM! Consistent use of structured validator data.The update to use validator addresses from the structured data improves code maintainability by reducing reliance on hardcoded identifiers.
Also applies to: 427-429
x/bundles/keeper/keeper_suite_inflation_splitting_test.go (1)
61-161
: Robust test setup with proper cleanup!The test setup and cleanup implementation ensures proper test isolation:
- Clean chain initialization for each test
- Proper cleanup of global variables
- Validity checks after each test
x/bundles/keeper/keeper_suite_valid_bundles_test.go (2)
1052-1053
: Address the TODO comment about uploader selection.The TODO comment questions why staker 2 is selected as the next uploader. This needs to be investigated and documented to ensure the uploader selection logic is working as intended.
Would you like me to:
- Help investigate why staker 2 is selected as the next uploader?
- Generate additional test cases to verify the uploader selection logic?
- Open a new issue to track this investigation?
1799-1802
: Verify the consistency of coin parameter updates.The changes to coin parameters appear to be part of a coordinated update to align with new decimal places and funding requirements. Please verify that these changes are consistent with:
- The overall system's decimal place standardization
- The intended funding thresholds for the platform
Run the following script to check for any inconsistencies in coin decimal places and funding amounts across the codebase:
✅ Verification successful
Consistency of Coin Parameter Updates Verified
The coin parameter changes in the valid bundles test file are consistent with the overall system updates. In particular:
- CoinDecimals: Set to 6 as expected across the code (e.g., in both
x/bundles/keeper/keeper_suite_valid_bundles_test.go
andx/funders/types/params.go
).- Funding Thresholds: The values for
MinFundingAmount
(100_000_000) andMinFundingAmountPerBundle
(100_000) in the valid bundles tests match those in the global parameters configuration.- Different Test Contexts: Although
x/funders/keeper/msg_server_update_params_test.go
uses different numerical values for funding amounts, these differences appear intentional for distinct update scenarios and do not indicate a broader inconsistency.Overall, the updates align with the new decimal and funding requirements.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for consistency in coin decimal places and funding amounts # Search for coin decimal declarations echo "Checking coin decimal declarations..." rg -A 2 "CoinDecimals.*6" # Search for minimum funding amount declarations echo "Checking minimum funding amounts..." rg -A 2 "MinFundingAmount.*100_000_000" # Search for minimum funding per bundle declarations echo "Checking minimum funding per bundle..." rg -A 2 "MinFundingAmountPerBundle.*100_000"Length of output: 5305
Summary by CodeRabbit