Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mikeshultz/solidbyte
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeshultz committed Sep 20, 2020
2 parents 6aea143 + 661371e commit c726e88
Show file tree
Hide file tree
Showing 23 changed files with 105 additions and 333 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
@@ -1,8 +1,9 @@
language: python
python:
- 3.6
- 3.6-dev
- 3.7-dev
# 3.7.9 selected due to: https://github.com/ipfs-shipyard/py-ipfs-http-client/issues/235
- 3.7.9
- 3.8
- 3.8-dev
cache: pip
env:
- TESTING=1 SCRIPT='pytest -v --cov solidbyte --cov-report term-missing'
Expand Down
6 changes: 3 additions & 3 deletions requirements.test.txt
@@ -1,3 +1,3 @@
coverage==4.0.3
pytest-cov~=2.5.1
python-coveralls~=2.9.1
coverage~=5.3
pytest-cov~=2.10.1
python-coveralls~=2.9.3
30 changes: 12 additions & 18 deletions requirements.txt
@@ -1,26 +1,20 @@
tabulate>=0.8.2
pytest>=3.9.3
attrdict>=2.0.0
# web3 and eth-account versions dictated by py-ethpm
eth-account>=0.2.3,<0.3.0
web3<4.9,>=4.7
eth-account>=0.5.3,<0.6
web3>=5.12.1,<6.0
pyyaml>=4.2b1
# EthPM stuff. Had to be removed because because the version that supports
# web3<5 auto-imports web3 infura, which now errors with web3.
ethpm==0.1.4a8
pytest-ethereum==0.1.3a5
#pytest-ethereum==0.1.3a6
eth-abi==1.2.2
# Until web3[tester] can be removed from py-ethpm, we need these
py-geth<3.0.0,>=2.0.1
eth-tester[py-evm]==0.1.0-beta.33
pysha3<2.0.0,>=1.0.0
eth-abi>=2.1.1,<3.0
py-evm==0.3.0a19
eth-tester[py-evm]==0.5.0-beta.2
# Vyper
vyper==0.1.0b9
vyper==0.2.4
# If not specified, causes issues for some reason
py-ecc==1.4.7
# some peer dependency tries to install an incompatible eth-utils
eth-utils==1.8.1
eth_typing==1.3.0
eth-utils<2.0.0,>=1.9.5
# Solidity
solidity-parser>=0.0.3
solidity-parser==0.0.7
# solidity-parser needs this, apparently but does not specify a version itself
antlr4-python3-runtime==4.7.2
# Fails on travis for some reason
pysha3<2.0.0,>=1.0.0
5 changes: 2 additions & 3 deletions setup.py
Expand Up @@ -96,9 +96,8 @@ def requirements_to_list(filename):
'Topic :: Software Development :: Build Tools',
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
],
keywords='solidity ethereum development',
packages=find_packages(exclude=['docs', 'tests', 'scripts', 'build']),
Expand Down
8 changes: 4 additions & 4 deletions solidbyte/accounts/__init__.py
Expand Up @@ -9,7 +9,7 @@
from attrdict import AttrDict
from eth_account import Account
from web3 import Web3
from web3.exceptions import UnhandledRequest
from web3.exceptions import CannotHandleRequest
from ..common import to_path
from ..common import store
from ..common.exceptions import SolidbyteException, ValidationError, WrongPassword
Expand Down Expand Up @@ -142,7 +142,7 @@ def _load_accounts(self, force: bool = False) -> None:
self.web3.eth.getBalance(self.web3.toChecksumAddress(addr)),
'ether'
)
except UnhandledRequest:
except CannotHandleRequest:
pass
self._accounts.append(AttrDict({
'address': addr,
Expand Down Expand Up @@ -223,7 +223,7 @@ def create_account(self, password: str) -> str:
"""

new_account = self.eth_account.create(os.urandom(len(password) * 2))
encrypted_account = Account.encrypt(new_account.privateKey, password)
encrypted_account = Account.encrypt(new_account.key, password)

self._write_json_file(encrypted_account)

Expand Down Expand Up @@ -300,4 +300,4 @@ def sign_tx(self, account_address: str, tx: dict, password: str = None) -> str:
tx['nonce'] = nonce

privkey = self.unlock(account_address, password)
return self.web3.eth.account.signTransaction(tx, privkey)
return self.web3.eth.account.sign_transaction(tx, privkey)
Binary file modified solidbyte/bin/solc
Binary file not shown.
1 change: 0 additions & 1 deletion solidbyte/cli/handler.py
Expand Up @@ -18,7 +18,6 @@
'show',
'console',
'accounts',
# 'install',
'metafile',
'sigs',
'script',
Expand Down
32 changes: 0 additions & 32 deletions solidbyte/cli/install.py

This file was deleted.

2 changes: 1 addition & 1 deletion solidbyte/cli/show.py
Expand Up @@ -23,7 +23,7 @@ def main(parser_args):
deployer = Deployer(network_name=network_name)
# TODO: Show all networks?
web3 = web3c.get_web3(network_name)
network_id = web3.net.chainId or web3.net.version
network_id = str(web3.eth.chainId or web3.net.version)
source_contracts = deployer.get_artifacts()
metafile = MetaFile()

Expand Down
4 changes: 2 additions & 2 deletions solidbyte/common/web3/__init__.py
Expand Up @@ -40,12 +40,12 @@ def normalize_address(addr):

def hash_hexstring(hexbytes):
assert hexbytes is not None, "hexbytes provided to hash_hexstring is None"
return normalize_hexstring(Web3.sha3(hexstr=normalize_hexstring(hexbytes)))
return normalize_hexstring(Web3.keccak(hexstr=normalize_hexstring(hexbytes)))


def hash_string(strong):
assert strong is not None, "strong provided to hash_string is None"
return normalize_hexstring(Web3.sha3(text=strong))
return normalize_hexstring(Web3.keccak(text=strong))


def clean_bytecode(bytecode):
Expand Down
15 changes: 12 additions & 3 deletions solidbyte/common/web3/connection.py
Expand Up @@ -18,7 +18,7 @@

log = getLogger(__name__)

TEST_BLOCK_GAS_LIMIT = int(6.5e6)
TEST_BLOCK_GAS_LIMIT = int(12e6)
ETH_TESTER_TYPES = ('eth_tester', 'eth-tester', 'ethereum-tester')


Expand Down Expand Up @@ -90,6 +90,8 @@ def _init_provider_from_type(self, config):
'eth_gasPrice': 1,
'eth_syncing': False,
'eth_mining': False,
# Maybe not standard, but used
'eth_chainId': str(int(datetime.now().timestamp())),
# Net
'net_version': str(int(datetime.now().timestamp())),
'net_listening': False,
Expand All @@ -100,13 +102,20 @@ def _init_provider_from_type(self, config):
middlewares = list(provider.middlewares)

i = 0
replaced = False
# TODO: fixture_middleware may no tlonger be default but let's check anyway. This is
# probably a depreciated block, however.
for m in middlewares:
log.debug(m.__name__)
if m.__name__ == 'fixture_middleware':
log.debug('Replacing fixture_middleware with our own.')
middlewares[i] = fixture_middleware # Replace with our own
replaced = True
break
i += 1

if not replaced:
middlewares.append(fixture_middleware)

# Set the new middlewars for the provider
provider.middlewares = middlewares

Expand Down Expand Up @@ -169,6 +178,6 @@ def get_web3(self, name=None):
self.web3.eth.setGasPriceStrategy(medium_gas_price_strategy)

# Add our middleware for signing
self.web3.middleware_stack.add(SolidbyteSignerMiddleware, name='SolidbyteSigner')
self.web3.middleware_onion.add(SolidbyteSignerMiddleware, name='SolidbyteSigner')

return self.web3
2 changes: 1 addition & 1 deletion solidbyte/compile/compiler.py
Expand Up @@ -5,7 +5,7 @@
from subprocess import Popen, PIPE, STDOUT
from pathlib import Path
from typing import Set
from vyper.signatures.interface import extract_file_interface_imports
from vyper.cli.utils import extract_file_interface_imports
from .vyper import is_vyper_interface, vyper_import_to_file_paths
from .solidity import is_solidity_interface_only
from ..common.utils import (
Expand Down
16 changes: 9 additions & 7 deletions solidbyte/compile/vyper.py
@@ -1,7 +1,8 @@
""" Vyper utilities """
import re
from typing import List
from vyper.parser.parser import parse_to_ast
from vyper.ast.utils import parse_to_ast
from vyper.ast.nodes import FunctionDef
from ..common.utils import to_path
from ..common.logging import getLogger

Expand All @@ -14,7 +15,7 @@
ARG_SPEC = r'(([\w]+)\:\s*' + VYPER_TYPES + r'(, )*)*'
FUNCTION = r'^(def [\w\_]+\(' + ARG_SPEC + r'\)){1}(\:|[\s]+\-\>[\s]+' + VYPER_TYPES + r'\:){1}'
PASS_BODY = r'([\n\r\s]*(pass)*)*'
FUNC_MODIFYING = r'(\s*(modifying|constant){1}){1}'
FUNC_MODIFYING = r'(\s*(payable|nonpayable|view|pure){1}){1}'
BODYLESS_FUNCTION = FUNCTION + FUNC_MODIFYING + PASS_BODY


Expand Down Expand Up @@ -45,14 +46,15 @@ def vyper_funcs_from_source(source_text):

for i in range(0, len(source_ast)):
node = source_ast[i]
start = node.lineno
end = -1

if i < len(source_ast) - 1:
end = source_ast[i+1].lineno - 1
if type(node) == FunctionDef:
start = node.lineno
end = -1

funcs.append(source_extract(source_text, start, end))
if i < len(source_ast) - 1:
end = source_ast[i+1].lineno - 1

funcs.append(source_extract(source_text, start, end))
return funcs


Expand Down
2 changes: 1 addition & 1 deletion solidbyte/console/__init__.py
Expand Up @@ -37,7 +37,7 @@ def __init__(self, _locals=None, filename="<console>", network_name=None,
self.web3 = web3c.get_web3(network_name)

if not _locals:
network_id = self.web3.net.chainId or self.web3.net.version
network_id = self.web3.eth.chainId or self.web3.net.version

d = Deployer(network_name=network_name)
contracts_meta = d.deployed_contracts
Expand Down
7 changes: 2 additions & 5 deletions solidbyte/deploy/__init__.py
Expand Up @@ -73,7 +73,7 @@ def __init__(self, network_name: str, account: str = None, project_dir: PS = Non
self._contracts = AttrDict()
self._artifacts = AttrDict()
self.web3 = web3c.get_web3(network_name)
self.network_id = self.web3.net.chainId or self.web3.net.version
self.network_id = self.web3.eth.chainId or self.web3.net.version

# yml = NetworksYML(project_dir=self.project_dir)
# if yml.is_eth_tester(network_name):
Expand Down Expand Up @@ -153,7 +153,6 @@ def refresh(self, force: bool = True) -> None:

def contracts_to_deploy(self) -> Set[str]:
""" Return a Set of contract names that need deployment """

self._build_dependency_tree()

needs_deploy: Set = set()
Expand All @@ -170,7 +169,6 @@ def contracts_to_deploy(self) -> Set[str]:
"interface.".format(name))
else:
if contract.check_needs_deployment(newest_bytecode):

needs_deploy.add(name)

assert self.deptree, "Invalid dependency tree. This is probably a bug."
Expand All @@ -191,7 +189,6 @@ def check_needs_deploy(self, name: str = None) -> bool:
:returns: (:code:`bool`) if deployment is required
"""

if name is not None and not self.artifacts.get(name):
raise FileNotFoundError("Unknown contract: {}".format(name))

Expand Down Expand Up @@ -220,7 +217,7 @@ def deploy(self) -> bool:
if self.account and self.web3.eth.getBalance(self.account) == 0:
log.warning("Account has zero balance ({})".format(self.account))

if self.network_id != (self.web3.net.chainId or self.web3.net.version):
if self.network_id != (self.web3.eth.chainId or self.web3.net.version):
raise DeploymentError("Connected node is does not match the provided chain ID")

self._execute_deploy_scripts()
Expand Down
15 changes: 9 additions & 6 deletions solidbyte/deploy/objects.py
Expand Up @@ -265,7 +265,7 @@ def __init__(self, name: str, network_name: str, from_account: str,
self.web3 = web3
else:
self.web3 = web3c.get_web3(network_name)
self.network_id = self.web3.net.chainId or self.web3.net.version
self.network_id = self.web3.eth.chainId or self.web3.net.version
self.accounts = Accounts(web3=self.web3)
self.metafile = metafile

Expand Down Expand Up @@ -395,24 +395,26 @@ def _process_instances(self, metafile_instances: List[Dict[str, T]]) -> None:

def _load_metafile_contract(self) -> None:
""" Process the contract dict for this contract from the metafile. """

metafile_contract = self.metafile.get_contract(self.name)

if not metafile_contract:
log.debug('No metafile.json entry for contract {}.'.format(self.name))
return

if metafile_contract['networks'].get(self.network_id):
# Metafile uses string network_id
net_id = str(self.network_id)

if metafile_contract['networks'].get(net_id):

self.deployedHash = metafile_contract['networks'][self.network_id].get('deployedHash')
deployed_instances = metafile_contract['networks'][self.network_id].get(
self.deployedHash = metafile_contract['networks'][net_id].get('deployedHash')
deployed_instances = metafile_contract['networks'][net_id].get(
'deployedInstances'
)

if deployed_instances and len(deployed_instances) > 0:

self._process_instances(
metafile_contract['networks'][self.network_id]['deployedInstances']
metafile_contract['networks'][net_id]['deployedInstances']
)

def _load_artifacts(self) -> None:
Expand Down Expand Up @@ -604,6 +606,7 @@ def _deploy(self, *args, **kwargs) -> Web3Contract:
)

log.info("Successfully deployed {}. Transaction has been mined.".format(self.name))
log.debug("Adding deployment with bytecode_hash of {}".format(bytecode_hash))

self.deployments.append(Deployment(
bytecode_hash=bytecode_hash,
Expand Down

0 comments on commit c726e88

Please sign in to comment.