This repository has been archived by the owner on Aug 8, 2018. It is now read-only.
forked from heikoheiko/pyethapp
-
Notifications
You must be signed in to change notification settings - Fork 605
Fix eth gas limit missing #153
Open
RomanZacharia
wants to merge
12
commits into
ethereum:develop
Choose a base branch
from
RomanZacharia:fix_eth_gasLimit_missing
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fa72dff
fixed #99, includes tests
4gn3s cb9702f
Added the tests for the rpc client
RomanZacharia 74e9cc4
Updated the rpc_client tests
RomanZacharia 5009882
Minor fix
RomanZacharia 0795086
Revert "Minor fix"
RomanZacharia 339de86
Added path checks
RomanZacharia 297d752
Added executable check
RomanZacharia 9124a41
Updated the setup mode to install so that the pyethapp executable can…
RomanZacharia f28d867
Merge branch 'fix_eth_gasLimit_missing' of https://github.com/RomanZa…
RomanZacharia 82a6274
Revert "Updated the setup mode to install so that the pyethapp execut…
RomanZacharia e2a028a
Added the "setup.py install" command so that the pyethapp executable …
RomanZacharia 5616f1f
Cleanup
RomanZacharia 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 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 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 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 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 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,74 @@ | ||
from pyethapp.jsonrpc import quantity_decoder | ||
from pyethapp.rpc_client import JSONRPCClient | ||
import pytest | ||
from subprocess import Popen | ||
import time | ||
from pyethapp.jsonrpc import address_encoder | ||
from ethereum import utils | ||
|
||
def executable_installed(program): | ||
import os | ||
|
||
def is_exe(fpath): | ||
return os.path.isfile(fpath) and os.access(fpath, os.X_OK) | ||
|
||
for path in os.environ["PATH"].split(os.pathsep): | ||
path = path.strip('"') | ||
exe_file = os.path.join(path, program) | ||
if is_exe(exe_file): | ||
return exe_file | ||
return None | ||
|
||
def prepare_rpc_tests(tmpdir): | ||
rpc_tests = tmpdir.mkdir('testdata') | ||
|
||
assert Popen(['git', 'clone', 'https://github.com/ethereum/rpc-tests'], cwd=str(rpc_tests)).wait() == 0 | ||
tests_dir = rpc_tests.join('rpc-tests') | ||
import os.path | ||
fpath = str(tests_dir.join('lib/config.js')) | ||
assert os.path.isfile(fpath) | ||
assert Popen(['git', 'submodule', 'update', '--init', '--recursive'], cwd=str(tests_dir)).wait() == 0 | ||
assert os.path.isfile(str(tests_dir.join('lib/tests/BlockchainTests/bcRPC_API_Test.json')).decode('unicode-escape')) | ||
return tests_dir | ||
|
||
|
||
@pytest.fixture() | ||
def test_setup(request, tmpdir): | ||
""" | ||
start the test_app with `subprocess.Popen`, so we can kill it properly. | ||
:param request: | ||
:param tmpdir: | ||
:return: | ||
""" | ||
rpc_tests_dir = prepare_rpc_tests(tmpdir) | ||
|
||
test_data = rpc_tests_dir.join('lib/tests/BlockchainTests/bcRPC_API_Test.json') | ||
assert executable_installed('pyethapp') | ||
test_app = Popen([ | ||
'pyethapp', | ||
'-d', str(tmpdir), | ||
'-l:info,eth.chainservice:debug,jsonrpc:debug', | ||
'-c jsonrpc.listen_port=8081', | ||
'-c p2p.max_peers=0', | ||
'-c p2p.min_peers=0', | ||
'blocktest', | ||
str(test_data), | ||
'RPC_API_Test' | ||
]) | ||
def fin(): | ||
test_app.terminate() | ||
request.addfinalizer(fin) | ||
|
||
time.sleep(60) | ||
return (test_app, rpc_tests_dir) | ||
|
||
|
||
def test_find_block(): | ||
restore = JSONRPCClient.call | ||
JSONRPCClient.call = lambda self, cmd, num, flag: num | ||
client = JSONRPCClient() | ||
client.find_block(lambda x: x == '0x5') | ||
JSONRPCClient.call = restore | ||
|
||
|
||
def test_default_host(): | ||
|
@@ -18,3 +83,68 @@ def test_set_host(): | |
client = JSONRPCClient(host) | ||
assert client.transport.endpoint == 'http://{}:{}'.format(host, client.port) | ||
assert client.transport.endpoint != 'http://{}:{}'.format(default_host, client.port) | ||
|
||
# The fixture takes much time to initialize, so the tests are grouped into one method | ||
def test_client(test_setup): | ||
(test_app, rpc_tests_dir) = test_setup | ||
client = JSONRPCClient(port=8081) | ||
|
||
genesis_block_info = client.call('eth_getBlockByNumber', 'earliest', False) | ||
genesis_gas_limit = quantity_decoder(genesis_block_info['gasLimit']) | ||
assert client.default_tx_gas == (genesis_gas_limit - 1) | ||
|
||
sender = client.sender | ||
assert sender == '\xde\x0b)Vi\xa9\xfd\x93\xd5\xf2\x8d\x9e\xc8^@\xf4\xcbi{\xae' | ||
|
||
coinbase = client.coinbase | ||
assert coinbase == '\xde\x0b)Vi\xa9\xfd\x93\xd5\xf2\x8d\x9e\xc8^@\xf4\xcbi{\xae' | ||
|
||
blocknumber = client.blocknumber() | ||
assert blocknumber == 32 | ||
|
||
nonce = client.nonce(sender) | ||
assert nonce == 0 | ||
|
||
balance1 = client.balance(sender) | ||
assert balance1 == 5156250000000000000 | ||
|
||
gaslimit = client.gaslimit() | ||
assert gaslimit == 3141592 | ||
|
||
lastgasprice = client.lastgasprice() | ||
assert lastgasprice == 1 | ||
|
||
balance2 = client.balance('\xff' * 20) | ||
assert balance2 == 0 | ||
fid = client.new_filter('pending', 'pending') | ||
|
||
# The following tests require an account with a positive balance | ||
# accs = client.call('eth_accounts') | ||
# sender = accs[0] | ||
# res_est = client.eth_sendTransaction(nonce, sender, address_encoder('\xff' * 20), 1) | ||
# assert 'result' in res_est.keys() | ||
|
||
# res_call = client.eth_call(utils.encode_hex(a0), '\xff' * 20, 0) | ||
# assert 'result' in res_call.keys() | ||
|
||
# res_st = client.send_transaction(sender, address_encoder('\xff' * 20), 1) | ||
# assert 'result' in res_st.keys() | ||
|
||
# solidity_code = "contract test { function multiply(uint a) returns(uint d) { return a * 7; } }" | ||
|
||
# import ethereum._solidity | ||
# s = ethereum._solidity.get_solidity() | ||
# if s is None: | ||
# pytest.xfail("solidity not installed, not tested") | ||
# else: | ||
# abi = s.mk_full_signature(solidity_code) | ||
# abic = client.new_abi_contract(abi, sender) | ||
# mult = abic.multiply(11111111) | ||
# assert mult == 77777777 | ||
|
||
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. can this be updated or removed? 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 Yes, it can be updated. A while ago you sent me the authorization hash for validating transactions with non-zero transfers, but it remained on slack unlike me. Could you please remind what's been there? You can send me the whole chat log so you don't have to search for it, thank you |
||
|
||
def test_default_tx_gas_assigned(): | ||
default_gas = 12345 | ||
client = JSONRPCClient(default_tx_gas=default_gas) | ||
assert client.default_tx_gas == default_gas | ||
|
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.
is this necessary for this issue?
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.
This was added to invoke the Popen(['pyethapp']). Otherwise it won't find the executable.
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.
Well the transport can be mocked int the same way as in #168 so this will not be necessary.