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) } }