|
| 1 | +--- |
| 2 | +sidebar_position: 3 |
| 3 | +title: Ledger Tests |
| 4 | +description: Comprehensive ledger functionality testing |
| 5 | +slug: /developers/testing/ledger-tests |
| 6 | +--- |
| 7 | + |
| 8 | +# Ledger Tests |
| 9 | + |
| 10 | +## Overview |
| 11 | + |
| 12 | +Comprehensive ledger functionality testing covers transaction processing, state |
| 13 | +management, and ledger operations. These tests require nightly Rust due to |
| 14 | +advanced features and dependencies. |
| 15 | + |
| 16 | +## Running Ledger Tests |
| 17 | + |
| 18 | +### Basic Ledger Testing |
| 19 | + |
| 20 | +```bash |
| 21 | +# Build ledger tests |
| 22 | +make build-ledger |
| 23 | + |
| 24 | +# Run ledger tests |
| 25 | +make test-ledger |
| 26 | + |
| 27 | +# Run with cargo-nextest |
| 28 | +make nextest-ledger |
| 29 | +``` |
| 30 | + |
| 31 | +**Note**: Ledger tests require nightly Rust toolchain. |
| 32 | + |
| 33 | +## VRF Tests |
| 34 | + |
| 35 | +```bash |
| 36 | +# Run VRF tests |
| 37 | +make test-vrf |
| 38 | + |
| 39 | +# Run with cargo-nextest |
| 40 | +make nextest-vrf |
| 41 | +``` |
| 42 | + |
| 43 | +**Note**: VRF tests also require nightly Rust toolchain. |
| 44 | + |
| 45 | +## Block Replayer Tool |
| 46 | + |
| 47 | +### Purpose |
| 48 | + |
| 49 | +The block replayer validates transaction and ledger logic by replaying |
| 50 | +historical blockchain data: |
| 51 | + |
| 52 | +- **Transaction Validation**: Verify transaction processing correctness |
| 53 | +- **Ledger State**: Ensure ledger state transitions are accurate |
| 54 | +- **Protocol Compliance**: Check adherence to protocol rules |
| 55 | +- **Performance Analysis**: Measure processing speeds and resource usage |
| 56 | + |
| 57 | +### Usage |
| 58 | + |
| 59 | +```bash |
| 60 | +# Replay blocks from chain data |
| 61 | +./target/release/mina replay --blocks-file chain.json |
| 62 | + |
| 63 | +# Validate specific block range |
| 64 | +./target/release/mina replay --start-block 1000 --end-block 2000 |
| 65 | +``` |
| 66 | + |
| 67 | +### Future development |
| 68 | + |
| 69 | +Continued development of the block replayer is recommended for: |
| 70 | + |
| 71 | +- **Enhanced validation**: More comprehensive transaction validation |
| 72 | +- **Performance testing**: Benchmark ledger operation performance |
| 73 | +- **Protocol evolution**: Test new protocol features against historical data |
| 74 | +- **Regression testing**: Ensure changes don't break existing functionality |
| 75 | + |
| 76 | +## Ledger testing components |
| 77 | + |
| 78 | +### Transaction processing |
| 79 | + |
| 80 | +Tests cover: |
| 81 | + |
| 82 | +- **User commands**: Payment and delegation transactions |
| 83 | +- **Fee transfers**: Block producer rewards and fees |
| 84 | +- **Coinbase**: Block reward distribution |
| 85 | +- **Account creation**: New account initialization |
| 86 | + |
| 87 | +### State management |
| 88 | + |
| 89 | +Validation includes: |
| 90 | + |
| 91 | +- **Account updates**: Balance and nonce changes |
| 92 | +- **Merkle tree operations**: Ledger tree consistency |
| 93 | +- **State transitions**: Valid state progression |
| 94 | +- **Rollback handling**: Proper state restoration |
| 95 | + |
| 96 | +### Scan state testing |
| 97 | + |
| 98 | +The scan state manages pending transactions: |
| 99 | + |
| 100 | +- **Transaction queuing**: Proper ordering and batching |
| 101 | +- **SNARK work integration**: Proof generation coordination |
| 102 | +- **Staged ledger**: Intermediate state management |
| 103 | +- **Fork resolution**: Handling competing chains |
| 104 | + |
| 105 | +## Performance Considerations |
| 106 | + |
| 107 | +### Resource management |
| 108 | + |
| 109 | +1. **Memory usage**: Ledger tests can be memory intensive |
| 110 | +2. **Disk I/O**: State persistence operations |
| 111 | +3. **CPU usage**: Cryptographic operations and proof verification |
| 112 | +4. **Test duration**: Comprehensive tests may take significant time |
| 113 | + |
| 114 | +### Optimization strategies |
| 115 | + |
| 116 | +1. **Parallel execution**: Use cargo-nextest for faster test runs |
| 117 | +2. **Test filtering**: Run specific test subsets during development |
| 118 | +3. **Mock services**: Use lightweight mocks where appropriate |
| 119 | +4. **Resource cleanup**: Ensure proper cleanup after tests |
| 120 | + |
| 121 | +## Best practices |
| 122 | + |
| 123 | +### Test design |
| 124 | + |
| 125 | +1. **Isolation**: Use fresh ledger state for each test |
| 126 | +2. **Deterministic**: Tests should produce consistent results |
| 127 | +3. **Coverage**: Test both success and failure scenarios |
| 128 | +4. **Edge cases**: Include boundary conditions and error cases |
| 129 | + |
| 130 | +### Debugging ledger tests |
| 131 | + |
| 132 | +1. **State inspection**: Examine ledger state at test failure points |
| 133 | +2. **Transaction tracing**: Track transaction processing steps |
| 134 | +3. **Merkle tree validation**: Verify tree consistency |
| 135 | +4. **Account state**: Check individual account changes |
| 136 | + |
| 137 | +## Integration with other components |
| 138 | + |
| 139 | +### Connection to P2P tests |
| 140 | + |
| 141 | +Ledger tests integrate with P2P testing for: |
| 142 | + |
| 143 | +- **Transaction propagation**: Ensuring transactions spread correctly |
| 144 | +- **Block validation**: Verifying received blocks |
| 145 | +- **Consensus integration**: Coordinating with consensus mechanisms |
| 146 | + |
| 147 | +### Scenario test integration |
| 148 | + |
| 149 | +Ledger functionality is tested within broader scenarios: |
| 150 | + |
| 151 | +- **Multi-node synchronization**: Consistent ledger state across nodes |
| 152 | +- **Fork resolution**: Proper handling of competing ledgers |
| 153 | +- **Performance testing**: Ledger operations under load |
| 154 | + |
| 155 | +## Related Documentation |
| 156 | + |
| 157 | +- [Testing Framework Overview](testing-framework): Main testing documentation |
| 158 | +- [Unit Tests](unit-tests): Basic component testing |
| 159 | +- [Scenario Tests](scenario-tests): Integration testing scenarios |
| 160 | +- [Architecture](../architecture): Overall system architecture including ledger |
0 commit comments