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

Update tezos-utils #351

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Update tezos-utils #351

wants to merge 3 commits into from

Conversation

sskeirik
Copy link
Collaborator

@sskeirik sskeirik commented May 1, 2022

This update solves three problems with tezos-utils which makes it more usable for more kinds of programs:

  1. the python dependencies are properly listed
  2. view functions generated by the LIGO compiler are ignored when deciding if something has the shape of a michelson contract
  3. an argument was added to truncate type literals which appeared in instructions that were too long to improve readability of rendered DOT graphs

@tothtamas28 I have currently assigned this to you since you know python well and are working on a Michelson-related audit with me. If you aren't able to review this or if you have questions, let me know.

@sskeirik sskeirik requested a review from tothtamas28 May 1, 2022 22:00
@sskeirik sskeirik force-pushed the update_tezos_utils branch from 08c0f42 to 80940ad Compare May 1, 2022 22:01
@sskeirik sskeirik force-pushed the update_tezos_utils branch from 80940ad to f711cba Compare May 1, 2022 22:02
@@ -23,6 +23,11 @@ On Ubuntu Linux derivatives, the system dependencies include:
For other distributions, you will need to find the appropriate packages.

The Python dependencies are all available available via PyPI packages and can be installed via `pip`:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The Python dependencies are all available available via PyPI packages and can be installed via `pip`:
The Python dependencies are all available via PyPI packages and can be installed via `pip`:

@@ -215,9 +234,9 @@ def is_micheline(mcode):
else:
return False

def micheline_to_dot(mcode, skipRevert = False):
def micheline_to_dot(mcode, skipRevert = False, type_length=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def micheline_to_dot(mcode, skipRevert = False, type_length=None):
def micheline_to_dot(mcode, skipRevert=False, type_length=None):

# check that section names are correct
sections = dict()
for prim in mcode:
name,val = prim['prim'], prim['args']
# skip view functions
if name == 'view': continue
# if we encounter an unexpected name, stop
if name not in ['parameter', 'storage', 'code'] or name in sections.keys():
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if name not in ['parameter', 'storage', 'code'] or name in sections.keys():
if name not in {'parameter', 'storage', 'code'} or name in sections:

Comment on lines +24 to +26
def truncate(s, l):
if len(s) <= l: return s
else: return s[:l] + "..."
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def truncate(s, l):
if len(s) <= l: return s
else: return s[:l] + "..."
def truncate(s, length):
if len(s) <= length:
return s
else:
return s[:length] + "..."

class BlockType(Enum):
STD = 1
SELFBREAK = 2
BREAK = 3
JOIN = 4

class Block:
def __init__(self, prim_seq, depth=0):
def __init__(self, prim_seq, depth=0, type_length=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider making the optional arguments keyword-only:

Suggested change
def __init__(self, prim_seq, depth=0, type_length=None):
def __init__(self, prim_seq, *, depth=0, type_length=None):

@@ -135,7 +140,7 @@ class Block:

elif name in HIDDEN_BLOCK_INSTRS:
self.append(prim)
hidden_block = Block({'prim' : '...' }, depth=self.depth)
hidden_block = Block({'prim' : '...' }, depth=self.depth, type_length=self.type_length)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
hidden_block = Block({'prim' : '...' }, depth=self.depth, type_length=self.type_length)
hidden_block = Block({'prim' : '...'}, depth=self.depth, type_length=self.type_length)

@@ -200,6 +218,7 @@ def get_code_section(mcode):
code = sections['code'][0]
logging.debug(f"Get code section: {code}")
return code
logging.debug("The code was not a JSON-encoded Micheline representation of a contract; fallback")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logging.debug("The code was not a JSON-encoded Micheline representation of a contract; fallback")
logging.debug("The code is not a JSON-encoded Micheline representation of a contract; fallback")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants