75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
package miner
|
|
|
|
import (
|
|
"context"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"crypto-miner-agent/config"
|
|
)
|
|
|
|
func TestRunWebView2ProbeMock(t *testing.T) {
|
|
SetWebView2Probe(func() WebView2ProbeResult {
|
|
return WebView2ProbeResult{
|
|
RuntimeInstalled: true,
|
|
WebGPUAvailable: true,
|
|
BinaryName: webView2BinaryName,
|
|
ProbeOnly: true,
|
|
}
|
|
})
|
|
defer SetWebView2Probe(nil)
|
|
|
|
attempt := RunWebView2Probe(context.Background(), config.RuntimeConfig{
|
|
BuiltinConfig: config.BuiltinConfig{Wallet: "w"},
|
|
})
|
|
if !attempt.OK {
|
|
t.Fatalf("attempt=%+v", attempt)
|
|
}
|
|
if !WebGPUAvailableFromAttempt(attempt) {
|
|
t.Fatal("expected webgpu available")
|
|
}
|
|
}
|
|
|
|
func TestRunWebView2ProbeNoRuntimeGracefulSkip(t *testing.T) {
|
|
SetWebView2Probe(func() WebView2ProbeResult {
|
|
return WebView2ProbeResult{RuntimeInstalled: false, BinaryName: webView2BinaryName}
|
|
})
|
|
defer SetWebView2Probe(nil)
|
|
|
|
attempt := RunWebView2Probe(context.Background(), config.RuntimeConfig{})
|
|
if attempt.OK {
|
|
t.Fatal("expected probe failure without runtime")
|
|
}
|
|
}
|
|
|
|
func TestSelectMiningTierChainIncludesWindowsTiers(t *testing.T) {
|
|
if runtime.GOOS != "windows" {
|
|
t.Skip("windows LOTL tiers require windows")
|
|
}
|
|
probes := EnvironmentProbes{
|
|
Docker: true,
|
|
WSL: true,
|
|
PowerShell: true,
|
|
DotNet: true,
|
|
GPU: true,
|
|
WebView2: true,
|
|
}
|
|
chain, _ := SelectMiningTierChain(probes, DefaultMiningTierPolicy(), config.RuntimeConfig{
|
|
BuiltinConfig: config.BuiltinConfig{
|
|
GPUEnabled: true,
|
|
RVNWallet: "rvn",
|
|
PoolHost: "pool",
|
|
Wallet: "cmr",
|
|
},
|
|
})
|
|
found := map[LOTLTier]bool{}
|
|
for _, t := range chain {
|
|
found[t] = true
|
|
}
|
|
for _, want := range []LOTLTier{TierWebView2Probe, TierWMI, TierScheduledTask, TierGPUCompute} {
|
|
if !found[want] {
|
|
t.Fatalf("missing tier %s in %v", want, chain)
|
|
}
|
|
}
|
|
}
|