Best Python code snippet using autotest_python
test_etherex.py
Source:test_etherex.py
...75 # Tests76 def test_creation(self):77 assert self.etx_contract.balanceOf(self.ALICE['address']) == self.initialIssuance78 assert self.bob_contract.balanceOf(self.ALICE['address']) == self.initialIssuance79 def test_initialize(self, block=None):80 # NameReg Alice81 ans = self.namereg.register(self.ALICE['address'], "Alice")82 assert ans == SUCCESS83 assert self._storage(self.namereg, "0x" + self.ALICE['address']) == "0x" + "Alice".encode('hex')84 assert self.namereg.getname(self.ALICE['address']) == utils.big_endian_to_int("Alice")85 # NameReg EtherEx86 ans = self.namereg.register(self.contract.address, "EtherEx")87 assert ans == SUCCESS88 assert self._storage(self.namereg, "0x" + self.contract.address.encode('hex')) == "0x" + "EtherEx".encode('hex')89 # NameReg ETX90 ans = self.namereg.register(self.etx_contract.address, "ETX")91 assert ans == SUCCESS92 assert self._storage(self.namereg, "0x" + self.etx_contract.address.encode('hex')) == "0x" + "ETX".encode('hex')93 # Register ETX94 ans = self.contract.add_market(95 "ETX",96 self.etx_contract.address,97 5,98 10 ** 8,99 10 ** 18,100 1,101 sender=self.ALICE['key'])102 assert ans == SUCCESS103 # TODO Register Solidity Standard Token104 # ans = self.contract.add_market(105 # "SST",106 # self.standard_contract.address,107 # 5,108 # 10 ** 8,109 # 10 ** 18,110 # 1,111 # sender=self.ALICE['key'])112 # assert ans == 1113 def test_get_last_market_id(self):114 self.test_initialize()115 ans = self.contract.get_last_market_id()116 assert ans == 1117 def test_get_market_id(self):118 self.test_initialize()119 assert self.contract.get_market_id(self.etx_contract.address) == 1120 def test_get_market(self):121 self.test_initialize()122 ans = self.contract.get_market(1)123 assert ans == [124 1,125 4543576,126 584202455294917676171628316407181071088652546483L,127 5,128 100000000,129 1000000000000000000,130 1,131 745948140856946866108753121277737810491401257713L,132 0,133 0,134 1]135 #136 # ETX137 #138 def test_alice_to_bob(self):139 self.test_initialize()140 # Send 1000 to Bob141 ans = self.etx_contract.transfer(self.BOB['address'], 1000 * 10 ** 5)142 assert ans == SUCCESS143 # Alice has 1000 less144 ans = self.etx_contract.balanceOf(self.ALICE['address'])145 assert ans == self.initialIssuance - 1000 * 10 ** 5146 # Bob has 1000147 ans = self.etx_contract.balanceOf(self.BOB['address'])148 assert ans == 1000 * 10 ** 5149 # assert self._storage(self.etx_contract, int(self.ALICE['address'], 16)) == self.xhex(1000000 - 1000)150 # assert self._storage(self.etx_contract, int(self.BOB['address'], 16)) == self.xhex(1000)151 def test_bob_to_charlie_fail(self):152 self.test_initialize()153 ans = self.etx_contract.transfer(self.CHARLIE['address'], 1000 * 10 ** 5, sender=self.BOB['key'])154 assert ans == FAILURE155 def test_alice_to_bob_to_charlie(self):156 self.test_initialize()157 # Send 1000 to Bob158 ans = self.etx_contract.transfer(self.BOB['address'], 1000 * 10 ** 5, profiling=1)159 assert ans['output'] == 1160 logger.info("\nTransfer profiling: %s" % ans)161 # Bob sends 250 to Charlie162 ans = self.etx_contract.transfer(self.CHARLIE['address'], 250 * 10 ** 5, sender=self.BOB['key'])163 assert ans == SUCCESS164 # Charlie now has 250165 ans = self.etx_contract.balanceOf(self.CHARLIE['address'])166 assert ans == 250 * 10 ** 5167 #168 # Balances169 #170 def test_sub_balance(self):171 self.test_initialize()172 ans = self.etx_contract.balanceOf(self.ALICE['address'])173 assert ans == self.initialIssuance174 def test_deposit_to_exchange(self, init=True):175 if init:176 self.test_initialize()177 # Approve deposit of 10,000178 ans = self.etx_contract.approve(179 self.contract.address,180 10000 * 10 ** 5,181 profiling=1)182 assert ans['output'] == 1183 logger.info("\napprove profiling: %s" % ans)184 # Verify exchange is approved for a transfer185 ans = self.etx_contract.allowance(186 self.ALICE['address'],187 self.contract.address)188 assert ans == 10000 * 10 ** 5189 # Deposit 10,000 into exchange190 ans = self.contract.deposit(10000 * 10 ** 5, 1, profiling=1)191 assert ans['output'] == 1000000000192 logger.info("\nDeposit profiling: %s" % ans)193 # Verify exchange is no longer approved for a transfer194 ans = self.etx_contract.allowance(195 self.ALICE['address'],196 self.contract.address)197 assert ans == FAILURE198 # Alice has 10,000 less199 ans = self.etx_contract.balanceOf(self.ALICE['address'])200 assert ans == self.initialIssuance - 10000 * 10 ** 5201 # Exchange has 10,000202 ans = self.etx_contract.balanceOf(self.contract.address)203 assert ans == 10000 * 10 ** 5204 # Alice has 10,000 in the exchange205 ans = self.contract.get_sub_balance(self.ALICE['address'], 1)206 assert ans == [10000 * 10 ** 5, 0]207 def test_log_deposit(self):208 snapshot = self.state.snapshot()209 o = []210 self.state.block.log_listeners.append(lambda x: o.append(self.contract._translator.listen(x)))211 self.test_deposit_to_exchange()212 assert o == [213 None, # Token contract events returning None...214 {215 '_event_type': 'log_market', 'id': 1216 },217 None,218 None,219 {220 "_event_type": "log_deposit",221 "market": 1,222 "sender": int("0x" + self.ALICE['address'], 16),223 "amount": 10000 * 10 ** 5224 }225 ]226 self.state.revert(snapshot)227 def test_withdraw_sub_fail(self):228 self.test_initialize()229 ans = self.contract.withdraw(1000 * 10 ** 5, 1)230 assert ans == 0231 def test_withdraw_sub(self):232 self.test_deposit_to_exchange()233 ans = self.contract.withdraw(1000 * 10 ** 5, 1, profiling=1)234 assert ans['output'] == 1235 logger.info("\nWithdraw profiling: %s" % ans)236 #237 # EtherEx238 #239 def test_no_data(self):240 self.test_initialize()241 ans = self.state.send(self.ALICE['key'], self.contract.address, 0, "0")242 assert ans == ''243 def test_invalid_operation(self):244 self.test_initialize()245 ans = self.state.send(self.ALICE['key'], self.contract.address, 0, "0xFF")246 assert ans == ''247 def test_missing_amount(self):248 self.test_initialize()249 ans = self.contract.buy(0, int(0.25 * 10 ** 8), 1)250 assert ans == 2251 def test_missing_price(self):252 self.test_initialize()253 ans = self.contract.buy(1000 * 10 ** 5, 0, 1)254 assert ans == 3255 def test_missing_market_id(self):256 self.test_initialize()257 ans = self.contract.buy(1000 * 10 ** 5, int(0.25 * 10 ** 8), 0)258 assert ans == 4259 def test_too_many_arguments(self):260 self.test_initialize()261 with pytest.raises(Exception) as excinfo:262 self.contract.buy(1000 * 10 ** 5, int(0.25 * 10 ** 8), 1, 1)263 assert "list index out of range" in excinfo.value.message264 def test_amount_out_of_range(self):265 self.test_initialize()266 with pytest.raises(Exception) as excinfo:267 self.contract.buy(2 ** 256, int(0.25 * 10 ** 8), 1)268 assert 'Number out of range' in excinfo.value.message269 def test_price_out_of_range(self):270 self.test_initialize()271 with pytest.raises(Exception) as excinfo:272 self.contract.buy(1000 * 10 ** 5, 2 ** 256, 1)273 assert 'Number out of range' in excinfo.value.message274 def test_add_bob_coin(self):275 self.test_initialize()276 # Register BOBcoin277 ans = self.contract.add_market(278 "BOB",279 self.bob_contract.address,280 4,281 10 ** 8,282 10 ** 18,283 1,284 sender=self.BOB['key'],285 profiling=1)286 assert ans['output'] == 1287 logger.info("\nAdd other market profiling: %s" % ans)288 def test_get_bob_market_id(self):289 self.test_add_bob_coin()290 assert self.contract.get_market_id(self.bob_contract.address) == 2291 def test_get_new_last_market_id(self):292 self.test_add_bob_coin()293 assert self.contract.get_last_market_id() == 2294 def test_insufficient_buy_trade(self):295 self.test_initialize()296 ans = self.contract.buy(500 * 10 ** 5, int(0.25 * 10 ** 8), 1, value=10 ** 17)297 assert ans == INSUFFICIENT_TRADE_AMOUNT298 def test_insufficient_sell_trade(self):299 self.test_initialize()300 ans = self.contract.sell(500 * 10 ** 5, int(0.25 * 10 ** 2), 1)301 assert ans == INSUFFICIENT_TRADE_AMOUNT302 def test_insufficient_mismatch_buy_trade(self):303 self.test_initialize()304 ans = self.contract.buy(500 * 10 ** 5, int(0.25 * 10 ** 8), 1, sender=self.BOB['key'], value=124 * 10 ** 18)305 assert ans == TRADE_AMOUNT_MISMATCH306 # TODO tests for MARKET_* error codes307 def test_market_name_invalid(self):308 ans = self.contract.add_market(309 -1,310 self.etx_contract.address,311 5,312 10 ** 8,313 10 ** 18,314 1)315 assert ans == MARKET_NAME_INVALID316 def test_market_name_already_exists(self):317 ans = self.contract.add_market(318 "ETX",319 self.etx_contract.address,320 5,321 10 ** 8,322 10 ** 18,323 1)324 assert ans == SUCCESS325 ans = self.contract.add_market(326 "ETX",327 self.etx_contract.address,328 5,329 10 ** 8,330 10 ** 18,331 1)332 assert ans == MARKET_NAME_ALREADY_EXISTS333 def test_market_contract_invalid(self):334 ans = self.contract.add_market(335 "ETX",336 0,337 5,338 10 ** 8,339 10 ** 18,340 1)341 assert ans == MARKET_CONTRACT_INVALID342 def test_market_category_invalid(self):343 ans = self.contract.add_market(344 "ETX",345 self.etx_contract.address,346 5,347 10 ** 8,348 10 ** 18,349 -1)350 assert ans == MARKET_CATEGORY_INVALID351 def test_market_decimals_invalid(self):352 ans = self.contract.add_market(353 "ETX",354 self.etx_contract.address,355 -1,356 10 ** 8,357 10 ** 18,358 1)359 assert ans == MARKET_DECIMALS_INVALID360 def test_market_precision_invalid(self):361 ans = self.contract.add_market(362 "ETX",363 self.etx_contract.address,364 5,365 -1,366 10 ** 18,367 1)368 assert ans == MARKET_PRECISION_INVALID369 def test_market_minimum_invalid(self):370 ans = self.contract.add_market(371 "ETX",372 self.etx_contract.address,373 5,374 10 ** 8,375 -1,376 1)377 assert ans == MARKET_MINIMUM_INVALID378 def test_market_nonstandard_allowance(self):379 code = """380def allowance(_address, _spender):381 return(-1)382"""383 nonstandard_contract = self.state.abi_contract(code)384 ans = self.contract.add_market(385 "NON",386 nonstandard_contract.address,387 5,388 10 ** 8,389 10 ** 18,390 1)391 assert ans == MARKET_NONSTANDARD_ALLOWANCE392 def test_market_nonstandard_approve(self):393 code = """394def approve(_spender, _value):395 return(-1)396"""397 nonstandard_contract = self.state.abi_contract(code)398 ans = self.contract.add_market(399 "NON",400 nonstandard_contract.address,401 5,402 10 ** 8,403 10 ** 18,404 1)405 assert ans == MARKET_NONSTANDARD_APPROVE406 def test_market_nonstandard_balanceof(self):407 code = """408def balanceOf(_address):409 return(-1)410def approve(_spender, _value):411 return(1)412"""413 nonstandard_contract = self.state.abi_contract(code)414 ans = self.contract.add_market(415 "NON",416 nonstandard_contract.address,417 5,418 10 ** 8,419 10 ** 18,420 1)421 assert ans == MARKET_NONSTANDARD_BALANCEOF422 def test_market_nonstandard_transfer(self):423 code = """424def transfer(_to, _value):425 return(-1)426def approve(_spender, _value):427 return(1)428"""429 nonstandard_contract = self.state.abi_contract(code)430 ans = self.contract.add_market(431 "NON",432 nonstandard_contract.address,433 5,434 10 ** 8,435 10 ** 18,436 1)437 assert ans == MARKET_NONSTANDARD_TRANSFER438 def test_market_nonstandard_transferfrom(self):439 code = """440def transferFrom(_from, _to, _value):441 return(-1)442def approve(_spender, _value):443 return(1)444"""445 nonstandard_contract = self.state.abi_contract(code)446 ans = self.contract.add_market(447 "NON",448 nonstandard_contract.address,449 5,450 10 ** 8,451 10 ** 18,452 1)453 assert ans == MARKET_NONSTANDARD_TRANSFERFROM454 #455 # Trades456 #457 def test_add_buy_trades(self):458 self.test_initialize()459 self.initial_balance = self.state.block.get_balance(self.ALICE['address'])460 # Add buy trade461 ans = self.contract.buy(500 * 10 ** 5, int(0.25 * 10 ** 8), 1, value=125 * 10 ** 18, profiling=1)462 assert ans['output'] == 23490291715255176443338864873375620519154876621682055163056454432194948412040L463 logger.info("\nAdd buy profiling: %s" % ans)464 # Another buy trade465 ans = self.contract.buy(600 * 10 ** 5, int(0.25 * 10 ** 8), 1, value=150 * 10 ** 18, profiling=1)466 assert ans['output'] == -35168633768494065610302920664120686116555617894816459733689825088489895266148L467 logger.info("\nAdd 2nd buy profiling: %s" % ans)468 # And another469 ans = self.contract.buy(700 * 10 ** 5, int(0.25 * 10 ** 8), 1, value=175 * 10 ** 18, profiling=1)470 assert ans['output'] == 38936224262371094519907212029104196662516973526369593745812124922634258039407L471 logger.info("\nAdd 3rd buy profiling: %s" % ans)472 self.after_buy_balance = self.state.block.get_balance(self.ALICE['address'])...
test_lightbrarian.py
Source:test_lightbrarian.py
...4from .lightbrarian import *5google_api_token = os.environ['GOOGLE_API_TOKEN']6# Create temporary default_reading_list.json to be used for all the tests.7@pytest.fixture(scope='session')8def test_initialize(tmp_path_factory):9 lightbrarian_reading_list_path = tmp_path_factory.mktemp('.lightbrarian') / 'default_reading_list.json'10 initialize(lightbrarian_reading_list_path.parent, lightbrarian_reading_list_path)11 return lightbrarian_reading_list_path12# Invoke the search_books function and save the first search result to the reading list.13def test_search_and_save_book(test_initialize, monkeypatch):14 monkeypatch.setattr('builtins.input', lambda _: 1)15 16 books = search_books(17 command='search',18 book_title='The',19 book_author=None,20 book_publisher=None,21 max_results=5,22 google_api_token=google_api_token,...
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!!