Restructured project for V2 refactor: **Structure Changes:** - Moved all V1 code to orig/ folder (preserved with git mv) - Created docs/planning/ directory - Added orig/README_V1.md explaining V1 preservation **Planning Documents:** - 00_V2_MASTER_PLAN.md: Complete architecture overview - Executive summary of critical V1 issues - High-level component architecture diagrams - 5-phase implementation roadmap - Success metrics and risk mitigation - 07_TASK_BREAKDOWN.md: Atomic task breakdown - 99+ hours of detailed tasks - Every task < 2 hours (atomic) - Clear dependencies and success criteria - Organized by implementation phase **V2 Key Improvements:** - Per-exchange parsers (factory pattern) - Multi-layer strict validation - Multi-index pool cache - Background validation pipeline - Comprehensive observability **Critical Issues Addressed:** - Zero address tokens (strict validation + cache enrichment) - Parsing accuracy (protocol-specific parsers) - No audit trail (background validation channel) - Inefficient lookups (multi-index cache) - Stats disconnection (event-driven metrics) Next Steps: 1. Review planning documents 2. Begin Phase 1: Foundation (P1-001 through P1-010) 3. Implement parsers in Phase 2 4. Build cache system in Phase 3 5. Add validation pipeline in Phase 4 6. Migrate and test in Phase 5 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
162 lines
3.1 KiB
Go
162 lines
3.1 KiB
Go
package arbitrage
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestParseSignedInt256(t *testing.T) {
|
|
sas := &ArbitrageService{}
|
|
|
|
tests := []struct {
|
|
name string
|
|
input []byte
|
|
expected string
|
|
}{
|
|
{
|
|
name: "positive value",
|
|
input: make([]byte, 32), // All zeros = 0
|
|
expected: "0",
|
|
},
|
|
{
|
|
name: "negative value",
|
|
input: func() []byte {
|
|
// Create a -1 value in two's complement (all 1s)
|
|
data := make([]byte, 32)
|
|
for i := range data {
|
|
data[i] = 0xFF
|
|
}
|
|
return data
|
|
}(),
|
|
expected: "-1",
|
|
},
|
|
{
|
|
name: "large positive value",
|
|
input: func() []byte {
|
|
data := make([]byte, 32)
|
|
data[31] = 0x01 // Small positive number
|
|
return data
|
|
}(),
|
|
expected: "1",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result, err := sas.parseSignedInt256(tt.input)
|
|
if err != nil {
|
|
t.Fatalf("parseSignedInt256() error = %v", err)
|
|
}
|
|
if result.String() != tt.expected {
|
|
t.Errorf("parseSignedInt256() = %v, want %v", result.String(), tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSignedInt24(t *testing.T) {
|
|
sas := &ArbitrageService{}
|
|
|
|
tests := []struct {
|
|
name string
|
|
input []byte
|
|
expected int32
|
|
}{
|
|
{
|
|
name: "zero value",
|
|
input: make([]byte, 32), // All zeros
|
|
expected: 0,
|
|
},
|
|
{
|
|
name: "positive value",
|
|
input: func() []byte {
|
|
data := make([]byte, 32)
|
|
data[31] = 0x01 // 1
|
|
return data
|
|
}(),
|
|
expected: 1,
|
|
},
|
|
{
|
|
name: "negative value (-1)",
|
|
input: func() []byte {
|
|
data := make([]byte, 32)
|
|
data[28] = 0xFF
|
|
// Set the 24-bit value to all 1s (which is -1 in two's complement)
|
|
data[29] = 0xFF
|
|
data[30] = 0xFF
|
|
data[31] = 0xFF
|
|
return data
|
|
}(),
|
|
expected: -1,
|
|
},
|
|
{
|
|
name: "max positive int24",
|
|
input: func() []byte {
|
|
data := make([]byte, 32)
|
|
// 0x7FFFFF = 8388607 (max int24)
|
|
data[29] = 0x7F
|
|
data[30] = 0xFF
|
|
data[31] = 0xFF
|
|
return data
|
|
}(),
|
|
expected: 8388607,
|
|
},
|
|
{
|
|
name: "min negative int24",
|
|
input: func() []byte {
|
|
data := make([]byte, 32)
|
|
data[28] = 0xFF
|
|
// 0x800000 = -8388608 (min int24)
|
|
data[29] = 0x80
|
|
data[30] = 0x00
|
|
data[31] = 0x00
|
|
return data
|
|
}(),
|
|
expected: -8388608,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result, err := sas.parseSignedInt24(tt.input)
|
|
if err != nil {
|
|
t.Fatalf("parseSignedInt24() error = %v", err)
|
|
}
|
|
if result != tt.expected {
|
|
t.Errorf("parseSignedInt24() = %v, want %v", result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSignedInt24Errors(t *testing.T) {
|
|
sas := &ArbitrageService{}
|
|
|
|
tests := []struct {
|
|
name string
|
|
input []byte
|
|
}{
|
|
{
|
|
name: "invalid length",
|
|
input: make([]byte, 16), // Wrong length
|
|
},
|
|
{
|
|
name: "out of range positive",
|
|
input: func() []byte {
|
|
data := make([]byte, 32)
|
|
// Set a value > 8388607
|
|
data[28] = 0x01 // This makes it > 24 bits
|
|
return data
|
|
}(),
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
_, err := sas.parseSignedInt24(tt.input)
|
|
if err == nil {
|
|
t.Errorf("parseSignedInt24() expected error but got none")
|
|
}
|
|
})
|
|
}
|
|
}
|