Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an example of unit-tests #27

Open
NickVolynkin opened this issue Jun 19, 2023 · 1 comment
Open

Add an example of unit-tests #27

NickVolynkin opened this issue Jun 19, 2023 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@NickVolynkin
Copy link
Contributor

NickVolynkin commented Jun 19, 2023

A normal development workflow includes writing and running unit-tests. We should have an example of tests in this template.

For reference, see https://github.com/color-typea/lido-zkllvm-accounting-curcuit/tree/minimal_setup_with_tests_and_crypto3 (commit color-typea/lido-zkllvm-accounting-circuit@41327cb)

Updated version of this branch is in https://github.com/NilFoundation/zkllvm-template/tree/minimal_setup_with_tests_and_crypto3 and #28

Smaller example is shown in #29

@color-typea
Copy link
Contributor

Some additional insight:

Command to build a circuit in main (as seen by adding VERBOSE=1 to build command: VERBOSE=1 cmake --build ./build --target template):

cd /opt/circuit/build/src && clang -target assigner -Xclang -no-opaque-pointers -Xclang -fpreserve-vec3-type -std=c++20 -D__ZKLLVM__ -I/opt/circuit/libs/crypto3/libs/algebra/include -I/opt/circuit/build/include -I/opt/boost_1_76_0/include -I -I/opt/circuit/libs/crypto3/libs/block/include -I/opt/boost_1_76_0/include -I/opt/circuit/libs/crypto3/libs/codec/include -I/opt/circuit/libs/crypto3/libs/containers/include -I/opt/circuit/libs/crypto3/libs/hash/include -I/opt/circuit/libs/crypto3/libs/kdf/include -I/opt/circuit/libs/crypto3/libs/mac/include -I/opt/circuit/libs/crypto3/libs/marshalling/core/include -I/opt/circuit/libs/crypto3/libs/marshalling/algebra/include -I/opt/circuit/libs/crypto3/libs/marshalling/multiprecision/include -I/opt/circuit/libs/crypto3/libs/marshalling/zk/include -I/opt/circuit/libs/crypto3/libs/math/include -I/opt/circuit/libs/crypto3/libs/modes/include -I/opt/circuit/libs/crypto3/libs/multiprecision/include -I/opt/circuit/libs/crypto3/libs/passhash/include -I/opt/circuit/libs/crypto3/libs/pbkdf/include -I/opt/circuit/libs/crypto3/libs/pkmodes/include -I/opt/circuit/libs/crypto3/libs/pkpad/include -I/opt/circuit/libs/crypto3/libs/pubkey/include -I/opt/circuit/libs/crypto3/libs/random/include -I/opt/circuit/libs/crypto3/libs/stream/include -I/opt/circuit/libs/crypto3/libs/vdf/include -I/opt/circuit/libs/crypto3/libs/zk/include -I/opt/circuit/src -emit-llvm -O1 -S -o lido_accounting_circuit.ll /opt/circuit/src/circuit.cpp

Command to build tests:

cd /opt/circuit/build/test && /usr/bin/c++ -DBOOST_ALL_NO_LIB -DBOOST_CONTAINER_DYN_LINK -DBOOST_RANDOM_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_TEST_DYN_LINK=1 -DBOOST_TEST_NO_AUTO_LINK=1 -DBOOST_UNIT_TEST_FRAMEWORK_DYN_LINK -DCRYPTO3_CODEC_BASE58 -DCRYPTO3_HAS_AVX2 -DCRYPTO3_HAS_CHACHA_AVX2 -DCRYPTO3_HAS_RIJNDAEL_NI -DCRYPTO3_VDF_BOOST -I/opt/circuit/test -I/opt/circuit/src -I/opt/circuit/libs/crypto3/libs/algebra/include -I/opt/circuit/build/include -I/opt/circuit/libs/crypto3/libs/hash/include -I/opt/circuit/libs/crypto3/libs/multiprecision/include -I/opt/circuit/libs/crypto3/libs/marshalling/algebra/include -I/opt/circuit/libs/crypto3/libs/marshalling/multiprecision/include -I/opt/circuit/libs/crypto3/libs/marshalling/core/include -I/opt/circuit/libs/crypto3/libs/block/include -I/opt/circuit/libs/crypto3/libs/codec/include -I/opt/circuit/libs/crypto3/libs/containers/include -I/opt/circuit/libs/crypto3/libs/kdf/include -I/opt/circuit/libs/crypto3/libs/mac/include -I/opt/circuit/libs/crypto3/libs/modes/include -I/opt/circuit/libs/crypto3/libs/marshalling/zk/include -I/opt/circuit/libs/crypto3/libs/zk/include -I/opt/circuit/libs/crypto3/libs/math/include -I/opt/circuit/libs/crypto3/libs/pubkey/include -I/opt/circuit/libs/crypto3/libs/pkpad/include -I/opt/circuit/libs/crypto3/libs/passhash/include -I/opt/circuit/libs/crypto3/libs/pbkdf/include -I/opt/circuit/libs/crypto3/libs/pkmodes/include -I/opt/circuit/libs/crypto3/libs/random/include -I/opt/circuit/libs/crypto3/libs/stream/include -I/opt/circuit/libs/crypto3/libs/vdf/include -isystem /opt/boost_1_76_0/include -O3 -DNDEBUG -fconstexpr-ops-limit=4294967295 -mavx2 -maes -mpclmul -mssse3 -O3 -fno-rtti -std=gnu++20 -MD -MT test/CMakeFiles/lib_test.dir/lib.cpp.o -MF CMakeFiles/lib_test.dir/lib.cpp.o.d -o CMakeFiles/lib_test.dir/lib.cpp.o -c /opt/circuit/test/lib.cpp

Note:

  1. Different compilers - "main" build uses clang, "test" build uses c++
  2. Main sets __ZKLLVM__ definition, while tests do not - and it is used throughout crypto3 (e.g. this place in crypto3::hash might be directly relevant)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants