package filterbuild import ( "path/filepath" "testing" "git.smesh.lol/btcd-lite/internal/wire" ) // TestMergeCollapsesADuplicateCreation: two blocks can create one outpoint - // Bitcoin's duplicate coinbase at 91722 and 91880 - and the table is a set, so // the second record must not be written. The walk on mainnet stops here // otherwise, at the height of that duplicate. func TestMergeCollapsesADuplicateCreation(t *testing.T) { dir := t.TempDir() op := wire.OutPoint{Index: 0} op.Hash[0] = 0xe3 other := wire.OutPoint{Index: 1} other.Hash[0] = 0xe3 created := []Entry{ {OutPoint: op, Script: []byte{0x51}}, {OutPoint: op, Script: []byte{0x51}}, {OutPoint: other, Script: []byte{0x52}}, } path := filepath.Join(dir, "t.tab") if err := Merge(filepath.Join(dir, "missing.tab"), path, nil, created); err != nil { t.Fatalf("merge: %v", err) } r, err := Open(path) if err != nil { t.Fatal(err) } defer r.Close() var got []Entry for { e, ok, err := r.Next() if err != nil { t.Fatal(err) } if !ok { break } got = append(got, e) } if len(got) != 2 { t.Fatalf("%d records for two outpoints: %v", len(got), got) } if got[0].OutPoint != op || got[1].OutPoint != other { t.Fatalf("records are %v", got) } }