A simple test suite that simulates and verifies basic token transfer transactions in a Monad-style blockchain execution environment.
This test demonstrates fundamental blockchain transaction processing including:
- Token transfers between accounts
- Balance state management
- Gas cost calculation and deduction
- Transaction nonce handling
- Edge case validation
Verify that a Monad node correctly processes basic token transfers by checking that account balances, gas fees, and nonces are updated properly in the blockchain state.
token_transfer_test.cpp- Main test suite with 6 comprehensive test casesrun_test.sh- Build and execution script
- G++ compiler with C++17 support
- Linux/Unix environment (or WSL on Windows)
- No external dependencies required
- Clone or download the repository
- Ensure you have g++ installed:
g++ --version
Run the test suite with a single command:
chmod +x run_test.sh
./run_test.shAlternatively, compile and run manually:
# Compile
g++ -std=c++17 -o token_transfer_test token_transfer_test.cpp
# Run
./token_transfer_test- Transfers 50,000 tokens from sender to receiver
- Verifies balance updates
- Confirms gas cost deduction (21,000 gas × 20 gas price)
- Checks nonce increment
- Attempts transfer exceeding available balance
- Verifies transaction rejection
- Ensures state remains unchanged
- Processes 3 sequential transfers
- Validates cumulative balance changes
- Confirms proper nonce progression
- Tests with high gas price (100)
- Verifies accurate gas cost computation
- Ensures correct fee deduction
- Edge case: transfer maximum possible amount
- Tests precision in balance calculations
- Confirms sender ends with zero balance
- Zero amount transfers
- Gas deduction verification for edge cases
========================================
Monad Token Transfer Test Suite
========================================
Testing basic transaction processing and state changes
Test 1: Successful Token Transfer
[PASS] Transfer should succeed
[PASS] Sender balance correct
[PASS] Receiver balance correct
[PASS] Nonce incremented
Test 2: Insufficient Balance Failure
[PASS] Transfer should fail
[PASS] Sender balance unchanged
[PASS] Receiver balance unchanged
Test 3: Multiple Transaction Processing
[PASS] Transaction 1 succeeds
[PASS] Transaction 2 succeeds
[PASS] Transaction 3 succeeds
[PASS] Sender final balance correct
[PASS] Receiver final balance correct
[PASS] Nonce updated for all transactions
Test 4: Gas Cost Calculation
[PASS] Transfer succeeds
[PASS] Gas cost calculated correctly
Test 5: Exact Balance Transfer (Edge Case)
[PASS] Max transfer succeeds
[PASS] Sender has zero balance
[PASS] Receiver gets max amount
Test 6: Edge Cases
[PASS] Zero amount transfer allowed
[PASS] Gas deducted even for zero transfer
========================================
Test Summary:
Passed: 20
Failed: 0
Total: 20
========================================
All tests passed!
Manages blockchain state including:
- Account balances (map of address → balance)
- Account nonces (map of address → nonce)
- Transfer logic with gas cost calculation
Represents a basic blockchain transaction:
struct Transaction {
string from; // Sender address
string to; // Recipient address
uint64_t value; // Amount to transfer
uint64_t gasLimit; // Maximum gas allowed
uint64_t gasPrice; // Price per gas unit
uint64_t nonce; // Transaction sequence number
}Custom test framework providing:
- Assertion methods (
assert_equal,assert_true,assert_false) - Test result tracking
- Summary reporting
Total Cost = Transfer Amount + (Gas Limit × Gas Price)
Standard transfer gas limit: 21,000 units
Sender Balance After = Initial Balance - Transfer Amount - Gas Cost
Receiver Balance After = Initial Balance + Transfer Amount
- Increments by 1 for each successful transaction
- Used to prevent replay attacks
- Ensures transaction ordering
This test uses mock/simulated classes for standalone operation. To integrate with the actual Monad blockchain:
- Replace
StateManagerwith Monad's actual state management system - Use Monad's transaction structures from
execution/transaction.h - Link against Monad execution libraries
- Update gas cost calculations to match Monad's implementation
- Ensure g++ supports C++17:
g++ -std=c++17 --version - Check file permissions:
ls -la token_transfer_test.cpp
chmod +x run_test.sh- Verify files are in current directory:
ls -la - Check you're in the correct directory:
pwd
To extend the test suite:
- Add new test functions following the pattern:
void test_name(TestRunner& runner) - Call your test in
main() - Use
runner.assert_*methods for validation - Document the test case in this README
This test suite is provided as-is for educational and testing purposes within the Monad blockchain project.
Created as a demonstration of basic transaction processing and state management in blockchain execution environments.
- v1.0 - Initial release with 6 core test cases
- Basic transfer validation
- Gas cost verification
- Edge case handling
- Standalone operation without external dependencies