Builds: design 47 G §677, lead answers A-198, A-219 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
35 lines
1.2 KiB
Go
35 lines
1.2 KiB
Go
package operatorask
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"testing"
|
|
)
|
|
|
|
// Design 47 G A-198: the act's form and its digest are mesh-sdk's, so a seat server in go/process digests an act as
|
|
// every asker does, with no import of the contracts; the digest is canonical over the act's named fields.
|
|
func TestTheActsDigestIsCanonicalOverItsNamedFields(t *testing.T) {
|
|
a1, _ := ActDigest(Act{"verb": "release", "arg.delivery": "hq"})
|
|
b := Act{}
|
|
b["arg.delivery"] = "hq"
|
|
b["verb"] = "release"
|
|
if a2, _ := ActDigest(b); a1 != a2 {
|
|
t.Error("the order an act was built in changed its digest")
|
|
}
|
|
x, _ := ActDigest(Act{"a": "b\n1:c"})
|
|
y, _ := ActDigest(Act{"a": "b", "c": ""})
|
|
if x == y {
|
|
t.Error("two different acts encode the same")
|
|
}
|
|
if _, err := ActDigest(Act{}); err == nil {
|
|
t.Error("an empty act was digested")
|
|
}
|
|
if _, err := ActDigest(Act{"": "x"}); err == nil {
|
|
t.Error("an act with a nameless field was digested")
|
|
}
|
|
sum := sha256.Sum256([]byte("novox.act.v1\n4:verb\n7:release\n"))
|
|
if got, _ := ActDigest(Act{"verb": "release"}); got != "sha256:"+hex.EncodeToString(sum[:]) {
|
|
t.Errorf("the act's encoding is not the one written down: %s", got)
|
|
}
|
|
}
|