65 lines
2.1 KiB
Go
65 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
// readers is the gate's own declaration of who reads its states (ADR 0495 clause 3: a read is granted only when the owner
|
|
// announced the state readable), kept here and not read from other repositories' manifests (clause 1). Each line names
|
|
// the modules of mesh-delivery whose manifest reads the state, as of R4e.
|
|
var readers = map[string][]string{
|
|
"asks": {"mesh-delivery-teller", "mesh-delivery-view"},
|
|
"merges": {"mesh-delivery-forge-bridge"},
|
|
"pulls": {"build-agent"}, // in mesh-controller
|
|
"owed": {"mesh-delivery-forge-bridge"},
|
|
"source": {"mesh-delivery-indexer", "mesh-delivery-checker"},
|
|
// ADR 0548 §3, §4: the checker reads the merge turns and claims no check of a repository one names; the gate alone writes
|
|
// them (a state is written by its owner's account alone, ADR 0495 §3: announcing it readable grants a read, never a write).
|
|
"turns": {"mesh-delivery-checker"},
|
|
}
|
|
|
|
// 1790/S: the states the module announces are the states its manifest declares, no more, no fewer, and the readable
|
|
// ones are the states other modules' manifests read.
|
|
func TestTheStatesTheModuleAnnouncesAreTheStatesItsManifestDeclares(t *testing.T) {
|
|
raw, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var m struct {
|
|
State []json.RawMessage `json:"state"`
|
|
}
|
|
if err := json.Unmarshal(raw, &m); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
declared := []string{}
|
|
for _, s := range m.State {
|
|
var name string
|
|
if json.Unmarshal(s, &name) != nil {
|
|
var o struct{ Name string }
|
|
if err := json.Unmarshal(s, &o); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
name = o.Name
|
|
}
|
|
declared = append(declared, name)
|
|
}
|
|
announced := []string{}
|
|
for _, s := range Kept {
|
|
announced = append(announced, s.Name)
|
|
}
|
|
slices.Sort(declared)
|
|
slices.Sort(announced)
|
|
if !slices.Equal(declared, announced) {
|
|
t.Errorf("announces %v, the manifest declares %v", announced, declared)
|
|
}
|
|
for _, s := range Kept {
|
|
if want := len(readers[s.Name]) > 0; s.Readable != want {
|
|
t.Errorf("state %s readable = %v, but its readers are %v", s.Name, s.Readable, readers[s.Name])
|
|
}
|
|
}
|
|
}
|