Files
AetherForge/server/internal/db/oath_ledger_test.go
AetherForge 894b7a50ae
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Add Fleet Torrent erasure extension with shard DHT and gossip.
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.
2026-06-07 09:24:55 -07:00

55 lines
1.2 KiB
Go

package db
import (
"encoding/json"
"testing"
)
func TestOathLedgerRoundTrip(t *testing.T) {
d, err := New(t.TempDir())
if err != nil {
t.Fatal(err)
}
defer d.Close()
why := map[string]string{"tier": "dns_txt", "lane": "spread"}
hash := HashWhyJSON(why)
entry, err := d.InsertOathLedger(
"operator", OathSpreadTierEscalation, "agent-1", "#aabbcc", hash, OathOutcomeSuccess,
map[string]string{"command_type": "reorder_tiers"},
)
if err != nil {
t.Fatal(err)
}
if entry == nil || entry.ID == 0 {
t.Fatalf("expected inserted entry, got %+v", entry)
}
if entry.WhyHash != hash {
t.Fatalf("why_hash = %q want %q", entry.WhyHash, hash)
}
rows, err := d.ListOathLedger(10)
if err != nil {
t.Fatal(err)
}
if len(rows) != 1 {
t.Fatalf("rows = %+v", rows)
}
if rows[0].ActionType != OathSpreadTierEscalation || rows[0].Actor != "operator" {
t.Fatalf("unexpected row: %+v", rows[0])
}
}
func TestHashWhyJSONStable(t *testing.T) {
src := map[string]interface{}{"verdict": "retry spread", "clearance": 4}
h1 := HashWhyJSON(src)
h2 := HashWhyJSON(src)
if h1 == "" || h1 != h2 {
t.Fatalf("hash unstable: %q %q", h1, h2)
}
if len(h1) != 64 {
t.Fatalf("expected sha256 hex length 64, got %d", len(h1))
}
_, _ = json.Marshal(src)
}