stacks-network / clarity-wasm

`clar2wasm` is a compiler for generating WebAssembly from Clarity.
GNU General Public License v3.0
12 stars 12 forks source link

Property testing for define-functions #426

Closed ameeratgithub closed 1 week ago

ameeratgithub commented 3 months ago

closes #289

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 86.54%. Comparing base (13792d0) to head (35f129f). Report is 342 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #426 +/- ## ======================================= Coverage 86.54% 86.54% ======================================= Files 43 43 Lines 19192 19192 Branches 19192 19192 ======================================= Hits 16609 16609 Misses 1118 1118 Partials 1465 1465 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

ameeratgithub commented 3 months ago

@Acaccia could you take a look at it again?

ameeratgithub commented 3 months ago

The tests for the functions definitions don't test at all if the arguments are accessible. They should be used in the function body.

There are no tests to prove that any type could be returned from private and read-only functions. Same for public function, it could show more kind of return types than (response int).

I'm not sure I understood this. Consider following example

>> (define-public (func) 1)
<stdin>:1:1: error: public functions must return an expression of type 'response', found 'int'
Acaccia commented 3 months ago

@ameeratgithub

Your tests should make sure that all the function's arguments are accessible. I would personally write a function that takes any number of arguments and returns a tuple which uses them all. -> This test would prove that the function can take any number of arguments of any type and use them all in the function body.

I would also make a function that can take also any number of random arguments and returns a randomly generated value. -> This test would prove that a function can return any type.

For the public function, you can generate a random response value like this: response in (prop_signature(), prop_signature()).prop_flat_map(|(ok_ty, err_ty)| PropValue::from_type(TypeSignature::ResponseType(Box::new((ok_ty, err_ty)))))

ameeratgithub commented 3 months ago

@Acaccia thanks for the details. Hopefully it will be good now.

csgui commented 1 week ago

This was implemented by #289. Can be closed.