Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
Add trace comparison scripts #327
Browse files Browse the repository at this point in the history
This adds some tools and documentation (!`README.md) for comparing
vm traces between geth and pyethapp/pyethereum.
  • Loading branch information
konradkonrad committed Apr 14, 2016
1 parent 5ab7008 commit 8b1eca5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
12 changes: 9 additions & 3 deletions debugging/README.md
Expand Up @@ -15,6 +15,12 @@ Create traces from tester file:

- with pyethapp

pyethapp --log-json -d /tmp/bt -l:trace blocktest \
tests/BlockchainTests/bcRPC_API_Test.json RPC_API_Test 2>&1 | grep "eth.vm.op"|while IFS=$'\n' read -r line; \
do python -mjson.tool <<<"$line"; done
pyethapp --log-json -d /tmp/bt -l:trace blocktest tests/BlockchainTests/bcRPC_API_Test.json RPC_API_Test 2>&1 | grep "eth.vm.op" > pylog.jsons

Now we can diff traces between geth and pyethapp. In the `debugging` folder run:

./compare_logs.py <block_number>

# e.g.

./compare_logs.py 3 # to compare the traces of block 3
21 changes: 21 additions & 0 deletions debugging/compare_logs.py
@@ -0,0 +1,21 @@
#!/usr/bin/env python
import sys
import json
from deepdiff import DeepDiff
from pprint import pprint
from print_pylog import read_pythons
# from __future__ import print_function


def read_geth(fn):
with open(fn) as f:
slogs = json.load(f)['result']['structLogs']
return slogs


if __name__ == '__main__':
pyblocks = read_pythons()
blocknum = int(sys.argv[1]) if len(sys.argv) > 1 else 1

goblock = read_geth("trace-{}.json".format(blocknum))
pprint(DeepDiff(goblock, pyblocks[blocknum]))
25 changes: 25 additions & 0 deletions debugging/print_pylog.py
@@ -0,0 +1,25 @@
#!/usr/bin/env python
import sys
import json
from collections import defaultdict


def read_pythons(fn='pylog.jsons'):
with open(fn) as f:
lines = [json.loads(line) for line in f.readlines()]
blocks = defaultdict(list)
bnum = 0
for l in lines:
if l['pc'] == 0:
bnum += 1
# remove py slogging specifics:
l.pop('event')
l.pop('level')
blocks[bnum].append(l)
return blocks

if __name__ == '__main__':
pyblocks = read_pythons()
blocknum = int(sys.argv[1]) if len(sys.argv) > 1 else 1

print json.dumps(pyblocks[blocknum], indent=2)

0 comments on commit 8b1eca5

Please sign in to comment.