Reputation: 21
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.
Upvotes: 1
Views: 987
Reputation: 505
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.
Upvotes: 1
Reputation: 198
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.
Upvotes: 0