rewind_test.go raw
1 package domain
2
3 import "testing"
4
5 // TestRewindDropsMarkersAtOrAboveTheHeight: a watched script can arrive after the
6 // block that pays it was read, and the per-height markers are what would make the
7 // next sync skip that block. Rewinding drops them, and never raises the birthday.
8 func TestRewindDropsMarkersAtOrAboveTheHeight(t *testing.T) {
9 r := newRig(t)
10
11 if _, err := r.domain.Restore("btc", phrase, "pass"); err != nil {
12 t.Fatal(err)
13 }
14
15 for _, height := range []uint32{3, 4, 5} {
16 if err := r.domain.store.Put(matchKey("btc", height), nil); err != nil {
17 t.Fatal(err)
18 }
19 }
20
21 if err := r.domain.SetFilterFrom("btc", 5); err != nil {
22 t.Fatal(err)
23 }
24
25 if err := r.domain.Rewind("btc", 4); err != nil {
26 t.Fatal(err)
27 }
28
29 matches := r.domain.Matches("btc")
30
31 if len(matches) != 1 || matches[0] != 3 {
32 t.Fatalf("after rewinding to 4 the markers are %v, want [3]", matches)
33 }
34
35 meta, err := r.domain.meta("btc")
36
37 if err != nil {
38 t.Fatal(err)
39 }
40
41 if meta.FilterFrom != 4 {
42 t.Fatalf("the birthday is %d, want 4", meta.FilterFrom)
43 }
44
45 // Rewinding below the birthday moves it down; rewinding above it does not.
46 if err := r.domain.Rewind("btc", 1); err != nil {
47 t.Fatal(err)
48 }
49
50 meta, err = r.domain.meta("btc")
51
52 if err != nil {
53 t.Fatal(err)
54 }
55
56 if meta.FilterFrom != 1 {
57 t.Fatalf("the birthday is %d, want 1", meta.FilterFrom)
58 }
59
60 if matches := r.domain.Matches("btc"); len(matches) != 0 {
61 t.Fatalf("markers remain at or above the rewind: %v", matches)
62 }
63 }
64