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/>.
|
|
|
|
"""
|
2019-04-17 23:51:08 +00:00
|
|
|
|
|
|
|
|
2018-10-17 16:33:20 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
from nucypher.blockchain.eth.agents import PolicyAgent
|
2019-03-20 03:38:29 +00:00
|
|
|
from nucypher.blockchain.eth.deployers import (
|
|
|
|
NucypherTokenDeployer,
|
2019-05-29 14:15:18 +00:00
|
|
|
StakingEscrowDeployer,
|
2019-03-20 03:38:29 +00:00
|
|
|
PolicyManagerDeployer,
|
|
|
|
DispatcherDeployer
|
|
|
|
)
|
2018-10-17 16:33:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_policy_manager_deployer(testerchain):
|
2019-06-17 21:10:19 +00:00
|
|
|
origin, *everybody_else = testerchain.w3.eth.accounts
|
2018-10-17 16:33:20 +00:00
|
|
|
|
|
|
|
token_deployer = NucypherTokenDeployer(blockchain=testerchain, deployer_address=origin)
|
2018-10-26 14:48:10 +00:00
|
|
|
|
2018-10-17 16:33:20 +00:00
|
|
|
token_deployer.deploy()
|
|
|
|
|
|
|
|
token_agent = token_deployer.make_agent() # 1: Token
|
|
|
|
|
2019-05-29 13:53:23 +00:00
|
|
|
stakers_escrow_secret = os.urandom(DispatcherDeployer.DISPATCHER_SECRET_LENGTH)
|
2019-06-18 06:14:01 +00:00
|
|
|
staking_escrow_deployer = StakingEscrowDeployer(deployer_address=origin, blockchain=testerchain)
|
2018-10-26 14:48:10 +00:00
|
|
|
|
2019-06-17 21:10:19 +00:00
|
|
|
staking_escrow_deployer.deploy(secret_hash=testerchain.w3.keccak(stakers_escrow_secret))
|
2018-10-17 16:33:20 +00:00
|
|
|
|
2019-05-29 14:15:18 +00:00
|
|
|
staking_agent = staking_escrow_deployer.make_agent() # 2 Staker Escrow
|
2018-10-17 16:33:20 +00:00
|
|
|
|
2019-03-20 03:38:29 +00:00
|
|
|
policy_manager_secret = os.urandom(DispatcherDeployer.DISPATCHER_SECRET_LENGTH)
|
2019-06-18 06:14:01 +00:00
|
|
|
deployer = PolicyManagerDeployer(deployer_address=origin, blockchain=testerchain)
|
2018-10-26 14:48:10 +00:00
|
|
|
|
2019-06-17 21:10:19 +00:00
|
|
|
deployment_txhashes = deployer.deploy(secret_hash=testerchain.w3.keccak(policy_manager_secret))
|
2018-10-17 16:33:20 +00:00
|
|
|
assert len(deployment_txhashes) == 3
|
|
|
|
|
|
|
|
for title, txhash in deployment_txhashes.items():
|
|
|
|
receipt = testerchain.wait_for_receipt(txhash=txhash)
|
|
|
|
assert receipt['status'] == 1, "Transaction Rejected {}:{}".format(title, txhash)
|
|
|
|
|
|
|
|
# Create a token instance
|
|
|
|
policy_agent = deployer.make_agent()
|
|
|
|
policy_manager_contract = policy_agent.contract
|
|
|
|
|
|
|
|
# Retrieve the token from the blockchain
|
2018-10-19 08:16:38 +00:00
|
|
|
some_policy_agent = PolicyAgent()
|
2018-10-17 16:33:20 +00:00
|
|
|
assert some_policy_agent.contract.address == policy_manager_contract.address
|
|
|
|
|
|
|
|
# Compare the contract address for equality
|
|
|
|
assert policy_agent.contract_address == some_policy_agent.contract_address
|
|
|
|
assert policy_agent == some_policy_agent # __eq__
|