snarkOS icon indicating copy to clipboard operation
snarkOS copied to clipboard

[Bug] A test in the cli package fails when testing the entire workspace

Open kaimast opened this issue 9 months ago • 4 comments

🐛 Bug Report

Running individual tests works fine, but when testing the entire workspace, test_parse_development_and_genesis in cli fails with the following error:

thread 'commands::start::tests::test_parse_development_and_genesis' panicked at cli/src/commands/start.rs:921:82:
called `Result::unwrap()` on an `Err` value: Invalid block metadata: {"network":0,"round":0,"height":0,"cumulative_weight":"0","cumulative_proof_target":"0","coinbase_target":536870911,"proof_target":134217728,"last_coinbase_target":536870911,"last_coinbase_timestamp":1725462000,"timestamp":1725462000}
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This is not a huge problem as CircleCI runs the tests individually, but might confuse new contributors. It looks like there is an inconsistency in how feature flags are set (or not set), which could cause other problems in the future.

Steps to Reproduce

Run cargo test --package snarkos-cli commands::start::tests::test_parse_development_and_genesis, which should succeed, and then cargo test --workspace commands::start::tests::test_parse_development_and_genesis.

Both commands will run the same unit test, but the --workspace flag causes the test to break. Your output should look like the following:

~> cargo test --package snarkos-cli commands::start::tests::test_parse_development_and_genesis
    Finished `test` profile [optimized + debuginfo] target(s) in 0.41s
     Running unittests src/lib.rs (/Users/kaimast/dev/snarkOS/target/debug/deps/snarkos_cli-fe91258e0e9b0cb4)

running 1 test
test commands::start::tests::test_parse_development_and_genesis ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 30 filtered out; finished in 0.22s

~> cargo test --workspace commands::start::tests::test_parse_development_and_genesis
   Compiling snarkos v3.3.2 (/Users/kaimast/dev/snarkOS)
    Finished `test` profile [optimized + debuginfo] target(s) in 26.61s
     Running unittests snarkos/main.rs (/Users/kaimast/dev/snarkOS/target/debug/deps/snarkos-319e0b736a923806)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running unittests src/lib.rs (/Users/kaimast/dev/snarkOS/target/debug/deps/snarkos_account-5a59c922ae1bfbce)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 3 filtered out; finished in 0.00s

     Running unittests src/lib.rs (/Users/kaimast/dev/snarkOS/target/debug/deps/snarkos_cli-6124789f1cb22f10)

running 1 test
test commands::start::tests::test_parse_development_and_genesis ... FAILED

failures:

---- commands::start::tests::test_parse_development_and_genesis stdout ----
thread 'commands::start::tests::test_parse_development_and_genesis' panicked at cli/src/commands/start.rs:921:82:
called `Result::unwrap()` on an `Err` value: Invalid block metadata: {"network":0,"round":0,"height":0,"cumulative_weight":"0","cumulative_proof_target":"0","coinbase_target":536870911,"proof_target":134217728,"last_coinbase_target":536870911,"last_coinbase_timestamp":1725462000,"timestamp":1725462000}
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    commands::start::tests::test_parse_development_and_genesis

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 30 filtered out; finished in 0.00s

error: test failed, to rerun pass `-p snarkos-cli --lib`

Expected Behavior

All tests should pass regardless of how cargo test was invoked.

Your Environment

  • This was tested on most recent staging and before the latest upgrade to the snarkVM dependency
  • The behavior was observed on the current MSRV 1.83
  • I noticed this first on OSX Sierra, but could reproduce it on a clean checkout on my Arch Linux machine as well.

kaimast avatar Mar 19 '25 19:03 kaimast

More context to narrow down the root of the problem. Some tests require the test_targets feature flag (which lowers the coinbase targets), while other tests break if that flag is set.

Running workspace-wide tests will set the test _targets flag for all builds and, thus, break some tests. Most likely, we would need to change how flags are set/used in snarkVM to fix this.

kaimast avatar Mar 26 '25 20:03 kaimast

@kaimast I suppose you meant macOS Sequoia and not Sierra (which is very very old 😅).

Can reproduce.

joske avatar Apr 10 '25 13:04 joske

Established that it's the test feature that is responsible, not test_targets. It's not clear to me why the test feature is not enabled when testing with -p. I would assume it would be.

joske avatar Apr 10 '25 14:04 joske

When the test feature is enabled on snarkVM, this lowers the targets, but the genesis bytes are still using the high targets, so the metadata validation fails. To fix, we should have a way to have Network::genesis_bytes() return something different when test is enabled. Probably lower priority for now than some other bugs, parking for now.

joske avatar Apr 11 '25 08:04 joske