Skip to content

Commit

Permalink
Improved differential test logging (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
ESultanik committed Nov 1, 2018
1 parent 17ba67b commit 2626d92
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions etheno/differentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class TestResult(Enum):

class DifferentialTester(EthenoPlugin):
def __init__(self):
self._transactions_by_hash = {}
self._unprocessed_transactions = set()
self.tests = {}
self._printed_summary = False
Expand Down Expand Up @@ -60,6 +61,7 @@ def after_post(self, data, client_results):
if method == 'eth_sendTransaction' or method == 'eth_sendRawTransaction':
if not isinstance(master_result, JSONRPCError) and 'result' in master_result and master_result['result']:
self._unprocessed_transactions.add(master_result['result'])
self._transactions_by_hash[master_result['result']] = data
elif method == 'eth_getTransactionReceipt':
if master_result and 'result' in master_result and master_result['result']:
# mark that we have processed the receipt for this transaction:
Expand All @@ -76,7 +78,7 @@ def after_post(self, data, client_results):
except Exception:
pass
if not created:
test = DifferentialTest(self, 'CONTRACT_CREATION', TestResult.FAILED, "the master client created a contract for transaction %s, but %s did not" % (data['params'][0], client))
test = DifferentialTest(self, 'CONTRACT_CREATION', TestResult.FAILED, f"{self.etheno.master_client} created a contract for transaction {data['params'][0]}, but {client} did not")
self.add_test_result(test)
self.logger.error(test.message)
else:
Expand All @@ -91,12 +93,23 @@ def after_post(self, data, client_results):
except Exception:
pass
if gas_used != master_gas:
test = DifferentialTest(self, 'GAS_USAGE', TestResult.FAILED, "transaction %s used 0x%x gas in the master client but 0x%x gas in %s!" % (data['params'][0], master_gas, gas_used, client))
test = DifferentialTest(self, 'GAS_USAGE', TestResult.FAILED, f"""Transaction {data['params'][0]} used:
0x{hex(master_gas)} gas in {self.etheno.master_client} but
0x{hex(gas_used)} gas in {client}
while mining this transaction:
{self._transactions_by_hash.get(data['params'][0], 'UNKNOWN TRANSACTION')}""")
self.add_test_result(test)
self.logger.error(test.message)
else:
self.add_test_result(DifferentialTest(self, 'GAS_USAGE', TestResult.PASSED, "client %s transaction %s used 0x%x gas" % (client, data['params'][0], gas_used)))

# we have processed this transaction, so no need to keep its original arguments around:
if data['params'][0] in self._transactions_by_hash:
del self._transactions_by_hash[data['params'][0]]

def finalize(self):
unprocessed = self._unprocessed_transactions
self._unprocessed_transactions = set()
Expand Down

0 comments on commit 2626d92

Please sign in to comment.