From 5edc7c2e837446fe9d0abefa1453b6198d2cce1e Mon Sep 17 00:00:00 2001 From: ClaytonNorthey92 Date: Thu, 24 Oct 2024 10:53:08 -0400 Subject: [PATCH] squashme --- e2e/docker-compose.yml | 1 + e2e/monitor/main_test.go | 95 ++++++++++++++++------------------------ 2 files changed, 39 insertions(+), 57 deletions(-) diff --git a/e2e/docker-compose.yml b/e2e/docker-compose.yml index 587bb8e1..89979319 100644 --- a/e2e/docker-compose.yml +++ b/e2e/docker-compose.yml @@ -15,6 +15,7 @@ services: - "-rpcallowip=0.0.0.0/0" - "-rpcbind=0.0.0.0:18443" - "-txindex=1" + - "-rpcworkqueue=400" ports: - "18443:18443" - "18444:18444" diff --git a/e2e/monitor/main_test.go b/e2e/monitor/main_test.go index d602bc48..41ac5783 100644 --- a/e2e/monitor/main_test.go +++ b/e2e/monitor/main_test.go @@ -6,9 +6,9 @@ package main import ( "encoding/json" - "fmt" "math/big" "testing" + "time" "github.com/hemilabs/heminetwork/hemi" ) @@ -17,76 +17,57 @@ import ( // after 5 minutes and check that it has progressed at least to a certain // point func TestMonitor(t *testing.T) { - ms := (1000 * 60 * 5) + 25*1000 // dump after 5 minutes + 25 seconds for cushion (1 keystone) - output := monitor(uint(ms)) - - t.Log(output) + time.Sleep(2 * time.Minute) var jo jsonOutput - if err := json.Unmarshal([]byte(output), &jo); err != nil { - t.Fatal(err) - } - - // each keystone is 25 seconds, so there are 4 keystones per 100 seconds, - // we expect the number of pop txs to be at least once every 25 seconds - // for the time we waited - // add 25 seconds for cushion - seconds := ms / 1000 - popTxsPer100Seconds := 4 - expectedPopTxs := popTxsPer100Seconds * (seconds / 100) - - t.Logf("expecting at least %d pop txs mined", expectedPopTxs) - - const maxRetries = 5 - const retryAfterSeconds = 30 - var lastErr error - - for i := range maxRetries { - lastErr = nil - - t.Logf("retry %d/%d, lastErr = %v", i, maxRetries, lastErr) - - if i != 0 { - output := monitor(uint(retryAfterSeconds * 1000)) - t.Log(output) + blockWaitTimeoutTimer := time.NewTimer(10 * time.Minute) + for jo.BitcoinBlockCount < 1012 { - if err := json.Unmarshal([]byte(output), &jo); err != nil { - t.Fatal(err) - } + select { + case <-blockWaitTimeoutTimer.C: + t.Fatalf("timed out waiting for btc blocks") + case <-time.After(10 * time.Second): } - if jo.PopTxCount < uint64(expectedPopTxs) { - lastErr = fmt.Errorf("popTxCount %d < %d", jo.PopTxCount, expectedPopTxs) - continue - } + output := monitor(uint(10 * 1000)) + t.Log(output) - // the expected balance should be at least 1 BaseHEMI per poptx - 8. We say - // "- 8" because we lag 8 keystones behind a pop payout (200 L2 blocks at - // 1 block per second) - popMinerBalance := big.NewInt(0) - balance, ok := popMinerBalance.SetString(jo.PopMinerHemiBalance, 10) - if !ok { - lastErr = fmt.Errorf("could not parse balance from %s", jo.PopMinerHemiBalance) - continue + if err := json.Unmarshal([]byte(output), &jo); err != nil { + t.Fatal(err) } + } - expectedPayouts := expectedPopTxs - 8 - expectedPayoutBalance := big.NewInt(hemi.HEMIBase) - expectedPayoutBalance = expectedPayoutBalance.Mul(big.NewInt(int64(expectedPayouts)), expectedPayoutBalance) + output := monitor(uint(60 * 1000)) + t.Log(output) + if err := json.Unmarshal([]byte(output), &jo); err != nil { + t.Fatal(err) + } - t.Logf("expecting actual balance %d to be greater than %d", balance, expectedPayoutBalance) + expectedPopTxs := 12 - if expectedPayoutBalance.Cmp(balance) > 0 { - lastErr = fmt.Errorf("pop miner payout balance received %d, want at least %d", balance, expectedPayoutBalance) - continue - } + t.Logf("expecting at least %d pop txs mined", expectedPopTxs) - break + if jo.PopTxCount < uint64(expectedPopTxs) { + t.Fatalf("popTxCount %d < %d", jo.PopTxCount, expectedPopTxs) } - if lastErr != nil { - t.Fatal(lastErr) + // the expected balance should be at least 1 BaseHEMI per poptx - 8. We say + // "- 8" because we lag 8 keystones behind a pop payout (200 L2 blocks at + // 1 block per second) + popMinerBalance := big.NewInt(0) + balance, ok := popMinerBalance.SetString(jo.PopMinerHemiBalance, 10) + if !ok { + t.Fatalf("could not parse balance from %s", jo.PopMinerHemiBalance) } + expectedPayouts := expectedPopTxs - 8 + expectedPayoutBalance := big.NewInt(hemi.HEMIBase) + expectedPayoutBalance = expectedPayoutBalance.Mul(big.NewInt(int64(expectedPayouts)), expectedPayoutBalance) + + t.Logf("expecting actual balance %d to be greater than %d", balance, expectedPayoutBalance) + + if expectedPayoutBalance.Cmp(balance) > 0 { + t.Fatalf("pop miner payout balance received %d, want at least %d", balance, expectedPayoutBalance) + } }