def test_send_signed_transaction_wasm_transaction(): """Test the send_signed_transaction method for a wasm transaction.""" cosmos_api = CosmosApi(**COSMOS_TESTNET_CONFIG) tx_signed = {"value": {"msg": [{"type": "wasm/store-code"}]}} with mock.patch.object(cosmos_api, "try_execute_wasm_transaction", return_value="digest"): result = cosmos_api.send_signed_transaction(tx_signed=tx_signed) assert result == "digest"
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!"