简体   繁体   中英

Hyperledger Fabric nodejs chaincode unit testing in nodejs,

I have developed a custom chaincode for my application in nodejs, I need to perform unit test to validate the functionality using any frameworks such as jest mocha chai, etc. I did did find Hyperledger fabric mock stub testing but it doesnt support fabric-contract-api as far as my knowledge. I also read about some truffle method but did not try. Is there any way to test chaincode in nodejs.

Hyperledger Fabric provides an SDK for Node fabric-sdk-node that allows you to submit transactions or query the contents of a ledger.

You can make use of the SDK along with the mocha testing framework and Chai for assertions for unit testing.

It's a little more complicated than just using Mocha and Chai. Testing the actual interfaces require you to mock those interfaces so you can change the conditions on which they operate. One of the SDK-Node maintainers created this example to demonstrate using Sinon to mock the chaincode stub: https://github.com/ampretia/fabric-application-examples/tree/master/contracts/cp-ts-extended/test

You can also use the IBM Blockchain Platform Extension for VSCode (just search blockchain in the VSCode extensions tab) to generate a contract in Node which will have prefilled functions and example tests for those function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM