Skip to content

Commit

Permalink
fix: print empy octets to string as empty strings
Browse files Browse the repository at this point in the history
  • Loading branch information
matteo-cristino authored and jaromil committed May 13, 2024
1 parent 4f37f56 commit b66ba9a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/lua/zencode_data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,9 @@ end
elseif dt == 'zenroom.float' or dt == 'zenroom.time' then
return to_number_f(data)
elseif iszen(dt) then
-- leverage first class citizen method on zenroom data
return fun(data:octet())
if fun == O.to_string and fun(data) == nil then return "" end
-- leverage first class citizen method on zenroom data
return fun(data:octet())
end
return fun(data)
end
Expand Down
4 changes: 2 additions & 2 deletions test/zencode/dictionary.bats
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ then print the 'copy'
and print the 'batches'
EOF
save_output 'dict-into-array.json'
assert_output '{"batches":[{"header":{"signer_public_key":"0209373bda3561c82c246b226ab3dfdfcab5fbdcba3cb3969508ea5b427628bb1f","transaction_ids":["3ff09b69c5973eaed4f06214bfa45ad0cf3d88f92476f3f297b331efb7ec9ad51f27b94a217e0fe1c59a714f067bcdd9e595f8d73c8e3ab22a085b732fc8bb94"]},"header_signature":"b81f74eec9f49fd8062c3a90dc5bd48249842ea6149b4a2e7cded38f50ca0e4d30cb66f6d74a807b737143f07fa2f7e807ef5dd44e3e03e89ac1f39ac41012f0","trace":false,"transactions":[{"header":{"batcher_public_key":"0209373bda3561c82c246b226ab3dfdfcab5fbdcba3cb3969508ea5b427628bb1f","dependencies":[],"family_name":"restroom","family_version":"1.0","inputs":["c274b5"],"outputs":["c274b5"],"payload_sha512":"263e4334456dbe1c5904417e8d2b80d0235fd6766a7e71ca3b95bd0fa134b0fe7c722877ee44a715ac81d9dda0df8496abb3455c0f447c26e801dbdfba5f2bc3","signer_public_key":"0209373bda3561c82c246b226ab3dfdfcab5fbdcba3cb3969508ea5b427628bb1f"},"header_signature":"3ff09b69c5973eaed4f06214bfa45ad0cf3d88f92476f3f297b331efb7ec9ad51f27b94a217e0fe1c59a714f067bcdd9e595f8d73c8e3ab22a085b732fc8bb94","payload":"omV2YWx1ZXiTeyJkYXRhVG9TdG9yZSI6IlRHbG1aU0JwY3lCaWIzSnBibWNzSUd4bGRDQjFjeUJ6Y0dsalpTQnBkQ0IxY0NCM2FYUm9JSE52YldVZ1lteHZZMnRqYUdGcGJpQm1kVzVySVE9PSIsIm15MTI4Qml0c1JhbmRvbSI6IklBTVRDNzNEMlB0b0dPdEVRVTlPUXc9PSJ9Z2FkZHJlc3N4RmMyNzRiNTAyYjk5YmUxZDA1NmFmY2UzYTRmZTI0ZmM2Y2NmZjM0NzdmOGJlYjE5ODk2YjdhYTY2ZTQ1MjVjYTAwMTdkY2U="}]}],"copy":"b81f74eec9f49fd8062c3a90dc5bd48249842ea6149b4a2e7cded38f50ca0e4d30cb66f6d74a807b737143f07fa2f7e807ef5dd44e3e03e89ac1f39ac41012f0"}'
assert_output '{"batches":[{"header":{"signer_public_key":"0209373bda3561c82c246b226ab3dfdfcab5fbdcba3cb3969508ea5b427628bb1f","transaction_ids":["3ff09b69c5973eaed4f06214bfa45ad0cf3d88f92476f3f297b331efb7ec9ad51f27b94a217e0fe1c59a714f067bcdd9e595f8d73c8e3ab22a085b732fc8bb94"]},"header_signature":"b81f74eec9f49fd8062c3a90dc5bd48249842ea6149b4a2e7cded38f50ca0e4d30cb66f6d74a807b737143f07fa2f7e807ef5dd44e3e03e89ac1f39ac41012f0","trace":false,"transactions":[{"header":{"batcher_public_key":"0209373bda3561c82c246b226ab3dfdfcab5fbdcba3cb3969508ea5b427628bb1f","dependencies":[],"family_name":"restroom","family_version":"1.0","inputs":["c274b5"],"nonce":"","outputs":["c274b5"],"payload_sha512":"263e4334456dbe1c5904417e8d2b80d0235fd6766a7e71ca3b95bd0fa134b0fe7c722877ee44a715ac81d9dda0df8496abb3455c0f447c26e801dbdfba5f2bc3","signer_public_key":"0209373bda3561c82c246b226ab3dfdfcab5fbdcba3cb3969508ea5b427628bb1f"},"header_signature":"3ff09b69c5973eaed4f06214bfa45ad0cf3d88f92476f3f297b331efb7ec9ad51f27b94a217e0fe1c59a714f067bcdd9e595f8d73c8e3ab22a085b732fc8bb94","payload":"omV2YWx1ZXiTeyJkYXRhVG9TdG9yZSI6IlRHbG1aU0JwY3lCaWIzSnBibWNzSUd4bGRDQjFjeUJ6Y0dsalpTQnBkQ0IxY0NCM2FYUm9JSE52YldVZ1lteHZZMnRqYUdGcGJpQm1kVzVySVE9PSIsIm15MTI4Qml0c1JhbmRvbSI6IklBTVRDNzNEMlB0b0dPdEVRVTlPUXc9PSJ9Z2FkZHJlc3N4RmMyNzRiNTAyYjk5YmUxZDA1NmFmY2UzYTRmZTI0ZmM2Y2NmZjM0NzdmOGJlYjE5ODk2YjdhYTY2ZTQ1MjVjYTAwMTdkY2U="}]}],"copy":"b81f74eec9f49fd8062c3a90dc5bd48249842ea6149b4a2e7cded38f50ca0e4d30cb66f6d74a807b737143f07fa2f7e807ef5dd44e3e03e89ac1f39ac41012f0"}'
}

@test "Pickup from path" {
Expand All @@ -561,7 +561,7 @@ Then print the 'batches'
and print the 'state root hash'
EOF
save_output 'pickup.zen'
assert_output '{"batches":[{"header":{"signer_public_key":"0209373bda3561c82c246b226ab3dfdfcab5fbdcba3cb3969508ea5b427628bb1f","transaction_ids":["3ff09b69c5973eaed4f06214bfa45ad0cf3d88f92476f3f297b331efb7ec9ad51f27b94a217e0fe1c59a714f067bcdd9e595f8d73c8e3ab22a085b732fc8bb94"]},"header_signature":"b81f74eec9f49fd8062c3a90dc5bd48249842ea6149b4a2e7cded38f50ca0e4d30cb66f6d74a807b737143f07fa2f7e807ef5dd44e3e03e89ac1f39ac41012f0","trace":false,"transactions":[{"header":{"batcher_public_key":"0209373bda3561c82c246b226ab3dfdfcab5fbdcba3cb3969508ea5b427628bb1f","dependencies":[],"family_name":"restroom","family_version":"1.0","inputs":["c274b5"],"outputs":["c274b5"],"payload_sha512":"263e4334456dbe1c5904417e8d2b80d0235fd6766a7e71ca3b95bd0fa134b0fe7c722877ee44a715ac81d9dda0df8496abb3455c0f447c26e801dbdfba5f2bc3","signer_public_key":"0209373bda3561c82c246b226ab3dfdfcab5fbdcba3cb3969508ea5b427628bb1f"},"header_signature":"3ff09b69c5973eaed4f06214bfa45ad0cf3d88f92476f3f297b331efb7ec9ad51f27b94a217e0fe1c59a714f067bcdd9e595f8d73c8e3ab22a085b732fc8bb94","payload":"omV2YWx1ZXiTeyJkYXRhVG9TdG9yZSI6IlRHbG1aU0JwY3lCaWIzSnBibWNzSUd4bGRDQjFjeUJ6Y0dsalpTQnBkQ0IxY0NCM2FYUm9JSE52YldVZ1lteHZZMnRqYUdGcGJpQm1kVzVySVE9PSIsIm15MTI4Qml0c1JhbmRvbSI6IklBTVRDNzNEMlB0b0dPdEVRVTlPUXc9PSJ9Z2FkZHJlc3N4RmMyNzRiNTAyYjk5YmUxZDA1NmFmY2UzYTRmZTI0ZmM2Y2NmZjM0NzdmOGJlYjE5ODk2YjdhYTY2ZTQ1MjVjYTAwMTdkY2U="}]},"6cc4c895d2c7881954489750d598ff37fef6d299ee9fb5e19598094c7817b4ed02e6770f50defca760b6b6bef278f85e88ad352e18464bd4b7681b1211a34b64"],"header_signature":"b81f74eec9f49fd8062c3a90dc5bd48249842ea6149b4a2e7cded38f50ca0e4d30cb66f6d74a807b737143f07fa2f7e807ef5dd44e3e03e89ac1f39ac41012f0","state_root_hash":"2debd89f31b8a8d18b663f16ab19d2b70ae79414a73d29b20eb19b60a4353997"}'
assert_output '{"batches":[{"header":{"signer_public_key":"0209373bda3561c82c246b226ab3dfdfcab5fbdcba3cb3969508ea5b427628bb1f","transaction_ids":["3ff09b69c5973eaed4f06214bfa45ad0cf3d88f92476f3f297b331efb7ec9ad51f27b94a217e0fe1c59a714f067bcdd9e595f8d73c8e3ab22a085b732fc8bb94"]},"header_signature":"b81f74eec9f49fd8062c3a90dc5bd48249842ea6149b4a2e7cded38f50ca0e4d30cb66f6d74a807b737143f07fa2f7e807ef5dd44e3e03e89ac1f39ac41012f0","trace":false,"transactions":[{"header":{"batcher_public_key":"0209373bda3561c82c246b226ab3dfdfcab5fbdcba3cb3969508ea5b427628bb1f","dependencies":[],"family_name":"restroom","family_version":"1.0","inputs":["c274b5"],"nonce":"","outputs":["c274b5"],"payload_sha512":"263e4334456dbe1c5904417e8d2b80d0235fd6766a7e71ca3b95bd0fa134b0fe7c722877ee44a715ac81d9dda0df8496abb3455c0f447c26e801dbdfba5f2bc3","signer_public_key":"0209373bda3561c82c246b226ab3dfdfcab5fbdcba3cb3969508ea5b427628bb1f"},"header_signature":"3ff09b69c5973eaed4f06214bfa45ad0cf3d88f92476f3f297b331efb7ec9ad51f27b94a217e0fe1c59a714f067bcdd9e595f8d73c8e3ab22a085b732fc8bb94","payload":"omV2YWx1ZXiTeyJkYXRhVG9TdG9yZSI6IlRHbG1aU0JwY3lCaWIzSnBibWNzSUd4bGRDQjFjeUJ6Y0dsalpTQnBkQ0IxY0NCM2FYUm9JSE52YldVZ1lteHZZMnRqYUdGcGJpQm1kVzVySVE9PSIsIm15MTI4Qml0c1JhbmRvbSI6IklBTVRDNzNEMlB0b0dPdEVRVTlPUXc9PSJ9Z2FkZHJlc3N4RmMyNzRiNTAyYjk5YmUxZDA1NmFmY2UzYTRmZTI0ZmM2Y2NmZjM0NzdmOGJlYjE5ODk2YjdhYTY2ZTQ1MjVjYTAwMTdkY2U="}]},"6cc4c895d2c7881954489750d598ff37fef6d299ee9fb5e19598094c7817b4ed02e6770f50defca760b6b6bef278f85e88ad352e18464bd4b7681b1211a34b64"],"header_signature":"b81f74eec9f49fd8062c3a90dc5bd48249842ea6149b4a2e7cded38f50ca0e4d30cb66f6d74a807b737143f07fa2f7e807ef5dd44e3e03e89ac1f39ac41012f0","state_root_hash":"2debd89f31b8a8d18b663f16ab19d2b70ae79414a73d29b20eb19b60a4353997"}'
}

@test "" {
Expand Down

0 comments on commit b66ba9a

Please sign in to comment.