-
Notifications
You must be signed in to change notification settings - Fork 42
Run Unit Tests Locally
You'll need docker, even if you'll run the tests without it. That's because tests in 0chain.net/smartcontract/dbs/event
uses docker to dynamically run a temporary database container.
Mockery is a tool to generate mock files for go tests. Please refer to the documentation here for installation on different platforms.
Rocksdb is used in both miner and sharder, and it's a persistent key-value store. To install on macOS or Linux (steps for version 8.1.1):
wget https://github.com/facebook/rocksdb/archive/refs/tags/v8.1.1.tar.gz
tar -xvf v8.1.1.tar.gz
cd rocksdb-8.1.1
sudo make install-shared
Note: For macOS, especially Apple Silicon processors, libraries that you install using homebrew is save in
/opt/homebrew/lib
, which is not readable by ld compiler (the one used to compile go for build and test), so you'll need either to add this directory to ld path, or just add symlinks to the libraries you'll need to/usr/local/lib
:ln -fs /opt/homebrew/lib/libzstd.dylib /usr/local/lib/libzstd.dylib
forlztsd
orlibzstd
as an example. You'll need to do so for the following libraries:libzstd
,liblz4
,libsnappy
,libcrypto
,libgmp
libgmpxx
. Please add to this wiki if you find any other libraries. If you find any trouble, feel free to communicate it in ochain-core channel.
Note: For Ubuntu Users, If you have all the dependencies installed on your machine, make sure they're all up-to-date. You can run
sudo apt-get update
Refer to this page for more on rocksdb installation
Those are cryptography libraries. To install for macOS/Linux:
git clone --recursive https://github.com/herumi/bls
cd bls
sudo make -C mcl -j 4 lib/libmclbn256.dylib install
sudo make MCL_DIR=./mcl MCL_USE_GMP=0 BLS_ETH=1 -j 4 install
We have a special docker compose project that runs unit testing, regardless of your device's OS or architecture, it builds an environment for the tests and runs them.
Note: You need Docker installed on your machine.
Bring the base docker container up for the unit tests:
cd 0chain
./docker.local/bin/build.base.sh
Run all the unit tests in the 0chain
repo:
./docker.local/bin/unit_test.sh
Or, you can specify a specific module to run tests against
./docker.local/bin/unit_test.sh 0chain.net/smartcontract/dbs/event
It automatically generates mock files using mockery, this will take some time. If you need to disable this (needs to be run at least once), use --no-mocks
flag.
./docker.local/bin/unit_test.sh --no-mocks
- Generate mock files by running
./generate_mocks.sh
at the root of 0chain repo. - Run the
go test
command (rungo help test
if you need to learn more about it), but you need to add the tagbn256
for it, so will looks likego test -tags bn256 .....
. You need to configure that in your IDE if you're going to use it for testing. In VSCode, you can configure it by adding this to.vscode/settings.json
:"go.buildTags": "bn256"
Please don't hesitate to edit, comment or report any issue in 0chain-core channel.
- Home
- Introduction
- Architecture
- 0Chain Smart Contracts
- Help