On a fresh clone, you MUST init submodules and install Flow dependencies before running tests, otherwise all tests will fail:
git submodule update --init --recursive
flow deps installThis step is required because the test suite depends on Flow standard contracts (FungibleToken, FlowToken, etc.) that must be downloaded from the Flow network.
The Flow test framework has a known limitation where contracts persist between test runs, causing "cannot overwrite existing contract" errors. We've implemented fixes and workarounds to address this issue.
-
Fixed test files that were incorrectly using
Test.reset():cadence/tests/pool_creation_workflow_test.cdc- removed unnecessary resetcadence/tests/reserve_withdrawal_test.cdc- removed unnecessary reset
-
Created test runner script (
run_tests.sh) that handles contract persistence issues -
Added documentation explaining the root cause
# Make sure the script is executable
chmod +x run_tests.sh
# Run all tests individually with automatic cache clearing
./run_tests.shThis script:
- Runs each test file separately to avoid contract conflicts
- Clears Flow cache (
~/.flow) before each test - Shows clear pass/fail status for each test
- Returns appropriate exit codes for CI/CD
# Run specific test files one at a time
flow test ./cadence/tests/pool_creation_workflow_test.cdc
flow test ./cadence/tests/reserve_withdrawal_test.cdc
flow test ./cadence/tests/platform_integration_test.cdc
# ... etc# Clear Flow cache first
rm -rf ~/.flow
# Then run all tests
flow test --coverNote: This may still fail due to contract deployment conflicts between test files.
- ✅
./run_tests.shshould pass all files incadence/tests/*_test.cdconce dependencies are installed. - ✅ Individual files should also pass when run directly with
flow test <path/to/test_file.cdc>.
The snapshot pattern should be used like this:
access(all) var snapshot: UInt64 = 0
access(all)
fun setup() {
deployContracts()
// Take snapshot AFTER contracts are deployed
snapshot = getCurrentBlockHeight()
}
access(all)
fun testExample() {
// Reset to snapshot before running test
Test.reset(to: snapshot)
// ... test logic ...
}Important: Only use Test.reset() when you need to reset blockchain state between multiple test functions in the same file. Don't use it for the first test or when there's only one test.
- Use the test runner script or run tests individually
- Clear Flow cache:
rm -rf ~/.flow
- Make sure snapshot is taken AFTER contract deployment
- Don't use Test.reset() unless necessary
- This is expected due to contract persistence
- Use the test runner script for consistent results
Use the test runner script:
- name: Run Cadence Tests
run: |
chmod +x run_tests.sh
./run_tests.shThe script returns exit code 0 if all tests pass, 1 if any fail.