A modern testing framework for the Metapool liquid staking smart contracts using near-workspaces
.
This repository provides comprehensive testing for NEAR smart contracts compiled from the main liquid-staking-contract repository
liquid-staking-contract/ # Main contract repo (Rust 1.80, near-sdk 3.1)
├── metapool/src/ # Contract source code
└── res/metapool.wasm # Compiled WASM → copy to this repo
liquid-staking-contract-fuzzy-testing/ # This testing repo (latest Rust, near-workspaces)
├── contracts/ # WASM files for testing
├── tests/ # Test suites
└── Cargo.toml # Modern dependencies
- Integration Testing: Full contract testing using
near-workspaces
- Fuzzy Testing: Property-based testing with randomized inputs
- Edge Case Testing: Boundary conditions and error scenarios
- Rust 1.70+ (latest stable recommended)
- WASM contracts from the main repository
-
Clone & compile the main repo https://github.com/meta-pool/liquid-staking-contract
-
Copy WASM contracts from the main repository:
# From the main liquid-staking-contract directory bash build.sh # Copy to this test repository, execute: bash update_contracts.sh # will copy: # cp res/metapool.wasm ../liquid-staking-contract-fuzzy-testing/contracts/ # cp res/staking_pool.wasm ../liquid-staking-contract-fuzzy-testing/contracts/
-
Install dependencies:
cargo build
# Test utilities
cargo test test_utils
# Staking and Unstaking
cargo cargo test sim_test_staking -- --nocapture
cargo cargo test sim_test_unstaking -- --nocapture
# single happy path
clear && bash update_contracts.sh && cargo cargo test simulation_happy_path -- --nocapture
# Fuzzy testing -- multiple cycles -- check invariants
clear && bash update_contracts.sh && cargo test simulation_fuzzy::main -- --no-capture
cargo test
RUST_LOG=debug cargo test -- --nocapture
Tests interact with contracts as black boxes using their public interface:
- No access to contract source code
- Tests only compiled WASM artifacts
- Focuses on behavioral correctness
- Validates contract invariants
- Create test functions in appropriate test files
- Use
sim_setup
,sim_utils
,test_utils
helpers for common operations - Include both positive and negative test cases
- Add property-based tests for complex scenarios
This repository can be integrated into CI/CD pipelines to:
- Automatically test new contract builds
- Validate contract upgrades
- Run regression tests
- Performance benchmarking
near-workspaces
- NEAR blockchain testing frameworktokio
- Async runtimeproptest
- Property-based testingserde_json
- JSON serializationanyhow
- Error handling
- Rust: Latest stable (1.70+)
- near-workspaces: 0.20+
When adding new tests:
- Follow existing patterns in test organization
- Include descriptive test names and comments
- Test both success and failure cases
- Update documentation for new test categories