property-based-test-with-hypothesis
Use when example-based tests miss input combinations — state an invariant and let Hypothesis generate hundreds of inputs, then freeze the minimized counterexample as a regression test.
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 81
- Forks
- 17
01 前言 Front Matter
- name
- property-based-test-with-hypothesis
- description
- Use when example-based tests miss input combinations — state an invariant and let Hypothesis generate hundreds of inputs, then freeze the minimized counterexample as a regression test.
02 资源文件 3
- 许可证LICENSE1.0 KB
- 参考文档SOURCE.md361 B
- 参考文档TRUST.auto.yaml2.2 KB
03 SKILL.md 正文
Property-based tests with Hypothesis
Example tests check the cases you thought of. A property test checks the rule that must hold for all inputs and hands you the smallest input that breaks it.
Procedure
- Name the invariant as a law, not an example: "decode(encode(x)) == x", "total >= sum(parts)", "len(sorted(x)) == len(x)".
- Express a round-trip or invariant with
@given:
from hypothesis import given, strategies as st
import json
@given(st.dictionaries(st.text(), st.integers()))
def test_json_roundtrip(d):
assert json.loads(json.dumps(d)) == d
- Bias the strategy toward your real domain —
st.text(min_size=1),st.emails(),st.from_regex(r"\d{4}-\d{2}-\d{2}"), or a@st.compositefor your own types. Unboundedst.text()mostly finds Unicode edge cases you never ship. - Set a budget so the run has a fixed cost:
@settings(max_examples=500, deadline=200). - Run it:
pytest tests/test_json_roundtrip.py -q. On failure Hypothesis prints a minimized counterexample — read it; that input, not the first, is the bug. - Freeze the counterexample so it never regresses:
@example({"": 0}) # frozen from the found counterexample
- Cache the example database in CI so shrinking state survives between runs:
- uses: actions/cache@v4
with: {path: .hypothesis, key: hyp-${{ hashFiles('**/test_*.py') }}
Pitfalls
- A property that restates the implementation tests nothing. The expected value must come from a different computation — a model, a reference library, or an algebraic law.
- Generators that rarely produce interesting values (e.g.
st.integers()for a parser) make runs slow and shallow. Constrain andassume(). - A
deadlineset too low flags slow-but-correct inputs as failures. Raise it per test or setdeadline=Nonefor IO tests. - Nondeterministic properties — float
==, unordered collections — fail spuriously. Compare with a tolerance, or sort before comparing.
Verification
pytest tests/test_json_roundtrip.py -q --hypothesis-seed=0
Passes = green with a fixed seed and the example count reported in the summary line. Report: "roundtrip property held over 500 generated dicts, zero counterexamples, seed 0 reproducible."
04 同仓库更多 Skills
troves
Deposit and withdraw from Troves DeFi yield vault strategies on Starknet. View available strategies, check positions, and manage vault deposits. Use this skill when the user mentions Troves, vault, yield vault, DeFi vault, strategy, yield farming, vault deposit, vault withdraw, earning yield through vaults, passive yield strategies, or wants to deposit into or withdraw from a yield strategy — even if they don't say "Troves" explicitly.
trade
Swap tokens on Starknet via Fibrous DEX aggregator. Supports per-provider selection (avnu, ekubo, or auto to race all). Use this skill when the user wants to swap, exchange, trade, convert, buy, or sell one token for another on Starknet. Also use when the user asks about token prices, exchange rates, DEX routing, best swap route, or wants to check how much they would receive for a given amount — even if they don't explicitly say "swap".
staking
Stake, unstake, claim, and compound rewards for STRK, WBTC, tBTC, SolvBTC, and LBTC on Starknet. View validators, pools, and staking positions. Use this skill when the user mentions staking, delegating, validators, staking pools, rewards, compounding, unstaking, earning yield, passive income on crypto, or wants to earn on their STRK or BTC tokens — even if they don't say "stake" explicitly.
send
Send STRK, ETH, or any ERC-20 token to a Starknet address. Supports simulation (dry-run) before execution. Use this skill when the user wants to send, transfer, pay, tip, or move tokens to another wallet address on Starknet. Also trigger when the user mentions sending funds to someone, making a payment, transferring assets, or moving crypto to a specific address — even if they just say "pay 10 STRK to 0x...".
portfolio
View a comprehensive DeFi portfolio dashboard and optimize portfolio allocation via automated rebalancing. Use this skill when the user wants an overview, summary, dashboard, total value, net worth, portfolio rebalancing, target allocation, or wants to see all their DeFi positions across Starknet at once. Also trigger when the user asks "what do I have", "show me everything", "how much am I worth", "my positions", "my investments", "rebalance my portfolio", "I want 50% ETH", "optimize my holdings", or any request for a holistic view of their Starknet holdings — even if they don't explicitly say "portfolio".
multi-swap
Execute multiple token swaps in a single Starknet transaction via Fibrous (default). Supports per-provider selection (avnu, ekubo, or auto to race all). Supports 2-3 swap pairs bundled into one multicall. Use this skill when the user wants to swap multiple token pairs at once, do batch swaps, execute several trades simultaneously, perform parallel swaps, or do bulk trading in one transaction. Also trigger when the user mentions "two swaps", "three swaps", "swap X and Y at the same time", or wants to convert multiple tokens in a single call.