Skip to content

Latest commit

 

History

History
125 lines (87 loc) · 4.04 KB

File metadata and controls

125 lines (87 loc) · 4.04 KB

Testing Strategy

Test Framework

GPUCoin uses Google Test (GTest) for unit testing with automatic test discovery via CMake's gtest_discover_tests().

Test Categories

Core 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

Cryptography Tests

  • 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

Compiler Tests

  • 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

State Tests

  • 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

Execution Tests

  • test_executor: Transfer execution, insufficient balance, nonce validation

Consensus Tests

  • test_consensus: Block rewards, fee distribution, heaviest-chain comparison, difficulty, genesis parameters
  • test_fraud_proof: Challenge window validation, proof verification, fraud detection

Network Tests

  • test_protocol: Message header serialization, checksum computation, Message round-trips, VersionPayload serialization

Node Tests

  • test_chain: Genesis initialization, block template creation, idempotent init
  • test_wallet: Account creation, listing, unlock with correct/wrong password, key import, persistence

Thread Safety Tests

  • test_thread_safety: Concurrent mempool add/remove/read, concurrent kernel cache put/get with LRU eviction

Sanitizers

Address Sanitizer (ASan)

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/asan

Thread Sanitizer (TSan)

Detects data races, deadlocks, and other concurrency bugs. Cannot run simultaneously with ASan.

cmake --preset tsan
cmake --build build/tsan
ctest --test-dir build/tsan

Undefined Behavior Sanitizer (UBSan)

Detects undefined behavior: integer overflow, null pointer dereference, type mismatches. Enabled alongside ASan in the default debug build.

Memory Sanitizer (MSan)

Detects use of uninitialized memory. Clang-only.

cmake --preset msan
cmake --build build/msan
ctest --test-dir build/msan

Valgrind

For 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 MemCheck

A valgrind.supp suppression file is provided to suppress known false positives from RocksDB and OpenSSL.

CI Pipeline

GitHub Actions runs four jobs on every push/PR:

  1. build-and-test: GCC-13 and Clang-17 builds with ASan + UBSan
  2. tsan: Thread Sanitizer build (Clang-17)
  3. valgrind: Full memory analysis with Valgrind memcheck
  4. release: Verifies clean release build

Running Tests

# 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