Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,073 changes: 3,025 additions & 48 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 23 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ version = "0.1.0"
edition = "2024"

[dependencies]
tester = { git = "https://github.com/stackclass/tester.git", tag = "v0.4.0"}
tester = { git = "https://github.com/stackclass/tester.git", tag = "v0.4.0" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
sha2 = "0.10"

# Mollusk dependencies
mollusk-svm = "0.9.0"
mollusk-svm-programs-token = "0.9.0"

# Solana SDK dependencies
solana-account = "3.2.0"
solana-clock = "3.0"
solana-instruction = "3.0"
solana-instruction-error = "2.0"
solana-program-option = "3.0"
solana-pubkey = "4.0"
solana-program-pack = "3.0"
solana-rent = "3.0"
solana-system-interface = "2.0"
solana-system-program = "3.1.0"

# SPL Token dependencies
spl-token-interface = "2.0.0"
spl-associated-token-account-interface = "2.0.0"
125 changes: 123 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
# Solana Lending Program Development Challenge Tester

This is a program that validates your progress on the "Solana Lending Program
Development" challenge.
Development" challenge using the Mollusk test harness.

## Overview

The tester has been enhanced with the Mollusk framework, a lightweight test
harness for Solana programs. This provides:

- **Fast Execution**: Direct SVM instruction execution without full validator runtime
- **Precise Control**: Explicit account management and instruction validation
- **Better Testing**: Comprehensive checks for account state, lamports, data, and more

## Architecture

The tester is organized into the following modules:

- `src/main.rs` - Entry point that initializes the tester
- `src/definition.rs` - Test case definitions
- `src/stages/` - Test implementations organized by stage
- `src/mollusk/` - Mollusk integration module
- `mod.rs` - Main Mollusk management
- `program_loader.rs` - Program loading utilities
- `test_context.rs` - Test context for state management
- `src/helpers.rs` - Helper functions for testing

## Requirements for binary

Expand All @@ -12,4 +34,103 @@ Development" challenge.
## User code requirements

- A binary named `your_program.sh` that executes the program.
- A file named `stackclass.yml`, with the following values: `debug`.
- A file named `stackclass.yml`, with the following values: `debug`.

## Building

```bash
cargo build --release
```

## Running Tests

The tester will automatically load and test the user's lending program using
Mollusk. Ensure the program is built before running tests:

```bash
cd <user-repo>
anchor build
```

## Test Stages

### Base Stages (7)
1. **be1** - Environment Setup
2. **rs2** - Rust Basics
3. **sm3** - Solana Model
4. **at4** - Anchor Try
5. **st5** - SPL Token Basics
6. **cp6** - Basic Deposit
7. **tt7** - Basic Withdraw

### Extension Modules (8 modules × 4 stages = 32 cases)

#### PDA Module
- **pa1** - PDA Concept
- **pa2** - PDA Derivation
- **pa3** - Bump Seeds
- **pa4** - PDA Practice

#### Treasury Module
- **tr1** - Treasury Intro
- **tr2** - Treasury Creation
- **tr3** - Treasury Security
- **tr4** - Treasury Practice

#### Account Structure Module
- **as1** - Bank Account
- **as2** - User Account
- **as3** - Account Space
- **as4** - Account Practice

#### Lending Core Module
- **lc1** - Borrow Basics
- **lc2** - Repay Basics
- **lc3** - LTV Calculation
- **lc4** - Core Practice

#### Oracle Module
- **or1** - Oracle Concept
- **or2** - Pyth Integration
- **or3** - Price Fetching
- **or4** - Oracle Practice

#### Liquidation Module
- **li1** - Health Factor
- **li2** - Liquidation Trigger
- **li3** - Liquidation Process
- **li4** - Liquidation Bonus
- **li5** - Liquidation Practice

#### Interest Module
- **in1** - Interest Basics
- **in2** - Accrued Interest
- **in3** - Rate Models
- **in4** - Interest Practice

#### Security Module
- **se1** - Common Vulnerabilities
- **se2** - Reentrancy Protection
- **se3** - Account Validation
- **se4** - Security Practice

## Mollusk Integration

The tester uses Mollusk for efficient program testing:

```rust
use crate::mollusk::{create_lending_mollusk, LendingTestContext};

// Create Mollusk instance
let mollusk = create_lending_mollusk(&repo_dir)?;
let mut context = LendingTestContext::new(mollusk)?;

// Create accounts and execute instructions
let user = context.create_funded_account(1_000_000_000);
let instruction = create_lending_instruction(data, accounts);
context.execute_instruction(&instruction)?;
```

## License

See LICENSE file for details.
39 changes: 39 additions & 0 deletions src/definition.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
// Copyright (c) The StackClass Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Definition module for the lending program tester.
//!
//! This module builds the test definition using the tester framework.
//! The test cases are implemented using the Mollusk test harness for
//! efficient and accurate Solana program testing.

use std::sync::Arc;

use tester::{Case, Definition};
Expand All @@ -16,47 +36,66 @@ use crate::stages::{
},
};

/// Build the test definition for the lending program.
///
/// This function creates a Definition struct that includes all test cases
/// for the lending program challenge. The tests are organized into base
/// stages and extension modules.
///
/// # Returns
///
/// * `Definition` - The test definition
pub fn build() -> Definition {
Definition {
executable_name: "your_program.sh".to_string(),
legacy_executable_name: None,
cases: vec![
// Base Stages (7 stages)
Case::new("be1", Arc::new(be1::test_env_setup)),
Case::new("rs2", Arc::new(rs2::test_rust_basics)),
Case::new("sm3", Arc::new(sm3::test_solana_model)),
Case::new("at4", Arc::new(at4::test_anchor_try)),
Case::new("st5", Arc::new(st5::test_spl_token_basics)),
Case::new("cp6", Arc::new(cp6::test_basic_deposit)),
Case::new("tt7", Arc::new(tt7::test_basic_withdraw)),
// Extension Modules (8 modules × 4 stages = 32 cases)
// PDA Module
Case::new("pa1", Arc::new(pa1::test_pda_concept)),
Case::new("pa2", Arc::new(pa2::test_pda_derivation)),
Case::new("pa3", Arc::new(pa3::test_pda_bump_seeds)),
Case::new("pa4", Arc::new(pa4::test_pda_practice)),
// Treasury Module
Case::new("tr1", Arc::new(tr1::test_treasury_intro)),
Case::new("tr2", Arc::new(tr2::test_treasury_creation)),
Case::new("tr3", Arc::new(tr3::test_treasury_security)),
Case::new("tr4", Arc::new(tr4::test_treasury_practice)),
// Account Structure Module
Case::new("as1", Arc::new(as1::test_bank_account)),
Case::new("as2", Arc::new(as2::test_user_account)),
Case::new("as3", Arc::new(as3::test_account_space)),
Case::new("as4", Arc::new(as4::test_account_practice)),
// Lending Core Module
Case::new("lc1", Arc::new(lc1::test_borrow_basics)),
Case::new("lc2", Arc::new(lc2::test_repay_basics)),
Case::new("lc3", Arc::new(lc3::test_ltv_calculation)),
Case::new("lc4", Arc::new(lc4::test_core_practice)),
// Oracle Module
Case::new("or1", Arc::new(or1::test_oracle_concept)),
Case::new("or2", Arc::new(or2::test_pyth_integration)),
Case::new("or3", Arc::new(or3::test_price_fetching)),
Case::new("or4", Arc::new(or4::test_oracle_practice)),
// Liquidation Module
Case::new("li1", Arc::new(li1::test_health_factor)),
Case::new("li2", Arc::new(li2::test_liquidation_trigger)),
Case::new("li3", Arc::new(li3::test_liquidation_process)),
Case::new("li4", Arc::new(li4::test_liquidation_bonus)),
Case::new("li5", Arc::new(li5::test_liquidation_practice)),
// Interest Module
Case::new("in1", Arc::new(in1::test_interest_basics)),
Case::new("in2", Arc::new(in2::test_accrued_interest)),
Case::new("in3", Arc::new(in3::test_rate_models)),
Case::new("in4", Arc::new(in4::test_interest_practice)),
// Security Module
Case::new("se1", Arc::new(se1::test_common_vulnerabilities)),
Case::new("se2", Arc::new(se2::test_reentrancy_protection)),
Case::new("se3", Arc::new(se3::test_account_validation)),
Expand Down
Loading