Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
*.py[co]
*.bin
.cache/
.tern-port
.tox/
ethjsonrpc.egg-info/
geth.log
**/geth
**/history
**/keystore
5 changes: 0 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ Implemented JSON-RPC methods
* eth_getTransactionReceipt
* eth_getUncleByBlockHashAndIndex
* eth_getUncleByBlockNumberAndIndex
* eth_getCompilers
* eth_compileSolidity
* eth_compileLLL
* eth_compileSerpent
Expand All @@ -191,10 +190,6 @@ Implemented JSON-RPC methods
* eth_getWork
* eth_submitWork
* eth_submitHashrate
* db_putString
* db_getString
* db_putHex
* db_getHex
* shh_version
* shh_post
* shh_newIdentity
Expand Down
80 changes: 8 additions & 72 deletions ethjsonrpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ def eth_getBalance(self, address=None, block=BLOCK_TAG_LATEST):
'''
address = address or self.eth_coinbase()
block = validate_block(block)
return hex_to_dec(self._call('eth_getBalance', [address, block]))
bal = self._call('eth_getBalance', [address, block])
if bal and bal != '<nil>':
return hex_to_dec(bal)
return 0

def eth_getStorageAt(self, address=None, position=0, block=BLOCK_TAG_LATEST):
'''
Expand All @@ -264,7 +267,10 @@ def eth_getTransactionCount(self, address, block=BLOCK_TAG_LATEST):
TESTED
'''
block = validate_block(block)
return hex_to_dec(self._call('eth_getTransactionCount', [address, block]))
hex = self._call('eth_getTransactionCount', [address, block])
if hex != None:
return hex_to_dec(hex)
return 0

def eth_getBlockTransactionCountByHash(self, block_hash):
'''
Expand Down Expand Up @@ -466,38 +472,6 @@ def eth_getUncleByBlockNumberAndIndex(self, block=BLOCK_TAG_LATEST, index=0):
block = validate_block(block)
return self._call('eth_getUncleByBlockNumberAndIndex', [block, hex(index)])

def eth_getCompilers(self):
'''
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getcompilers

TESTED
'''
return self._call('eth_getCompilers')

def eth_compileSolidity(self, code):
'''
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_compilesolidity

TESTED
'''
return self._call('eth_compileSolidity', [code])

def eth_compileLLL(self, code):
'''
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_compilelll

N/A
'''
return self._call('eth_compileLLL', [code])

def eth_compileSerpent(self, code):
'''
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_compileserpent

N/A
'''
return self._call('eth_compileSerpent', [code])

def eth_newFilter(self, from_block=BLOCK_TAG_LATEST, to_block=BLOCK_TAG_LATEST, address=None, topics=None):
'''
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newfilter
Expand Down Expand Up @@ -584,44 +558,6 @@ def eth_submitHashrate(self, hash_rate, client_id):
'''
return self._call('eth_submitHashrate', [hex(hash_rate), client_id])

def db_putString(self, db_name, key, value):
'''
https://github.com/ethereum/wiki/wiki/JSON-RPC#db_putstring

TESTED
'''
warnings.warn('deprecated', DeprecationWarning)
return self._call('db_putString', [db_name, key, value])

def db_getString(self, db_name, key):
'''
https://github.com/ethereum/wiki/wiki/JSON-RPC#db_getstring

TESTED
'''
warnings.warn('deprecated', DeprecationWarning)
return self._call('db_getString', [db_name, key])

def db_putHex(self, db_name, key, value):
'''
https://github.com/ethereum/wiki/wiki/JSON-RPC#db_puthex

TESTED
'''
if not value.startswith('0x'):
value = '0x{}'.format(value)
warnings.warn('deprecated', DeprecationWarning)
return self._call('db_putHex', [db_name, key, value])

def db_getHex(self, db_name, key):
'''
https://github.com/ethereum/wiki/wiki/JSON-RPC#db_gethex

TESTED
'''
warnings.warn('deprecated', DeprecationWarning)
return self._call('db_getHex', [db_name, key])

def shh_version(self):
'''
https://github.com/ethereum/wiki/wiki/JSON-RPC#shh_version
Expand Down
4 changes: 3 additions & 1 deletion ethjsonrpc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ def hex_to_dec(x):
'''
Convert hex to decimal
'''
return int(x, 16)
if x:
return int(x, 16)
return 0


def clean_hex(d):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='ethjsonrpc',
version='0.3.0',
version='0.4.0',
description='Ethereum JSON-RPC client',
long_description=open('README.rst').read(),
author='ConsenSys',
Expand Down
140 changes: 0 additions & 140 deletions test.py

This file was deleted.

14 changes: 14 additions & 0 deletions tests/Example.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pragma solidity ^0.4.0;

contract Example {

string s;

function set_s(string new_s) {
s = new_s;
}

function get_s() returns (string) {
return s;
}
}
21 changes: 21 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
GETH := $(ROOT_DIR)/bin/geth.sh
SOURCES = $(wildcard *.sol)
BINS = $(SOURCES:.sol=.bin)

.PHONY: start
start:
@sh $(GETH) start

%.bin: %.sol
@solc --bin --output-dir ${ROOT_DIR} $<

compile: $(BINS)

.PHONY: test
test: start compile
@pytest -v -s && sh $(GETH) stop || sh $(GETH) stop

.PHONY: clean
clean:
@rm -f ${BINS} && sh $(GETH) clean
Empty file added tests/__init__.py
Empty file.
36 changes: 36 additions & 0 deletions tests/bin/geth.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
LOG="$DIR"/geth.log
PID="$DIR"/geth.pid
IPC="$DIR"/geth.ipc

start() {
if [ ! -e "$PID" ]; then
geth --dev --rpc --datadir "$DIR" "$IPC" 2> "$LOG" &
echo $! > "$PID" && \
until $(curl --output /dev/null --silent --head --fail http://127.0.0.1:8545); do
sleep 1
done
geth --datadir "$DIR" --exec 'loadScript("'"$DIR"'/setup.js"); console.log(miner)' attach "$IPC"
fi
}

stop() {
if [ -e "$PID" ]; then
kill $(cat "$PID")
rm "$PID"
fi
}

if [ "$1" = "start" ]; then
start
elif [ "$1" = "stop" ]; then
stop
elif [ "$1" = "clean" ]; then
rm -f "$PID" "$LOG" "$IPC"
fi


7 changes: 7 additions & 0 deletions tests/bin/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if( !web3.eth.accounts ) {
personal.newAccount( "" );
}
var main = web3.eth.accounts[0];
miner.setEtherbase( main );
miner.start();
personal.unlockAccount( main, "" );
Loading