risc0 / risc0-foundry-template

Template for integrating RISC Zero and Ethereum using Foundry and Bonsai
https://risczero.com
90 stars 54 forks source link

Failures in forge test not being caught #130

Open austinabell opened 1 month ago

austinabell commented 1 month ago

I might be missing something here, but adding a panic in the guest does not make any of the tests fail:

diff --git a/methods/guest/src/bin/is_even.rs b/methods/guest/src/bin/is_even.rs
index 9d834b6..0dba652 100644
--- a/methods/guest/src/bin/is_even.rs
+++ b/methods/guest/src/bin/is_even.rs
@@ -19,17 +19,18 @@ use alloy_sol_types::SolValue;
 use risc0_zkvm::guest::env;

 fn main() {
diff --git a/methods/guest/src/bin/is_even.rs b/methods/guest/src/bin/is_even.rs
index 9d834b6..19b1163 100644
--- a/methods/guest/src/bin/is_even.rs
+++ b/methods/guest/src/bin/is_even.rs
@@ -19,17 +19,5 @@ use alloy_sol_types::SolValue;
 use risc0_zkvm::guest::env;

 fn main() {
-    // Read the input data for this application.
-    let mut input_bytes = Vec::<u8>::new();
-    env::stdin().read_to_end(&mut input_bytes).unwrap();
-    // Decode and parse the input
-    let number = <U256>::abi_decode(&input_bytes, true).unwrap();
-
-    // Run the computation.
-    // In this case, asserting that the provided number is even.
-    assert!(!number.bit(0), "number is not even");
-
-    // Commit the journal that will be received by the application contract.
-    // Journal is encoded using Solidity ABI for easy decoding in the app contract.
-    env::commit_slice(number.abi_encode().as_slice());
+    panic!("test");
 }

output:

~/dev/ris/risc0-foundry-template (main|✚1) 🌲 forge test -vvv
[⠊] Compiling...
No files changed, compilation skipped

Ran 2 tests for tests/EvenNumber.t.sol:EvenNumberTest
[PASS] test_SetEven() (gas: 294609)
Logs:
  Deployed RiscZeroGroth16Verifier to 0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f

[PASS] test_SetZero() (gas: 274756)
Logs:
  Deployed RiscZeroGroth16Verifier to 0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f

Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 92.60s (148.42s CPU time)

Ran 1 test suite in 92.61s (92.60s CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)
linear[bot] commented 1 month ago

WEB3-53 Failures in forge test not being caught

nategraf commented 1 month ago

So, I'm guessing this is because you are not running cargo build after making that change. We don't have any mechanism in place to build the guest when someone runs forge build and forge test right now. This is a good issue to raise though, because I am sure other folks will trip over this.

austinabell commented 1 month ago

ah, you're right, that was dumb. I swear I had rebuilt before running test.

Feel free to close, but sounds like you may want to keep this open?

nategraf commented 1 month ago

I want to bring it up for discussion at the next web3 sync. Maybe there is a way we can ensure that the ELF elf is up to date when forge test runs.