package store_test import ( "os" "path/filepath" "testing" "git.smesh.lol/nostrino/pkg/crypto/chainhash" "git.smesh.lol/btcd-lite/internal/store" ) // TestTrustingOpenDoesNotReadTheStore: the trusting open must not read a single // stored body, which is the whole point on a dataset that is hours of reads. func TestTrustingOpenDoesNotReadTheStore(t *testing.T) { dir := t.TempDir() s, err := store.NewBlockStore(dir) if err != nil { t.Fatal(err) } raw := make([]byte, 81) raw[0] = 1 h := chainhash.DoubleHashH(raw[:80]) if err := s.PutBlock(h, raw); err != nil { t.Fatal(err) } if err := s.Close(); err != nil { t.Fatal(err) } // A handle that counts reads: truncating the body file would make a reading // open fail, so the file is made unreadable instead. body := filepath.Join(dir, "00000000.blk") if err := os.Chmod(body, 0o000); err != nil { t.Skipf("cannot chmod: %v", err) } defer os.Chmod(body, 0o644) if _, err := store.NewBlockStoreTrusting(dir); err != nil { t.Fatalf("the trusting open read the body: %v", err) } if _, err := store.NewBlockStore(dir); err == nil { t.Fatal("the verifying open did not read the body") } }