paint-brush
Test Your Blockchain On Google Cloud Using Hyperledger Caliper [A How To Guide]by@rafaelbelchior
1,936 reads
1,936 reads

Test Your Blockchain On Google Cloud Using Hyperledger Caliper [A How To Guide]

by Rafael BelchiorNovember 9th, 2019
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

This article provides a 101 guide on how to use Hyperledger Caliper (commit 302665) on Google Cloud. The guide tackles the scenario of testing a. blockchain framework which facilitates the development of. Hyperledgers Fabric applications. This testing process applies to all blockchains supported by Hyperledged. Caliper is available on the Google Cloud, with a free trial grant from the Linux Foundation. For example, Caliper was created by Rafael Belchior, a PhD researcher (Blockchain)

Company Mentioned

Mention Thumbnail

Coin Mentioned

Mention Thumbnail
featured image - Test Your Blockchain On Google Cloud Using Hyperledger Caliper [A How To Guide]
Rafael Belchior HackerNoon profile picture

I am a 🇵🇹 PhD researcher @ Técnico Lisboa, where I teach User Centered Design. I am being a mentor at the Hyperledger Fabric Based Access Control project, supported and funded by Hyperledger and the Linux Foundation 🔥.

Please make sure to check my blockchain projects on my Github sponsors page 🚀 💪

Testing blockchain applications ⛓️ can be cumbersome, mainly because they are complex, resource-demanding distributed systems. Testing your blockchain app on the cloud might improve the efficiency of the testing process, as well as achieving more realistic test environments.

This article provides a 101 guide on how to use Hyperledger Caliper (commit 302665) on Google Cloud, tackling the scenario of testing a Hyperledger Composer application, a blockchain framework which facilitates the development of Hyperledger Fabric applications. Nonetheless, this testing process applies to all blockchains supported by Hyperledger Caliper (Hyperledger BurrowHyperledger FabricHyperledger IrohaHyperledger Sawtooth and more to come).

Setting Up The Testing Environment

Create a private repository (e.g., on Github).Fork the Hyperledger Caliper project to your private repo:

1. Create a private repository (e.g., on Github).
2.Fork the Hyperledger Caliper project to your private repo:

git clone --bare https://github.com/hyperledger/caliper.git
cd caliper.git
git push --mirror https://github.com/USERNAME/CALIPER-PRIVATE-REPO.git
cd ..
rm -rf caliper.git

3. Clone your private repo:

git clone https://github.com/USERNAME/CALIPER-PRIVATE-REPO.git

4. On CALIPER-PRIVATE-REPO/packages/caliper-samples/benchmark/composer , create a folder with the name of your application, e.g. my-network.

5. On the my-network folder, paste the contents of the configuration and test files from this repository. On a future article, I will explain how to write tests (my-network.js) and benchmark configurations (config.yaml).

6. You should have a developed business network using Composer (the BNA archive). If you have not developed a business network, you can still configure Caliper to test default business networks.

On CALIPER-PRIVATE-REPO-justicechain/packages/caliper-samples/src/contract/composer, create a folder named my-network. Paste your business network archive files (decompressed BNA file) inside the folder. You should have a lib folder, a models folder, and the files package.json, permission.acl and optionally, a README.md.

jsonNote that on package.json, the name and version of the network have to coincide with the one on composer.json. Example package.json:

{  
   "engines":{  
      "composer":"^0.20.0"
   },
   "name":"my-network",
   "version":"0.2.6-deploy.1",
 
 ... ETC

7. You have the necessary files to test your app. Push them to your repository:

git add *
git commit -m"add benchmark files"
git push origin master

Setting Up Google Cloud

1. Create an account on Google Cloud. New accounts can apply for a free trial grant. Create a project, and activate the Compute Instance API.

2. At Compute Engine -> VM Instances, click on Create a new instance.

3. Start your instance.

4. Click on Connect — SSH.

5. Install the prerequisites for Hyperledger Caliper (thanks Daz Wilkin):

sudo apt-get update
sudo apt-get install \
    linux-image-extra-$(uname -r) \
    linux-image-extra-virtual
sudo apt-get update
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
sudo apt-get update
sudo apt-get install docker-ce
sudo usermod -aG docker $USER
sudo systemctl enable docker
docker --version
sudo curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Golang (optional)
VERSION=1.9.1
OS=linux
ARCH=amd64
sudo curl \
--location https://golang.org/dl/go$VERSION.$OS-$ARCH.tar.gz \
--output go$VERSION.$OS-$ARCH.tar.gz
sudo tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
export PATH=$PATH:/usr/local/go/bin
go version

6. Clone your private repository with Caliper and your blockchain app to your Google Compute instance.

Testing your Application

To run your benchmark, navigate to caliper/packages/caliper-samples.

To benchmark your application with CouchDB run:
caliper benchmark run -w ./ -c benchmark/composer/justice/config.yaml -n benchmark/composer/justice/composer.json

To benchmark your application with LevelDB run:
caliper benchmark run -w ./ -c benchmark/composer/justice/config.yaml -n benchmark/composer/justice/composer-level.json

The results of the benchmark will be reported on the terminal.

Do not forget to stop your machines in Google Cloud after finishing the experiments or else 💸.

Next Steps

Thanks very much for reading. You Rock 💪.

If you like blockchain and open source, be sure to support my work on Github sponsors page 🚀 🙏