Skip to content

Improved deployers tests#1111

Merged
KPrasch merged 31 commits intonucypher:sekanjabinfrom
cygnusv:drama-school
Jul 22, 2019
Merged

Improved deployers tests#1111
KPrasch merged 31 commits intonucypher:sekanjabinfrom
cygnusv:drama-school

Conversation

@cygnusv
Copy link
Member

@cygnusv cygnusv commented Jul 1, 2019

The goal of this PR is to improve the deployer tests. Initially, the goal included to improve actor tests (hence drama-school), but I prefer to reduce the scope of the PR for the moment. Nevertheless, it does include some improvements in some actor tests (e.g., a rough test of Investigator).

Hopefully, this will increase coverage a little.

@codecov
Copy link

codecov bot commented Jul 1, 2019

Codecov Report

Merging #1111 into sekanjabin will decrease coverage by 0.15%.
The diff coverage is 90.44%.

Impacted file tree graph

@@              Coverage Diff               @@
##           sekanjabin    #1111      +/-   ##
==============================================
- Coverage       83.42%   83.26%   -0.16%     
==============================================
  Files              71       71              
  Lines            9707     9747      +40     
==============================================
+ Hits             8098     8116      +18     
- Misses           1609     1631      +22
Impacted Files Coverage Δ
nucypher/blockchain/eth/agents.py 86.15% <100%> (-5.8%) ⬇️
nucypher/blockchain/eth/policies.py 77.61% <100%> (ø) ⬆️
nucypher/blockchain/eth/registry.py 75.43% <100%> (-0.44%) ⬇️
nucypher/cli/deploy.py 71.12% <100%> (ø) ⬆️
nucypher/cli/config.py 96% <100%> (-0.08%) ⬇️
nucypher/utilities/sandbox/blockchain.py 81.08% <50%> (+0.12%) ⬆️
nucypher/config/node.py 90.53% <50%> (ø) ⬆️
nucypher/blockchain/eth/decorators.py 75% <71.42%> (-2.15%) ⬇️
nucypher/blockchain/eth/actors.py 83.6% <88.88%> (+0.73%) ⬆️
nucypher/blockchain/eth/interfaces.py 80.74% <91.66%> (+0.28%) ⬆️
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b9d96f9...2e90165. Read the comment docs.

@cygnusv cygnusv changed the base branch from master to alhambra-verde July 3, 2019 12:50
@cygnusv cygnusv changed the base branch from alhambra-verde to sekanjabin July 9, 2019 21:29
@KPrasch KPrasch force-pushed the sekanjabin branch 2 times, most recently from 0de6912 to 2e26f57 Compare July 15, 2019 19:25
@cygnusv cygnusv changed the title [WIP] Drama school Improved deployers tests Jul 17, 2019
@cygnusv cygnusv marked this pull request as ready for review July 17, 2019 13:17
secret_hash = self.contract.functions.secretHash().call()
is_valid_secret = secret_hash == keccak_digest(secret)

if is_valid_secret: # Yay! \ (•◡•) /
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha 🎊



class Deployer(NucypherTokenActor):
class DeployerActor(NucypherTokenActor):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wants another name. Any ideas?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it not stay Deployer?

Who is an actor which deploys a token or contract? Bursar? Secretary? Executive?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jMyles - This name clashes with the namespace in nucypher.blockchain.eth.deployers.Deployer.


def __eq__(self, other) -> bool:
"""Actors are equal if they have the same address."""
return bool(self.checksum_address == other.checksum_address)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will raise AttributeError is the other doesn't have a checksum_address. This might be OK, but also maybe we want to catch it and raise TypeError instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My initial impression is that returning False is desirable is that situation.



class Deployer(NucypherTokenActor):
class DeployerActor(NucypherTokenActor):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it not stay Deployer?

Who is an actor which deploys a token or contract? Bursar? Secretary? Executive?

paint_contract_deployment(contract_name=NucypherTokenDeployer.contract_name,
receipts=token_receipts,
contract_address=token_deployer.contract_address)
deployment_receipts[NucypherTokenDeployer.contract_name] = token_receipts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the key space of the dict will be values of NucypherTokenDeployer.contract_name... does this value mutate then? It's not obvious how to think about this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - they do not mutate - they are hard-coded class attributes on the Deployer claas. This is an effort to have a single source of contract names in the codebase. In general, this method can be code-optimized somewhat with a loop and/or function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe uhhh... 🤔... Maybe use a constant? NucypherTokenDeployer.contract_name is a hard thing for the reader to resolve in terms of understanding the keyspace here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I can see it that way. You propose we have a constants module with all the contract name strings defined?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

staker = Staker(is_me=True, checksum_address=checksum_address, blockchain=self.blockchain)
if not password:
raise ValueError(f'No checksum address or password supplied to initialize new stake.')
staker = self.__create_staker(password=password)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to dive in w/ a debugger, but I'm imagining that a random wallet is generated here? Maybe that needs to be called out in at least a comment on this layer?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree - more comments are needed here. This area needs some thinking, ( see related Issue #1128 and #1129 ). In the case of a software wallet - the RPC endpoint for account creation is used. In the cased of a hardware wallet, an unused account is derived and used (which is always the last index geth loads for hardware wallets).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, so this is a bit of a lava bridge. I think it's a little nerve-racking for self.__create_staker to, without affirmative direction to do so, use a heretofore unused checksum address.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a brid's-eye view does it make sense to implement the feature at all? (#1129 ). What's the user's experience like if they need to create accounts to stake with?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jMyles - Also, If you read above, the user is prompted for consent to use a new account.

@derekpierre
Copy link
Member

derekpierre commented Jul 19, 2019

@cygnusv your tests are so easy to read 🎉 !

KPrasch added a commit to KPrasch/nucypher that referenced this pull request Jul 21, 2019
KPrasch added a commit to KPrasch/nucypher that referenced this pull request Jul 22, 2019
Copy link
Member

@KPrasch KPrasch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several follow up Issues opened, but looking good.

@KPrasch KPrasch merged commit df10a43 into nucypher:sekanjabin Jul 22, 2019
KPrasch added a commit to KPrasch/nucypher that referenced this pull request Jul 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants