From b4c93e9a581e071a7b15dc4ee47e89c5867fc9bf Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Mon, 6 Jun 2022 12:37:35 -0400 Subject: [PATCH 01/15] adding util method to get a Method from an interface or contract by name string --- algosdk/atomic_transaction_composer.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/algosdk/atomic_transaction_composer.py b/algosdk/atomic_transaction_composer.py index 05e57ec1..9e954b8e 100644 --- a/algosdk/atomic_transaction_composer.py +++ b/algosdk/atomic_transaction_composer.py @@ -711,3 +711,26 @@ def __init__( self.confirmed_round = confirmed_round self.tx_ids = tx_ids self.abi_results = results + + +def get_method_by_name( + iface: Union[abi.Contract, abi.Interface], name: str +) -> abi.Method: + if not isinstance(iface, abi.Contract) and not isinstance( + iface, abi.Interface + ): + raise TypeError("Expected Interface or Contract, got {}".format(iface)) + + method = None + for m in iface.methods: + if m.name == name: + if m is not None: + raise KeyError( + "Found multiple methods with the same name {}".format(name) + ) + method = m + + if method is None: + raise KeyError("No method {} found".format(name)) + + return method From e03a975b6d30d0a4b6bc34b4969571d83d8cfd4c Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Tue, 7 Jun 2022 07:39:56 -0400 Subject: [PATCH 02/15] move get_method_by_name to interface/contract objects --- algosdk/abi/contract.py | 17 +++++++++++++++++ algosdk/abi/interface.py | 17 +++++++++++++++++ algosdk/atomic_transaction_composer.py | 23 ----------------------- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/algosdk/abi/contract.py b/algosdk/abi/contract.py index b64fb652..e3dda310 100644 --- a/algosdk/abi/contract.py +++ b/algosdk/abi/contract.py @@ -63,6 +63,23 @@ def undictify(d: dict) -> "Contract": name=name, desc=desc, networks=networks, methods=method_list ) + def get_method_by_name(self, name: str) -> Method: + methods_filtered = filter( + lambda method: method.name == name, self.methods + ) + + if len(methods_filtered) > 1: + raise KeyError( + "Found {} methods with the same name {}".format( + len(methods_filtered), name + ) + ) + + if len(methods_filtered) == 0: + raise KeyError("No method {} found".format(name)) + + return methods_filtered[0] + class NetworkInfo: """ diff --git a/algosdk/abi/interface.py b/algosdk/abi/interface.py index 775bc8df..c5a8e69e 100644 --- a/algosdk/abi/interface.py +++ b/algosdk/abi/interface.py @@ -49,3 +49,20 @@ def undictify(d: dict) -> "Interface": method_list = [Method.undictify(method) for method in d["methods"]] desc = d["desc"] if "desc" in d else None return Interface(name=name, desc=desc, methods=method_list) + + def get_method_by_name(self, name: str) -> Method: + methods_filtered = filter( + lambda method: method.name == name, self.methods + ) + + if len(methods_filtered) > 1: + raise KeyError( + "Found {} methods with the same name {}".format( + len(methods_filtered), name + ) + ) + + if len(methods_filtered) == 0: + raise KeyError("No method {} found".format(name)) + + return methods_filtered[0] diff --git a/algosdk/atomic_transaction_composer.py b/algosdk/atomic_transaction_composer.py index 9e954b8e..05e57ec1 100644 --- a/algosdk/atomic_transaction_composer.py +++ b/algosdk/atomic_transaction_composer.py @@ -711,26 +711,3 @@ def __init__( self.confirmed_round = confirmed_round self.tx_ids = tx_ids self.abi_results = results - - -def get_method_by_name( - iface: Union[abi.Contract, abi.Interface], name: str -) -> abi.Method: - if not isinstance(iface, abi.Contract) and not isinstance( - iface, abi.Interface - ): - raise TypeError("Expected Interface or Contract, got {}".format(iface)) - - method = None - for m in iface.methods: - if m.name == name: - if m is not None: - raise KeyError( - "Found multiple methods with the same name {}".format(name) - ) - method = m - - if method is None: - raise KeyError("No method {} found".format(name)) - - return method From 8f96a784be1576e73a60628b7a1a49a3bf1abf08 Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Tue, 7 Jun 2022 07:53:21 -0400 Subject: [PATCH 03/15] print out all the methods we found in the case of >1 --- algosdk/abi/contract.py | 5 ++++- algosdk/abi/interface.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/algosdk/abi/contract.py b/algosdk/abi/contract.py index e3dda310..b81e8941 100644 --- a/algosdk/abi/contract.py +++ b/algosdk/abi/contract.py @@ -71,7 +71,10 @@ def get_method_by_name(self, name: str) -> Method: if len(methods_filtered) > 1: raise KeyError( "Found {} methods with the same name {}".format( - len(methods_filtered), name + len(methods_filtered), + ",".join( + [method.get_signature() for method in methods_filtered] + ), ) ) diff --git a/algosdk/abi/interface.py b/algosdk/abi/interface.py index c5a8e69e..23773d43 100644 --- a/algosdk/abi/interface.py +++ b/algosdk/abi/interface.py @@ -58,7 +58,10 @@ def get_method_by_name(self, name: str) -> Method: if len(methods_filtered) > 1: raise KeyError( "Found {} methods with the same name {}".format( - len(methods_filtered), name + len(methods_filtered), + ",".join( + [method.get_signature() for method in methods_filtered] + ), ) ) From db026d5d3e51442985461326da50bedccccad724 Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Tue, 7 Jun 2022 08:55:21 -0400 Subject: [PATCH 04/15] make it a list --- algosdk/abi/contract.py | 4 ++-- algosdk/abi/interface.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/algosdk/abi/contract.py b/algosdk/abi/contract.py index b81e8941..09cc7e52 100644 --- a/algosdk/abi/contract.py +++ b/algosdk/abi/contract.py @@ -64,8 +64,8 @@ def undictify(d: dict) -> "Contract": ) def get_method_by_name(self, name: str) -> Method: - methods_filtered = filter( - lambda method: method.name == name, self.methods + methods_filtered = list( + filter(lambda method: method.name == name, self.methods) ) if len(methods_filtered) > 1: diff --git a/algosdk/abi/interface.py b/algosdk/abi/interface.py index 23773d43..274e7681 100644 --- a/algosdk/abi/interface.py +++ b/algosdk/abi/interface.py @@ -51,8 +51,8 @@ def undictify(d: dict) -> "Interface": return Interface(name=name, desc=desc, methods=method_list) def get_method_by_name(self, name: str) -> Method: - methods_filtered = filter( - lambda method: method.name == name, self.methods + methods_filtered = list( + filter(lambda method: method.name == name, self.methods) ) if len(methods_filtered) > 1: From ecfa5c4e4f02c66201dd76d2afcd31d0ca1a05f6 Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Tue, 7 Jun 2022 14:13:25 -0400 Subject: [PATCH 05/15] adding tests for get method by name --- algosdk/abi/contract.py | 2 +- algosdk/abi/interface.py | 2 +- run_integration.sh | 4 +++- test/steps/application_v2_steps.py | 36 ++++++++++++++++++++++++++++++ test/steps/steps.py | 1 + 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/algosdk/abi/contract.py b/algosdk/abi/contract.py index 09cc7e52..0d703178 100644 --- a/algosdk/abi/contract.py +++ b/algosdk/abi/contract.py @@ -79,7 +79,7 @@ def get_method_by_name(self, name: str) -> Method: ) if len(methods_filtered) == 0: - raise KeyError("No method {} found".format(name)) + raise KeyError("found 0 methods for {}".format(name)) return methods_filtered[0] diff --git a/algosdk/abi/interface.py b/algosdk/abi/interface.py index 274e7681..0593564d 100644 --- a/algosdk/abi/interface.py +++ b/algosdk/abi/interface.py @@ -66,6 +66,6 @@ def get_method_by_name(self, name: str) -> Method: ) if len(methods_filtered) == 0: - raise KeyError("No method {} found".format(name)) + raise KeyError("found 0 methods for {}".format(name)) return methods_filtered[0] diff --git a/run_integration.sh b/run_integration.sh index 76b293e8..d6be13b9 100755 --- a/run_integration.sh +++ b/run_integration.sh @@ -7,12 +7,14 @@ pushd $rootdir # Reset test harness rm -rf test-harness -git clone --single-branch --branch master https://github.com/algorand/algorand-sdk-testing.git test-harness +git clone --single-branch --branch get-method-by-name https://github.com/algorand/algorand-sdk-testing.git test-harness ## Copy feature files into the project resources mkdir -p test/features cp -r test-harness/features/* test/features +exit + # Build SDK testing environment docker build -t py-sdk-testing --build-arg PYTHON_VERSION="${PYTHON_VERSION}" -f Dockerfile "$(pwd)" diff --git a/test/steps/application_v2_steps.py b/test/steps/application_v2_steps.py index e7a1f9c7..8f27bd3a 100644 --- a/test/steps/application_v2_steps.py +++ b/test/steps/application_v2_steps.py @@ -992,3 +992,39 @@ def spin_results_satisfy(context, result_index, regex): spin = bytes(spin).decode() assert re.search(regex, spin), f"{spin} did not match the regex {regex}" + + + + +@when('I create an Interface object from the Method object') +def create_interface_from_method(context): + context.iface = abi.Interface('', [context.abi_method]) + +@when('I create a Contract object from the Method object') +def create_contract_from_method(context): + context.contract = abi.Contract('', [context.abi_method]) + +@when('I get the method from the Interface by name "{name}"') +def get_interface_method_by_name(context, name): + try: + context.retrieved_method = context.iface.get_method_by_name(name) + except KeyError as ke: + context.error = str(ke) + +@when('I get the method from the Contract by name "{name}"') +def get_contract_method_by_name(context, name): + try: + context.retrieved_method = context.contract.get_method_by_name(name) + except KeyError as ke: + context.error = str(ke) + +@then('the produced method signature should equal "{methodsig}" if there is an error it is equal to "{error:MaybeString}"') +def check_found_method_or_error(context, methodsig, error: str = None): + if hasattr(context, 'retrieved_method'): + assert error == "" + assert methodsig == context.retrieved_method.get_signature() + elif hasattr(context, 'error'): + assert error != "" + assert error in context.error + else: + assert False, "Both retrieved method and error string are None" \ No newline at end of file diff --git a/test/steps/steps.py b/test/steps/steps.py index 99e8ea9a..7773d6cf 100644 --- a/test/steps/steps.py +++ b/test/steps/steps.py @@ -11,6 +11,7 @@ from algosdk import util from algosdk import constants from algosdk import logic +from algosdk import abi from algosdk.future import template import os from datetime import datetime From b4cff485b30527c5cd7daa6f043aa53753f98de9 Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Tue, 7 Jun 2022 14:45:32 -0400 Subject: [PATCH 06/15] fmt --- test/steps/application_v2_steps.py | 28 ++++++++++++++++------------ test/steps/steps.py | 1 - 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/test/steps/application_v2_steps.py b/test/steps/application_v2_steps.py index 8f27bd3a..c7156dc8 100644 --- a/test/steps/application_v2_steps.py +++ b/test/steps/application_v2_steps.py @@ -994,15 +994,15 @@ def spin_results_satisfy(context, result_index, regex): assert re.search(regex, spin), f"{spin} did not match the regex {regex}" - - -@when('I create an Interface object from the Method object') +@when("I create an Interface object from the Method object") def create_interface_from_method(context): - context.iface = abi.Interface('', [context.abi_method]) + context.iface = abi.Interface("", [context.abi_method]) + -@when('I create a Contract object from the Method object') +@when("I create a Contract object from the Method object") def create_contract_from_method(context): - context.contract = abi.Contract('', [context.abi_method]) + context.contract = abi.Contract("", [context.abi_method]) + @when('I get the method from the Interface by name "{name}"') def get_interface_method_by_name(context, name): @@ -1011,6 +1011,7 @@ def get_interface_method_by_name(context, name): except KeyError as ke: context.error = str(ke) + @when('I get the method from the Contract by name "{name}"') def get_contract_method_by_name(context, name): try: @@ -1018,13 +1019,16 @@ def get_contract_method_by_name(context, name): except KeyError as ke: context.error = str(ke) -@then('the produced method signature should equal "{methodsig}" if there is an error it is equal to "{error:MaybeString}"') + +@then( + 'the produced method signature should equal "{methodsig}" if there is an error it is equal to "{error:MaybeString}"' +) def check_found_method_or_error(context, methodsig, error: str = None): - if hasattr(context, 'retrieved_method'): + if hasattr(context, "retrieved_method"): assert error == "" assert methodsig == context.retrieved_method.get_signature() - elif hasattr(context, 'error'): + elif hasattr(context, "error"): assert error != "" - assert error in context.error - else: - assert False, "Both retrieved method and error string are None" \ No newline at end of file + assert error in context.error + else: + assert False, "Both retrieved method and error string are None" diff --git a/test/steps/steps.py b/test/steps/steps.py index 7773d6cf..99e8ea9a 100644 --- a/test/steps/steps.py +++ b/test/steps/steps.py @@ -11,7 +11,6 @@ from algosdk import util from algosdk import constants from algosdk import logic -from algosdk import abi from algosdk.future import template import os from datetime import datetime From f6c6ca1a47e446b8cc97cfec2abebeb0ee9f4005 Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Wed, 8 Jun 2022 15:01:59 -0400 Subject: [PATCH 07/15] adding test for dupe name --- algosdk/abi/contract.py | 2 +- algosdk/abi/interface.py | 2 +- test/steps/application_v2_steps.py | 21 ++++++++++++++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/algosdk/abi/contract.py b/algosdk/abi/contract.py index 0d703178..83db5d20 100644 --- a/algosdk/abi/contract.py +++ b/algosdk/abi/contract.py @@ -70,7 +70,7 @@ def get_method_by_name(self, name: str) -> Method: if len(methods_filtered) > 1: raise KeyError( - "Found {} methods with the same name {}".format( + "found {} methods with the same name {}".format( len(methods_filtered), ",".join( [method.get_signature() for method in methods_filtered] diff --git a/algosdk/abi/interface.py b/algosdk/abi/interface.py index 0593564d..91c0c942 100644 --- a/algosdk/abi/interface.py +++ b/algosdk/abi/interface.py @@ -57,7 +57,7 @@ def get_method_by_name(self, name: str) -> Method: if len(methods_filtered) > 1: raise KeyError( - "Found {} methods with the same name {}".format( + "found {} methods with the same name {}".format( len(methods_filtered), ",".join( [method.get_signature() for method in methods_filtered] diff --git a/test/steps/application_v2_steps.py b/test/steps/application_v2_steps.py index c7156dc8..6ca6a6d9 100644 --- a/test/steps/application_v2_steps.py +++ b/test/steps/application_v2_steps.py @@ -994,14 +994,29 @@ def spin_results_satisfy(context, result_index, regex): assert re.search(regex, spin), f"{spin} did not match the regex {regex}" +@when( + 'I create another Method object from method signature "{extramethod:MaybeString}"' +) +def make_extra_method(context, extramethod): + if extramethod != "": + context.extramethod = abi.Method.from_signature(extramethod) + + @when("I create an Interface object from the Method object") def create_interface_from_method(context): - context.iface = abi.Interface("", [context.abi_method]) + methods = [context.abi_method] + if hasattr(context, "extramethod"): + methods.append(context.extramethod) + + context.iface = abi.Interface("", methods) @when("I create a Contract object from the Method object") def create_contract_from_method(context): - context.contract = abi.Contract("", [context.abi_method]) + methods = [context.abi_method] + if hasattr(context, "extramethod"): + methods.append(context.extramethod) + context.contract = abi.Contract("", methods) @when('I get the method from the Interface by name "{name}"') @@ -1021,7 +1036,7 @@ def get_contract_method_by_name(context, name): @then( - 'the produced method signature should equal "{methodsig}" if there is an error it is equal to "{error:MaybeString}"' + 'the produced method signature should equal "{methodsig}". If there is an error it begins with "{error:MaybeString}"' ) def check_found_method_or_error(context, methodsig, error: str = None): if hasattr(context, "retrieved_method"): From b7e0895dc686456c741a1ad9add340ae303210ae Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Thu, 9 Jun 2022 08:57:04 -0400 Subject: [PATCH 08/15] revert sdk-testing branch --- run_integration.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/run_integration.sh b/run_integration.sh index d6be13b9..76b293e8 100755 --- a/run_integration.sh +++ b/run_integration.sh @@ -7,14 +7,12 @@ pushd $rootdir # Reset test harness rm -rf test-harness -git clone --single-branch --branch get-method-by-name https://github.com/algorand/algorand-sdk-testing.git test-harness +git clone --single-branch --branch master https://github.com/algorand/algorand-sdk-testing.git test-harness ## Copy feature files into the project resources mkdir -p test/features cp -r test-harness/features/* test/features -exit - # Build SDK testing environment docker build -t py-sdk-testing --build-arg PYTHON_VERSION="${PYTHON_VERSION}" -f Dockerfile "$(pwd)" From 1ec7d7cf7318fc96c0c692138c5073b5da388af6 Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Thu, 9 Jun 2022 09:58:19 -0400 Subject: [PATCH 09/15] Update algosdk/abi/contract.py Co-authored-by: Zeph Grunschlag --- algosdk/abi/contract.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/algosdk/abi/contract.py b/algosdk/abi/contract.py index 83db5d20..0d8ec23c 100644 --- a/algosdk/abi/contract.py +++ b/algosdk/abi/contract.py @@ -64,9 +64,7 @@ def undictify(d: dict) -> "Contract": ) def get_method_by_name(self, name: str) -> Method: - methods_filtered = list( - filter(lambda method: method.name == name, self.methods) - ) + methods_filtered = [m for m in self.methods if m.name == name] if len(methods_filtered) > 1: raise KeyError( From f94c4e5185fed26bdc43a9d02abb5c477280e54e Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Thu, 9 Jun 2022 10:08:24 -0400 Subject: [PATCH 10/15] updated with new tests --- run_integration.sh | 5 ++++- test/steps/application_v2_steps.py | 26 +++++++++++--------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/run_integration.sh b/run_integration.sh index 76b293e8..2b8a06c3 100755 --- a/run_integration.sh +++ b/run_integration.sh @@ -7,12 +7,15 @@ pushd $rootdir # Reset test harness rm -rf test-harness -git clone --single-branch --branch master https://github.com/algorand/algorand-sdk-testing.git test-harness +git clone --single-branch --branch get-method-by-name https://github.com/algorand/algorand-sdk-testing.git test-harness ## Copy feature files into the project resources mkdir -p test/features cp -r test-harness/features/* test/features + +exit + # Build SDK testing environment docker build -t py-sdk-testing --build-arg PYTHON_VERSION="${PYTHON_VERSION}" -f Dockerfile "$(pwd)" diff --git a/test/steps/application_v2_steps.py b/test/steps/application_v2_steps.py index 6ca6a6d9..d0f74295 100644 --- a/test/steps/application_v2_steps.py +++ b/test/steps/application_v2_steps.py @@ -995,28 +995,24 @@ def spin_results_satisfy(context, result_index, regex): @when( - 'I create another Method object from method signature "{extramethod:MaybeString}"' + 'I append to my Method objects list in the case of a non-empty signature "{method:MaybeString}"' ) -def make_extra_method(context, extramethod): - if extramethod != "": - context.extramethod = abi.Method.from_signature(extramethod) +def make_extra_method(context, method): + if not hasattr(context, 'methods'): + context.methods = [] + if method != "": + context.methods.append(abi.Method.from_signature(method)) -@when("I create an Interface object from the Method object") -def create_interface_from_method(context): - methods = [context.abi_method] - if hasattr(context, "extramethod"): - methods.append(context.extramethod) - context.iface = abi.Interface("", methods) +@when("I create an Interface object from my Method objects list") +def create_interface_from_method(context): + context.iface = abi.Interface("", context.methods) -@when("I create a Contract object from the Method object") +@when("I create a Contract object from my Method objects list") def create_contract_from_method(context): - methods = [context.abi_method] - if hasattr(context, "extramethod"): - methods.append(context.extramethod) - context.contract = abi.Contract("", methods) + context.contract = abi.Contract("", context.methods) @when('I get the method from the Interface by name "{name}"') From a3f2067344269b7b237bc268e80566afd36f6056 Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Thu, 9 Jun 2022 10:09:19 -0400 Subject: [PATCH 11/15] updated with comprehension for interface --- algosdk/abi/interface.py | 6 +++--- test/steps/application_v2_steps.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/algosdk/abi/interface.py b/algosdk/abi/interface.py index 91c0c942..51acad4b 100644 --- a/algosdk/abi/interface.py +++ b/algosdk/abi/interface.py @@ -51,9 +51,9 @@ def undictify(d: dict) -> "Interface": return Interface(name=name, desc=desc, methods=method_list) def get_method_by_name(self, name: str) -> Method: - methods_filtered = list( - filter(lambda method: method.name == name, self.methods) - ) + methods_filtered = [ + method for method in self.methods if method.name == name + ] if len(methods_filtered) > 1: raise KeyError( diff --git a/test/steps/application_v2_steps.py b/test/steps/application_v2_steps.py index d0f74295..3b338de0 100644 --- a/test/steps/application_v2_steps.py +++ b/test/steps/application_v2_steps.py @@ -998,7 +998,7 @@ def spin_results_satisfy(context, result_index, regex): 'I append to my Method objects list in the case of a non-empty signature "{method:MaybeString}"' ) def make_extra_method(context, method): - if not hasattr(context, 'methods'): + if not hasattr(context, "methods"): context.methods = [] if method != "": From 1b108648dbddf093e42c6f338bf26055a3893c26 Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Mon, 13 Jun 2022 08:55:49 -0400 Subject: [PATCH 12/15] abstract method to shared implementation --- algosdk/abi/contract.py | 20 ++------------------ algosdk/abi/interface.py | 21 ++------------------- algosdk/abi/method.py | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 37 deletions(-) diff --git a/algosdk/abi/contract.py b/algosdk/abi/contract.py index 0d8ec23c..6b87ebcd 100644 --- a/algosdk/abi/contract.py +++ b/algosdk/abi/contract.py @@ -1,7 +1,7 @@ import json from typing import Dict, List, Union -from algosdk.abi.method import Method +from algosdk.abi.method import Method, get_method_by_name class Contract: @@ -64,23 +64,7 @@ def undictify(d: dict) -> "Contract": ) def get_method_by_name(self, name: str) -> Method: - methods_filtered = [m for m in self.methods if m.name == name] - - if len(methods_filtered) > 1: - raise KeyError( - "found {} methods with the same name {}".format( - len(methods_filtered), - ",".join( - [method.get_signature() for method in methods_filtered] - ), - ) - ) - - if len(methods_filtered) == 0: - raise KeyError("found 0 methods for {}".format(name)) - - return methods_filtered[0] - + return get_method_by_name(self.methods, name) class NetworkInfo: """ diff --git a/algosdk/abi/interface.py b/algosdk/abi/interface.py index 51acad4b..75784528 100644 --- a/algosdk/abi/interface.py +++ b/algosdk/abi/interface.py @@ -1,7 +1,7 @@ import json from typing import List, Union -from algosdk.abi.method import Method +from algosdk.abi.method import Method, get_method_by_name class Interface: @@ -51,21 +51,4 @@ def undictify(d: dict) -> "Interface": return Interface(name=name, desc=desc, methods=method_list) def get_method_by_name(self, name: str) -> Method: - methods_filtered = [ - method for method in self.methods if method.name == name - ] - - if len(methods_filtered) > 1: - raise KeyError( - "found {} methods with the same name {}".format( - len(methods_filtered), - ",".join( - [method.get_signature() for method in methods_filtered] - ), - ) - ) - - if len(methods_filtered) == 0: - raise KeyError("found 0 methods for {}".format(name)) - - return methods_filtered[0] + return get_method_by_name(self.methods, name) \ No newline at end of file diff --git a/algosdk/abi/method.py b/algosdk/abi/method.py index 67d7bf35..2bbf663b 100644 --- a/algosdk/abi/method.py +++ b/algosdk/abi/method.py @@ -126,6 +126,28 @@ def undictify(d: dict) -> "Method": return Method(name=name, args=arg_list, returns=return_obj, desc=desc) +def get_method_by_name(methods: List[Method], name: str) -> Method: + methods_filtered = [ + method for method in methods if method.name == name + ] + + if len(methods_filtered) > 1: + raise KeyError( + "found {} methods with the same name {}".format( + len(methods_filtered), + ",".join( + [method.get_signature() for method in methods_filtered] + ), + ) + ) + + if len(methods_filtered) == 0: + raise KeyError("found 0 methods for {}".format(name)) + + return methods_filtered[0] + + + class Argument: """ Represents an argument for a ABI method From cdd0b8d77152baf12f06a99b56e3a42f2e265113 Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Mon, 13 Jun 2022 09:06:06 -0400 Subject: [PATCH 13/15] fmt --- algosdk/abi/contract.py | 1 + algosdk/abi/interface.py | 2 +- algosdk/abi/method.py | 5 +---- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/algosdk/abi/contract.py b/algosdk/abi/contract.py index 6b87ebcd..8d8e02d0 100644 --- a/algosdk/abi/contract.py +++ b/algosdk/abi/contract.py @@ -66,6 +66,7 @@ def undictify(d: dict) -> "Contract": def get_method_by_name(self, name: str) -> Method: return get_method_by_name(self.methods, name) + class NetworkInfo: """ Represents network information. diff --git a/algosdk/abi/interface.py b/algosdk/abi/interface.py index 75784528..5bd79aa4 100644 --- a/algosdk/abi/interface.py +++ b/algosdk/abi/interface.py @@ -51,4 +51,4 @@ def undictify(d: dict) -> "Interface": return Interface(name=name, desc=desc, methods=method_list) def get_method_by_name(self, name: str) -> Method: - return get_method_by_name(self.methods, name) \ No newline at end of file + return get_method_by_name(self.methods, name) diff --git a/algosdk/abi/method.py b/algosdk/abi/method.py index 2bbf663b..08397de0 100644 --- a/algosdk/abi/method.py +++ b/algosdk/abi/method.py @@ -127,9 +127,7 @@ def undictify(d: dict) -> "Method": def get_method_by_name(methods: List[Method], name: str) -> Method: - methods_filtered = [ - method for method in methods if method.name == name - ] + methods_filtered = [method for method in methods if method.name == name] if len(methods_filtered) > 1: raise KeyError( @@ -147,7 +145,6 @@ def get_method_by_name(methods: List[Method], name: str) -> Method: return methods_filtered[0] - class Argument: """ Represents an argument for a ABI method From 64908028b4efe64a85f04e7eb9acee997bff2951 Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Mon, 13 Jun 2022 09:45:52 -0400 Subject: [PATCH 14/15] revert integration shell script --- run_integration.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/run_integration.sh b/run_integration.sh index 2b8a06c3..76b293e8 100755 --- a/run_integration.sh +++ b/run_integration.sh @@ -7,15 +7,12 @@ pushd $rootdir # Reset test harness rm -rf test-harness -git clone --single-branch --branch get-method-by-name https://github.com/algorand/algorand-sdk-testing.git test-harness +git clone --single-branch --branch master https://github.com/algorand/algorand-sdk-testing.git test-harness ## Copy feature files into the project resources mkdir -p test/features cp -r test-harness/features/* test/features - -exit - # Build SDK testing environment docker build -t py-sdk-testing --build-arg PYTHON_VERSION="${PYTHON_VERSION}" -f Dockerfile "$(pwd)" From 8be29857f39a61ae43fbe7191bad34f358d465cc Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Mon, 13 Jun 2022 12:23:42 -0400 Subject: [PATCH 15/15] adding byname tests to unit tests --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8f066457..d9cc68fb 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -UNITS = "@unit.abijson or @unit.algod or @unit.algod.ledger_refactoring or @unit.applications or @unit.atomic_transaction_composer or @unit.dryrun or @unit.dryrun.trace.application or @unit.feetest or @unit.indexer or @unit.indexer.ledger_refactoring or @unit.indexer.logs or @unit.offline or @unit.rekey or @unit.transactions.keyreg or @unit.responses or @unit.responses.231 or @unit.tealsign or @unit.transactions or @unit.transactions.payment or @unit.responses.unlimited_assets" +UNITS = "@unit.abijson or @unit.abijson.byname or @unit.algod or @unit.algod.ledger_refactoring or @unit.applications or @unit.atomic_transaction_composer or @unit.dryrun or @unit.dryrun.trace.application or @unit.feetest or @unit.indexer or @unit.indexer.ledger_refactoring or @unit.indexer.logs or @unit.offline or @unit.rekey or @unit.transactions.keyreg or @unit.responses or @unit.responses.231 or @unit.tealsign or @unit.transactions or @unit.transactions.payment or @unit.responses.unlimited_assets" unit: behave --tags=$(UNITS) test -f progress2