Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Algod: Add disassembly endpoint and implement cucumber test #440

Merged
merged 2 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 23 additions & 1 deletion algosdk/v2client/algod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -450,7 +472,7 @@ def transaction_proof(
req,
params=params,
response_format=response_format,
**kwargs
**kwargs,
)

def lightblockheader_proof(self, round_num, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions tests/integration.tags
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@auction
@c2c
@compile
@compile.disassemble
@compile.sourcemap
@dryrun
@dryrun.testing
Expand Down
11 changes: 11 additions & 0 deletions tests/steps/other_v2_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down