Skip to content

Commit

Permalink
Rename test dir to tests and move unit and integration tests
Browse files Browse the repository at this point in the history
Refactoring

Revert and refactor unit tests

Finish moving tests to separate modules

Remove test feature files

adding method to ABIResult (#342)

* adding method to ABIResult

Add method to get Method by name (#345)

* adding util method to get a Method from an interface or contract by name string

Change paths for tests

Change makefile
  • Loading branch information
algochoi committed Jun 16, 2022
1 parent d056766 commit c767b86
Show file tree
Hide file tree
Showing 21 changed files with 4,391 additions and 4,273 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ venv.bak/

# Testing files
*.feature
test/features
tests/features
test-harness

# Build files
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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
behave --tags=$(UNITS) tests -f progress2

INTEGRATIONS = "@abi or @algod or @applications or @applications.verified or @assets or @auction or @c2c or @compile or @dryrun or @dryrun.testing or @indexer or @indexer.231 or @indexer.applications or @kmd or @rekey or @send.keyregtxn or @send"
integration:
behave --tags=$(INTEGRATIONS) test -f progress2
behave --tags=$(INTEGRATIONS) tests -f progress2

PYTHON_VERSION ?= 3.8
docker-test:
Expand Down
5 changes: 4 additions & 1 deletion algosdk/abi/contract.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -63,6 +63,9 @@ def undictify(d: dict) -> "Contract":
name=name, desc=desc, networks=networks, methods=method_list
)

def get_method_by_name(self, name: str) -> Method:
return get_method_by_name(self.methods, name)


class NetworkInfo:
"""
Expand Down
5 changes: 4 additions & 1 deletion algosdk/abi/interface.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -49,3 +49,6 @@ 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:
return get_method_by_name(self.methods, name)
19 changes: 19 additions & 0 deletions algosdk/abi/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,25 @@ 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
Expand Down
4 changes: 4 additions & 0 deletions algosdk/atomic_transaction_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ def execute(
return_value=return_value,
decode_error=decode_error,
tx_info=tx_info,
method=self.method_dict[i],
)
)
continue
Expand Down Expand Up @@ -549,6 +550,7 @@ def execute(
return_value=return_value,
decode_error=decode_error,
tx_info=tx_info,
method=self.method_dict[i],
)
method_results.append(abi_result)

Expand Down Expand Up @@ -696,12 +698,14 @@ def __init__(
return_value: Any,
decode_error: Optional[Exception],
tx_info: dict,
method: abi.Method,
) -> None:
self.tx_id = tx_id
self.raw_value = raw_value
self.return_value = return_value
self.decode_error = decode_error
self.tx_info = tx_info
self.method = method


class AtomicTransactionResponse:
Expand Down
4 changes: 2 additions & 2 deletions run_integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ rm -rf test-harness
git clone --single-branch --branch feature/box-storage 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
mkdir -p tests/features
cp -r test-harness/features/* tests/features

# Build SDK testing environment
docker build -t py-sdk-testing --build-arg PYTHON_VERSION="${PYTHON_VERSION}" -f Dockerfile "$(pwd)"
Expand Down

0 comments on commit c767b86

Please sign in to comment.