Files
mev-beta/orig/internal/config/config_test.go
Administrator 803de231ba feat: create v2-prep branch with comprehensive planning
Restructured project for V2 refactor:

**Structure Changes:**
- Moved all V1 code to orig/ folder (preserved with git mv)
- Created docs/planning/ directory
- Added orig/README_V1.md explaining V1 preservation

**Planning Documents:**
- 00_V2_MASTER_PLAN.md: Complete architecture overview
  - Executive summary of critical V1 issues
  - High-level component architecture diagrams
  - 5-phase implementation roadmap
  - Success metrics and risk mitigation

- 07_TASK_BREAKDOWN.md: Atomic task breakdown
  - 99+ hours of detailed tasks
  - Every task < 2 hours (atomic)
  - Clear dependencies and success criteria
  - Organized by implementation phase

**V2 Key Improvements:**
- Per-exchange parsers (factory pattern)
- Multi-layer strict validation
- Multi-index pool cache
- Background validation pipeline
- Comprehensive observability

**Critical Issues Addressed:**
- Zero address tokens (strict validation + cache enrichment)
- Parsing accuracy (protocol-specific parsers)
- No audit trail (background validation channel)
- Inefficient lookups (multi-index cache)
- Stats disconnection (event-driven metrics)

Next Steps:
1. Review planning documents
2. Begin Phase 1: Foundation (P1-001 through P1-010)
3. Implement parsers in Phase 2
4. Build cache system in Phase 3
5. Add validation pipeline in Phase 4
6. Migrate and test in Phase 5

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-10 10:14:26 +01:00

140 lines
3.8 KiB
Go

package config
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestLoad(t *testing.T) {
// Create a temporary config file for testing
tmpFile, err := os.CreateTemp("", "config_test_*.yaml")
require.NoError(t, err)
defer os.Remove(tmpFile.Name())
// Write test config content
configContent := `
arbitrum:
rpc_endpoint: "${ARBITRUM_RPC_ENDPOINT}"
ws_endpoint: "${ARBITRUM_WS_ENDPOINT}"
chain_id: 42161
rate_limit:
requests_per_second: 5
max_concurrent: 3
burst: 10
bot:
enabled: true
polling_interval: 3
min_profit_threshold: 10.0
gas_price_multiplier: 1.2
max_workers: 3
channel_buffer_size: 50
rpc_timeout: 30
uniswap:
factory_address: "0x1F98431c8aD98523631AE4a59f267346ea31F984"
position_manager_address: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88"
fee_tiers:
- 500
- 3000
- 10000
cache:
enabled: true
expiration: 300
max_size: 10000
log:
level: "debug"
format: "text"
file: "logs/mev-bot.log"
database:
file: "mev-bot.db"
max_open_connections: 10
max_idle_connections: 5
`
_, err = tmpFile.Write([]byte(configContent))
require.NoError(t, err)
err = tmpFile.Close()
require.NoError(t, err)
// Set environment variables for test
os.Setenv("ARBITRUM_RPC_ENDPOINT", "wss://arbitrum-mainnet.core.chainstack.com/53c30e7a941160679fdcc396c894fc57")
os.Setenv("ARBITRUM_WS_ENDPOINT", "wss://arbitrum-mainnet.core.chainstack.com/53c30e7a941160679fdcc396c894fc57")
defer func() {
os.Unsetenv("ARBITRUM_RPC_ENDPOINT")
os.Unsetenv("ARBITRUM_WS_ENDPOINT")
}()
// Test loading the config
cfg, err := Load(tmpFile.Name())
require.NoError(t, err)
// Verify the loaded config
assert.Equal(t, "wss://arbitrum-mainnet.core.chainstack.com/53c30e7a941160679fdcc396c894fc57", cfg.Arbitrum.RPCEndpoint)
assert.Equal(t, "wss://arbitrum-mainnet.core.chainstack.com/53c30e7a941160679fdcc396c894fc57", cfg.Arbitrum.WSEndpoint)
assert.Equal(t, int64(42161), cfg.Arbitrum.ChainID)
assert.Equal(t, 5, cfg.Arbitrum.RateLimit.RequestsPerSecond)
assert.True(t, cfg.Bot.Enabled)
assert.Equal(t, 3, cfg.Bot.PollingInterval)
assert.Equal(t, 10.0, cfg.Bot.MinProfitThreshold)
assert.Equal(t, "0x1F98431c8aD98523631AE4a59f267346ea31F984", cfg.Uniswap.FactoryAddress)
assert.Len(t, cfg.Uniswap.FeeTiers, 3)
assert.Equal(t, true, cfg.Uniswap.Cache.Enabled)
assert.Equal(t, "debug", cfg.Log.Level)
assert.Equal(t, "logs/mev-bot.log", cfg.Log.File)
assert.Equal(t, "mev-bot.db", cfg.Database.File)
}
func TestLoadWithInvalidFile(t *testing.T) {
// Test loading a non-existent config file
_, err := Load("/non/existent/file.yaml")
assert.Error(t, err)
}
func TestOverrideWithEnv(t *testing.T) {
// Create a temporary config file for testing
tmpFile, err := os.CreateTemp("", "config_test_*.yaml")
require.NoError(t, err)
defer os.Remove(tmpFile.Name())
// Write test config content
configContent := `
arbitrum:
rpc_endpoint: "https://arb1.arbitrum.io/rpc"
rate_limit:
requests_per_second: 10
max_concurrent: 5
bot:
max_workers: 10
channel_buffer_size: 100
`
_, err = tmpFile.Write([]byte(configContent))
require.NoError(t, err)
err = tmpFile.Close()
require.NoError(t, err)
// Set environment variables to override config
os.Setenv("ARBITRUM_RPC_ENDPOINT", "https://override.arbitrum.io/rpc")
os.Setenv("RPC_REQUESTS_PER_SECOND", "20")
os.Setenv("BOT_MAX_WORKERS", "20")
defer func() {
os.Unsetenv("ARBITRUM_RPC_ENDPOINT")
os.Unsetenv("RPC_REQUESTS_PER_SECOND")
os.Unsetenv("BOT_MAX_WORKERS")
}()
// Load the config
cfg, err := Load(tmpFile.Name())
require.NoError(t, err)
// Verify the overridden values
assert.Equal(t, "https://override.arbitrum.io/rpc", cfg.Arbitrum.RPCEndpoint)
assert.Equal(t, 20, cfg.Arbitrum.RateLimit.RequestsPerSecond)
assert.Equal(t, 20, cfg.Bot.MaxWorkers)
}