Composer Configuration
The latest supported version of Hyperledger Composer is v0.20
Hyperledger Composer is a set of development tools to assist in the building of blockchain business applications. When a Business Network Archive is deployed into a blockchain system using the Composer tooling, the resulting chaincode includes both the Composer runtime (which is generic) and the user defined business network. Consequently the performance of the business application is determined by both the Composer runtime and the user defined business network.
Installing Composer dependencies
The framework has been verified with the following dependencies:
"composer-admin": "0.20.0",
"composer-client": "0.20.0",
"composer-common": "0.20.0",
"fabric-ca-client": "1.2.0",
"fabric-client": "1.2.0",
In order to configure your local system to run tests on static (published) versions, it is recommended to update the Caliper package.json to import the version of Composer packages (composer-client, composer-admin and composer-common) that you wish to test, and the relevant versions of fabric-ca-client and fabric-client.
In order to configure your system to run tests on unpublished version, for instance testing the impact of a code change in a local repository, it is necessary to:
- use an npm proxy such as Verdaccio to host the latest code
- update the package information in the Caliper project to reflect the unpublished version that are to be tested
- perform an npm install in the Caliper project in order to retrieve the latest code A point of note here is that during the chaincode instantiation process using Composer, as the chaincode is built, it will perform an npm install of the latest Composer code that matches the version of the Composer code that invoked the process. Due to this it is necesary to ensure that for each system the chaincode is being instantiated on, an npm proxy that can make the required code available is present.
Composer Code Locations
The Composer contribution to Caliper is contained within three folders:
/Caliper/benchmark/composer, which contains the test runner and all tests/Caliper/src/composer, which comprises the Composer specific code that uses the Caliper interfaces/Caliper/contract/composer, which contains the business network files to be used in tests
Running a Composer Performance Test
As per the Caliper framework, tests are run based on configuration files. These files are used to create a (Fabric) Blockchain topology and run a series of tests with a target tps.
The sample configuration file /caliper/benchmark/composer/config-composer.json indicates how a test should be run:
- Blockchain
typeis ‘composer’ and the blockchainconfigis pointed to a required composer.config file within a folder that contains a json specifiction of a desired test network topology. - The
startandendcommands reflect the same folder location for the target topology - The
roundsindicate the testlabelto be run and hold a location to the test script itself as thecallback
Points to note:
- The test
labelmust match a correspondingchaincodestag that is present within the network topology configration file.
To run a Composer based test, on a published set of versions, the required process is:
- npm install, having specified the required Hyperledger Fabric/Composer versions
- navigate to /caliper/benchmark/composer
- run
node main.js -c my-config.json
Following the command issue, the Caliper bench-flow process will execute, targeting the Composer tests specified within a config file. If no config file is passed, it will default to using config-composer.json.
Testing Your own Business Network Definition
Examples for existing Business Networks are provided within the /caliper/benchmark/composer/composer-samples directory. To test your own Business Network, you must:
- Place your Business Network files into a folder within
caliper/src/contract/composer. The name of the folder that holds your Buinsess Network files should be named the same as your Business Network and represents thechaincodethat is deployed. - Add the new Business Network within the network topology file as a
chaincodeto deploy - Create a test script that includes an
init,runandendphase - Add the new test script to the test config file as a test round, making sure that the
labelmatches the Business Network name and that specified in the network topologychaincodes, and that the correctcallbackis specified. - If a Business Network has multiple transactions that are to be tested, it is possible to pass a named transaction within the test round
arguments.
If modifying the existing config-composer.json file, then:
- Modify
config-composer.json- Change
rounds.labelto be the name of the folder insidecaliper/src/contract/composerthat contains your Business Network files - Change
rounds.callbackto be the location of your test script - Change
rounds.argumentsto provide any required arguments to your test
- Change
- Modify the corresponding
composer.jsonfile identified inconfig-composer.jsonunderblockchain.configto list (or replace) your business network name in thecomposer.chaincodesarray
Creating Tests For Your Business Network
When creating tests for a business network, it is important to consider the system under test in order to prevent deadlocks and access denial.
For instance, if the desire is to test the update of an Asset, then it is not recommended to try updating the same asset concurrently. Instead it is necessary to create a set of assets to work with during the init phase and then update each asset within a single instance of the test run. In such instances the test should be driven under txNumber mode and the number of assets created in the test should ideally match the number of transactions specified within txNumber.