GPUCoin uses Google Test (GTest) for unit testing with automatic test discovery via CMake's gtest_discover_tests().
- test_types: uint256_t arithmetic, Hash256/Address conversions, hex encoding
- test_transaction: Serialization round-trips for all 3 transaction types, signing hash, kernel address derivation
- test_block: Block header/body serialization, header hashing
- test_crypto: SHA-256 known vectors, double SHA-256, Keccak-256, hash_pair, merkle_root, KeyPair generation/signing/verification/recovery
- test_merkle: Merkle tree construction, proof generation/verification, odd leaf counts
- test_compiler: BarraCUDA compilation (vector_add.cu), error handling, BIR serialize/deserialize
- test_compute_meter: Opcode cost table, deploy cost calculation, kernel cost scaling
- test_kernel_cache: LRU cache put/get/evict, capacity limits, eviction ordering
- test_statedb: Low-level RocksDB operations — put/get/del, batch writes, scan, column family isolation, persistence, large values
- test_state: WorldState — account CRUD, kernel deploy/retrieve, storage, block storage
- test_executor: Transfer execution, insufficient balance, nonce validation
- test_consensus: Block rewards, fee distribution, heaviest-chain comparison, difficulty, genesis parameters
- test_fraud_proof: Challenge window validation, proof verification, fraud detection
- test_protocol: Message header serialization, checksum computation, Message round-trips, VersionPayload serialization
- test_chain: Genesis initialization, block template creation, idempotent init
- test_wallet: Account creation, listing, unlock with correct/wrong password, key import, persistence
- test_thread_safety: Concurrent mempool add/remove/read, concurrent kernel cache put/get with LRU eviction
Detects memory errors: heap/stack/global buffer overflows, use-after-free, double-free, memory leaks.
cmake --preset asan
cmake --build build/asan
ASAN_OPTIONS=detect_leaks=1 ctest --test-dir build/asanDetects data races, deadlocks, and other concurrency bugs. Cannot run simultaneously with ASan.
cmake --preset tsan
cmake --build build/tsan
ctest --test-dir build/tsanDetects undefined behavior: integer overflow, null pointer dereference, type mismatches. Enabled alongside ASan in the default debug build.
Detects use of uninitialized memory. Clang-only.
cmake --preset msan
cmake --build build/msan
ctest --test-dir build/msanFor comprehensive memory analysis without compiler sanitizer overhead:
cmake --preset valgrind
cmake --build build/valgrind
# Run individual tests
valgrind --leak-check=full --error-exitcode=1 \
--track-origins=yes --suppressions=valgrind.supp \
build/valgrind/tests/test_crypto
# Run all tests with CTest + Valgrind
cd build/valgrind
ctest --overwrite MemoryCheckCommand=/usr/bin/valgrind \
--overwrite MemoryCheckCommandOptions="--leak-check=full --error-exitcode=1" \
-T MemCheckA valgrind.supp suppression file is provided to suppress known false positives from RocksDB and OpenSSL.
GitHub Actions runs four jobs on every push/PR:
- build-and-test: GCC-13 and Clang-17 builds with ASan + UBSan
- tsan: Thread Sanitizer build (Clang-17)
- valgrind: Full memory analysis with Valgrind memcheck
- release: Verifies clean release build
# All tests
ctest --test-dir build/debug --output-on-failure
# Specific test suite
build/debug/tests/test_crypto
# Specific test case
build/debug/tests/test_crypto --gtest_filter="CryptoTest.SHA256KnownVector"
# Verbose output
ctest --test-dir build/debug -V