Skip to content

Meta-Pool/liquid-staking-contract-fuzzy-testing

Repository files navigation

Metapool Contract Testing Suite

A modern testing framework for the Metapool liquid staking smart contracts using near-workspaces.

Overview

This repository provides comprehensive testing for NEAR smart contracts compiled from the main liquid-staking-contract repository

Architecture

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

Features

  • Integration Testing: Full contract testing using near-workspaces
  • Fuzzy Testing: Property-based testing with randomized inputs
  • Edge Case Testing: Boundary conditions and error scenarios

Prerequisites

  • Rust 1.70+ (latest stable recommended)
  • WASM contracts from the main repository

Setup

  1. Clone & compile the main repo https://github.com/meta-pool/liquid-staking-contract

  2. 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/
  3. Install dependencies:

    cargo build

Running Tests

Specific Test Suites -- Incremental complexity

# 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

All Tests

cargo test

With Logging

RUST_LOG=debug cargo test -- --nocapture

Contract Testing Approach

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

Adding New Tests

  1. Create test functions in appropriate test files
  2. Use sim_setup, sim_utils, test_utils helpers for common operations
  3. Include both positive and negative test cases
  4. Add property-based tests for complex scenarios

CI/CD Integration

This repository can be integrated into CI/CD pipelines to:

  • Automatically test new contract builds
  • Validate contract upgrades
  • Run regression tests
  • Performance benchmarking

Dependencies

  • near-workspaces - NEAR blockchain testing framework
  • tokio - Async runtime
  • proptest - Property-based testing
  • serde_json - JSON serialization
  • anyhow - Error handling

Version Compatibility

  • Rust: Latest stable (1.70+)
  • near-workspaces: 0.20+

Contributing

When adding new tests:

  1. Follow existing patterns in test organization
  2. Include descriptive test names and comments
  3. Test both success and failure cases
  4. Update documentation for new test categories

About

testing for Meta Pool's NEAR Liquid Staking contract

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published