Analyze Python code for correctness using symbolic execution and SMT solving to automatically find counterexamples for functions with type annotations and contracts.
86
Build a simple bank account manager that validates account operations using contract-based verification. The system should enforce business rules through preconditions and postconditions to ensure valid account transactions.
Implement a BankAccount class that manages account balance and transactions with the following operations:
The implementation must use contract-based specifications to enforce these business rules. You should define:
You may use any contract specification approach, including:
Implement the following test cases:
@generates
class BankAccount:
"""
A bank account that enforces business rules through contract verification.
"""
def __init__(self, account_number: str, initial_balance: float) -> None:
"""
Initialize a bank account with an account number and initial balance.
Args:
account_number: Unique identifier for the account
initial_balance: Starting balance (must be non-negative)
"""
pass
def deposit(self, amount: float) -> float:
"""
Deposit money into the account.
Args:
amount: Amount to deposit (must be positive)
Returns:
New balance after deposit
"""
pass
def withdraw(self, amount: float) -> float:
"""
Withdraw money from the account.
Args:
amount: Amount to withdraw (must be positive and <= balance)
Returns:
New balance after withdrawal
"""
pass
def get_balance(self) -> float:
"""
Get the current account balance.
Returns:
Current balance
"""
pass
def transfer(self, amount: float, destination: 'BankAccount') -> None:
"""
Transfer money to another account.
Args:
amount: Amount to transfer (must be positive and <= balance)
destination: The destination account
"""
passProvides contract verification and symbolic execution capabilities for Python code.
Install with Tessl CLI
npx tessl i tessl/pypi-crosshair-toolevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10