Best Python code snippet using tempest_python
PoolNameRegistryTemplate1.v.py
Source:PoolNameRegistryTemplate1.v.py
...61 return True62### Internal functions ###63@private64@constant65def _name_exists(_name: string[64]) -> bool:66 return self.names[self.name_to_id[_name]].name == _name67@private68def _lock_name(_name: string[64]):69 assert self.nonreentrant_pool_name_locks[_name] == False70 self.nonreentrant_pool_name_locks[_name] = True71@private72def _unlock_name(_name: string[64]):73 assert self.nonreentrant_pool_name_locks[_name] == True74 self.nonreentrant_pool_name_locks[_name] = False75@private76def _add_name(_name: string[64], _operator: address, _sender: address):77 self.name_to_id[_name] = self.next_name_id78 _LST_stake: uint256 = self.name_registration_stake_lookup[len(_name)].stake79 if as_unitless_number(_LST_stake) == 0:80 _LST_stake = self.name_registration_minimum_stake81 assert not as_unitless_number(_LST_stake) == 082 self.names[self.next_name_id] = Name({83 name: _name,84 operator: _operator,85 LST_staked: _LST_stake,86 interest_pool_registered: False,87 underwriter_pool_registered: False,88 id: self.next_name_id89 })90 if _sender == self.daos[DAO_INTEREST_POOL]:91 self.names[self.next_name_id].interest_pool_registered = True92 if _sender == self.daos[DAO_UNDERWRITER_POOL]:93 self.names[self.next_name_id].underwriter_pool_registered = True94 self.next_name_id += 195 assert_modifiable(CurrencyDao(self.daos[DAO_CURRENCY]).authorized_transfer_erc20(96 self.LST, _operator, self, _LST_stake))97@private98def _remove_name(_name: string[64], _name_id: uint256):99 # transfer staked LST back to operator100 assert_modifiable(ERC20(self.LST).transfer(101 self.names[_name_id].operator,102 self.names[_name_id].LST_staked103 ))104 clear(self.name_to_id[_name])105 if as_unitless_number(_name_id) < as_unitless_number(self.next_name_id - 1):106 self.names[_name_id] = Name({107 name: self.names[self.next_name_id - 1].name,108 operator: self.names[self.next_name_id - 1].operator,109 LST_staked: self.names[self.next_name_id - 1].LST_staked,110 interest_pool_registered: self.names[self.next_name_id - 1].interest_pool_registered,111 underwriter_pool_registered: self.names[self.next_name_id - 1].underwriter_pool_registered,112 id: _name_id113 })114 _last_name: string[64] = self.names[self.next_name_id - 1].name115 self.name_to_id[_last_name] = _name_id116 clear(self.names[self.next_name_id - 1])117 self.next_name_id -= 1118@private119def _pause():120 """121 @dev Internal function to pause this contract.122 """123 assert not self.paused124 self.paused = True125@private126def _unpause():127 """128 @dev Internal function to unpause this contract.129 """130 assert self.paused131 self.paused = False132@private133def _transfer_balance_erc20(_token: address):134 """135 @dev Internal function to transfer this contract's balance of the given136 ERC20 token to the Escape Hatch Token Holder.137 @param _token The address of the ERC20 token.138 """139 assert_modifiable(ERC20(_token).transfer(140 ProtocolDao(self.protocol_dao).authorized_callers(CALLER_ESCAPE_HATCH_TOKEN_HOLDER),141 ERC20(_token).balanceOf(self)142 ))143### External functions ###144@public145@constant146def name_exists(_name: string[64]) -> bool:147 return self._name_exists(_name)148# Admin functions149@public150def set_name_registration_minimum_stake(_value: uint256) -> bool:151 """152 @dev Function to set the minimum stake required to register a pool name.153 Only the Protocol DAO can call this function.154 @param _value The minimum stake value.155 @return A bool with a value of "True" indicating the minimum stake156 has been set.157 """158 assert self.initialized159 assert msg.sender == self.protocol_dao160 self.name_registration_minimum_stake = _value161 log.StakeMinimumValueUpdated(msg.sender, _value)162 return True163@public164def set_name_registration_stake_lookup(_name_length: int128, _stake: uint256) -> bool:165 """166 @dev Function to set the stake required for a pool name with a specified167 character length. For eg, 3-character Pool names need a higher168 stake than 4-character, which in turn need a higher stake than a169 5-character name, and so on. Only the Protocol DAO can call this170 function.171 @param _name_length The character length of a pool name.172 @param _value The stake required for the given pool name character length.173 @return A bool with a value of "True" indicating the minimum stake174 has been set.175 """176 assert self.initialized177 assert msg.sender == self.protocol_dao178 self.name_registration_stake_lookup[_name_length] = NameRegistrationStakeLookup({179 name_length: _name_length,180 stake: _stake181 })182 log.StakeLookupUpdated(msg.sender, _name_length, _stake)183 return True184# Escape-hatches185@public186def pause() -> bool:187 """188 @dev Escape hatch function to pause this contract. Only the Protocol DAO189 can call this function.190 @return A bool with a value of "True" indicating this contract has been191 paused.192 """193 assert self.initialized194 assert msg.sender == self.protocol_dao195 self._pause()196 return True197@public198def unpause() -> bool:199 """200 @dev Escape hatch function to unpause this contract. Only the Protocol201 DAO can call this function.202 @return A bool with a value of "True" indicating this contract has been203 unpaused.204 """205 assert self.initialized206 assert msg.sender == self.protocol_dao207 self._unpause()208 return True209@public210def escape_hatch_erc20(_currency: address) -> bool:211 """212 @dev Escape hatch function to transfer all tokens of an ERC20 address213 from this contract to the Escape Hatch Token Holder. Only the214 Protocol DAO can call this function.215 @param _currency The address of the ERC20 token216 @return A bool with a value of "True" indicating the ERC20 transfer has217 been made to the Escape Hatch Token Holder.218 """219 assert self.initialized220 assert msg.sender == self.protocol_dao221 self._transfer_balance_erc20(_currency)222 return True223# Non-admin functions224@public225def register_name(_name: string[64]) -> bool:226 assert self.initialized227 assert not self.paused228 if self._name_exists(_name):229 raise "Pool name already exists"230 self._lock_name(_name)231 self._add_name(_name, msg.sender, self)232 self._unlock_name(_name)233 return True234@public235def register_name_and_pool(_name: string[64], _operator: address) -> bool:236 assert self.initialized237 assert not self.paused238 assert msg.sender == self.daos[DAO_INTEREST_POOL] or \239 msg.sender == self.daos[DAO_UNDERWRITER_POOL]240 assert not self._name_exists(_name)241 self._lock_name(_name)242 self._add_name(_name, _operator, msg.sender)243 self._unlock_name(_name)244 return True245@public246def register_pool(_name: string[64], _operator: address) -> bool:247 assert self.initialized248 assert not self.paused249 assert msg.sender == self.daos[DAO_INTEREST_POOL] or \250 msg.sender == self.daos[DAO_UNDERWRITER_POOL]251 assert self._name_exists(_name)252 _name_id: uint256 = self.name_to_id[_name]253 assert _operator == self.names[_name_id].operator254 if msg.sender == self.daos[DAO_INTEREST_POOL]:255 assert not self.names[_name_id].interest_pool_registered256 self.names[_name_id].interest_pool_registered = True257 if msg.sender == self.daos[DAO_UNDERWRITER_POOL]:258 assert not self.names[_name_id].underwriter_pool_registered259 self.names[_name_id].underwriter_pool_registered = True260 return True261@public262def deregister_pool(_name: string[64], _operator: address) -> bool:263 assert self.initialized264 assert not self.paused265 assert msg.sender == self.daos[DAO_INTEREST_POOL] or \266 msg.sender == self.daos[DAO_UNDERWRITER_POOL]267 assert self._name_exists(_name)268 _name_id: uint256 = self.name_to_id[_name]269 assert as_unitless_number(self.names[_name_id].LST_staked) > 0270 assert _operator == self.names[_name_id].operator271 if msg.sender == self.daos[DAO_INTEREST_POOL]:272 assert self.names[_name_id].interest_pool_registered273 self.names[_name_id].interest_pool_registered = False274 if msg.sender == self.daos[DAO_UNDERWRITER_POOL]:275 assert self.names[_name_id].underwriter_pool_registered276 self.names[_name_id].underwriter_pool_registered = False277 return True278@public279def deregister_name(_name: string[64]) -> bool:280 assert self.initialized281 assert not self.paused282 assert self._name_exists(_name)283 _name_id: uint256 = self.name_to_id[_name]284 assert self.names[_name_id].operator == msg.sender285 assert _name_id < self.next_name_id286 self._lock_name(_name)287 self._remove_name(_name, _name_id)288 self._unlock_name(_name)...
workspace.py
Source:workspace.py
...62 return self.workspaces.get(name)63 @lockutils.synchronized('workspaces', external=True)64 def rename_workspace(self, old_name, new_name):65 self._populate()66 self._name_exists(old_name)67 self._workspace_name_exists(new_name)68 self.workspaces[new_name] = self.workspaces.pop(old_name)69 self._write_file()70 @lockutils.synchronized('workspaces', external=True)71 def move_workspace(self, name, path):72 self._populate()73 path = os.path.abspath(os.path.expanduser(path))74 self._name_exists(name)75 self._validate_path(path)76 self.workspaces[name] = path77 self._write_file()78 def _name_exists(self, name):79 if name not in self.workspaces:80 print("A workspace was not found with name: {0}".format(name))81 sys.exit(1)82 @lockutils.synchronized('workspaces', external=True)83 def remove_workspace(self, name):84 self._populate()85 self._name_exists(name)86 self.workspaces.pop(name)87 self._write_file()88 @lockutils.synchronized('workspaces', external=True)89 def list_workspaces(self):90 self._populate()91 self._validate_workspaces()92 return self.workspaces93 def _workspace_name_exists(self, name):94 if name in self.workspaces:95 print("A workspace already exists with name: {0}.".format(96 name))97 sys.exit(1)98 def _validate_path(self, path):99 if not os.path.exists(path):100 print("Path does not exist.")101 sys.exit(1)102 @lockutils.synchronized('workspaces', external=True)103 def register_new_workspace(self, name, path, init=False):104 """Adds the new workspace and writes out the new workspace config"""105 self._populate()106 path = os.path.abspath(os.path.expanduser(path))107 # This only happens when register is called from outside of init108 if not init:109 self._validate_path(path)110 self._workspace_name_exists(name)111 self.workspaces[name] = path112 self._write_file()113 def _validate_workspaces(self):114 if self.workspaces is not None:115 self.workspaces = {n: p for n, p in self.workspaces.items()116 if os.path.exists(p)}117 self._write_file()118 def _write_file(self):119 with open(self.path, 'w') as f:120 f.write(yaml.dump(self.workspaces))121 def _populate(self):122 if not os.path.isfile(self.path):123 return124 with open(self.path, 'r') as f:...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!