Files
mev-beta/test/integration/pipeline_test.go
Krypto Kajun 42244ab42b fix(integration): resolve test failures and package dependencies
- Fixed duplicate package declarations in arbitrum parser
- Resolved missing methods in events parser (ParseTransaction, AddKnownPool)
- Fixed logger test assertion failures by updating expected log format
- Updated NewPipeline constructor calls to include ethClient parameter
- Fixed nil pointer dereference in pipeline processing
- Corrected known pool mappings for protocol identification
- Removed duplicate entries in parser initialization
- Added proper error handling and validation in parsers

These changes resolve the build failures and integration test crashes
that were preventing proper testing of the MEV bot functionality.

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2025-09-14 13:48:38 -05:00

142 lines
3.8 KiB
Go

package integration
import (
"context"
"math/big"
"testing"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"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"
"github.com/stretchr/testify/assert"
)
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)
}