paircheck_test.go raw

   1  package utxobuild_test
   2  
   3  import (
   4  	"testing"
   5  
   6  	"git.smesh.lol/nostrino/pkg/crypto/chainhash"
   7  
   8  	"git.smesh.lol/btcd-lite/internal/utxo"
   9  	utxostore "git.smesh.lol/btcd-lite/internal/utxo/store"
  10  	"git.smesh.lol/btcd-lite/internal/wire"
  11  )
  12  
  13  // TestWalkTouchesPerCheckpoint compares the two things the builder could get
  14  // wrong on its own: the touches it collects for a range, and the name of the
  15  // checkpoint it writes. It walks the fixture's bodies itself and prints, per
  16  // range, the touch count and the walk's name, so the builder's log line can be
  17  // put beside it.
  18  func TestWalkTouchesPerCheckpoint(t *testing.T) {
  19  	bodies, _ := chainOfBodies(40)
  20  	var set []utxo.Entry
  21  	var touches []utxo.Touch
  22  	from := uint32(0)
  23  	for h := uint32(0); h < 40; h++ {
  24  		b, err := wire.ParseBlock(bodies[h])
  25  		if err != nil {
  26  			t.Fatalf("body %d: %v", h, err)
  27  		}
  28  		lookup := utxo.Lookup(func(op wire.OutPoint) (utxo.Entry, bool) { return utxo.Find(set, op) })
  29  		ts, err := utxo.BlockTouches(b, h, lookup)
  30  		if err != nil {
  31  			t.Fatalf("body %d touches: %v", h, err)
  32  		}
  33  		touches = append(touches, ts...)
  34  		set, err = utxo.ApplyRange(set, ts)
  35  		if err != nil {
  36  			t.Fatalf("body %d apply: %v", h, err)
  37  		}
  38  		if (h+1)%10 != 0 {
  39  			continue
  40  		}
  41  		t.Logf("range %d..%d: %d touches, %d entries, walk %s", from, h+1, len(touches), len(set), utxostore.NameOf(set))
  42  		from, touches = h+1, nil
  43  	}
  44  	_ = chainhash.Hash{}
  45  }
  46