Files
mev-beta/pkg/arbitrage/swap_parser_test.go
Krypto Kajun 850223a953 fix(multicall): resolve critical multicall parsing corruption issues
- Added comprehensive bounds checking to prevent buffer overruns in multicall parsing
- Implemented graduated validation system (Strict/Moderate/Permissive) to reduce false positives
- Added LRU caching system for address validation with 10-minute TTL
- Enhanced ABI decoder with missing Universal Router and Arbitrum-specific DEX signatures
- Fixed duplicate function declarations and import conflicts across multiple files
- Added error recovery mechanisms with multiple fallback strategies
- Updated tests to handle new validation behavior for suspicious addresses
- Fixed parser test expectations for improved validation system
- Applied gofmt formatting fixes to ensure code style compliance
- Fixed mutex copying issues in monitoring package by introducing MetricsSnapshot
- Resolved critical security vulnerabilities in heuristic address extraction
- Progress: Updated TODO audit from 10% to 35% complete

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-17 00:12:55 -05:00

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")
}
})
}
}