proptest
БесплатноБез исполняемых скриптовНе проверенproptest — property-based testing for Rust (Hypothesis-style). Generates thousands of random inputs to find counterexamples to invariants, with shrinking to…
от claude-dev-suite★ 51 звезда на GitHubОб этом скилле
proptest — Property-Based Testing in Rust
Deep Knowledge: Use
mcp__documentation__fetch_docswith technology:proptest.
Why Property-Based Testing
Unit tests check specific examples; property tests check invariants (must hold for ALL inputs):
// Unit test: one example
#[test]
fn add_examples() {
assert_eq!(add(2, 3), 5);
}
// Property test: invariant for any pair
proptest! {
#[test]
fn add_commutative(a: i32, b: i32) {
prop_assert_eq!(add(a, b), add(b, a));
}
}
proptest generates ~256 random (a, b) pairs by default. If any fails, shrinks to minimal example. Catches edge cases (0, MAX, MIN, negative, etc.) you'd never write manually.
Critical for:
- Crypto code — encrypt/decrypt round-trip, signature verify
- Parsers/serializers —
parse(serialize(x)) == xfor anyx - Finance — total preserved across operations
- State machines — invariants hold across transitions
- Wallet code — coin selection, fee calculation, descriptor parsing
Setup
[dev-dependencies]
proptest = "1.5"
proptest-derive = "0.5" # for #[derive(Arbitrary)]
Basic Property Test
use proptest::prelude::*;
fn reverse(s: &str) -> String {
s.chars().rev().collect()
}
proptest! {
#[test]
fn reverse_twice_is_identity(s in ".*") { // any string
prop_assert_eq!(reverse(&reverse(&s)), s);
}
#[test]
fn reverse_preserves_length(s in ".*") {
prop_assert_eq!(reverse(&s).len(), s.len());
}
}
s in ".*" is a regex strategy — generates strings matching the regex. Powerful for parsers.
Strategies — Generating Inputs
Primitives
proptest! {
#[test]
fn test_int(x in 0i32..=100) { // bounded int
prop_assert!(x >= 0 && x <= 100);
}
#[test]
fn test_int_any(x in any::<i32>()) { // any i32
// ...
}
#[test]
fn test_uint(x: u64) { // syntactic sugar for any::<u64>()
// ...
}
#[test]
fn test_float(f in -1000.0f64..1000.0) {
// ...
}
}
Strings via Regex
proptest! {
#[test]
fn test_email(email in r"[a-z]{1,10}@[a-z]{1,10}\.(com|org|net)") {
// valid-looking email strings
}
#[test]
fn test_btc_addr(addr in r"bc1[a-z0-9]{38,42}") {
// bech32-style strings
}
}
Collections
use proptest::collection::vec;
proptest! {
#[test]
fn test_vec(v in vec(0u32..1000, 0..100)) { // Vec<u32>, len 0-100
prop_assert!(v.iter().all(|&x| x < 1000));
}
#[test]
fn test_btreemap(m in proptest::collection::btree_map(0u32..100, ".*", 1..10)) {
// BTreeMap<u32, String> with 1-10 entries
}
}
Tuples and Combinations
proptest! {
#[test]
fn test_pair((a, b) in (0i32..100, 0i32..100)) {
prop_assert!(a >= 0 && b >= 0);
}
#[test]
fn test_either(x in prop_oneof![Just(0), Just(1), 2..=10]) {
// 1/3 chance each: 0, 1, or random in 2..=10
prop_assert!(x >= 0);
}
}
Custom Strategies
fn arb_wallet() -> impl Strategy<Value = Wallet> {
(
"[a-z]{1,20}", // name
0u64..21_000_000_00000000, // balance in sats
prop::collection::vec(arb_address(), 1..10),
).prop_map(|(name, balance, addresses)| {
Wallet { name, balance, addresses }
})
}
fn arb_address() -> impl Strategy<Value = Address> {
r"bc1[a-z0-9]{38,42}".prop_map(Address)
}
proptest! {
#[test]
fn wallet_balance_matches_addresses(w in arb_wallet()) {
let computed: u64 = w.addresses.iter().map(|a| a.balance()).sum();
prop_assert_eq!(computed, w.balance);
}
}
#[derive(Arbitrary)]
use proptest_derive::Arbitrary;
#[derive(Debug, Arbitrary)]
struct Tx {
#[proptest(strategy = "0u64..21_000_000_00000000")]
amount_sats: u64,
#[proptest(regex = "bc1[a-z0-9]{38,42}")]
address: String,
#[proptest(strategy = "1u64..1000")]
fee_rate: u64,
}
proptest! {
#[test]
fn tx_total_at_most_supply(tx: Tx) {
prop_assert!(tx.amount_sats + tx.fee_rate * 250 <= 21_000_000_00000000);
}
}
Common Property Patterns
Round-trip
proptest! {
#[test]
fn serialize_deserialize_roundtrip(w in arb_wallet()) {
let json = serde_json::to_string(&w).unwrap();
let parsed: Wallet = serde_json::from_str(&json).unwrap();
prop_assert_eq!(parsed, w);
}
#[test]
fn encrypt_decrypt_roundtrip(plaintext: Vec<u8>, key in arb_key()) {
let ciphertext = encrypt(&plaintext, &key);
let decrypted = decrypt(&ciphertext, &key).unwrap();
prop_assert_eq!(decrypted, plaintext);
}
}
Invariants
proptest! {
#[test]
fn coin_selection_total_at_least_target(
utxos in vec(0u64..1_000_000, 1..50),
Установить proptest в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadGrepGlobWriteEditFAQ
Что делает скилл proptest?
proptest — property-based testing for Rust (Hypothesis-style). Generates thousands of random inputs to find counterexamples to invariants, with shrinking to minimal failing case. Critical for crypto, parsers, state machines, and finance code where edge cases matter. Includes strategies (gen functions), regression tracking, and integration with cargo test. Alternative: quickcheck (simpler API, less powerful). USE WHEN: user mentions "proptest", "property-based test", "proptest!", "Strategy", "Arbitrary", "shrink", "quickcheck", "regression file", "fuzz-light", "proptest-derive" DO NOT USE FOR: Generic Rust unit tests - use `testing/rust-testing` DO NOT USE FOR: Fuzzing with mutator (cargo-fuzz, AFL) - use bitcoin/testing/fuzz DO NOT USE FOR: KMP property testing - use `testing/kotest` (has built-in property)
Как установить скилл proptest?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл proptest запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic