From fc38db47dfb11c084c6337619f2ad7ff320dd490 Mon Sep 17 00:00:00 2001 From: algochoi <86622919+algochoi@users.noreply.github.com> Date: Mon, 30 Jan 2023 12:53:05 -0500 Subject: [PATCH 1/2] Add disassembly endpoint and implement cucumber test --- algosdk/v2client/algod.py | 24 +++++++++++++++++++++++- tests/steps/other_v2_steps.py | 11 +++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/algosdk/v2client/algod.py b/algosdk/v2client/algod.py index 1614f847..64dc94ae 100644 --- a/algosdk/v2client/algod.py +++ b/algosdk/v2client/algod.py @@ -403,6 +403,28 @@ def compile(self, source, source_map=False, **kwargs): "POST", req, params=params, data=source.encode("utf-8"), **kwargs ) + def disassemble(self, program_bytes, **kwargs): + """ + Disassable TEAL program bytes with remote algod. + Args: + program (bytes): bytecode to be disassembled + request_header (dict, optional): additional header for request + Returns: + str: disassembled TEAL source code in plain text + """ + if not isinstance(program_bytes, bytes): + raise error.InvalidProgram( + message=f"disassemble endpoints only accepts bytes but request program_bytes is of type {type(program_bytes)}" + ) + + req = "/teal/disassemble" + headers = util.build_headers_from( + kwargs.get("headers", False), + {"Content-Type": "application/x-binary"}, + ) + kwargs["headers"] = headers + return self.algod_request("POST", req, data=program_bytes, **kwargs) + def dryrun(self, drr, **kwargs): """ Dryrun with remote algod. @@ -450,7 +472,7 @@ def transaction_proof( req, params=params, response_format=response_format, - **kwargs + **kwargs, ) def lightblockheader_proof(self, round_num, **kwargs): diff --git a/tests/steps/other_v2_steps.py b/tests/steps/other_v2_steps.py index ef038d29..a2edb601 100644 --- a/tests/steps/other_v2_steps.py +++ b/tests/steps/other_v2_steps.py @@ -1072,6 +1072,17 @@ def b64decode_compiled_teal_step(context, binary): assert base64.b64decode(response_result.encode()) == binary +@then('disassembly of "{bytecode_filename}" matches "{source_filename}"') +def disassembly_matches_source(context, bytecode_filename, source_filename): + bytecode = load_resource(bytecode_filename) + expected_source = load_resource(source_filename).decode("utf-8") + + context.response = context.app_acl.disassemble(bytecode) + actual_source = context.response["result"] + + assert actual_source == expected_source + + @when('I dryrun a "{kind}" program "{program}"') def dryrun_step(context, kind, program): data = load_resource(program) From f88c90b1aee7769522bbbe4491a0f1c217ef95bf Mon Sep 17 00:00:00 2001 From: algochoi <86622919+algochoi@users.noreply.github.com> Date: Tue, 31 Jan 2023 09:45:28 -0500 Subject: [PATCH 2/2] Add integration tag for tests --- tests/integration.tags | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integration.tags b/tests/integration.tags index de2c60c5..2ead9e95 100644 --- a/tests/integration.tags +++ b/tests/integration.tags @@ -6,6 +6,7 @@ @auction @c2c @compile +@compile.disassemble @compile.sourcemap @dryrun @dryrun.testing