Skip to content

test: strategy integration tests #68

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

Merged
merged 4 commits into from
Feb 20, 2025
Merged

Conversation

0xnigir1
Copy link
Collaborator

@0xnigir1 0xnigir1 commented Feb 17, 2025

🤖 Linear

Closes GIT-265 GIT-262

Description

Write integration tests for Strategy events on Orchestrator level (continuation of #67). Also, fix some issues on Registration handler regarding Date and BlockTimestamp conversion

Summary by CodeRabbit

  • New Features
    • Expanded strategy mapping to support additional entries.
  • Refactor
    • Enhanced event handling by making a key parameter optional with a default value.
    • Refined timestamp processing to ensure consistent and accurate date representations.
  • Tests
    • Introduced new integration tests to validate and monitor strategy event processing and time accuracy.

@0xnigir1 0xnigir1 self-assigned this Feb 17, 2025
Copy link

linear bot commented Feb 17, 2025

Copy link

coderabbitai bot commented Feb 17, 2025

📝 Walkthrough

Walkthrough

The pull request introduces several updates across the codebase. A new entry is added to the default strategy mapping, associating a specific chain ID with an extra address and its hex value. The event factory now defines the block number parameter as optional, setting a default value when omitted. A new integration test suite for the orchestrator has been implemented to evaluate the processing of various strategy-related events using defined mocks and spies. In addition, multiple strategy handler modules and their corresponding tests are modified: the conversion of the block timestamp has been changed to use the value directly (in milliseconds) instead of multiplying by 1000. This adjustment affects the way that timestamps are interpreted both in production code and in tests, ensuring a consistent representation of time across the system.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

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

🧹 Nitpick comments (2)
packages/data-flow/test/integration/strategy.integration.spec.ts (2)

55-55: Enhance test descriptions for better clarity.

Consider making test descriptions more descriptive by focusing on the expected behavior rather than the implementation detail of "processing". For example:

  • "process Distributed event" → "updates round total when distribution occurs"
  • "process DistributionUpdated event" → "updates round data when distribution is updated"

Also applies to: 112-112, 191-191, 259-259, 354-354, 436-436


59-63: Consider extracting test data constants.

Consider extracting commonly used test values into named constants for better maintainability and readability. For example:

  • Amount values
  • Token addresses
  • Metadata values

Also applies to: 115-118, 194-199, 263-267, 358-363, 439-444

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c8fd4d0 and 8f9b76f.

📒 Files selected for processing (9)
  • packages/data-flow/test/integration/helpers/dependencies.ts (1 hunks)
  • packages/data-flow/test/integration/helpers/eventFactory.ts (2 hunks)
  • packages/data-flow/test/integration/strategy.integration.spec.ts (1 hunks)
  • packages/processors/src/processors/strategy/directGrantsLite/handlers/registered.handler.ts (1 hunks)
  • packages/processors/src/processors/strategy/directGrantsSimple/handlers/registered.handler.ts (1 hunks)
  • packages/processors/src/processors/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/registered.handler.ts (1 hunks)
  • packages/processors/test/strategy/directGrantsLite/handlers/registered.handler.spec.ts (1 hunks)
  • packages/processors/test/strategy/directGrantsSimple/handlers/registered.handler.spec.ts (1 hunks)
  • packages/processors/test/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/registered.handler.spec.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.ts`: Review TypeScript files for adherence to the fo...

**/*.ts: Review TypeScript files for adherence to the following guidelines:
- Avoid over-abstraction; prioritize composition over inheritance.
- Use dependency injection and follow SOLID principles.
- Avoid any; use unknown when necessary.
- Use runtime type-checking for environment variables (e.g., Zod).
- Prevent circular dependencies with the internal module pattern.
- Libraries should have an external.ts file explicitly listing public exports.
- Use bigint as-is; cast to Number only when exposing values via APIs.
- Document all code with JSDoc.
- Encourage static async factory functions for constructors.

  • Avoid overly nitpicky feedback beyond these best practices.
  • packages/processors/src/processors/strategy/directGrantsSimple/handlers/registered.handler.ts
  • packages/processors/src/processors/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/registered.handler.ts
  • packages/processors/test/strategy/directGrantsSimple/handlers/registered.handler.spec.ts
  • packages/processors/test/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/registered.handler.spec.ts
  • packages/processors/src/processors/strategy/directGrantsLite/handlers/registered.handler.ts
  • packages/data-flow/test/integration/strategy.integration.spec.ts
  • packages/processors/test/strategy/directGrantsLite/handlers/registered.handler.spec.ts
  • packages/data-flow/test/integration/helpers/dependencies.ts
  • packages/data-flow/test/integration/helpers/eventFactory.ts
`**/*.spec.ts`: Review the unit test files with the followin...

**/*.spec.ts: Review the unit test files with the following guidelines:
- Avoid using the word "should" in test descriptions.
- Ensure descriptive test names convey the intent of each test.
- Validate adherence to the Mocha/Chai/Jest test library best practices.

  • Be concise and avoid overly nitpicky feedback outside of these best practices.
  • packages/processors/test/strategy/directGrantsSimple/handlers/registered.handler.spec.ts
  • packages/processors/test/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/registered.handler.spec.ts
  • packages/data-flow/test/integration/strategy.integration.spec.ts
  • packages/processors/test/strategy/directGrantsLite/handlers/registered.handler.spec.ts
🔇 Additional comments (9)
packages/data-flow/test/integration/helpers/eventFactory.ts (1)

99-99: LGTM! Consistent parameter handling.

The change to make blockNumber optional with a default value aligns with the pattern used in other event factory functions, improving API consistency.

Also applies to: 109-109

packages/data-flow/test/integration/helpers/dependencies.ts (1)

116-119: LGTM! Strategy mapping entry added.

The new strategy mapping entry follows the established pattern and is properly formatted.

packages/data-flow/test/integration/strategy.integration.spec.ts (1)

20-527: Well-structured and comprehensive test suite!

The test suite is well-implemented with:

  • Proper test setup and cleanup
  • Comprehensive coverage of different event types
  • Good use of mocks and spies
  • Detailed assertions
  • Proper error handling
packages/processors/src/processors/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/registered.handler.ts (1)

72-72:

❓ Verification inconclusive

Verify the blockTimestamp format.

The change from new Date(blockTimestamp * 1000) to new Date(blockTimestamp) assumes that blockTimestamp is already in milliseconds. Please verify this assumption.


🏁 Script executed:

#!/bin/bash
# Description: Check the format of blockTimestamp in the codebase
# Look for any timestamp conversions or related comments

rg -A 2 'blockTimestamp' --type ts

Length of output: 183


Verify BlockTimestamp Assumption – Manual Confirmation Needed

The change from using new Date(blockTimestamp * 1000) to new Date(blockTimestamp) hinges on the assumption that blockTimestamp is provided in milliseconds rather than in seconds. However, our initial investigation (using ripgrep) did not return any useful results due to filtering issues.

Next Steps:

  • Search for Conversion Logic: Check if there are any instances of blockTimestamp * 1000 elsewhere in the codebase that might indicate the previous expectation of a seconds-based timestamp.

  • Examine the Specific File: In

    packages/processors/src/processors/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/registered.handler.ts
    

    verify near line 72 (or elsewhere) how blockTimestamp is derived and whether any conversion (multiplication by 1000) is performed before its usage.

  • Re-run More Targeted Searches: For example, you can run the following shell script to help locate any conversions related to blockTimestamp and confirm the file’s content:

    #!/bin/bash
    # Check if the expected file exists
    find . -type f -path "packages/processors/src/processors/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/registered.handler.ts" || echo "registered.handler.ts file not found"
    
    # Search for usage of blockTimestamp multiplied by 1000 anywhere in the repository
    rg -n "blockTimestamp\s*\*\s*1000" || echo "No occurrences of blockTimestamp * 1000 found"
    
    # Display occurrences of blockTimestamp in the specified file
    grep -n "blockTimestamp" packages/processors/src/processors/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/registered.handler.ts || echo "No blockTimestamp references found in registered.handler.ts"

Please run the above script and manually verify that:

  • There is no residual expectation of seconds-based timestamps elsewhere.
  • The value in blockTimestamp is indeed provided in milliseconds.

Once confirmed, no further action on this part is necessary. Otherwise, adjust the conversion accordingly.


Manual Verification Needed – Confirm BlockTimestamp Format

The revised shell script above is intended to help verify whether the change from using new Date(blockTimestamp * 1000) to new Date(blockTimestamp) is valid—that is, whether blockTimestamp is indeed already in milliseconds. Please run this script and review its output for:

  • Any occurrences of blockTimestamp indicating its origin or manipulation.
  • Any patterns multiplying blockTimestamp by 1000 which would imply it is initially in seconds.

Based on the results, update the conversion logic if necessary.


🏁 Script executed:

[run_scripts]
#!/bin/bash
# Search for any usage of "blockTimestamp" across the repository without file type filtering
echo "Searching for blockTimestamp occurrences (no file type filter):"
rg -A 2 "blockTimestamp" || echo "No occurrences found."

# Search the repository for any instance where blockTimestamp is multiplied by 1000
echo "Searching for blockTimestamp multiplication pattern:"
rg -n "blockTimestamp\s*\*\s*1000" || echo "No multiplication pattern found."

# Optionally, check the content of the specific file for context on blockTimestamp usage
echo "Checking registered.handler.ts for blockTimestamp references:"
grep -n "blockTimestamp" packages/processors/src/processors/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/registered.handler.ts || echo "No blockTimestamp references found in registered.handler.ts."

Length of output: 1129


BlockTimestamp Format Verification – Manual Confirmation Required

Our automated search did not return any instances of multiplying blockTimestamp by 1000, and we couldn’t locate the file at the specified path. This suggests that either the file path is different than expected or that the conversion was already updated elsewhere. Please verify the following manually:

  • Confirm that the file under review (or its correct location) indeed contains the change from new Date(blockTimestamp * 1000) to new Date(blockTimestamp).
  • Verify that the value of blockTimestamp is already provided in milliseconds throughout the codebase.
  • Ensure there are no other parts of the repository still expecting a seconds-based timestamp (e.g., by checking for any conversion logic like blockTimestamp * 1000).

Based on your manual verification, adjust the conversion if necessary.

packages/processors/src/processors/strategy/directGrantsSimple/handlers/registered.handler.ts (1)

78-78:

❓ Verification inconclusive

Ensure consistent timestamp handling.

The timestamp handling has been changed consistently across all handlers. However, please verify that this change aligns with how timestamps are handled in other parts of the system.


🏁 Script executed:

#!/bin/bash
# Description: Check for other timestamp handling patterns
# Look for Date constructor usage patterns

ast-grep --pattern 'new Date($timestamp)'

Length of output: 43


Below is an updated shell script to widen the search for timestamp handling patterns across the repository. The previous ast-grep command didn’t produce any output, so please run this alternative using rg to ensure we capture all instances of the new Date( usage:

Once you run this command, please review the output to verify that the usage in
packages/processors/src/processors/strategy/directGrantsSimple/handlers/registered.handler.ts at line 78
(updatedAt: new Date(blockTimestamp)) aligns with how timestamps are processed elsewhere in the system.


🏁 Script executed:

[run_scripts]
#!/bin/bash
# Searching for consistent timestamp handling patterns across the repository using rg.
rg "new Date(" -n .

Length of output: 212


Re-run the Timestamp Consistency Check

The earlier command encountered a regex error due to unescaped parenthesis. Please run the updated script below to search for all instances of the Date constructor across the repository. This will help you verify that the timestamp handling in packages/processors/src/processors/strategy/directGrantsSimple/handlers/registered.handler.ts (line 78) is consistent with other parts of the system.


🏁 Script executed:

[run_scripts]
#!/bin/bash
# Searching for consistent use of new Date(...) with proper escaping
rg "new Date\\(" -n .

Length of output: 144


Timestamp Handling Consistency – Further Manual Verification Needed

The automated searches did not yield additional instances of new Date( usage that conflict with the change in updatedAt: new Date(blockTimestamp). However, since the automated output was inconclusive, please manually verify that the timestamp handling in this handler aligns with the approach taken throughout the system.

packages/processors/src/processors/strategy/directGrantsLite/handlers/registered.handler.ts (1)

77-77: LGTM! Consistent timestamp handling.

The timestamp handling is consistent with other handlers in the system.

packages/processors/test/strategy/directGrantsSimple/handlers/registered.handler.spec.ts (1)

87-87: LGTM! Test updated to match implementation.

The test has been correctly updated to reflect the new timestamp handling approach.

packages/processors/test/strategy/directGrantsLite/handlers/registered.handler.spec.ts (1)

91-91:

❓ Verification inconclusive

LGTM! Correct timestamp handling.

The removal of * 1000 multiplication is the right approach since blockchain timestamps are typically in milliseconds.

Let's confirm the timestamp unit in the codebase:


🏁 Script executed:

#!/bin/bash
# Search for blockTimestamp usage patterns to verify the timestamp unit
rg -A 2 'blockTimestamp' --type ts

Length of output: 183


🏁 Script executed:

#!/bin/bash
# Re-run search for blockTimestamp in the specific test file to ensure we gather the proper context.
rg -A 2 'blockTimestamp' packages/processors/test/strategy/directGrantsLite/handlers/registered.handler.spec.ts

Length of output: 238


Timestamp Handling Verification (Manual Check Requested)

The updated code using new Date(mockEvent.blockTimestamp) appears correct based on the assumption that blockchain timestamps are provided in milliseconds. However, our automated search for occurrences of blockTimestamp did not return any results—likely due to file relocation or naming differences—which makes it difficult to conclusively confirm the unit across the codebase.

  • Action Items:
    • Manually verify that the event’s blockTimestamp is indeed in milliseconds and no further scaling (like multiplying by 1000) is needed.
    • Confirm that the referenced test file location is correct or update the file path if it has moved.

Overall, the removal of the * 1000 multiplication is intended since timestamps are expected in milliseconds. Please ensure that this assumption holds true in all relevant parts of the application.

packages/processors/test/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/registered.handler.spec.ts (1)

111-111: LGTM! Consistent timestamp handling.

The timestamp handling is now consistent with other handlers and correctly preserves the millisecond precision.

params: {
recipientId: mockAnchorAddress,
amount: "1000000000000000000", // 1 ETH
token: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", // ETH
Copy link
Collaborator

Choose a reason for hiding this comment

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

idk this doesn't look like ETH to me haha

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

jajaj it's actually the way we represent the native token address (since it doesnt have an address) but i can delete the comment to avoid confussion

eventName: "DistributedWithRecipientAddress",
params: {
recipientId: "0xrecipient",
recipientAddress: "0xrecipient",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think generally we should use a valid mock address where we have an address field because I've gotten issues before in EBO where we were using invalid addresses and it caused test errors later on when we were adding address validation, wdyt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@0xnigir1 0xnigir1 requested a review from jahabeebs February 20, 2025 16:42
@0xnigir1 0xnigir1 merged commit f80492e into dev Feb 20, 2025
6 checks passed
@0xnigir1 0xnigir1 deleted the test/strategy-integration-tests branch February 20, 2025 19:22
0xkenj1 pushed a commit that referenced this pull request Feb 24, 2025
# 🤖 Linear

Closes GIT-265 GIT-262

## Description

Write integration tests for Strategy events on Orchestrator level
(continuation of #67). Also, fix some issues on Registration handler
regarding Date and BlockTimestamp conversion

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
	- Expanded strategy mapping to support additional entries.
- **Refactor**
- Enhanced event handling by making a key parameter optional with a
default value.
- Refined timestamp processing to ensure consistent and accurate date
representations.
- **Tests**
- Introduced new integration tests to validate and monitor strategy
event processing and time accuracy.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants