def test_get_address_history_from(self): transfer = self.get_completed_op() transfer["incident_id"] = "cbeea30e-2218-4405-9089-86d003e4df81" transfer["chain_identifier"] = "chainidentifier_1235" transfer["customer_id"] = "user_memo_message" transfer["from"] = utils.get_exchange_account_id() implementations._get_os().insert_operation(transfer) history = implementations.get_address_history_to( get_tracking_address(transfer), 1, 0) self.assertEqual(history, [{ 'timestamp': history[0]['timestamp'], 'fromAddress': 'lykke-test', 'toAddress': 'lykke-dev-autotests:user_memo_message', 'assetId': '1.3.121', 'amount': '50000000', 'hash': 'chainidentifier_1235' }]) history = implementations.get_address_history_from( utils.get_exchange_account_id(), 1, 0) self.assertEqual(history, [{ 'timestamp': history[0]['timestamp'], 'fromAddress': 'lykke-test', 'toAddress': 'lykke-dev-autotests:user_memo_message', 'assetId': '1.3.121', 'amount': '50000000', 'hash': 'chainidentifier_1235' }])
def test_delete(self): op = self.get_in_progress_op() op["to"] = get_exchange_account_id() self.storage.insert_operation(op) op = self.get_completed_op() op["to"] = get_exchange_account_id() self.storage.flag_operation_completed(op) operations = self.storage.get_operations_completed() assert len(operations) == 1 self.storage.delete_operation(operations[0]) self.assertRaises(OperationNotFoundException, self.storage.delete_operation, operations[0]) assert len(self.storage.get_operations_in_progress()) == 0 assert len(self.storage.get_operations_completed()) == 0 filled_operation = self.get_in_progress_op() filled_operation["incident_id"] = "some_other_chain_identifier_1" self.storage.insert_operation(filled_operation) self.storage.delete_operation(filled_operation["incident_id"]) assert len(self.storage.get_operations_in_progress()) == 0
def test_split_address(self): unique_wallet = create_unique_address( utils.get_exchange_account_id(), lambda: "9ed8c906-d6ab-4fb8-a314-0516a175717a") address = split_unique_address(unique_wallet) assert address["account_id"] == utils.get_exchange_account_id()
def test_insert_and_complete(self): filled_operation = self.get_in_progress_op() self.storage.insert_operation(filled_operation) self.assertRaises(NoBlockNumException, self.storage.flag_operation_completed, filled_operation) filled_operation = self.get_completed_op() filled_operation["chain_identifier"] = "doesnt_exist" self.assertRaises(OperationNotFoundException, self.storage.flag_operation_completed, filled_operation) filled_operation = self.get_completed_op() filled_operation["to"] = get_exchange_account_id() self.storage.flag_operation_completed(filled_operation) filled_operation["status"] = "in-progress" self.assertRaises(StatusInvalidException, self.storage.flag_operation_completed, filled_operation) assert len(self.storage.get_operations_in_progress()) == 0 assert len(self.storage.get_operations_completed()) == 1 for document in self.storage.get_operations_completed(): assert document["chain_identifier"] == self.get_completed_op( )["chain_identifier"]
def test_tracking(self): address1 = create_unique_address(get_exchange_account_id()) address2 = create_unique_address("lykke-test") addr2s = split_unique_address(address2) self.storage.track_address(address1) self.assertRaises(AddressAlreadyTrackedException, self.storage.track_address, address1) self.storage.track_address(address2) filled_operation = self.get_completed_op() filled_operation["to"] = addr2s["account_id"] filled_operation["customer_id"] = addr2s["customer_id"] filled_operation["amount_asset_id"] = "1.3.4123" filled_operation["amount_value"] = 1234 self.storage.insert_operation(filled_operation) balances = self.storage.get_balances(2) assert address1 not in balances.keys() assert address2 in balances.keys() assert balances[address2]["1.3.4123"] == 1234 self.storage.untrack_address(address1) self.assertRaises(AddressNotTrackedException, self.storage.untrack_address, address1)
def test_get_and_delete_broadcasted(self): completed = self.get_completed_op() completed["incident_id"] = "cbeea30e-2218-4405-9089-86d003e4df83" completed["to"] = utils.get_exchange_account_id() implementations._get_os().insert_operation(completed) operation = implementations.get_broadcasted_transaction( "cbeea30e-2218-4405-9089-86d003e4df83") assert operation.get("block", None) is not None implementations.delete_broadcasted_transaction( "cbeea30e-2218-4405-9089-86d003e4df83") self.assertRaises(OperationNotFoundException, implementations.get_broadcasted_transaction, "cbeea30e-2218-4405-9089-86d003e4df81") in_progress = self.get_in_progress_op() in_progress["incident_id"] = "cbeea30e-2218-4405-9089-86d003e4df81" implementations._get_os().insert_operation(in_progress) implementations._get_os().flag_operation_failed(in_progress, message="manual fail") operation = implementations.get_broadcasted_transaction( "cbeea30e-2218-4405-9089-86d003e4df81") assert operation.get("block", None) is None
def test_build_transaction(self): from_id = utils.get_exchange_account_id() from_memo_key = utils.get_exchange_memo_key() tx = implementations.build_transaction( "cbeea30e-2218-4405-9089-86d003e4df88", from_id + DELIMITER + "from_customer_id", from_memo_key, self.get_customer_id() + DELIMITER + "to_customer_id", "1.3.0", 10000, False) tx = json.loads(tx["transactionContext"]) self.assertEqual(len(tx["operations"]), 1) self.assertEqual( tx["operations"][0][0], 0 # transfer ) op = tx["operations"][0][1] self.assertEqual( op["from"], from_id, # lykkee account id "1.2.397770", # blockchainbv account ) self.assertEqual(op["amount"]["asset_id"], "1.3.0") self.assertEqual(op["amount"]["amount"], 10000) self.assertGreater(op["fee"]["amount"], 0)
def test_create_unique_address(self): unique_wallet = create_unique_address( utils.get_exchange_account_id(), lambda: "9ed8c906-d6ab-4fb8-a314-0516a175717a") assert unique_wallet == utils.get_exchange_account_name( ) + ":9ed8c906-d6ab-4fb8-a314-0516a175717a"
def test_build_transaction_wrong_memo(self): from_id = "1.2.20139" from_memo_key = utils.get_exchange_memo_key() self.assertRaises( MemoMatchingFailedException, implementations.build_transaction, "cbeea30e-2218-4405-9089-86d003e4df40", from_id + DELIMITER + "from_customer_id", None, utils.get_exchange_account_id() + DELIMITER + "to_customer_id", "1.3.0", 10000, False) self.assertRaises( MemoMatchingFailedException, implementations.build_transaction, "cbeea30e-2218-4405-9089-86d003e4df30", from_id + DELIMITER + "from_customer_id", from_memo_key, utils.get_exchange_account_id() + DELIMITER + "to_customer_id", "1.3.0", 10000, False)
def test_get_balance(self): address = create_unique_address(get_exchange_account_id()) addrs = split_unique_address(address) asset = "1.3.131" self.storage.track_address(address) filled_operation = self.get_completed_op() filled_operation["to"] = addrs["account_id"] filled_operation["amount_asset_id"] = asset filled_operation["customer_id"] = addrs["customer_id"] filled_operation["incident_id"] = "some_operation_id_1" filled_operation["chain_identifier"] = "some_chain_identifier_1" filled_operation["amount_value"] = 10 self.storage.insert_operation(filled_operation) filled_operation["incident_id"] = "some_operation_id_2" filled_operation["chain_identifier"] = "some_chain_identifier_2" filled_operation["amount_value"] = 20 self.storage.insert_operation(filled_operation) filled_operation["incident_id"] = "some_operation_id_3" filled_operation["chain_identifier"] = "some_chain_identifier_3" filled_operation["amount_value"] = -5 self.storage.insert_operation(filled_operation) filled_operation["from"] = addrs["account_id"] filled_operation["to"] = get_exchange_account_id() filled_operation["incident_id"] = "some_operation_id_4" filled_operation["chain_identifier"] = "some_chain_identifier_4" filled_operation["amount_value"] = 7 self.storage.insert_operation(filled_operation) balances = self.storage.get_balances(2) assert balances[address][asset] == 18 self.assertRaises(InputInvalidException, self.storage.get_balances, 2, "§=)$") self.assertRaises(InputInvalidException, self.storage.get_balances, 2, "069548")
def test_broadcast_transaction(self): from_id = utils.get_exchange_account_id() from_memo_key = utils.get_exchange_memo_key() tx = manage_service.implementations.build_transaction( "cbeea30e-2218-4405-9089-86d003e4df84", from_id + DELIMITER + "from_customer_id", from_memo_key, self.get_customer_id() + DELIMITER + "to_customer_id", "1.3.0", 100000, False) stx = sign_service.implementations.sign( tx["transactionContext"], [utils.get_exchange_active_key()]) implementations.broadcast_transaction(stx["signedTransaction"])
def test_observe_address(self): address = create_unique_address("some_id", "user_name_bla") self.assertRaises(AccountDoesNotExistsException, implementations.observe_address, address) address = create_unique_address(utils.get_exchange_account_id(), "user_name_bla") implementations.observe_address(address) self.assertRaises(AddressAlreadyTrackedException, implementations.observe_address, address) implementations.unobserve_address(address) self.assertRaises(AddressNotTrackedException, implementations.unobserve_address, address)
def test_build_transaction2(self): from_id = utils.get_exchange_account_id() from_memo_key = utils.get_exchange_memo_key() tx = implementations.build_transaction( "cbeea30e-2218-4405-9089-86d003e4df86", from_id + DELIMITER + "from_customer_id", from_memo_key, self.get_customer_id() + DELIMITER + "to_customer_id", "1.3.0", 10000, True # This changes behavior!!!!!!!!!!!!!!! ) tx = json.loads(tx["transactionContext"]) op = tx["operations"][0][1] self.assertLess(op["amount"]["amount"], 10000) self.assertGreater(op["fee"]["amount"], 0)
def test_insert(self): filled_operation = self.get_in_progress_op() self.storage.insert_operation(filled_operation) filled_operation = self.get_completed_op() filled_operation["chain_identifier"] = "some_other_chain_identifier_1" filled_operation["incident_id"] = "some_other_incident_id" filled_operation["to"] = get_exchange_account_id() self.storage.insert_operation(filled_operation) self.assertRaises(DuplicateOperationException, self.storage.insert_operation, filled_operation) assert len(self.storage.get_operations_in_progress()) == 1 assert len(self.storage.get_operations_completed()) == 1 for document in self.storage.get_operations_in_progress(): assert document["incident_id"] ==\ self.get_in_progress_op()["incident_id"]
def test_get_balances(self): assert implementations.get_balances(1) ==\ {'continuation': None, 'items': []} transfer = self.get_completed_op() transfer["block_num"] = 1010 transfer["amount_asset_id"] = "1.3.0" transfer["customer_id"] = "user_name_bla" transfer["to"] = utils.get_exchange_account_id() first = transfer.copy() transfer["incident_id"] = "something_else" transfer["customer_id"] = "user_name_bla_2" transfer["chain_identifier"] = "24:25" transfer["amount_value"] = 50000001 second = transfer.copy() transfer["incident_id"] = "something_else_2" transfer["customer_id"] = "user_name_bla_3" transfer["chain_identifier"] = "24:24" transfer["amount_value"] = 50000002 third = transfer.copy() transfer["incident_id"] = "something_else_3" transfer["customer_id"] = "user_name_bla_3" transfer["chain_identifier"] = "24:26" transfer["from"] = utils.get_exchange_account_id() transfer["to"] = "some_dude" transfer["fee_value"] = 0 implementations.observe_address(get_tracking_address(first)) implementations.observe_address(get_tracking_address(second)) implementations.observe_address(get_tracking_address(third)) implementations._get_os().insert_operation(first) implementations._get_os().insert_operation(second) implementations._get_os().insert_operation(third) implementations._get_os().insert_operation(transfer) sleep(1) all_balances = [] result = implementations.get_balances(1) all_balances.append(result['items']) result = implementations.get_balances(1, result["continuation"]) all_balances.append(result['items']) result = implementations.get_balances(1, result["continuation"]) all_balances.append(result['items']) self.assertIn( [{ 'address': 'lykke-test:user_name_bla_2', 'assetId': '1.3.0', 'balance': 50000001, 'block': 1010 * 10 }], all_balances, ) self.assertIn( [{ 'address': 'lykke-test:user_name_bla', 'assetId': '1.3.0', 'balance': 50000000, 'block': 1010 * 10 }], all_balances, )