-
Notifications
You must be signed in to change notification settings - Fork 565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/dirtycheck #73
base: master
Are you sure you want to change the base?
Feat/dirtycheck #73
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,7 @@ registrar.json | |
|
||
# Crowdsale definitions | ||
crowdsales/*.yml | ||
crowdsales/*.py | ||
*.csv | ||
|
||
# Customer test cases | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from git import Repo | ||
import os | ||
import time | ||
|
||
join = os.path.join | ||
repo = Repo(os.getcwd()) | ||
assert not repo.bare | ||
|
||
repo.config_reader() | ||
|
||
def git_sanitycheck(): | ||
git_ismaster() | ||
git_isold() | ||
git_isdirty() | ||
|
||
def git_isdirty(): | ||
if repo.is_dirty(): | ||
raise RuntimeError("The repository is not committed, won't continue. Please commit.") | ||
|
||
return | ||
|
||
def git_ismaster(): | ||
# User can override git_isold checking for a week | ||
if ((float(os.getenv("ICO_DEPLOY_ANYWAY", 0)) + 604800) > time.time()): | ||
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. As @ztane mentioned, you don't have to use that many parentheses in Python
And if it's me, I would probably move
Btw why is this time check done in this function and not in |
||
return True | ||
|
||
if (repo.active_branch.commit != repo.heads.master.commit): | ||
raise RuntimeError("This branch is not 'master'. Please switch to master, or use the following command to postpone this check for a week:\nexport ICO_DEPLOY_ANYWAY=" + str(time.time())) | ||
|
||
def git_isold(): | ||
git_root = repo.git.rev_parse("--show-toplevel") | ||
latest_pull = os.stat(git_root + "/.git/FETCH_HEAD").st_mtime | ||
deadline = latest_pull + 604800 # One week from latest commit | ||
|
||
if (time.time() > deadline): | ||
raise RuntimeError("You haven't pulled for a week. Please do git pull.") | ||
else: | ||
return | ||
|
||
def git_current_commit(): | ||
return repo.active_branch.commit |
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.
yep - it all seems good. - ztane have placed some comments already.
But these numbers with a lot of zeros are really hard to read correctly, and they are very critical - I'd suggest creating a global constant of one million - ie - a line in the beggining of the file like
MILLION = int(10e6)
and them write these gas_price expressions as:
gasprice * 100 * MILLION
(
int(10e8)
would work, of course, but I find 100 * MILLION more readable)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.
I have totally different view on this, even though it's a rather small matter. I would say having constant like
MILLION = int(10e6)
is not only not correct (10e6
is actually10**7
=> 10 millions) but also doesn't really improve the readability of the code.The context of this part of code is to convert
gas_price
from wei to gigawei. So the thing that developers really care about is how many0
there are, which is the reason why we can say1000000000
is a hard number to read => easy to make mistake. And for that reason alone it's best to use exponentiation.And if you want to take it a little bit further, then you can define an utility function like:
then it's readable, understandable, reusable and testable.
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.
I would not say it is small matter - and neither that it is "totally different" view. The major problem, of course is reading the zeros. I agree that putting the exponentiation directly will make the number of zeros more apparent (and less prone to subtle catastrophic mistakes as the one I just made, of writting 10e6 thinking about 10 ** 6)
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.
There is the other matter that
int(1e6)
is not a compile-time constant, unlike10 ** 6
.