2019-06-24 11:46:28 +00:00
|
|
|
"""
|
|
|
|
This file is part of nucypher.
|
|
|
|
|
|
|
|
nucypher is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
|
|
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
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import pytest
|
|
|
|
from eth_utils import keccak
|
|
|
|
|
|
|
|
from nucypher.blockchain.eth.agents import AdjudicatorAgent
|
|
|
|
from nucypher.blockchain.eth.deployers import (
|
|
|
|
AdjudicatorDeployer,
|
|
|
|
NucypherTokenDeployer,
|
|
|
|
StakingEscrowDeployer,
|
|
|
|
DispatcherDeployer
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.slow()
|
2019-08-12 07:15:43 +00:00
|
|
|
def test_adjudicator_deployer(testerchain,
|
|
|
|
slashing_economics,
|
|
|
|
deployment_progress,
|
|
|
|
test_registry):
|
|
|
|
testerchain = testerchain
|
2019-06-24 11:46:28 +00:00
|
|
|
origin = testerchain.etherbase_account
|
|
|
|
|
2019-08-12 07:15:43 +00:00
|
|
|
token_deployer = NucypherTokenDeployer(deployer_address=origin, registry=test_registry)
|
2019-06-24 11:46:28 +00:00
|
|
|
token_deployer.deploy()
|
|
|
|
|
|
|
|
stakers_escrow_secret = os.urandom(DispatcherDeployer.DISPATCHER_SECRET_LENGTH)
|
2019-08-12 07:15:43 +00:00
|
|
|
staking_escrow_deployer = StakingEscrowDeployer(deployer_address=origin, registry=test_registry)
|
2019-06-24 11:46:28 +00:00
|
|
|
|
|
|
|
staking_escrow_deployer.deploy(secret_hash=keccak(stakers_escrow_secret))
|
|
|
|
staking_agent = staking_escrow_deployer.make_agent() # 2 Staker Escrow
|
|
|
|
|
2019-08-12 07:15:43 +00:00
|
|
|
deployer = AdjudicatorDeployer(deployer_address=origin, registry=test_registry)
|
2019-07-29 14:28:48 +00:00
|
|
|
deployment_receipts = deployer.deploy(secret_hash=os.urandom(DispatcherDeployer.DISPATCHER_SECRET_LENGTH),
|
|
|
|
progress=deployment_progress)
|
2019-06-24 11:46:28 +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) == len(deployment_receipts) == 3
|
2019-06-24 11:46:28 +00:00
|
|
|
|
2019-08-02 23:06:32 +00:00
|
|
|
for step in deployer.deployment_steps:
|
|
|
|
assert deployment_receipts[step]['status'] == 1
|
2019-06-24 11:46:28 +00:00
|
|
|
|
|
|
|
# Create an AdjudicatorAgent instance
|
|
|
|
adjudicator_agent = deployer.make_agent()
|
|
|
|
|
|
|
|
# Check default Adjudicator deployment parameters
|
2019-08-12 07:15:43 +00:00
|
|
|
assert staking_escrow_deployer.deployer_address != staking_agent.contract_address
|
2019-06-24 11:46:28 +00:00
|
|
|
assert adjudicator_agent.staking_escrow_contract == staking_agent.contract_address
|
|
|
|
assert adjudicator_agent.hash_algorithm == slashing_economics.hash_algorithm
|
|
|
|
assert adjudicator_agent.base_penalty == slashing_economics.base_penalty
|
|
|
|
assert adjudicator_agent.penalty_history_coefficient == slashing_economics.penalty_history_coefficient
|
|
|
|
assert adjudicator_agent.percentage_penalty_coefficient == slashing_economics.percentage_penalty_coefficient
|
|
|
|
assert adjudicator_agent.reward_coefficient == slashing_economics.reward_coefficient
|
|
|
|
|
|
|
|
# Retrieve the AdjudicatorAgent singleton
|
2019-08-12 07:15:43 +00:00
|
|
|
some_policy_agent = AdjudicatorAgent(registry=test_registry)
|
2019-06-24 11:46:28 +00:00
|
|
|
assert adjudicator_agent == some_policy_agent # __eq__
|
|
|
|
|
|
|
|
# Compare the contract address for equality
|
|
|
|
assert adjudicator_agent.contract_address == some_policy_agent.contract_address
|