Update module name to github.com/fraktal/mev-beta and fix channel closing issues in pipeline stages
This commit is contained in:
152
test/integration/pipeline_test.go
Normal file
152
test/integration/pipeline_test.go
Normal file
@@ -0,0 +1,152 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"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/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"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)
|
||||
|
||||
// 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 config
|
||||
cfg := &config.BotConfig{
|
||||
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
|
||||
scnr := scanner.NewMarketScanner(cfg, 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)
|
||||
|
||||
// Use the variables to avoid unused variable warnings
|
||||
_ = scnr
|
||||
}
|
||||
|
||||
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)
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user