-
Notifications
You must be signed in to change notification settings - Fork 45
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
Balance proof as a namedtuple instead of a tuple #1272
Balance proof as a namedtuple instead of a tuple #1272
Conversation
61bb3ab
to
08d5717
Compare
Codecov Report
@@ Coverage Diff @@
## master #1272 +/- ##
=======================================
Coverage 81.66% 81.66%
=======================================
Files 21 21
Lines 1456 1456
Branches 190 190
=======================================
Hits 1189 1189
Misses 228 228
Partials 39 39 Continue to review full report at Codecov.
|
instead of a tuple. This gets rid of many balance_proof[0], balance_proof[1] etc. Also, after this change, calls to create_balance_proof_countersignature() can easily be turned into calls with keyword arguments.
08d5717
to
05b4f48
Compare
Hey @pirapira I will review the PR as requested but before I do I have a suggestion to tweak what this PR is doing. If you like it please implement it, if not then I will review the PR as it already is. In the "Why I am making this PR" section you stated:
I think that what's even more readable is a named tuple. But apart from readability named tuples are also very well typed and can be checked with mypy while dictionaries not so much unless we use the typed dicts. I know this is tests-only code so that's why I am leaving it up to you to decide what to do. So it would be something like class BalanceProof(NamedTuple):
balance_hash: TypeOfBalanceHash
nonce: int
additional_hash: TypeOfAddHash
signature: TypeOfSignature
You can do that with named tuples too! You just need to unpack them as a dict. So if |
@LefterisJP then I'll do namedtuple. I guess the additional change is not big. |
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.
thank you. LGTM
) | ||
token_network.functions.updateNonClosingBalanceProof( | ||
channel_identifier, A, B, *balance_proof_A, balance_proof_update_signature_B | ||
channel_identifier, |
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.
nitpick: add kwargs
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.
This will be done here, after Alderaan: #1292
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.
Hmm ... that's not what I mean. I meant to specify the name of the arguments such as
token_network.functions.updateNonClosingBalanceProof(
channel_identifier=channel_identifier,
participant1=A,
....
)
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.
Positional arguments cannot come after kwargs.
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.
Ah I just noticed *balance_proof_A._asdict().values()
. All right then, disregard.
What this PR does
This PR changes
create_balance_proof()
s return value from a tuple to a dictionary.Why I'm making this PR
balance_proof[0]
balance_proof[3]
was less readable thanbalance_proof["balance_hash"]
.**balance_proof
in other function calls,balance_proof
has to be a dictionary.What's tricky about this PR (if any)
The fields of the dictionary have the same name as the parameters of
create_balance_proof_countersignature()
.Any reviewer can check these:
make compile_contracts
and add the resultingraiden_contracts/data/contracts.json
in the PR.[skip ci]
in the commit message so Travis does not waste time.[skip ci]
and let Travis check the hash of the source.solidityFunction
_solidity_argument
solidity_variable
python_variable
PYTHON_CONSTANT
etherscan_verify.py
runs on the new contract.gas.json
.pytest.raises(TransactionFailed, match="error message"):
And before "merge" all checkboxes have to be checked. If you find redundant points, remove them.