mirror of https://github.com/nucypher/nucypher.git
Bare deployment and Retargeting tests for deployer and CLI
parent
2567bdd3ec
commit
0a713c1e51
|
@ -80,21 +80,19 @@ def test_staking_escrow_has_dispatcher(staking_escrow_deployer, testerchain, tes
|
|||
assert target == existing_bare_contract.address
|
||||
|
||||
|
||||
def test_upgrade(testerchain, test_registry):
|
||||
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)
|
||||
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
|
||||
|
||||
|
@ -162,6 +160,20 @@ def test_deploy_bare_upgradeable_contract_deployment(testerchain, test_registry,
|
|||
assert new_number_of_proxy_enrollments == old_number_of_proxy_enrollments
|
||||
|
||||
|
||||
def test_deployer_version_management(testerchain, test_registry, token_economics):
|
||||
deployer = StakingEscrowDeployer(deployer_address=testerchain.etherbase_account,
|
||||
registry=test_registry,
|
||||
economics=token_economics)
|
||||
|
||||
untargeted_deployment = deployer.get_latest_enrollment(registry=test_registry)
|
||||
latest_targeted_deployment = deployer.get_principal_contract(registry=test_registry)
|
||||
|
||||
proxy_deployer = deployer.get_proxy_deployer(registry=test_registry, provider_uri=TEST_PROVIDER_URI)
|
||||
proxy_target = proxy_deployer.target_contract.address
|
||||
assert latest_targeted_deployment.address == proxy_target
|
||||
assert untargeted_deployment.address != latest_targeted_deployment.address
|
||||
|
||||
|
||||
def test_manual_proxy_retargeting(testerchain, test_registry, token_economics):
|
||||
|
||||
deployer = StakingEscrowDeployer(registry=test_registry,
|
||||
|
@ -169,14 +181,10 @@ def test_manual_proxy_retargeting(testerchain, test_registry, token_economics):
|
|||
economics=token_economics)
|
||||
|
||||
# Get Proxy-Direct
|
||||
existing_bare_contract = deployer.get_principal_contract(registry=test_registry, provider_uri=TEST_PROVIDER_URI)
|
||||
proxy_deployer = StakingEscrowDeployer._proxy_deployer(registry=test_registry,
|
||||
target_contract=existing_bare_contract,
|
||||
deployer_address=testerchain.etherbase_account,
|
||||
bare=True) # acquire agency for the proxy itself.
|
||||
proxy_deployer = deployer.get_proxy_deployer(registry=test_registry, provider_uri=TEST_PROVIDER_URI)
|
||||
|
||||
# Re-Deploy Staking Escrow
|
||||
old_target = proxy_deployer.contract.functions.target().call()
|
||||
old_target = proxy_deployer.target_contract.address
|
||||
|
||||
old_secret = bytes("...maybe not.", encoding='utf-8')
|
||||
new_secret = keccak_digest(bytes('thistimeforsure', encoding='utf-8'))
|
||||
|
|
|
@ -219,9 +219,9 @@ def test_upgrade_contracts(click_runner, registry_filepath, testerchain):
|
|||
use_proxy_address=False)
|
||||
|
||||
# Ensure the proxy targets the current deployed contract
|
||||
proxy = testerchain.get_proxy(registry=registry,
|
||||
target_address=real_old_contract.address,
|
||||
proxy_name=proxy_name)
|
||||
proxy = testerchain.get_proxy_contract(registry=registry,
|
||||
target_address=real_old_contract.address,
|
||||
proxy_name=proxy_name)
|
||||
targeted_address = proxy.functions.target().call()
|
||||
assert targeted_address == real_old_contract.address
|
||||
|
||||
|
@ -274,9 +274,9 @@ def test_upgrade_contracts(click_runner, registry_filepath, testerchain):
|
|||
assert old_address != new_address
|
||||
|
||||
# Ensure the proxy now targets the new deployment
|
||||
proxy = testerchain.get_proxy(registry=registry,
|
||||
target_address=new_address,
|
||||
proxy_name=proxy_name)
|
||||
proxy = testerchain.get_proxy_contract(registry=registry,
|
||||
target_address=new_address,
|
||||
proxy_name=proxy_name)
|
||||
targeted_address = proxy.functions.target().call()
|
||||
assert targeted_address != old_address
|
||||
assert targeted_address == new_address
|
||||
|
@ -323,13 +323,13 @@ def test_rollback(click_runner, testerchain, registry_filepath):
|
|||
|
||||
# Ensure the proxy targets the rollback target (previous version)
|
||||
with pytest.raises(BlockchainInterface.UnknownContract):
|
||||
testerchain.get_proxy(registry=registry,
|
||||
target_address=current_target_address,
|
||||
proxy_name='Dispatcher')
|
||||
testerchain.get_proxy_contract(registry=registry,
|
||||
target_address=current_target_address,
|
||||
proxy_name='Dispatcher')
|
||||
|
||||
proxy = testerchain.get_proxy(registry=registry,
|
||||
target_address=rollback_target_address,
|
||||
proxy_name='Dispatcher')
|
||||
proxy = testerchain.get_proxy_contract(registry=registry,
|
||||
target_address=rollback_target_address,
|
||||
proxy_name='Dispatcher')
|
||||
|
||||
# Deeper - Ensure the proxy targets the old deployment on-chain
|
||||
targeted_address = proxy.functions.target().call()
|
||||
|
|
|
@ -7,9 +7,11 @@ from nucypher.blockchain.eth.agents import (
|
|||
ContractAgency
|
||||
)
|
||||
from nucypher.blockchain.eth.constants import STAKING_ESCROW_CONTRACT_NAME
|
||||
from nucypher.blockchain.eth.deployers import StakingEscrowDeployer
|
||||
from nucypher.blockchain.eth.registry import InMemoryContractRegistry, LocalContractRegistry
|
||||
from nucypher.cli.deploy import deploy
|
||||
from nucypher.utilities.sandbox.constants import TEST_PROVIDER_URI, MOCK_REGISTRY_FILEPATH
|
||||
from nucypher.utilities.sandbox.constants import TEST_PROVIDER_URI, MOCK_REGISTRY_FILEPATH, \
|
||||
INSECURE_DEVELOPMENT_PASSWORD, INSECURE_DEPLOYMENT_SECRET_PLAINTEXT
|
||||
|
||||
registry_filepath = '/tmp/nucypher-test-registry.json'
|
||||
|
||||
|
@ -18,7 +20,7 @@ registry_filepath = '/tmp/nucypher-test-registry.json'
|
|||
def temp_registry(testerchain, test_registry, agency):
|
||||
# Disable registry fetching, use the mock one instead
|
||||
InMemoryContractRegistry.download_latest_publication = lambda: registry_filepath
|
||||
test_registry.commit(filepath=registry_filepath)
|
||||
test_registry.commit(filepath=registry_filepath, overwrite=True)
|
||||
|
||||
|
||||
def test_nucypher_deploy_inspect_no_deployments(click_runner, testerchain):
|
||||
|
@ -104,3 +106,39 @@ def test_transfer_ownership(click_runner, testerchain, agency):
|
|||
assert result.exit_code == 0
|
||||
assert staking_agent.owner != maclane
|
||||
assert staking_agent.owner == michwill
|
||||
|
||||
|
||||
def test_bare_contract_deployment(click_runner, test_registry):
|
||||
|
||||
command = ('contracts',
|
||||
'--contract-name', StakingEscrowDeployer.contract_name,
|
||||
'--bare',
|
||||
'--provider', TEST_PROVIDER_URI,
|
||||
'--registry-outfile', registry_filepath,
|
||||
'--poa')
|
||||
|
||||
user_input = '0\n' + 'Y\n' + 'DEPLOY'
|
||||
result = click_runner.invoke(deploy, command, input=user_input, catch_exceptions=False)
|
||||
assert result.exit_code == 0
|
||||
|
||||
|
||||
def test_manual_proxy_retargeting(testerchain, click_runner, test_registry, token_economics):
|
||||
local_registry = LocalContractRegistry(filepath=registry_filepath)
|
||||
deployer = StakingEscrowDeployer(deployer_address=testerchain.etherbase_account,
|
||||
registry=local_registry,
|
||||
economics=token_economics)
|
||||
|
||||
untargeted_deployment = deployer.get_latest_enrollment(registry=local_registry)
|
||||
command = ('upgrade',
|
||||
'--retarget',
|
||||
'--contract-name', StakingEscrowDeployer.contract_name,
|
||||
'--target-address', untargeted_deployment.address,
|
||||
'--provider', TEST_PROVIDER_URI,
|
||||
'--registry-infile', registry_filepath,
|
||||
'--registry-outfile', registry_filepath,
|
||||
'--poa')
|
||||
|
||||
old_secret = INSECURE_DEPLOYMENT_SECRET_PLAINTEXT.decode()
|
||||
user_input = '0\n' + 'Y\n' + f'{old_secret}\n' + (f'{INSECURE_DEVELOPMENT_PASSWORD}\n' * 2) + 'Y\n'
|
||||
result = click_runner.invoke(deploy, command, input=user_input, catch_exceptions=False)
|
||||
assert result.exit_code == 0
|
||||
|
|
Loading…
Reference in New Issue