2026-04-04 10:29:02 +00:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
2026-04-05 07:02:54 +01:00
|
|
|
// TestCustomDiff_Apply_Good verifies a user suffix "+50000" sets customDiff and strips the suffix.
|
|
|
|
|
//
|
|
|
|
|
// cd := proxy.NewCustomDiff(10000)
|
|
|
|
|
// cd.Apply(&proxy.Miner{user: "WALLET+50000"})
|
|
|
|
|
// // miner.User() == "WALLET", miner.customDiff == 50000
|
|
|
|
|
func TestCustomDiff_Apply_Good(t *testing.T) {
|
2026-04-04 10:29:02 +00:00
|
|
|
cd := NewCustomDiff(10000)
|
|
|
|
|
miner := &Miner{user: "WALLET+50000"}
|
|
|
|
|
cd.OnLogin(Event{Miner: miner})
|
|
|
|
|
if miner.User() != "WALLET" {
|
|
|
|
|
t.Fatalf("expected stripped user, got %q", miner.User())
|
|
|
|
|
}
|
|
|
|
|
if miner.customDiff != 50000 {
|
|
|
|
|
t.Fatalf("expected custom diff 50000, got %d", miner.customDiff)
|
|
|
|
|
}
|
2026-04-05 07:02:54 +01:00
|
|
|
}
|
2026-04-04 10:29:02 +00:00
|
|
|
|
2026-04-05 07:02:54 +01:00
|
|
|
// TestCustomDiff_Apply_Bad verifies "+abc" (non-numeric) leaves user unchanged, customDiff=0.
|
|
|
|
|
//
|
|
|
|
|
// cd := proxy.NewCustomDiff(10000)
|
|
|
|
|
// cd.Apply(&proxy.Miner{user: "WALLET+abc"})
|
|
|
|
|
// // miner.User() == "WALLET+abc", miner.customDiff == 0
|
|
|
|
|
func TestCustomDiff_Apply_Bad(t *testing.T) {
|
|
|
|
|
cd := NewCustomDiff(10000)
|
|
|
|
|
miner := &Miner{user: "WALLET+abc"}
|
2026-04-04 10:29:02 +00:00
|
|
|
cd.OnLogin(Event{Miner: miner})
|
|
|
|
|
if miner.User() != "WALLET+abc" {
|
2026-04-05 07:02:54 +01:00
|
|
|
t.Fatalf("expected invalid suffix to remain unchanged, got %q", miner.User())
|
2026-04-04 10:29:02 +00:00
|
|
|
}
|
2026-04-04 20:48:10 +00:00
|
|
|
if miner.customDiff != 0 {
|
|
|
|
|
t.Fatalf("expected invalid suffix to disable custom diff, got %d", miner.customDiff)
|
2026-04-04 10:29:02 +00:00
|
|
|
}
|
2026-04-05 07:02:54 +01:00
|
|
|
}
|
2026-04-04 10:29:02 +00:00
|
|
|
|
2026-04-05 07:02:54 +01:00
|
|
|
// TestCustomDiff_Apply_Ugly verifies globalDiff=10000 is used when no suffix is present.
|
|
|
|
|
//
|
|
|
|
|
// cd := proxy.NewCustomDiff(10000)
|
|
|
|
|
// cd.Apply(&proxy.Miner{user: "WALLET"})
|
|
|
|
|
// // miner.customDiff == 10000 (falls back to global)
|
|
|
|
|
func TestCustomDiff_Apply_Ugly(t *testing.T) {
|
|
|
|
|
cd := NewCustomDiff(10000)
|
|
|
|
|
miner := &Miner{user: "WALLET"}
|
2026-04-04 10:29:02 +00:00
|
|
|
cd.OnLogin(Event{Miner: miner})
|
|
|
|
|
if miner.customDiff != 10000 {
|
2026-04-05 07:02:54 +01:00
|
|
|
t.Fatalf("expected global diff fallback 10000, got %d", miner.customDiff)
|
2026-04-04 10:29:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
2026-04-05 00:32:43 +00:00
|
|
|
|
2026-04-05 07:02:54 +01:00
|
|
|
// TestCustomDiff_OnLogin_NonNumericSuffix verifies a non-decimal suffix after plus is ignored.
|
|
|
|
|
//
|
|
|
|
|
// cd := proxy.NewCustomDiff(10000)
|
|
|
|
|
// cd.OnLogin(proxy.Event{Miner: &proxy.Miner{user: "WALLET+50000extra"}})
|
|
|
|
|
func TestCustomDiff_OnLogin_NonNumericSuffix(t *testing.T) {
|
2026-04-05 02:31:37 +00:00
|
|
|
cd := NewCustomDiff(10000)
|
|
|
|
|
miner := &Miner{user: "WALLET+50000extra"}
|
|
|
|
|
|
|
|
|
|
cd.OnLogin(Event{Miner: miner})
|
|
|
|
|
|
|
|
|
|
if miner.User() != "WALLET+50000extra" {
|
2026-04-05 07:02:54 +01:00
|
|
|
t.Fatalf("expected non-numeric suffix plus segment to remain unchanged, got %q", miner.User())
|
2026-04-05 02:31:37 +00:00
|
|
|
}
|
|
|
|
|
if miner.customDiff != 0 {
|
|
|
|
|
t.Fatalf("expected invalid suffix to disable custom diff, got %d", miner.customDiff)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-05 07:02:54 +01:00
|
|
|
// TestEffectiveShareDifficulty_CustomDiffCapsPoolDifficulty verifies the cap applied by custom diff.
|
|
|
|
|
//
|
|
|
|
|
// job := proxy.Job{Target: "01000000"}
|
|
|
|
|
// miner := &proxy.Miner{customDiff: 25000}
|
|
|
|
|
// proxy.EffectiveShareDifficulty(job, miner) // 25000 (capped)
|
2026-04-05 00:32:43 +00:00
|
|
|
func TestEffectiveShareDifficulty_CustomDiffCapsPoolDifficulty(t *testing.T) {
|
2026-04-05 01:05:00 +00:00
|
|
|
job := Job{Target: "01000000"}
|
2026-04-05 00:32:43 +00:00
|
|
|
miner := &Miner{customDiff: 25000}
|
|
|
|
|
|
|
|
|
|
if got := EffectiveShareDifficulty(job, miner); got != 25000 {
|
|
|
|
|
t.Fatalf("expected capped difficulty 25000, got %d", got)
|
|
|
|
|
}
|
|
|
|
|
}
|