Skip to content

Create local test configuration branch#11

Open
BowTiedSwan wants to merge 5 commits intomainfrom
cursor/create-local-test-configuration-branch-7f19
Open

Create local test configuration branch#11
BowTiedSwan wants to merge 5 commits intomainfrom
cursor/create-local-test-configuration-branch-7f19

Conversation

@BowTiedSwan
Copy link
Copy Markdown
Contributor

@BowTiedSwan BowTiedSwan commented Jun 17, 2025

Create a PR description that addresses the implementation of the local testing solution as well as ability ot index local data

🚀 PR: Local Anvil Testing & Local Data Indexing System

📌 Objective

Provide a zero-config, first-class local-testing experience for developers by:

  1. Introducing a new local_test environment that auto-detects localhost RPCs.
  2. Mapping your deployed Anvil-fork contract addresses (Arbitrum & Base).
  3. Replacing remote GraphQL reads with a Local Data Indexer that pulls data straight from local contracts, so newly-created subnets, stakes, withdrawals, etc. are visible in the UI in real time.

🆕 Key Features

Area Feature Description
Config local_test environment Added to NetworkEnvironment + localTestChains with your contract addresses.
Auto-Detection RPC inspection If wallet RPC URL contains localhost or 127.0.0.1, app switches to local_test.
wagmi Local chain definitions localArbitrum (ID 42161, port 8545) & localBase (ID 8453, port 8546) added to wagmi config.
Indexer local-data.service.ts • Discovers subnets/pools via SubnetCreated / BuilderPoolCreated events.
• Reads on-chain state (subnets, subnetsMetadata, builderPools, etc.) with wagmi/viem.
• Transforms to GraphQL-compatible objects.
Adapter graphql-client.adapter.ts Transparently switches data source:
mainnet / testnet → remote GraphQL
local_test → local contracts
Debug UI LocalDataDebug component Orange panel (visible only in local mode) showing:
• Live discovered subnets & pools
• Refresh button
• Raw debug JSON
Visual UX Banner tweaks Distinct banner for LOCAL TEST MODE.
Docs docs/local-anvil-testing.md LOCAL_DATA_INDEXING_SUMMARY.md Step-by-step setup, architecture diagrams, troubleshooting.

🗄️ Code Structure

config/
  networks.ts              ← adds local_test chains + helpers
  index.tsx                ← wagmi config with local chains
app/services/
  local-data.service.ts    ← event discovery + contract reads
  graphql-client.adapter.ts← runtime data-source switch
components/debug/
  local-data-debug.tsx     ← debug panel
pages/
  builders/page.tsx        ← inject debug panel
docs/
  local-anvil-testing.md   ← user guide
  LOCAL_DATA_INDEXING_SUMMARY.md ← technical deep-dive

🧩 How It Works

  1. Detect
    Wallet connects to http://127.0.0.1:8545/8546environment = 'local_test'.

  2. Discover
    local-data.service scans blocks 0 → latest for creation events and caches subnet/pool IDs.

  3. Read
    For each ID, read:

    subnets(id)           // BuilderSubnetsV2
    subnetsMetadata(id)
    subnetsData(id)
    builderPools(id)      // Builders
    usersData(addr,id)
  4. Transform
    Contract tuples → GraphQL‐style BuilderSubnet, BuilderProject, etc.

  5. Serve
    graphql-client.adapter returns those objects; existing hooks/components render them.

  6. Debug
    <LocalDataDebug /> shows a live dashboard + manual refresh.


🔬 Testing Instructions

# 1. Start forks
anvil --fork-url https://arb1.arbitrum.io/rpc   --port 8545
anvil --fork-url https://mainnet.base.org       --port 8546

# 2. Deploy contracts to the addresses configured in networks.ts
#    (MOR Token + Builders for each fork)

# 3. Add networks in MetaMask:
#    - Arbitrum Local: 127.0.0.1:8545 / ChainID 42161
#    - Base     Local: 127.0.0.1:8546 / ChainID 8453

# 4. Switch wallet → Observe:
#    🛠️  Orange banner + Debug panel
#    Create subnet → appears instantly

🛡️ Backward Compatibility

  • Mainnet/Testnet behaviour unchanged – continues to use existing subgraphs.
  • UI Components untouched; data source is abstracted.
  • Added code is gated behind environment === 'local_test'.

📝 Future Work (Optional)

  • Real-time event listeners (ws) instead of historical scan.
  • Index stake/withdraw/claim events for per-user histories.
  • Persist cache between refreshes (IndexedDB).
  • Extend to additional local chains/builders.

🎉 This PR delivers a full end-to-end local testing workflow – create a subnet on your Anvil fork and watch it appear in the dashboard instantly, no config required!

…tworkEnvironment type to include local_test - Add localTestChains configuration for Anvil forks - Implement auto-detection based on RPC URL - Update NetworkProvider with automatic environment switching - Add local chains to wagmi configuration - Extend testnet indicator to show local test mode - Add comprehensive documentation for local testing setup
…ervice.ts for contract reading and event discovery - Add graphql-client.adapter.ts for seamless data source switching - Implement LocalDataDebug component for real-time contract monitoring - Integrate debug panel into builders page for local test mode - Support BuilderSubnetsV2 and Builders contract functions - Auto-discover subnets/pools from blockchain events - Transform contract data to GraphQL-compatible format - Provide zero-config solution that works automatically with localhost RPCs
@vercel
Copy link
Copy Markdown

vercel bot commented Jun 17, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
dashboard-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 17, 2025 1:00pm

cursor[bot]

This comment was marked as outdated.

…actData - Replace Set usage with state updates for discovered IDs and enhance logging for better clarity
cursor[bot]

This comment was marked as outdated.

…ocal test chain definitions and integrate local RPC URLs directly into existing chain configurations for Arbitrum and Base
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.

2 participants