You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to test the behaviour of the ACIR optimisers using a #[test] in #6781 by making an integration test and put it under test_programs/noir_test_success, writing a test such as this:
fnmain(a:Field,b:Field,e:Field){let c = <complex expression using a and b>;assert_eq(c, e,"oh no, foo!");}#[test(should_fail_with = "foo")]fntest_foo(){main(10,20,100);}
My goal was to see some of optimisations reorder the expressions and lose track of where the assertion message was.
However, when I looked at the final ACIR there was just nothing to reorder as it all became just 1 ACIR opcode.
If instead of nargo test I used nargo compile, I could see there were multiple ACIR opcodes, but because test_foo gives the compiler extra information about a, b and e, it was able to perform deeper optimisations on it. But that meant I was testing a different circuit, although the side effects should be the same.
Ideally we want the option to test the code as it would be if it was invoked with execute. I can see the value in #[test] resulting in a circuit that is optimised for the exact code that appears in the test itself, but I would also like the option of writing a unit test to verify the behaviour of the actual circuit, without having to write a full integration test that takes its inputs from Prover.toml; in this instance that would not have worked anyway because I wanted to the execution to fail with an expected message, and I don't think the test_programs/execute_success handles that case.
NB the SSA was the same in both cases, it was the ACIR optimisation that worked differently. The std::hint::black_box hint also doesn't work on this, because its effect is limited to the SSA pass.
Happy Case
My proposal is to add an attribute similar to test_case which would be handled by nargo test to:
Find these like other test functions that take input
Instead of passing them to the fuzzer, parse the ABI encoded inputs from the attribute and invoke the test with those
In the above example, it would look something like this:
It could also support multiple such attributes (with an optional description), to invoke the test with multiple scenarios, similar to the Rust crate.
I left the #[test] there so that it can still provide the place for should_fail_with; this is different from the Rust version. The Rust version is also macro based, but in our case it would need to be supported by the framework itself, so that the compiler would treat the inputs as opaque witnesses.
Workaround
Yes
Workaround Description
The workaround in this case was to move the a, b and e variables into an input position so they don't get eliminated by the merge expression optimiser. When I did, the test was handled by the fuzzer, but then that one executes it 100 times, which I don't need, and I cannot specify the inputs.
Additional Context
No response
Project Impact
None
Blocker Context
No response
Would you like to submit a PR for this Issue?
Maybe
Support Needs
No response
The text was updated successfully, but these errors were encountered:
Problem
I wanted to test the behaviour of the ACIR optimisers using a
#[test]
in #6781 by making an integration test and put it undertest_programs/noir_test_success
, writing a test such as this:My goal was to see some of optimisations reorder the expressions and lose track of where the assertion message was.
However, when I looked at the final ACIR there was just nothing to reorder as it all became just 1 ACIR opcode.
If instead of
nargo test
I usednargo compile
, I could see there were multiple ACIR opcodes, but becausetest_foo
gives the compiler extra information abouta
,b
ande
, it was able to perform deeper optimisations on it. But that meant I was testing a different circuit, although the side effects should be the same.Ideally we want the option to test the code as it would be if it was invoked with
execute
. I can see the value in#[test]
resulting in a circuit that is optimised for the exact code that appears in the test itself, but I would also like the option of writing a unit test to verify the behaviour of the actual circuit, without having to write a full integration test that takes its inputs fromProver.toml
; in this instance that would not have worked anyway because I wanted to the execution to fail with an expected message, and I don't think thetest_programs/execute_success
handles that case.NB the SSA was the same in both cases, it was the ACIR optimisation that worked differently. The
std::hint::black_box
hint also doesn't work on this, because its effect is limited to the SSA pass.Happy Case
My proposal is to add an attribute similar to test_case which would be handled by
nargo test
to:In the above example, it would look something like this:
It could also support multiple such attributes (with an optional description), to invoke the test with multiple scenarios, similar to the Rust crate.
I left the
#[test]
there so that it can still provide the place forshould_fail_with
; this is different from the Rust version. The Rust version is also macro based, but in our case it would need to be supported by the framework itself, so that the compiler would treat the inputs as opaque witnesses.Workaround
Yes
Workaround Description
The workaround in this case was to move the
a
,b
ande
variables into an input position so they don't get eliminated by the merge expression optimiser. When I did, the test was handled by the fuzzer, but then that one executes it 100 times, which I don't need, and I cannot specify the inputs.Additional Context
No response
Project Impact
None
Blocker Context
No response
Would you like to submit a PR for this Issue?
Maybe
Support Needs
No response
The text was updated successfully, but these errors were encountered: