From 479ed78cbed044ff8a8ecd2d369816c49c9067b6 Mon Sep 17 00:00:00 2001 From: Igor Lins e Silva <4753812+igorls@users.noreply.github.com> Date: Wed, 20 Nov 2024 02:43:09 -0300 Subject: [PATCH] add serialization test --- examples/nested.mjs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/examples/nested.mjs b/examples/nested.mjs index 24df67a..20c7b25 100644 --- a/examples/nested.mjs +++ b/examples/nested.mjs @@ -45,7 +45,7 @@ const serializedData = Serializer.encode({ const hexData = serializedData.toString('hex'); -console.log("HEX Data", hexData); +console.log("HEX Data (from Wharfkit)\n", hexData); const deserializedData = Serializer.decode({ abi, @@ -58,12 +58,22 @@ console.log("Deserialized Data (Wharfkit)", Serializer.objectify(deserializedDat // loading ABI const status = abieos.loadAbi('test', abi.toJSON()); if (status) { + + // deserialize const abieosDecoded = abieos.hexToJson('test', 'nested', hexData); console.log("Deserialized Data (ABIEOS)", abieosDecoded); - const outputString = JSON.stringify(abieosDecoded); - if (outputString !== inputString) { + if (JSON.stringify(abieosDecoded) !== inputString) { console.error(`Input / Output Mismatch`); } else { - console.log('Test Completed!'); + console.log('JSON Data Matched!'); + } + + // serialize again + const abieosEncoded = abieos.jsonToHex('test', 'nested', abieosDecoded); + console.log("HEX Data (ABIEOS)\n", abieosEncoded); + if (hexData !== abieosEncoded) { + console.error(`Hex Data Mismatch`); + } else { + console.log('HEX Data Matched!'); } }