From cba35e799d5b7ff939f538481f78e41db8b05adc Mon Sep 17 00:00:00 2001 From: Etienne Wallet <116115319+EtienneWallet@users.noreply.github.com> Date: Thu, 29 Feb 2024 21:15:32 +0100 Subject: [PATCH] Fix/decoded results with results types (#65) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: decode results by default when provided with results types * fix: wrong example * Bump version: 2.1.0-dev0 → 2.1.0-dev1 --------- Co-authored-by: github-actions <41898282+github-actions@users.noreply.github.com> --- docs/source/user_documentation/steps.md | 2 +- mxops/execution/steps.py | 23 ++++++++++------------- pyproject.toml | 2 +- setup.cfg | 2 +- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/docs/source/user_documentation/steps.md b/docs/source/user_documentation/steps.md index e9873bc..8aba371 100644 --- a/docs/source/user_documentation/steps.md +++ b/docs/source/user_documentation/steps.md @@ -148,7 +148,7 @@ arguments: [] results_save_keys: # optional, key(s) under which save the results of the query - EsdtIdentifier results_types: # mandatory if results are to be saved and no ABI have been provided for this contract - - TokenIdentifier + - type: TokenIdentifier print_results: true # optional, if the query results should be printed in the console ``` diff --git a/mxops/execution/steps.py b/mxops/execution/steps.py index a3ce9ae..8737a6e 100644 --- a/mxops/execution/steps.py +++ b/mxops/execution/steps.py @@ -3,6 +3,7 @@ This module contains the classes used to execute scenes in a scenario """ + from __future__ import annotations import base64 from dataclasses import dataclass, field @@ -539,18 +540,8 @@ def save_results(self): if self.results_save_keys is None: return - # decode results if specified - if self.results_types is None: - if self.decoded_results is None: - raise ValueError( - "No result were decoded due to lack of ABI but `results_types` was " - "not specified either" - ) - else: - data_parts = self.query_response.get_return_data_parts() - self.decoded_results = AbiSerializer().decode_io( - self.results_types, data_parts - ) + if self.decoded_results is None: + raise ValueError("No decoded results to save") LOGGER.info("Saving query results") sub_keys = self.results_save_keys.sub_keys @@ -619,7 +610,13 @@ def execute(self): self._interpret_return_data(data) for data in self.query_response.return_data ] - if serializer is not None: + if self.results_types is not None: + data_parts = self.query_response.get_return_data_parts() + print(self.results_types, data_parts) + self.decoded_results = AbiSerializer().decode_io( + self.results_types, data_parts + ) + elif serializer is not None: self.decoded_results = serializer.decode_contract_query_response( self.endpoint, self.query_response ) diff --git a/pyproject.toml b/pyproject.toml index 168b5b9..ad2e39c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta" [project] name = "mxops" -version = "2.1.0-dev0" +version = "2.1.0-dev1" authors = [ {name="Etienne Wallet"}, ] diff --git a/setup.cfg b/setup.cfg index 0b5e110..02b4db9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.1.0-dev0 +current_version = 2.1.0-dev1 parse = (?P\d+)\.(?P\d+)\.(?P\d+)(-(?P\w+)(?P\d+))? serialize = {major}.{minor}.{patch}-{release}{build}