package serve import ( "crypto/ed25519" "net/http/httptest" "testing" "git.smesh.lol/btcd-lite/internal/manifest" "git.smesh.lol/btcd-lite/internal/service" "git.smesh.lol/btcd-lite/internal/store" ) // TestManifestWithKey: a view with a key publishes a manifest of its block // coverage, and a client verifying it with the same key's public half accepts // it. func TestManifestWithKey(t *testing.T) { dir := t.TempDir() b, hdr := putBlocks(t, dir, 20) defer b.Close() defer hdr.Close() v := New(map[string]*store.HeaderStore{"btc": hdr}, b) v.Key = ed25519.NewKeyFromSeed(make([]byte, 32)) h := service.Handler(v) w := httptest.NewRecorder() h.ServeHTTP(w, httptest.NewRequest("GET", "/v1/manifest", nil)) if w.Code != 200 { t.Fatalf("manifest status %d: %s", w.Code, w.Body) } pub := v.Key.Public().(ed25519.PublicKey) m, err := manifest.Verify(w.Body.Bytes(), pub) if err != nil { t.Fatalf("verify: %v", err) } cov, ok := m.ChainTip("btc") if !ok || cov.Tip != 20 { t.Fatalf("coverage %+v", cov) } }