Skip to content

Commit

Permalink
settings, test: reduce auto announce NDF
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Dec 6, 2023
1 parent e9641a5 commit 632d009
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 10 additions & 7 deletions host/settings/announce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,27 @@ func TestAutoAnnounce(t *testing.T) {
time.Sleep(time.Second)

// confirm the announcement
if err := node.MineBlocks(node.Address(), 2); err != nil {
if err := node.MineBlocks(node.Address(), 5); err != nil {
t.Fatal(err)
}
time.Sleep(time.Second)

lastAnnouncement, err := manager.LastAnnouncement()
if err != nil {
t.Fatal(err)
} else if lastAnnouncement.Index.Height != 101 {
t.Fatalf("expected height 100, got %v", lastAnnouncement.Index.Height)
} else if lastAnnouncement.Index.Height == 0 {
t.Fatalf("expected an announcement, got %v", lastAnnouncement.Index.Height)
} else if lastAnnouncement.Address != "foo.bar:1234" {
t.Fatal("announcement not updated")
}
lastHeight := lastAnnouncement.Index.Height

remainingBlocks := lastHeight + 100 - node.ChainManager().TipState().Index.Height
t.Log("remaining blocks:", remainingBlocks)

// mine until right before the next announcement to ensure that the
// announcement is not triggered early
if err := node.MineBlocks(node.Address(), 99); err != nil {
if err := node.MineBlocks(node.Address(), int(remainingBlocks-1)); err != nil {
t.Fatal(err)
}
time.Sleep(time.Second)
Expand All @@ -94,12 +97,12 @@ func TestAutoAnnounce(t *testing.T) {
}
time.Sleep(time.Second)

nextHeight := lastHeight + 1 + 100 // off-by-one because the announcement is mined in the next block
prevHeight := lastAnnouncement.Index.Height
lastAnnouncement, err = manager.LastAnnouncement()
if err != nil {
t.Fatal(err)
} else if lastAnnouncement.Index.Height != nextHeight {
t.Fatalf("expected height %v, got %v", nextHeight, lastAnnouncement.Index.Height)
} else if lastAnnouncement.Index.Height <= prevHeight {
t.Fatalf("expected a new announcement after %v, got %v", prevHeight, lastAnnouncement.Index.Height)
} else if lastAnnouncement.Address != "foo.bar:1234" {
t.Fatal("announcement not updated")
}
Expand Down
2 changes: 2 additions & 0 deletions internal/test/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"sync"
"time"

"go.sia.tech/core/types"
"go.sia.tech/siad/crypto"
Expand Down Expand Up @@ -135,6 +136,7 @@ func (m *Miner) Mine(addr types.Address, n int) error {
return fmt.Errorf("failed to mine block %v: %w", mined, errFailedToSolve)
}
mined++
time.Sleep(time.Millisecond)
}
return nil
}
Expand Down

0 comments on commit 632d009

Please sign in to comment.