Anya Core Testing Guide¶
Test Organization¶
The test suite has been reorganized to eliminate duplicates and provide centralized utilities:
Test Structure¶
tests/
├── common/
│ ├── mod.rs # Common module exports
│ └── test_utilities.rs # Centralized test utilities
├── bitcoin/ # Bitcoin protocol tests
├── hardware/ # Hardware optimization tests
├── dao/ # DAO functionality tests
├── layer2/ # Layer 2 protocol tests
├── web5/ # Web5 integration tests
├── unit_tests/ # Unit tests
└── mod.rs # Main test module
Centralized Test Utilities¶
All tests now use centralized utilities from tests/common/test_utilities.rs
:
TestTransactionFactory¶
create_simple()
- Creates basic test transactionscreate_dummy_transaction()
- Legacy compatibility wrappercreate_dummy_transaction_batch(size)
- Batch transaction creation
TestEnvironmentFactory¶
new_basic()
- Basic test environmentnew_with_config(config)
- Custom configuration
MockFactory¶
create_bitcoin_keys()
- Mock Bitcoin key pairscreate_oracle_data()
- Mock DLC oracle datacreate_secp256k1_context()
- Mock secp256k1 context
TestAssertions¶
assert_transaction_valid(tx)
- Transaction validationassert_consensus_compliant(data)
- Consensus complianceassert_performance_acceptable(metrics)
- Performance validation
Running Tests¶
Quick Test Run¶
cargo test
Organized Test Execution¶
./scripts/run-all-tests.sh
Category-Specific Tests¶
cargo test --test bitcoin_tests
cargo test --test hardware_tests
cargo test --test dao_tests
Test Cleanup Completed¶
✅ Eliminated Duplicates:
- Removed duplicate create_dummy_transaction()
functions
- Consolidated TestEnvironment::new()
patterns
- Merged duplicate test directories
- Removed RISC-V test file duplicates
✅ Standardized Patterns: - Centralized test utilities - Consistent import structure - Unified assertion helpers - Common mock data creation
✅ Improved Organization: - Clear test categorization - Proper module structure - Centralized re-exports - Backward compatibility maintained
Best Practices¶
- Use Centralized Utilities: Always import from
crate::common::test_utilities
- Follow Naming Conventions: Use descriptive test function names
- Categorize Tests: Place tests in appropriate directories
- Mock External Dependencies: Use MockFactory for external resources
- Validate Results: Use TestAssertions for consistent validation