2018-11-04 19:23:11 +00:00
|
|
|
"""
|
|
|
|
This file is part of nucypher.
|
|
|
|
|
|
|
|
nucypher is free software: you can redistribute it and/or modify
|
2019-03-05 02:50:11 +00:00
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
2018-11-04 19:23:11 +00:00
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
nucypher is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-03-05 02:50:11 +00:00
|
|
|
GNU Affero General Public License for more details.
|
2018-11-04 19:23:11 +00:00
|
|
|
|
2019-03-05 02:50:11 +00:00
|
|
|
You should have received a copy of the GNU Affero General Public License
|
2018-11-04 19:23:11 +00:00
|
|
|
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
"""
|
2018-10-16 19:46:30 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from nucypher.blockchain.eth.agents import NucypherTokenAgent
|
|
|
|
from nucypher.blockchain.eth.deployers import NucypherTokenDeployer
|
2019-08-14 02:17:08 +00:00
|
|
|
from nucypher.blockchain.eth.interfaces import BaseContractRegistry
|
2018-10-16 19:46:30 +00:00
|
|
|
|
|
|
|
|
2019-08-12 07:15:43 +00:00
|
|
|
def test_token_deployer_and_agent(testerchain, deployment_progress, test_registry):
|
|
|
|
testerchain = testerchain
|
2019-04-10 09:46:22 +00:00
|
|
|
origin = testerchain.etherbase_account
|
2018-10-16 19:46:30 +00:00
|
|
|
|
|
|
|
# Trying to get token from blockchain before it's been published fails
|
2019-08-14 02:17:08 +00:00
|
|
|
with pytest.raises(BaseContractRegistry.UnknownContract):
|
2019-08-12 07:15:43 +00:00
|
|
|
NucypherTokenAgent(registry=test_registry)
|
2018-10-16 19:46:30 +00:00
|
|
|
|
|
|
|
# The big day...
|
2019-08-12 07:15:43 +00:00
|
|
|
deployer = NucypherTokenDeployer(registry=test_registry, deployer_address=origin)
|
2018-10-16 19:46:30 +00:00
|
|
|
|
2019-07-29 14:28:48 +00:00
|
|
|
deployment_receipts = deployer.deploy(progress=deployment_progress)
|
2018-10-17 16:33:20 +00:00
|
|
|
|
2019-07-16 19:05:24 +00:00
|
|
|
for title, receipt in deployment_receipts.items():
|
|
|
|
assert receipt['status'] == 1
|
2018-10-16 19:46:30 +00:00
|
|
|
|
2019-07-29 14:28:48 +00:00
|
|
|
# deployment steps must match expected number of steps
|
2019-08-02 23:06:32 +00:00
|
|
|
assert deployment_progress.num_steps == len(deployer.deployment_steps) == 1
|
2019-07-29 14:28:48 +00:00
|
|
|
|
2018-10-16 19:46:30 +00:00
|
|
|
# Create a token instance
|
|
|
|
token_agent = deployer.make_agent()
|
2018-10-17 16:33:20 +00:00
|
|
|
token_contract = token_agent.contract
|
2018-10-16 19:46:30 +00:00
|
|
|
|
|
|
|
expected_token_supply = token_contract.functions.totalSupply().call()
|
|
|
|
assert expected_token_supply == token_agent.contract.functions.totalSupply().call()
|
|
|
|
|
|
|
|
# Retrieve the token from the blockchain
|
2019-08-12 07:15:43 +00:00
|
|
|
same_token_agent = NucypherTokenAgent(registry=test_registry)
|
2018-10-16 19:46:30 +00:00
|
|
|
|
|
|
|
# Compare the contract address for equality
|
|
|
|
assert token_agent.contract_address == same_token_agent.contract_address
|
|
|
|
assert token_agent == same_token_agent # __eq__
|
|
|
|
|
2019-08-12 07:15:43 +00:00
|
|
|
test_registry.clear() # TODO?
|