cheatah
Source

tests/purrc/ed25519_cr_test.cpp

1// Copyright (c) 2026 BigBrain LLC. MIT-licensed (see LICENSE).
2// Original work; see ACKNOWLEDGMENTS.md for the open-source ideas we build upon.
3// Compile-run unit tests for the `ed25519` module: one test per function, each a tiny
4// .purr compiled by purrc and run under the cheatah runtime. Keys/signatures are hex.
5// The deterministic cases use the RFC 8032 §7.1 known-answer vectors; generate() is
6// non-deterministic, so it is asserted by PROPERTY (a fresh key still signs+verifies).
7// Complements the in-process unit tests (stdlib/tests/ed25519_test.cpp) and the
8// per-module system-level test (StdlibE2E.Ed25519).
9#include "e2e_harness.hpp"
11// RFC 8032 TEST 3: seed c5aa… -> public key fc51….
12TEST(Ed25519CompileRun, PublicKey) {
13 e2e::expect_e2e("ed25519_public_key", R"PURR(import io
14import ed25519
15io.print(ed25519.public_key("c5aa8df43f9f837bedb7442f31dcb7b166d38535076f094b85ce3a2e0b4458f7"))
16)PURR", "fc51cd8e6218a1a38da47ed00230f0580816ed13ba3303ac5deb911548908025\n");
19// Sign a message and verify it — the round trip a recipient performs.
20TEST(Ed25519CompileRun, SignVerify) {
21 e2e::expect_e2e("ed25519_sign_verify", R"PURR(import io
22import ed25519
23let secret = "c5aa8df43f9f837bedb7442f31dcb7b166d38535076f094b85ce3a2e0b4458f7"
24let pub = ed25519.public_key(secret)
25let sig = ed25519.sign(secret, "hello cheatah")
26io.print(ed25519.verify(pub, "hello cheatah", sig))
27)PURR", "True\n");
30// generate() makes a fresh secret seed; it must still produce a working keypair.
31TEST(Ed25519CompileRun, Generate) {
32 e2e::expect_e2e("ed25519_generate", R"PURR(import io
33import ed25519
34let secret = ed25519.generate()
35let pub = ed25519.public_key(secret)
36let sig = ed25519.sign(secret, "msg")
37io.print(len(secret), ed25519.verify(pub, "msg", sig))
38)PURR", "64 True\n");