This document outlines how to run tests for the Fabric Token SDK.
To work with the SDK and run tests, you first need to clone the repository and set up your environment.
Clone the code and make sure it is on your $GOPATH.
(Important: we assume in this documentation and default configuration that your $GOPATH has a single root-directory!).
Sometimes, we use $FTS_PATH to refer to the Fabric Token SDK repository in your filesystem.
export FTS_PATH=$GOPATH/src/github.com/hyperledger-labs/fabric-token-sdk
git clone https://github.com/hyperledger-labs/fabric-token-sdk.git $FTS_PATHBefore running tests, ensure you have the necessary tools and environment set up.
Fabric Token SDK uses a system called NWO from Fabric Smart Client for its integration tests and samples to programmatically create a fabric network along with the fabric-smart-client nodes.
-
Install Tools:
make install-tools
After installing the tools, run the checks to verify that everything is in order:
make checks
-
Download Fabric Binaries: The integration tests require Hyperledger Fabric binaries.
In order for a fabric network to be able to be created you need to ensure you have downloaded the appropriate version of the hyperledger fabric binaries from Fabric Releases and unpack the compressed file onto your file system. This will create a directory structure of /bin and /config. You will then need to set the environment variable
FAB_BINSto thebindirectory.Do not store the fabric binaries within your fabric-token-sdk cloned repo as this will cause problems running the samples and integration tests as they will not be able to install chaincode.
Almost all the samples and integration tests require the fabric binaries to be downloaded and the environment variable
FAB_BINSset to point to the directory where these binaries are stored. One way to ensure this is to execute the following in the root of the fabric-token-sdk project:make download-fabric export FAB_BINS=$PWD/../fabric/bin
You can also use this to download a different version of the fabric binaries, for example:
FABRIC_VERSION=2.5 make download-fabric
-
Docker Images: Build the necessary Docker images for testing.
make testing-docker-images make docker-images
You can run unit tests using the following make targets:
- Standard Unit Tests:
make unit-tests
- Unit Tests with Race Detection:
make unit-tests-race
- Regression Unit Tests:
These tests ensure that recent changes have not reintroduced previously fixed bugs or broken existing functionality.
make unit-tests-regression
Integration tests are crucial for verifying the interaction between different components.
Run specific integration tests using the integration-tests-<target> pattern.
Here are some common integration test targets (refer to .github/workflows/tests.yml or integration/ folder for a full list):
dlog-fabric-t1fabtoken-fabric-t1nft-dlognft-fabtokendvp-fabtokeninterop-fabtoken-t1
To run the dlog-fabric-t1 test:
make integration-tests-dlog-fabric-t1For tests involving Fabric-X (starts with fabricx), you need additional setup:
make fxconfig configtxgen fabricx-docker-images
make integration-tests-fabricx-dlog-t1After running tests, especially integration tests that spin up Docker containers, you might want to clean up your environment.
# Clean up Docker artifacts (containers, volumes, networks) and generated files
make clean
# Remove all Docker containers (running and stopped)
make clean-all-containers
# Remove Fabric peer images
make clean-fabric-peer-images