Files
mev-beta/internal/config/config_test.go
Krypto Kajun 850223a953 fix(multicall): resolve critical multicall parsing corruption issues
- Added comprehensive bounds checking to prevent buffer overruns in multicall parsing
- Implemented graduated validation system (Strict/Moderate/Permissive) to reduce false positives
- Added LRU caching system for address validation with 10-minute TTL
- Enhanced ABI decoder with missing Universal Router and Arbitrum-specific DEX signatures
- Fixed duplicate function declarations and import conflicts across multiple files
- Added error recovery mechanisms with multiple fallback strategies
- Updated tests to handle new validation behavior for suspicious addresses
- Fixed parser test expectations for improved validation system
- Applied gofmt formatting fixes to ensure code style compliance
- Fixed mutex copying issues in monitoring package by introducing MetricsSnapshot
- Resolved critical security vulnerabilities in heuristic address extraction
- Progress: Updated TODO audit from 10% to 35% complete

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-17 00:12:55 -05: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)
}