{"_id":"@apex-pub/fabric-mock-stub","_rev":"16-0fd8cb0ae5161e207486b03b672e8ef8","name":"@apex-pub/fabric-mock-stub","dist-tags":{"latest":"1.4.1-3","canary":"1.4.1-4-alpha.5f94f88e"},"versions":{"1.0.0":{"name":"@apex-pub/fabric-mock-stub","version":"1.0.0","description":"Mock implementation of the hyperledger fabric-shim package for testing","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npm run clean && tsc","test":"mocha -r ts-node/register test/**/*.spec.ts --reporter spec","test:coverage":"nyc --no-clean mocha -r ts-node/register test/**/*.spec.ts --reporter spec","report-coverage":"nyc report --reporter=text-lcov > coverage.lcov && codecov","lint":"tslint --fix -c tslint.json './src/**/*.ts'","clean":"rimraf dist","prepare":"npm run build","generate:docs":"rimraf docs && typedoc src --out docs --target ES6 --excludePrivate && touch docs/.nojekyll && touch docs/modules/.nojekyll"},"keywords":[],"license":"MIT","devDependencies":{"@types/chai":"^4.0.4","@types/lodash":"^4.14.104","@types/mocha":"^5.2.1","@types/node":"^16.11.1","@types/winston":"^2.3.8","chai":"^4.1.2","codecov":"^3.0.4","coveralls":"^3.0.0","husky":"^0.15.0-rc.8","istanbul":"^0.4.5","mocha":"^5.0.3","nyc":"^12.0.2","rimraf":"^2.6.2","tslint":"5.9.1","typedoc":"^0.16.2"},"dependencies":{"@theledger/couchdb-query-engine":"^2.4.4","@types/google-protobuf":"^3.7.2","fabric-shim":"2.5.4","google-protobuf":"^3.6.1","lodash":"^4.17.11","ts-node":"^8.6.2","typescript":"4.8","winston":"^2.4.0"},"publishConfig":{"registry":"https://registry.npmjs.org","access":"public"},"husky":{"hooks":{"pre-push":"npm run test && git add ."}},"nyc":{"include":["src/**/*.ts"],"extension":[".ts"],"require":["ts-node/register"],"reporter":["text"],"sourceMap":true,"instrument":true},"_id":"@apex-pub/fabric-mock-stub@1.0.0","_nodeVersion":"10.18.1","_npmVersion":"6.13.4","dist":{"integrity":"sha512-1OZ8XWmSKcQuKgnv80Y0sF/wIyEuacWdhUoFkxXgbq3d5PawRL7CQY/J3iJk11BgpyluI0YuCXSTCbGjVNciMA==","shasum":"b59f791f5d382ccafbc26efddfc715b25e7eac01","tarball":"https://registry.npmjs.org/@apex-pub/fabric-mock-stub/-/fabric-mock-stub-1.0.0.tgz","fileCount":44,"unpackedSize":112750,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDjFWa5keBBFndXCNce7XcJfesjdqsu6AwP0Z5Qh6HsqAIhAKXCJkPyOeIsSDOmKypeAXXna+XDYjv/5+GMxDuJbr5d"}]},"_npmUser":{"name":"akshaysood112","email":"akshay.sood@live.com"},"directories":{},"maintainers":[{"name":"akshaysood112","email":"akshay.sood@live.com"},{"name":"rodolfoleal","email":"rodolfo.pk@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fabric-mock-stub_1.0.0_1688424341612_0.9409796128625503"},"_hasShrinkwrap":false},"1.4.0":{"name":"@apex-pub/fabric-mock-stub","version":"1.4.0","description":"Mock implementation of the hyperledger fabric-shim package for testing","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npm run clean && tsc","test":"mocha -r ts-node/register test/**/*.spec.ts --reporter spec","test:coverage":"nyc --no-clean mocha -r ts-node/register test/**/*.spec.ts --reporter spec","report-coverage":"nyc report --reporter=text-lcov > coverage.lcov && codecov","lint":"tslint --fix -c tslint.json './src/**/*.ts'","clean":"rimraf dist","prepare":"npm run build","generate:docs":"rimraf docs && typedoc src --out docs --target ES6 --excludePrivate && touch docs/.nojekyll && touch docs/modules/.nojekyll"},"keywords":[],"license":"MIT","devDependencies":{"@types/chai":"^4.0.4","@types/lodash":"^4.14.104","@types/mocha":"^5.2.1","@types/node":"^16.11.1","@types/winston":"^2.3.8","chai":"^4.1.2","codecov":"^3.0.4","coveralls":"^3.0.0","husky":"^0.15.0-rc.8","istanbul":"^0.4.5","mocha":"^5.0.3","nyc":"^12.0.2","rimraf":"^2.6.2","tslint":"5.9.1","typedoc":"^0.16.2"},"dependencies":{"@theledger/couchdb-query-engine":"^2.4.4","@types/google-protobuf":"^3.7.2","fabric-shim":"2.5.4","google-protobuf":"^3.6.1","lodash":"^4.17.11","ts-node":"^8.6.2","typescript":"4.8","winston":"^2.4.0"},"publishConfig":{"registry":"https://registry.npmjs.org","access":"public"},"husky":{"hooks":{"pre-push":"npm run test && git add ."}},"nyc":{"include":["src/**/*.ts"],"extension":[".ts"],"require":["ts-node/register"],"reporter":["text"],"sourceMap":true,"instrument":true},"_id":"@apex-pub/fabric-mock-stub@1.4.0","_nodeVersion":"10.18.1","_npmVersion":"6.13.4","dist":{"integrity":"sha512-bqRViw551edaIa9qwFyYiDa5tc6Sc/AXXdisgkD07l5LhZs8K/xGfG9K9RWI+o7fsYN/MI/+TyL3lJMjQ/kssw==","shasum":"2b69080da21e07ea57d75aae45474d8f9653df8f","tarball":"https://registry.npmjs.org/@apex-pub/fabric-mock-stub/-/fabric-mock-stub-1.4.0.tgz","fileCount":44,"unpackedSize":112750,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIE2czp+XAAF33iil7DThn407tsdwYFGZSUA4hBCTZ6vaAiBoq2JEtUhTcqtI9XXYLorsTSsCEvWVcXBenCPGvQIAQw=="}]},"_npmUser":{"name":"akshaysood112","email":"akshay.sood@live.com"},"directories":{},"maintainers":[{"name":"akshaysood112","email":"akshay.sood@live.com"},{"name":"rodolfoleal","email":"rodolfo.pk@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fabric-mock-stub_1.4.0_1688424596979_0.7244409301178223"},"_hasShrinkwrap":false},"1.4.1-0":{"name":"@apex-pub/fabric-mock-stub","version":"1.4.1-0","description":"Mock implementation of the hyperledger fabric-shim package for testing","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npm run clean && tsc","test":"mocha -r ts-node/register test/**/*.spec.ts --reporter spec","test:coverage":"nyc --no-clean mocha -r ts-node/register test/**/*.spec.ts --reporter spec","report-coverage":"nyc report --reporter=text-lcov > coverage.lcov && codecov","lint":"tslint --fix -c tslint.json './src/**/*.ts'","clean":"rimraf dist","prepare":"npm run build","generate:docs":"rimraf docs && typedoc src --out docs --target ES6 --excludePrivate && touch docs/.nojekyll && touch docs/modules/.nojekyll"},"keywords":[],"license":"MIT","devDependencies":{"@types/lodash":"^4.14.104","@types/winston":"^2.3.8","codecov":"^3.0.4","coveralls":"^3.0.0","istanbul":"^0.4.5","nyc":"^12.0.2"},"dependencies":{"@theledger/couchdb-query-engine":"^2.4.4","@types/google-protobuf":"^3.7.2","fabric-shim":"2.5.4","google-protobuf":"^3.6.1","lodash":"^4.17.11","winston":"^2.4.0"},"publishConfig":{"registry":"https://registry.npmjs.org","access":"public"},"husky":{"hooks":{"pre-push":"npm run test && git add ."}},"nyc":{"include":["src/**/*.ts"],"extension":[".ts"],"require":["ts-node/register"],"reporter":["text"],"sourceMap":true,"instrument":true},"gitHead":"9b31b0c776c2aabd83d21c31a073d84360aa306e","_id":"@apex-pub/fabric-mock-stub@1.4.1-0","_nodeVersion":"18.16.1","_npmVersion":"9.5.1","dist":{"integrity":"sha512-dD/fwjO6Wrtd4sDirVPp53eMPJjqoXF1zLCXOq/qxaOEsLGiz/1PakwcC1fFHRBUFdwj6fYx5s4iw5rxXMUWdw==","shasum":"25268bf05563bb23cfe435520dd0a0bde7b1938c","tarball":"https://registry.npmjs.org/@apex-pub/fabric-mock-stub/-/fabric-mock-stub-1.4.1-0.tgz","fileCount":44,"unpackedSize":112465,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFT1shfjjynEH4OchhjTPokm1g+VpKakgw3RgqFUekliAiEArpi5+XBsY6Q9Heg7POyV6+WJQ1/yp4s5LjefFCp6tZE="}]},"_npmUser":{"name":"akshaysood112","email":"akshay.sood@live.com"},"directories":{},"maintainers":[{"name":"akshaysood112","email":"akshay.sood@live.com"},{"name":"rodolfoleal","email":"rodolfo.pk@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fabric-mock-stub_1.4.1-0_1688510487826_0.36393488991735423"},"_hasShrinkwrap":false},"1.4.1-1.4.1-node20.0":{"name":"@apex-pub/fabric-mock-stub","version":"1.4.1-1.4.1-node20.0","description":"Mock implementation of the hyperledger fabric-shim package for testing","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npm run clean && tsc","test":"mocha -r ts-node/register test/**/*.spec.ts --reporter spec","test:coverage":"nyc --no-clean mocha -r ts-node/register test/**/*.spec.ts --reporter spec","report-coverage":"nyc report --reporter=text-lcov > coverage.lcov && codecov","lint":"tslint --fix -c tslint.json './src/**/*.ts'","clean":"rimraf dist","prepare":"npm run build","generate:docs":"rimraf docs && typedoc src --out docs --target ES6 --excludePrivate && touch docs/.nojekyll && touch docs/modules/.nojekyll"},"keywords":[],"license":"MIT","devDependencies":{"@types/lodash":"^4.14.104","@types/winston":"^2.3.8","codecov":"^3.0.4","coveralls":"^3.0.0","istanbul":"^0.4.5","nyc":"^12.0.2"},"dependencies":{"@theledger/couchdb-query-engine":"^2.4.4","@types/google-protobuf":"^3.7.2","fabric-shim":"2.5.4","google-protobuf":"^3.6.1","lodash":"^4.17.11","winston":"^2.4.0"},"publishConfig":{"registry":"https://registry.npmjs.org","access":"public"},"husky":{"hooks":{"pre-push":"npm run test && git add ."}},"nyc":{"include":["src/**/*.ts"],"extension":[".ts"],"require":["ts-node/register"],"reporter":["text"],"sourceMap":true,"instrument":true},"gitHead":"8869ed555205adc20373804aa34c41fa1465d927","_id":"@apex-pub/fabric-mock-stub@1.4.1-1.4.1-node20.0","_nodeVersion":"20.3.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-lup32Z2aNd9g8L/mxQlMGoHofsBVhQqGgJHzjKEiDPNbHGk6xHLjjLj0z2fEZOF0ew22JNYaDWFZZfq3s2m3aw==","shasum":"a73898112b142b002366048c8a3b78eca5ca41cd","tarball":"https://registry.npmjs.org/@apex-pub/fabric-mock-stub/-/fabric-mock-stub-1.4.1-1.4.1-node20.0.tgz","fileCount":44,"unpackedSize":112478,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHgmczRtH6DuNY4Uf2Ir5okxBH0BeVt3b57WkmPhHOoYAiBsl4lb6x/4wRHPThowSLiYoR7MmF9DrVhTXnzgh3CJ7g=="}]},"_npmUser":{"name":"akshaysood112","email":"akshay.sood@live.com"},"directories":{},"maintainers":[{"name":"akshaysood112","email":"akshay.sood@live.com"},{"name":"rodolfoleal","email":"rodolfo.pk@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fabric-mock-stub_1.4.1-1.4.1-node20.0_1688511670252_0.13684793965583952"},"_hasShrinkwrap":false},"1.4.1-2.0":{"name":"@apex-pub/fabric-mock-stub","version":"1.4.1-2.0","description":"Mock implementation of the hyperledger fabric-shim package for testing","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npm run clean && tsc","test":"mocha -r ts-node/register test/**/*.spec.ts --reporter spec","test:coverage":"nyc --no-clean mocha -r ts-node/register test/**/*.spec.ts --reporter spec","report-coverage":"nyc report --reporter=text-lcov > coverage.lcov && codecov","lint":"tslint --fix -c tslint.json './src/**/*.ts'","clean":"rimraf dist","prepare":"npm run build","generate:docs":"rimraf docs && typedoc src --out docs --target ES6 --excludePrivate && touch docs/.nojekyll && touch docs/modules/.nojekyll"},"keywords":[],"license":"MIT","devDependencies":{"@types/lodash":"^4.14.104","@types/winston":"^2.3.8","codecov":"^3.0.4","coveralls":"^3.0.0","istanbul":"^0.4.5","nyc":"^12.0.2"},"dependencies":{"@theledger/couchdb-query-engine":"^2.4.4","@types/google-protobuf":"^3.7.2","fabric-shim":"2.5.4","google-protobuf":"^3.6.1","lodash":"^4.17.11","winston":"^2.4.0"},"publishConfig":{"registry":"https://registry.npmjs.org","access":"public"},"husky":{"hooks":{"pre-push":"npm run test && git add ."}},"nyc":{"include":["src/**/*.ts"],"extension":[".ts"],"require":["ts-node/register"],"reporter":["text"],"sourceMap":true,"instrument":true},"gitHead":"32d66b2920b13d33c301442ee5ea54f23f9bf5c5","_id":"@apex-pub/fabric-mock-stub@1.4.1-2.0","_nodeVersion":"20.3.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-QpUK1Ij7MMT6TDZ0VGqM0W2WR/z+RuHJdxfi80IAjlEqNbeIIu+waNqfw/81+7KmTRHDqiTct/KdMI6RIuEtww==","shasum":"3305cc80001332f734425bf4a671b825e83870eb","tarball":"https://registry.npmjs.org/@apex-pub/fabric-mock-stub/-/fabric-mock-stub-1.4.1-2.0.tgz","fileCount":44,"unpackedSize":112467,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEKCuuEYFcjCu6cUMUzpjb9vCVTpYAPahmc6kzMEU/QrAiEAknG9EkkW1MlWR9lpbaXJx6CWz+74M9tJQzC0YHrEGM0="}]},"_npmUser":{"name":"akshaysood112","email":"akshay.sood@live.com"},"directories":{},"maintainers":[{"name":"akshaysood112","email":"akshay.sood@live.com"},{"name":"rodolfoleal","email":"rodolfo.pk@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fabric-mock-stub_1.4.1-2.0_1689026342964_0.06780195032913694"},"_hasShrinkwrap":false},"1.4.1-3":{"name":"@apex-pub/fabric-mock-stub","version":"1.4.1-3","description":"Mock implementation of the hyperledger fabric-shim package for testing","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npm run clean && tsc","test":"mocha -r ts-node/register test/**/*.spec.ts --reporter spec","test:coverage":"nyc --no-clean mocha -r ts-node/register test/**/*.spec.ts --reporter spec","report-coverage":"nyc report --reporter=text-lcov > coverage.lcov && codecov","lint":"tslint --fix -c tslint.json './src/**/*.ts'","clean":"rimraf dist","prepare":"npm run build","generate:docs":"rimraf docs && typedoc src --out docs --target ES6 --excludePrivate && touch docs/.nojekyll && touch docs/modules/.nojekyll"},"keywords":[],"license":"MIT","devDependencies":{"@types/lodash":"^4.14.104","@types/winston":"^2.3.8","codecov":"^3.0.4","coveralls":"^3.0.0","istanbul":"^0.4.5","nyc":"^12.0.2"},"dependencies":{"@theledger/couchdb-query-engine":"^2.4.4","@types/google-protobuf":"^3.7.2","fabric-shim":"2.5.4","google-protobuf":"^3.6.1","lodash":"^4.17.11","winston":"^2.4.0"},"publishConfig":{"registry":"https://registry.npmjs.org","access":"public"},"husky":{"hooks":{"pre-push":"npm run test && git add ."}},"nyc":{"include":["src/**/*.ts"],"extension":[".ts"],"require":["ts-node/register"],"reporter":["text"],"sourceMap":true,"instrument":true},"gitHead":"aa4051586a4f3a2d53daef69c0afd20679c77db5","_id":"@apex-pub/fabric-mock-stub@1.4.1-3","_nodeVersion":"20.4.0","_npmVersion":"9.7.2","dist":{"integrity":"sha512-Zclq0o5OxsZ29AC5AHP3nTI5o+ymVl7hKpjhSz+Ju2RLKgGAM1oHaoQqIoL1EPt/To6j4CSr+lU01Y7QPFUDFQ==","shasum":"844ba6c0df41e40f69083dce560a5d92e9c78950","tarball":"https://registry.npmjs.org/@apex-pub/fabric-mock-stub/-/fabric-mock-stub-1.4.1-3.tgz","fileCount":44,"unpackedSize":112465,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCRjRHKR8jjFpvZfaMPlgHVpQlBqmD0KILIdO9i0lsD4AIgN1LPs1/OKlNPt/LcL2V6bEgsFO9qZ107nq7q0GG1hkY="}]},"_npmUser":{"name":"akshaysood112","email":"akshay.sood@live.com"},"directories":{},"maintainers":[{"name":"akshaysood112","email":"akshay.sood@live.com"},{"name":"rodolfoleal","email":"rodolfo.pk@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fabric-mock-stub_1.4.1-3_1689104749624_0.3312830469640866"},"_hasShrinkwrap":false},"1.4.1-4-alpha.aa405158":{"name":"@apex-pub/fabric-mock-stub","version":"1.4.1-4-alpha.aa405158","description":"Mock implementation of the hyperledger fabric-shim package for testing","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npm run clean && tsc","test":"mocha -r ts-node/register test/**/*.spec.ts --reporter spec","test:coverage":"nyc --no-clean mocha -r ts-node/register test/**/*.spec.ts --reporter spec","report-coverage":"nyc report --reporter=text-lcov > coverage.lcov && codecov","lint":"tslint --fix -c tslint.json './src/**/*.ts'","clean":"rimraf dist","prepare":"npm run build","generate:docs":"rimraf docs && typedoc src --out docs --target ES6 --excludePrivate && touch docs/.nojekyll && touch docs/modules/.nojekyll"},"keywords":[],"license":"MIT","devDependencies":{"@types/lodash":"^4.14.104","@types/winston":"^2.3.8","codecov":"^3.0.4","coveralls":"^3.0.0","istanbul":"^0.4.5","nyc":"^12.0.2"},"dependencies":{"@theledger/couchdb-query-engine":"^2.4.4","@types/google-protobuf":"^3.7.2","fabric-shim":"2.5.4","google-protobuf":"^3.6.1","lodash":"^4.17.11","winston":"^2.4.0"},"publishConfig":{"registry":"https://registry.npmjs.org","access":"public"},"husky":{"hooks":{"pre-push":"npm run test && git add ."}},"nyc":{"include":["src/**/*.ts"],"extension":[".ts"],"require":["ts-node/register"],"reporter":["text"],"sourceMap":true,"instrument":true},"readme":"[![Build Status](https://travis-ci.org/wearetheledger/fabric-mock-stub.svg?branch=master)](https://travis-ci.org/wearetheledger/fabric-mock-stub) [![npm version](https://badge.fury.io/js/%40theledger%2Ffabric-mock-stub.svg)](https://badge.fury.io/js/%40theledger%2Ffabric-mock-stub) [![codecov](https://codecov.io/gh/wearetheledger/fabric-mock-stub/branch/master/graph/badge.svg)](https://codecov.io/gh/wearetheledger/fabric-mock-stub)\n# Hyperledger Fabric Nodejs mockstub\n\nA Nodejs module that helps you to test your Hyperledger Fabric Nodejs chaincode. When it proves itself, we will be adding this package to the official Gerrit of the Fabric Nodejs SDK.\n\n- [Docs](https://wearetheledger.github.io/fabric-mock-stub)\n- [Example usage](https://github.com/wearetheledger/fabric-network-boilerplate/tree/master/chaincode/node)\n- [Article about this repo](https://medium.com/wearetheledger/how-to-start-testing-your-hyperledger-fabric-nodejs-chaincode-229453c3c214)\n\n## 🚨 Note\nDue to the complexity, key endorsement policies introduced in v1.4 are currently not being enforced.\n\n## Table of contents\n- [Version matching](#version-matching)\n- [Installation](#installation)\n- [Todo](#todo)\n- [Usage](#usage)\n- [Contributing](#contributing)\n- [Credits](#credits)\n- [License](#license)\n\n## Version matching\n| Fabric node SDK        | Mock stub    |\n| ------------- |:-------------:|\n| v1.4.X     | v4.X.X |\n| v1.3.X     | v3.X.X |\n| v1.2.X     | v2.X.X |\n| V1.1.X     | v1.3.X     |\n\n\n## Installation\n```sh\nyarn add @theledger/fabric-mock-stub --dev\n```\n\n## Todo\n- [ ] Finish [node-couchdb-query-engine](https://github.com/wearetheledger/node-couchdb-query-engine)\n- [ ] Implement `fields` and `sort` into GetQueryResult\n- Implement remaining mock methods for\n    - [ ] getBinding\n    - [ ] getChannelID\n\n## Usage\n### ChaincodeMockStub [View definition](https://wearetheledger.github.io/fabric-mock-stub/classes/_chaincodemockstub_.chaincodemockstub.html)\nThis ChaincodeMockStub is a Mock implementation of the fabric-shim stub. This means you can test your chaincode without actually starting your network.\n\nExamples are located at [examples/tests](examples/tests)\n\n**!! Following methods are not (yet) implemented and will not work !!**\n- getBinding\n- getChannelID\n\n### How to test\nTesting NodeJS chaincode works similarly to testing using the mockstub in the Golang chaincode.\n\nThe **ChaincodeMockStub** has 2 important mock functions `mockInit`and `mockInvoke`. By passing your chaincode, it will mock a transaction and execute a invoke/init similarly to how it will originally be called. Both these functions will return a [ChaincodeResponse](https://github.com/wearetheledger/fabric-shim-types/blob/4b8844769c2439303954d03f5c8a66dc0a795ed4/index.d.ts#L93). Using this ChaincodeResponse object, we can test whether or not the action returned an expected result.\n\nOn *success*, this response will look like this. If the method returns something, the response will also contain a `payload`.\n\n```json\n{\n    \"status\": 200,\n    \"payload\": <Buffer_with_your_data>\n}\n```\n\nOn *error*, this response will look like this.\n\n```json\n{\n    \"status\": 500,\n    \"message\": <Buffer_with_your_error_message>\n}\n```\n\nYou'll be able to validate the response using something like `chai`.\n\n```javascript\n// Validate response status\nexpect(response.status).to.eql(200)\n// Validate payload - using `Transform.bufferToObject` because we recieve the payload as a buffer\nexpect(Transform.bufferToObject(response.payload).owner).to.eql(\"newOwner\")\n```\n\n#### Include your chaincode\nAt the top of your test file, you can import and instantiate your chaincode, this only has to be done once.\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n```\n#### Include the mockstub\nAfter this, in your tests, you can create a new mockstub. You have to pass a random name (not that important) and your chaincode. It's up to you if you want to create a new mockstub for each test, which runs those tests with an empty state. Or use one for all the tests. If you reuse the same stub, you also reuse the previous tests state.\n\n```javascript\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\nconst mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n```\n\n#### Example\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should init without issues\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        // Your test code\n    });\n});\n```\n\n### Test Init\nThe `Init()`method can be tested using the `mockStub.mockInit(txId: string, args: string[])` function. It will create a new mock transaction and call the init method on your chaincode. Since the init happens when instantiating your chaincode, you generally don't want it to return anything. So, for this, we'll check the response status.\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should init without issues\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInit(\"tx1\", []);\n\n        expect(response.status).to.eql(200)\n    });\n});\n```\n\n### Test Invoke\nThe `Invoke()`method can be tested using the `mockStub.mockInvoke(txId: string, args: string[])` function. It will create a new mock transaction and call the invoke method on your chaincode. The client will either send a query or an invoke, but the chaincode will accept these both as invoke. In your tests there isn't any difference, both invokes and queries can return a result.\n\n**Test queryCar**\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should query car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInvoke(\"tx2\", ['queryCar', `CAR0`]);\n\n        expect(Transform.bufferToObject(response.payload)).to.deep.eq({\n            'make': 'prop1',\n            'model': 'prop2',\n            'color': 'prop3',\n            'owner': 'owner',\n            'docType': 'car'\n        });\n    });\n});\n```\n\n**Test createCar**\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInvoke(\"tx1\", ['createCar', `CAR0`, `prop1`, `prop2`, `prop3`, `owner`]);\n\n        expect(response.status).to.eql(200)\n\n        const response = await mockStub.mockInvoke(\"tx1\", ['queryCar', `CAR0`]);\n\n        expect(Transform.bufferToObject(response.payload)).to.deep.eq({\n            'make': 'prop1',\n            'model': 'prop2',\n            'color': 'prop3',\n            'owner': 'owner',\n            'docType': 'car'\n        })\n    });\n});\n```\n\n### Testing individual classes\nYou are not required to only test using the `mockInvoke` and `mockInit`. You can directly call the methods on your chaincode or on the mockStub if you really want to.\n\n#### Testing using Mychaincode directly\nA remark when using this, depending what you return in your function, you will be able to receive a Buffer or an object in your tests. This is discussed in [chaincode](#writing-chaincode)\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const stub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const car0 = {\n            'make': 'Toyota',\n            'model': 'Prius',\n            'color': 'blue',\n            'owner': 'Tomoko',\n            'docType': 'car'\n        };\n\n        const car = await chaincode.queryCar(stub, [\"CAR0\"])\n\n        expect(car).to.deep.equal(car0);\n    });\n});\n```\n\n#### Testing using ChaincodeMockStub directly 🤨\nYou can do this, but you shouldn't. Your logic should be written in your functions, not your tests.\n\n##### Test query results\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const query = {\n            selector: {\n                model: {\n                    \"$in\": ['Nano', \"Punto\"]\n                }\n            }\n        };\n\n        const it = await mockStub.getQueryResult(JSON.stringify(query));\n\n        const items = await Transform.iteratorToList(it);\n\n        expect(items).to.be.length(2)\n    });\n});\n```\n\n##### Test emitted events\n\n```javascript\nit(\"Should get the emitted event\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        await mockStub.mockInvoke(\"tx1\", ['createCar', `CAR0`, `prop1`, `prop2`, `prop3`, `owner`]);\n\n        const eventPayload = await mockStub.getEvent('CREATE_CAR');\n\n        expect(eventPayload).to.equal('Car created.');\n});\n```\n\n## Contributing\n\n1. Fork it! 🍴\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request 😁 🎉\n\n## Credits\n\n- Developer - Jo ([@jestersimpps](https://github.com/jestersimpps))\n- Developer - Jonas ([@Superjo149](https://github.com/Superjo149))\n- Company - TheLedger ([theledger.be](https://theledger.be))\n\n## License\nThe MIT License (MIT)\n\nCopyright (c) 2018 TheLedger\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","gitHead":"aa4051586a4f3a2d53daef69c0afd20679c77db5","_id":"@apex-pub/fabric-mock-stub@1.4.1-4-alpha.aa405158","_nodeVersion":"20.4.0","_npmVersion":"9.7.2","dist":{"integrity":"sha512-xieOoBxdJAbvx3Eouvihoi0lnTXJ84khw9t8/NnEls4IuAL1snstJy0bwdfX+SIAbNCtWQYZQLTmSeYiM3Fi2g==","shasum":"ce0325bc2de37ae7b94d04d4d05e3466f9f14c00","tarball":"https://registry.npmjs.org/@apex-pub/fabric-mock-stub/-/fabric-mock-stub-1.4.1-4-alpha.aa405158.tgz","fileCount":44,"unpackedSize":112480,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDSpTsTt2wafZX/8h80SZkPnJHFKfj84DsYt3zcGw1VEAIhAOwz0w4d5bdFp+X6Utl6vKC6tAPBLzGN05DCq6YyZIJt"}]},"_npmUser":{"name":"akshaysood112","email":"akshay.sood@live.com"},"directories":{},"maintainers":[{"name":"akshaysood112","email":"akshay.sood@live.com"},{"name":"rodolfoleal","email":"rodolfo.pk@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fabric-mock-stub_1.4.1-4-alpha.aa405158_1689106842321_0.9349261588639053"},"_hasShrinkwrap":false},"1.4.1-4-alpha.6064f94c":{"name":"@apex-pub/fabric-mock-stub","version":"1.4.1-4-alpha.6064f94c","description":"Mock implementation of the hyperledger fabric-shim package for testing","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npm run clean && tsc","test":"mocha -r ts-node/register test/**/*.spec.ts --reporter spec","test:coverage":"nyc --no-clean mocha -r ts-node/register test/**/*.spec.ts --reporter spec","report-coverage":"nyc report --reporter=text-lcov > coverage.lcov && codecov","lint":"tslint --fix -c tslint.json './src/**/*.ts'","clean":"rimraf dist","prepare":"npm run build","generate:docs":"rimraf docs && typedoc src --out docs --target ES6 --excludePrivate && touch docs/.nojekyll && touch docs/modules/.nojekyll"},"keywords":[],"license":"MIT","devDependencies":{"@types/lodash":"^4.14.104","@types/winston":"^2.3.8","codecov":"^3.0.4","coveralls":"^3.0.0","istanbul":"^0.4.5","nyc":"^12.0.2"},"dependencies":{"@theledger/couchdb-query-engine":"^2.4.4","@types/google-protobuf":"^3.7.2","fabric-shim":"2.5.4","google-protobuf":"^3.6.1","lodash":"^4.17.11","winston":"^2.4.0"},"publishConfig":{"registry":"https://registry.npmjs.org","access":"public"},"husky":{"hooks":{"pre-push":"npm run test && git add ."}},"nyc":{"include":["src/**/*.ts"],"extension":[".ts"],"require":["ts-node/register"],"reporter":["text"],"sourceMap":true,"instrument":true},"readme":"[![Build Status](https://travis-ci.org/wearetheledger/fabric-mock-stub.svg?branch=master)](https://travis-ci.org/wearetheledger/fabric-mock-stub) [![npm version](https://badge.fury.io/js/%40theledger%2Ffabric-mock-stub.svg)](https://badge.fury.io/js/%40theledger%2Ffabric-mock-stub) [![codecov](https://codecov.io/gh/wearetheledger/fabric-mock-stub/branch/master/graph/badge.svg)](https://codecov.io/gh/wearetheledger/fabric-mock-stub)\n# Hyperledger Fabric Nodejs mockstub\n\nA Nodejs module that helps you to test your Hyperledger Fabric Nodejs chaincode. When it proves itself, we will be adding this package to the official Gerrit of the Fabric Nodejs SDK.\n\n- [Docs](https://wearetheledger.github.io/fabric-mock-stub)\n- [Example usage](https://github.com/wearetheledger/fabric-network-boilerplate/tree/master/chaincode/node)\n- [Article about this repo](https://medium.com/wearetheledger/how-to-start-testing-your-hyperledger-fabric-nodejs-chaincode-229453c3c214)\n\n## 🚨 Note\nDue to the complexity, key endorsement policies introduced in v1.4 are currently not being enforced.\n\n## Table of contents\n- [Version matching](#version-matching)\n- [Installation](#installation)\n- [Todo](#todo)\n- [Usage](#usage)\n- [Contributing](#contributing)\n- [Credits](#credits)\n- [License](#license)\n\n## Version matching\n| Fabric node SDK        | Mock stub    |\n| ------------- |:-------------:|\n| v1.4.X     | v4.X.X |\n| v1.3.X     | v3.X.X |\n| v1.2.X     | v2.X.X |\n| V1.1.X     | v1.3.X     |\n\n\n## Installation\n```sh\nyarn add @theledger/fabric-mock-stub --dev\n```\n\n## Todo\n- [ ] Finish [node-couchdb-query-engine](https://github.com/wearetheledger/node-couchdb-query-engine)\n- [ ] Implement `fields` and `sort` into GetQueryResult\n- Implement remaining mock methods for\n    - [ ] getBinding\n    - [ ] getChannelID\n\n## Usage\n### ChaincodeMockStub [View definition](https://wearetheledger.github.io/fabric-mock-stub/classes/_chaincodemockstub_.chaincodemockstub.html)\nThis ChaincodeMockStub is a Mock implementation of the fabric-shim stub. This means you can test your chaincode without actually starting your network.\n\nExamples are located at [examples/tests](examples/tests)\n\n**!! Following methods are not (yet) implemented and will not work !!**\n- getBinding\n- getChannelID\n\n### How to test\nTesting NodeJS chaincode works similarly to testing using the mockstub in the Golang chaincode.\n\nThe **ChaincodeMockStub** has 2 important mock functions `mockInit`and `mockInvoke`. By passing your chaincode, it will mock a transaction and execute a invoke/init similarly to how it will originally be called. Both these functions will return a [ChaincodeResponse](https://github.com/wearetheledger/fabric-shim-types/blob/4b8844769c2439303954d03f5c8a66dc0a795ed4/index.d.ts#L93). Using this ChaincodeResponse object, we can test whether or not the action returned an expected result.\n\nOn *success*, this response will look like this. If the method returns something, the response will also contain a `payload`.\n\n```json\n{\n    \"status\": 200,\n    \"payload\": <Buffer_with_your_data>\n}\n```\n\nOn *error*, this response will look like this.\n\n```json\n{\n    \"status\": 500,\n    \"message\": <Buffer_with_your_error_message>\n}\n```\n\nYou'll be able to validate the response using something like `chai`.\n\n```javascript\n// Validate response status\nexpect(response.status).to.eql(200)\n// Validate payload - using `Transform.bufferToObject` because we recieve the payload as a buffer\nexpect(Transform.bufferToObject(response.payload).owner).to.eql(\"newOwner\")\n```\n\n#### Include your chaincode\nAt the top of your test file, you can import and instantiate your chaincode, this only has to be done once.\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n```\n#### Include the mockstub\nAfter this, in your tests, you can create a new mockstub. You have to pass a random name (not that important) and your chaincode. It's up to you if you want to create a new mockstub for each test, which runs those tests with an empty state. Or use one for all the tests. If you reuse the same stub, you also reuse the previous tests state.\n\n```javascript\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\nconst mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n```\n\n#### Example\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should init without issues\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        // Your test code\n    });\n});\n```\n\n### Test Init\nThe `Init()`method can be tested using the `mockStub.mockInit(txId: string, args: string[])` function. It will create a new mock transaction and call the init method on your chaincode. Since the init happens when instantiating your chaincode, you generally don't want it to return anything. So, for this, we'll check the response status.\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should init without issues\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInit(\"tx1\", []);\n\n        expect(response.status).to.eql(200)\n    });\n});\n```\n\n### Test Invoke\nThe `Invoke()`method can be tested using the `mockStub.mockInvoke(txId: string, args: string[])` function. It will create a new mock transaction and call the invoke method on your chaincode. The client will either send a query or an invoke, but the chaincode will accept these both as invoke. In your tests there isn't any difference, both invokes and queries can return a result.\n\n**Test queryCar**\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should query car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInvoke(\"tx2\", ['queryCar', `CAR0`]);\n\n        expect(Transform.bufferToObject(response.payload)).to.deep.eq({\n            'make': 'prop1',\n            'model': 'prop2',\n            'color': 'prop3',\n            'owner': 'owner',\n            'docType': 'car'\n        });\n    });\n});\n```\n\n**Test createCar**\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInvoke(\"tx1\", ['createCar', `CAR0`, `prop1`, `prop2`, `prop3`, `owner`]);\n\n        expect(response.status).to.eql(200)\n\n        const response = await mockStub.mockInvoke(\"tx1\", ['queryCar', `CAR0`]);\n\n        expect(Transform.bufferToObject(response.payload)).to.deep.eq({\n            'make': 'prop1',\n            'model': 'prop2',\n            'color': 'prop3',\n            'owner': 'owner',\n            'docType': 'car'\n        })\n    });\n});\n```\n\n### Testing individual classes\nYou are not required to only test using the `mockInvoke` and `mockInit`. You can directly call the methods on your chaincode or on the mockStub if you really want to.\n\n#### Testing using Mychaincode directly\nA remark when using this, depending what you return in your function, you will be able to receive a Buffer or an object in your tests. This is discussed in [chaincode](#writing-chaincode)\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const stub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const car0 = {\n            'make': 'Toyota',\n            'model': 'Prius',\n            'color': 'blue',\n            'owner': 'Tomoko',\n            'docType': 'car'\n        };\n\n        const car = await chaincode.queryCar(stub, [\"CAR0\"])\n\n        expect(car).to.deep.equal(car0);\n    });\n});\n```\n\n#### Testing using ChaincodeMockStub directly 🤨\nYou can do this, but you shouldn't. Your logic should be written in your functions, not your tests.\n\n##### Test query results\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const query = {\n            selector: {\n                model: {\n                    \"$in\": ['Nano', \"Punto\"]\n                }\n            }\n        };\n\n        const it = await mockStub.getQueryResult(JSON.stringify(query));\n\n        const items = await Transform.iteratorToList(it);\n\n        expect(items).to.be.length(2)\n    });\n});\n```\n\n##### Test emitted events\n\n```javascript\nit(\"Should get the emitted event\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        await mockStub.mockInvoke(\"tx1\", ['createCar', `CAR0`, `prop1`, `prop2`, `prop3`, `owner`]);\n\n        const eventPayload = await mockStub.getEvent('CREATE_CAR');\n\n        expect(eventPayload).to.equal('Car created.');\n});\n```\n\n## Contributing\n\n1. Fork it! 🍴\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request 😁 🎉\n\n## Credits\n\n- Developer - Jo ([@jestersimpps](https://github.com/jestersimpps))\n- Developer - Jonas ([@Superjo149](https://github.com/Superjo149))\n- Company - TheLedger ([theledger.be](https://theledger.be))\n\n## License\nThe MIT License (MIT)\n\nCopyright (c) 2018 TheLedger\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","gitHead":"6064f94cefd4046f9af56c4a27cafb8a6e7ddf05","_id":"@apex-pub/fabric-mock-stub@1.4.1-4-alpha.6064f94c","_nodeVersion":"20.4.0","_npmVersion":"9.7.2","dist":{"integrity":"sha512-k6WUQd0b3/gQqBGtTtumoJvTFNPQjbhh6sXpGAOfEAyrX1vW0tj+yyhculwAJ4XRimx0RyNi5h90ibkQoUg12g==","shasum":"53d786aae7f20e9eec2c4e67479b4487b593d843","tarball":"https://registry.npmjs.org/@apex-pub/fabric-mock-stub/-/fabric-mock-stub-1.4.1-4-alpha.6064f94c.tgz","fileCount":44,"unpackedSize":105782,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCeEbbb0aWs8GPVE2IfAYVXi7TjXo1OZ8QtXgNSlEKENwIgMrDFtOllSMKknP3oFdrVNhapyylUZUqqdV7BDGsHveQ="}]},"_npmUser":{"name":"akshaysood112","email":"akshay.sood@live.com"},"directories":{},"maintainers":[{"name":"akshaysood112","email":"akshay.sood@live.com"},{"name":"rodolfoleal","email":"rodolfo.pk@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fabric-mock-stub_1.4.1-4-alpha.6064f94c_1690251782425_0.599377386226216"},"_hasShrinkwrap":false},"1.4.1-4-alpha.8d3ff686":{"name":"@apex-pub/fabric-mock-stub","version":"1.4.1-4-alpha.8d3ff686","description":"Mock implementation of the hyperledger fabric-shim package for testing","main":"dist/index.js","type":"module","types":"dist/index.d.ts","scripts":{"build":"npm run clean && tsc","test":"mocha -r ts-node/register test/**/*.spec.ts --reporter spec","test:coverage":"nyc --no-clean mocha -r ts-node/register test/**/*.spec.ts --reporter spec","report-coverage":"nyc report --reporter=text-lcov > coverage.lcov && codecov","lint":"tslint --fix -c tslint.json './src/**/*.ts'","clean":"rimraf dist","prepare":"npm run build","generate:docs":"rimraf docs && typedoc src --out docs --target ES6 --excludePrivate && touch docs/.nojekyll && touch docs/modules/.nojekyll"},"keywords":[],"license":"MIT","devDependencies":{"@types/lodash":"^4.14.104","@types/winston":"^2.3.8","codecov":"^3.0.4","coveralls":"^3.0.0","istanbul":"^0.4.5","nyc":"^12.0.2"},"dependencies":{"@theledger/couchdb-query-engine":"^2.4.4","@types/google-protobuf":"^3.7.2","fabric-shim":"2.5.4","google-protobuf":"^3.6.1","lodash":"^4.17.11","winston":"^2.4.0"},"publishConfig":{"registry":"https://registry.npmjs.org","access":"public"},"husky":{"hooks":{"pre-push":"npm run test && git add ."}},"nyc":{"include":["src/**/*.ts"],"extension":[".ts"],"require":["ts-node/register"],"reporter":["text"],"sourceMap":true,"instrument":true},"readme":"[![Build Status](https://travis-ci.org/wearetheledger/fabric-mock-stub.svg?branch=master)](https://travis-ci.org/wearetheledger/fabric-mock-stub) [![npm version](https://badge.fury.io/js/%40theledger%2Ffabric-mock-stub.svg)](https://badge.fury.io/js/%40theledger%2Ffabric-mock-stub) [![codecov](https://codecov.io/gh/wearetheledger/fabric-mock-stub/branch/master/graph/badge.svg)](https://codecov.io/gh/wearetheledger/fabric-mock-stub)\n# Hyperledger Fabric Nodejs mockstub\n\nA Nodejs module that helps you to test your Hyperledger Fabric Nodejs chaincode. When it proves itself, we will be adding this package to the official Gerrit of the Fabric Nodejs SDK.\n\n- [Docs](https://wearetheledger.github.io/fabric-mock-stub)\n- [Example usage](https://github.com/wearetheledger/fabric-network-boilerplate/tree/master/chaincode/node)\n- [Article about this repo](https://medium.com/wearetheledger/how-to-start-testing-your-hyperledger-fabric-nodejs-chaincode-229453c3c214)\n\n## 🚨 Note\nDue to the complexity, key endorsement policies introduced in v1.4 are currently not being enforced.\n\n## Table of contents\n- [Version matching](#version-matching)\n- [Installation](#installation)\n- [Todo](#todo)\n- [Usage](#usage)\n- [Contributing](#contributing)\n- [Credits](#credits)\n- [License](#license)\n\n## Version matching\n| Fabric node SDK        | Mock stub    |\n| ------------- |:-------------:|\n| v1.4.X     | v4.X.X |\n| v1.3.X     | v3.X.X |\n| v1.2.X     | v2.X.X |\n| V1.1.X     | v1.3.X     |\n\n\n## Installation\n```sh\nyarn add @theledger/fabric-mock-stub --dev\n```\n\n## Todo\n- [ ] Finish [node-couchdb-query-engine](https://github.com/wearetheledger/node-couchdb-query-engine)\n- [ ] Implement `fields` and `sort` into GetQueryResult\n- Implement remaining mock methods for\n    - [ ] getBinding\n    - [ ] getChannelID\n\n## Usage\n### ChaincodeMockStub [View definition](https://wearetheledger.github.io/fabric-mock-stub/classes/_chaincodemockstub_.chaincodemockstub.html)\nThis ChaincodeMockStub is a Mock implementation of the fabric-shim stub. This means you can test your chaincode without actually starting your network.\n\nExamples are located at [examples/tests](examples/tests)\n\n**!! Following methods are not (yet) implemented and will not work !!**\n- getBinding\n- getChannelID\n\n### How to test\nTesting NodeJS chaincode works similarly to testing using the mockstub in the Golang chaincode.\n\nThe **ChaincodeMockStub** has 2 important mock functions `mockInit`and `mockInvoke`. By passing your chaincode, it will mock a transaction and execute a invoke/init similarly to how it will originally be called. Both these functions will return a [ChaincodeResponse](https://github.com/wearetheledger/fabric-shim-types/blob/4b8844769c2439303954d03f5c8a66dc0a795ed4/index.d.ts#L93). Using this ChaincodeResponse object, we can test whether or not the action returned an expected result.\n\nOn *success*, this response will look like this. If the method returns something, the response will also contain a `payload`.\n\n```json\n{\n    \"status\": 200,\n    \"payload\": <Buffer_with_your_data>\n}\n```\n\nOn *error*, this response will look like this.\n\n```json\n{\n    \"status\": 500,\n    \"message\": <Buffer_with_your_error_message>\n}\n```\n\nYou'll be able to validate the response using something like `chai`.\n\n```javascript\n// Validate response status\nexpect(response.status).to.eql(200)\n// Validate payload - using `Transform.bufferToObject` because we recieve the payload as a buffer\nexpect(Transform.bufferToObject(response.payload).owner).to.eql(\"newOwner\")\n```\n\n#### Include your chaincode\nAt the top of your test file, you can import and instantiate your chaincode, this only has to be done once.\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n```\n#### Include the mockstub\nAfter this, in your tests, you can create a new mockstub. You have to pass a random name (not that important) and your chaincode. It's up to you if you want to create a new mockstub for each test, which runs those tests with an empty state. Or use one for all the tests. If you reuse the same stub, you also reuse the previous tests state.\n\n```javascript\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\nconst mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n```\n\n#### Example\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should init without issues\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        // Your test code\n    });\n});\n```\n\n### Test Init\nThe `Init()`method can be tested using the `mockStub.mockInit(txId: string, args: string[])` function. It will create a new mock transaction and call the init method on your chaincode. Since the init happens when instantiating your chaincode, you generally don't want it to return anything. So, for this, we'll check the response status.\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should init without issues\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInit(\"tx1\", []);\n\n        expect(response.status).to.eql(200)\n    });\n});\n```\n\n### Test Invoke\nThe `Invoke()`method can be tested using the `mockStub.mockInvoke(txId: string, args: string[])` function. It will create a new mock transaction and call the invoke method on your chaincode. The client will either send a query or an invoke, but the chaincode will accept these both as invoke. In your tests there isn't any difference, both invokes and queries can return a result.\n\n**Test queryCar**\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should query car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInvoke(\"tx2\", ['queryCar', `CAR0`]);\n\n        expect(Transform.bufferToObject(response.payload)).to.deep.eq({\n            'make': 'prop1',\n            'model': 'prop2',\n            'color': 'prop3',\n            'owner': 'owner',\n            'docType': 'car'\n        });\n    });\n});\n```\n\n**Test createCar**\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInvoke(\"tx1\", ['createCar', `CAR0`, `prop1`, `prop2`, `prop3`, `owner`]);\n\n        expect(response.status).to.eql(200)\n\n        const response = await mockStub.mockInvoke(\"tx1\", ['queryCar', `CAR0`]);\n\n        expect(Transform.bufferToObject(response.payload)).to.deep.eq({\n            'make': 'prop1',\n            'model': 'prop2',\n            'color': 'prop3',\n            'owner': 'owner',\n            'docType': 'car'\n        })\n    });\n});\n```\n\n### Testing individual classes\nYou are not required to only test using the `mockInvoke` and `mockInit`. You can directly call the methods on your chaincode or on the mockStub if you really want to.\n\n#### Testing using Mychaincode directly\nA remark when using this, depending what you return in your function, you will be able to receive a Buffer or an object in your tests. This is discussed in [chaincode](#writing-chaincode)\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const stub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const car0 = {\n            'make': 'Toyota',\n            'model': 'Prius',\n            'color': 'blue',\n            'owner': 'Tomoko',\n            'docType': 'car'\n        };\n\n        const car = await chaincode.queryCar(stub, [\"CAR0\"])\n\n        expect(car).to.deep.equal(car0);\n    });\n});\n```\n\n#### Testing using ChaincodeMockStub directly 🤨\nYou can do this, but you shouldn't. Your logic should be written in your functions, not your tests.\n\n##### Test query results\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const query = {\n            selector: {\n                model: {\n                    \"$in\": ['Nano', \"Punto\"]\n                }\n            }\n        };\n\n        const it = await mockStub.getQueryResult(JSON.stringify(query));\n\n        const items = await Transform.iteratorToList(it);\n\n        expect(items).to.be.length(2)\n    });\n});\n```\n\n##### Test emitted events\n\n```javascript\nit(\"Should get the emitted event\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        await mockStub.mockInvoke(\"tx1\", ['createCar', `CAR0`, `prop1`, `prop2`, `prop3`, `owner`]);\n\n        const eventPayload = await mockStub.getEvent('CREATE_CAR');\n\n        expect(eventPayload).to.equal('Car created.');\n});\n```\n\n## Contributing\n\n1. Fork it! 🍴\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request 😁 🎉\n\n## Credits\n\n- Developer - Jo ([@jestersimpps](https://github.com/jestersimpps))\n- Developer - Jonas ([@Superjo149](https://github.com/Superjo149))\n- Company - TheLedger ([theledger.be](https://theledger.be))\n\n## License\nThe MIT License (MIT)\n\nCopyright (c) 2018 TheLedger\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","gitHead":"8d3ff686c4a7bc0b3ff04daed3d5aebcef8b366e","_id":"@apex-pub/fabric-mock-stub@1.4.1-4-alpha.8d3ff686","_nodeVersion":"20.4.0","_npmVersion":"9.7.2","dist":{"integrity":"sha512-HD7X6fzBoaAp8N4vTvbF6BYjDEwzIYtnzsPla6xmyUwsjfSn3YafP0ellqCJwLMTKXHNl6+P17d7eeMAZQ8acw==","shasum":"ca7c2bf1791478de60f967bc67b6ae653752a2e3","tarball":"https://registry.npmjs.org/@apex-pub/fabric-mock-stub/-/fabric-mock-stub-1.4.1-4-alpha.8d3ff686.tgz","fileCount":44,"unpackedSize":105802,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEAwkpVVVu5XPRij66S9QNGBlGvC7jEnK2iKQMTQ5L9VAiEAzTBBX/PmLG1tAhs0l5AguzB79JjO+tZzS0WzoTp9KUA="}]},"_npmUser":{"name":"akshaysood112","email":"akshay.sood@live.com"},"directories":{},"maintainers":[{"name":"akshaysood112","email":"akshay.sood@live.com"},{"name":"rodolfoleal","email":"rodolfo.pk@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fabric-mock-stub_1.4.1-4-alpha.8d3ff686_1690252825700_0.029960572218831194"},"_hasShrinkwrap":false},"1.4.1-4-alpha.8939dce7":{"name":"@apex-pub/fabric-mock-stub","version":"1.4.1-4-alpha.8939dce7","description":"Mock implementation of the hyperledger fabric-shim package for testing","main":"dist/index.js","type":"module","types":"dist/index.d.ts","scripts":{"build":"npm run clean && tsc","test":"mocha -r ts-node/register test/**/*.spec.ts --reporter spec","test:coverage":"nyc --no-clean mocha -r ts-node/register test/**/*.spec.ts --reporter spec","report-coverage":"nyc report --reporter=text-lcov > coverage.lcov && codecov","lint":"tslint --fix -c tslint.json './src/**/*.ts'","clean":"rimraf dist","prepare":"npm run build","generate:docs":"rimraf docs && typedoc src --out docs --target ES6 --excludePrivate && touch docs/.nojekyll && touch docs/modules/.nojekyll"},"keywords":[],"license":"MIT","devDependencies":{"@types/lodash":"^4.14.104","@types/winston":"^2.3.8","codecov":"^3.0.4","coveralls":"^3.0.0","istanbul":"^0.4.5","nyc":"^12.0.2"},"dependencies":{"@theledger/couchdb-query-engine":"^2.4.4","@types/google-protobuf":"^3.7.2","fabric-shim":"2.5.4","google-protobuf":"^3.6.1","lodash":"^4.17.11","winston":"^2.4.0"},"publishConfig":{"registry":"https://registry.npmjs.org","access":"public"},"husky":{"hooks":{"pre-push":"npm run test && git add ."}},"nyc":{"include":["src/**/*.ts"],"extension":[".ts"],"require":["ts-node/register"],"reporter":["text"],"sourceMap":true,"instrument":true},"readme":"[![Build Status](https://travis-ci.org/wearetheledger/fabric-mock-stub.svg?branch=master)](https://travis-ci.org/wearetheledger/fabric-mock-stub) [![npm version](https://badge.fury.io/js/%40theledger%2Ffabric-mock-stub.svg)](https://badge.fury.io/js/%40theledger%2Ffabric-mock-stub) [![codecov](https://codecov.io/gh/wearetheledger/fabric-mock-stub/branch/master/graph/badge.svg)](https://codecov.io/gh/wearetheledger/fabric-mock-stub)\n# Hyperledger Fabric Nodejs mockstub\n\nA Nodejs module that helps you to test your Hyperledger Fabric Nodejs chaincode. When it proves itself, we will be adding this package to the official Gerrit of the Fabric Nodejs SDK.\n\n- [Docs](https://wearetheledger.github.io/fabric-mock-stub)\n- [Example usage](https://github.com/wearetheledger/fabric-network-boilerplate/tree/master/chaincode/node)\n- [Article about this repo](https://medium.com/wearetheledger/how-to-start-testing-your-hyperledger-fabric-nodejs-chaincode-229453c3c214)\n\n## 🚨 Note\nDue to the complexity, key endorsement policies introduced in v1.4 are currently not being enforced.\n\n## Table of contents\n- [Version matching](#version-matching)\n- [Installation](#installation)\n- [Todo](#todo)\n- [Usage](#usage)\n- [Contributing](#contributing)\n- [Credits](#credits)\n- [License](#license)\n\n## Version matching\n| Fabric node SDK        | Mock stub    |\n| ------------- |:-------------:|\n| v1.4.X     | v4.X.X |\n| v1.3.X     | v3.X.X |\n| v1.2.X     | v2.X.X |\n| V1.1.X     | v1.3.X     |\n\n\n## Installation\n```sh\nyarn add @theledger/fabric-mock-stub --dev\n```\n\n## Todo\n- [ ] Finish [node-couchdb-query-engine](https://github.com/wearetheledger/node-couchdb-query-engine)\n- [ ] Implement `fields` and `sort` into GetQueryResult\n- Implement remaining mock methods for\n    - [ ] getBinding\n    - [ ] getChannelID\n\n## Usage\n### ChaincodeMockStub [View definition](https://wearetheledger.github.io/fabric-mock-stub/classes/_chaincodemockstub_.chaincodemockstub.html)\nThis ChaincodeMockStub is a Mock implementation of the fabric-shim stub. This means you can test your chaincode without actually starting your network.\n\nExamples are located at [examples/tests](examples/tests)\n\n**!! Following methods are not (yet) implemented and will not work !!**\n- getBinding\n- getChannelID\n\n### How to test\nTesting NodeJS chaincode works similarly to testing using the mockstub in the Golang chaincode.\n\nThe **ChaincodeMockStub** has 2 important mock functions `mockInit`and `mockInvoke`. By passing your chaincode, it will mock a transaction and execute a invoke/init similarly to how it will originally be called. Both these functions will return a [ChaincodeResponse](https://github.com/wearetheledger/fabric-shim-types/blob/4b8844769c2439303954d03f5c8a66dc0a795ed4/index.d.ts#L93). Using this ChaincodeResponse object, we can test whether or not the action returned an expected result.\n\nOn *success*, this response will look like this. If the method returns something, the response will also contain a `payload`.\n\n```json\n{\n    \"status\": 200,\n    \"payload\": <Buffer_with_your_data>\n}\n```\n\nOn *error*, this response will look like this.\n\n```json\n{\n    \"status\": 500,\n    \"message\": <Buffer_with_your_error_message>\n}\n```\n\nYou'll be able to validate the response using something like `chai`.\n\n```javascript\n// Validate response status\nexpect(response.status).to.eql(200)\n// Validate payload - using `Transform.bufferToObject` because we recieve the payload as a buffer\nexpect(Transform.bufferToObject(response.payload).owner).to.eql(\"newOwner\")\n```\n\n#### Include your chaincode\nAt the top of your test file, you can import and instantiate your chaincode, this only has to be done once.\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n```\n#### Include the mockstub\nAfter this, in your tests, you can create a new mockstub. You have to pass a random name (not that important) and your chaincode. It's up to you if you want to create a new mockstub for each test, which runs those tests with an empty state. Or use one for all the tests. If you reuse the same stub, you also reuse the previous tests state.\n\n```javascript\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\nconst mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n```\n\n#### Example\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should init without issues\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        // Your test code\n    });\n});\n```\n\n### Test Init\nThe `Init()`method can be tested using the `mockStub.mockInit(txId: string, args: string[])` function. It will create a new mock transaction and call the init method on your chaincode. Since the init happens when instantiating your chaincode, you generally don't want it to return anything. So, for this, we'll check the response status.\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should init without issues\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInit(\"tx1\", []);\n\n        expect(response.status).to.eql(200)\n    });\n});\n```\n\n### Test Invoke\nThe `Invoke()`method can be tested using the `mockStub.mockInvoke(txId: string, args: string[])` function. It will create a new mock transaction and call the invoke method on your chaincode. The client will either send a query or an invoke, but the chaincode will accept these both as invoke. In your tests there isn't any difference, both invokes and queries can return a result.\n\n**Test queryCar**\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should query car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInvoke(\"tx2\", ['queryCar', `CAR0`]);\n\n        expect(Transform.bufferToObject(response.payload)).to.deep.eq({\n            'make': 'prop1',\n            'model': 'prop2',\n            'color': 'prop3',\n            'owner': 'owner',\n            'docType': 'car'\n        });\n    });\n});\n```\n\n**Test createCar**\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInvoke(\"tx1\", ['createCar', `CAR0`, `prop1`, `prop2`, `prop3`, `owner`]);\n\n        expect(response.status).to.eql(200)\n\n        const response = await mockStub.mockInvoke(\"tx1\", ['queryCar', `CAR0`]);\n\n        expect(Transform.bufferToObject(response.payload)).to.deep.eq({\n            'make': 'prop1',\n            'model': 'prop2',\n            'color': 'prop3',\n            'owner': 'owner',\n            'docType': 'car'\n        })\n    });\n});\n```\n\n### Testing individual classes\nYou are not required to only test using the `mockInvoke` and `mockInit`. You can directly call the methods on your chaincode or on the mockStub if you really want to.\n\n#### Testing using Mychaincode directly\nA remark when using this, depending what you return in your function, you will be able to receive a Buffer or an object in your tests. This is discussed in [chaincode](#writing-chaincode)\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const stub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const car0 = {\n            'make': 'Toyota',\n            'model': 'Prius',\n            'color': 'blue',\n            'owner': 'Tomoko',\n            'docType': 'car'\n        };\n\n        const car = await chaincode.queryCar(stub, [\"CAR0\"])\n\n        expect(car).to.deep.equal(car0);\n    });\n});\n```\n\n#### Testing using ChaincodeMockStub directly 🤨\nYou can do this, but you shouldn't. Your logic should be written in your functions, not your tests.\n\n##### Test query results\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const query = {\n            selector: {\n                model: {\n                    \"$in\": ['Nano', \"Punto\"]\n                }\n            }\n        };\n\n        const it = await mockStub.getQueryResult(JSON.stringify(query));\n\n        const items = await Transform.iteratorToList(it);\n\n        expect(items).to.be.length(2)\n    });\n});\n```\n\n##### Test emitted events\n\n```javascript\nit(\"Should get the emitted event\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        await mockStub.mockInvoke(\"tx1\", ['createCar', `CAR0`, `prop1`, `prop2`, `prop3`, `owner`]);\n\n        const eventPayload = await mockStub.getEvent('CREATE_CAR');\n\n        expect(eventPayload).to.equal('Car created.');\n});\n```\n\n## Contributing\n\n1. Fork it! 🍴\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request 😁 🎉\n\n## Credits\n\n- Developer - Jo ([@jestersimpps](https://github.com/jestersimpps))\n- Developer - Jonas ([@Superjo149](https://github.com/Superjo149))\n- Company - TheLedger ([theledger.be](https://theledger.be))\n\n## License\nThe MIT License (MIT)\n\nCopyright (c) 2018 TheLedger\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","gitHead":"8939dce7fe46db813b5072d4f2da55a81137be72","_id":"@apex-pub/fabric-mock-stub@1.4.1-4-alpha.8939dce7","_nodeVersion":"20.4.0","_npmVersion":"9.7.2","dist":{"integrity":"sha512-EvhaPCb6eT1xBXBllEyqXnT1GNNIH6tLm/WSkXgAm+bnCEz3u2Y04q8AmDOZB9kM6FD5IPe1aTdAZJJ+wNj6+w==","shasum":"3e84ecc0c336e2dccfe64ebc1c88790231fd4a80","tarball":"https://registry.npmjs.org/@apex-pub/fabric-mock-stub/-/fabric-mock-stub-1.4.1-4-alpha.8939dce7.tgz","fileCount":44,"unpackedSize":105865,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFE5Wz21AzLPXb5QMcTYocpyDfwa6gXilXdANlIzY+o9AiEA0Qi0Vk2BfPyJPlBnbnHbBsOJOJ2Pq84bUnoOes1OqEM="}]},"_npmUser":{"name":"akshaysood112","email":"akshay.sood@live.com"},"directories":{},"maintainers":[{"name":"akshaysood112","email":"akshay.sood@live.com"},{"name":"rodolfoleal","email":"rodolfo.pk@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fabric-mock-stub_1.4.1-4-alpha.8939dce7_1690256533564_0.30091869064653576"},"_hasShrinkwrap":false},"1.4.1-4-alpha.4ece38f3":{"name":"@apex-pub/fabric-mock-stub","version":"1.4.1-4-alpha.4ece38f3","description":"Mock implementation of the hyperledger fabric-shim package for testing","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npm run clean && tsc","test":"mocha -r ts-node/register test/**/*.spec.ts --reporter spec","test:coverage":"nyc --no-clean mocha -r ts-node/register test/**/*.spec.ts --reporter spec","report-coverage":"nyc report --reporter=text-lcov > coverage.lcov && codecov","lint":"tslint --fix -c tslint.json './src/**/*.ts'","clean":"rimraf dist","prepare":"npm run build","generate:docs":"rimraf docs && typedoc src --out docs --target ES6 --excludePrivate && touch docs/.nojekyll && touch docs/modules/.nojekyll"},"keywords":[],"license":"MIT","devDependencies":{"@types/lodash":"^4.14.104","@types/winston":"^2.3.8","codecov":"^3.0.4","coveralls":"^3.0.0","istanbul":"^0.4.5","nyc":"^12.0.2"},"dependencies":{"@theledger/couchdb-query-engine":"^2.4.4","@types/google-protobuf":"^3.7.2","fabric-shim":"2.5.4","google-protobuf":"^3.6.1","lodash":"^4.17.11","winston":"^2.4.0"},"publishConfig":{"registry":"https://registry.npmjs.org","access":"public"},"husky":{"hooks":{"pre-push":"npm run test && git add ."}},"nyc":{"include":["src/**/*.ts"],"extension":[".ts"],"require":["ts-node/register"],"reporter":["text"],"sourceMap":true,"instrument":true},"_id":"@apex-pub/fabric-mock-stub@1.4.1-4-alpha.4ece38f3","readme":"[![Build Status](https://travis-ci.org/wearetheledger/fabric-mock-stub.svg?branch=master)](https://travis-ci.org/wearetheledger/fabric-mock-stub) [![npm version](https://badge.fury.io/js/%40theledger%2Ffabric-mock-stub.svg)](https://badge.fury.io/js/%40theledger%2Ffabric-mock-stub) [![codecov](https://codecov.io/gh/wearetheledger/fabric-mock-stub/branch/master/graph/badge.svg)](https://codecov.io/gh/wearetheledger/fabric-mock-stub)\n# Hyperledger Fabric Nodejs mockstub\n\nA Nodejs module that helps you to test your Hyperledger Fabric Nodejs chaincode. When it proves itself, we will be adding this package to the official Gerrit of the Fabric Nodejs SDK.\n\n- [Docs](https://wearetheledger.github.io/fabric-mock-stub)\n- [Example usage](https://github.com/wearetheledger/fabric-network-boilerplate/tree/master/chaincode/node)\n- [Article about this repo](https://medium.com/wearetheledger/how-to-start-testing-your-hyperledger-fabric-nodejs-chaincode-229453c3c214)\n\n## 🚨 Note\nDue to the complexity, key endorsement policies introduced in v1.4 are currently not being enforced.\n\n## Table of contents\n- [Version matching](#version-matching)\n- [Installation](#installation)\n- [Todo](#todo)\n- [Usage](#usage)\n- [Contributing](#contributing)\n- [Credits](#credits)\n- [License](#license)\n\n## Version matching\n| Fabric node SDK        | Mock stub    |\n| ------------- |:-------------:|\n| v1.4.X     | v4.X.X |\n| v1.3.X     | v3.X.X |\n| v1.2.X     | v2.X.X |\n| V1.1.X     | v1.3.X     |\n\n\n## Installation\n```sh\nyarn add @theledger/fabric-mock-stub --dev\n```\n\n## Todo\n- [ ] Finish [node-couchdb-query-engine](https://github.com/wearetheledger/node-couchdb-query-engine)\n- [ ] Implement `fields` and `sort` into GetQueryResult\n- Implement remaining mock methods for\n    - [ ] getBinding\n    - [ ] getChannelID\n\n## Usage\n### ChaincodeMockStub [View definition](https://wearetheledger.github.io/fabric-mock-stub/classes/_chaincodemockstub_.chaincodemockstub.html)\nThis ChaincodeMockStub is a Mock implementation of the fabric-shim stub. This means you can test your chaincode without actually starting your network.\n\nExamples are located at [examples/tests](examples/tests)\n\n**!! Following methods are not (yet) implemented and will not work !!**\n- getBinding\n- getChannelID\n\n### How to test\nTesting NodeJS chaincode works similarly to testing using the mockstub in the Golang chaincode.\n\nThe **ChaincodeMockStub** has 2 important mock functions `mockInit`and `mockInvoke`. By passing your chaincode, it will mock a transaction and execute a invoke/init similarly to how it will originally be called. Both these functions will return a [ChaincodeResponse](https://github.com/wearetheledger/fabric-shim-types/blob/4b8844769c2439303954d03f5c8a66dc0a795ed4/index.d.ts#L93). Using this ChaincodeResponse object, we can test whether or not the action returned an expected result.\n\nOn *success*, this response will look like this. If the method returns something, the response will also contain a `payload`.\n\n```json\n{\n    \"status\": 200,\n    \"payload\": <Buffer_with_your_data>\n}\n```\n\nOn *error*, this response will look like this.\n\n```json\n{\n    \"status\": 500,\n    \"message\": <Buffer_with_your_error_message>\n}\n```\n\nYou'll be able to validate the response using something like `chai`.\n\n```javascript\n// Validate response status\nexpect(response.status).to.eql(200)\n// Validate payload - using `Transform.bufferToObject` because we recieve the payload as a buffer\nexpect(Transform.bufferToObject(response.payload).owner).to.eql(\"newOwner\")\n```\n\n#### Include your chaincode\nAt the top of your test file, you can import and instantiate your chaincode, this only has to be done once.\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n```\n#### Include the mockstub\nAfter this, in your tests, you can create a new mockstub. You have to pass a random name (not that important) and your chaincode. It's up to you if you want to create a new mockstub for each test, which runs those tests with an empty state. Or use one for all the tests. If you reuse the same stub, you also reuse the previous tests state.\n\n```javascript\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\nconst mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n```\n\n#### Example\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should init without issues\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        // Your test code\n    });\n});\n```\n\n### Test Init\nThe `Init()`method can be tested using the `mockStub.mockInit(txId: string, args: string[])` function. It will create a new mock transaction and call the init method on your chaincode. Since the init happens when instantiating your chaincode, you generally don't want it to return anything. So, for this, we'll check the response status.\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should init without issues\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInit(\"tx1\", []);\n\n        expect(response.status).to.eql(200)\n    });\n});\n```\n\n### Test Invoke\nThe `Invoke()`method can be tested using the `mockStub.mockInvoke(txId: string, args: string[])` function. It will create a new mock transaction and call the invoke method on your chaincode. The client will either send a query or an invoke, but the chaincode will accept these both as invoke. In your tests there isn't any difference, both invokes and queries can return a result.\n\n**Test queryCar**\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should query car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInvoke(\"tx2\", ['queryCar', `CAR0`]);\n\n        expect(Transform.bufferToObject(response.payload)).to.deep.eq({\n            'make': 'prop1',\n            'model': 'prop2',\n            'color': 'prop3',\n            'owner': 'owner',\n            'docType': 'car'\n        });\n    });\n});\n```\n\n**Test createCar**\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInvoke(\"tx1\", ['createCar', `CAR0`, `prop1`, `prop2`, `prop3`, `owner`]);\n\n        expect(response.status).to.eql(200)\n\n        const response = await mockStub.mockInvoke(\"tx1\", ['queryCar', `CAR0`]);\n\n        expect(Transform.bufferToObject(response.payload)).to.deep.eq({\n            'make': 'prop1',\n            'model': 'prop2',\n            'color': 'prop3',\n            'owner': 'owner',\n            'docType': 'car'\n        })\n    });\n});\n```\n\n### Testing individual classes\nYou are not required to only test using the `mockInvoke` and `mockInit`. You can directly call the methods on your chaincode or on the mockStub if you really want to.\n\n#### Testing using Mychaincode directly\nA remark when using this, depending what you return in your function, you will be able to receive a Buffer or an object in your tests. This is discussed in [chaincode](#writing-chaincode)\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const stub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const car0 = {\n            'make': 'Toyota',\n            'model': 'Prius',\n            'color': 'blue',\n            'owner': 'Tomoko',\n            'docType': 'car'\n        };\n\n        const car = await chaincode.queryCar(stub, [\"CAR0\"])\n\n        expect(car).to.deep.equal(car0);\n    });\n});\n```\n\n#### Testing using ChaincodeMockStub directly 🤨\nYou can do this, but you shouldn't. Your logic should be written in your functions, not your tests.\n\n##### Test query results\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const query = {\n            selector: {\n                model: {\n                    \"$in\": ['Nano', \"Punto\"]\n                }\n            }\n        };\n\n        const it = await mockStub.getQueryResult(JSON.stringify(query));\n\n        const items = await Transform.iteratorToList(it);\n\n        expect(items).to.be.length(2)\n    });\n});\n```\n\n##### Test emitted events\n\n```javascript\nit(\"Should get the emitted event\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        await mockStub.mockInvoke(\"tx1\", ['createCar', `CAR0`, `prop1`, `prop2`, `prop3`, `owner`]);\n\n        const eventPayload = await mockStub.getEvent('CREATE_CAR');\n\n        expect(eventPayload).to.equal('Car created.');\n});\n```\n\n## Contributing\n\n1. Fork it! 🍴\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request 😁 🎉\n\n## Credits\n\n- Developer - Jo ([@jestersimpps](https://github.com/jestersimpps))\n- Developer - Jonas ([@Superjo149](https://github.com/Superjo149))\n- Company - TheLedger ([theledger.be](https://theledger.be))\n\n## License\nThe MIT License (MIT)\n\nCopyright (c) 2018 TheLedger\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","gitHead":"4ece38f36a95a1f2b40729529c9327ac7fe340c2","_nodeVersion":"20.5.0","_npmVersion":"9.8.0","dist":{"integrity":"sha512-ZHwofn0hlEpLlhilB67ZAyV4iiP7A9c2kMWUoIQMZ0bBY3DtaU/6SexOnMgVMM2NoV413jVa7eLNCxtXkc3JuQ==","shasum":"7ccfd546883d510cee123898a43bbfffb3c11273","tarball":"https://registry.npmjs.org/@apex-pub/fabric-mock-stub/-/fabric-mock-stub-1.4.1-4-alpha.4ece38f3.tgz","fileCount":44,"unpackedSize":105782,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCC2tDh8ekpHt4xtoU8Znr64QHRgqoD2y+WEdOCrO/0WQIhAITApFNSgiEOm0lruuslAlVSQ/Svgyw6JOiiwyVS0WvO"}]},"_npmUser":{"name":"akshaysood112","email":"akshay.sood@live.com"},"directories":{},"maintainers":[{"name":"akshaysood112","email":"akshay.sood@live.com"},{"name":"rodolfoleal","email":"rodolfo.pk@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fabric-mock-stub_1.4.1-4-alpha.4ece38f3_1690404370351_0.5229300295641808"},"_hasShrinkwrap":false},"1.4.1-4-alpha.5d0544b6":{"name":"@apex-pub/fabric-mock-stub","version":"1.4.1-4-alpha.5d0544b6","description":"Mock implementation of the hyperledger fabric-shim package for testing","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npm run clean && tsc","test":"mocha -r ts-node/register test/**/*.spec.ts --reporter spec","test:coverage":"nyc --no-clean mocha -r ts-node/register test/**/*.spec.ts --reporter spec","report-coverage":"nyc report --reporter=text-lcov > coverage.lcov && codecov","lint":"tslint --fix -c tslint.json './src/**/*.ts'","clean":"rimraf dist","prepare":"npm run build","generate:docs":"rimraf docs && typedoc src --out docs --target ES6 --excludePrivate && touch docs/.nojekyll && touch docs/modules/.nojekyll"},"keywords":[],"license":"MIT","devDependencies":{"@types/lodash":"^4.14.104","@types/winston":"^2.3.8","codecov":"^3.0.4","coveralls":"^3.0.0","istanbul":"^0.4.5","nyc":"^12.0.2"},"dependencies":{"@theledger/couchdb-query-engine":"^2.4.4","@types/google-protobuf":"^3.7.2","fabric-shim":"2.5.4","google-protobuf":"^3.6.1","lodash":"^4.17.11","winston":"^2.4.0"},"publishConfig":{"registry":"https://registry.npmjs.org","access":"public"},"husky":{"hooks":{"pre-push":"npm run test && git add ."}},"nyc":{"include":["src/**/*.ts"],"extension":[".ts"],"require":["ts-node/register"],"reporter":["text"],"sourceMap":true,"instrument":true},"_id":"@apex-pub/fabric-mock-stub@1.4.1-4-alpha.5d0544b6","readme":"[![Build Status](https://travis-ci.org/wearetheledger/fabric-mock-stub.svg?branch=master)](https://travis-ci.org/wearetheledger/fabric-mock-stub) [![npm version](https://badge.fury.io/js/%40theledger%2Ffabric-mock-stub.svg)](https://badge.fury.io/js/%40theledger%2Ffabric-mock-stub) [![codecov](https://codecov.io/gh/wearetheledger/fabric-mock-stub/branch/master/graph/badge.svg)](https://codecov.io/gh/wearetheledger/fabric-mock-stub)\n# Hyperledger Fabric Nodejs mockstub\n\nA Nodejs module that helps you to test your Hyperledger Fabric Nodejs chaincode. When it proves itself, we will be adding this package to the official Gerrit of the Fabric Nodejs SDK.\n\n- [Docs](https://wearetheledger.github.io/fabric-mock-stub)\n- [Example usage](https://github.com/wearetheledger/fabric-network-boilerplate/tree/master/chaincode/node)\n- [Article about this repo](https://medium.com/wearetheledger/how-to-start-testing-your-hyperledger-fabric-nodejs-chaincode-229453c3c214)\n\n## 🚨 Note\nDue to the complexity, key endorsement policies introduced in v1.4 are currently not being enforced.\n\n## Table of contents\n- [Version matching](#version-matching)\n- [Installation](#installation)\n- [Todo](#todo)\n- [Usage](#usage)\n- [Contributing](#contributing)\n- [Credits](#credits)\n- [License](#license)\n\n## Version matching\n| Fabric node SDK        | Mock stub    |\n| ------------- |:-------------:|\n| v1.4.X     | v4.X.X |\n| v1.3.X     | v3.X.X |\n| v1.2.X     | v2.X.X |\n| V1.1.X     | v1.3.X     |\n\n\n## Installation\n```sh\nyarn add @theledger/fabric-mock-stub --dev\n```\n\n## Todo\n- [ ] Finish [node-couchdb-query-engine](https://github.com/wearetheledger/node-couchdb-query-engine)\n- [ ] Implement `fields` and `sort` into GetQueryResult\n- Implement remaining mock methods for\n    - [ ] getBinding\n    - [ ] getChannelID\n\n## Usage\n### ChaincodeMockStub [View definition](https://wearetheledger.github.io/fabric-mock-stub/classes/_chaincodemockstub_.chaincodemockstub.html)\nThis ChaincodeMockStub is a Mock implementation of the fabric-shim stub. This means you can test your chaincode without actually starting your network.\n\nExamples are located at [examples/tests](examples/tests)\n\n**!! Following methods are not (yet) implemented and will not work !!**\n- getBinding\n- getChannelID\n\n### How to test\nTesting NodeJS chaincode works similarly to testing using the mockstub in the Golang chaincode.\n\nThe **ChaincodeMockStub** has 2 important mock functions `mockInit`and `mockInvoke`. By passing your chaincode, it will mock a transaction and execute a invoke/init similarly to how it will originally be called. Both these functions will return a [ChaincodeResponse](https://github.com/wearetheledger/fabric-shim-types/blob/4b8844769c2439303954d03f5c8a66dc0a795ed4/index.d.ts#L93). Using this ChaincodeResponse object, we can test whether or not the action returned an expected result.\n\nOn *success*, this response will look like this. If the method returns something, the response will also contain a `payload`.\n\n```json\n{\n    \"status\": 200,\n    \"payload\": <Buffer_with_your_data>\n}\n```\n\nOn *error*, this response will look like this.\n\n```json\n{\n    \"status\": 500,\n    \"message\": <Buffer_with_your_error_message>\n}\n```\n\nYou'll be able to validate the response using something like `chai`.\n\n```javascript\n// Validate response status\nexpect(response.status).to.eql(200)\n// Validate payload - using `Transform.bufferToObject` because we recieve the payload as a buffer\nexpect(Transform.bufferToObject(response.payload).owner).to.eql(\"newOwner\")\n```\n\n#### Include your chaincode\nAt the top of your test file, you can import and instantiate your chaincode, this only has to be done once.\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n```\n#### Include the mockstub\nAfter this, in your tests, you can create a new mockstub. You have to pass a random name (not that important) and your chaincode. It's up to you if you want to create a new mockstub for each test, which runs those tests with an empty state. Or use one for all the tests. If you reuse the same stub, you also reuse the previous tests state.\n\n```javascript\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\nconst mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n```\n\n#### Example\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should init without issues\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        // Your test code\n    });\n});\n```\n\n### Test Init\nThe `Init()`method can be tested using the `mockStub.mockInit(txId: string, args: string[])` function. It will create a new mock transaction and call the init method on your chaincode. Since the init happens when instantiating your chaincode, you generally don't want it to return anything. So, for this, we'll check the response status.\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should init without issues\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInit(\"tx1\", []);\n\n        expect(response.status).to.eql(200)\n    });\n});\n```\n\n### Test Invoke\nThe `Invoke()`method can be tested using the `mockStub.mockInvoke(txId: string, args: string[])` function. It will create a new mock transaction and call the invoke method on your chaincode. The client will either send a query or an invoke, but the chaincode will accept these both as invoke. In your tests there isn't any difference, both invokes and queries can return a result.\n\n**Test queryCar**\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should query car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInvoke(\"tx2\", ['queryCar', `CAR0`]);\n\n        expect(Transform.bufferToObject(response.payload)).to.deep.eq({\n            'make': 'prop1',\n            'model': 'prop2',\n            'color': 'prop3',\n            'owner': 'owner',\n            'docType': 'car'\n        });\n    });\n});\n```\n\n**Test createCar**\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInvoke(\"tx1\", ['createCar', `CAR0`, `prop1`, `prop2`, `prop3`, `owner`]);\n\n        expect(response.status).to.eql(200)\n\n        const response = await mockStub.mockInvoke(\"tx1\", ['queryCar', `CAR0`]);\n\n        expect(Transform.bufferToObject(response.payload)).to.deep.eq({\n            'make': 'prop1',\n            'model': 'prop2',\n            'color': 'prop3',\n            'owner': 'owner',\n            'docType': 'car'\n        })\n    });\n});\n```\n\n### Testing individual classes\nYou are not required to only test using the `mockInvoke` and `mockInit`. You can directly call the methods on your chaincode or on the mockStub if you really want to.\n\n#### Testing using Mychaincode directly\nA remark when using this, depending what you return in your function, you will be able to receive a Buffer or an object in your tests. This is discussed in [chaincode](#writing-chaincode)\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const stub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const car0 = {\n            'make': 'Toyota',\n            'model': 'Prius',\n            'color': 'blue',\n            'owner': 'Tomoko',\n            'docType': 'car'\n        };\n\n        const car = await chaincode.queryCar(stub, [\"CAR0\"])\n\n        expect(car).to.deep.equal(car0);\n    });\n});\n```\n\n#### Testing using ChaincodeMockStub directly 🤨\nYou can do this, but you shouldn't. Your logic should be written in your functions, not your tests.\n\n##### Test query results\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const query = {\n            selector: {\n                model: {\n                    \"$in\": ['Nano', \"Punto\"]\n                }\n            }\n        };\n\n        const it = await mockStub.getQueryResult(JSON.stringify(query));\n\n        const items = await Transform.iteratorToList(it);\n\n        expect(items).to.be.length(2)\n    });\n});\n```\n\n##### Test emitted events\n\n```javascript\nit(\"Should get the emitted event\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        await mockStub.mockInvoke(\"tx1\", ['createCar', `CAR0`, `prop1`, `prop2`, `prop3`, `owner`]);\n\n        const eventPayload = await mockStub.getEvent('CREATE_CAR');\n\n        expect(eventPayload).to.equal('Car created.');\n});\n```\n\n## Contributing\n\n1. Fork it! 🍴\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request 😁 🎉\n\n## Credits\n\n- Developer - Jo ([@jestersimpps](https://github.com/jestersimpps))\n- Developer - Jonas ([@Superjo149](https://github.com/Superjo149))\n- Company - TheLedger ([theledger.be](https://theledger.be))\n\n## License\nThe MIT License (MIT)\n\nCopyright (c) 2018 TheLedger\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","gitHead":"5d0544b6d6d70377be9a2450794393f3543c3186","_nodeVersion":"20.5.0","_npmVersion":"9.8.0","dist":{"integrity":"sha512-f1YtYQdLxx45znTWOdnVVVLHqOBz/037ewwm/vHa9RgMgZV3eFneT1cdXRdmsbwgBQwpAT74Kh0syxtNqsQoag==","shasum":"480738cd8947fbf7c493079de6ecb079bcad49eb","tarball":"https://registry.npmjs.org/@apex-pub/fabric-mock-stub/-/fabric-mock-stub-1.4.1-4-alpha.5d0544b6.tgz","fileCount":44,"unpackedSize":105782,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICci3P1OBQ3D9eAzrOLtNvU/3PJ7z06mBlFdX/OlxDmVAiAWIVOx3K89+NmVqQ2TMUXVnbe7OJfzr8ljjcYki44VkQ=="}]},"_npmUser":{"name":"akshaysood112","email":"akshay.sood@live.com"},"directories":{},"maintainers":[{"name":"akshaysood112","email":"akshay.sood@live.com"},{"name":"rodolfoleal","email":"rodolfo.pk@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fabric-mock-stub_1.4.1-4-alpha.5d0544b6_1690418179531_0.012670141288513959"},"_hasShrinkwrap":false},"1.4.1-4-alpha.e17c6b86":{"name":"@apex-pub/fabric-mock-stub","version":"1.4.1-4-alpha.e17c6b86","description":"Mock implementation of the hyperledger fabric-shim package for testing","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npm run clean && tsc","test":"mocha -r ts-node/register test/**/*.spec.ts --reporter spec","test:coverage":"nyc --no-clean mocha -r ts-node/register test/**/*.spec.ts --reporter spec","report-coverage":"nyc report --reporter=text-lcov > coverage.lcov && codecov","lint":"tslint --fix -c tslint.json './src/**/*.ts'","clean":"rimraf dist","prepare":"npm run build","generate:docs":"rimraf docs && typedoc src --out docs --target ES6 --excludePrivate && touch docs/.nojekyll && touch docs/modules/.nojekyll"},"keywords":[],"license":"MIT","devDependencies":{"@types/lodash":"^4.14.104","@types/winston":"^2.3.8","codecov":"^3.0.4","coveralls":"^3.0.0","istanbul":"^0.4.5","nyc":"^12.0.2"},"dependencies":{"@theledger/couchdb-query-engine":"^2.4.4","@types/google-protobuf":"^3.7.2","fabric-shim":"2.5.4","google-protobuf":"^3.6.1","lodash":"^4.17.11","winston":"^2.4.0"},"publishConfig":{"registry":"https://registry.npmjs.org","access":"public"},"husky":{"hooks":{"pre-push":"npm run test && git add ."}},"nyc":{"include":["src/**/*.ts"],"extension":[".ts"],"require":["ts-node/register"],"reporter":["text"],"sourceMap":true,"instrument":true},"_id":"@apex-pub/fabric-mock-stub@1.4.1-4-alpha.e17c6b86","readme":"[![Build Status](https://travis-ci.org/wearetheledger/fabric-mock-stub.svg?branch=master)](https://travis-ci.org/wearetheledger/fabric-mock-stub) [![npm version](https://badge.fury.io/js/%40theledger%2Ffabric-mock-stub.svg)](https://badge.fury.io/js/%40theledger%2Ffabric-mock-stub) [![codecov](https://codecov.io/gh/wearetheledger/fabric-mock-stub/branch/master/graph/badge.svg)](https://codecov.io/gh/wearetheledger/fabric-mock-stub)\n# Hyperledger Fabric Nodejs mockstub\n\nA Nodejs module that helps you to test your Hyperledger Fabric Nodejs chaincode. When it proves itself, we will be adding this package to the official Gerrit of the Fabric Nodejs SDK.\n\n- [Docs](https://wearetheledger.github.io/fabric-mock-stub)\n- [Example usage](https://github.com/wearetheledger/fabric-network-boilerplate/tree/master/chaincode/node)\n- [Article about this repo](https://medium.com/wearetheledger/how-to-start-testing-your-hyperledger-fabric-nodejs-chaincode-229453c3c214)\n\n## 🚨 Note\nDue to the complexity, key endorsement policies introduced in v1.4 are currently not being enforced.\n\n## Table of contents\n- [Version matching](#version-matching)\n- [Installation](#installation)\n- [Todo](#todo)\n- [Usage](#usage)\n- [Contributing](#contributing)\n- [Credits](#credits)\n- [License](#license)\n\n## Version matching\n| Fabric node SDK        | Mock stub    |\n| ------------- |:-------------:|\n| v1.4.X     | v4.X.X |\n| v1.3.X     | v3.X.X |\n| v1.2.X     | v2.X.X |\n| V1.1.X     | v1.3.X     |\n\n\n## Installation\n```sh\nyarn add @theledger/fabric-mock-stub --dev\n```\n\n## Todo\n- [ ] Finish [node-couchdb-query-engine](https://github.com/wearetheledger/node-couchdb-query-engine)\n- [ ] Implement `fields` and `sort` into GetQueryResult\n- Implement remaining mock methods for\n    - [ ] getBinding\n    - [ ] getChannelID\n\n## Usage\n### ChaincodeMockStub [View definition](https://wearetheledger.github.io/fabric-mock-stub/classes/_chaincodemockstub_.chaincodemockstub.html)\nThis ChaincodeMockStub is a Mock implementation of the fabric-shim stub. This means you can test your chaincode without actually starting your network.\n\nExamples are located at [examples/tests](examples/tests)\n\n**!! Following methods are not (yet) implemented and will not work !!**\n- getBinding\n- getChannelID\n\n### How to test\nTesting NodeJS chaincode works similarly to testing using the mockstub in the Golang chaincode.\n\nThe **ChaincodeMockStub** has 2 important mock functions `mockInit`and `mockInvoke`. By passing your chaincode, it will mock a transaction and execute a invoke/init similarly to how it will originally be called. Both these functions will return a [ChaincodeResponse](https://github.com/wearetheledger/fabric-shim-types/blob/4b8844769c2439303954d03f5c8a66dc0a795ed4/index.d.ts#L93). Using this ChaincodeResponse object, we can test whether or not the action returned an expected result.\n\nOn *success*, this response will look like this. If the method returns something, the response will also contain a `payload`.\n\n```json\n{\n    \"status\": 200,\n    \"payload\": <Buffer_with_your_data>\n}\n```\n\nOn *error*, this response will look like this.\n\n```json\n{\n    \"status\": 500,\n    \"message\": <Buffer_with_your_error_message>\n}\n```\n\nYou'll be able to validate the response using something like `chai`.\n\n```javascript\n// Validate response status\nexpect(response.status).to.eql(200)\n// Validate payload - using `Transform.bufferToObject` because we recieve the payload as a buffer\nexpect(Transform.bufferToObject(response.payload).owner).to.eql(\"newOwner\")\n```\n\n#### Include your chaincode\nAt the top of your test file, you can import and instantiate your chaincode, this only has to be done once.\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n```\n#### Include the mockstub\nAfter this, in your tests, you can create a new mockstub. You have to pass a random name (not that important) and your chaincode. It's up to you if you want to create a new mockstub for each test, which runs those tests with an empty state. Or use one for all the tests. If you reuse the same stub, you also reuse the previous tests state.\n\n```javascript\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\nconst mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n```\n\n#### Example\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should init without issues\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        // Your test code\n    });\n});\n```\n\n### Test Init\nThe `Init()`method can be tested using the `mockStub.mockInit(txId: string, args: string[])` function. It will create a new mock transaction and call the init method on your chaincode. Since the init happens when instantiating your chaincode, you generally don't want it to return anything. So, for this, we'll check the response status.\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should init without issues\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInit(\"tx1\", []);\n\n        expect(response.status).to.eql(200)\n    });\n});\n```\n\n### Test Invoke\nThe `Invoke()`method can be tested using the `mockStub.mockInvoke(txId: string, args: string[])` function. It will create a new mock transaction and call the invoke method on your chaincode. The client will either send a query or an invoke, but the chaincode will accept these both as invoke. In your tests there isn't any difference, both invokes and queries can return a result.\n\n**Test queryCar**\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should query car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInvoke(\"tx2\", ['queryCar', `CAR0`]);\n\n        expect(Transform.bufferToObject(response.payload)).to.deep.eq({\n            'make': 'prop1',\n            'model': 'prop2',\n            'color': 'prop3',\n            'owner': 'owner',\n            'docType': 'car'\n        });\n    });\n});\n```\n\n**Test createCar**\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInvoke(\"tx1\", ['createCar', `CAR0`, `prop1`, `prop2`, `prop3`, `owner`]);\n\n        expect(response.status).to.eql(200)\n\n        const response = await mockStub.mockInvoke(\"tx1\", ['queryCar', `CAR0`]);\n\n        expect(Transform.bufferToObject(response.payload)).to.deep.eq({\n            'make': 'prop1',\n            'model': 'prop2',\n            'color': 'prop3',\n            'owner': 'owner',\n            'docType': 'car'\n        })\n    });\n});\n```\n\n### Testing individual classes\nYou are not required to only test using the `mockInvoke` and `mockInit`. You can directly call the methods on your chaincode or on the mockStub if you really want to.\n\n#### Testing using Mychaincode directly\nA remark when using this, depending what you return in your function, you will be able to receive a Buffer or an object in your tests. This is discussed in [chaincode](#writing-chaincode)\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const stub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const car0 = {\n            'make': 'Toyota',\n            'model': 'Prius',\n            'color': 'blue',\n            'owner': 'Tomoko',\n            'docType': 'car'\n        };\n\n        const car = await chaincode.queryCar(stub, [\"CAR0\"])\n\n        expect(car).to.deep.equal(car0);\n    });\n});\n```\n\n#### Testing using ChaincodeMockStub directly 🤨\nYou can do this, but you shouldn't. Your logic should be written in your functions, not your tests.\n\n##### Test query results\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const query = {\n            selector: {\n                model: {\n                    \"$in\": ['Nano', \"Punto\"]\n                }\n            }\n        };\n\n        const it = await mockStub.getQueryResult(JSON.stringify(query));\n\n        const items = await Transform.iteratorToList(it);\n\n        expect(items).to.be.length(2)\n    });\n});\n```\n\n##### Test emitted events\n\n```javascript\nit(\"Should get the emitted event\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        await mockStub.mockInvoke(\"tx1\", ['createCar', `CAR0`, `prop1`, `prop2`, `prop3`, `owner`]);\n\n        const eventPayload = await mockStub.getEvent('CREATE_CAR');\n\n        expect(eventPayload).to.equal('Car created.');\n});\n```\n\n## Contributing\n\n1. Fork it! 🍴\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request 😁 🎉\n\n## Credits\n\n- Developer - Jo ([@jestersimpps](https://github.com/jestersimpps))\n- Developer - Jonas ([@Superjo149](https://github.com/Superjo149))\n- Company - TheLedger ([theledger.be](https://theledger.be))\n\n## License\nThe MIT License (MIT)\n\nCopyright (c) 2018 TheLedger\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","gitHead":"e17c6b86990c301cf6117ff4da58df646d6895b2","_nodeVersion":"20.5.0","_npmVersion":"9.8.0","dist":{"integrity":"sha512-9ZcslWI9UqpG8E0yHY5frprPnqypagMrILmD/yXjIN+uXXtGv5ky2vIdNFSOWRefWSrSOok52dWmfPibJaILCw==","shasum":"51036c28d0bd4159f788166b8fb7b55cbb82ee80","tarball":"https://registry.npmjs.org/@apex-pub/fabric-mock-stub/-/fabric-mock-stub-1.4.1-4-alpha.e17c6b86.tgz","fileCount":44,"unpackedSize":110184,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC8D0i7Eg3f/5kFsVX5Gmab7jgxN0aKetnpSIkSNm7aqgIhALa9yIPTgSHM4kbde1vcVwuE4zbGJ4r6PJMM3FPbsf0c"}]},"_npmUser":{"name":"akshaysood112","email":"akshay.sood@live.com"},"directories":{},"maintainers":[{"name":"akshaysood112","email":"akshay.sood@live.com"},{"name":"rodolfoleal","email":"rodolfo.pk@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fabric-mock-stub_1.4.1-4-alpha.e17c6b86_1690423587461_0.971533556786915"},"_hasShrinkwrap":false},"1.4.1-4-alpha.c429017f":{"name":"@apex-pub/fabric-mock-stub","version":"1.4.1-4-alpha.c429017f","description":"Mock implementation of the hyperledger fabric-shim package for testing","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npm run clean && tsc","test":"mocha -r ts-node/register test/**/*.spec.ts --reporter spec","test:coverage":"nyc --no-clean mocha -r ts-node/register test/**/*.spec.ts --reporter spec","report-coverage":"nyc report --reporter=text-lcov > coverage.lcov && codecov","lint":"tslint --fix -c tslint.json './src/**/*.ts'","clean":"rimraf dist","prepare":"npm run build","generate:docs":"rimraf docs && typedoc src --out docs --target ES6 --excludePrivate && touch docs/.nojekyll && touch docs/modules/.nojekyll"},"keywords":[],"license":"MIT","devDependencies":{"@types/lodash":"^4.14.104","@types/winston":"^2.3.8","codecov":"^3.0.4","coveralls":"^3.0.0","istanbul":"^0.4.5","nyc":"^12.0.2"},"dependencies":{"@theledger/couchdb-query-engine":"^2.4.4","@types/google-protobuf":"^3.7.2","fabric-shim":"2.5.4","google-protobuf":"^3.6.1","lodash":"^4.17.11","winston":"^2.4.0"},"publishConfig":{"registry":"https://registry.npmjs.org","access":"public"},"husky":{"hooks":{"pre-push":"npm run test && git add ."}},"nyc":{"include":["src/**/*.ts"],"extension":[".ts"],"require":["ts-node/register"],"reporter":["text"],"sourceMap":true,"instrument":true},"_id":"@apex-pub/fabric-mock-stub@1.4.1-4-alpha.c429017f","readme":"[![Build Status](https://travis-ci.org/wearetheledger/fabric-mock-stub.svg?branch=master)](https://travis-ci.org/wearetheledger/fabric-mock-stub) [![npm version](https://badge.fury.io/js/%40theledger%2Ffabric-mock-stub.svg)](https://badge.fury.io/js/%40theledger%2Ffabric-mock-stub) [![codecov](https://codecov.io/gh/wearetheledger/fabric-mock-stub/branch/master/graph/badge.svg)](https://codecov.io/gh/wearetheledger/fabric-mock-stub)\n# Hyperledger Fabric Nodejs mockstub\n\nA Nodejs module that helps you to test your Hyperledger Fabric Nodejs chaincode. When it proves itself, we will be adding this package to the official Gerrit of the Fabric Nodejs SDK.\n\n- [Docs](https://wearetheledger.github.io/fabric-mock-stub)\n- [Example usage](https://github.com/wearetheledger/fabric-network-boilerplate/tree/master/chaincode/node)\n- [Article about this repo](https://medium.com/wearetheledger/how-to-start-testing-your-hyperledger-fabric-nodejs-chaincode-229453c3c214)\n\n## 🚨 Note\nDue to the complexity, key endorsement policies introduced in v1.4 are currently not being enforced.\n\n## Table of contents\n- [Version matching](#version-matching)\n- [Installation](#installation)\n- [Todo](#todo)\n- [Usage](#usage)\n- [Contributing](#contributing)\n- [Credits](#credits)\n- [License](#license)\n\n## Version matching\n| Fabric node SDK        | Mock stub    |\n| ------------- |:-------------:|\n| v1.4.X     | v4.X.X |\n| v1.3.X     | v3.X.X |\n| v1.2.X     | v2.X.X |\n| V1.1.X     | v1.3.X     |\n\n\n## Installation\n```sh\nyarn add @theledger/fabric-mock-stub --dev\n```\n\n## Todo\n- [ ] Finish [node-couchdb-query-engine](https://github.com/wearetheledger/node-couchdb-query-engine)\n- [ ] Implement `fields` and `sort` into GetQueryResult\n- Implement remaining mock methods for\n    - [ ] getBinding\n    - [ ] getChannelID\n\n## Usage\n### ChaincodeMockStub [View definition](https://wearetheledger.github.io/fabric-mock-stub/classes/_chaincodemockstub_.chaincodemockstub.html)\nThis ChaincodeMockStub is a Mock implementation of the fabric-shim stub. This means you can test your chaincode without actually starting your network.\n\nExamples are located at [examples/tests](examples/tests)\n\n**!! Following methods are not (yet) implemented and will not work !!**\n- getBinding\n- getChannelID\n\n### How to test\nTesting NodeJS chaincode works similarly to testing using the mockstub in the Golang chaincode.\n\nThe **ChaincodeMockStub** has 2 important mock functions `mockInit`and `mockInvoke`. By passing your chaincode, it will mock a transaction and execute a invoke/init similarly to how it will originally be called. Both these functions will return a [ChaincodeResponse](https://github.com/wearetheledger/fabric-shim-types/blob/4b8844769c2439303954d03f5c8a66dc0a795ed4/index.d.ts#L93). Using this ChaincodeResponse object, we can test whether or not the action returned an expected result.\n\nOn *success*, this response will look like this. If the method returns something, the response will also contain a `payload`.\n\n```json\n{\n    \"status\": 200,\n    \"payload\": <Buffer_with_your_data>\n}\n```\n\nOn *error*, this response will look like this.\n\n```json\n{\n    \"status\": 500,\n    \"message\": <Buffer_with_your_error_message>\n}\n```\n\nYou'll be able to validate the response using something like `chai`.\n\n```javascript\n// Validate response status\nexpect(response.status).to.eql(200)\n// Validate payload - using `Transform.bufferToObject` because we recieve the payload as a buffer\nexpect(Transform.bufferToObject(response.payload).owner).to.eql(\"newOwner\")\n```\n\n#### Include your chaincode\nAt the top of your test file, you can import and instantiate your chaincode, this only has to be done once.\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n```\n#### Include the mockstub\nAfter this, in your tests, you can create a new mockstub. You have to pass a random name (not that important) and your chaincode. It's up to you if you want to create a new mockstub for each test, which runs those tests with an empty state. Or use one for all the tests. If you reuse the same stub, you also reuse the previous tests state.\n\n```javascript\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\nconst mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n```\n\n#### Example\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should init without issues\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        // Your test code\n    });\n});\n```\n\n### Test Init\nThe `Init()`method can be tested using the `mockStub.mockInit(txId: string, args: string[])` function. It will create a new mock transaction and call the init method on your chaincode. Since the init happens when instantiating your chaincode, you generally don't want it to return anything. So, for this, we'll check the response status.\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should init without issues\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInit(\"tx1\", []);\n\n        expect(response.status).to.eql(200)\n    });\n});\n```\n\n### Test Invoke\nThe `Invoke()`method can be tested using the `mockStub.mockInvoke(txId: string, args: string[])` function. It will create a new mock transaction and call the invoke method on your chaincode. The client will either send a query or an invoke, but the chaincode will accept these both as invoke. In your tests there isn't any difference, both invokes and queries can return a result.\n\n**Test queryCar**\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should query car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInvoke(\"tx2\", ['queryCar', `CAR0`]);\n\n        expect(Transform.bufferToObject(response.payload)).to.deep.eq({\n            'make': 'prop1',\n            'model': 'prop2',\n            'color': 'prop3',\n            'owner': 'owner',\n            'docType': 'car'\n        });\n    });\n});\n```\n\n**Test createCar**\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInvoke(\"tx1\", ['createCar', `CAR0`, `prop1`, `prop2`, `prop3`, `owner`]);\n\n        expect(response.status).to.eql(200)\n\n        const response = await mockStub.mockInvoke(\"tx1\", ['queryCar', `CAR0`]);\n\n        expect(Transform.bufferToObject(response.payload)).to.deep.eq({\n            'make': 'prop1',\n            'model': 'prop2',\n            'color': 'prop3',\n            'owner': 'owner',\n            'docType': 'car'\n        })\n    });\n});\n```\n\n### Testing individual classes\nYou are not required to only test using the `mockInvoke` and `mockInit`. You can directly call the methods on your chaincode or on the mockStub if you really want to.\n\n#### Testing using Mychaincode directly\nA remark when using this, depending what you return in your function, you will be able to receive a Buffer or an object in your tests. This is discussed in [chaincode](#writing-chaincode)\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const stub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const car0 = {\n            'make': 'Toyota',\n            'model': 'Prius',\n            'color': 'blue',\n            'owner': 'Tomoko',\n            'docType': 'car'\n        };\n\n        const car = await chaincode.queryCar(stub, [\"CAR0\"])\n\n        expect(car).to.deep.equal(car0);\n    });\n});\n```\n\n#### Testing using ChaincodeMockStub directly 🤨\nYou can do this, but you shouldn't. Your logic should be written in your functions, not your tests.\n\n##### Test query results\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const query = {\n            selector: {\n                model: {\n                    \"$in\": ['Nano', \"Punto\"]\n                }\n            }\n        };\n\n        const it = await mockStub.getQueryResult(JSON.stringify(query));\n\n        const items = await Transform.iteratorToList(it);\n\n        expect(items).to.be.length(2)\n    });\n});\n```\n\n##### Test emitted events\n\n```javascript\nit(\"Should get the emitted event\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        await mockStub.mockInvoke(\"tx1\", ['createCar', `CAR0`, `prop1`, `prop2`, `prop3`, `owner`]);\n\n        const eventPayload = await mockStub.getEvent('CREATE_CAR');\n\n        expect(eventPayload).to.equal('Car created.');\n});\n```\n\n## Contributing\n\n1. Fork it! 🍴\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request 😁 🎉\n\n## Credits\n\n- Developer - Jo ([@jestersimpps](https://github.com/jestersimpps))\n- Developer - Jonas ([@Superjo149](https://github.com/Superjo149))\n- Company - TheLedger ([theledger.be](https://theledger.be))\n\n## License\nThe MIT License (MIT)\n\nCopyright (c) 2018 TheLedger\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","gitHead":"c429017f7d9f500c23e1920883e17d8497b4a229","_nodeVersion":"20.5.0","_npmVersion":"9.8.0","dist":{"integrity":"sha512-BuXCWmxB7WAzH56kLPfO9C5i5nods0LN0HwiWuoNLMGPf9C8SV2VDPTDsD+8rw01391VWpRK+7lqLNj2uG3zjA==","shasum":"573cefc53544876f520b750243cf94dedca0edba","tarball":"https://registry.npmjs.org/@apex-pub/fabric-mock-stub/-/fabric-mock-stub-1.4.1-4-alpha.c429017f.tgz","fileCount":44,"unpackedSize":110184,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC2grCO6BtXhlYvhQjefSyFQTN/kcDmd+0oQUqxh+JeUAIgJ/rmerm4FzOMtVy1pyYYjlOFO9EkGbz3Q4welsql4zo="}]},"_npmUser":{"name":"akshaysood112","email":"akshay.sood@live.com"},"directories":{},"maintainers":[{"name":"akshaysood112","email":"akshay.sood@live.com"},{"name":"rodolfoleal","email":"rodolfo.pk@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fabric-mock-stub_1.4.1-4-alpha.c429017f_1690472756206_0.8496215015937894"},"_hasShrinkwrap":false},"1.4.1-4-alpha.71b29c8b":{"name":"@apex-pub/fabric-mock-stub","version":"1.4.1-4-alpha.71b29c8b","description":"Mock implementation of the hyperledger fabric-shim package for testing","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npm run clean && tsc","test":"mocha -r ts-node/register test/**/*.spec.ts --reporter spec","test:coverage":"nyc --no-clean mocha -r ts-node/register test/**/*.spec.ts --reporter spec","report-coverage":"nyc report --reporter=text-lcov > coverage.lcov && codecov","lint":"tslint --fix -c tslint.json './src/**/*.ts'","clean":"rimraf dist","prepare":"npm run build","generate:docs":"rimraf docs && typedoc src --out docs --target ES6 --excludePrivate && touch docs/.nojekyll && touch docs/modules/.nojekyll"},"keywords":[],"license":"MIT","devDependencies":{"@types/lodash":"^4.14.104","@types/winston":"^2.3.8","codecov":"^3.0.4","coveralls":"^3.0.0","istanbul":"^0.4.5","nyc":"^12.0.2"},"dependencies":{"@theledger/couchdb-query-engine":"^2.4.4","@types/google-protobuf":"^3.7.2","fabric-shim":"2.5.4","google-protobuf":"^3.6.1","lodash":"^4.17.11","winston":"^2.4.0"},"publishConfig":{"registry":"https://registry.npmjs.org","access":"public"},"husky":{"hooks":{"pre-push":"npm run test && git add ."}},"nyc":{"include":["src/**/*.ts"],"extension":[".ts"],"require":["ts-node/register"],"reporter":["text"],"sourceMap":true,"instrument":true},"_id":"@apex-pub/fabric-mock-stub@1.4.1-4-alpha.71b29c8b","readme":"[![Build Status](https://travis-ci.org/wearetheledger/fabric-mock-stub.svg?branch=master)](https://travis-ci.org/wearetheledger/fabric-mock-stub) [![npm version](https://badge.fury.io/js/%40theledger%2Ffabric-mock-stub.svg)](https://badge.fury.io/js/%40theledger%2Ffabric-mock-stub) [![codecov](https://codecov.io/gh/wearetheledger/fabric-mock-stub/branch/master/graph/badge.svg)](https://codecov.io/gh/wearetheledger/fabric-mock-stub)\n# Hyperledger Fabric Nodejs mockstub\n\nA Nodejs module that helps you to test your Hyperledger Fabric Nodejs chaincode. When it proves itself, we will be adding this package to the official Gerrit of the Fabric Nodejs SDK.\n\n- [Docs](https://wearetheledger.github.io/fabric-mock-stub)\n- [Example usage](https://github.com/wearetheledger/fabric-network-boilerplate/tree/master/chaincode/node)\n- [Article about this repo](https://medium.com/wearetheledger/how-to-start-testing-your-hyperledger-fabric-nodejs-chaincode-229453c3c214)\n\n## 🚨 Note\nDue to the complexity, key endorsement policies introduced in v1.4 are currently not being enforced.\n\n## Table of contents\n- [Version matching](#version-matching)\n- [Installation](#installation)\n- [Todo](#todo)\n- [Usage](#usage)\n- [Contributing](#contributing)\n- [Credits](#credits)\n- [License](#license)\n\n## Version matching\n| Fabric node SDK        | Mock stub    |\n| ------------- |:-------------:|\n| v1.4.X     | v4.X.X |\n| v1.3.X     | v3.X.X |\n| v1.2.X     | v2.X.X |\n| V1.1.X     | v1.3.X     |\n\n\n## Installation\n```sh\nyarn add @theledger/fabric-mock-stub --dev\n```\n\n## Todo\n- [ ] Finish [node-couchdb-query-engine](https://github.com/wearetheledger/node-couchdb-query-engine)\n- [ ] Implement `fields` and `sort` into GetQueryResult\n- Implement remaining mock methods for\n    - [ ] getBinding\n    - [ ] getChannelID\n\n## Usage\n### ChaincodeMockStub [View definition](https://wearetheledger.github.io/fabric-mock-stub/classes/_chaincodemockstub_.chaincodemockstub.html)\nThis ChaincodeMockStub is a Mock implementation of the fabric-shim stub. This means you can test your chaincode without actually starting your network.\n\nExamples are located at [examples/tests](examples/tests)\n\n**!! Following methods are not (yet) implemented and will not work !!**\n- getBinding\n- getChannelID\n\n### How to test\nTesting NodeJS chaincode works similarly to testing using the mockstub in the Golang chaincode.\n\nThe **ChaincodeMockStub** has 2 important mock functions `mockInit`and `mockInvoke`. By passing your chaincode, it will mock a transaction and execute a invoke/init similarly to how it will originally be called. Both these functions will return a [ChaincodeResponse](https://github.com/wearetheledger/fabric-shim-types/blob/4b8844769c2439303954d03f5c8a66dc0a795ed4/index.d.ts#L93). Using this ChaincodeResponse object, we can test whether or not the action returned an expected result.\n\nOn *success*, this response will look like this. If the method returns something, the response will also contain a `payload`.\n\n```json\n{\n    \"status\": 200,\n    \"payload\": <Buffer_with_your_data>\n}\n```\n\nOn *error*, this response will look like this.\n\n```json\n{\n    \"status\": 500,\n    \"message\": <Buffer_with_your_error_message>\n}\n```\n\nYou'll be able to validate the response using something like `chai`.\n\n```javascript\n// Validate response status\nexpect(response.status).to.eql(200)\n// Validate payload - using `Transform.bufferToObject` because we recieve the payload as a buffer\nexpect(Transform.bufferToObject(response.payload).owner).to.eql(\"newOwner\")\n```\n\n#### Include your chaincode\nAt the top of your test file, you can import and instantiate your chaincode, this only has to be done once.\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n```\n#### Include the mockstub\nAfter this, in your tests, you can create a new mockstub. You have to pass a random name (not that important) and your chaincode. It's up to you if you want to create a new mockstub for each test, which runs those tests with an empty state. Or use one for all the tests. If you reuse the same stub, you also reuse the previous tests state.\n\n```javascript\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\nconst mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n```\n\n#### Example\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should init without issues\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        // Your test code\n    });\n});\n```\n\n### Test Init\nThe `Init()`method can be tested using the `mockStub.mockInit(txId: string, args: string[])` function. It will create a new mock transaction and call the init method on your chaincode. Since the init happens when instantiating your chaincode, you generally don't want it to return anything. So, for this, we'll check the response status.\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should init without issues\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInit(\"tx1\", []);\n\n        expect(response.status).to.eql(200)\n    });\n});\n```\n\n### Test Invoke\nThe `Invoke()`method can be tested using the `mockStub.mockInvoke(txId: string, args: string[])` function. It will create a new mock transaction and call the invoke method on your chaincode. The client will either send a query or an invoke, but the chaincode will accept these both as invoke. In your tests there isn't any difference, both invokes and queries can return a result.\n\n**Test queryCar**\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should query car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInvoke(\"tx2\", ['queryCar', `CAR0`]);\n\n        expect(Transform.bufferToObject(response.payload)).to.deep.eq({\n            'make': 'prop1',\n            'model': 'prop2',\n            'color': 'prop3',\n            'owner': 'owner',\n            'docType': 'car'\n        });\n    });\n});\n```\n\n**Test createCar**\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInvoke(\"tx1\", ['createCar', `CAR0`, `prop1`, `prop2`, `prop3`, `owner`]);\n\n        expect(response.status).to.eql(200)\n\n        const response = await mockStub.mockInvoke(\"tx1\", ['queryCar', `CAR0`]);\n\n        expect(Transform.bufferToObject(response.payload)).to.deep.eq({\n            'make': 'prop1',\n            'model': 'prop2',\n            'color': 'prop3',\n            'owner': 'owner',\n            'docType': 'car'\n        })\n    });\n});\n```\n\n### Testing individual classes\nYou are not required to only test using the `mockInvoke` and `mockInit`. You can directly call the methods on your chaincode or on the mockStub if you really want to.\n\n#### Testing using Mychaincode directly\nA remark when using this, depending what you return in your function, you will be able to receive a Buffer or an object in your tests. This is discussed in [chaincode](#writing-chaincode)\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const stub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const car0 = {\n            'make': 'Toyota',\n            'model': 'Prius',\n            'color': 'blue',\n            'owner': 'Tomoko',\n            'docType': 'car'\n        };\n\n        const car = await chaincode.queryCar(stub, [\"CAR0\"])\n\n        expect(car).to.deep.equal(car0);\n    });\n});\n```\n\n#### Testing using ChaincodeMockStub directly 🤨\nYou can do this, but you shouldn't. Your logic should be written in your functions, not your tests.\n\n##### Test query results\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const query = {\n            selector: {\n                model: {\n                    \"$in\": ['Nano', \"Punto\"]\n                }\n            }\n        };\n\n        const it = await mockStub.getQueryResult(JSON.stringify(query));\n\n        const items = await Transform.iteratorToList(it);\n\n        expect(items).to.be.length(2)\n    });\n});\n```\n\n##### Test emitted events\n\n```javascript\nit(\"Should get the emitted event\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        await mockStub.mockInvoke(\"tx1\", ['createCar', `CAR0`, `prop1`, `prop2`, `prop3`, `owner`]);\n\n        const eventPayload = await mockStub.getEvent('CREATE_CAR');\n\n        expect(eventPayload).to.equal('Car created.');\n});\n```\n\n## Contributing\n\n1. Fork it! 🍴\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request 😁 🎉\n\n## Credits\n\n- Developer - Jo ([@jestersimpps](https://github.com/jestersimpps))\n- Developer - Jonas ([@Superjo149](https://github.com/Superjo149))\n- Company - TheLedger ([theledger.be](https://theledger.be))\n\n## License\nThe MIT License (MIT)\n\nCopyright (c) 2018 TheLedger\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","gitHead":"71b29c8b390cb62af08013f7d1c34bb8fdd231d0","_nodeVersion":"20.5.0","_npmVersion":"9.8.0","dist":{"integrity":"sha512-emohi4xGPM0F7RL019DtYIy0+W57ut9R9YVNPbNO2AIW7ql7dWJ15OCbXHIrmGZ33Rnls/xX+aC2QK4aVqQuIA==","shasum":"86bee204c8a4a9fc6c28caa28292c84b140a0460","tarball":"https://registry.npmjs.org/@apex-pub/fabric-mock-stub/-/fabric-mock-stub-1.4.1-4-alpha.71b29c8b.tgz","fileCount":44,"unpackedSize":110184,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFGkWfJzM0bnX92hyTQnzOUFBVE5fho2JUOXKos/lpicAiEArxeOk0GUZyJu2GyHvO9ApTZDwdbpBnEESw1OIX/suCo="}]},"_npmUser":{"name":"akshaysood112","email":"akshay.sood@live.com"},"directories":{},"maintainers":[{"name":"akshaysood112","email":"akshay.sood@live.com"},{"name":"rodolfoleal","email":"rodolfo.pk@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fabric-mock-stub_1.4.1-4-alpha.71b29c8b_1690475754818_0.3080770153154426"},"_hasShrinkwrap":false},"1.4.1-4-alpha.808cd029":{"name":"@apex-pub/fabric-mock-stub","version":"1.4.1-4-alpha.808cd029","description":"Mock implementation of the hyperledger fabric-shim package for testing","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npm run clean && tsc","test":"mocha -r ts-node/register test/**/*.spec.ts --reporter spec","test:coverage":"nyc --no-clean mocha -r ts-node/register test/**/*.spec.ts --reporter spec","report-coverage":"nyc report --reporter=text-lcov > coverage.lcov && codecov","lint":"tslint --fix -c tslint.json './src/**/*.ts'","clean":"rimraf dist","prepare":"npm run build","generate:docs":"rimraf docs && typedoc src --out docs --target ES6 --excludePrivate && touch docs/.nojekyll && touch docs/modules/.nojekyll"},"keywords":[],"license":"MIT","devDependencies":{"@types/lodash":"^4.14.104","@types/winston":"^2.3.8","codecov":"^3.0.4","coveralls":"^3.0.0","istanbul":"^0.4.5","nyc":"^12.0.2"},"dependencies":{"@theledger/couchdb-query-engine":"^2.4.4","@types/google-protobuf":"^3.7.2","fabric-shim":"2.5.4","google-protobuf":"^3.6.1","lodash":"^4.17.11","winston":"^2.4.0"},"publishConfig":{"registry":"https://registry.npmjs.org","access":"public"},"husky":{"hooks":{"pre-push":"npm run test && git add ."}},"nyc":{"include":["src/**/*.ts"],"extension":[".ts"],"require":["ts-node/register"],"reporter":["text"],"sourceMap":true,"instrument":true},"_id":"@apex-pub/fabric-mock-stub@1.4.1-4-alpha.808cd029","readme":"[![Build Status](https://travis-ci.org/wearetheledger/fabric-mock-stub.svg?branch=master)](https://travis-ci.org/wearetheledger/fabric-mock-stub) [![npm version](https://badge.fury.io/js/%40theledger%2Ffabric-mock-stub.svg)](https://badge.fury.io/js/%40theledger%2Ffabric-mock-stub) [![codecov](https://codecov.io/gh/wearetheledger/fabric-mock-stub/branch/master/graph/badge.svg)](https://codecov.io/gh/wearetheledger/fabric-mock-stub)\n# Hyperledger Fabric Nodejs mockstub\n\nA Nodejs module that helps you to test your Hyperledger Fabric Nodejs chaincode. When it proves itself, we will be adding this package to the official Gerrit of the Fabric Nodejs SDK.\n\n- [Docs](https://wearetheledger.github.io/fabric-mock-stub)\n- [Example usage](https://github.com/wearetheledger/fabric-network-boilerplate/tree/master/chaincode/node)\n- [Article about this repo](https://medium.com/wearetheledger/how-to-start-testing-your-hyperledger-fabric-nodejs-chaincode-229453c3c214)\n\n## 🚨 Note\nDue to the complexity, key endorsement policies introduced in v1.4 are currently not being enforced.\n\n## Table of contents\n- [Version matching](#version-matching)\n- [Installation](#installation)\n- [Todo](#todo)\n- [Usage](#usage)\n- [Contributing](#contributing)\n- [Credits](#credits)\n- [License](#license)\n\n## Version matching\n| Fabric node SDK        | Mock stub    |\n| ------------- |:-------------:|\n| v1.4.X     | v4.X.X |\n| v1.3.X     | v3.X.X |\n| v1.2.X     | v2.X.X |\n| V1.1.X     | v1.3.X     |\n\n\n## Installation\n```sh\nyarn add @theledger/fabric-mock-stub --dev\n```\n\n## Todo\n- [ ] Finish [node-couchdb-query-engine](https://github.com/wearetheledger/node-couchdb-query-engine)\n- [ ] Implement `fields` and `sort` into GetQueryResult\n- Implement remaining mock methods for\n    - [ ] getBinding\n    - [ ] getChannelID\n\n## Usage\n### ChaincodeMockStub [View definition](https://wearetheledger.github.io/fabric-mock-stub/classes/_chaincodemockstub_.chaincodemockstub.html)\nThis ChaincodeMockStub is a Mock implementation of the fabric-shim stub. This means you can test your chaincode without actually starting your network.\n\nExamples are located at [examples/tests](examples/tests)\n\n**!! Following methods are not (yet) implemented and will not work !!**\n- getBinding\n- getChannelID\n\n### How to test\nTesting NodeJS chaincode works similarly to testing using the mockstub in the Golang chaincode.\n\nThe **ChaincodeMockStub** has 2 important mock functions `mockInit`and `mockInvoke`. By passing your chaincode, it will mock a transaction and execute a invoke/init similarly to how it will originally be called. Both these functions will return a [ChaincodeResponse](https://github.com/wearetheledger/fabric-shim-types/blob/4b8844769c2439303954d03f5c8a66dc0a795ed4/index.d.ts#L93). Using this ChaincodeResponse object, we can test whether or not the action returned an expected result.\n\nOn *success*, this response will look like this. If the method returns something, the response will also contain a `payload`.\n\n```json\n{\n    \"status\": 200,\n    \"payload\": <Buffer_with_your_data>\n}\n```\n\nOn *error*, this response will look like this.\n\n```json\n{\n    \"status\": 500,\n    \"message\": <Buffer_with_your_error_message>\n}\n```\n\nYou'll be able to validate the response using something like `chai`.\n\n```javascript\n// Validate response status\nexpect(response.status).to.eql(200)\n// Validate payload - using `Transform.bufferToObject` because we recieve the payload as a buffer\nexpect(Transform.bufferToObject(response.payload).owner).to.eql(\"newOwner\")\n```\n\n#### Include your chaincode\nAt the top of your test file, you can import and instantiate your chaincode, this only has to be done once.\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n```\n#### Include the mockstub\nAfter this, in your tests, you can create a new mockstub. You have to pass a random name (not that important) and your chaincode. It's up to you if you want to create a new mockstub for each test, which runs those tests with an empty state. Or use one for all the tests. If you reuse the same stub, you also reuse the previous tests state.\n\n```javascript\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\nconst mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n```\n\n#### Example\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should init without issues\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        // Your test code\n    });\n});\n```\n\n### Test Init\nThe `Init()`method can be tested using the `mockStub.mockInit(txId: string, args: string[])` function. It will create a new mock transaction and call the init method on your chaincode. Since the init happens when instantiating your chaincode, you generally don't want it to return anything. So, for this, we'll check the response status.\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should init without issues\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInit(\"tx1\", []);\n\n        expect(response.status).to.eql(200)\n    });\n});\n```\n\n### Test Invoke\nThe `Invoke()`method can be tested using the `mockStub.mockInvoke(txId: string, args: string[])` function. It will create a new mock transaction and call the invoke method on your chaincode. The client will either send a query or an invoke, but the chaincode will accept these both as invoke. In your tests there isn't any difference, both invokes and queries can return a result.\n\n**Test queryCar**\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should query car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInvoke(\"tx2\", ['queryCar', `CAR0`]);\n\n        expect(Transform.bufferToObject(response.payload)).to.deep.eq({\n            'make': 'prop1',\n            'model': 'prop2',\n            'color': 'prop3',\n            'owner': 'owner',\n            'docType': 'car'\n        });\n    });\n});\n```\n\n**Test createCar**\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInvoke(\"tx1\", ['createCar', `CAR0`, `prop1`, `prop2`, `prop3`, `owner`]);\n\n        expect(response.status).to.eql(200)\n\n        const response = await mockStub.mockInvoke(\"tx1\", ['queryCar', `CAR0`]);\n\n        expect(Transform.bufferToObject(response.payload)).to.deep.eq({\n            'make': 'prop1',\n            'model': 'prop2',\n            'color': 'prop3',\n            'owner': 'owner',\n            'docType': 'car'\n        })\n    });\n});\n```\n\n### Testing individual classes\nYou are not required to only test using the `mockInvoke` and `mockInit`. You can directly call the methods on your chaincode or on the mockStub if you really want to.\n\n#### Testing using Mychaincode directly\nA remark when using this, depending what you return in your function, you will be able to receive a Buffer or an object in your tests. This is discussed in [chaincode](#writing-chaincode)\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const stub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const car0 = {\n            'make': 'Toyota',\n            'model': 'Prius',\n            'color': 'blue',\n            'owner': 'Tomoko',\n            'docType': 'car'\n        };\n\n        const car = await chaincode.queryCar(stub, [\"CAR0\"])\n\n        expect(car).to.deep.equal(car0);\n    });\n});\n```\n\n#### Testing using ChaincodeMockStub directly 🤨\nYou can do this, but you shouldn't. Your logic should be written in your functions, not your tests.\n\n##### Test query results\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const query = {\n            selector: {\n                model: {\n                    \"$in\": ['Nano', \"Punto\"]\n                }\n            }\n        };\n\n        const it = await mockStub.getQueryResult(JSON.stringify(query));\n\n        const items = await Transform.iteratorToList(it);\n\n        expect(items).to.be.length(2)\n    });\n});\n```\n\n##### Test emitted events\n\n```javascript\nit(\"Should get the emitted event\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        await mockStub.mockInvoke(\"tx1\", ['createCar', `CAR0`, `prop1`, `prop2`, `prop3`, `owner`]);\n\n        const eventPayload = await mockStub.getEvent('CREATE_CAR');\n\n        expect(eventPayload).to.equal('Car created.');\n});\n```\n\n## Contributing\n\n1. Fork it! 🍴\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request 😁 🎉\n\n## Credits\n\n- Developer - Jo ([@jestersimpps](https://github.com/jestersimpps))\n- Developer - Jonas ([@Superjo149](https://github.com/Superjo149))\n- Company - TheLedger ([theledger.be](https://theledger.be))\n\n## License\nThe MIT License (MIT)\n\nCopyright (c) 2018 TheLedger\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","gitHead":"808cd029d1cf8bc22f376df0e5da047724a2133a","_nodeVersion":"20.5.0","_npmVersion":"9.8.0","dist":{"integrity":"sha512-7llJlNsYaeznh5GejLGSkRDl9cv8ar17AzABU7g6QqHiy5dk2OtVVgWuoRzDWuS0Qb5tTBm2PN/ztuRHgLRJVg==","shasum":"375abc5870bdf4c0d5ef03cfc6d3572461685441","tarball":"https://registry.npmjs.org/@apex-pub/fabric-mock-stub/-/fabric-mock-stub-1.4.1-4-alpha.808cd029.tgz","fileCount":44,"unpackedSize":110184,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDNo37gdQeaT4XlYYw+aBgqL7lfyxBreBFyyOdSJG+6sAIhAMG+h1kREjFeX7/ZiUlfFFsJCiMaIV7mH4BjsI+jT9IE"}]},"_npmUser":{"name":"akshaysood112","email":"akshay.sood@live.com"},"directories":{},"maintainers":[{"name":"akshaysood112","email":"akshay.sood@live.com"},{"name":"rodolfoleal","email":"rodolfo.pk@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fabric-mock-stub_1.4.1-4-alpha.808cd029_1690483854908_0.813153417871467"},"_hasShrinkwrap":false},"1.4.1-4-alpha.5f94f88e":{"name":"@apex-pub/fabric-mock-stub","version":"1.4.1-4-alpha.5f94f88e","description":"Mock implementation of the hyperledger fabric-shim package for testing","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npm run clean && tsc","test":"mocha -r ts-node/register test/**/*.spec.ts --reporter spec","test:coverage":"nyc --no-clean mocha -r ts-node/register test/**/*.spec.ts --reporter spec","report-coverage":"nyc report --reporter=text-lcov > coverage.lcov && codecov","lint":"tslint --fix -c tslint.json './src/**/*.ts'","clean":"rimraf dist","prepare":"npm run build","generate:docs":"rimraf docs && typedoc src --out docs --target ES6 --excludePrivate && touch docs/.nojekyll && touch docs/modules/.nojekyll"},"keywords":[],"license":"MIT","devDependencies":{"@types/lodash":"^4.14.104","@types/winston":"^2.3.8","codecov":"^3.0.4","coveralls":"^3.0.0","istanbul":"^0.4.5","nyc":"^12.0.2"},"dependencies":{"@theledger/couchdb-query-engine":"^2.4.4","@types/google-protobuf":"^3.7.2","fabric-shim":"2.5.4","google-protobuf":"^3.6.1","lodash":"^4.17.11","winston":"^2.4.0"},"publishConfig":{"registry":"https://registry.npmjs.org","access":"public"},"husky":{"hooks":{"pre-push":"npm run test && git add ."}},"nyc":{"include":["src/**/*.ts"],"extension":[".ts"],"require":["ts-node/register"],"reporter":["text"],"sourceMap":true,"instrument":true},"_id":"@apex-pub/fabric-mock-stub@1.4.1-4-alpha.5f94f88e","readme":"[![Build Status](https://travis-ci.org/wearetheledger/fabric-mock-stub.svg?branch=master)](https://travis-ci.org/wearetheledger/fabric-mock-stub) [![npm version](https://badge.fury.io/js/%40theledger%2Ffabric-mock-stub.svg)](https://badge.fury.io/js/%40theledger%2Ffabric-mock-stub) [![codecov](https://codecov.io/gh/wearetheledger/fabric-mock-stub/branch/master/graph/badge.svg)](https://codecov.io/gh/wearetheledger/fabric-mock-stub)\n# Hyperledger Fabric Nodejs mockstub\n\nA Nodejs module that helps you to test your Hyperledger Fabric Nodejs chaincode. When it proves itself, we will be adding this package to the official Gerrit of the Fabric Nodejs SDK.\n\n- [Docs](https://wearetheledger.github.io/fabric-mock-stub)\n- [Example usage](https://github.com/wearetheledger/fabric-network-boilerplate/tree/master/chaincode/node)\n- [Article about this repo](https://medium.com/wearetheledger/how-to-start-testing-your-hyperledger-fabric-nodejs-chaincode-229453c3c214)\n\n## 🚨 Note\nDue to the complexity, key endorsement policies introduced in v1.4 are currently not being enforced.\n\n## Table of contents\n- [Version matching](#version-matching)\n- [Installation](#installation)\n- [Todo](#todo)\n- [Usage](#usage)\n- [Contributing](#contributing)\n- [Credits](#credits)\n- [License](#license)\n\n## Version matching\n| Fabric node SDK        | Mock stub    |\n| ------------- |:-------------:|\n| v1.4.X     | v4.X.X |\n| v1.3.X     | v3.X.X |\n| v1.2.X     | v2.X.X |\n| V1.1.X     | v1.3.X     |\n\n\n## Installation\n```sh\nyarn add @theledger/fabric-mock-stub --dev\n```\n\n## Todo\n- [ ] Finish [node-couchdb-query-engine](https://github.com/wearetheledger/node-couchdb-query-engine)\n- [ ] Implement `fields` and `sort` into GetQueryResult\n- Implement remaining mock methods for\n    - [ ] getBinding\n    - [ ] getChannelID\n\n## Usage\n### ChaincodeMockStub [View definition](https://wearetheledger.github.io/fabric-mock-stub/classes/_chaincodemockstub_.chaincodemockstub.html)\nThis ChaincodeMockStub is a Mock implementation of the fabric-shim stub. This means you can test your chaincode without actually starting your network.\n\nExamples are located at [examples/tests](examples/tests)\n\n**!! Following methods are not (yet) implemented and will not work !!**\n- getBinding\n- getChannelID\n\n### How to test\nTesting NodeJS chaincode works similarly to testing using the mockstub in the Golang chaincode.\n\nThe **ChaincodeMockStub** has 2 important mock functions `mockInit`and `mockInvoke`. By passing your chaincode, it will mock a transaction and execute a invoke/init similarly to how it will originally be called. Both these functions will return a [ChaincodeResponse](https://github.com/wearetheledger/fabric-shim-types/blob/4b8844769c2439303954d03f5c8a66dc0a795ed4/index.d.ts#L93). Using this ChaincodeResponse object, we can test whether or not the action returned an expected result.\n\nOn *success*, this response will look like this. If the method returns something, the response will also contain a `payload`.\n\n```json\n{\n    \"status\": 200,\n    \"payload\": <Buffer_with_your_data>\n}\n```\n\nOn *error*, this response will look like this.\n\n```json\n{\n    \"status\": 500,\n    \"message\": <Buffer_with_your_error_message>\n}\n```\n\nYou'll be able to validate the response using something like `chai`.\n\n```javascript\n// Validate response status\nexpect(response.status).to.eql(200)\n// Validate payload - using `Transform.bufferToObject` because we recieve the payload as a buffer\nexpect(Transform.bufferToObject(response.payload).owner).to.eql(\"newOwner\")\n```\n\n#### Include your chaincode\nAt the top of your test file, you can import and instantiate your chaincode, this only has to be done once.\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n```\n#### Include the mockstub\nAfter this, in your tests, you can create a new mockstub. You have to pass a random name (not that important) and your chaincode. It's up to you if you want to create a new mockstub for each test, which runs those tests with an empty state. Or use one for all the tests. If you reuse the same stub, you also reuse the previous tests state.\n\n```javascript\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\nconst mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n```\n\n#### Example\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should init without issues\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        // Your test code\n    });\n});\n```\n\n### Test Init\nThe `Init()`method can be tested using the `mockStub.mockInit(txId: string, args: string[])` function. It will create a new mock transaction and call the init method on your chaincode. Since the init happens when instantiating your chaincode, you generally don't want it to return anything. So, for this, we'll check the response status.\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should init without issues\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInit(\"tx1\", []);\n\n        expect(response.status).to.eql(200)\n    });\n});\n```\n\n### Test Invoke\nThe `Invoke()`method can be tested using the `mockStub.mockInvoke(txId: string, args: string[])` function. It will create a new mock transaction and call the invoke method on your chaincode. The client will either send a query or an invoke, but the chaincode will accept these both as invoke. In your tests there isn't any difference, both invokes and queries can return a result.\n\n**Test queryCar**\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should query car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInvoke(\"tx2\", ['queryCar', `CAR0`]);\n\n        expect(Transform.bufferToObject(response.payload)).to.deep.eq({\n            'make': 'prop1',\n            'model': 'prop2',\n            'color': 'prop3',\n            'owner': 'owner',\n            'docType': 'car'\n        });\n    });\n});\n```\n\n**Test createCar**\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const response = await mockStub.mockInvoke(\"tx1\", ['createCar', `CAR0`, `prop1`, `prop2`, `prop3`, `owner`]);\n\n        expect(response.status).to.eql(200)\n\n        const response = await mockStub.mockInvoke(\"tx1\", ['queryCar', `CAR0`]);\n\n        expect(Transform.bufferToObject(response.payload)).to.deep.eq({\n            'make': 'prop1',\n            'model': 'prop2',\n            'color': 'prop3',\n            'owner': 'owner',\n            'docType': 'car'\n        })\n    });\n});\n```\n\n### Testing individual classes\nYou are not required to only test using the `mockInvoke` and `mockInit`. You can directly call the methods on your chaincode or on the mockStub if you really want to.\n\n#### Testing using Mychaincode directly\nA remark when using this, depending what you return in your function, you will be able to receive a Buffer or an object in your tests. This is discussed in [chaincode](#writing-chaincode)\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const stub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const car0 = {\n            'make': 'Toyota',\n            'model': 'Prius',\n            'color': 'blue',\n            'owner': 'Tomoko',\n            'docType': 'car'\n        };\n\n        const car = await chaincode.queryCar(stub, [\"CAR0\"])\n\n        expect(car).to.deep.equal(car0);\n    });\n});\n```\n\n#### Testing using ChaincodeMockStub directly 🤨\nYou can do this, but you shouldn't. Your logic should be written in your functions, not your tests.\n\n##### Test query results\n\n```javascript\nimport { MyChaincode } from '../<path_to_your_chaincode_class>';\nimport { ChaincodeMockStub, Transform } from \"@theledger/fabric-mock-stub\";\n\n// You always need your chaincode so it knows which chaincode to invoke on\nconst chaincode = new MyChaincode();\n\ndescribe('Test MyChaincode', () => {\n\n    it(\"Should be able to add car\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        const query = {\n            selector: {\n                model: {\n                    \"$in\": ['Nano', \"Punto\"]\n                }\n            }\n        };\n\n        const it = await mockStub.getQueryResult(JSON.stringify(query));\n\n        const items = await Transform.iteratorToList(it);\n\n        expect(items).to.be.length(2)\n    });\n});\n```\n\n##### Test emitted events\n\n```javascript\nit(\"Should get the emitted event\", async () => {\n        const mockStub = new ChaincodeMockStub(\"MyMockStub\", chaincode);\n\n        await mockStub.mockInvoke(\"tx1\", ['createCar', `CAR0`, `prop1`, `prop2`, `prop3`, `owner`]);\n\n        const eventPayload = await mockStub.getEvent('CREATE_CAR');\n\n        expect(eventPayload).to.equal('Car created.');\n});\n```\n\n## Contributing\n\n1. Fork it! 🍴\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request 😁 🎉\n\n## Credits\n\n- Developer - Jo ([@jestersimpps](https://github.com/jestersimpps))\n- Developer - Jonas ([@Superjo149](https://github.com/Superjo149))\n- Company - TheLedger ([theledger.be](https://theledger.be))\n\n## License\nThe MIT License (MIT)\n\nCopyright (c) 2018 TheLedger\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","readmeFilename":"README.md","gitHead":"5f94f88e49bb1f1eeb04daa32a1233520ef1dc13","_nodeVersion":"20.5.0","_npmVersion":"9.8.0","dist":{"integrity":"sha512-wVFFlNniXKFGsQ5f14sDU3+7o/2zkcaqVGEIo49En/yQa2IyFMGY6CG3ZjYtnMBDJKB5A5mmxlHaExpIEa67aA==","shasum":"fd01636554dd2ed2b34f89c335662685a268b3aa","tarball":"https://registry.npmjs.org/@apex-pub/fabric-mock-stub/-/fabric-mock-stub-1.4.1-4-alpha.5f94f88e.tgz","fileCount":44,"unpackedSize":110184,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC/oawIe9od9AuF0gk0YdnaJ53R3FnQq+L9aL0MbejuvwIhAMEuK/5pvTtGHdmWQymGng0r7nBvFQG5neSIJ+Vb/ivv"}]},"_npmUser":{"name":"akshaysood112","email":"akshay.sood@live.com"},"directories":{},"maintainers":[{"name":"akshaysood112","email":"akshay.sood@live.com"},{"name":"rodolfoleal","email":"rodolfo.pk@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fabric-mock-stub_1.4.1-4-alpha.5f94f88e_1690485717961_0.44838301277531256"},"_hasShrinkwrap":false}},"time":{"created":"2023-07-03T22:45:41.487Z","1.0.0":"2023-07-03T22:45:41.814Z","modified":"2023-07-27T19:21:58.240Z","1.4.0":"2023-07-03T22:49:57.149Z","1.4.1-0":"2023-07-04T22:41:28.017Z","1.4.1-1.4.1-node20.0":"2023-07-04T23:01:10.513Z","1.4.1-2.0":"2023-07-10T21:59:03.183Z","1.4.1-3":"2023-07-11T19:45:49.843Z","1.4.1-4-alpha.aa405158":"2023-07-11T20:20:42.504Z","1.4.1-4-alpha.6064f94c":"2023-07-25T02:23:02.601Z","1.4.1-4-alpha.8d3ff686":"2023-07-25T02:40:25.921Z","1.4.1-4-alpha.8939dce7":"2023-07-25T03:42:13.762Z","1.4.1-4-alpha.4ece38f3":"2023-07-26T20:46:10.543Z","1.4.1-4-alpha.5d0544b6":"2023-07-27T00:36:19.733Z","1.4.1-4-alpha.e17c6b86":"2023-07-27T02:06:27.645Z","1.4.1-4-alpha.c429017f":"2023-07-27T15:45:56.381Z","1.4.1-4-alpha.71b29c8b":"2023-07-27T16:35:54.995Z","1.4.1-4-alpha.808cd029":"2023-07-27T18:50:55.104Z","1.4.1-4-alpha.5f94f88e":"2023-07-27T19:21:58.122Z"},"maintainers":[{"name":"akshaysood112","email":"akshay.sood@live.com"},{"name":"rodolfoleal","email":"rodolfo.pk@gmail.com"}],"description":"Mock implementation of the hyperledger fabric-shim package for testing","keywords":[],"license":"MIT","readme":"","readmeFilename":""}