Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: adding test configuration and test coverage for binance plugin #2482

Merged
merged 6 commits into from
Jan 18, 2025

Conversation

ai16z-demirix
Copy link
Contributor

@ai16z-demirix ai16z-demirix commented Jan 18, 2025

Relates to

#2481

Risks

Low: adding test coverage and configuration

Background

What does this PR do?

Test Structure:

  • Organized tests into separate files for each service: price.test.ts, account.test.ts, and trade.test.ts
  • Used Vitest as the testing framework
  • Implemented proper mocking of external dependencies (Binance API client)
    Account Service Tests (account.test.ts)
  • Basic service initialization with API credentials
  • Balance retrieval functionality
  • Filtering non-zero balances
  • Asset-specific balance filtering
  • Balance sufficiency checks
  • Error handling for missing credentials
    Trade Service Tests (trade.test.ts)
  • Market order execution
    -Limit order execution with price and time-in-force parameters
    -Symbol validation
    Comprehensive error handling:
  • Authentication errors
  • Invalid symbols
  • Minimum notional value requirements
  • Missing required parameters (e.g., price for limit orders)
    Price Service Tests (price.test.ts)
  • Price checking functionality
  • Symbol validation
  • Error handling for API responses

What kind of change is this?

Feature/tests

#2481

Documentation changes needed?

None

Testing

Where should a reviewer start?

packages/plugin-binance

Detailed testing steps

pnpm install & pnpm build
navigate to desired directory to see tests
run pnpm test

Copy link
Contributor

coderabbitai bot commented Jan 18, 2025

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/plugin-binance/__tests__/account.test.ts

Oops! Something went wrong! :(

ESLint: 9.18.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

📝 Walkthrough

Walkthrough

The pull request introduces comprehensive test suites for the Binance plugin, focusing on three key services: AccountService, PriceService, and TradeService. The changes include creating test files with Vitest, adding a Vitest configuration, and updating the package.json to support testing. These tests validate the functionality, error handling, and core methods of each service using mock implementations of the Binance client.

Changes

File Change Summary
__tests__/account.test.ts Added test suite for AccountService with tests for balance retrieval, balance checking, and error handling
__tests__/price.test.ts Implemented tests for PriceService covering price retrieval, formatting, and error scenarios
__tests__/trade.test.ts Created comprehensive tests for TradeService including order execution and error handling
package.json Added Vitest dependencies, testing scripts, and updated package configuration
vitest.config.ts New configuration file for Vitest with global test settings and module resolution

Possibly related issues

  • elizaOS/eliza#2481: Directly addresses the issue's request to add test configuration and tests for the Binance plugin, covering Account, Trade, and Price services with comprehensive test coverage.

Finishing Touches

  • 📝 Generate Docstrings (Beta)

🪧 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
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
packages/plugin-binance/vitest.config.ts (1)

4-16: Add coverage configuration to track test coverage metrics.

Consider adding coverage configuration to track and enforce test coverage thresholds:

 export default defineConfig({
     test: {
         globals: true,
         environment: 'node',
-        testTimeout: 10000
+        testTimeout: 10000,
+        coverage: {
+            provider: 'v8',
+            reporter: ['text', 'json', 'html'],
+            branches: 80,
+            functions: 80,
+            lines: 80,
+            statements: 80
+        }
     },
     resolve: {
packages/plugin-binance/__tests__/price.test.ts (1)

69-87: Add edge cases to price formatting tests.

Consider adding tests for:

  • Zero values
  • Negative numbers
  • Scientific notation
  • Invalid input handling
 describe('formatPrice', () => {
+    it('should handle edge cases', () => {
+        expect(PriceService.formatPrice('0')).toBe('0.00');
+        expect(PriceService.formatPrice('-42150.25')).toBe('-42,150.25');
+        expect(PriceService.formatPrice('1e-8')).toBe('0.00000001');
+        expect(() => PriceService.formatPrice('invalid')).toThrow();
+    });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between beb0bc1 and 0dca0cd.

📒 Files selected for processing (5)
  • packages/plugin-binance/__tests__/account.test.ts (1 hunks)
  • packages/plugin-binance/__tests__/price.test.ts (1 hunks)
  • packages/plugin-binance/__tests__/trade.test.ts (1 hunks)
  • packages/plugin-binance/package.json (1 hunks)
  • packages/plugin-binance/vitest.config.ts (1 hunks)
🔇 Additional comments (3)
packages/plugin-binance/package.json (3)

23-23: LGTM! Workspace dependency is correctly configured.

The @elizaos/core dependency is properly set up as a workspace dependency, which is ideal for monorepo setups.


34-36: Test scripts follow standard conventions.

The scripts are well-organized with both single-run and watch mode options for testing.


27-30: Test framework dependencies are well-chosen.

The combination of Vitest with vite-tsconfig-paths provides a robust testing setup with proper path resolution support.

Let's verify the Vitest configuration:

✅ Verification successful

Test framework setup is properly configured and utilized

  • Test files exist in __tests__ directory with proper naming
  • Vitest config includes correct environment, timeout, and path resolution settings
  • Configuration extends core tsconfig with appropriate compiler options
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify Vitest configuration exists and includes necessary settings

# Check if vitest config exists
fd -t f "vitest.config" packages/plugin-binance/

# Check if tsconfig includes proper test paths
fd -t f "tsconfig.json" packages/plugin-binance/ --exec cat {} | jq -r 'select(.compilerOptions.paths != null)'

Length of output: 203


Script:

#!/bin/bash
# Check configuration files content
cat packages/plugin-binance/vitest.config.ts
echo "---"
cat packages/plugin-binance/tsconfig.json
echo "---"
# Look for test files
fd -e test.ts -e spec.ts . packages/plugin-binance/

Length of output: 928

@wtfsayo wtfsayo enabled auto-merge (squash) January 18, 2025 14:49
@wtfsayo wtfsayo self-requested a review January 18, 2025 14:49
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants