merge_test.go raw
1 package filterbuild
2
3 import (
4 "path/filepath"
5 "testing"
6
7 "git.smesh.lol/btcd-lite/internal/wire"
8 )
9
10 // TestMergeCollapsesADuplicateCreation: two blocks can create one outpoint -
11 // Bitcoin's duplicate coinbase at 91722 and 91880 - and the table is a set, so
12 // the second record must not be written. The walk on mainnet stops here
13 // otherwise, at the height of that duplicate.
14 func TestMergeCollapsesADuplicateCreation(t *testing.T) {
15 dir := t.TempDir()
16 op := wire.OutPoint{Index: 0}
17 op.Hash[0] = 0xe3
18 other := wire.OutPoint{Index: 1}
19 other.Hash[0] = 0xe3
20 created := []Entry{
21 {OutPoint: op, Script: []byte{0x51}},
22 {OutPoint: op, Script: []byte{0x51}},
23 {OutPoint: other, Script: []byte{0x52}},
24 }
25 path := filepath.Join(dir, "t.tab")
26 if err := Merge(filepath.Join(dir, "missing.tab"), path, nil, created); err != nil {
27 t.Fatalf("merge: %v", err)
28 }
29 r, err := Open(path)
30 if err != nil {
31 t.Fatal(err)
32 }
33 defer r.Close()
34 var got []Entry
35 for {
36 e, ok, err := r.Next()
37 if err != nil {
38 t.Fatal(err)
39 }
40 if !ok {
41 break
42 }
43 got = append(got, e)
44 }
45 if len(got) != 2 {
46 t.Fatalf("%d records for two outpoints: %v", len(got), got)
47 }
48 if got[0].OutPoint != op || got[1].OutPoint != other {
49 t.Fatalf("records are %v", got)
50 }
51 }
52