gofractally / demo-clsdk

Demonstration of using the clsdk to build and test contracts
13 stars 2 forks source link

check should behave like assert #6

Closed 7flash closed 2 years ago

7flash commented 2 years ago

currently when check is failing in unit test, its still passing

tbfleming commented 2 years ago

If you're using act, then either assert or check inside a contract currently cause it to fail the test. If you're using expect, then you can fail the test if the contract doesn't assert, or if it asserts with the wrong error message.

tbfleming commented 2 years ago

I assume you're talking about eosio_assert or eosio::assert. C++'s assert isn't fully supported.

7flash commented 2 years ago

Correct, when I do check inside of the contract and expect in unit test, then it shows failed cases properly.

But if I do "check(false)" inside of unit test, it seems to be ignored, and still showing test as passed.

Temporary workaround I do when I want to check some tables and assert unit test, is creating additional actions in smart contract and invoking them inside of expect handler. But would be better if I can check tables in assert in unit test file directly.

tbfleming commented 2 years ago

check(false) within a test aborts execution of the tester. That prevents it from printing any messages which say the test pass. It also causes the cltester executable to return a non-0 exit code.

tbfleming commented 2 years ago

i.e. check(false) aborts the currently-executing wasm, whether that wasm is a contract (which a test case can detect) or a test wasm (which the test wasm itself can't detect since it aborted).

7flash commented 2 years ago

You are right, that happens as expected, thanks for support!

Actually the reason I was this issue was because didn't recompile unit test after adding "check(false)", can be closed now

image