def test_transfer(): """Test transfer of wealth.""" def try_transact(cc1, cc2, amount) -> str: attempts = 0 while attempts < 3: fee = 1000 tx_digest = cosmos_api.transfer(cc1, cc2.address, amount, fee) assert tx_digest is not None, "Failed to submit transfer!" not_settled = True elapsed_time = 0 while not_settled and elapsed_time < 20: elapsed_time += 2 time.sleep(2) is_settled = cosmos_api.is_transaction_settled(tx_digest) not_settled = not is_settled is_settled = cosmos_api.is_transaction_settled(tx_digest) if is_settled: attempts = 3 else: attempts += 1 assert is_settled, "Failed to complete tx on 3 attempts!" return tx_digest cosmos_api = CosmosApi(**COSMOS_TESTNET_CONFIG) cc1 = CosmosCrypto(private_key_path=COSMOS_PRIVATE_KEY_PATH) cc2 = CosmosCrypto() amount = 10000 tx_digest = try_transact(cc1, cc2, amount) # TODO remove requirement for "" tx nonce stub is_valid = cosmos_api.is_transaction_valid(tx_digest, cc2.address, cc1.address, "", amount) assert is_valid, "Failed to settle tx correctly!"
def test_construct_sign_and_submit_transfer_transaction(): """Test the construction, signing and submitting of a transfer transaction.""" account = CosmosCrypto() balance = get_wealth(account.address) assert balance > 0, "Failed to fund account." cc2 = CosmosCrypto() cosmos_api = CosmosApi(**COSMOS_TESTNET_CONFIG) amount = 10000 assert amount < balance, "Not enough funds." transfer_transaction = cosmos_api.get_transfer_transaction( sender_address=account.address, destination_address=cc2.address, amount=amount, tx_fee=1000, tx_nonce="something", ) assert (isinstance(transfer_transaction, dict) and len(transfer_transaction) == 6), "Incorrect transfer_transaction constructed." signed_transaction = account.sign_transaction(transfer_transaction) assert (isinstance(signed_transaction, dict) and len(signed_transaction["tx"]) == 4 and isinstance(signed_transaction["tx"]["signatures"], list)), "Incorrect signed_transaction constructed." transaction_digest = cosmos_api.send_signed_transaction(signed_transaction) assert transaction_digest is not None, "Failed to submit transfer transaction!" not_settled = True elapsed_time = 0 while not_settled and elapsed_time < 20: elapsed_time += 1 time.sleep(2) transaction_receipt = cosmos_api.get_transaction_receipt( transaction_digest) if transaction_receipt is None: continue is_settled = cosmos_api.is_transaction_settled(transaction_receipt) not_settled = not is_settled assert transaction_receipt is not None, "Failed to retrieve transaction receipt." assert is_settled, "Failed to verify tx!" tx = cosmos_api.get_transaction(transaction_digest) is_valid = cosmos_api.is_transaction_valid(tx, cc2.address, account.address, "", amount) assert is_valid, "Failed to settle tx correctly!" assert tx == transaction_receipt, "Should be same!"