Skip to content

Commit

Permalink
dedupe constants, more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wolovim committed Oct 26, 2020
1 parent 12aae2e commit 3071442
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 71 deletions.
76 changes: 9 additions & 67 deletions tests/integration/generate_fixtures/go_ethereum.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
is_bytes,
is_dict,
is_same_address,
remove_0x_prefix,
to_hex,
to_text,
to_wei,
)
from eth_utils.toolz import (
merge,
Expand All @@ -41,50 +39,6 @@
REVERT_CONTRACT_BYTECODE,
)

COINBASE = '0xdc544d1aa88ff8bbd2f2aec754b1f1e99e1812fd'
COINBASE_PK = '0x58d23b55bc9cdce1f18c2500f40ff4ab7245df9a89505e9b1fa4851f623d241d'

KEYFILE_DATA = '{"address":"dc544d1aa88ff8bbd2f2aec754b1f1e99e1812fd","crypto":{"cipher":"aes-128-ctr","ciphertext":"52e06bc9397ea9fa2f0dae8de2b3e8116e92a2ecca9ad5ff0061d1c449704e98","cipherparams":{"iv":"aa5d0a5370ef65395c1a6607af857124"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"9fdf0764eb3645ffc184e166537f6fe70516bf0e34dc7311dea21f100f0c9263"},"mac":"4e0b51f42b865c15c485f4faefdd1f01a38637e5247f8c75ffe6a8c0eba856f6"},"id":"5a6124e0-10f1-4c1c-ae3e-d903eacb740a","version":3}' # noqa: E501

KEYFILE_PW = 'web3py-test'
KEYFILE_FILENAME = 'UTC--2017-08-24T19-42-47.517572178Z--dc544d1aa88ff8bbd2f2aec754b1f1e99e1812fd' # noqa: E501

RAW_TXN_ACCOUNT = '0x39EEed73fb1D3855E90Cbd42f348b3D7b340aAA6'

UNLOCKABLE_PRIVATE_KEY = '0x392f63a79b1ff8774845f3fa69de4a13800a59e7083f5187f1558f0797ad0f01'
UNLOCKABLE_ACCOUNT = '0x12efdc31b1a8fa1a1e756dfd8a1601055c971e13'
UNLOCKABLE_ACCOUNT_PW = KEYFILE_PW


GENESIS_DATA = {
"nonce": "0xdeadbeefdeadbeef",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", # noqa: E501
"extraData": "0x7765623370792d746573742d636861696e",
"gasLimit": "0x47d5cc",
"difficulty": "0x01",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", # noqa: E501
"coinbase": "0x3333333333333333333333333333333333333333",
"alloc": {
remove_0x_prefix(COINBASE): {
'balance': str(to_wei(1000000000, 'ether')),
},
remove_0x_prefix(RAW_TXN_ACCOUNT): {
'balance': str(to_wei(10, 'ether')),
},
remove_0x_prefix(UNLOCKABLE_ACCOUNT): {
'balance': str(to_wei(10, 'ether')),
},
},
"config": {
"chainId": 131277322940537, # the string 'web3py' as an integer
"homesteadBlock": 0,
"eip150Block": 0,
"eip155Block": 0,
"eip158Block": 0
},
}


@contextlib.contextmanager
def graceful_kill_on_exit(proc):
Expand Down Expand Up @@ -120,7 +74,7 @@ def get_geth_process(geth_binary,
'--gcmode', 'archive',
'--nodiscover',
'--port', geth_port,
'--etherbase', COINBASE[2:],
'--etherbase', common.COINBASE[2:],
)

popen_proc = subprocess.Popen(
Expand Down Expand Up @@ -162,12 +116,12 @@ def generate_go_ethereum_fixture(destination_dir):

keystore_dir = os.path.join(datadir, 'keystore')
common.ensure_path_exists(keystore_dir)
keyfile_path = os.path.join(keystore_dir, KEYFILE_FILENAME)
keyfile_path = os.path.join(keystore_dir, common.KEYFILE_FILENAME)
with open(keyfile_path, 'w') as keyfile:
keyfile.write(KEYFILE_DATA)
keyfile.write(common.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))
genesis_file.write(json.dumps(common.GENESIS_DATA))

geth_ipc_path_dir = stack.enter_context(common.tempdir())
geth_ipc_path = os.path.join(geth_ipc_path_dir, 'geth.ipc')
Expand Down Expand Up @@ -203,8 +157,8 @@ def generate_go_ethereum_fixture(destination_dir):
verify_chain_state(web3, chain_data)

static_data = {
'raw_txn_account': RAW_TXN_ACCOUNT,
'keyfile_pw': KEYFILE_PW,
'raw_txn_account': common.RAW_TXN_ACCOUNT,
'keyfile_pw': common.KEYFILE_PW,
}
config = merge(chain_data, static_data)
pprint.pprint(config)
Expand All @@ -222,7 +176,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=180)
return web3.eth.waitForTransactionReceipt(txn_hash, timeout=120)
finally:
web3.geth.miner.stop()

Expand All @@ -243,22 +197,10 @@ 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 setup_chain_state(web3):
coinbase = web3.eth.coinbase

assert is_same_address(coinbase, COINBASE)
assert is_same_address(coinbase, common.COINBASE)

#
# Math Contract
Expand Down Expand Up @@ -333,7 +275,7 @@ def setup_chain_state(web3):
#
# Block with Transaction
#
web3.geth.personal.unlock_account(coinbase, KEYFILE_PW)
web3.geth.personal.unlock_account(coinbase, common.KEYFILE_PW)
web3.geth.miner.start(1)
mined_txn_hash = web3.eth.sendTransaction({
'from': coinbase,
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/generate_fixtures/parity.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ 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 '/Users/mg/Downloads/openethereum-2.5.13/target/release/parity'
# return 'parity'
return 'parity'


@contextlib.contextmanager
Expand Down
Binary file modified tests/integration/geth-1.9.19-fixture.zip
Binary file not shown.
3 changes: 1 addition & 2 deletions tests/integration/go_ethereum/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

KEYFILE_PW = 'web3py-test'

# GETH_1919_ZIP = 'geth-1.9.19-fixture.zip'
GETH_1919_ZIP = 'test.zip'
GETH_1919_ZIP = 'geth-1.9.19-fixture.zip'


@pytest.fixture(scope='module')
Expand Down
Binary file removed tests/integration/test.zip
Binary file not shown.

0 comments on commit 3071442

Please sign in to comment.