package serve import ( "path/filepath" "testing" "git.smesh.lol/nostrino/pkg/btcwire" "git.smesh.lol/nostrino/pkg/neutrino" "git.smesh.lol/btcd-lite/internal/store" ) // putBlocks seeds a body store and a header store with n heights of one chain: // each body is a real header followed by filler, so the body's first 80 bytes // are the header the store files the body under. func putBlocks(t *testing.T, dir string, n int) (*store.BlockStore, *store.HeaderStore) { t.Helper() b, err := store.NewBlockStore(filepath.Join(dir, "blocks")) if err != nil { t.Fatal(err) } hdrs := make([]btcwire.BlockHeader, 0, n) for i := 0; i < n; i++ { h := testHeader(uint32(i)) hdrs = append(hdrs, h) blk := append(h.SerializeAll(), make([]byte, 16)...) if err := b.PutBlock(h.BlockHash(), blk); err != nil { t.Fatal(err) } } hdr, err := store.NewHeaderStore(filepath.Join(dir, "headers")) if err != nil { t.Fatal(err) } if err := hdr.SetAnchor(neutrino.Anchor{Height: 0, BlockHash: hdrs[0].BlockHash(), FilterHeight: -1}); err != nil { t.Fatal(err) } if err := hdr.PutHeaders(0, hdrs); err != nil { t.Fatal(err) } return b, hdr } // testHeader is a distinct valid header per height. func testHeader(i uint32) btcwire.BlockHeader { return btcwire.BlockHeader{ Version: 1, MerkleRoot: [32]byte{byte(i), byte(i >> 8)}, Timestamp: 1231006505 + i, Bits: 0x1d00ffff, Nonce: i, } }