Skip to content

Commit

Permalink
contracts: fix ndf
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Apr 22, 2024
1 parent 1b09544 commit b42e507
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions host/contracts/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@ func TestContractLifecycle(t *testing.T) {
}
defer node.Close()

cm := node.ChainManager()
webhookReporter, err := webhooks.NewManager(node.Store(), log.Named("webhooks"))
if err != nil {
t.Fatal(err)
Expand All @@ -797,11 +798,19 @@ func TestContractLifecycle(t *testing.T) {
}
defer c.Close()

// waitForScan is a helper func to wait for the contract manager
// to catch up with chain manager
waitForScan := func() {
for cm.TipState().Index.Height != c.ScanHeight() {
time.Sleep(100 * time.Millisecond)
}
}

// note: many more blocks than necessary are mined to ensure all forks have activated
if err := node.MineBlocks(node.Address(), int(stypes.MaturityDelay*4)); err != nil {
t.Fatal(err)
}
time.Sleep(100 * time.Millisecond) // sync time
waitForScan()

renterFunds := types.Siacoins(500)
hostCollateral := types.Siacoins(1000)
Expand All @@ -828,7 +837,7 @@ func TestContractLifecycle(t *testing.T) {
if err := node.MineBlocks(types.VoidAddress, 1); err != nil {
t.Fatal(err)
}
time.Sleep(100 * time.Millisecond) // sync time
waitForScan()

contract, err = c.Contract(rev.Revision.ParentID)
if err != nil {
Expand Down Expand Up @@ -914,12 +923,13 @@ func TestContractLifecycle(t *testing.T) {
if err := node.MineBlocks(types.VoidAddress, int(remainingBlocks)); err != nil {
t.Fatal(err)
}
time.Sleep(100 * time.Millisecond) // sync time
waitForScan()

// confirm the revision
if err := node.MineBlocks(types.VoidAddress, 1); err != nil {
t.Fatal(err)
}
time.Sleep(100 * time.Millisecond) // sync time
waitForScan()

contract, err = c.Contract(rev.Revision.ParentID)
if err != nil {
Expand All @@ -935,7 +945,7 @@ func TestContractLifecycle(t *testing.T) {
if err := node.MineBlocks(types.VoidAddress, int(remainingBlocks)); err != nil {
t.Fatal(err)
}
time.Sleep(time.Second) // sync time
waitForScan()

// check that the contract is still active
contract, err = c.Contract(rev.Revision.ParentID)
Expand Down

0 comments on commit b42e507

Please sign in to comment.