CG

Testing & Mock Server

Updated May 29, 2026, 12:30 PM

Testing & Mock Server

Testing & Mock Server

Mock Server Overview

The mock server is a full drop-in replacement for the ChainGPT API. It provides:

  • Realistic responses matching the live API schema
  • Simulated latency for real-world behavior
  • Credit tracking (no actual charges)
  • Zero cost for unlimited testing

No API key is required to use the mock server.


Setup

cd mock-server
npm install
npm run dev

The mock server starts on localhost:3001.

Point your environment at the mock server:

export CHAINGPT_BASE_URL=http://localhost:3001

All MCP server tools will automatically route requests to the mock server instead of the live API.


Test Suite

The plugin includes 79 passing tests across two test suites:

SuiteTestsCoverage
MCP server unit tests53All 12 tools, error handling, input validation
Mock server endpoint tests26All endpoints, response schemas, edge cases

Running Tests

# Run all tests
npm test

# Run MCP server tests only
npm run test:mcp

# Run mock server tests only
npm run test:mock

# Run with coverage
npm run test:coverage

Validation Script

A structural validation script checks the entire plugin for correctness:

bash scripts/validate.sh

This runs 118 structural checks including:

  • File existence and naming conventions
  • JSON schema validation for plugin.json and .mcp.json
  • Markdown structure and link integrity
  • Template completeness
  • Reference doc cross-references

CI Workflow

All tests run automatically on every push and pull request. The CI workflow:

  1. Installs dependencies
  2. Starts the mock server
  3. Runs the full test suite (79 tests)
  4. Executes the validation script (118 checks)
  5. Reports results

Using the Mock Server in Development

The mock server mirrors every endpoint of the live ChainGPT API:

# LLM Chat
curl http://localhost:3001/chat -X POST -H "Content-Type: application/json" \
  -d '{"question": "What is Ethereum?"}'

# NFT Generation
curl http://localhost:3001/nft/generate -X POST -H "Content-Type: application/json" \
  -d '{"prompt": "cyberpunk city"}'

# Contract Audit
curl http://localhost:3001/contract/audit -X POST -H "Content-Type: application/json" \
  -d '{"code": "pragma solidity ^0.8.0; contract Test {}"}'

# Check credit balance (simulated)
curl http://localhost:3001/credits/balance

Responses include the same fields, status codes, and error formats as the production API, making it safe to build and test integrations before going live.

View original source