holochain-proto
holochain-proto copied to clipboard
Zygo ribosome's `get` incorrectly returns JSONified `%result` for string entries
When using the get
function in Zygomys, the %result
of the returned hashmap will be surrounded by quotation marks if the entry is a string.
Example:
dna.json
:
"Zomes": [
{
"Name": "zygoStrBug",
"Description": "Demonstrate how Zygomys strings are incorrectly JSONified in the get function",
"CodeFile": "zygoStrBug.zy",
"RibosomeType": "zygo",
"Entries": [
{
"Name": "sampleEntry",
"DataFormat": "string",
"Sharing": "public"
}
],
"Functions": [
{
"Name": "createEntry",
"CallingType": "string",
"Exposure": "public"
},
{
"Name": "getEntry",
"CallingType": "string",
"Exposure": "public"
}
]
}
]
zygoStrBug.zy
:
(defn genesis [] true)
(defn validateCommit [entryType entry header package sources] true)
(defn validatePut [entryType entry header package sources] true)
(defn createEntry [s] (commit "sampleEntry" s))
(defn getEntry [h] (hget (get h) %result))
test/sample.json
:
{
"Tests": [
{
"Convey": "Create an entry",
"Zome": "zygoStrBug",
"FnName": "createEntry",
"Input": "Hello, world!",
"Output": "%h%"
},
{
"Convey": "Read an entry",
"Zome": "zygoStrBug",
"FnName": "getEntry",
"Input": "%h%",
"Output": "Hello, world!"
}
]
}
test results
:
➜ zygostrbug hcdev test
Copying chain to: /home/phoenix/.holochaindev
========================================
Test: 'sample' starting...
========================================
Test 'sample.0' t+0ms: Create an entry
passed! ✔
Test 'sample.1' t+11ms: Read an entry
=====================
Test: sample:1
Expected: Hello, world!
Got: "Hello, world!"
failed! m(
=====================
==================================================================
+++++ 1 test(s) failed :( +++++
==================================================================
test:
Test: sample:1
Expected: Hello, world!
Got: "Hello, world!"
Not sure because I don't actually know any Go but I think this line is the problem.
In the Javascript ribosome, I think the analogous line would be this one. This line uses a function that checks if the entry is actual JSON data before stringifying it.
I think the best solution for now would be to create a function in zygosome.go
that does the same thing. A more long term solution (easier to support the addition of other ribosomes) would be to put the entry stringify function in a shared ribosome library.