This repository was archived by the owner on May 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 724
Piper/fix block tests invalid state #369
Merged
konradkonrad
merged 5 commits into
ethereum:develop
from
pipermerriam:piper/fix-block-tests-invalid-state
Jun 29, 2016
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,9 +1,9 @@ | ||
| import sys | ||
| import logging | ||
| import json | ||
| import textwrap | ||
| from json.encoder import JSONEncoder | ||
| from logging import StreamHandler, Formatter, FileHandler | ||
| from ethereum.utils import bcolors, isnumeric | ||
|
|
||
|
|
||
| DEFAULT_LOGLEVEL = 'INFO' | ||
|
|
@@ -20,6 +20,33 @@ | |
| log_listeners = [] | ||
|
|
||
|
|
||
| if sys.version_info.major == 2: | ||
| integer_types = (int, long) | ||
| number_types = (int, long, float, complex) | ||
| else: | ||
| integer_types = (int,) | ||
| number_types = (int, float, complex) | ||
|
|
||
|
|
||
| def is_integer(value): | ||
| return isinstance(value, integer_types) | ||
|
|
||
|
|
||
| def is_number(value): | ||
| return isinstance(value, number_types) | ||
|
|
||
|
|
||
| class bcolors: | ||
| HEADER = '\033[95m' | ||
| OKBLUE = '\033[94m' | ||
| OKGREEN = '\033[92m' | ||
| WARNING = '\033[91m' | ||
| FAIL = '\033[91m' | ||
| ENDC = '\033[0m' | ||
| BOLD = '\033[1m' | ||
| UNDERLINE = '\033[4m' | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @konradkonrad it lives here now
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah alright then, I missed that! |
||
|
|
||
|
|
||
| def _inject_into_logger(name, code, namespace=None): | ||
| # This is a hack to fool the logging module into reporting correct source files. | ||
| # It determines the actual source of a logging call by inspecting the stack frame's | ||
|
|
@@ -190,7 +217,7 @@ def format_message(self, msg, kwargs, highlight, level): | |
| msg = json.dumps(message, cls=_LogJSONEncoder) | ||
| except UnicodeDecodeError: | ||
| message.update({ | ||
| k: v if isnumeric(v) or isinstance(v, (float, complex)) else repr(v) | ||
| k: v if is_number(v) else repr(v) | ||
| for k, v in kwargs.items() | ||
| }) | ||
| msg = json.dumps(message, cls=_LogJSONEncoder) | ||
|
|
@@ -260,7 +287,7 @@ def _stringify_dict_keys(input_): | |
| res = {} | ||
| for k, v in input_.items(): | ||
| v = _stringify_dict_keys(v) | ||
| if not isinstance(k, (int, long, bool, None.__class__)): | ||
| if not is_integer(k) and not isinstance(k, (bool, None.__class__)): | ||
| k = str(k) | ||
| res[k] = v | ||
| elif isinstance(input_, (list, tuple)): | ||
|
|
||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -62,8 +62,6 @@ def to_string_for_regexp(value): | |
| def bytearray_to_bytestr(value): | ||
| return bytes(value) | ||
|
|
||
| isnumeric = is_numeric | ||
|
|
||
|
|
||
| def mk_contract_address(sender, nonce): | ||
| return sha3(rlp.encode([normalize_address(sender), nonce]))[12:] | ||
|
|
@@ -119,7 +117,7 @@ def sha3(seed): | |
| sha3_count[0] += 1 | ||
| return sha3_256(to_string(seed)) | ||
|
|
||
| assert encode_hex(sha3('')) == b'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470' | ||
| assert encode_hex(sha3(b'')) == b'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470' | ||
|
|
||
|
|
||
| def privtoaddr(x, extended=False): | ||
|
|
@@ -145,11 +143,11 @@ def check_and_strip_checksum(x): | |
|
|
||
|
|
||
| def normalize_address(x, allow_blank=False): | ||
| if isinstance(x, (int, long)): | ||
| if is_numeric(x): | ||
| return int_to_addr(x) | ||
| if allow_blank and (x == '' or x == b''): | ||
| if allow_blank and x in {'', b''}: | ||
| return b'' | ||
| if len(x) in (42, 50) and x[:2] == '0x': | ||
| if len(x) in (42, 50) and x[:2] in {'0x', b'0x'}: | ||
| x = x[2:] | ||
| if len(x) in (40, 48): | ||
| x = decode_hex(x) | ||
|
|
@@ -173,7 +171,7 @@ def zunpad(x): | |
|
|
||
|
|
||
| def int_to_addr(x): | ||
| o = [''] * 20 | ||
| o = [b''] * 20 | ||
| for i in range(20): | ||
| o[19 - i] = ascii_chr(x & 0xff) | ||
| x >>= 8 | ||
|
|
@@ -428,17 +426,6 @@ def __init__(self): | |
| trie_root = Binary.fixed_length(32, allow_empty=True) | ||
|
|
||
|
|
||
| class bcolors: | ||
| HEADER = '\033[95m' | ||
| OKBLUE = '\033[94m' | ||
| OKGREEN = '\033[92m' | ||
| WARNING = '\033[91m' | ||
| FAIL = '\033[91m' | ||
| ENDC = '\033[0m' | ||
| BOLD = '\033[1m' | ||
| UNDERLINE = '\033[4m' | ||
|
|
||
|
|
||
| def DEBUG(msg, *args, **kwargs): | ||
| from ethereum import slogging | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did you remove this?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is only used by the |
||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@konradkonrad removing these two imports makes this module independent from the rest of the package.