From 1895be0ead42d5db3dff0ea7fd51df0e34c27b84 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Thu, 28 Sep 2023 14:19:37 -0500 Subject: [PATCH] pool: Use mock upgrade path in tests. This modifies the tests for client upgrades to used mock test data instead of relying on the existence of specific models of ASICs which no longer exist. --- pool/client_test.go | 53 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/pool/client_test.go b/pool/client_test.go index 6b9b5c5d..a6a0091e 100644 --- a/pool/client_test.go +++ b/pool/client_test.go @@ -1543,26 +1543,63 @@ func testClientTimeRolledWork(t *testing.T) { } func testClientUpgrades(t *testing.T) { + // Create mock upgrade path for CPU mining. + const clientCPU2 = CPU + "2" + activeNet := config.ActiveNet + mockPoolDiffs := func() map[string]*DifficultyInfo { + const maxGenTime = time.Millisecond * 500 + genTime := new(big.Int).SetInt64(int64(maxGenTime.Seconds())) + return map[string]*DifficultyInfo{ + CPU: func() *DifficultyInfo { + hashRate := minerHashes[CPU] + target, diff := calculatePoolTarget(activeNet, hashRate, genTime) + return &DifficultyInfo{ + target: target, + difficulty: diff, + powLimit: new(big.Rat).SetInt(activeNet.PowLimit), + } + }(), + clientCPU2: func() *DifficultyInfo { + hashRate := new(big.Int).Mul(minerHashes[CPU], big.NewInt(2)) + target, diff := calculatePoolTarget(activeNet, hashRate, genTime) + return &DifficultyInfo{ + target: target, + difficulty: diff, + powLimit: new(big.Rat).SetInt(activeNet.PowLimit), + } + }(), + } + }() + fetchMinerDifficulty := func(miner string) (*DifficultyInfo, error) { + diffData, ok := mockPoolDiffs[miner] + if !ok { + desc := fmt.Sprintf("no difficulty data found for miner %s", miner) + return nil, errs.PoolError(errs.ValueNotFound, desc) + } + return diffData, nil + } + ctx := context.Background() cfg := *config cfg.RollWorkCycle = time.Minute * 5 // Avoiding rolled work for this test. cfg.MaxUpgradeTries = 2 cfg.MonitorCycle = time.Millisecond * 100 cfg.ClientTimeout = time.Millisecond * 300 + cfg.FetchMinerDifficulty = fetchMinerDifficulty _, ln, client, _, _, err := setup(ctx, &cfg) if err != nil { ln.Close() t.Fatalf("[setup] unexpected error: %v", err) } - err = setMiner(client, AntminerDR3) + err = setMiner(client, CPU) if err != nil { ln.Close() t.Fatalf("unexpected set miner error: %v", err) } - minerIdx := 0 - idPair := minerIDs[dr3ID] + const minerIdx = 0 + idPair := newMinerIDPair(cpuID, CPU, clientCPU2) // Trigger a client upgrade. atomic.StoreInt64(&client.submissions, 50) @@ -1570,9 +1607,9 @@ func testClientUpgrades(t *testing.T) { go client.monitor(minerIdx, idPair, cfg.MonitorCycle, cfg.MaxUpgradeTries) time.Sleep(cfg.MonitorCycle + (cfg.MonitorCycle / 2)) - if fetchMiner(client) != AntminerDR5 { + if fetchMiner(client) != clientCPU2 { ln.Close() - t.Fatalf("expected a miner id of %s, got %s", AntminerDR5, client.miner) + t.Fatalf("expected a miner id of %s, got %s", clientCPU2, client.miner) } client.cancel() @@ -1588,7 +1625,7 @@ func testClientUpgrades(t *testing.T) { defer ln.Close() - err = setMiner(client, AntminerDR3) + err = setMiner(client, CPU) if err != nil { t.Fatalf("unexpected set miner error: %v", err) } @@ -1598,8 +1635,8 @@ func testClientUpgrades(t *testing.T) { go client.monitor(minerIdx, idPair, cfg.MonitorCycle, cfg.MaxUpgradeTries) time.Sleep(cfg.MonitorCycle + (cfg.MonitorCycle / 2)) - if fetchMiner(client) == AntminerDR3 { - t.Fatalf("expected a miner of %s, got %s", AntminerDR3, client.miner) + if fetchMiner(client) == CPU { + t.Fatalf("expected a miner of %s, got %s", CPU, client.miner) } // Trigger a client timeout by waiting.