-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ABI Interaction Support for Python SDK (#247)
* Start ABI JSON interaction * Add static annoation * Fix Method argument parsing * Add ABI Typing to Method arguments * [WIP] Add AtomicTransactionComposer build functions * [WIP] Sign and send atomic transaction groups * Add unit tests for object parsing * Clean up method calls * Address PR comments on JSON objects * Refactor ABI Type to ABIType so it can be exposed to outside world * Add cucumber steps for ABI tests and update existing implementation so it can pass these tests * Refactor TransactionSigner to Abstract class and merge signatures when signing * Update testing to reflect json unit tests and composer tests * Formatting and docstring fixes * Clean up imports * Fix unit test for appId * Refactor some names and add txn as an arg type * Partially address PR comments * Add some additional checks for safety * Fix a step so we check for empty string instead of None * MInclude returns tests and check for a valid returns from a ABI call * Addressing PR comments about type hints and returning self * Ensure group ids are zero when adding transactions
- Loading branch information
Showing
19 changed files
with
1,391 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
unit: | ||
behave --tags="@unit.offline or @unit.algod or @unit.indexer or @unit.rekey or @unit.tealsign or @unit.dryrun or @unit.applications or @unit.responses or @unit.transactions or @unit.responses.231 or @unit.feetest or @unit.indexer.logs" test -f progress2 | ||
behave --tags="@unit.offline or @unit.algod or @unit.indexer or @unit.rekey or @unit.tealsign or @unit.dryrun or @unit.applications or @unit.responses or @unit.transactions or @unit.transactions.payment or @unit.responses.231 or @unit.feetest or @unit.indexer.logs or @unit.abijson or @unit.atomic_transaction_composer" test -f progress2 | ||
|
||
integration: | ||
behave --tags="@algod or @assets or @auction or @kmd or @send or @template or @indexer or @indexer.applications or @rekey or @compile or @dryrun or @dryrun.testing or @applications or @applications.verified or @indexer.231" test -f progress2 | ||
behave --tags="@algod or @assets or @auction or @kmd or @send or @template or @indexer or @indexer.applications or @rekey or @compile or @dryrun or @dryrun.testing or @applications or @applications.verified or @indexer.231 or @abi" test -f progress2 | ||
|
||
docker-test: | ||
./run_integration.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
from .util import type_from_string | ||
from .uint_type import UintType | ||
from .ufixed_type import UfixedType | ||
from .base_type import ABIType | ||
from .bool_type import BoolType | ||
from .byte_type import ByteType | ||
from .address_type import AddressType | ||
from .string_type import StringType | ||
from .array_dynamic_type import ArrayDynamicType | ||
from .array_static_type import ArrayStaticType | ||
from .tuple_type import TupleType | ||
from .method import Method, Argument, Returns | ||
from .interface import Interface | ||
from .contract import Contract | ||
|
||
name = "abi" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import json | ||
|
||
from algosdk.abi.method import Method | ||
|
||
|
||
class Contract: | ||
""" | ||
Represents a ABI contract description. | ||
Args: | ||
name (string): name of the contract | ||
app_id (int): application id associated with the contract | ||
methods (list): list of Method objects | ||
""" | ||
|
||
def __init__(self, name, app_id, methods) -> None: | ||
self.name = name | ||
self.app_id = int(app_id) | ||
self.methods = methods | ||
|
||
def __eq__(self, o) -> bool: | ||
if not isinstance(o, Contract): | ||
return False | ||
return ( | ||
self.name == o.name | ||
and self.app_id == o.app_id | ||
and self.methods == o.methods | ||
) | ||
|
||
@staticmethod | ||
def from_json(resp): | ||
d = json.loads(resp) | ||
return Contract.undictify(d) | ||
|
||
def dictify(self): | ||
d = {} | ||
d["name"] = self.name | ||
d["appId"] = self.app_id | ||
d["methods"] = [m.dictify() for m in self.methods] | ||
return d | ||
|
||
@staticmethod | ||
def undictify(d): | ||
name = d["name"] | ||
app_id = d["appId"] | ||
method_list = [Method.undictify(method) for method in d["methods"]] | ||
return Contract(name=name, app_id=app_id, methods=method_list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import json | ||
|
||
from algosdk.abi.method import Method | ||
|
||
|
||
class Interface: | ||
""" | ||
Represents a ABI interface description. | ||
Args: | ||
name (string): name of the interface | ||
methods (list): list of Method objects | ||
""" | ||
|
||
def __init__(self, name, methods): | ||
self.name = name | ||
self.methods = methods | ||
|
||
def __eq__(self, o): | ||
if not isinstance(o, Interface): | ||
return False | ||
return self.name == o.name and self.methods == o.methods | ||
|
||
@staticmethod | ||
def from_json(resp): | ||
d = json.loads(resp) | ||
return Interface.undictify(d) | ||
|
||
def dictify(self): | ||
d = {} | ||
d["name"] = self.name | ||
d["methods"] = [m.dictify() for m in self.methods] | ||
return d | ||
|
||
@staticmethod | ||
def undictify(d): | ||
name = d["name"] | ||
method_list = [Method.undictify(method) for method in d["methods"]] | ||
return Interface(name=name, methods=method_list) |
Oops, something went wrong.