Skip to content

Commit

Permalink
squashme
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaytonNorthey92 committed May 1, 2024
1 parent 14cb377 commit ed73b3e
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 7 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/localnet-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ jobs:

- name: "get localnet stats"
env:
# give the tests 5 minutes to run
HEMI_E2E_DUMP_JSON_AFTER_MS: '300000'
working-directory: ./e2e/monitor
# assert that:
# - we have at least 8 pop txs
run: |
[[ $(go run ./... | jq '.["pop_tx_count"]') -gt 8 ]] && echo 'passing' || exit 1
go test ./...
20 changes: 14 additions & 6 deletions e2e/monitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

const (
dataRefreshSeconds = 5
dataRefreshSeconds = 1
tableRefreshSeconds = 1
)

Expand All @@ -34,6 +34,11 @@ type state struct {
}

func main() {
output := monitor(dumpJsonAfterMsFromEnv())
fmt.Println(output)
}

func monitor(dumpJsonAfterMs uint) string {
s := state{
bitcoinBlockCount: 0,
}
Expand All @@ -48,25 +53,28 @@ func main() {
go monitorPopTxs(ctx, &s, &mtx)
go monitorRolledUpTxs(ctx, &s, &mtx)

if dumpJsonAfterMs() == 0 {
if dumpJsonAfterMs == 0 {
go render(ctx, &s, t, &mtx)
}

if dumpJsonAfterMs() > 0 {
if dumpJsonAfterMs > 0 {
select {
case <-time.After(time.Duration(dumpJsonAfterMs()) * time.Millisecond):
case <-time.After(time.Duration(dumpJsonAfterMs) * time.Millisecond):
output := dumpJson(&mtx, &s)
fmt.Println(output)
return output
case <-ctx.Done():
}
} else {
for {
select {
case <-ctx.Done():
return ""
default:
}
}
}

return ""
}

type jsonOutput struct {
Expand Down Expand Up @@ -316,7 +324,7 @@ func monitorRolledUpTxs(ctx context.Context, s *state, mtx *sync.Mutex) {

}

func dumpJsonAfterMs() uint {
func dumpJsonAfterMsFromEnv() uint {
val := os.Getenv("HEMI_E2E_DUMP_JSON_AFTER_MS")
if val == "" {
return 0
Expand Down
47 changes: 47 additions & 0 deletions e2e/monitor/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

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

"github.com/hemilabs/heminetwork/hemi"
)

func Test_Monitor(t *testing.T) {
ms := 1000 * 60 * 5 // dump after 5 minutes
seconds := ms / 1000

output := monitor(uint(ms))

var jo jsonOutput

if err := json.Unmarshal([]byte(output), &jo); err != nil {
t.Fatal(err)
}

popTxsPer100Seconds := 4
expectedPopTxs := popTxsPer100Seconds * (seconds / 100)

t.Logf("expecting at least %d pop txs mined", expectedPopTxs)

if jo.PopTxCount < uint64(expectedPopTxs) {
t.Fatalf("popTxCount %d < %d", jo.PopTxCount, expectedPopTxs)
}

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 %d < %d", expectedPayoutBalance, balance)
}
}

0 comments on commit ed73b3e

Please sign in to comment.