Skip to content

Commit cdde22e

Browse files
committed
add another test
1 parent 53f3a2e commit cdde22e

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

ffi/tests/basic.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use risc0_ethereum_contracts::encode_seal;
2020
use risc0_zkvm::{FakeReceipt, InnerReceipt, Receipt, ReceiptClaim};
2121

2222
#[test]
23-
fn main() {
23+
fn basic_usage() {
2424
let exe_path = env!("CARGO_BIN_EXE_risc0-forge-ffi");
2525
let args = ["prove", ECHO_PATH, "0xdeadbeef"];
2626
println!("{} {:?}", exe_path, args);
@@ -49,3 +49,37 @@ fn main() {
4949
let expect_seal = encode_seal(&expected_receipt).unwrap();
5050
assert_eq!(expect_seal, seal.to_vec());
5151
}
52+
53+
// It's important that `risc0-forge-ffi` only send to stdout the output to be consumed by forge
54+
// with the FFI cheatcode. If any extra output is sent, ABI decoding will fail.
55+
#[test]
56+
fn basic_usage_with_rust_log() {
57+
let exe_path = env!("CARGO_BIN_EXE_risc0-forge-ffi");
58+
let args = ["prove", ECHO_PATH, "0xdeadbeef"];
59+
println!("{} {:?}", exe_path, args);
60+
let output = Command::new(exe_path)
61+
.env_clear()
62+
// PATH is required so r0vm can be found.
63+
.env("PATH", std::env::var("PATH").unwrap())
64+
.env("RISC0_DEV_MODE", "1")
65+
.env("RUST_LOG", "debug")
66+
.args(args)
67+
.output()
68+
.unwrap();
69+
70+
println!("{:#?}", &output);
71+
72+
let output_bytes = hex::decode(output.stdout).unwrap();
73+
let (journal, seal) = <(Bytes, Bytes)>::abi_decode(&output_bytes, true).unwrap();
74+
75+
assert_eq!(journal, hex::decode("deadbeef").unwrap());
76+
let expected_receipt = Receipt::new(
77+
InnerReceipt::Fake(FakeReceipt::new(ReceiptClaim::ok(
78+
ECHO_ID,
79+
journal.to_vec(),
80+
))),
81+
journal.into(),
82+
);
83+
let expect_seal = encode_seal(&expected_receipt).unwrap();
84+
assert_eq!(expect_seal, seal.to_vec());
85+
}

0 commit comments

Comments
 (0)