Files
mev-beta/test/integration/pipeline_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

146 lines
3.9 KiB
Go

//go:build integration && legacy
// +build integration,legacy
package integration_test
import (
"context"
"math/big"
"testing"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/assert"
"github.com/fraktal/mev-beta/internal/config"
"github.com/fraktal/mev-beta/internal/logger"
"github.com/fraktal/mev-beta/pkg/events"
"github.com/fraktal/mev-beta/pkg/market"
"github.com/fraktal/mev-beta/pkg/scanner"
)
func TestPipelineIntegration(t *testing.T) {
// Create test config
cfg := &config.BotConfig{
MaxWorkers: 2,
ChannelBufferSize: 5,
MinProfitThreshold: 10.0,
}
// Create test logger
logger := logger.New("info", "text", "")
// Create market manager
marketMgr := market.NewMarketManager(&config.UniswapConfig{
Cache: config.CacheConfig{
Expiration: 300,
MaxSize: 10000,
},
}, logger)
// Create market scanner
scanner := scanner.NewMarketScanner(cfg, logger)
// Create pipeline
pipeline := market.NewPipeline(cfg, logger, marketMgr, scanner, nil)
// Add default stages
pipeline.AddDefaultStages()
// 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)
// Process transactions through the pipeline
ctx := context.Background()
blockNumber := uint64(12345)
timestamp := uint64(time.Now().Unix())
err := pipeline.ProcessTransactions(ctx, transactions, blockNumber, timestamp)
// Verify no error
assert.NoError(t, err)
}
func TestMarketManagerAndScannerIntegration(t *testing.T) {
// Create test logger
logger := logger.New("info", "text", "")
// Create market manager
marketMgr := market.NewMarketManager(&config.UniswapConfig{
Cache: config.CacheConfig{
Expiration: 300,
MaxSize: 10000,
},
}, logger)
// Get a pool from the market manager
ctx := context.Background()
poolAddress := common.HexToAddress("0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640")
pool, err := marketMgr.GetPool(ctx, poolAddress)
// Verify no error and pool is not nil
assert.NoError(t, err)
assert.NotNil(t, pool)
// Get pools by tokens
token0 := common.HexToAddress("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48") // USDC
token1 := common.HexToAddress("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2") // WETH
pools := marketMgr.GetPoolsByTokens(token0, token1)
// Verify pools are returned
assert.NotNil(t, pools)
}
func TestEventParserAndPipelineIntegration(t *testing.T) {
// Create test config
cfg := &config.BotConfig{
MaxWorkers: 2,
ChannelBufferSize: 5,
}
// Create test logger
logger := logger.New("info", "text", "")
// Create market manager
marketMgr := market.NewMarketManager(&config.UniswapConfig{
Cache: config.CacheConfig{
Expiration: 300,
MaxSize: 10000,
},
}, logger)
// Create market scanner
scnr := scanner.NewMarketScanner(cfg, logger)
// Create pipeline
pipe := market.NewPipeline(cfg, logger, marketMgr, scnr, nil)
pipe.AddDefaultStages()
// Create event parser
parser := events.NewEventParser()
// 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)
blockNumber := uint64(12345)
timestamp := uint64(time.Now().Unix())
// Parse the transaction
parsedEvents, err := parser.ParseTransaction(tx, blockNumber, timestamp)
assert.NoError(t, err)
assert.Len(t, parsedEvents, 1)
// Verify the parsed event
event := parsedEvents[0]
assert.Equal(t, events.Swap, event.Type)
assert.Equal(t, "UniswapV3", event.Protocol)
assert.Equal(t, to, event.PoolAddress)
assert.Equal(t, blockNumber, event.BlockNumber)
assert.Equal(t, timestamp, event.Timestamp)
}