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:
Administrator
2025-11-10 10:53:05 +01:00
parent 803de231ba
commit c54c569f30
718 changed files with 8304 additions and 8281 deletions

View File

@@ -0,0 +1,218 @@
package test
import (
"fmt"
"strings"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/fraktal/mev-beta/internal/validation"
)
// TestValidationFixForKnownAddresses tests the validation fixes against the specific addresses causing errors in production
func TestValidationFixForKnownAddresses(t *testing.T) {
validator := validation.NewAddressValidator()
// Test the specific addresses that were causing "Error getting pool data" logs
testCases := []struct {
name string
address string
expectERC20 bool
expectValidPool bool
expectValidation bool
description string
}{
{
name: "WETH - should be recognized as ERC-20",
address: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
expectERC20: true,
expectValidPool: false,
expectValidation: true,
description: "WETH was being treated as a pool causing slot0 errors",
},
{
name: "USDC - should be recognized as ERC-20",
address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
expectERC20: true,
expectValidPool: false,
expectValidation: true,
description: "USDC was being treated as a pool causing execution reverts",
},
{
name: "USDT - should be recognized as ERC-20",
address: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
expectERC20: true,
expectValidPool: false,
expectValidation: true,
description: "USDT was being treated as a pool causing execution reverts",
},
{
name: "ARB Token - should be recognized as ERC-20",
address: "0x912CE59144191C1204E64559FE8253a0e49E6548",
expectERC20: true,
expectValidPool: false,
expectValidation: true,
description: "ARB token was being treated as a pool",
},
{
name: "Zero address - should be rejected",
address: "0x0000000000000000000000000000000000000000",
expectERC20: false,
expectValidPool: false,
expectValidation: false,
description: "Zero address corruption causing massive log spam",
},
{
name: "Corrupted address pattern 1",
address: "0x0000000000000000000000000000001202a5e794",
expectERC20: false,
expectValidPool: false,
expectValidation: false,
description: "Leading zeros corruption pattern",
},
{
name: "Corrupted address pattern 2",
address: "0x00000003000000000000000000000000003528C0",
expectERC20: false,
expectValidPool: false,
expectValidation: false,
description: "Mixed zero corruption pattern",
},
}
fmt.Println("🧪 Testing Validation Fixes for Production Error Addresses")
fmt.Println(strings.Repeat("=", 80))
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
addr := common.HexToAddress(tc.address)
// Test basic validation
result := validator.ValidateAddress(tc.address)
// Test pool operation validation
poolOpErr := validator.ValidatePoolOperation(addr, "slot0")
// Test detailed analysis
analysis := validator.GetDetailedAddressAnalysis(addr)
fmt.Printf("\n🔍 Testing: %s\n", tc.name)
fmt.Printf(" Address: %s\n", tc.address)
fmt.Printf(" Description: %s\n", tc.description)
fmt.Printf(" Valid: %v (Expected: %v)\n", result.IsValid, tc.expectValidation)
fmt.Printf(" Corruption Score: %d\n", result.CorruptionScore)
fmt.Printf(" Contract Type: %s\n", result.ContractType.String())
if isERC20, ok := analysis["is_known_erc20"].(bool); ok {
fmt.Printf(" Known ERC-20: %v (Expected: %v)\n", isERC20, tc.expectERC20)
if isERC20 != tc.expectERC20 {
t.Errorf("ERC-20 recognition failed: expected %v, got %v", tc.expectERC20, isERC20)
}
}
if tokenName, ok := analysis["token_name"].(string); ok && tc.expectERC20 {
fmt.Printf(" Token Name: %s\n", tokenName)
}
// Test pool operation validation
if tc.expectERC20 {
if poolOpErr == nil {
t.Errorf("Expected pool operation to be rejected for ERC-20 token %s", tc.address)
fmt.Printf(" ❌ Pool Operation: Should have been rejected but was allowed\n")
} else {
fmt.Printf(" ✅ Pool Operation: Correctly rejected - %s\n", poolOpErr.Error())
}
} else if tc.expectValidation {
if poolOpErr != nil {
fmt.Printf(" Pool Operation: Rejected - %s\n", poolOpErr.Error())
} else {
fmt.Printf(" ✅ Pool Operation: Allowed for valid pool\n")
}
} else {
if poolOpErr != nil {
fmt.Printf(" ✅ Pool Operation: Correctly rejected for invalid address\n")
} else {
t.Errorf("Expected pool operation to be rejected for invalid address %s", tc.address)
}
}
// Verify corruption pattern detection
if corruptionPattern, ok := analysis["corruption_pattern"].(string); ok {
fmt.Printf(" Corruption Pattern: %s\n", corruptionPattern)
}
// Verify basic validation expectation
if result.IsValid != tc.expectValidation {
t.Errorf("Validation result mismatch for %s: expected %v, got %v",
tc.address, tc.expectValidation, result.IsValid)
}
})
}
fmt.Println("\n" + strings.Repeat("=", 80))
fmt.Println("🎯 Validation Fix Test Summary:")
fmt.Println(" - Major ERC-20 tokens (WETH, USDC, USDT, ARB) should be recognized")
fmt.Println(" - Pool operations on ERC-20 tokens should be prevented")
fmt.Println(" - Corrupted addresses should be properly detected and rejected")
fmt.Println(" - This should eliminate the 535K+ log spam from production")
}
// TestCorruptionSourceAnalysis tests the system's ability to identify corruption sources
func TestCorruptionSourceAnalysis(t *testing.T) {
validator := validation.NewAddressValidator()
// Test various corruption patterns found in the logs
corruptionCases := []struct {
corrupted string
pattern string
description string
}{
{
corrupted: "0x0000000000000000000000000000000000000000",
pattern: "ZERO_ADDRESS",
description: "Complete zero address - most common corruption (6,895 occurrences)",
},
{
corrupted: "0x0000000000000000000000000000001202a5e794",
pattern: "LEADING_ZEROS_CORRUPTION",
description: "Leading zeros with trailing data - ABI decoding issue",
},
{
corrupted: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1weth",
pattern: "EMBEDDED_WETH_PATTERN",
description: "WETH address with embedded corruption",
},
}
fmt.Println("\n🔍 Testing Corruption Pattern Detection")
fmt.Println(strings.Repeat("=", 60))
for _, tc := range corruptionCases {
t.Run(tc.pattern, func(t *testing.T) {
// Note: This would require modifying the test to handle invalid hex
// For now, test with valid hex patterns
if len(tc.corrupted) == 42 && tc.corrupted[:2] == "0x" {
addr := common.HexToAddress(tc.corrupted)
analysis := validator.GetDetailedAddressAnalysis(addr)
fmt.Printf("\n Pattern: %s\n", tc.pattern)
fmt.Printf(" Address: %s\n", tc.corrupted)
fmt.Printf(" Description: %s\n", tc.description)
if detectedPattern, ok := analysis["corruption_pattern"].(string); ok {
fmt.Printf(" Detected: %s\n", detectedPattern)
if detectedPattern == tc.pattern {
fmt.Printf(" ✅ Correctly identified\n")
} else {
fmt.Printf(" ⚠️ Different pattern detected\n")
}
}
if corruptionScore, ok := analysis["corruption_score"].(int); ok {
fmt.Printf(" Corruption Score: %d\n", corruptionScore)
}
}
})
}
}