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

Dryrun response #283

Merged
merged 53 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
7b62bab
Merge branch 'release/v1.8.0'
bricerisingalgorand Oct 4, 2021
6785baa
Merge branch 'release/v1.9.0b1'
onetechnical Nov 26, 2021
6bb2533
Merge branch 'release/v1.9.0b2'
egieseke Jan 3, 2022
1e4990f
Merge branch 'release/v1.9.0'
algobarb Jan 14, 2022
598a5b6
adding dryrun result object
barnjamin Jan 31, 2022
062ce94
fmt
barnjamin Jan 31, 2022
072e947
typo
barnjamin Jan 31, 2022
508025b
make space size configurable
barnjamin Jan 31, 2022
0d2f81c
zeph cr, thanks!
barnjamin Feb 4, 2022
4ce2a14
inline snake caser, fix str call
barnjamin Feb 4, 2022
8815d72
add check to make sure we have the attr we try to use
barnjamin Feb 4, 2022
0fa8d8e
first stab at test
barnjamin Feb 5, 2022
dd1b093
some changes to formatting to help with readability
barnjamin Feb 5, 2022
31d49f1
update
barnjamin Feb 5, 2022
d1083ce
use lsig disassembly
barnjamin Feb 5, 2022
c010e75
pad before line number, remove pipe
barnjamin Feb 5, 2022
efb281e
make the max line width work right
barnjamin Feb 5, 2022
33bb685
adding pc and headers
barnjamin Feb 6, 2022
5e2ef10
unpack into vars
barnjamin Feb 6, 2022
1e35187
take out empty string thing
barnjamin Feb 6, 2022
edd8328
fmt
barnjamin Feb 6, 2022
69a891a
adding methods to check if the DryrunTxnResult was successful
barnjamin Feb 8, 2022
357e1c6
take out case since its merged
barnjamin Feb 9, 2022
0e036ec
merge develop
barnjamin Feb 10, 2022
89182e8
changing padding math
barnjamin Feb 10, 2022
c01d415
adding dryrun trace for application test
barnjamin Feb 10, 2022
07eca10
fmt
barnjamin Feb 10, 2022
ede274a
added new given string, temporarily chekced out the branch with the t…
barnjamin Feb 11, 2022
5287739
fmt
barnjamin Feb 11, 2022
eaebf36
merge develop
barnjamin Feb 23, 2022
f661cca
revert sdk testing to master branch
barnjamin Feb 23, 2022
fa9211a
almost
barnjamin Mar 22, 2022
83dca7e
passing tests with new formatting
barnjamin Mar 22, 2022
2972067
dont use type, its incorrect in some cases
barnjamin Mar 22, 2022
3dfe4c4
trigger build
barnjamin Mar 22, 2022
48ffbda
alias package name
barnjamin Mar 22, 2022
a81d5b8
Update algosdk/dryrun_results.py
barnjamin Mar 23, 2022
8190e2b
Update algosdk/dryrun_results.py
barnjamin Mar 23, 2022
0d2620c
Update algosdk/dryrun_results.py
barnjamin Mar 23, 2022
e9022c1
Update algosdk/dryrun_results.py
barnjamin Mar 23, 2022
bd2a723
Update algosdk/dryrun_results.py
barnjamin Mar 23, 2022
ed3605a
Update test/steps/v2_steps.py
barnjamin Mar 23, 2022
0185f87
Update Makefile
barnjamin Mar 23, 2022
5181e2d
Update algosdk/dryrun_results.py
barnjamin Mar 23, 2022
8b54442
Update algosdk/dryrun_results.py
barnjamin Mar 23, 2022
78aa402
fix comma, fmt
barnjamin Mar 23, 2022
8ded7ec
adding tabulate as requirement
barnjamin Mar 23, 2022
371875f
remove tabulate dep
barnjamin Mar 23, 2022
846e7e9
better name of max width config param
barnjamin Mar 25, 2022
5efa115
Merge branch 'develop' into dryrun-response
barnjamin Mar 31, 2022
b7fb15c
merge fmt
barnjamin Mar 31, 2022
d336364
merge fmt
barnjamin Mar 31, 2022
8e562b9
Merge branch 'dryrun-response' of github.com:algorand/py-algorand-sdk…
barnjamin Mar 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions algosdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
from . import util
from . import wallet
from . import wordlist
from . import dryrun_results
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we keep this in alphabetical order?


name = "algosdk"
112 changes: 112 additions & 0 deletions algosdk/dryrun_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
from typing import List


class DryrunResponse:
def __init__(self, drrjson: dict):

for param in ["error", "protocol-version", "txns"]:
assert (
param in drrjson
), f"expecting dryrun response object to have key '{param}' but it is missing"

# These are all required fields
barnjamin marked this conversation as resolved.
Show resolved Hide resolved
self.error = drrjson["error"]
self.protocol = drrjson["protocol-version"]
self.txns = [DryrunTransactionResult(txn) for txn in drrjson["txns"]]


class DryrunTransactionResult:
DEFAULT_TRACE_SPACES: int = 16

def __init__(self, dr):
assert (
"disassembly" in dr
), "expecting dryrun transaction result to have key 'disassembly' but its missing"

self.disassembly = dr["disassembly"]
barnjamin marked this conversation as resolved.
Show resolved Hide resolved

optionals = [
"app-call-messages",
"local-deltas",
"global-delta",
"cost",
"logic-sig-messages",
"logs",
]
for field in optionals:
if field in dr:
setattr(self, field.replace("-", "_"), dr[field])

traces = ["app-call-trace", "logic-sig-trace"]
for trace_field in traces:
if trace_field in dr:
setattr(
self,
trace_field.replace("-", "_"),
barnjamin marked this conversation as resolved.
Show resolved Hide resolved
barnjamin marked this conversation as resolved.
Show resolved Hide resolved
DryrunTrace(dr[trace_field]),
)

@classmethod
def trace(
cls,
dr_trace: "DryrunTrace",
disassembly: List[str],
spaces: int = None,
) -> str:
if spaces is None:
spaces = cls.DEFAULT_TRACE_SPACES

lines = []
for line in dr_trace.get_trace():
src_line = disassembly[line[0] - 1]
lines.append(
"{}{}\t{}".format(
src_line, " " * (spaces - len(src_line)), line[1]
)
)

return "\n".join(lines)

def app_trace(self, spaces: int = None) -> str:
if not hasattr(self, "app_call_trace"):
return ""

return self.trace(self.app_call_trace, self.disassembly, spaces=spaces)

def lsig_trace(self, spaces: int = None) -> str:
if not hasattr(self, "logic_sig_trace"):
return ""

return self.trace(
self.logic_sig_trace, self.disassembly, spaces=spaces
)


class DryrunTrace:
def __init__(self, trace: List[dict]):
self.trace = [DryrunTraceLine(line) for line in trace]

def get_trace(self) -> List[str]:
return [line.trace_line() for line in self.trace]


class DryrunTraceLine:
def __init__(self, tl):
self.line = tl["line"]
self.pc = tl["pc"]
self.stack = [DryrunStackValue(sv) for sv in tl["stack"]]

def trace_line(self):
return (self.line, [str(sv) for sv in self.stack])


class DryrunStackValue:
def __init__(self, v):
self.type = v["type"]
self.bytes = v["bytes"]
self.int = v["uint"]

def __str__(self) -> str:
if self.type == 1:
return str(self.bytes)
return str(self.int)