def test_create_wallet_unique_for_key_pair(self): """Tests the transaction with the same keys for different wallets is failed""" for validator_id in range(self.network.validators_count()): host, public_port, private_port = self.network.api_address( validator_id) client = ExonumClient(host, public_port, private_port) with ExonumCryptoAdvancedClient(client) as crypto_client: alice_keys = KeyPair.generate() tx_response = crypto_client.create_wallet( alice_keys, "Alice" + str(validator_id)) with client.create_subscriber("blocks") as subscriber: subscriber.wait_for_new_event() # TODO: Sometimes it fails without time.sleep() [ECR-3876] time.sleep(2) tx_status = client.get_tx_info( tx_response.json()['tx_hash']).json()['status']['type'] self.assertEqual(tx_status, 'success') # create the wallet with the same keys again tx_same_keys = crypto_client.create_wallet( alice_keys, "Alice_Dublicate" + str(validator_id)) with client.create_subscriber("blocks") as subscriber: subscriber.wait_for_new_event() tx_status = client.get_tx_info( tx_same_keys.json()['tx_hash']).json()['status']['type'] self.assertEqual(tx_status, 'service_error')
def test_transfer_funds_insufficient(self): """Tests the transfer insufficient amount of funds is failed""" for validator_id in range(self.network.validators_count()): host, public_port, private_port = self.network.api_address( validator_id) client = ExonumClient(host, public_port, private_port) with ExonumCryptoAdvancedClient(client) as crypto_client: alice_keys = KeyPair.generate() crypto_client.create_wallet(alice_keys, "Alice" + str(validator_id)) bob_keys = KeyPair.generate() crypto_client.create_wallet(bob_keys, "Bob" + str(validator_id)) with client.create_subscriber("blocks") as subscriber: subscriber.wait_for_new_event() tx_response = crypto_client.transfer( 110, alice_keys, bob_keys.public_key.value) subscriber.wait_for_new_event() tx_status = client.get_tx_info( tx_response.json()['tx_hash']).json()['status']['type'] self.assertEqual(tx_status, 'service_error') alice_balance = (crypto_client.get_wallet_info( alice_keys).json()['wallet_proof']['to_wallet'] ['entries'][0]['value']['balance']) bob_balance = (crypto_client.get_wallet_info( bob_keys).json()['wallet_proof']['to_wallet'] ['entries'][0]['value']['balance']) self.assertEqual(alice_balance, 100) self.assertEqual(bob_balance, 100)
def ensure_transaction_success(client: ExonumClient, tx_hash: str) -> None: """Checks that the transaction is committed and the status is success.""" tx_info_response = client.get_tx_info(tx_hash) ensure_status_code(tx_info_response) tx_info = tx_info_response.json() if not (tx_info["type"] == "committed" and tx_info["status"]["type"] == "success"): raise RuntimeError(f"Error occured during transaction execution: {tx_info}")
def test_get_unknown_transaction(self): """Tests the `transactions` endpoint. Check response for unknown transaction""" for validator_id in range(self.network.validators_count()): host, public_port, private_port = self.network.api_address( validator_id) client = ExonumClient(host, public_port, private_port) tx_response = client.get_tx_info( "b2d09e1bddca851bee8faf8ffdcfc18cb87fbde167a29bd049fa2eee4a82c1ca" ) self.assertEqual(tx_response.status_code, 404) self.assertEqual(tx_response.json()['type'], "unknown")
def test_add_funds_to_nonexistent_wallet(self): """Tests the funds issue is failed if wallet doesn't exist""" for validator_id in range(self.network.validators_count()): host, public_port, private_port = self.network.api_address( validator_id) client = ExonumClient(host, public_port, private_port) with ExonumCryptoAdvancedClient(client) as crypto_client: alice_keys = KeyPair.generate() tx_response = crypto_client.issue(alice_keys, 100) with client.create_subscriber("blocks") as subscriber: subscriber.wait_for_new_event() # TODO: Sometimes it fails without time.sleep() [ECR-3876] time.sleep(2) tx_status = client.get_tx_info( tx_response.json()['tx_hash']).json()['status']['type'] self.assertEqual(tx_status, 'service_error')