Re: Test cases for Chaincode written with fabric-contract-api

Brett T Logan <brett.t.logan@...>

With the new chaincode model you can simply use standard mocking tools in your language of choice. While I don't have experience with mocking NodeJS, a quick Google search show's multiple mocking tools that can be used to do the job.
In Golang this looks something like this where I've mocked the actual interface you need to test chaincode:
//go:generate counterfeiter -o mock/transaction.go -fake-name TransactionContext . TransactionContext
type TransactionContext interface {
And then you simply call:
"go generate ." 
from the directory and you get an auto generated mock you can use for testing. The same general principle applies across languages, just implement it using the language and framework of you choice. 
Brett Logan
Software Engineer, IBM Blockchain
Phone: 1-984-242-6890

----- Original message -----
From: "Abhijeet Bhowmik" <abhijeet@...>
Sent by: fabric@...
To: fabric@...
Subject: [EXTERNAL] [Hyperledger Fabric] Test cases for Chaincode written with fabric-contract-api
Date: Sun, Jul 5, 2020 1:08 PM
Dear all,
Hope everyone is doing well. I have run into a dire situation where I have a bulk of chaincode written but can't find a way to do offline testing. Earlier we used fabric-shim for cc development but now switched to fabric-contract-api due to cleanliness and easy handling of chaincode. But, what we used earlier to write test ''@theledger/fabric-mock-stub" now no longer works as it expects ChaincodeInterface and what we have is a class extending Contract class. So now the question arises, how could we do it for Contract API? Deploying untested chaincode is unaffordable. I have gone through documentation, online forums and other helpful resources but to no avail. Please advise.
Thank you. Regards.
Abhijeet Bhowmik

Join to automatically receive all group messages.