mirror of
https://github.com/luxfi/evm.git
synced 2026-09-24 00:27:44 +00:00
- GPU ecrecover bridge: 32x speedup (1613ms → ~50ms for 47K sigs) - Auto-detect Metal on darwin, no build tags required - Per-tx signer derivation (not per-batch) — fixes mixed-chainID bug - EIP-2 low-S enforcement before GPU submission - Zero-address rejection for GPU results - CacheSender stores pre-recovered senders, CPU fallback for misses - Merged parallel.go + default.go into single tag-free file
81 lines
2.2 KiB
Go
81 lines
2.2 KiB
Go
// Copyright (C) 2025-2026, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package parallel
|
|
|
|
import (
|
|
"runtime"
|
|
"testing"
|
|
|
|
"github.com/luxfi/geth/core/types"
|
|
"github.com/luxfi/geth/core/vm"
|
|
)
|
|
|
|
// TestDefaultExecutorReturnsNil verifies the default executor signals
|
|
// "not handled" by returning (nil, nil).
|
|
func TestDefaultExecutorReturnsNil(t *testing.T) {
|
|
exec := DefaultExecutor()
|
|
receipts, err := exec.ExecuteBlock(nil, nil, nil, nil, vm.Config{})
|
|
if err != nil {
|
|
t.Fatalf("DefaultExecutor returned error: %v", err)
|
|
}
|
|
if receipts != nil {
|
|
t.Fatalf("DefaultExecutor returned non-nil receipts: %v", receipts)
|
|
}
|
|
}
|
|
|
|
// TestGPUAutoDetect verifies GPU is auto-detected on darwin (Metal)
|
|
// and reports unavailable on other platforms.
|
|
func TestGPUAutoDetect(t *testing.T) {
|
|
gpu := DefaultGPU()
|
|
if runtime.GOOS == "darwin" {
|
|
// On macOS with CGo, the Metal GPU bridge should be registered
|
|
t.Logf("GPU available: %v (expected true on darwin with Metal)", gpu.Available())
|
|
} else {
|
|
if gpu.Available() {
|
|
t.Fatal("GPU should not be available on non-darwin")
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestGPUBatchEcrecover verifies batch ecrecover handles empty/nil inputs.
|
|
func TestGPUBatchEcrecover(t *testing.T) {
|
|
gpu := DefaultGPU()
|
|
|
|
// Nil input
|
|
result, err := gpu.BatchEcrecover(nil)
|
|
if err != nil {
|
|
t.Fatalf("nil input returned error: %v", err)
|
|
}
|
|
if result != nil {
|
|
t.Fatalf("nil input returned non-nil result: %v", result)
|
|
}
|
|
|
|
// Empty input
|
|
result, err = gpu.BatchEcrecover([]*types.Transaction{})
|
|
if err != nil {
|
|
t.Fatalf("empty input returned error: %v", err)
|
|
}
|
|
if result != nil {
|
|
t.Fatalf("empty input returned non-nil result: %v", result)
|
|
}
|
|
}
|
|
|
|
// TestGPUBatchKeccakReturnsNil verifies batch keccak returns nil (not yet wired).
|
|
func TestGPUBatchKeccakReturnsNil(t *testing.T) {
|
|
gpu := DefaultGPU()
|
|
result, err := gpu.BatchKeccak([][]byte{{0x01, 0x02}})
|
|
if err != nil {
|
|
t.Fatalf("BatchKeccak returned error: %v", err)
|
|
}
|
|
if result != nil {
|
|
t.Fatalf("BatchKeccak returned non-nil result: %v", result)
|
|
}
|
|
}
|
|
|
|
// TestInterfaceCompliance verifies the types satisfy interfaces at runtime.
|
|
func TestInterfaceCompliance(t *testing.T) {
|
|
var _ BlockExecutor = DefaultExecutor()
|
|
var _ GPUAccelerator = DefaultGPU()
|
|
}
|