Move NULL_ADDRESS constant from BlockchainInterface to the eth.constants module

pull/1790/head
David Núñez 2020-04-05 19:59:11 +02:00
parent 867e0b33b5
commit 7230aeac41
24 changed files with 101 additions and 107 deletions

View File

@ -35,8 +35,7 @@ from constant_sorrow.constants import (
from eth_tester.exceptions import TransactionFailed
from eth_utils import keccak, is_checksum_address, to_checksum_address, to_canonical_address
from twisted.logger import Logger
from web3 import Web3, IPCProvider
from web3.contract import ContractFunction
from web3 import Web3
from nucypher.blockchain.economics import StandardTokenEconomics, EconomicsFactory, BaseEconomics
from nucypher.blockchain.eth.agents import (
@ -49,8 +48,8 @@ from nucypher.blockchain.eth.agents import (
MultiSigAgent,
WorkLockAgent
)
from nucypher.blockchain.eth.decorators import only_me, save_receipt
from nucypher.blockchain.eth.decorators import validate_checksum_address
from nucypher.blockchain.eth.constants import NULL_ADDRESS
from nucypher.blockchain.eth.decorators import only_me, save_receipt, validate_checksum_address
from nucypher.blockchain.eth.deployers import (
NucypherTokenDeployer,
StakingEscrowDeployer,
@ -64,7 +63,6 @@ from nucypher.blockchain.eth.deployers import (
MultiSigDeployer
)
from nucypher.blockchain.eth.interfaces import BlockchainDeployerInterface, BlockchainInterfaceFactory
from nucypher.blockchain.eth.interfaces import BlockchainInterface
from nucypher.blockchain.eth.multisig import Authorization, Proposal
from nucypher.blockchain.eth.registry import (
AllocationRegistry,
@ -852,7 +850,7 @@ class Staker(NucypherTokenActor):
def to_dict(self) -> dict:
stake_info = [stake.to_stake_info() for stake in self.stakes]
worker_address = self.worker_address or BlockchainInterface.NULL_ADDRESS
worker_address = self.worker_address or NULL_ADDRESS
staker_funds = {'ETH': int(self.eth_balance), 'NU': int(self.token_balance)}
staker_payload = {'staker': self.checksum_address,
'balances': staker_funds,
@ -1099,7 +1097,7 @@ class Staker(NucypherTokenActor):
worker_address = self.staking_agent.get_worker_from_staker(staker_address=self.checksum_address)
self.__worker_address = worker_address
if self.__worker_address == BlockchainInterface.NULL_ADDRESS:
if self.__worker_address == NULL_ADDRESS:
return NO_WORKER_ASSIGNED.bool_value(False)
return self.__worker_address
@ -1110,7 +1108,7 @@ class Staker(NucypherTokenActor):
receipt = self.preallocation_escrow_agent.release_worker()
else:
receipt = self.staking_agent.release_worker(staker_address=self.checksum_address)
self.__worker_address = BlockchainInterface.NULL_ADDRESS
self.__worker_address = NULL_ADDRESS
return receipt
#
@ -1307,7 +1305,7 @@ class Worker(NucypherTokenActor):
ether_balance = client.get_balance(self.__worker_address)
# Bonding
if (not bonded) and (staking_address != BlockchainInterface.NULL_ADDRESS):
if (not bonded) and (staking_address != NULL_ADDRESS):
bonded = True
emitter.message(f"Worker is bonded to ({staking_address})!", color='green', bold=True)
@ -1317,7 +1315,7 @@ class Worker(NucypherTokenActor):
emitter.message(f"Worker is funded with {balance} ETH!", color='green', bold=True)
# Success and Escape
if staking_address != BlockchainInterface.NULL_ADDRESS and ether_balance:
if staking_address != NULL_ADDRESS and ether_balance:
self._checksum_address = staking_address
# TODO: #1823 - Workaround for new nickname every restart
@ -1329,7 +1327,7 @@ class Worker(NucypherTokenActor):
now = maya.now()
delta = now - start
if delta.total_seconds() >= timeout:
if staking_address == BlockchainInterface.NULL_ADDRESS:
if staking_address == NULL_ADDRESS:
raise self.DetachedWorker(f"Worker {self.__worker_address} not bonded after waiting {timeout} seconds.")
elif not ether_balance:
raise RuntimeError(f"Worker {self.__worker_address} has no ether after waiting {timeout} seconds.")

View File

@ -428,7 +428,7 @@ class StakingEscrowAgent(EthereumContractAgent):
@validate_checksum_address
def release_worker(self, staker_address: str):
return self.set_worker(staker_address=staker_address, worker_address=BlockchainInterface.NULL_ADDRESS)
return self.set_worker(staker_address=staker_address, worker_address=NULL_ADDRESS)
@validate_checksum_address
def confirm_activity(self, worker_address: str):
@ -900,7 +900,7 @@ class PreallocationEscrowAgent(EthereumContractAgent):
return receipt
def release_worker(self):
receipt = self.set_worker(worker_address=BlockchainInterface.NULL_ADDRESS)
receipt = self.set_worker(worker_address=NULL_ADDRESS)
return receipt
def mint(self):

View File

@ -53,4 +53,4 @@ AVERAGE_BLOCK_TIME_IN_SECONDS = 14
ETH_ADDRESS_BYTE_LENGTH = 20
ETH_ADDRESS_STR_LENGTH = 40
MAX_UINT16 = 65535
NULL_ADDRESS = '0x' + '0' * 40 # FIXME: Remove this in BlockchainInterface everywhere
NULL_ADDRESS = '0x' + '0' * 40

View File

@ -43,13 +43,12 @@ from nucypher.blockchain.eth.agents import (
MultiSigAgent,
ContractAgency
)
from nucypher.blockchain.eth.constants import DISPATCHER_CONTRACT_NAME
from nucypher.blockchain.eth.constants import DISPATCHER_CONTRACT_NAME, NULL_ADDRESS
from nucypher.blockchain.eth.decorators import validate_checksum_address
from nucypher.blockchain.eth.interfaces import (
BlockchainDeployerInterface,
BlockchainInterfaceFactory,
VersionedContract,
BlockchainInterface
)
from nucypher.blockchain.eth.registry import AllocationRegistry
from nucypher.blockchain.eth.registry import BaseContractRegistry
@ -849,7 +848,7 @@ class StakingInterfaceDeployer(BaseContractDeployer, UpgradeableContractMixin):
def _deploy_essential(self, contract_version: str, gas_limit: int = None, confirmations: int = 0):
"""Note: These parameters are order-sensitive"""
worklock_address = self.worklock_contract.address if self.worklock_contract else BlockchainInterface.NULL_ADDRESS
worklock_address = self.worklock_contract.address if self.worklock_contract else NULL_ADDRESS
constructor_args = (self.token_contract.address,
self.staking_contract.address,
self.policy_contract.address,
@ -1240,7 +1239,7 @@ class MultiSigDeployer(BaseContractDeployer):
if not (0 < threshold <= len(owners) <= self.MAX_OWNER_COUNT):
raise ValueError(f"Parameters threshold={threshold} and len(owners)={len(owners)} don't satisfy inequality "
f"0 < threshold <= len(owners) <= {self.MAX_OWNER_COUNT}")
if BlockchainDeployerInterface.NULL_ADDRESS in owners:
if NULL_ADDRESS in owners:
raise ValueError("The null address is not allowed as an owner")
if len(owners) != len(set(owners)):
raise ValueError("Can't use the same owner address more than once")

View File

@ -77,7 +77,6 @@ class BlockchainInterface:
"""
TIMEOUT = 600 # seconds
NULL_ADDRESS = '0x' + '0' * 40
DEFAULT_GAS_STRATEGY = 'medium'
GAS_STRATEGIES = {'glacial': time_based.glacial_gas_price_strategy, # 24h

View File

@ -22,7 +22,7 @@ from nucypher.blockchain.eth.agents import (
NucypherTokenAgent,
ContractAgency
)
from nucypher.blockchain.eth.interfaces import BlockchainInterface
from nucypher.blockchain.eth.constants import NULL_ADDRESS
from nucypher.blockchain.eth.registry import BaseContractRegistry
from nucypher.blockchain.eth.token import NU
from nucypher.characters.banners import FELIX_BANNER, NU_BANNER
@ -103,7 +103,7 @@ class Felix(Character, NucypherTokenActor):
self.token_agent = ContractAgency.get_agent(NucypherTokenAgent, registry=registry)
self.blockchain = self.token_agent.blockchain
self.reserved_addresses = [self.checksum_address, BlockchainInterface.NULL_ADDRESS]
self.reserved_addresses = [self.checksum_address, NULL_ADDRESS]
# Update reserved addresses with deployed contracts
existing_entries = list(registry.enrolled_addresses)

View File

@ -36,9 +36,9 @@ from nucypher.blockchain.eth.agents import (
StakingEscrowAgent,
PreallocationEscrowAgent,
WorkLockAgent)
from nucypher.blockchain.eth.constants import NUCYPHER_TOKEN_CONTRACT_NAME, STAKING_ESCROW_CONTRACT_NAME
from nucypher.blockchain.eth.constants import NUCYPHER_TOKEN_CONTRACT_NAME, STAKING_ESCROW_CONTRACT_NAME, NULL_ADDRESS
from nucypher.blockchain.eth.deployers import DispatcherDeployer, StakingInterfaceRouterDeployer, PolicyManagerDeployer
from nucypher.blockchain.eth.interfaces import BlockchainInterface, BlockchainInterfaceFactory
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
from nucypher.blockchain.eth.registry import BaseContractRegistry
from nucypher.blockchain.eth.sol import SOLIDITY_COMPILER_VERSION
from nucypher.blockchain.eth.token import NU
@ -740,7 +740,7 @@ def paint_stakers(emitter, stakers: List[str], staking_agent, policy_agent) -> N
f"(last time for period #{last_confirmed_period})", color='red')
emitter.echo(f"{tab} {'Worker:':10} ", nl=False)
if worker == BlockchainInterface.NULL_ADDRESS:
if worker == NULL_ADDRESS:
emitter.echo(f"Worker not set", color='red')
else:
emitter.echo(f"{worker}")

View File

@ -52,7 +52,7 @@ from umbral.signing import Signature
from nucypher.blockchain.economics import EconomicsFactory
from nucypher.blockchain.eth.agents import ContractAgency, StakingEscrowAgent
from nucypher.blockchain.eth.interfaces import BlockchainInterface
from nucypher.blockchain.eth.constants import NULL_ADDRESS
from nucypher.blockchain.eth.registry import BaseContractRegistry
from nucypher.config.constants import SeednodeMetadata
from nucypher.config.storages import ForgetfulNodeStorage
@ -1105,7 +1105,7 @@ class Teacher:
staking_agent = ContractAgency.get_agent(StakingEscrowAgent, registry=registry)
staker_address = staking_agent.get_staker_from_worker(worker_address=self.worker_address)
if staker_address == BlockchainInterface.NULL_ADDRESS:
if staker_address == NULL_ADDRESS:
raise self.DetachedWorker(f"Worker {self.worker_address} is detached")
return staker_address == self.checksum_address

View File

@ -20,9 +20,13 @@ import pytest
from eth_tester.exceptions import TransactionFailed
from nucypher.blockchain.eth.interfaces import BlockchainInterface
from nucypher.utilities.sandbox.constants import MOCK_IP_ADDRESS, MOCK_IP_ADDRESS_2, MAX_TEST_SEEDER_ENTRIES, \
from nucypher.blockchain.eth.constants import NULL_ADDRESS
from nucypher.utilities.sandbox.constants import (
MOCK_IP_ADDRESS,
MOCK_IP_ADDRESS_2,
MAX_TEST_SEEDER_ENTRIES,
MOCK_URSULA_STARTING_PORT
)
@pytest.mark.slow()
@ -47,13 +51,13 @@ def test_seeder(testerchain, deploy_contract):
testerchain.wait_for_receipt(txhash)
assert contract.functions.seeds(seed_address).call() == [*seed]
assert contract.functions.seedArray(0).call() == seed_address
assert contract.functions.seedArray(1).call() == BlockchainInterface.NULL_ADDRESS
assert contract.functions.seedArray(1).call() == NULL_ADDRESS
txhash = contract.functions.enroll(another_seed_address, *another_seed).transact({'from': origin})
testerchain.wait_for_receipt(txhash)
assert contract.functions.seeds(another_seed_address).call() == [*another_seed]
assert contract.functions.seedArray(0).call() == seed_address
assert contract.functions.seedArray(1).call() == another_seed_address
assert contract.functions.seedArray(2).call() == BlockchainInterface.NULL_ADDRESS
assert contract.functions.seedArray(2).call() == NULL_ADDRESS
txhash = contract.functions.refresh(*another_seed).transact({'from': seed_address})
testerchain.wait_for_receipt(txhash)

View File

@ -20,7 +20,7 @@ from eth_tester.exceptions import TransactionFailed
from web3.contract import Contract
from web3.exceptions import BadFunctionCallOutput
from nucypher.blockchain.eth.interfaces import BlockchainInterface
from nucypher.blockchain.eth.constants import NULL_ADDRESS
@pytest.mark.slow
@ -52,7 +52,7 @@ def test_dispatcher(testerchain, deploy_contract):
events = upgrades.get_all_entries()
assert 1 == len(events)
event_args = events[0]['args']
assert BlockchainInterface.NULL_ADDRESS == event_args['from']
assert NULL_ADDRESS == event_args['from']
assert contract1_lib.address == event_args['to']
assert creator == event_args['owner']
@ -455,7 +455,7 @@ def test_selfdestruct(testerchain, deploy_contract):
# Can't create dispatcher using address without contract
with pytest.raises((TransactionFailed, ValueError)):
deploy_contract('Dispatcher', BlockchainInterface.NULL_ADDRESS)
deploy_contract('Dispatcher', NULL_ADDRESS)
with pytest.raises((TransactionFailed, ValueError)):
deploy_contract('Dispatcher', account)
with pytest.raises((TransactionFailed, ValueError)):
@ -477,7 +477,7 @@ def test_selfdestruct(testerchain, deploy_contract):
# Can't upgrade to an address without contract
with pytest.raises((TransactionFailed, ValueError)):
tx = dispatcher.functions.upgrade(BlockchainInterface.NULL_ADDRESS).transact({'from': creator})
tx = dispatcher.functions.upgrade(NULL_ADDRESS).transact({'from': creator})
testerchain.wait_for_receipt(tx)
with pytest.raises((TransactionFailed, ValueError)):
tx = dispatcher.functions.upgrade(account).transact({'from': creator})
@ -495,7 +495,7 @@ def test_selfdestruct(testerchain, deploy_contract):
# Can't upgrade to an address without contract
with pytest.raises((TransactionFailed, ValueError)):
tx = dispatcher.functions.upgrade(BlockchainInterface.NULL_ADDRESS).transact({'from': creator})
tx = dispatcher.functions.upgrade(NULL_ADDRESS).transact({'from': creator})
testerchain.wait_for_receipt(tx)
with pytest.raises((TransactionFailed, ValueError)):
tx = dispatcher.functions.upgrade(account).transact({'from': creator})

View File

@ -20,7 +20,7 @@ import pytest
from eth_tester.exceptions import TransactionFailed
from eth_utils import to_canonical_address
from nucypher.blockchain.eth.interfaces import BlockchainInterface
from nucypher.blockchain.eth.constants import NULL_ADDRESS
def sign_hash(testerchain, account: str, data_hash: bytes) -> dict:
@ -45,7 +45,7 @@ def test_execute(testerchain, deploy_contract):
# Can't create the contract with the address 0x0 (address 0x0 is restricted for use)
with pytest.raises((TransactionFailed, ValueError)):
deploy_contract('MultiSig', 3, owners + [BlockchainInterface.NULL_ADDRESS])
deploy_contract('MultiSig', 3, owners + [NULL_ADDRESS])
# Owners must be no less than the threshold value
with pytest.raises((TransactionFailed, ValueError)):
deploy_contract('MultiSig', 6, owners)
@ -333,7 +333,7 @@ def test_owners_management(testerchain, deploy_contract):
multisig.functions.addOwner(owners[0]).buildTransaction({'from': multisig.address, 'gasPrice': 0})
# Can't add the address 0x0 as an owner
with pytest.raises((TransactionFailed, ValueError)):
multisig.functions.addOwner(BlockchainInterface.NULL_ADDRESS).buildTransaction({'from': multisig.address, 'gasPrice': 0})
multisig.functions.addOwner(NULL_ADDRESS).buildTransaction({'from': multisig.address, 'gasPrice': 0})
# Can't remove nonexistent owner
with pytest.raises((TransactionFailed, ValueError)):

View File

@ -26,7 +26,7 @@ from umbral.signing import Signer
from web3.contract import Contract
from nucypher.blockchain.economics import BaseEconomics
from nucypher.blockchain.eth.interfaces import BlockchainInterface
from nucypher.blockchain.eth.constants import NULL_ADDRESS
from nucypher.crypto.api import sha256_digest
from nucypher.crypto.signing import SignatureStamp
@ -768,7 +768,7 @@ def test_policy(testerchain,
policy_id_3 = os.urandom(16)
tx = policy_manager.functions.createPolicy(
policy_id_3, BlockchainInterface.NULL_ADDRESS, end_timestamp, [staker1, preallocation_escrow_1.address]) \
policy_id_3, NULL_ADDRESS, end_timestamp, [staker1, preallocation_escrow_1.address]) \
.transact({'from': alice2, 'value': value, 'gas_price': 0})
testerchain.wait_for_receipt(tx)
policy_manager_balance += value

View File

@ -23,7 +23,7 @@ from eth_tester.exceptions import TransactionFailed
from eth_utils import to_canonical_address
from web3.contract import Contract
from nucypher.blockchain.eth.interfaces import BlockchainInterface
from nucypher.blockchain.eth.constants import NULL_ADDRESS
SPONSOR_FIELD = 0
OWNER_FIELD = 1
@ -120,7 +120,7 @@ def test_create_revoke(testerchain, escrow, policy_manager):
assert policy_sponsor_balance - 200 == testerchain.client.get_balance(policy_sponsor)
policy = policy_manager.functions.policies(policy_id).call()
assert policy_sponsor == policy[SPONSOR_FIELD]
assert BlockchainInterface.NULL_ADDRESS == policy[OWNER_FIELD]
assert NULL_ADDRESS == policy[OWNER_FIELD]
assert rate == policy[RATE_FIELD]
assert current_timestamp == policy[START_TIMESTAMP_FIELD]
assert end_timestamp == policy[END_TIMESTAMP_FIELD]
@ -218,7 +218,7 @@ def test_create_revoke(testerchain, escrow, policy_manager):
testerchain.wait_for_receipt(tx)
# Can't revoke null arrangement (also it's nonexistent)
with pytest.raises((TransactionFailed, ValueError)):
tx = policy_manager.functions.revokeArrangement(policy_id_2, BlockchainInterface.NULL_ADDRESS).transact({'from': policy_sponsor})
tx = policy_manager.functions.revokeArrangement(policy_id_2, NULL_ADDRESS).transact({'from': policy_sponsor})
testerchain.wait_for_receipt(tx)
# Policy sponsor can't revoke policy, only owner can
@ -251,7 +251,7 @@ def test_create_revoke(testerchain, escrow, policy_manager):
testerchain.wait_for_receipt(tx)
# Can't revoke null arrangement (it's nonexistent)
with pytest.raises((TransactionFailed, ValueError)):
tx = policy_manager.functions.revokeArrangement(policy_id_2, BlockchainInterface.NULL_ADDRESS).transact({'from': policy_sponsor})
tx = policy_manager.functions.revokeArrangement(policy_id_2, NULL_ADDRESS).transact({'from': policy_sponsor})
testerchain.wait_for_receipt(tx)
# Revoke policy with remaining arrangements
@ -392,7 +392,7 @@ def test_create_revoke(testerchain, escrow, policy_manager):
# Create new policy
end_timestamp = current_timestamp + (number_of_periods - 1) * one_period
tx = policy_manager.functions.createPolicy(
policy_id_3, BlockchainInterface.NULL_ADDRESS, end_timestamp, [node1, node2]) \
policy_id_3, NULL_ADDRESS, end_timestamp, [node1, node2]) \
.transact({'from': policy_sponsor, 'value': 2 * value, 'gas_price': 0})
testerchain.wait_for_receipt(tx)
current_timestamp = testerchain.w3.eth.getBlock(block_identifier='latest').timestamp
@ -400,7 +400,7 @@ def test_create_revoke(testerchain, escrow, policy_manager):
assert policy_sponsor_balance - 2 * value == testerchain.client.get_balance(policy_sponsor)
policy = policy_manager.functions.policies(policy_id_3).call()
assert policy_sponsor == policy[SPONSOR_FIELD]
assert BlockchainInterface.NULL_ADDRESS == policy[OWNER_FIELD]
assert NULL_ADDRESS == policy[OWNER_FIELD]
assert rate == policy[RATE_FIELD]
assert current_timestamp == policy[START_TIMESTAMP_FIELD]
assert end_timestamp == policy[END_TIMESTAMP_FIELD]
@ -434,12 +434,12 @@ def test_create_revoke(testerchain, escrow, policy_manager):
assert value == testerchain.client.get_balance(policy_manager.address)
assert policy_sponsor_balance - value == testerchain.client.get_balance(policy_sponsor)
assert not policy_manager.functions.policies(policy_id_3).call()[DISABLED_FIELD]
assert BlockchainInterface.NULL_ADDRESS == policy_manager.functions.getArrangementInfo(policy_id_3, 0).call()[0]
assert NULL_ADDRESS == policy_manager.functions.getArrangementInfo(policy_id_3, 0).call()[0]
assert node2 == policy_manager.functions.getArrangementInfo(policy_id_3, 1).call()[0]
data = policy_id_3 + to_canonical_address(BlockchainInterface.NULL_ADDRESS)
data = policy_id_3 + to_canonical_address(NULL_ADDRESS)
signature = testerchain.client.sign_message(account=policy_sponsor, message=data)
tx = policy_manager.functions.revoke(policy_id_3, BlockchainInterface.NULL_ADDRESS, signature)\
tx = policy_manager.functions.revoke(policy_id_3, NULL_ADDRESS, signature)\
.transact({'from': creator, 'gas_price': 0})
testerchain.wait_for_receipt(tx)
assert policy_manager.functions.policies(policy_id_3).call()[DISABLED_FIELD]
@ -451,15 +451,15 @@ def test_create_revoke(testerchain, escrow, policy_manager):
.transact({'from': policy_sponsor, 'value': 3 * value, 'gas_price': 0})
testerchain.wait_for_receipt(tx)
data = policy_id_4 + to_canonical_address(BlockchainInterface.NULL_ADDRESS)
data = policy_id_4 + to_canonical_address(NULL_ADDRESS)
wrong_signature = testerchain.client.sign_message(account=policy_sponsor, message=data)
# Only owner's signature can be used
with pytest.raises((TransactionFailed, ValueError)):
tx = policy_manager.functions.revoke(policy_id_4, BlockchainInterface.NULL_ADDRESS, wrong_signature)\
tx = policy_manager.functions.revoke(policy_id_4, NULL_ADDRESS, wrong_signature)\
.transact({'from': policy_owner, 'gas_price': 0})
testerchain.wait_for_receipt(tx)
signature = testerchain.client.sign_message(account=policy_owner, message=data)
tx = policy_manager.functions.revoke(policy_id_4, BlockchainInterface.NULL_ADDRESS, signature)\
tx = policy_manager.functions.revoke(policy_id_4, NULL_ADDRESS, signature)\
.transact({'from': creator, 'gas_price': 0})
testerchain.wait_for_receipt(tx)
assert policy_manager.functions.policies(policy_id_4).call()[DISABLED_FIELD]
@ -500,17 +500,17 @@ def test_create_revoke(testerchain, escrow, policy_manager):
policy_id_5 = os.urandom(POLICY_ID_LENGTH)
with pytest.raises((TransactionFailed, ValueError)):
tx = policy_manager.functions\
.createPolicy(policy_id_5, BlockchainInterface.NULL_ADDRESS, end_timestamp, [node1]) \
.createPolicy(policy_id_5, NULL_ADDRESS, end_timestamp, [node1]) \
.transact({'from': policy_sponsor, 'value': default_rate - 1})
testerchain.wait_for_receipt(tx)
with pytest.raises((TransactionFailed, ValueError)):
tx = policy_manager.functions\
.createPolicy(policy_id_5, BlockchainInterface.NULL_ADDRESS, end_timestamp, [node2]) \
.createPolicy(policy_id_5, NULL_ADDRESS, end_timestamp, [node2]) \
.transact({'from': policy_sponsor, 'value': default_rate - 1})
testerchain.wait_for_receipt(tx)
tx = policy_manager.functions \
.createPolicy(policy_id_5, BlockchainInterface.NULL_ADDRESS, end_timestamp, [node1, node2]) \
.createPolicy(policy_id_5, NULL_ADDRESS, end_timestamp, [node1, node2]) \
.transact({'from': policy_sponsor, 'value': 2 * default_rate})
testerchain.wait_for_receipt(tx)

View File

@ -21,7 +21,7 @@ import os
import pytest
from eth_tester.exceptions import TransactionFailed
from nucypher.blockchain.eth.interfaces import BlockchainInterface
from nucypher.blockchain.eth.constants import NULL_ADDRESS
SPONSOR_FIELD = 0
OWNER_FIELD = 1
@ -260,14 +260,14 @@ def test_refund(testerchain, escrow, policy_manager):
tx = policy_manager.functions.refund(policy_id, node1).transact({'from': policy_creator})
testerchain.wait_for_receipt(tx)
with pytest.raises((TransactionFailed, ValueError)):
tx = policy_manager.functions.refund(policy_id, BlockchainInterface.NULL_ADDRESS).transact({'from': policy_creator})
tx = policy_manager.functions.refund(policy_id, NULL_ADDRESS).transact({'from': policy_creator})
testerchain.wait_for_receipt(tx)
with pytest.raises((TransactionFailed, ValueError)):
policy_manager.functions.calculateRefundValue(policy_id).call({'from': policy_creator})
with pytest.raises((TransactionFailed, ValueError)):
policy_manager.functions.calculateRefundValue(policy_id, node1).call({'from': policy_creator})
with pytest.raises((TransactionFailed, ValueError)):
policy_manager.functions.calculateRefundValue(policy_id, BlockchainInterface.NULL_ADDRESS).call({'from': policy_creator})
policy_manager.functions.calculateRefundValue(policy_id, NULL_ADDRESS).call({'from': policy_creator})
# Create new policy
testerchain.time_travel(hours=1)
@ -383,13 +383,13 @@ def test_refund(testerchain, escrow, policy_manager):
tx = policy_manager.functions.refund(policy_id_2, node1).transact({'from': policy_creator})
testerchain.wait_for_receipt(tx)
with pytest.raises((TransactionFailed, ValueError)):
tx = policy_manager.functions.refund(policy_id_2, BlockchainInterface.NULL_ADDRESS)\
tx = policy_manager.functions.refund(policy_id_2, NULL_ADDRESS)\
.transact({'from': policy_creator})
testerchain.wait_for_receipt(tx)
with pytest.raises((TransactionFailed, ValueError)):
policy_manager.functions.calculateRefundValue(policy_id_2, node1).call({'from': policy_creator})
with pytest.raises((TransactionFailed, ValueError)):
policy_manager.functions.calculateRefundValue(policy_id_2, BlockchainInterface.NULL_ADDRESS)\
policy_manager.functions.calculateRefundValue(policy_id_2, NULL_ADDRESS)\
.call({'from': policy_creator})
# But can refund others arrangements
@ -579,7 +579,7 @@ def test_reentrancy(testerchain, escrow, policy_manager, deploy_contract):
assert policy_value == testerchain.client.get_balance(policy_manager.address)
tx = policy_manager.functions.createPolicy(
policy_id_2, BlockchainInterface.NULL_ADDRESS, end_timestamp, [contract_address])\
policy_id_2, NULL_ADDRESS, end_timestamp, [contract_address])\
.transact({'value': policy_value, 'gas_price': 0})
testerchain.wait_for_receipt(tx)

View File

@ -19,7 +19,7 @@ import pytest
from eth_tester.exceptions import TransactionFailed
from web3.contract import Contract
from nucypher.blockchain.eth.interfaces import BlockchainInterface
from nucypher.blockchain.eth.constants import NULL_ADDRESS
@pytest.fixture()
@ -446,7 +446,7 @@ def test_interface_without_worklock(testerchain, deploy_contract, token, escrow,
# Test interface without worklock
staking_interface, _ = deploy_contract(
'StakingInterface', token.address, escrow.address, policy_manager.address, BlockchainInterface.NULL_ADDRESS)
'StakingInterface', token.address, escrow.address, policy_manager.address, NULL_ADDRESS)
tx = router.functions.upgrade(staking_interface.address).transact({'from': creator})
testerchain.wait_for_receipt(tx)

View File

@ -15,15 +15,12 @@ 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_tester.exceptions import TransactionFailed
from web3.contract import Contract
from web3.exceptions import BadFunctionCallOutput
from nucypher.blockchain.eth.interfaces import BlockchainInterface
from nucypher.blockchain.eth.constants import NULL_ADDRESS
@pytest.mark.slow
@ -109,7 +106,7 @@ def test_interface_selfdestruct(testerchain, token, deploy_contract, escrow):
# Can't create router using address without contract
with pytest.raises((TransactionFailed, ValueError)):
deploy_contract('StakingInterfaceRouter', BlockchainInterface.NULL_ADDRESS)
deploy_contract('StakingInterfaceRouter', NULL_ADDRESS)
with pytest.raises((TransactionFailed, ValueError)):
deploy_contract('StakingInterfaceRouter', account)
with pytest.raises((TransactionFailed, ValueError)):
@ -136,7 +133,7 @@ def test_interface_selfdestruct(testerchain, token, deploy_contract, escrow):
# Can't upgrade to an address without contract
with pytest.raises((TransactionFailed, ValueError)):
tx = router_contract.functions.upgrade(BlockchainInterface.NULL_ADDRESS).transact({'from': creator})
tx = router_contract.functions.upgrade(NULL_ADDRESS).transact({'from': creator})
testerchain.wait_for_receipt(tx)
with pytest.raises((TransactionFailed, ValueError)):
tx = router_contract.functions.upgrade(account).transact({'from': creator})
@ -154,7 +151,7 @@ def test_interface_selfdestruct(testerchain, token, deploy_contract, escrow):
# Can't upgrade to an address without contract
with pytest.raises((TransactionFailed, ValueError)):
tx = router_contract.functions.upgrade(BlockchainInterface.NULL_ADDRESS).transact({'from': creator})
tx = router_contract.functions.upgrade(NULL_ADDRESS).transact({'from': creator})
testerchain.wait_for_receipt(tx)
with pytest.raises((TransactionFailed, ValueError)):
tx = router_contract.functions.upgrade(account).transact({'from': creator})

View File

@ -21,7 +21,7 @@ from eth_tester.exceptions import TransactionFailed
from eth_utils import keccak
from web3.contract import Contract
from nucypher.blockchain.eth.interfaces import BlockchainInterface
from nucypher.blockchain.eth.constants import NULL_ADDRESS
from nucypher.blockchain.eth.token import NU
DISABLE_RE_STAKE_FIELD = 3
@ -78,7 +78,7 @@ def test_upgrading(testerchain, token, token_economics, deploy_contract):
)
# Can't set wrong address
with pytest.raises((TransactionFailed, ValueError)):
tx = contract.functions.setPolicyManager(BlockchainInterface.NULL_ADDRESS).transact()
tx = contract.functions.setPolicyManager(NULL_ADDRESS).transact()
testerchain.wait_for_receipt(tx)
with pytest.raises((TransactionFailed, ValueError)):
tx = contract.functions.setPolicyManager(contract_library_v1.address).transact()
@ -497,16 +497,16 @@ def test_worker(testerchain, token, escrow_contract, deploy_contract):
tx = intermediary1.functions.deposit(sub_stake, duration).transact({'from': ursula1})
testerchain.wait_for_receipt(tx)
assert sub_stake == escrow.functions.getAllTokens(intermediary1.address).call()
assert BlockchainInterface.NULL_ADDRESS == escrow.functions.getWorkerFromStaker(intermediary1.address).call()
assert BlockchainInterface.NULL_ADDRESS == escrow.functions.getStakerFromWorker(intermediary1.address).call()
assert NULL_ADDRESS == escrow.functions.getWorkerFromStaker(intermediary1.address).call()
assert NULL_ADDRESS == escrow.functions.getStakerFromWorker(intermediary1.address).call()
tx = token.functions.transfer(intermediary2.address, sub_stake).transact()
testerchain.wait_for_receipt(tx)
tx = intermediary2.functions.deposit(sub_stake, duration).transact({'from': ursula2})
testerchain.wait_for_receipt(tx)
assert sub_stake == escrow.functions.getAllTokens(intermediary2.address).call()
assert BlockchainInterface.NULL_ADDRESS == escrow.functions.getWorkerFromStaker(intermediary2.address).call()
assert BlockchainInterface.NULL_ADDRESS == escrow.functions.getStakerFromWorker(intermediary2.address).call()
assert NULL_ADDRESS == escrow.functions.getWorkerFromStaker(intermediary2.address).call()
assert NULL_ADDRESS == escrow.functions.getStakerFromWorker(intermediary2.address).call()
tx = token.functions.transfer(ursula3, sub_stake).transact()
testerchain.wait_for_receipt(tx)
@ -514,8 +514,8 @@ def test_worker(testerchain, token, escrow_contract, deploy_contract):
.transact({'from': ursula3})
testerchain.wait_for_receipt(tx)
assert sub_stake == escrow.functions.getAllTokens(ursula3).call()
assert BlockchainInterface.NULL_ADDRESS == escrow.functions.getWorkerFromStaker(ursula3).call()
assert BlockchainInterface.NULL_ADDRESS == escrow.functions.getStakerFromWorker(ursula3).call()
assert NULL_ADDRESS == escrow.functions.getWorkerFromStaker(ursula3).call()
assert NULL_ADDRESS == escrow.functions.getStakerFromWorker(ursula3).call()
# Ursula can't confirm activity because there is no worker by default
with pytest.raises((TransactionFailed, ValueError)):
@ -567,14 +567,14 @@ def test_worker(testerchain, token, escrow_contract, deploy_contract):
# She can't unset her worker too, until enough time has passed
with pytest.raises((TransactionFailed, ValueError)):
tx = intermediary1.functions.setWorker(BlockchainInterface.NULL_ADDRESS).transact({'from': ursula1})
tx = intermediary1.functions.setWorker(NULL_ADDRESS).transact({'from': ursula1})
testerchain.wait_for_receipt(tx)
# Let's advance one period and unset the worker
testerchain.time_travel(hours=1)
tx = intermediary1.functions.setWorker(BlockchainInterface.NULL_ADDRESS).transact({'from': ursula1})
tx = intermediary1.functions.setWorker(NULL_ADDRESS).transact({'from': ursula1})
testerchain.wait_for_receipt(tx)
assert BlockchainInterface.NULL_ADDRESS == escrow.functions.getWorkerFromStaker(intermediary1.address).call()
assert NULL_ADDRESS == escrow.functions.getWorkerFromStaker(intermediary1.address).call()
number_of_events += 1
events = worker_log.get_all_entries()
@ -582,7 +582,7 @@ def test_worker(testerchain, token, escrow_contract, deploy_contract):
event_args = events[-1]['args']
assert intermediary1.address == event_args['staker']
# Now the worker has been unset ...
assert BlockchainInterface.NULL_ADDRESS == event_args['worker']
assert NULL_ADDRESS == event_args['worker']
# ... with a new starting period.
assert escrow.functions.getCurrentPeriod().call() == event_args['startPeriod']
@ -591,7 +591,7 @@ def test_worker(testerchain, token, escrow_contract, deploy_contract):
testerchain.wait_for_receipt(tx)
assert worker2 == escrow.functions.getWorkerFromStaker(intermediary1.address).call()
assert intermediary1.address == escrow.functions.getStakerFromWorker(worker2).call()
assert BlockchainInterface.NULL_ADDRESS == escrow.functions.getStakerFromWorker(worker1).call()
assert NULL_ADDRESS == escrow.functions.getStakerFromWorker(worker1).call()
number_of_events += 1
events = worker_log.get_all_entries()
@ -635,7 +635,7 @@ def test_worker(testerchain, token, escrow_contract, deploy_contract):
testerchain.wait_for_receipt(tx)
assert ursula2 == escrow.functions.getWorkerFromStaker(intermediary2.address).call()
assert intermediary2.address == escrow.functions.getStakerFromWorker(ursula2).call()
assert BlockchainInterface.NULL_ADDRESS == escrow.functions.getStakerFromWorker(worker1).call()
assert NULL_ADDRESS == escrow.functions.getStakerFromWorker(worker1).call()
number_of_events += 1
events = worker_log.get_all_entries()
@ -650,8 +650,8 @@ def test_worker(testerchain, token, escrow_contract, deploy_contract):
.transact({'from': worker1})
testerchain.wait_for_receipt(tx)
assert sub_stake == escrow.functions.getAllTokens(worker1).call()
assert BlockchainInterface.NULL_ADDRESS == escrow.functions.getStakerFromWorker(worker1).call()
assert BlockchainInterface.NULL_ADDRESS == escrow.functions.getWorkerFromStaker(worker1).call()
assert NULL_ADDRESS == escrow.functions.getStakerFromWorker(worker1).call()
assert NULL_ADDRESS == escrow.functions.getWorkerFromStaker(worker1).call()
# Ursula can't use the first worker again because worker is a staker now
testerchain.time_travel(hours=1)

View File

@ -20,7 +20,7 @@ import pytest
from eth_tester.exceptions import TransactionFailed
from eth_utils import to_wei
from nucypher.blockchain.eth.interfaces import BlockchainInterface
from nucypher.blockchain.eth.constants import NULL_ADDRESS
@pytest.fixture()
@ -722,7 +722,7 @@ def test_reentrancy(testerchain, token_economics, deploy_contract, escrow, workl
# Do force refund and check bidders
testerchain.time_travel(seconds=ONE_HOUR)
tx = reentrancy_contract.functions.setData(0, BlockchainInterface.NULL_ADDRESS, 0, b'').transact()
tx = reentrancy_contract.functions.setData(0, NULL_ADDRESS, 0, b'').transact()
testerchain.wait_for_receipt(tx)
tx = worklock.functions.forceRefund([contract_address]).transact()
testerchain.wait_for_receipt(tx)
@ -1002,7 +1002,7 @@ def test_force_refund(testerchain, token_economics, deploy_contract, worklock_fa
with pytest.raises((TransactionFailed, ValueError)):
tx = worklock.functions.forceRefund(group).transact()
testerchain.wait_for_receipt(tx)
group = sorted([BlockchainInterface.NULL_ADDRESS, *whales], key=str.casefold)
group = sorted([NULL_ADDRESS, *whales], key=str.casefold)
with pytest.raises((TransactionFailed, ValueError)):
tx = worklock.functions.forceRefund(group).transact()
testerchain.wait_for_receipt(tx)

View File

@ -5,7 +5,7 @@ from eth_tester.exceptions import TransactionFailed
from nucypher.blockchain.eth.actors import Bidder
from nucypher.blockchain.eth.agents import ContractAgency, StakingEscrowAgent, WorkLockAgent
from nucypher.blockchain.eth.interfaces import BlockchainInterface
from nucypher.blockchain.eth.constants import NULL_ADDRESS
def test_create_bidder(testerchain, test_registry, agency, token_economics):
@ -163,4 +163,4 @@ def test_claim(testerchain, agency, token_economics, test_registry):
# Confirm the stake is unbonded
worker_address = staking_agent.get_worker_from_staker(staker_address=bidder.checksum_address)
assert worker_address == BlockchainInterface.NULL_ADDRESS
assert worker_address == NULL_ADDRESS

View File

@ -21,9 +21,8 @@ from umbral.keys import UmbralPrivateKey
from umbral.signing import Signer
from nucypher.blockchain.eth.actors import Staker, Investigator
from nucypher.blockchain.eth.interfaces import BlockchainInterface
from nucypher.blockchain.eth.constants import NULL_ADDRESS
from nucypher.blockchain.eth.token import NU
from nucypher.crypto.powers import TransactingPower
from nucypher.crypto.signing import SignatureStamp
from nucypher.utilities.sandbox.constants import INSECURE_DEVELOPMENT_PASSWORD
@ -74,7 +73,7 @@ def test_investigator_requests_slashing(testerchain,
assert staker.locked_tokens(periods=1) == locked_tokens
# The staker hasn't set a worker yet
assert BlockchainInterface.NULL_ADDRESS == staking_agent.get_worker_from_staker(staker_address=staker_account)
assert NULL_ADDRESS == staking_agent.get_worker_from_staker(staker_address=staker_account)
_txhash = staking_agent.set_worker(staker_address=staker_account,
worker_address=worker_account)

View File

@ -22,7 +22,7 @@ from umbral.signing import Signer
from nucypher.blockchain.eth.actors import NucypherTokenActor, Staker
from nucypher.blockchain.eth.agents import AdjudicatorAgent
from nucypher.blockchain.eth.interfaces import BlockchainInterface
from nucypher.blockchain.eth.constants import NULL_ADDRESS
from nucypher.blockchain.eth.token import NU
from nucypher.crypto.signing import SignatureStamp
from nucypher.utilities.sandbox.constants import INSECURE_DEVELOPMENT_PASSWORD
@ -74,7 +74,7 @@ def test_adjudicator_slashes(agency,
assert staker.locked_tokens(periods=1) == locked_tokens
# The staker hasn't set a worker yet
assert BlockchainInterface.NULL_ADDRESS == staking_agent.get_worker_from_staker(staker_address=staker_account)
assert NULL_ADDRESS == staking_agent.get_worker_from_staker(staker_address=staker_account)
_txhash = staking_agent.set_worker(staker_address=staker_account,
worker_address=worker_account)

View File

@ -18,10 +18,9 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
import pytest
from collections import Counter
from nucypher.blockchain.economics import StandardTokenEconomics, BaseEconomics
from nucypher.blockchain.economics import BaseEconomics
from nucypher.blockchain.eth.agents import StakingEscrowAgent
from nucypher.blockchain.eth.interfaces import BlockchainInterface
from nucypher.blockchain.eth.constants import STAKING_ESCROW_CONTRACT_NAME
from nucypher.blockchain.eth.constants import NULL_ADDRESS, STAKING_ESCROW_CONTRACT_NAME
@pytest.fixture()
@ -124,7 +123,7 @@ def test_sampling_distribution(testerchain, token, deploy_contract):
while sampled < SAMPLES:
try:
addresses = set(staking_agent.sample(quantity=quantity, additional_ursulas=1, duration=1))
addresses.discard(BlockchainInterface.NULL_ADDRESS)
addresses.discard(NULL_ADDRESS)
except staking_agent.NotEnoughStakers:
failed += 1
continue

View File

@ -21,9 +21,8 @@ import pytest
from eth_utils.address import to_checksum_address, is_address
from nucypher.blockchain.eth.agents import StakingEscrowAgent, ContractAgency
from nucypher.blockchain.eth.interfaces import BlockchainInterface
from nucypher.blockchain.eth.constants import NULL_ADDRESS
from nucypher.blockchain.eth.registry import BaseContractRegistry
from nucypher.crypto.powers import TransactingPower
from nucypher.utilities.sandbox.constants import INSECURE_DEVELOPMENT_PASSWORD
@ -107,7 +106,7 @@ def test_stakers_and_workers_relationships(testerchain, agency):
staker_account, worker_account, *other = testerchain.unassigned_accounts
# The staker hasn't set a worker yet
assert BlockchainInterface.NULL_ADDRESS == staking_agent.get_worker_from_staker(staker_address=staker_account)
assert NULL_ADDRESS == staking_agent.get_worker_from_staker(staker_address=staker_account)
_txhash = staking_agent.set_worker(staker_address=staker_account,
worker_address=worker_account)
@ -118,8 +117,8 @@ def test_stakers_and_workers_relationships(testerchain, agency):
# No staker-worker relationship
random_address = to_checksum_address(os.urandom(20))
assert BlockchainInterface.NULL_ADDRESS == staking_agent.get_worker_from_staker(staker_address=random_address)
assert BlockchainInterface.NULL_ADDRESS == staking_agent.get_staker_from_worker(worker_address=random_address)
assert NULL_ADDRESS == staking_agent.get_worker_from_staker(staker_address=random_address)
assert NULL_ADDRESS == staking_agent.get_staker_from_worker(worker_address=random_address)
@pytest.mark.slow()

View File

@ -18,8 +18,8 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
import pytest
from nucypher.blockchain.eth.agents import MultiSigAgent
from nucypher.blockchain.eth.constants import NULL_ADDRESS
from nucypher.blockchain.eth.deployers import MultiSigDeployer
from nucypher.blockchain.eth.interfaces import BlockchainInterface
@pytest.mark.slow()
@ -40,7 +40,7 @@ def test_multisig_deployer_and_agent(testerchain,
# Can't have the zero address as an owner
with pytest.raises(ValueError):
owners = testerchain.unassigned_accounts[0:3] + [BlockchainInterface.NULL_ADDRESS]
owners = testerchain.unassigned_accounts[0:3] + [NULL_ADDRESS]
_ = multisig_deployer.deploy(threshold=1, owners=owners)
# Can't have repeated owners