Skip to content

Secure Decentralized IoT Service Platform using Consortium Blockchain

License

Notifications You must be signed in to change notification settings

nexus-lab/iot-service-blockchain

Repository files navigation

IoT Service Blockchain

Overview

This repository contains the chaincode and SDKs of the IoT Service Blockchain project. IoT Service Blockchain is a secure decentralized IoT service platform based-on consortium blockchain technology. The chaincode provides a management interface of the IoT devices and services on the Hyperledger Fabric blockchain. The SDKs offer application developers to join the blockchain network with their IoT devices, define services of their devices, and request services from IoT devices.

Installation & Usage

  • Chaincode

    IoT Service Blockchain chaincode requires Hyperledger Fabric version 2.4 or above. The chaincode is located under chaincode directory. Follow Hyperledger Fabric's guide to deploy the chaincode to your Hyperledger Fabric blockchain.

  • Go SDK

    To install the Go SDK of IoT Service Blockchain, run:

    go get github.com/nexus-lab/iot-service-blockchain

    Refer to tests/e2e/go for usage examples of the Go SDK.

  • Java SDK

    To install the Java SDK of IoT Service Blockchain, you will first need to authenticate to GitHub Packages. Follow Authenticating to GitHub Packages for more information. Then, add this package as a dependency to your pom.xml:

    <dependency>
      <groupId>org.nexus-lab.iot-service-blockchain</groupId>
      <artifactId>sdk</artifactId>
      <version>0.0.4-SNAPSHOT</version>
    </dependency>

    Finally, run mvn install to complete the installation. Also, refer to tests/e2e/java for usage examples of the Java SDK.

  • JavaScript SDK

    To install the JavaScript SDK of IoT Service Blockchain, you will first need to authenticate to GitHub Packages. Follow Authenticating to GitHub Packages for more information. Then, set up the .npmrc file following Installing a package to let your package manager search for this package on the GitHub Package repository. Finally, run the following command to install the SDK:

    npm install @nexus-lab/iot-service-blockchain@0.0.5

    Also, refer to tests/e2e/javascript for usage examples of the JavaScript SDK.

Testing

Requirements

  • End-to-end tests: Docker & Docker Compose
  • Chaincode and Go SDK: Go version 1.16 and above
  • Java SDK: Java version 1.8 and above, Maven
  • JavaScript SDK: Node.js version 14 and above, Yarn

Run Unit Tests

  • Chaincode and Go SDK

    Run unit tests using the following command:

    go test -v ./...
  • Java SDK

    Run unit tests using the following command:

    mvn test
  • JavaScript SDK

    First, install the dependencies:

    yarn install

    Then, run unit tests using the following command:

    env TZ="America/New_York" yarn test

Run End-to-end Tests

The tests/scripts/fabric script provides simple commands that quickly creates a testing Hyperledger Fabric blockchain network.

To download and start the network, run:

./tests/scripts/fabric download
./tests/scripts/fabric network up

This will download necessary files and binaries to the .fabric and .explorer directories.

Use the following command to install the chaincode to the testing blockchain network:

./tests/scripts/fabric chaincode deploy

Then, run end-to-end tests using the following information:

  • Go SDK

    To run the end-to-end tests of Go SDK, execute:

    export FABRIC_ROOT=$(pwd)/.fabric
    go run ./tests/e2e/go/run.go
  • Java SDK

    To run the end-to-end tests of Java SDK, execute:

    export FABRIC_ROOT=$(pwd)/.fabric
    mvn install
    cd tests/e2e/java
    mvn compile exec:java -Dexec.mainClass="com.example.e2e.Run"
    cd -
  • JavaScript SDK

    To run the end-to-end tests of JavaScript SDK, execute:

    export FABRIC_ROOT=$(pwd)/.fabric
    yarn build
    env TZ="America/New_York" node ./tests/e2e/javascript/run.js

Finally, when the testings are done, use this command to shutdown the network and clean up:

./tests/scripts/fabric network down

Contributing

Please refer to CONTRIBUTING.md for the process of submitting pull requests to us.

License

This project is licensed under the GPL v3 License - see LICENSE for details.

Reference

If this work is helpful to you, please consider citing the following article:

@Article{s22218186,
  AUTHOR = {Zhang, Ruipeng and Xu, Chen and Xie, Mengjun},
  TITLE = {Secure Decentralized IoT Service Platform Using Consortium Blockchain},
  JOURNAL = {Sensors},
  VOLUME = {22},
  YEAR = {2022},
  NUMBER = {21},
  ARTICLE-NUMBER = {8186},
  URL = {https://www.mdpi.com/1424-8220/22/21/8186},
  ISSN = {1424-8220},
  DOI = {10.3390/s22218186}
}