Esempio n. 1
0
def test_send_signed_transaction_wasm_transaction():
    """Test the send_signed_transaction method for a wasm transaction."""
    cosmos_api = FetchAIApi(**FETCHAI_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"
Esempio n. 2
0
def test_construct_sign_and_submit_transfer_transaction():
    """Test the construction, signing and submitting of a transfer transaction."""
    account = FetchAICrypto()
    balance = get_wealth(account.address)
    assert balance > 0, "Failed to fund account."
    fc2 = FetchAICrypto()
    fetchai_api = FetchAIApi(**FETCHAI_TESTNET_CONFIG)

    amount = 10000
    assert amount < balance, "Not enough funds."
    transfer_transaction = fetchai_api.get_transfer_transaction(
        sender_address=account.address,
        destination_address=fc2.address,
        amount=amount,
        tx_fee=1000,
        tx_nonce="",
    )
    assert isinstance(
        transfer_transaction,
        Transaction), "Incorrect transfer_transaction constructed."

    signed_transaction = account.sign_transaction(transfer_transaction)
    assert (isinstance(signed_transaction, Transaction)
            and len(signed_transaction.signatures)
            == 1), "Incorrect signed_transaction constructed."

    transaction_digest = fetchai_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 = fetchai_api.get_transaction_receipt(
            transaction_digest)
        if transaction_receipt is None:
            continue
        is_settled = fetchai_api.is_transaction_settled(transaction_receipt)
        if is_settled is None:
            continue
        not_settled = not is_settled
    assert transaction_receipt is not None, "Failed to retrieve transaction receipt."
    assert is_settled, "Failed to verify tx!"

    tx = fetchai_api.get_transaction(transaction_digest)
    assert tx != transaction_receipt, "Should be same!"
    is_valid = fetchai_api.is_transaction_valid(tx, fc2.address,
                                                account.address, "", amount)
    assert is_valid, "Failed to settle tx correctly!"