Files
mev-beta/test/e2e/e2e_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

139 lines
3.9 KiB
Go

//go:build integration
// +build integration
package e2e
import (
"context"
"math/big"
"testing"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/stretchr/testify/assert"
"github.com/fraktal/mev-beta/internal/config"
"github.com/fraktal/mev-beta/internal/logger"
"github.com/fraktal/mev-beta/internal/ratelimit"
"github.com/fraktal/mev-beta/pkg/market"
"github.com/fraktal/mev-beta/pkg/monitor"
"github.com/fraktal/mev-beta/pkg/scanner"
)
func TestEndToEndPipeline(t *testing.T) {
// Skip this test in short mode
if testing.Short() {
t.Skip("skipping end-to-end test in short mode")
}
// Create test config
arbCfg := &config.ArbitrumConfig{
RPCEndpoint: "https://arb1.arbitrum.io/rpc",
ChainID: 42161,
RateLimit: config.RateLimitConfig{
RequestsPerSecond: 10,
MaxConcurrent: 5,
Burst: 20,
},
}
botCfg := &config.BotConfig{
Enabled: true,
PollingInterval: 1,
MinProfitThreshold: 10.0,
GasPriceMultiplier: 1.2,
MaxWorkers: 2, // Use fewer workers for testing
ChannelBufferSize: 5,
RPCTimeout: 30,
}
uniswapCfg := &config.UniswapConfig{
FactoryAddress: "0x1F98431c8aD98523631AE4a59f267346ea31F984",
PositionManagerAddress: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88",
FeeTiers: []int64{500, 3000, 10000},
Cache: config.CacheConfig{
Enabled: true,
Expiration: 300,
MaxSize: 10000,
},
}
// Create test logger
log := logger.New("info", "text", "")
// Create rate limiter manager
rateLimiter := ratelimit.NewLimiterManager(arbCfg)
// Create market manager
marketMgr := market.NewMarketManager(uniswapCfg, log)
// Create market scanner
scanner := scanner.NewMarketScanner(botCfg, log)
// Create monitor (this would normally connect to a real RPC endpoint)
// For testing, we'll just verify it can be created
monitor, err := monitor.NewArbitrumMonitor(
arbCfg,
botCfg,
log,
rateLimiter,
marketMgr,
scanner,
)
assert.NoError(t, err)
assert.NotNil(t, monitor)
// Test that we can process a block of transactions
// Create test transactions
transactions := make([]*types.Transaction, 0)
// Create a transaction that interacts with a DEX
to := common.HexToAddress("0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640") // Uniswap V3 pool
tx := types.NewTransaction(0, to, big.NewInt(0), 0, big.NewInt(0), nil)
transactions = append(transactions, tx)
// Create pipeline
// Create pipeline with Ethereum client
var ethClient *ethclient.Client // nil for testing
pipeline := market.NewPipeline(botCfg, log, marketMgr, scanner, ethClient)
pipeline.AddDefaultStages()
// Process transactions through the pipeline
ctx := context.Background()
blockNumber := uint64(12345)
timestamp := uint64(time.Now().Unix())
err = pipeline.ProcessTransactions(ctx, transactions, blockNumber, timestamp)
assert.NoError(t, err)
}
func TestConfigurationLoading(t *testing.T) {
// This test would normally load a real config file
// For now, we'll just test that the config package works
cfg := &config.Config{
Arbitrum: config.ArbitrumConfig{
RPCEndpoint: "https://arb1.arbitrum.io/rpc",
ChainID: 42161,
},
Bot: config.BotConfig{
Enabled: true,
},
Uniswap: config.UniswapConfig{
FactoryAddress: "0x1F98431c8aD98523631AE4a59f267346ea31F984",
},
Log: config.LogConfig{
Level: "info",
},
Database: config.DatabaseConfig{
File: "mev-bot.db",
},
}
// Verify the config was created correctly
assert.Equal(t, "https://arb1.arbitrum.io/rpc", cfg.Arbitrum.RPCEndpoint)
assert.Equal(t, int64(42161), cfg.Arbitrum.ChainID)
assert.True(t, cfg.Bot.Enabled)
assert.Equal(t, "0x1F98431c8aD98523631AE4a59f267346ea31F984", cfg.Uniswap.FactoryAddress)
assert.Equal(t, "info", cfg.Log.Level)
assert.Equal(t, "mev-bot.db", cfg.Database.File)
}