Exemplo n.º 1
0
def three_agents(testerchain):
    """
    Musketeers, if you will.
    Launch the big three contracts on provided chain,
    make agents for each and return them.
    """

    """Launch all Nucypher ethereum contracts"""
    origin, *everybody_else = testerchain.interface.w3.eth.accounts

    token_deployer = NucypherTokenDeployer(blockchain=testerchain, deployer_address=origin)

    token_deployer.deploy()

    token_agent = token_deployer.make_agent()  # 1: Token

    miners_escrow_secret = os.urandom(DISPATCHER_SECRET_LENGTH)
    miner_escrow_deployer = MinerEscrowDeployer(
        deployer_address=origin,
        secret_hash=testerchain.interface.w3.keccak(miners_escrow_secret))

    miner_escrow_deployer.deploy()

    miner_agent = miner_escrow_deployer.make_agent()  # 2 Miner Escrow

    policy_manager_secret = os.urandom(DISPATCHER_SECRET_LENGTH)
    policy_manager_deployer = PolicyManagerDeployer(
        deployer_address=origin,
        secret_hash=testerchain.interface.w3.keccak(policy_manager_secret))

    policy_manager_deployer.deploy()

    policy_agent = policy_manager_deployer.make_agent()  # 3 Policy Agent

    return token_agent, miner_agent, policy_agent
Exemplo n.º 2
0
    def deploy_token_contract(self):

        token_deployer = NucypherTokenDeployer(blockchain=self.blockchain, deployer_address=self.deployer_address)

        txhashes = token_deployer.deploy()
        self.token_agent = token_deployer.make_agent()
        return txhashes
Exemplo n.º 3
0
def agent(testerchain):
    origin, *everybody_else = testerchain.interface.w3.eth.accounts
    token_deployer = NucypherTokenDeployer(blockchain=testerchain, deployer_address=origin)

    token_deployer.deploy()
    token_agent = token_deployer.make_agent()
    return token_agent
def test_staking_escrow_deployer_and_agent(testerchain):
    origin, *everybody_else = testerchain.client.accounts

    # The big day...
    token_deployer = NucypherTokenDeployer(blockchain=testerchain,
                                           deployer_address=origin)
    token_deployer.deploy()

    secret_hash = os.urandom(DispatcherDeployer.DISPATCHER_SECRET_LENGTH)
    deployer = StakingEscrowDeployer(blockchain=testerchain,
                                     deployer_address=origin)
    deployment_txhashes = deployer.deploy(secret_hash=secret_hash)

    assert len(deployment_txhashes) == 4

    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 StakingEscrowAgent instance
    staking_agent = deployer.make_agent()

    # TODO: #1102 - Check that token contract address and staking parameters are correct

    # Retrieve the StakingEscrowAgent singleton
    same_staking_agent = StakingEscrowAgent()
    assert staking_agent == same_staking_agent

    # Compare the contract address for equality
    assert staking_agent.contract_address == same_staking_agent.contract_address

    testerchain.registry.clear()
Exemplo n.º 5
0
def test_token_deployer_and_agent(testerchain, deployment_progress,
                                  test_registry):
    testerchain = testerchain
    origin = testerchain.etherbase_account

    # Trying to get token from blockchain before it's been published fails
    with pytest.raises(BaseContractRegistry.UnknownContract):
        NucypherTokenAgent(registry=test_registry)

    # The big day...
    deployer = NucypherTokenDeployer(registry=test_registry,
                                     deployer_address=origin)

    deployment_receipts = deployer.deploy(progress=deployment_progress)

    for title, receipt in deployment_receipts.items():
        assert receipt['status'] == 1

    # deployment steps must match expected number of steps
    assert deployment_progress.num_steps == len(deployer.deployment_steps) == 1

    # Create a token instance
    token_agent = deployer.make_agent()
    token_contract = token_agent.contract

    expected_token_supply = token_contract.functions.totalSupply().call()
    assert expected_token_supply == token_agent.contract.functions.totalSupply(
    ).call()

    # Retrieve the token from the blockchain
    same_token_agent = NucypherTokenAgent(registry=test_registry)

    # Compare the contract address for equality
    assert token_agent.contract_address == same_token_agent.contract_address
    assert token_agent == same_token_agent  # __eq__
Exemplo n.º 6
0
def three_agents(testerchain):
    """
    Musketeers, if you will.
    Launch the big three contracts on provided chain,
    make agents for each and return them.
    """
    """Launch all Nucypher ethereum contracts"""
    origin = testerchain.etherbase_account

    token_deployer = NucypherTokenDeployer(blockchain=testerchain,
                                           deployer_address=origin)
    token_deployer.deploy()

    miner_escrow_deployer = MinerEscrowDeployer(deployer_address=origin)
    miner_escrow_deployer.deploy(
        secret_hash=os.urandom(DispatcherDeployer.DISPATCHER_SECRET_LENGTH))

    policy_manager_deployer = PolicyManagerDeployer(deployer_address=origin)
    policy_manager_deployer.deploy(
        secret_hash=os.urandom(DispatcherDeployer.DISPATCHER_SECRET_LENGTH))

    token_agent = token_deployer.make_agent()  # 1: Token
    miner_agent = miner_escrow_deployer.make_agent()  # 2 Miner Escrow
    policy_agent = policy_manager_deployer.make_agent()  # 3 Policy Agent

    adjudicator_deployer = MiningAdjudicatorDeployer(deployer_address=origin)
    adjudicator_deployer.deploy(
        secret_hash=os.urandom(DispatcherDeployer.DISPATCHER_SECRET_LENGTH))

    yield token_agent, miner_agent, policy_agent
    Agency.clear()
Exemplo n.º 7
0
def test_token_deployer_and_agent(testerchain):
    origin = testerchain.etherbase_account

    # Trying to get token from blockchain before it's been published fails
    with pytest.raises(EthereumContractRegistry.UnknownContract):
        NucypherTokenAgent(blockchain=testerchain)

    # The big day...
    deployer = NucypherTokenDeployer(blockchain=testerchain, deployer_address=origin)

    deployment_txhashes = deployer.deploy()

    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
    token_agent = deployer.make_agent()
    token_contract = token_agent.contract

    expected_token_supply = token_contract.functions.totalSupply().call()
    assert expected_token_supply == token_agent.contract.functions.totalSupply().call()

    # Retrieve the token from the blockchain
    same_token_agent = NucypherTokenAgent(blockchain=testerchain)

    # Compare the contract address for equality
    assert token_agent.contract_address == same_token_agent.contract_address
    assert token_agent == same_token_agent  # __eq__

    testerchain.registry.clear()
Exemplo n.º 8
0
def agent(testerchain, test_registry):
    origin, *everybody_else = testerchain.client.accounts
    token_deployer = NucypherTokenDeployer(registry=test_registry, deployer_address=origin)

    token_deployer.deploy()
    token_agent = token_deployer.make_agent()
    return token_agent
Exemplo n.º 9
0
def agent(testerchain, test_registry) -> NucypherTokenAgent:
    origin, *everybody_else = testerchain.client.accounts
    token_deployer = NucypherTokenDeployer(registry=test_registry)
    tpower = TransactingPower(account=origin, signer=Web3Signer(testerchain.client))

    token_deployer.deploy(transacting_power=tpower)
    token_agent = token_deployer.make_agent()
    return token_agent
Exemplo n.º 10
0
def _make_agency(testerchain, test_registry):
    """
    Launch the big three contracts on provided chain,
    make agents for each and return them.
    """

    # Mock TransactingPower Consumption (Deployer)
    testerchain.transacting_power = TransactingPower(
        password=INSECURE_DEVELOPMENT_PASSWORD,
        account=testerchain.etherbase_account)
    testerchain.transacting_power.activate()

    origin = testerchain.etherbase_account

    token_deployer = NucypherTokenDeployer(deployer_address=origin,
                                           registry=test_registry)
    token_deployer.deploy()

    staking_escrow_deployer = StakingEscrowDeployer(deployer_address=origin,
                                                    registry=test_registry,
                                                    test_mode=True)
    staking_escrow_deployer.deploy(secret_hash=INSECURE_DEPLOYMENT_SECRET_HASH)

    policy_manager_deployer = PolicyManagerDeployer(deployer_address=origin,
                                                    registry=test_registry)
    policy_manager_deployer.deploy(secret_hash=INSECURE_DEPLOYMENT_SECRET_HASH)

    adjudicator_deployer = AdjudicatorDeployer(deployer_address=origin,
                                               registry=test_registry)
    adjudicator_deployer.deploy(secret_hash=INSECURE_DEPLOYMENT_SECRET_HASH)

    staking_interface_deployer = StakingInterfaceDeployer(
        deployer_address=origin, registry=test_registry)
    staking_interface_deployer.deploy(
        secret_hash=INSECURE_DEPLOYMENT_SECRET_HASH)

    token_agent = token_deployer.make_agent()  # 1 Token
    staking_agent = staking_escrow_deployer.make_agent()  # 2 Staking Escrow
    policy_agent = policy_manager_deployer.make_agent()  # 3 Policy Agent
    _adjudicator_agent = adjudicator_deployer.make_agent()  # 4 Adjudicator

    # TODO: Get rid of returning these agents here.
    # What's important is deploying and creating the first agent for each contract,
    # and since agents are singletons, in tests it's only necessary to call the agent
    # constructor again to receive the existing agent.
    #
    # For example:
    #     staking_agent = StakingEscrowAgent()
    #
    # This is more clear than how we currently obtain an agent instance in tests:
    #     _, staking_agent, _ = agency
    #
    # Other advantages is that it's closer to how agents should be use (i.e., there
    # are no fixtures IRL) and it's more extensible (e.g., AdjudicatorAgent)

    return token_agent, staking_agent, policy_agent
Exemplo n.º 11
0
def test_token_deployer_and_agent(testerchain):
    origin, *everybody_else = testerchain.interface.w3.eth.accounts

    # Trying to get token from blockchain before it's been published fails
    with pytest.raises(EthereumContractRegistry.UnknownContract):
        NucypherTokenAgent(blockchain=testerchain)

    # The big day...
    deployer = NucypherTokenDeployer(blockchain=testerchain,
                                     deployer_address=origin)

    # It's not armed
    with pytest.raises(NucypherTokenDeployer.ContractDeploymentError):
        deployer.deploy()

    # Token must be armed before deploying to the blockchain
    deployer.arm()
    deployer.deploy()

    # Create a token instance
    token_agent = deployer.make_agent()
    token_contract = testerchain.get_contract(token_agent.contract_name)

    expected_token_supply = token_contract.functions.totalSupply().call()
    assert expected_token_supply == token_agent.contract.functions.totalSupply(
    ).call()

    # Retrieve the token from the blockchain
    same_token_agent = NucypherTokenAgent(blockchain=testerchain)

    # Compare the contract address for equality
    assert token_agent.contract_address == same_token_agent.contract_address
    assert token_agent == same_token_agent  # __eq__

    testerchain.interface._registry.clear()
Exemplo n.º 12
0
def test_upgradeability(temp_dir_path):
    # Prepare remote source for compilation
    download_github_dir(GITHUB_SOURCE_LINK, temp_dir_path)
    solidity_compiler = SolidityCompiler(source_dirs=[SourceDirs(SolidityCompiler.default_contract_dir()),
                                                      SourceDirs(temp_dir_path)])

    # Prepare the blockchain
    provider_uri = 'tester://pyevm/2'
    try:
        blockchain_interface = BlockchainDeployerInterface(provider_uri=provider_uri,
                                                           compiler=solidity_compiler,
                                                           gas_strategy=free_gas_price_strategy)
        blockchain_interface.connect()
        origin = blockchain_interface.client.accounts[0]
        BlockchainInterfaceFactory.register_interface(interface=blockchain_interface)
        blockchain_interface.transacting_power = TransactingPower(password=INSECURE_DEVELOPMENT_PASSWORD, account=origin)
        blockchain_interface.transacting_power.activate()

        # Check contracts with multiple versions
        raw_contracts = blockchain_interface._raw_contract_cache
        contract_name = AdjudicatorDeployer.contract_name
        test_adjudicator = len(raw_contracts[contract_name]) > 1
        contract_name = StakingEscrowDeployer.contract_name
        test_staking_escrow = len(raw_contracts[contract_name]) > 1
        contract_name = PolicyManagerDeployer.contract_name
        test_policy_manager = len(raw_contracts[contract_name]) > 1

        if not test_adjudicator and not test_staking_escrow and not test_policy_manager:
            return

        # Prepare master version of contracts and upgrade to the latest
        registry = InMemoryContractRegistry()

        token_deployer = NucypherTokenDeployer(registry=registry, deployer_address=origin)
        token_deployer.deploy()

        staking_escrow_deployer = StakingEscrowDeployer(registry=registry, deployer_address=origin)
        deploy_earliest_contract(blockchain_interface, staking_escrow_deployer)
        if test_staking_escrow:
            staking_escrow_deployer.upgrade(contract_version="latest", confirmations=0)

        if test_policy_manager:
            policy_manager_deployer = PolicyManagerDeployer(registry=registry, deployer_address=origin)
            deploy_earliest_contract(blockchain_interface, policy_manager_deployer)
            policy_manager_deployer.upgrade(contract_version="latest", confirmations=0)

        if test_adjudicator:
            adjudicator_deployer = AdjudicatorDeployer(registry=registry, deployer_address=origin)
            deploy_earliest_contract(blockchain_interface, adjudicator_deployer)
            adjudicator_deployer.upgrade(contract_version="latest", confirmations=0)

    finally:
        # Unregister interface
        with contextlib.suppress(KeyError):
            del BlockchainInterfaceFactory._interfaces[provider_uri]
Exemplo n.º 13
0
def test_adjudicator_deployer(testerchain, token_economics,
                              deployment_progress, test_registry):
    testerchain = testerchain
    origin = testerchain.etherbase_account

    token_deployer = NucypherTokenDeployer(deployer_address=origin,
                                           registry=test_registry)
    token_deployer.deploy()

    stakers_escrow_secret = os.urandom(
        DispatcherDeployer.DISPATCHER_SECRET_LENGTH)
    staking_escrow_deployer = StakingEscrowDeployer(deployer_address=origin,
                                                    registry=test_registry)

    staking_escrow_deployer.deploy(secret_hash=keccak(stakers_escrow_secret))
    staking_agent = staking_escrow_deployer.make_agent()  # 2 Staker Escrow

    deployer = AdjudicatorDeployer(deployer_address=origin,
                                   registry=test_registry)
    deployment_receipts = deployer.deploy(secret_hash=os.urandom(
        DispatcherDeployer.DISPATCHER_SECRET_LENGTH),
                                          progress=deployment_progress)

    # deployment steps must match expected number of steps
    assert deployment_progress.num_steps == len(
        deployer.deployment_steps) == len(deployment_receipts) == 3

    for step in deployer.deployment_steps:
        assert deployment_receipts[step]['status'] == 1

    # Create an AdjudicatorAgent instance
    adjudicator_agent = deployer.make_agent()

    # Check default Adjudicator deployment parameters
    assert staking_escrow_deployer.deployer_address != staking_agent.contract_address
    assert adjudicator_agent.staking_escrow_contract == staking_agent.contract_address
    assert adjudicator_agent.hash_algorithm == token_economics.hash_algorithm
    assert adjudicator_agent.base_penalty == token_economics.base_penalty
    assert adjudicator_agent.penalty_history_coefficient == token_economics.penalty_history_coefficient
    assert adjudicator_agent.percentage_penalty_coefficient == token_economics.percentage_penalty_coefficient
    assert adjudicator_agent.reward_coefficient == token_economics.reward_coefficient

    # Retrieve the AdjudicatorAgent singleton
    some_policy_agent = AdjudicatorAgent(registry=test_registry)
    assert adjudicator_agent == some_policy_agent  # __eq__

    # Compare the contract address for equality
    assert adjudicator_agent.contract_address == some_policy_agent.contract_address
Exemplo n.º 14
0
def test_nucypher_contract_compiled(testerchain):
    # Ensure that solidity smart contacts are available, post-compile.
    origin, *everybody_else = testerchain.interface.w3.eth.accounts

    token_contract_identifier = NucypherTokenDeployer(
        blockchain=testerchain, deployer_address=origin).contract_name
    assert token_contract_identifier in testerchain.interface._BlockchainInterface__raw_contract_cache
Exemplo n.º 15
0
def _make_agency(test_registry, token_economics, deployer_transacting_power,
                 threshold_staking):
    transacting_power = deployer_transacting_power

    token_deployer = NucypherTokenDeployer(economics=token_economics,
                                           registry=test_registry)
    token_deployer.deploy(transacting_power=transacting_power)

    pre_application_deployer = PREApplicationDeployer(
        economics=token_economics,
        registry=test_registry,
        staking_interface=threshold_staking.address)
    pre_application_deployer.deploy(transacting_power=transacting_power)

    subscription_manager_deployer = SubscriptionManagerDeployer(
        economics=token_economics, registry=test_registry)
    subscription_manager_deployer.deploy(transacting_power=transacting_power)
Exemplo n.º 16
0
def _make_agency(testerchain):
    """
    Launch the big three contracts on provided chain,
    make agents for each and return them.
    """
    origin = testerchain.etherbase_account

    token_deployer = NucypherTokenDeployer(blockchain=testerchain,
                                           deployer_address=origin)
    token_deployer.deploy()

    staking_escrow_deployer = StakingEscrowDeployer(deployer_address=origin,
                                                    blockchain=testerchain)
    staking_escrow_deployer.deploy(
        secret_hash=os.urandom(DispatcherDeployer.DISPATCHER_SECRET_LENGTH))

    policy_manager_deployer = PolicyManagerDeployer(deployer_address=origin,
                                                    blockchain=testerchain)
    policy_manager_deployer.deploy(
        secret_hash=os.urandom(DispatcherDeployer.DISPATCHER_SECRET_LENGTH))

    adjudicator_deployer = AdjudicatorDeployer(deployer_address=origin,
                                               blockchain=testerchain)
    adjudicator_deployer.deploy(
        secret_hash=os.urandom(DispatcherDeployer.DISPATCHER_SECRET_LENGTH))

    token_agent = token_deployer.make_agent()  # 1 Token
    staking_agent = staking_escrow_deployer.make_agent()  # 2 Miner Escrow
    policy_agent = policy_manager_deployer.make_agent()  # 3 Policy Agent
    _adjudicator_agent = adjudicator_deployer.make_agent()  # 4 Adjudicator

    # TODO: Perhaps we should get rid of returning these agents here.
    # What's important is deploying and creating the first agent for each contract,
    # and since agents are singletons, in tests it's only necessary to call the agent
    # constructor again to receive the existing agent.
    #
    # For example:
    #     staking_agent = StakingEscrowAgent()
    #
    # This is more clear than how we currently obtain an agent instance in tests:
    #     _, staking_agent, _ = agency
    #
    # Other advantages is that it's closer to how agents should be use (i.e., there
    # are no fixtures IRL) and it's more extensible (e.g., AdjudicatorAgent)

    return token_agent, staking_agent, policy_agent
Exemplo n.º 17
0
def three_agents(testerchain):
    """
    Musketeers, if you will.
    Launch the big three contracts on provided chain,
    make agents for each and return them.
    """
    """Launch all Nucypher ethereum contracts"""
    origin, *everybody_else = testerchain.interface.w3.eth.accounts

    token_deployer = NucypherTokenDeployer(blockchain=testerchain,
                                           deployer_address=origin)
    token_deployer.arm()
    token_deployer.deploy()

    token_agent = token_deployer.make_agent()

    miner_escrow_deployer = MinerEscrowDeployer(token_agent=token_agent,
                                                deployer_address=origin)
    miner_escrow_deployer.arm()
    miner_escrow_deployer.deploy()

    miner_agent = miner_escrow_deployer.make_agent()

    policy_manager_deployer = PolicyManagerDeployer(miner_agent=miner_agent,
                                                    deployer_address=origin)
    policy_manager_deployer.arm()
    policy_manager_deployer.deploy()

    policy_agent = policy_manager_deployer.make_agent()

    return token_agent, miner_agent, policy_agent
Exemplo n.º 18
0
def test_nucypher_contract_compiled(testerchain, test_registry):
    # Ensure that solidity smart contacts are available, post-compile.
    origin, *everybody_else = testerchain.client.accounts

    token_contract_identifier = NucypherTokenDeployer(registry=test_registry, deployer_address=origin).contract_name
    assert token_contract_identifier in testerchain._raw_contract_cache
    token_data = testerchain._raw_contract_cache[token_contract_identifier]
    assert len(token_data) == 1
    assert "v0.0.0" in token_data
Exemplo n.º 19
0
def test_adjudicator_deployer(testerchain, application_economics,
                              deployment_progress, test_registry):

    origin = testerchain.etherbase_account
    tpower = TransactingPower(account=origin,
                              signer=Web3Signer(testerchain.client))

    token_deployer = NucypherTokenDeployer(registry=test_registry)
    token_deployer.deploy(transacting_power=tpower)

    staking_escrow_deployer = StakingEscrowDeployer(registry=test_registry)

    staking_escrow_deployer.deploy(transacting_power=tpower)
    staking_agent = staking_escrow_deployer.make_agent()  # 2 Staker Escrow

    deployer = AdjudicatorDeployer(registry=test_registry)
    deployment_receipts = deployer.deploy(progress=deployment_progress,
                                          transacting_power=tpower)

    # deployment steps must match expected number of steps
    assert deployment_progress.num_steps == len(
        deployer.deployment_steps) == len(deployment_receipts) == 2

    for step in deployer.deployment_steps:
        assert deployment_receipts[step]['status'] == 1

    # Create an AdjudicatorAgent instance
    adjudicator_agent = deployer.make_agent()

    # Check default Adjudicator deployment parameters
    assert tpower.account != staking_agent.contract_address
    assert adjudicator_agent.staking_escrow_contract == staking_agent.contract_address
    assert adjudicator_agent.hash_algorithm == application_economics.hash_algorithm
    assert adjudicator_agent.base_penalty == application_economics.base_penalty
    assert adjudicator_agent.penalty_history_coefficient == application_economics.penalty_history_coefficient
    assert adjudicator_agent.percentage_penalty_coefficient == application_economics.percentage_penalty_coefficient
    assert adjudicator_agent.reward_coefficient == application_economics.reward_coefficient

    # Retrieve the AdjudicatorAgent singleton
    some_policy_agent = AdjudicatorAgent(registry=test_registry)
    assert adjudicator_agent == some_policy_agent  # __eq__

    # Compare the contract address for equality
    assert adjudicator_agent.contract_address == some_policy_agent.contract_address
def test_policy_manager_deployer(testerchain):
    origin, *everybody_else = testerchain.interface.w3.eth.accounts

    token_deployer = NucypherTokenDeployer(blockchain=testerchain,
                                           deployer_address=origin)

    token_deployer.deploy()

    token_agent = token_deployer.make_agent()  # 1: Token

    miners_escrow_secret = os.urandom(DISPATCHER_SECRET_LENGTH)
    miner_escrow_deployer = MinerEscrowDeployer(
        deployer_address=origin,
        secret_hash=testerchain.interface.w3.keccak(miners_escrow_secret))

    miner_escrow_deployer.deploy()

    miner_agent = miner_escrow_deployer.make_agent()  # 2 Miner Escrow

    policy_manager_secret = os.urandom(DISPATCHER_SECRET_LENGTH)
    deployer = PolicyManagerDeployer(
        deployer_address=origin,
        secret_hash=testerchain.interface.w3.keccak(policy_manager_secret))

    deployment_txhashes = deployer.deploy()
    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
    some_policy_agent = PolicyAgent()
    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__
def test_nucypher_contract_compiled(testerchain, test_registry):
    """Ensure that solidity smart contacts are available, post-compile."""
    origin, *everybody_else = testerchain.client.accounts

    token_contract_identifier = NucypherTokenDeployer(
        registry=test_registry).contract_name
    assert token_contract_identifier in testerchain._raw_contract_cache
    token_data = testerchain._raw_contract_cache[token_contract_identifier]
    assert len(token_data) == 1
    assert DEFAULT_VERSION_STRING in token_data
Exemplo n.º 22
0
def test_staking_interface_deployer(testerchain, deployment_progress,
                                    test_registry):

    #
    # Setup
    #

    origin = testerchain.etherbase_account

    token_deployer = NucypherTokenDeployer(deployer_address=origin,
                                           registry=test_registry)
    token_deployer.deploy()

    staking_escrow_deployer = StakingEscrowDeployer(deployer_address=origin,
                                                    registry=test_registry)
    staking_escrow_deployer.deploy(secret_hash=INSECURE_DEPLOYMENT_SECRET_HASH)

    policy_manager_deployer = PolicyManagerDeployer(deployer_address=origin,
                                                    registry=test_registry)
    policy_manager_deployer.deploy(secret_hash=INSECURE_DEPLOYMENT_SECRET_HASH)

    adjudicator_deployer = AdjudicatorDeployer(deployer_address=origin,
                                               registry=test_registry)
    adjudicator_deployer.deploy(secret_hash=INSECURE_DEPLOYMENT_SECRET_HASH)

    #
    # Test
    #

    staking_interface_deployer = StakingInterfaceDeployer(
        deployer_address=origin, registry=test_registry)
    staking_interface_receipts = staking_interface_deployer.deploy(
        secret_hash=INSECURE_DEPLOYMENT_SECRET_HASH,
        progress=deployment_progress)

    # deployment steps must match expected number of steps
    assert deployment_progress.num_steps == len(
        staking_interface_deployer.deployment_steps) == 2
    assert len(staking_interface_receipts) == 2

    for step in staking_interface_deployer.deployment_steps:
        assert staking_interface_receipts[step]['status'] == 1
Exemplo n.º 23
0
def _make_agency(testerchain, test_registry, token_economics,
                 deployer_transacting_power):

    transacting_power = deployer_transacting_power

    token_deployer = NucypherTokenDeployer(economics=token_economics,
                                           registry=test_registry)
    token_deployer.deploy(transacting_power=transacting_power)

    staking_escrow_deployer = StakingEscrowDeployer(economics=token_economics,
                                                    registry=test_registry)
    staking_escrow_deployer.deploy(deployment_mode=INIT,
                                   transacting_power=transacting_power)

    policy_manager_deployer = PolicyManagerDeployer(economics=token_economics,
                                                    registry=test_registry)
    policy_manager_deployer.deploy(transacting_power=transacting_power)

    adjudicator_deployer = AdjudicatorDeployer(economics=token_economics,
                                               registry=test_registry)
    adjudicator_deployer.deploy(transacting_power=transacting_power)

    staking_interface_deployer = StakingInterfaceDeployer(
        economics=token_economics, registry=test_registry)
    staking_interface_deployer.deploy(transacting_power=transacting_power)

    worklock_deployer = WorklockDeployer(economics=token_economics,
                                         registry=test_registry)
    worklock_deployer.deploy(transacting_power=transacting_power)

    staking_escrow_deployer = StakingEscrowDeployer(economics=token_economics,
                                                    registry=test_registry)
    staking_escrow_deployer.deploy(deployment_mode=FULL,
                                   transacting_power=transacting_power)

    # Set additional parameters
    minimum, default, maximum = FEE_RATE_RANGE
    policy_agent = policy_manager_deployer.make_agent()
    txhash = policy_agent.contract.functions.setFeeRateRange(
        minimum, default, maximum).transact()
    testerchain.wait_for_receipt(txhash)
Exemplo n.º 24
0
def test_policy_manager_deployer(testerchain):
    origin, *everybody_else = testerchain.client.accounts

    token_deployer = NucypherTokenDeployer(blockchain=testerchain,
                                           deployer_address=origin)

    token_deployer.deploy()

    stakers_escrow_secret = os.urandom(
        DispatcherDeployer.DISPATCHER_SECRET_LENGTH)
    staking_escrow_deployer = StakingEscrowDeployer(deployer_address=origin,
                                                    blockchain=testerchain)

    staking_escrow_deployer.deploy(secret_hash=keccak(stakers_escrow_secret))

    policy_manager_secret = os.urandom(
        DispatcherDeployer.DISPATCHER_SECRET_LENGTH)
    deployer = PolicyManagerDeployer(deployer_address=origin,
                                     blockchain=testerchain)

    deployment_txhashes = deployer.deploy(
        secret_hash=keccak(policy_manager_secret))
    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 PolicyAgent
    policy_agent = deployer.make_agent()

    # TODO: #1102 - Check that StakingEscrow contract address and public parameters are correct

    # Retrieve the PolicyAgent singleton
    some_policy_agent = PolicyAgent()
    assert policy_agent == some_policy_agent  # __eq__

    # Compare the contract address for equality
    assert policy_agent.contract_address == some_policy_agent.contract_address
Exemplo n.º 25
0
def test_deploy_ethereum_contracts(chain):
    """
    Launch all ethereum contracts:
    - NuCypherToken
    - PolicyManager
    - MinersEscrow
    - UserEscrow
    - Issuer
    """

    token_deployer = NucypherTokenDeployer(blockchain=chain)
    token_deployer.arm()
    token_deployer.deploy()

    token_agent = NucypherTokenAgent(blockchain=chain)

    miner_escrow_deployer = MinerEscrowDeployer(token_agent=token_agent)
    miner_escrow_deployer.arm()
    miner_escrow_deployer.deploy()

    miner_agent = MinerAgent(token_agent=token_agent)

    policy_manager_contract = PolicyManagerDeployer(miner_agent=miner_agent)
    policy_manager_contract.arm()
    policy_manager_contract.deploy()
Exemplo n.º 26
0
def test_deploy_ethereum_contracts(testerchain):
    """
    A bare minimum nucypher deployment fixture.
    """
    origin, *everybody_else = testerchain.interface.w3.eth.accounts

    token_deployer = NucypherTokenDeployer(blockchain=testerchain,
                                           deployer_address=origin)
    token_deployer.arm()
    token_deployer.deploy()

    token_agent = NucypherTokenAgent(blockchain=testerchain)

    miners_escrow_secret = os.urandom(constants.DISPATCHER_SECRET_LENGTH)
    miner_escrow_deployer = MinerEscrowDeployer(
        token_agent=token_agent,
        deployer_address=origin,
        secret_hash=testerchain.interface.w3.sha3(miners_escrow_secret))
    miner_escrow_deployer.arm()
    miner_escrow_deployer.deploy()

    miner_agent = MinerAgent(token_agent=token_agent)

    policy_manager_secret = os.urandom(constants.DISPATCHER_SECRET_LENGTH)
    policy_manager_deployer = PolicyManagerDeployer(
        miner_agent=miner_agent,
        deployer_address=origin,
        secret_hash=testerchain.interface.w3.sha3(policy_manager_secret))
    policy_manager_deployer.arm()
    policy_manager_deployer.deploy()

    policy_agent = policy_manager_deployer.make_agent()
Exemplo n.º 27
0
def test_deploy_ethereum_contracts(testerchain):
    """
    Launch all ethereum contracts:
    - NuCypherToken
    - PolicyManager
    - MinersEscrow
    - UserEscrow
    - Issuer
    """
    origin, *everybody_else = testerchain.interface.w3.eth.accounts

    token_deployer = NucypherTokenDeployer(blockchain=testerchain,
                                           deployer_address=origin)
    token_deployer.arm()
    token_deployer.deploy()

    token_agent = NucypherTokenAgent(blockchain=testerchain)

    miner_escrow_deployer = MinerEscrowDeployer(token_agent=token_agent,
                                                deployer_address=origin)
    miner_escrow_deployer.arm()
    miner_escrow_deployer.deploy()

    miner_agent = MinerAgent(token_agent=token_agent)

    policy_manager_deployer = PolicyManagerDeployer(miner_agent=miner_agent,
                                                    deployer_address=origin)
    policy_manager_deployer.arm()
    policy_manager_deployer.deploy()

    policy_agent = policy_manager_deployer.make_agent()
Exemplo n.º 28
0
def test_token_deployer_and_agent(testerchain):
    origin, *everybody_else = testerchain.interface.w3.eth.accounts

    # The big day...
    token_deployer = NucypherTokenDeployer(blockchain=testerchain,
                                           deployer_address=origin)

    token_deployer.deploy()

    secret_hash = os.urandom(32)
    deployer = MinerEscrowDeployer(blockchain=testerchain,
                                   deployer_address=origin,
                                   secret_hash=secret_hash)

    deployment_txhashes = deployer.deploy()

    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
    miner_agent = deployer.make_agent()
    miner_escrow_contract = miner_agent.contract

    expected_token_supply = miner_escrow_contract.functions.totalSupply().call(
    )
    assert expected_token_supply == miner_agent.contract.functions.totalSupply(
    ).call()

    # Retrieve the token from the blockchain
    same_miner_agent = MinerAgent()

    # Compare the contract address for equality
    assert miner_agent.contract_address == same_miner_agent.contract_address
    assert miner_agent == same_miner_agent  # __eq__

    testerchain.interface.registry.clear()
Exemplo n.º 29
0
def test_adjudicator_deployer(testerchain, slashing_economics):
    origin = testerchain.etherbase_account

    token_deployer = NucypherTokenDeployer(blockchain=testerchain, deployer_address=origin)
    token_deployer.deploy()

    stakers_escrow_secret = os.urandom(DispatcherDeployer.DISPATCHER_SECRET_LENGTH)
    staking_escrow_deployer = StakingEscrowDeployer(deployer_address=origin, blockchain=testerchain)

    staking_escrow_deployer.deploy(secret_hash=keccak(stakers_escrow_secret))
    staking_agent = staking_escrow_deployer.make_agent()  # 2 Staker Escrow

    deployer = AdjudicatorDeployer(deployer_address=origin, blockchain=testerchain)
    deployment_txhashes = deployer.deploy(secret_hash=os.urandom(DispatcherDeployer.DISPATCHER_SECRET_LENGTH))

    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 an AdjudicatorAgent instance
    adjudicator_agent = deployer.make_agent()

    # Check default Adjudicator deployment parameters
    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
    some_policy_agent = AdjudicatorAgent()
    assert adjudicator_agent == some_policy_agent  # __eq__

    # Compare the contract address for equality
    assert adjudicator_agent.contract_address == some_policy_agent.contract_address
Exemplo n.º 30
0
def test_token_deployer_and_agent(chain):

    # Trying to get token from blockchain before it's been published fails
    with pytest.raises(Registrar.UnknownContract):
        NucypherTokenAgent(blockchain=chain)

    # The big day...
    deployer = NucypherTokenDeployer(blockchain=chain)

    with pytest.raises(NucypherTokenDeployer.ContractDeploymentError):
        deployer.deploy()

    # Token must be armed before deploying to the blockchain
    deployer.arm()
    deployer.deploy()

    # Create a token instance
    token_agent = NucypherTokenAgent(blockchain=chain)

    # Make sure we got the name right
    deployer_contract_identifier = NucypherTokenDeployer._contract_name
    assert 'NuCypherToken' == deployer_contract_identifier

    # Ensure the contract is deployed and has a valid blockchain address
    assert len(token_agent.contract_address) == 42

    # Check that the token contract has tokens
    assert token_agent.contract.functions.totalSupply().call() != 0
    # assert token().totalSupply() == int(1e9) * _M     # TODO

    # Retrieve the token from the blockchain
    same_token_agent = NucypherTokenAgent(blockchain=chain)

    # Compare the contract address for equality
    assert token_agent.contract_address == same_token_agent.contract_address
    assert token_agent == same_token_agent  # __eq__