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 tiny4
// .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() is6
// 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 the8
// per-module system-level test (StdlibE2E.Ed25519).9
#include "e2e_harness.hpp"11
// RFC 8032 TEST 3: seed c5aa… -> public key fc51….12
TEST(Ed25519CompileRun, PublicKey) {13
e2e::expect_e2e("ed25519_public_key", R"PURR(import io14
import ed2551915
io.print(ed25519.public_key("c5aa8df43f9f837bedb7442f31dcb7b166d38535076f094b85ce3a2e0b4458f7"))16
)PURR", "fc51cd8e6218a1a38da47ed00230f0580816ed13ba3303ac5deb911548908025\n");17
}19
// Sign a message and verify it — the round trip a recipient performs.20
TEST(Ed25519CompileRun, SignVerify) {21
e2e::expect_e2e("ed25519_sign_verify", R"PURR(import io22
import ed2551923
let secret = "c5aa8df43f9f837bedb7442f31dcb7b166d38535076f094b85ce3a2e0b4458f7"24
let pub = ed25519.public_key(secret)25
let sig = ed25519.sign(secret, "hello cheatah")26
io.print(ed25519.verify(pub, "hello cheatah", sig))27
)PURR", "True\n");28
}30
// generate() makes a fresh secret seed; it must still produce a working keypair.31
TEST(Ed25519CompileRun, Generate) {32
e2e::expect_e2e("ed25519_generate", R"PURR(import io33
import ed2551934
let secret = ed25519.generate()35
let pub = ed25519.public_key(secret)36
let sig = ed25519.sign(secret, "msg")37
io.print(len(secret), ed25519.verify(pub, "msg", sig))38
)PURR", "64 True\n");39
}