scanback_test.go raw

   1  package domain
   2  
   3  import (
   4  	"context"
   5  	"testing"
   6  
   7  	"git.smesh.lol/nostrino/pkg/chaindata"
   8  )
   9  
  10  // TestScanBackwardsWalksDownAndStopsAtTheGap: with no match the walk covers descending windows and
  11  // stops after the gap rather than running to genesis, so a new wallet answers "no coins here" in
  12  // minutes instead of hours.
  13  func TestScanBackwardsWalksDownAndStopsAtTheGap(t *testing.T) {
  14  	r := newRig(t)
  15  
  16  	if _, err := r.domain.Restore("btc", "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about", "pass"); err != nil {
  17  		t.Fatal(err)
  18  	}
  19  
  20  	chain := r.chains["btc"]
  21  	chain.position = chaindata.Position{Tip: 10_000, Filters: 10_000}
  22  	chain.matched = nil
  23  
  24  	report, err := r.domain.ScanBackwards(context.Background(), "btc", 500, 1_000)
  25  
  26  	if err != nil {
  27  		t.Fatal(err)
  28  	}
  29  
  30  	if report.Scripts == 0 {
  31  		t.Fatal("no scripts were derived")
  32  	}
  33  
  34  	if chain.lastFrom != 9_001 {
  35  		t.Fatalf("the last window started at %d, want 9001", chain.lastFrom)
  36  	}
  37  
  38  	if len(report.Matched) != 0 {
  39  		t.Fatalf("matched %v", report.Matched)
  40  	}
  41  }
  42