def test_exchange(test_client, user_with_reserve_balance, initialised_blockchain_network, from_token, to_token, from_amount, status_code): from_token_obj = initialised_blockchain_network[from_token] to_token_obj = initialised_blockchain_network[to_token] response = test_client.post( '/api/v1/me/exchange/', headers=dict( Authorization=get_complete_auth_token(user_with_reserve_balance), Accept='application/json'), json={ 'from_token_id': from_token_obj.id, 'to_token_id': to_token_obj.id, 'from_amount': from_amount }) assert response.status_code == status_code if status_code == 200 and will_func_test_blockchain(): task_uuid = response.json['data']['exchange']['blockchain_task_uuid'] time.sleep( 1) # Have to wait til after_request for task to be submitted result = bt.await_task_success(task_uuid, timeout=config.SYNCRONOUS_TASK_TIMEOUT * 12) assert result['status'] == 'SUCCESS'
def mock_blockchain_tasks(monkeymodule): from server import bt if will_func_test_blockchain(): print( '~~~NOT Mocking Blockchain Endpoints, Eth Worker will be tested~~~' ) else: print( '~~~Mocking Blockchain Endpoints, Eth Worker will NOT be tested~~~' ) mock_class(bt, MockBlockchainTasker, monkeymodule)
def inner(address): if will_func_test_blockchain(): w3 = Web3(HTTPProvider(config.ETH_HTTP_PROVIDER)) tx_hash = w3.eth.sendTransaction({ 'to': address, 'from': w3.eth.accounts[0], 'value': 5 * 10**18 }) hash = w3.eth.waitForTransactionReceipt(tx_hash) # print(f' Load account result {hash}') return hash
def wait_for_worker_boot_if_needed(): TIMEOUT = 60 from server.utils.celery_utils import get_celery_worker_status from helpers.utils import will_func_test_blockchain if will_func_test_blockchain(): elapsed = 0 while elapsed < TIMEOUT: worker_status = get_celery_worker_status() if 'ERROR' not in worker_status: print("Celery Workers Found") return sleep(1) elapsed += 1 raise Exception("Timeout while waiting for celery workers") else: print("Not testing blockchain; not waiting for celery workers") return
def test_force_third_party_transaction_sync(): if will_func_test_blockchain(): task_uuid = bt.force_third_party_transaction_sync() bt.await_task_success( task_uuid, timeout=config.CHAINS['ETHEREUM']['SYNCRONOUS_TASK_TIMEOUT'] * 48)