refactor: move all remaining files to orig/ directory
Completed clean root directory structure: - Root now contains only: .git, .env, docs/, orig/ - Moved all remaining files and directories to orig/: - Config files (.claude, .dockerignore, .drone.yml, etc.) - All .env variants (except active .env) - Git config (.gitconfig, .github, .gitignore, etc.) - Tool configs (.golangci.yml, .revive.toml, etc.) - Documentation (*.md files, @prompts) - Build files (Dockerfiles, Makefile, go.mod, go.sum) - Docker compose files - All source directories (scripts, tests, tools, etc.) - Runtime directories (logs, monitoring, reports) - Dependency files (node_modules, lib, cache) - Special files (--delete) - Removed empty runtime directories (bin/, data/) V2 structure is now clean: - docs/planning/ - V2 planning documents - orig/ - Complete V1 codebase preserved - .env - Active environment config (not in git) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
138
orig/test/profit_calc_test.go
Normal file
138
orig/test/profit_calc_test.go
Normal file
@@ -0,0 +1,138 @@
|
||||
//go:build integration && legacy && forked
|
||||
// +build integration,legacy,forked
|
||||
|
||||
package test_main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
||||
"github.com/fraktal/mev-beta/internal/logger"
|
||||
"github.com/fraktal/mev-beta/pkg/profitcalc"
|
||||
)
|
||||
|
||||
func TestSimpleProfitCalculator(t *testing.T) {
|
||||
// Create a test logger
|
||||
log := logger.New("debug", "text", "")
|
||||
|
||||
// Create profit calculator
|
||||
calc := profitcalc.NewProfitCalculator(log)
|
||||
|
||||
// Test tokens (WETH and USDC on Arbitrum)
|
||||
wethAddr := common.HexToAddress("0x82af49447d8a07e3bd95bd0d56f35241523fbab1")
|
||||
usdcAddr := common.HexToAddress("0xaf88d065e77c8cc2239327c5edb3a432268e5831")
|
||||
|
||||
// Test case: 1 ETH -> 2000 USDC swap
|
||||
amountIn := big.NewFloat(1.0) // 1 ETH
|
||||
amountOut := big.NewFloat(2000.0) // 2000 USDC
|
||||
|
||||
// Analyze the opportunity
|
||||
opportunity := calc.AnalyzeSwapOpportunity(
|
||||
context.Background(),
|
||||
wethAddr,
|
||||
usdcAddr,
|
||||
amountIn,
|
||||
amountOut,
|
||||
"UniswapV3",
|
||||
)
|
||||
|
||||
// Verify opportunity was created
|
||||
if opportunity == nil {
|
||||
t.Fatal("Expected opportunity to be created, got nil")
|
||||
}
|
||||
|
||||
// Verify basic fields
|
||||
if opportunity.TokenA != wethAddr {
|
||||
t.Errorf("Expected TokenA to be WETH, got %s", opportunity.TokenA.Hex())
|
||||
}
|
||||
|
||||
if opportunity.TokenB != usdcAddr {
|
||||
t.Errorf("Expected TokenB to be USDC, got %s", opportunity.TokenB.Hex())
|
||||
}
|
||||
|
||||
// Verify amounts
|
||||
if opportunity.AmountIn.Cmp(amountIn) != 0 {
|
||||
t.Errorf("Expected AmountIn to be %s, got %s", amountIn.String(), opportunity.AmountIn.String())
|
||||
}
|
||||
|
||||
if opportunity.AmountOut.Cmp(amountOut) != 0 {
|
||||
t.Errorf("Expected AmountOut to be %s, got %s", amountOut.String(), opportunity.AmountOut.String())
|
||||
}
|
||||
|
||||
// Verify profit calculations exist
|
||||
if opportunity.EstimatedProfit == nil {
|
||||
t.Error("Expected EstimatedProfit to be calculated")
|
||||
}
|
||||
|
||||
if opportunity.GasCost == nil {
|
||||
t.Error("Expected GasCost to be calculated")
|
||||
}
|
||||
|
||||
if opportunity.NetProfit == nil {
|
||||
t.Error("Expected NetProfit to be calculated")
|
||||
}
|
||||
|
||||
// Verify profit margin is calculated
|
||||
if opportunity.ProfitMargin == 0 {
|
||||
t.Error("Expected ProfitMargin to be calculated")
|
||||
}
|
||||
|
||||
// Verify confidence score
|
||||
if opportunity.Confidence < 0 || opportunity.Confidence > 1 {
|
||||
t.Errorf("Expected Confidence to be between 0 and 1, got %f", opportunity.Confidence)
|
||||
}
|
||||
|
||||
// Log results for manual verification
|
||||
t.Logf("Opportunity Analysis:")
|
||||
t.Logf(" ID: %s", opportunity.ID)
|
||||
t.Logf(" AmountIn: %s ETH", opportunity.AmountIn.String())
|
||||
t.Logf(" AmountOut: %s tokens", opportunity.AmountOut.String())
|
||||
t.Logf(" EstimatedProfit: %s ETH", calc.FormatEther(opportunity.EstimatedProfit))
|
||||
t.Logf(" GasCost: %s ETH", calc.FormatEther(opportunity.GasCost))
|
||||
t.Logf(" NetProfit: %s ETH", calc.FormatEther(opportunity.NetProfit))
|
||||
t.Logf(" ProfitMargin: %.4f%%", opportunity.ProfitMargin*100)
|
||||
t.Logf(" IsExecutable: %t", opportunity.IsExecutable)
|
||||
t.Logf(" RejectReason: %s", opportunity.RejectReason)
|
||||
t.Logf(" Confidence: %.2f", opportunity.Confidence)
|
||||
}
|
||||
|
||||
func TestSimpleProfitCalculatorSmallTrade(t *testing.T) {
|
||||
// Create a test logger
|
||||
log := logger.New("debug", "text", "")
|
||||
|
||||
// Create profit calculator
|
||||
calc := profitcalc.NewProfitCalculator(log)
|
||||
|
||||
// Test tokens
|
||||
tokenA := common.HexToAddress("0x1111111111111111111111111111111111111111")
|
||||
tokenB := common.HexToAddress("0x2222222222222222222222222222222222222222")
|
||||
|
||||
// Test case: Small trade that should be unprofitable after gas
|
||||
amountIn := big.NewFloat(0.01) // 0.01 ETH
|
||||
amountOut := big.NewFloat(20.0) // 20 tokens
|
||||
|
||||
// Analyze the opportunity
|
||||
opportunity := calc.AnalyzeSwapOpportunity(
|
||||
context.Background(),
|
||||
tokenA,
|
||||
tokenB,
|
||||
amountIn,
|
||||
amountOut,
|
||||
"UniswapV2",
|
||||
)
|
||||
|
||||
// Verify opportunity was created
|
||||
if opportunity == nil {
|
||||
t.Fatal("Expected opportunity to be created, got nil")
|
||||
}
|
||||
|
||||
// Small trades should likely be unprofitable due to gas costs
|
||||
t.Logf("Small Trade Analysis:")
|
||||
t.Logf(" NetProfit: %s ETH", calc.FormatEther(opportunity.NetProfit))
|
||||
t.Logf(" IsExecutable: %t", opportunity.IsExecutable)
|
||||
t.Logf(" RejectReason: %s", opportunity.RejectReason)
|
||||
t.Logf(" Confidence: %.2f", opportunity.Confidence)
|
||||
}
|
||||
Reference in New Issue
Block a user