From a6b88c85e596923b8a776f7c486b3b70c0aaede1 Mon Sep 17 00:00:00 2001 From: matteo-cristino Date: Mon, 28 Aug 2023 09:52:49 +0200 Subject: [PATCH 1/2] =?UTF-8?q?fix(dictionary):=20=F0=9F=90=9B=20do=20not?= =?UTF-8?q?=20clone=20codec=20when=20copying=20from=20dictionary?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lua/zencode_dictionary.lua | 10 ++++++++-- test/zencode/dictionary.bats | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/lua/zencode_dictionary.lua b/src/lua/zencode_dictionary.lua index 8830e0827..0debf3ef8 100644 --- a/src/lua/zencode_dictionary.lua +++ b/src/lua/zencode_dictionary.lua @@ -213,12 +213,18 @@ local function _extract(tab, ele, root) end local function create_copy_f(root, in1, in2) empty'copy' - local r = have(root) + local r, r_codec = have(root) ACK.copy = _extract(r, in1, root) if in2 then ACK.copy = _extract(ACK.copy, in2, in1) end - new_codec('copy', nil, root) + local n_codec = { encoding = r_codec.encoding } + -- table of schemas can only contain elements + if r_codec.schema then + n_codec.schema = r_codec.schema + n_codec.zentype = "e" + end + new_codec('copy', n_codec) ZEN.CODEC['copy'].name = in2 or in1 end When("create the copy of '' from dictionary ''", function(name, dict) create_copy_f(dict, name) end) diff --git a/test/zencode/dictionary.bats b/test/zencode/dictionary.bats index 27f65f7f7..86fd6f1a0 100644 --- a/test/zencode/dictionary.bats +++ b/test/zencode/dictionary.bats @@ -775,3 +775,29 @@ EOF save_output 'move_in_array_of_schemas.json' assert_output '{"signatures":["0xed8f36c71989f8660e8f5d4adbfd8f1c0288cca90d3a5330b7bf735d71ab52fe7ba0a7827dc4ba707431f1c10babd389f658f8e208b89390a9be3c097579a2ff1b"]}' } + +@test "copy element from schemas" { + cat << EOF | save_asset copy_from_schema_dictionary.data +{ + "addresses_signatures": { + "add_sig_1":{ + "address": "0x2B8070975AF995Ef7eb949AE28ee7706B9039504", + "signature": "0xed8f36c71989f8660e8f5d4adbfd8f1c0288cca90d3a5330b7bf735d71ab52fe7ba0a7827dc4ba707431f1c10babd389f658f8e208b89390a9be3c097579a2ff1b", + }, + "add_sig_2":{ + "address": "0x3028806AC293B5aC9b863B685c73813626311DaD", + "signature": "0x40d305373c648bb6b2bbadebe02ada256a9d0b3d3c37367c0a2795e367b22f7372e40dfc3497927764d1585783d058e4367bb4d24d2107777d7aa4ddcb6593c71b" + } + } +} +EOF + + cat << EOF | zexe copy_from_schema_dictionary.zen copy_from_schema_dictionary.data +Scenario 'ethereum': copy element +Given I have a 'ethereum address signature pair dictionary' named 'addresses_signatures' +When I create the copy of 'add_sig_1' from dictionary 'addresses_signatures' +Then print the 'copy' +EOF + save_output 'copy_from_schema_dictionary.json' + assert_output '{"copy":{"address":"0x2B8070975AF995Ef7eb949AE28ee7706B9039504","signature":"0xed8f36c71989f8660e8f5d4adbfd8f1c0288cca90d3a5330b7bf735d71ab52fe7ba0a7827dc4ba707431f1c10babd389f658f8e208b89390a9be3c097579a2ff1b"}}' +} From 575c7211b32d718591adecf27ee10bb0cc663997 Mon Sep 17 00:00:00 2001 From: matteo-cristino Date: Mon, 28 Aug 2023 10:03:07 +0200 Subject: [PATCH 2/2] =?UTF-8?q?fix(array):=20=F0=9F=90=9B=20support=20sche?= =?UTF-8?q?mas=20when=20copying=20from=20array?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lua/zencode_array.lua | 8 +++++++- test/zencode/array.bats | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/lua/zencode_array.lua b/src/lua/zencode_array.lua index 849fada3e..593867fd6 100644 --- a/src/lua/zencode_array.lua +++ b/src/lua/zencode_array.lua @@ -112,7 +112,13 @@ When("create the copy of element '' in array ''", function(pos, arr) ZEN.assert(num, "Argument is not a position number: "..pos) ZEN.assert(src[num], "No element found in: "..arr.."["..pos.."]") ACK.copy = src[num] - new_codec('copy', {encoding = src_codec.encoding}) + local n_codec = { encoding = src_codec.encoding } + -- table of schemas can only contain elements + if src_codec.schema then + n_codec.schema = src_codec.schema + n_codec.zentype = "e" + end + new_codec('copy', n_codec) end) local function _insert_in(what, dest) diff --git a/test/zencode/array.bats b/test/zencode/array.bats index 22b0deb14..dee839a9c 100755 --- a/test/zencode/array.bats +++ b/test/zencode/array.bats @@ -970,3 +970,29 @@ EOF save_output "copy_element.json" assert_output '{"dictionary_from_dictionary":{"paperino":"duck"},"string_from_array_1":"pluto","string_from_array_2":"paperino","string_from_array_3":"topolino","string_from_dictionary_1":"dog","string_from_dictionary_2":"mouse"}' } + +@test "copy element from schemas" { + cat << EOF | save_asset copy_from_schema_array.data +{ + "addresses_signatures": [ + { + "address": "0x2B8070975AF995Ef7eb949AE28ee7706B9039504", + "signature": "0xed8f36c71989f8660e8f5d4adbfd8f1c0288cca90d3a5330b7bf735d71ab52fe7ba0a7827dc4ba707431f1c10babd389f658f8e208b89390a9be3c097579a2ff1b", + }, + { + "address": "0x3028806AC293B5aC9b863B685c73813626311DaD", + "signature": "0x40d305373c648bb6b2bbadebe02ada256a9d0b3d3c37367c0a2795e367b22f7372e40dfc3497927764d1585783d058e4367bb4d24d2107777d7aa4ddcb6593c71b" + } + ] +} +EOF + + cat << EOF | zexe copy_from_schema_array.zen copy_from_schema_array.data +Scenario 'ethereum': copy element +Given I have a 'ethereum address signature pair array' named 'addresses_signatures' +When I create the copy of element '1' in array 'addresses_signatures' +Then print the 'copy' +EOF + save_output 'copy_from_schema_array.json' + assert_output '{"copy":{"address":"0x2B8070975AF995Ef7eb949AE28ee7706B9039504","signature":"0xed8f36c71989f8660e8f5d4adbfd8f1c0288cca90d3a5330b7bf735d71ab52fe7ba0a7827dc4ba707431f1c10babd389f658f8e208b89390a9be3c097579a2ff1b"}}' +}