wearetheledger / fabric-mock-stub

Mock implementation of the fabric-shim stub for testing
https://theledger.be
MIT License
49 stars 28 forks source link

getState() should return empty bytes rather than 'undefined' for non-existence key/value #13

Closed ibmamnt closed 5 years ago

ibmamnt commented 6 years ago

First of all, thank you for this project. This enabled us to run chaincode test in a CI way.

I found that MockStub.getState(key) returns 'undefined' rather than empty bytes which actual node.js chaincode shim returns (as of v1.2.3). I've already included to check for empty bytes in my chaincode. If it is possible, please return empty bytes when the key does not exists in the State.

Jojoooo1 commented 6 years ago

I had exactly the same problem, would be very great ! for example if we try to .toString() on the response returned by getState(key) of undefined it throw an error, in order to work we need to add additional if statement to avoid doing operation on undefined variable