package domain import "testing" // TestRewindDropsMarkersAtOrAboveTheHeight: a watched script can arrive after the // block that pays it was read, and the per-height markers are what would make the // next sync skip that block. Rewinding drops them, and never raises the birthday. func TestRewindDropsMarkersAtOrAboveTheHeight(t *testing.T) { r := newRig(t) if _, err := r.domain.Restore("btc", phrase, "pass"); err != nil { t.Fatal(err) } for _, height := range []uint32{3, 4, 5} { if err := r.domain.store.Put(matchKey("btc", height), nil); err != nil { t.Fatal(err) } } if err := r.domain.SetFilterFrom("btc", 5); err != nil { t.Fatal(err) } if err := r.domain.Rewind("btc", 4); err != nil { t.Fatal(err) } matches := r.domain.Matches("btc") if len(matches) != 1 || matches[0] != 3 { t.Fatalf("after rewinding to 4 the markers are %v, want [3]", matches) } meta, err := r.domain.meta("btc") if err != nil { t.Fatal(err) } if meta.FilterFrom != 4 { t.Fatalf("the birthday is %d, want 4", meta.FilterFrom) } // Rewinding below the birthday moves it down; rewinding above it does not. if err := r.domain.Rewind("btc", 1); err != nil { t.Fatal(err) } meta, err = r.domain.meta("btc") if err != nil { t.Fatal(err) } if meta.FilterFrom != 1 { t.Fatalf("the birthday is %d, want 1", meta.FilterFrom) } if matches := r.domain.Matches("btc"); len(matches) != 0 { t.Fatalf("markers remain at or above the rewind: %v", matches) } }