Closed CallForSanity closed 6 years ago
I'm not sure in which case you would need this. Could you show an example or write a test for it?
My code could be wrong, but consider this:
`export class Test extends Chaincode {
async init(stubHelper: StubHelper) {
await stubHelper.putState('a', 0);
}
async getA(stubHelper: StubHelper, args: string[]): Promise<number> {
return (await stubHelper.getStateAsObject('a')) as number;
}
}`
The problem is that the if-clause will evaluate the returned 0
from getA
as true
and the if-body then returns null
. If your client code expects a number such as 0
, this is a problem. In my case angular.io was simple not producing any output if the query return value was changed from 0
to null
which was very confusing to debug.
A proper test for null
should be performed instead. Maybe even
https://nodejs.org/api/util.html#util_util_isnullorundefined_object
In case
0 == payload
the existing if-statement evaluates totrue
. A query then returnsnull
which is unexpected behavior.Please test my change request before merging. I have NOT tested it.