def make_federated_ursulas( ursula_config: UrsulaConfiguration, quantity: int = NUMBER_OF_URSULAS_IN_DEVELOPMENT_NETWORK, know_each_other: bool = True, **ursula_overrides) -> Set[Ursula]: if not MOCK_KNOWN_URSULAS_CACHE: starting_port = MOCK_URSULA_STARTING_PORT else: starting_port = max(MOCK_KNOWN_URSULAS_CACHE.keys()) + 1 federated_ursulas = set() for port in range(starting_port, starting_port + quantity): ursula = ursula_config.produce(rest_port=port + 100, db_filepath=MOCK_URSULA_DB_FILEPATH, **ursula_overrides) federated_ursulas.add(ursula) # Store this Ursula in our global testing cache. port = ursula.rest_interface.port MOCK_KNOWN_URSULAS_CACHE[port] = ursula if know_each_other: for ursula_to_teach in federated_ursulas: # Add other Ursulas as known nodes. for ursula_to_learn_about in federated_ursulas: ursula_to_teach.remember_node(ursula_to_learn_about) return federated_ursulas
def make_decentralized_ursulas(ursula_config: UrsulaConfiguration, stakers_addresses: Iterable[str], workers_addresses: Iterable[str], confirm_activity: bool = False, **ursula_overrides) -> List[Ursula]: if not MOCK_KNOWN_URSULAS_CACHE: starting_port = MOCK_URSULA_STARTING_PORT else: starting_port = max(MOCK_KNOWN_URSULAS_CACHE.keys()) + 1 stakers_and_workers = zip(stakers_addresses, workers_addresses) ursulas = list() for port, (staker_address, worker_address) in enumerate(stakers_and_workers, start=starting_port): ursula = ursula_config.produce(checksum_address=staker_address, worker_address=worker_address, db_filepath=MOCK_URSULA_DB_FILEPATH, rest_port=port + 100, **ursula_overrides) if confirm_activity: ursula.confirm_activity() ursulas.append(ursula) # Store this Ursula in our global cache. port = ursula.rest_interface.port MOCK_KNOWN_URSULAS_CACHE[port] = ursula return ursulas
def make_decentralized_ursulas(ursula_config: UrsulaConfiguration, ether_addresses: Union[list, int], stake: bool = False, know_each_other: bool = True, **ursula_overrides) -> Set[Ursula]: # Alternately accepts an int of the quantity of ursulas to make if isinstance(ether_addresses, int): ether_addresses = [ to_checksum_address(secure_random(20)) for _ in range(ether_addresses) ] if not MOCK_KNOWN_URSULAS_CACHE: starting_port = MOCK_URSULA_STARTING_PORT else: starting_port = max(MOCK_KNOWN_URSULAS_CACHE.keys()) + 1 ursulas = set() for port, checksum_address in enumerate(ether_addresses, start=starting_port): ursula = ursula_config.produce( checksum_public_address=checksum_address, db_filepath=MOCK_URSULA_DB_FILEPATH, rest_port=port + 100, **ursula_overrides) if stake is True: min_stake, balance = MIN_ALLOWED_LOCKED, ursula.token_balance amount = random.randint(min_stake, balance) # for a random lock duration min_locktime, max_locktime = MIN_LOCKED_PERIODS, MAX_MINTING_PERIODS periods = random.randint(min_locktime, max_locktime) ursula.initialize_stake(amount=amount, lock_periods=periods) ursulas.add(ursula) # Store this Ursula in our global cache. port = ursula.rest_information()[0].port MOCK_KNOWN_URSULAS_CACHE[port] = ursula if know_each_other: for ursula_to_teach in ursulas: # Add other Ursulas as known nodes. for ursula_to_learn_about in ursulas: ursula_to_teach.remember_node(ursula_to_learn_about) return ursulas
def make_decentralized_ursulas(ursula_config: UrsulaConfiguration, ether_addresses: Union[list, int], stake: bool = False, economics: TokenEconomics = None, **ursula_overrides) -> List[Ursula]: if not economics: economics = TokenEconomics() # Alternately accepts an int of the quantity of ursulas to make if isinstance(ether_addresses, int): ether_addresses = [to_checksum_address(secure_random(20)) for _ in range(ether_addresses)] if not MOCK_KNOWN_URSULAS_CACHE: starting_port = MOCK_URSULA_STARTING_PORT else: starting_port = max(MOCK_KNOWN_URSULAS_CACHE.keys()) + 1 ursulas = list() for port, checksum_address in enumerate(ether_addresses, start=starting_port): ursula = ursula_config.produce(checksum_address=checksum_address, db_filepath=MOCK_URSULA_DB_FILEPATH, rest_port=port + 100, **ursula_overrides) if stake is True: min_stake, balance = economics.minimum_allowed_locked, ursula.token_balance amount = random.randint(min_stake, balance) # for a random lock duration min_locktime, max_locktime = economics.minimum_locked_periods, economics.maximum_locked_periods periods = random.randint(min_locktime, max_locktime) ursula.initialize_stake(amount=amount, lock_periods=periods) ursulas.append(ursula) # Store this Ursula in our global cache. port = ursula.rest_information()[0].port MOCK_KNOWN_URSULAS_CACHE[port] = ursula return ursulas