diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/keeps_test.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/keeps_test.go index e3ef8b05e..4694f8f7c 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/keeps_test.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/keeps_test.go @@ -5,6 +5,7 @@ import ( "os" "path/filepath" "slices" + "strings" "testing" ) @@ -30,7 +31,12 @@ func TestTheStatesTheModuleAnnouncesAreTheStatesItsManifestDeclares(t *testing.T t.Fatal(err) } var m struct { - State []json.RawMessage `json:"state"` + State []json.RawMessage `json:"state"` + Requires []struct { + Name string `json:"name"` + Storage string `json:"storage"` + Template string `json:"template"` + } `json:"requires"` } if err := json.Unmarshal(raw, &m); err != nil { t.Fatal(err) @@ -47,6 +53,12 @@ func TestTheStatesTheModuleAnnouncesAreTheStatesItsManifestDeclares(t *testing.T } declared = append(declared, name) } + // The kept data of the template `state` are asked for in `requires`, under their local names (design 47 G §613). + for _, r := range m.Requires { + if r.Storage == "key-value" && r.Template == "state" { + declared = append(declared, r.Name) + } + } announced := []string{} for _, s := range Kept { announced = append(announced, s.Name) @@ -62,3 +74,37 @@ func TestTheStatesTheModuleAnnouncesAreTheStatesItsManifestDeclares(t *testing.T } } } + +// Design 47 G §613 (A-20): deliveries, groups, owed and conditions are `requires` entries of the template `state` under +// their local names, taking the buckets they already had; merges and source stay in the old `state` section. +func TestTheFourStatesMoveToTheTemplateAndTwoStayOld(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"` + Requires []struct{ Name, Storage, Template string } + } + if err := json.Unmarshal(raw, &m); err != nil { + t.Fatal(err) + } + moved := map[string]bool{} + for _, r := range m.Requires { + if r.Storage == "key-value" && r.Template == "state" { + moved[r.Name] = true + } + } + old := string(raw[strings.Index(string(raw), `"state": [`):]) + old = old[:strings.Index(old, "]")] + for _, n := range []string{"deliveries", "groups", "owed", "conditions"} { + if !moved[n] || strings.Contains(old, `"`+n+`"`) { + t.Errorf("%s: template state %v, old section lists it %v", n, moved[n], strings.Contains(old, `"`+n+`"`)) + } + } + for _, n := range []string{"merges", "source"} { + if moved[n] || !strings.Contains(old, `"`+n+`"`) { + t.Errorf("%s stays in the old section", n) + } + } +} diff --git a/modules/mesh-delivery-gate/module.json b/modules/mesh-delivery-gate/module.json index b015d3760..62651668b 100644 --- a/modules/mesh-delivery-gate/module.json +++ b/modules/mesh-delivery-gate/module.json @@ -278,6 +278,29 @@ ] } ] + }, + { + "name": "deliveries", + "storage": "key-value", + "template": "state" + }, + { + "name": "groups", + "storage": "key-value", + "template": "state" + }, + { + "name": "owed", + "storage": "key-value", + "template": "state", + "options": { + "history": 5 + } + }, + { + "name": "conditions", + "storage": "key-value", + "template": "state" } ], "packages": { @@ -296,8 +319,6 @@ "mesh-delivery-view.view_reach" ], "state": [ - "deliveries", - "groups", "pulls", { "name": "asks", @@ -307,15 +328,10 @@ "name": "merges", "history": 10 }, - { - "name": "owed", - "history": 5 - }, { "name": "source", "history": 64 - }, - "conditions" + } ], "capabilities": [ "ledger-calls",