Skip to content

Commit

Permalink
upgrade parity fixture + handle parity revert
Browse files Browse the repository at this point in the history
  • Loading branch information
wolovim committed Oct 23, 2020
1 parent e3a70e9 commit 7772beb
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 164 deletions.
26 changes: 14 additions & 12 deletions tests/integration/generate_fixtures/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,26 @@
"homesteadBlock": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
# "petersburgBlock": 0,
# "istanbulBlock": 0,
"eip150Block": 0,
"eip155Block": 0,
"eip158Block": 0,
"eip160Block": 0,
},
"nonce": "0x0000000000000042",
"alloc": {
COINBASE: {
"balance": "1000000000000000000000000000"
},
UNLOCKABLE_ACCOUNT: {
"balance": "1000000000000000000000000000"
},
RAW_TXN_ACCOUNT: {
"balance": "1000000000000000000000000000"
}
COINBASE: {"balance": "1000000000000000000000000000"},
UNLOCKABLE_ACCOUNT: {"balance": "1000000000000000000000000000"},
RAW_TXN_ACCOUNT: {"balance": "1000000000000000000000000000"},
"0000000000000000000000000000000000000001": {"balance": "1"},
"0000000000000000000000000000000000000002": {"balance": "1"},
"0000000000000000000000000000000000000003": {"balance": "1"},
"0000000000000000000000000000000000000004": {"balance": "1"},
"0000000000000000000000000000000000000005": {"balance": "1"},
"0000000000000000000000000000000000000006": {"balance": "1"},
# "0000000000000000000000000000000000000007": {"balance": "1"},
# "0000000000000000000000000000000000000008": {"balance": "1"},
# "0000000000000000000000000000000000000009": {"balance": "1"},
},
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
Expand Down
121 changes: 22 additions & 99 deletions tests/integration/generate_fixtures/go_ethereum.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
import os
import pprint
import shutil
import signal
import socket
import subprocess
import sys
import tempfile
import time

from eth_utils.curried import (
apply_formatter_if,
is_bytes,
is_checksum_address,
is_dict,
is_same_address,
remove_0x_prefix,
Expand All @@ -26,6 +22,7 @@
valmap,
)

import common
from tests.utils import (
get_open_port,
)
Expand Down Expand Up @@ -89,86 +86,12 @@
}


def ensure_path_exists(dir_path):
"""
Make sure that a path exists
"""
if not os.path.exists(dir_path):
os.makedirs(dir_path)
return True
return False


@contextlib.contextmanager
def tempdir():
dir_path = tempfile.mkdtemp()
try:
yield dir_path
finally:
shutil.rmtree(dir_path)


def get_geth_binary():
from geth.install import (
get_executable_path,
install_geth,
)

if 'GETH_BINARY' in os.environ:
return os.environ['GETH_BINARY']
elif 'GETH_VERSION' in os.environ:
geth_version = os.environ['GETH_VERSION']
_geth_binary = get_executable_path(geth_version)
if not os.path.exists(_geth_binary):
install_geth(geth_version)
assert os.path.exists(_geth_binary)
return _geth_binary
else:
return 'geth'


def wait_for_popen(proc, timeout):
start = time.time()
while time.time() < start + timeout:
if proc.poll() is None:
time.sleep(0.01)
else:
break


def kill_proc_gracefully(proc):
if proc.poll() is None:
proc.send_signal(signal.SIGINT)
wait_for_popen(proc, 13)

if proc.poll() is None:
proc.terminate()
wait_for_popen(proc, 5)

if proc.poll() is None:
proc.kill()
wait_for_popen(proc, 2)


def wait_for_socket(ipc_path, timeout=30):
start = time.time()
while time.time() < start + timeout:
try:
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect(ipc_path)
sock.settimeout(timeout)
except (FileNotFoundError, socket.error):
time.sleep(0.01)
else:
break


@contextlib.contextmanager
def graceful_kill_on_exit(proc):
try:
yield proc
finally:
kill_proc_gracefully(proc)
common.kill_proc_gracefully(proc)


@contextlib.contextmanager
Expand Down Expand Up @@ -235,22 +158,22 @@ def write_config_json(config, datadir):

def generate_go_ethereum_fixture(destination_dir):
with contextlib.ExitStack() as stack:
datadir = stack.enter_context(tempdir())
datadir = stack.enter_context(common.tempdir())

keystore_dir = os.path.join(datadir, 'keystore')
ensure_path_exists(keystore_dir)
common.ensure_path_exists(keystore_dir)
keyfile_path = os.path.join(keystore_dir, KEYFILE_FILENAME)
with open(keyfile_path, 'w') as keyfile:
keyfile.write(KEYFILE_DATA)
genesis_file_path = os.path.join(datadir, 'genesis.json')
with open(genesis_file_path, 'w') as genesis_file:
genesis_file.write(json.dumps(GENESIS_DATA))

geth_ipc_path_dir = stack.enter_context(tempdir())
geth_ipc_path_dir = stack.enter_context(common.tempdir())
geth_ipc_path = os.path.join(geth_ipc_path_dir, 'geth.ipc')

geth_port = get_open_port()
geth_binary = get_geth_binary()
geth_binary = common.get_geth_binary()

with get_geth_process(
geth_binary=geth_binary,
Expand All @@ -259,7 +182,7 @@ def generate_go_ethereum_fixture(destination_dir):
geth_ipc_path=geth_ipc_path,
geth_port=geth_port):

wait_for_socket(geth_ipc_path)
common.wait_for_socket(geth_ipc_path)
web3 = Web3(Web3.IPCProvider(geth_ipc_path))
chain_data = setup_chain_state(web3)
# close geth by exiting context
Expand All @@ -275,7 +198,7 @@ def generate_go_ethereum_fixture(destination_dir):
geth_ipc_path=geth_ipc_path,
geth_port=geth_port):

wait_for_socket(geth_ipc_path)
common.wait_for_socket(geth_ipc_path)
web3 = Web3(Web3.IPCProvider(geth_ipc_path))
verify_chain_state(web3, chain_data)

Expand All @@ -299,7 +222,7 @@ def verify_chain_state(web3, chain_data):
def mine_transaction_hash(web3, txn_hash):
web3.geth.miner.start(1)
try:
return web3.eth.waitForTransactionReceipt(txn_hash, timeout=60)
return web3.eth.waitForTransactionReceipt(txn_hash, timeout=180)
finally:
web3.geth.miner.stop()

Expand All @@ -309,7 +232,7 @@ def mine_block(web3):

start_time = time.time()
web3.geth.miner.start(1)
while time.time() < start_time + 60:
while time.time() < start_time + 120:
block_number = web3.eth.blockNumber
if block_number > origin_block_number:
web3.geth.miner.stop()
Expand All @@ -320,16 +243,16 @@ def mine_block(web3):
raise ValueError("No block mined during wait period")


def deploy_contract(web3, name, factory):
web3.geth.personal.unlock_account(web3.eth.coinbase, KEYFILE_PW)
deploy_txn_hash = factory.constructor().transact({'from': web3.eth.coinbase})
print('{0}_CONTRACT_DEPLOY_HASH: '.format(name.upper()), deploy_txn_hash)
deploy_receipt = mine_transaction_hash(web3, deploy_txn_hash)
print('{0}_CONTRACT_DEPLOY_TRANSACTION_MINED'.format(name.upper()))
contract_address = deploy_receipt['contractAddress']
assert is_checksum_address(contract_address)
print('{0}_CONTRACT_ADDRESS:'.format(name.upper()), contract_address)
return deploy_receipt
# def deploy_contract(web3, name, factory):
# web3.geth.personal.unlock_account(web3.eth.coinbase, KEYFILE_PW)
# deploy_txn_hash = factory.constructor().transact({'from': web3.eth.coinbase})
# print('{0}_CONTRACT_DEPLOY_HASH: '.format(name.upper()), deploy_txn_hash)
# deploy_receipt = mine_transaction_hash(web3, deploy_txn_hash)
# print('{0}_CONTRACT_DEPLOY_TRANSACTION_MINED'.format(name.upper()))
# contract_address = deploy_receipt['contractAddress']
# assert is_checksum_address(contract_address)
# print('{0}_CONTRACT_ADDRESS:'.format(name.upper()), contract_address)
# return deploy_receipt


def setup_chain_state(web3):
Expand All @@ -344,7 +267,7 @@ def setup_chain_state(web3):
abi=MATH_ABI,
bytecode=MATH_BYTECODE,
)
math_deploy_receipt = deploy_contract(web3, 'math', math_contract_factory)
math_deploy_receipt = common.deploy_contract(web3, 'math', math_contract_factory)
assert is_dict(math_deploy_receipt)

#
Expand All @@ -354,7 +277,7 @@ def setup_chain_state(web3):
abi=CONTRACT_EMITTER_ABI,
bytecode=CONTRACT_EMITTER_CODE,
)
emitter_deploy_receipt = deploy_contract(web3, 'emitter', emitter_contract_factory)
emitter_deploy_receipt = common.deploy_contract(web3, 'emitter', emitter_contract_factory)
emitter_contract = emitter_contract_factory(emitter_deploy_receipt['contractAddress'])

txn_hash_with_log = emitter_contract.functions.logDouble(
Expand Down
82 changes: 66 additions & 16 deletions tests/integration/generate_fixtures/parity.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,45 @@
"minimumDifficulty": "0x020000",
"difficultyBoundDivisor": "0x0800",
"durationLimit": "0x0d",
"blockReward": "0x4563918244F40000",
# "blockReward": "0x4563918244F40000", # homestead
# "blockReward": "0x29a2241af62c0000", # byzantium
"blockReward": "0x1bc16d674ec80000", # constantinople
"difficultyBombDelays": {
# "0x0": "0x2dc6c0", # byzantium
"0x0": "0x1e8480",
},
"homesteadTransition": 0,
"eip100bTransition": 0,
}
}
},
"params": {
"gasLimitBoundDivisor": "0x0400",
"registrar": "0x81a4b044831c4f12ba601adb9274516939e9b8a2",
"eip140Transition": 0,
# Tangerine Whistle
"eip150Transition": 0,
"eip155Transition": 0,
# Spurious Dragon
"eip160Transition": 0,
"eip161abcTransition": 0,
"eip161dTransition": 0,
"eip155Transition": 0,
# Byzantium
"eip140Transition": 0,
"eip211Transition": 0,
"eip214Transition": 0,
"eip658Transition": 0,
# Constantinople
"eip145Transition": 0,
"eip1014Transition": 0,
"eip1052Transition": 0,
"eip1283Transition": 0,
# Petersburg
# "eip1283DisableTransition": 0,
# Istanbul
# "eip1283ReenableTransition": 0,
# "eip1344Transition": 0,
# "eip1884Transition": 0,
# "eip2028Transition": 0,
"accountStartNonce": "0x0",
"maximumExtraDataSize": "0x20",
"minGasLimit": "0x1388",
Expand All @@ -67,28 +89,55 @@
"gasLimit": "0x1000000"
},
"accounts": {
common.COINBASE: {
"balance": "1000000000000000000000000000",
"nonce": "0",
common.COINBASE: {"balance": "1000000000000000000000000000", "nonce": "0"},
common.UNLOCKABLE_ACCOUNT: {"balance": "1000000000000000000000000000", "nonce": "0"},
common.RAW_TXN_ACCOUNT: {"balance": "1000000000000000000000000000", "nonce": "0"},
"0000000000000000000000000000000000000001": {
"balance": "0x1",
"builtin": {
"name": "ecrecover", "pricing": {"linear": {"base": 3000, "word": 0}}
"name": "ecrecover",
"pricing": {"linear": {"base": 3000, "word": 0}}
}
},
common.UNLOCKABLE_ACCOUNT: {
"balance": "1000000000000000000000000000",
"nonce": "0",
"0000000000000000000000000000000000000002": {
"balance": "0x1",
"builtin": {
"name": "sha256", "pricing": {"linear": {"base": 60, "word": 12}}
"name": "sha256",
"pricing": {"linear": {"base": 60, "word": 12}}
}
},
common.RAW_TXN_ACCOUNT: {
"balance": "1000000000000000000000000000",
"nonce": "0",
"0000000000000000000000000000000000000003": {
"balance": "0x1",
"builtin": {
"name": "ripemd160",
"pricing": {"linear": {"base": 600, "word": 120}}
}
}
},
"0000000000000000000000000000000000000004": {
"balance": "0x1",
"builtin": {
"name": "identity",
"pricing": {"linear": {"base": 15, "word": 3}}
}
},
"0000000000000000000000000000000000000005": {
"balance": "0x1",
"builtin": {
"name": "modexp",
"pricing": {"modexp": {"divisor": 20}}
}
},
"0000000000000000000000000000000000000006": {
"balance": "0x1",
"builtin": {
"name": "alt_bn128_add",
"activate_at": "0x7530",
"pricing": {"linear": {"base": 500, "word": 0}}
}
},
# "0000000000000000000000000000000000000007": {},
# "0000000000000000000000000000000000000008": {},
# "0000000000000000000000000000000000000009": {},
}
}

Expand All @@ -98,7 +147,8 @@ def get_parity_binary():
If generating a fixture from a local binary, update this value to that bin, e.g.,
return '/Users/xzy/Downloads/openethereum-2.5.13/target/release/parity'
"""
return 'parity'
return '/Users/mg/Downloads/openethereum-2.5.13/target/release/parity'
# return 'parity'


@contextlib.contextmanager
Expand Down
Binary file modified tests/integration/parity-2.5.13-fixture.zip
Binary file not shown.
Loading

0 comments on commit 7772beb

Please sign in to comment.