Coder Social home page Coder Social logo

asararatnakar / fabric_v1_chaincode_instructions Goto Github PK

View Code? Open in Web Editor NEW
14.0 4.0 10.0 45 KB

How to test Fabric V1.0 based chaincode

Shell 100.00%
howtotestchaincode chaincodecallingchaincode fabricchaincode marblechaincodecommands testchaincodeonnonvagrant calling-chaincode-to-chaincode chaincodewithoutchannel

fabric_v1_chaincode_instructions's Introduction

How to test hyperledger fabric V1.0 chaincode from CLI

How to test your chaincode from Vagrant :

You wrote some chaincode on Fabric V1.0 and now you wanted to test your chaincode with simple of steps of creating a channel configuration , create channel and join channel ...?

Follow are the instructions:


Pre-requisites:

mkdir -p $GOPATH/src/github.com/hyperledger

cd $GOPATH/src/github.com/hyperledger

git clone https://github.com/hyperledger/fabric.git

rm -rf /var/hyperledger/*

Build native binaries

cd fabric/devenv

vagrant up && vagrant ssh

cd $GOPATH/src/github.com/hyperledger/fabric

make peer orderer

NOTE: If required do make clean and build the binaries


Vagrant Terminal Tab 1:

Start the Orderer

ORDERER_GENERAL_GENESISPROFILE=SampleSingleMSPSolo orderer


Vagrant Terminal Tab 2:

Start the peer

peer node start


Vagrant Terminal Tab 3:

This uses chaincode example program example02 Install chaincode on the peer

peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02


Generate channel configuration (transaction)

configtxgen -channelID myc -outputCreateChannelTx myc.tx -profile SampleSingleMSPChannel


Create channel

peer channel create -o 127.0.0.1:7050 -c myc -f myc.tx -t 10


Join channel

peer channel join -c myc -f myc.block


Instantiate chaincode

peer chaincode instantiate -o 127.0.0.1:7050 -C myc -n mycc -v 1.0 -c '{"Args":["init","a", "100", "b","200"]}'

After succesful chaincode instantiation, you would see chaincode container comes up. docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
ba2746fd32bf        dev-jdoe-mycc-0    "chaincode -peer.a..."   6 seconds ago       Up 5 seconds                            dev-jdoe-mycc-0

Invoke

Issue an invoke to move "10" from "a" to "b":

peer chaincode invoke -o 127.0.0.1:7050 -C myc -n mycc -c '{"Args":["invoke","a","b","10"]}'

Wait a few seconds for the operation to complete


Query

Query for the value of "a"

peer chaincode query -n mycc -c '{"Args":["query","a"]}'


cleanup

Don't forget to clear ledger after each run!

rm -rf /var/hyperledger/*

And may be chaincode containers(optional)

docker rm -f $(docker ps -aq)

docker rmi -f $(docker images | grep "dev-jdoe" | awk '{print $3}')

Troubleshoot

??


few more samples:

  • commands to create channel and test chaincode on the custom channel Instructions here

  • commands to test chaincode upgrade functionality, instructions here

  • run chaincode in dev mode, instructions here

  • commands for Calling chaincode to chaincode, instructions below

with default channel

with non-default channel

  • commands to test chaincode on non-vagrant environment (ubuntu) , details here

  • commands to test marbles02 chaincode, Instructions here

fabric_v1_chaincode_instructions's People

Contributors

asararatnakar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fabric_v1_chaincode_instructions's Issues

Cannot get string data from another chaincode

Hello,

Example. I have 2 chaincode (A, B)

  • chaincode A: generate a password hash (string) using bcrypt
  • chaincode B: invoke chaincode A and get the password hash
  • Test 1: I call chaincode A and get the password hash likes this: "$2a$10$e9lha95xDRV0EfQQIW9zMecZqspeA5aaI8JUf36vgUmoKXtmzs"
  • Test 2: I call chaincode B to get the password hash likes this: "0Y0═�H�=╗╔�H�=╚╔╚B"

Anyone, please could you tell me what happened? How to fix?
Thanks a lot.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.