Skip to content

Commit

Permalink
squashme
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaytonNorthey92 committed Oct 24, 2024
1 parent a83ce31 commit 5edc7c2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 57 deletions.
1 change: 1 addition & 0 deletions e2e/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
95 changes: 38 additions & 57 deletions e2e/monitor/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ package main

import (
"encoding/json"
"fmt"
"math/big"
"testing"
"time"

"github.com/hemilabs/heminetwork/hemi"
)
Expand All @@ -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)
}
}

0 comments on commit 5edc7c2

Please sign in to comment.