package utxostore import ( "os" "path/filepath" "testing" "git.smesh.lol/nostrino/pkg/crypto/chainhash" "git.smesh.lol/btcd-lite/internal/utxo" "git.smesh.lol/btcd-lite/internal/wire" ) func TestDbgW4(t *testing.T) { base := nodeEntriesAt4(t) ts, walk := nodeSecondRange(t, base) dir := t.TempDir() _, _ = WriteSet(dir, 0, base) _, _ = Promote(dir, 0) _, _ = CutRange(dir, 0, 1, ts) d, _ := LoadDiff(dir, 0, 1) debugWrite = func(op wire.OutPoint, n int) { t.Logf("wrote %x:%d from a list of %d", op.Hash[:2], op.Index, n) } defer func() { debugWrite = func(wire.OutPoint, int) {} }() got, err := MergeRange(dir, 0, 1, d, chainhash.Hash{}) raw := readSetFile(t, dir, 1) t.Logf("merge %s err %v walk %s; file entries %d", got, err, NameOf(walk), len(raw)) for i, e := range raw { if i < 4 { t.Logf(" file %d: %x:%d v=%d h=%d", i, e.OutPoint.Hash[:2], e.OutPoint.Index, e.Value, e.Height) } } _ = utxo.Entry{} } // readSetFile reads a canonical set file back as entries. func readSetFile(t *testing.T, dir string, height uint32) []utxo.Entry { t.Helper() raw, err := os.ReadFile(filepath.Join(dir, SetFile(height))) if err != nil { t.Fatalf("read set: %v", err) } buf := make([]byte, EntrySize) var out []utxo.Entry for i := 0; i+EntrySize <= len(raw); i += EntrySize { copy(buf, raw[i:i+EntrySize]) out = append(out, utxo.Decode(buf)) } return out }