From b66ba9ae5ceec8e5de5f8398a9a2dc256c3187d9 Mon Sep 17 00:00:00 2001 From: matteo-cristino Date: Mon, 13 May 2024 16:49:37 +0200 Subject: [PATCH] fix: print empy octets to string as empty strings --- src/lua/zencode_data.lua | 5 +++-- test/zencode/dictionary.bats | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lua/zencode_data.lua b/src/lua/zencode_data.lua index 5a98103c2..1f09ab545 100644 --- a/src/lua/zencode_data.lua +++ b/src/lua/zencode_data.lua @@ -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 diff --git a/test/zencode/dictionary.bats b/test/zencode/dictionary.bats index a6a3580e7..fd1366697 100644 --- a/test/zencode/dictionary.bats +++ b/test/zencode/dictionary.bats @@ -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" { @@ -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 "" {