示例#1
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]
示例#2
0
def test_rollback(testerchain, test_registry, transacting_power):

    deployer = StakingEscrowDeployer(registry=test_registry)

    staking_agent = ContractAgency.get_agent(StakingEscrowAgent,
                                             registry=test_registry)
    current_target = staking_agent.contract.functions.target().call()

    # Let's do one more upgrade
    receipts = deployer.upgrade(ignore_deployed=True,
                                confirmations=0,
                                transacting_power=transacting_power)

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

    old_target = current_target
    current_target = staking_agent.contract.functions.target().call()
    assert current_target != old_target

    # It's time to rollback.
    receipt = deployer.rollback(transacting_power=transacting_power)
    assert receipt['status'] == 1

    new_target = staking_agent.contract.functions.target().call()
    assert new_target != current_target
    assert new_target == old_target
def test_upgrade(testerchain, test_registry, token_economics, transacting_power):

    deployer = StakingEscrowDeployer(registry=test_registry,economics=token_economics)

    receipts = deployer.upgrade(ignore_deployed=True, confirmations=0, transacting_power=transacting_power)
    for title, receipt in receipts.items():
        assert receipt['status'] == 1
示例#4
0
def test_rollback(testerchain, test_registry, transacting_power,
                  threshold_staking):

    deployer = StakingEscrowDeployer(
        staking_interface=threshold_staking.address, registry=test_registry)

    contract = testerchain.get_contract_by_name(
        registry=test_registry,
        contract_name=deployer.contract_name,
        proxy_name=DispatcherDeployer.contract_name,
        use_proxy_address=True)

    current_target = contract.functions.target().call()

    # Let's do one more upgrade
    receipts = deployer.upgrade(ignore_deployed=True,
                                confirmations=0,
                                transacting_power=transacting_power)

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

    old_target = current_target
    current_target = contract.functions.target().call()
    assert current_target != old_target

    # It's time to rollback.
    receipt = deployer.rollback(transacting_power=transacting_power)
    assert receipt['status'] == 1

    new_target = contract.functions.target().call()
    assert new_target != current_target
    assert new_target == old_target
示例#5
0
def test_upgrade(session_testerchain):
    wrong_secret = b"on second thoughts..."
    old_secret = bytes(STAKING_ESCROW_DEPLOYMENT_SECRET, encoding='utf-8')
    new_secret_hash = keccak(b'new'+old_secret)

    deployer = StakingEscrowDeployer(blockchain=session_testerchain,
                                     deployer_address=session_testerchain.etherbase_account)

    with pytest.raises(deployer.ContractDeploymentError):
        deployer.upgrade(existing_secret_plaintext=wrong_secret,
                         new_secret_hash=new_secret_hash)

    receipts = deployer.upgrade(existing_secret_plaintext=old_secret,
                                new_secret_hash=new_secret_hash)

    for title, receipt in receipts.items():
        assert receipt['status'] == 1
示例#6
0
def test_upgrade(testerchain, test_registry, token_economics):

    deployer = StakingEscrowDeployer(registry=test_registry,
                                     economics=token_economics,
                                     deployer_address=testerchain.etherbase_account)

    receipts = deployer.upgrade(ignore_deployed=True)
    for title, receipt in receipts.items():
        assert receipt['status'] == 1
示例#7
0
def test_upgrade(testerchain, test_registry, token_economics):
    wrong_secret = b"on second thoughts..."
    old_secret = bytes(STAKING_ESCROW_DEPLOYMENT_SECRET, encoding='utf-8')
    new_secret_hash = keccak(b'new' + old_secret)

    deployer = StakingEscrowDeployer(
        registry=test_registry,
        economics=token_economics,
        deployer_address=testerchain.etherbase_account)

    with pytest.raises(deployer.ContractDeploymentError):
        deployer.upgrade(existing_secret_plaintext=wrong_secret,
                         new_secret_hash=new_secret_hash)

    receipts = deployer.upgrade(existing_secret_plaintext=old_secret,
                                new_secret_hash=new_secret_hash,
                                ignore_deployed=True)
    for title, receipt in receipts.items():
        assert receipt['status'] == 1
示例#8
0
def test_upgrade(testerchain, test_registry, application_economics,
                 transacting_power, threshold_staking):

    deployer = StakingEscrowDeployer(
        staking_interface=threshold_staking.address,
        registry=test_registry,
        economics=application_economics)

    receipts = deployer.upgrade(ignore_deployed=True,
                                confirmations=0,
                                transacting_power=transacting_power)
    for title, receipt in receipts.items():
        assert receipt['status'] == 1
示例#9
0
def test_rollback(testerchain, test_registry):
    old_secret = bytes('new' + STAKING_ESCROW_DEPLOYMENT_SECRET,
                       encoding='utf-8')
    new_secret_hash = keccak(text="third time's the charm")

    deployer = StakingEscrowDeployer(
        registry=test_registry, deployer_address=testerchain.etherbase_account)

    staking_agent = ContractAgency.get_agent(StakingEscrowAgent,
                                             registry=test_registry)
    current_target = staking_agent.contract.functions.target().call()

    # Let's do one more upgrade
    receipts = deployer.upgrade(existing_secret_plaintext=old_secret,
                                new_secret_hash=new_secret_hash,
                                ignore_deployed=True)

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

    old_target = current_target
    current_target = staking_agent.contract.functions.target().call()
    assert current_target != old_target

    # It's time to rollback. But first...
    wrong_secret = b"WRONG!!"
    with pytest.raises(deployer.ContractDeploymentError):
        deployer.rollback(existing_secret_plaintext=wrong_secret,
                          new_secret_hash=new_secret_hash)

    # OK, *now* is time for rollback
    old_secret = b"third time's the charm"
    new_secret_hash = keccak(text="...maybe not.")
    receipt = deployer.rollback(existing_secret_plaintext=old_secret,
                                new_secret_hash=new_secret_hash)

    assert receipt['status'] == 1

    new_target = staking_agent.contract.functions.target().call()
    assert new_target != current_target
    assert new_target == old_target
def test_upgradeability(temp_dir_path):
    # Prepare remote source for compilation
    download_github_dir(GITHUB_SOURCE_LINK, temp_dir_path)

    # Prepare the blockchain
    TesterBlockchain.SOURCES = [
        SourceBundle(base_path=SOLIDITY_SOURCE_ROOT,
                     other_paths=(TEST_SOLIDITY_SOURCE_ROOT, )),
        SourceBundle(base_path=Path(temp_dir_path))
    ]

    eth_provider_uri = 'tester://pyevm/2'  # TODO: Testerchain caching Issues
    try:
        blockchain_interface = TesterBlockchain(gas_strategy='free')
        blockchain_interface.eth_provider_uri = eth_provider_uri
        blockchain_interface.connect()
        origin = blockchain_interface.client.accounts[0]
        BlockchainInterfaceFactory.register_interface(
            interface=blockchain_interface)
        transacting_power = TransactingPower(
            password=INSECURE_DEVELOPMENT_PASSWORD,
            signer=Web3Signer(blockchain_interface.client),
            account=origin)

        economics = make_token_economics(blockchain_interface)

        # Check contracts with multiple versions
        contract_name = StakingEscrowDeployer.contract_name
        skip_staking_escrow_test = skip_test(blockchain_interface,
                                             contract_name)

        if skip_staking_escrow_test:
            return

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

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

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

        if not skip_staking_escrow_test:
            economics.worklock_supply = economics.maximum_allowed_locked
            worklock_deployer = WorklockDeployer(registry=registry,
                                                 economics=economics)
            worklock_deployer.deploy(transacting_power=transacting_power)

        staking_escrow_deployer = StakingEscrowDeployer(registry=registry,
                                                        economics=economics)
        deploy_base_contract(blockchain_interface,
                             staking_escrow_deployer,
                             transacting_power=transacting_power,
                             skipt_test=skip_staking_escrow_test)

        if not skip_staking_escrow_test:
            prepare_staker(blockchain_interface=blockchain_interface,
                           deployer=staking_escrow_deployer,
                           transacting_power=transacting_power)
            staking_escrow_deployer.upgrade(
                transacting_power=transacting_power,
                contract_version="latest",
                confirmations=0)

    finally:
        # Unregister interface  # TODO: Move to method?
        with contextlib.suppress(KeyError):
            del BlockchainInterfaceFactory._interfaces[eth_provider_uri]
示例#11
0
def test_upgradeability(temp_dir_path):
    # Prepare remote source for compilation
    download_github_dir(GITHUB_SOURCE_LINK, temp_dir_path)

    # Prepare the blockchain
    BlockchainDeployerInterface.SOURCES = [
        SourceBundle(base_path=SOLIDITY_SOURCE_ROOT),
        SourceBundle(base_path=Path(temp_dir_path))
    ]

    provider_uri = 'tester://pyevm/2'  # TODO: Testerchain caching Issues
    try:
        blockchain_interface = BlockchainDeployerInterface(
            provider_uri=provider_uri, gas_strategy='free')
        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()

        economics = make_token_economics(blockchain_interface)

        # Check contracts with multiple versions
        contract_name = AdjudicatorDeployer.contract_name
        skip_adjudicator_test = skip_test(blockchain_interface, contract_name)
        contract_name = StakingEscrowDeployer.contract_name
        skip_staking_escrow_test = skip_test(blockchain_interface,
                                             contract_name)
        contract_name = PolicyManagerDeployer.contract_name
        skip_policy_manager_test = skip_test(blockchain_interface,
                                             contract_name)

        if not skip_adjudicator_test and not skip_staking_escrow_test and not skip_policy_manager_test:
            return

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

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

        staking_escrow_deployer = StakingEscrowDeployer(
            registry=registry, deployer_address=origin, economics=economics)
        staking_escrow_deployer.deploy(deployment_mode=constants.INIT)

        policy_manager_deployer = PolicyManagerDeployer(
            registry=registry, deployer_address=origin, economics=economics)
        deploy_base_contract(blockchain_interface,
                             policy_manager_deployer,
                             skipt_test=skip_policy_manager_test)

        adjudicator_deployer = AdjudicatorDeployer(registry=registry,
                                                   deployer_address=origin,
                                                   economics=economics)
        deploy_base_contract(blockchain_interface,
                             adjudicator_deployer,
                             skipt_test=skip_adjudicator_test)

        if skip_staking_escrow_test:
            worklock_deployer = WorklockDeployer(registry=registry,
                                                 deployer_address=origin,
                                                 economics=economics)
            worklock_deployer.deploy()

        staking_escrow_deployer = StakingEscrowDeployer(
            registry=registry, deployer_address=origin, economics=economics)
        deploy_base_contract(blockchain_interface,
                             staking_escrow_deployer,
                             skipt_test=skip_staking_escrow_test)

        if not skip_staking_escrow_test:
            # TODO prepare at least one staker before calling upgrade
            staking_escrow_deployer.upgrade(contract_version="latest",
                                            confirmations=0)

        if not skip_policy_manager_test:
            policy_manager_deployer.upgrade(contract_version="latest",
                                            confirmations=0)

        if not skip_adjudicator_test:
            adjudicator_deployer.upgrade(contract_version="latest",
                                         confirmations=0)

    finally:
        # Unregister interface  # TODO: Move to method?
        with contextlib.suppress(KeyError):
            del BlockchainInterfaceFactory._interfaces[provider_uri]