Skip to content

Commit

Permalink
All done. Gren light.
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed Apr 11, 2017
1 parent b0eb7d6 commit 769eb5e
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import "./MintableToken.sol";
*
* - Tokens are dynamically created during the crowdsale
*
* - At the end of the crowdsale, a
*
*
*/
contract MintedTokenCappedCrowdsale is Crowdsale {
Expand Down
1 change: 1 addition & 0 deletions contracts/PresaleFundCollector.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pragma solidity ^0.4.6;


import "./Crowdsale.sol";
import "./SafeMathLib.sol";

Expand Down
8 changes: 7 additions & 1 deletion ico/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

from eth_utils.currency import to_wei
from ruamel.yaml.comments import CommentedMap
from web3 import Web3
from web3.contract import Contract

from ico.state import CrowdsaleState
from ico.utils import check_succesful_tx


def _datetime(*args) -> datetime.datetime:
Expand Down Expand Up @@ -56,7 +58,7 @@ def get_jinja_context(data: dict) -> dict:
return context


def get_post_actions_context(section_data: str, runtime_data: dict, contracts: Dict[str, Contract]) -> dict:
def get_post_actions_context(section_data: str, runtime_data: dict, contracts: Dict[str, Contract], web3: Web3) -> dict:
"""Get Python evalution context for post-deploy and verify actions.
:param runtime_data:
Expand All @@ -67,11 +69,15 @@ def get_post_actions_context(section_data: str, runtime_data: dict, contracts: D

context = get_jinja_context(runtime_data)

def _confirm_tx(txid):
check_succesful_tx(web3, txid)

# Make contracts available in the context
for name, contract in contracts.items():
context[name] = contract

context["CrowdsaleState"] = CrowdsaleState
context["confirm_tx"] = _confirm_tx

return context

Expand Down
29 changes: 20 additions & 9 deletions ico/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,43 +137,54 @@ def write_deployment_report(yaml_filename: str, runtime_data: dict):
out.write(ruamel.yaml.round_trip_dump(runtime_data))


def exec_lines(lines: str, context: dict):
def exec_lines(lines: str, context: dict, print_prefix=None):
"""Exec python code line-by-line and stop on error.
:param lines: Python code snippet to evaluate
:param context: Evaluation context
:param print_prefix: Echo all lines we evaluate
"""

for line in lines.split("\n"):

if not line.strip():
continue

if print_prefix:
print(print_prefix, line)
try:
exec(line, context)
except Exception as e:
raise RuntimeError("Failed when running: {}".format(line)) from e


def perform_post_actions(runtime_data: dict, contracts: dict):
def perform_post_actions(chain, runtime_data: dict, contracts: dict):
"""Make contracts to set up call chains."""

web3 = chain.web3

post_actions = runtime_data.get("post_actions")
if post_actions:
context = get_post_actions_context(post_actions, runtime_data, contracts)
context = get_post_actions_context(post_actions, runtime_data, contracts, web3)
post_actions = textwrap.dedent(post_actions)

print("Performing post-deployment contract actions")
exec_lines(post_actions, context)
exec_lines(post_actions, context, print_prefix="Action:")
else:
print("No post-deployment actions defined")


def perform_verify_actions(runtime_data: dict, contracts: dict):
def perform_verify_actions(chain, runtime_data: dict, contracts: dict):
"""Check out deployment was solid."""

web3 = chain.web3

verify_actions = runtime_data.get("verify_actions")
if verify_actions:
context = get_post_actions_context(verify_actions, runtime_data, contracts)
context = get_post_actions_context(verify_actions, runtime_data, contracts, web3)

verify_actions = textwrap.dedent(verify_actions)
print("Performing deployment verification")
exec_lines(verify_actions, context)
exec_lines(verify_actions, context, print_prefix="Verification:")
else:
print("No verify defined")

Expand All @@ -193,8 +204,8 @@ def deploy_crowdsale_from_file(project: Project, yaml_filename: str, deployment_
print("Owner balance is", from_wei(web3.eth.getBalance(address), "ether"), "ETH")

runtime_data, statistics, contracts = deploy_crowdsale(project, chain, chain_data, deploy_address)
perform_post_actions(runtime_data, contracts)
perform_verify_actions(runtime_data, contracts)
perform_post_actions(chain, runtime_data, contracts)
perform_verify_actions(chain, runtime_data, contracts)
write_deployment_report(yaml_filename, runtime_data)

return runtime_data, statistics, contracts
Expand Down
4 changes: 4 additions & 0 deletions ico/importexpand.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def process_source(self, src: str, parent_path: str):
prefix, import_path, suffix = line.split('"')
source = self.expand_file(import_path, parent_path=parent_path)
out += source.split("\n")
elif line.startswith("import '"):
prefix, import_path, suffix = line.split("'")
source = self.expand_file(import_path, parent_path=parent_path)
out += source.split("\n")
elif line.startswith('pragma'):
# Only allow one pragma statement per file
if self.pragma_processed:
Expand Down
6 changes: 3 additions & 3 deletions ico/tests/tools/test_crowdsale_deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def test_deploy_crowdsale(project, chain, accounts, example_yaml_filename):
# Not needed for testrpc
chain_data["unlock_deploy_address"] = False

runtime_data, statistics, contracts = deploy_crowdsale(project, chain, chain_data, accounts[0])
runtime_data, statistics, contracts = deploy_crowdsale(project, chain, chain_data, accounts[7])

perform_post_actions(runtime_data, contracts)
perform_verify_actions(runtime_data, contracts)
perform_post_actions(chain, runtime_data, contracts)
perform_verify_actions(chain, runtime_data, contracts)
write_deployment_report(example_yaml_filename, runtime_data)
2 changes: 2 additions & 0 deletions ico/tests/tools/test_expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ def test_expand_token(project: Project):

expanded, imported_files = expand_contract_imports(project, "CrowdsaleToken.sol")
assert "contract CrowdsaleToken" in expanded
assert 'import "' not in expanded
assert "import '" not in expanded


0 comments on commit 769eb5e

Please sign in to comment.