diff --git a/proofstream_parity_test.go b/proofstream_parity_test.go index 9b4f81a..630670a 100644 --- a/proofstream_parity_test.go +++ b/proofstream_parity_test.go @@ -72,6 +72,43 @@ func TestParityRejectPaths(t *testing.T) { } } +type receiptParityVectors struct { + Cases []struct { + ID string `json:"id"` + PublicKeyHex string `json:"public_key_hex"` + Receipt SignedReceipt `json:"receipt"` + ExpectOK bool `json:"expect_ok"` + ExpectProblem []string `json:"expect_problems"` + } `json:"cases"` +} + +func TestParityReceiptVerification(t *testing.T) { + path := filepath.Join("..", "..", "golden-vectors", "sdk-parity", "receipts.json") + raw, err := os.ReadFile(path) + if err != nil { + t.Fatalf("read receipt vectors: %v", err) + } + var v receiptParityVectors + if err := json.Unmarshal(raw, &v); err != nil { + t.Fatalf("decode receipt vectors: %v", err) + } + for _, c := range v.Cases { + report := VerifyReceiptOffline(c.Receipt, c.PublicKeyHex) + if report.OK != c.ExpectOK { + t.Errorf("%s: ok=%v want %v (problems=%v)", c.ID, report.OK, c.ExpectOK, report.Problems) + } + if len(report.Problems) != len(c.ExpectProblem) { + t.Errorf("%s: problems=%v want %v", c.ID, report.Problems, c.ExpectProblem) + continue + } + for i, p := range c.ExpectProblem { + if report.Problems[i] != p { + t.Errorf("%s: problem[%d]=%q want %q", c.ID, i, report.Problems[i], p) + } + } + } +} + func TestParityVerifyPayloadCommitment(t *testing.T) { for _, c := range loadParityVectors(t).Accept { commitment, err := PayloadCommitment(c.Payload)