Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Apply SwarmMagnet, uiHelp, AccessDepthPanel, Seer, miningsurgery, and path-tracer test fixes; add agent cloud telemetry fields and main strings import; refresh tests/README and PROBLEMS AWS operator notes.
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package erasure
|
|
|
|
import "testing"
|
|
|
|
func TestBuildTorrentManifestMagnet(t *testing.T) {
|
|
p := DefaultParams()
|
|
hashes := []string{"aa", "bb", "cc", "dd", "ee", "ff"}
|
|
m, err := BuildTorrentManifest("http://c2:8989", "deadbeef", "abc123", 1024, p, hashes)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if m.SwarmMagnet == "" || m.ManifestURL == "" {
|
|
t.Fatalf("manifest=%+v", m)
|
|
}
|
|
if len(m.ShardManifestURLs) != 6 {
|
|
t.Fatalf("urls=%d", len(m.ShardManifestURLs))
|
|
}
|
|
if m.Shards[0].URL != "http://c2:8989/api/v1/public/erasure-shard/deadbeef/0" {
|
|
t.Fatalf("shard url=%q", m.Shards[0].URL)
|
|
}
|
|
}
|
|
|
|
func TestSwarmMagnetLink(t *testing.T) {
|
|
m := SwarmMagnetLink("tok12345678", "deadbeef")
|
|
if m == "" || !contains(m, "tok12345678") || !contains(m, "aetherforge") {
|
|
t.Fatalf("magnet=%q", m)
|
|
}
|
|
}
|
|
|
|
func contains(s, sub string) bool {
|
|
return len(s) >= len(sub) && (s == sub || len(sub) == 0 || indexOf(s, sub) >= 0)
|
|
}
|
|
|
|
func indexOf(s, sub string) int {
|
|
for i := 0; i+len(sub) <= len(s); i++ {
|
|
if s[i:i+len(sub)] == sub {
|
|
return i
|
|
}
|
|
}
|
|
return -1
|
|
}
|
|
|
|
func TestShardContentHash(t *testing.T) {
|
|
h1 := ShardContentHash([]byte("shard-a"))
|
|
h2 := ShardContentHash([]byte("shard-b"))
|
|
if h1 == h2 || len(h1) != 64 {
|
|
t.Fatalf("hash=%q", h1)
|
|
}
|
|
}
|