1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
package types
import (
"encoding/json"
"testing"
)
func TestCanonicalizeJSON(t *testing.T) {
raw := []byte(` { "z": 1, "a" : { "b" : 2 } } `)
canon, err := CanonicalizeJSON(raw)
if err != nil {
t.Fatalf("CanonicalizeJSON returned error: %v", err)
}
if got, want := string(canon), `{"z":1,"a":{"b":2}}`; got != want {
t.Fatalf("canonical mismatch: got %s want %s", got, want)
}
}
func TestParseOperationComputesCID(t *testing.T) {
rec := ExportRecord{
Seq: 10,
DID: "did:plc:test",
Operation: json.RawMessage(`{"didDoc":{"id":"did:plc:test"},"sig":"abc","publicKey":"def"}`),
}
op, err := ParseOperation(rec)
if err != nil {
t.Fatalf("ParseOperation returned error: %v", err)
}
if op.CID == "" {
t.Fatalf("expected computed CID")
}
if op.Sequence != rec.Seq {
t.Fatalf("seq mismatch: got %d want %d", op.Sequence, rec.Seq)
}
}
|