[ISSUE #166] Added test for sending ETH after request command

This commit is contained in:
yevh-berdnyk 2017-11-09 12:55:02 +02:00 committed by Anton Danchenko
parent af97424146
commit 63848efc20
8 changed files with 173 additions and 78 deletions

View File

@ -0,0 +1,38 @@
import logging
import pytest
import requests
import time
def get_transactions(address: str) -> dict:
url = 'http://ropsten.etherscan.io/api?module=account&action=txlist&address=0x%s&sort=desc' % address
return requests.request('GET', url=url).json()['result']
def is_transaction_successful(transaction_hash: str) -> int:
url = "https://ropsten.etherscan.io/api?module=transaction&action=getstatus&txhash=%s" % transaction_hash
return not int(requests.request('GET', url=url).json()['result']['isError'])
def get_balance(address):
url = 'http://ropsten.etherscan.io/api?module=account&action=balance&address=0x%s&tag=latest' % address
for i in range(5):
try:
return int(requests.request('GET', url).json()["result"])
except ValueError:
pass
def verify_balance_is_updated(initial_balance, recipient_address, wait_time=120):
counter = 0
while True:
if counter == wait_time:
pytest.fail('Balance is not changed during %s seconds, funds were not received!' % wait_time)
elif initial_balance == get_balance(recipient_address):
counter += 10
time.sleep(10)
logging.info('Waiting %s seconds for funds' % counter)
else:
logging.info('Transaction was received and verified on ropsten.etherscan.io')
break

View File

@ -0,0 +1,6 @@
import requests
def get_ethereum_price_in_usd() -> float:
url = 'https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD'
return float(requests.request('GET', url).json()['USD'])

View File

@ -1,12 +1,17 @@
import pytest
from selenium.common.exceptions import NoSuchElementException
from apis.ropsten_api import get_balance, verify_balance_is_updated
from tests.basetestcase import MultiplyDeviceTestCase
from tests.preconditions import set_password_as_new_user, change_user_details
from tests.preconditions import set_password_as_new_user, change_user_details, recover_access
from tests import transaction_users
from views.base_view import verify_transaction_in_ropsten
from views.chats import get_unique_amount
from views.home import HomeView
@pytest.mark.all
class TestMultiplyDevices(MultiplyDeviceTestCase):
@pytest.mark.discover
def test_new_profile_name_and_status_on_discover(self):
device_1, device_2 = HomeView(self.driver_1), HomeView(self.driver_2)
@ -167,3 +172,55 @@ class TestMultiplyDevices(MultiplyDeviceTestCase):
message_text = chats_d1.element_by_text(message_3, 'text')
if message_text.is_element_present(20):
pytest.fail('Message is shown for the user which has been removed from the GroupChat', False)
@pytest.mark.chat
def test_send_funds_via_request_in_one_to_one_chat(self):
recipient = transaction_users['A_USER']
sender = transaction_users['B_USER']
device_1, device_2 = HomeView(self.driver_1), HomeView(self.driver_2)
recover_access(device_1,
passphrase=recipient['passphrase'],
password=recipient['password'],
username=recipient['username'])
chats_d1 = device_1.get_chats()
recover_access(device_2,
passphrase=sender['passphrase'],
password=sender['password'],
username=sender['username'])
chats_d2 = device_2.get_chats()
try:
chats_d1.element_by_text_part(sender['username'][:25], 'button').click()
except NoSuchElementException:
chats_d1.plus_button.click()
chats_d1.add_new_contact.click()
chats_d1.public_key_edit_box.send_keys(sender['public_key'])
chats_d1.confirm()
chats_d1.confirm_public_key_button.click()
chats_d1.request_funds_button.click()
amount = get_unique_amount()
chats_d1.chat_message_input.set_value(amount)
chats_d1.send_message_button.click()
initial_balance_recipient = get_balance(recipient['address'])
chats_d2.element_by_text_part(recipient['username'][:25], 'button').click()
chats_d2.element_by_text('Requesting %s ETH' % amount, 'button').click()
chats_d2.send_message_button.click()
chats_d2.sign_transaction_button.click()
chats_d2.enter_password_input.send_keys(sender['password'])
chats_d2.sign_transaction_button.click()
chats_d2.got_it_button.click()
verify_balance_is_updated(initial_balance_recipient, recipient['address'])
chats_d2.verify_amount_is_sent(amount)
chats_d2.back_button.click()
wallet = chats_d2.wallet_button.click()
tr_view = wallet.transactions_button.click()
transaction = tr_view.transactions_table.find_transaction(amount=amount)
details_view = transaction.click()
transaction_hash = details_view.get_transaction_hash()
verify_transaction_in_ropsten(address=sender['address'], transaction_hash=transaction_hash)

View File

@ -1,8 +1,10 @@
import pytest
import time
from apis.ropsten_api import verify_balance_is_updated, get_balance
from tests.basetestcase import SingleDeviceTestCase
from views.home import HomeView
from tests.preconditions import set_password_as_new_user, recover_access
from tests.preconditions import recover_access
from tests import transaction_users
from selenium.common.exceptions import TimeoutException
@ -29,7 +31,7 @@ class TestTransactions(SingleDeviceTestCase):
sender_address = transaction_users[sender]['address']
recipient_address = transaction_users[recipient]['address']
recipient_key = transaction_users[recipient]['public_key']
initial_balance_recipient = chats.get_balance(recipient_address)
initial_balance_recipient = get_balance(recipient_address)
chats.plus_button.click()
chats.add_new_contact.click()
@ -75,7 +77,7 @@ class TestTransactions(SingleDeviceTestCase):
chats.find_full_text('Delivered', 10)
if test == 'group_chat':
chats.find_full_text('to ' + transaction_users[recipient]['username'], 60)
chats.verify_balance_is_updated(initial_balance_recipient, recipient_address)
verify_balance_is_updated(initial_balance_recipient, recipient_address)
@pytest.mark.transaction
def test_send_transaction_from_daap(self):
@ -87,7 +89,7 @@ class TestTransactions(SingleDeviceTestCase):
chats = home.get_chats()
address = transaction_users['B_USER']['address']
initial_balance = chats.get_balance(address)
initial_balance = get_balance(address)
contacts = chats.contacts_button.click()
auction_house = contacts.auction_house_button.click()
@ -104,4 +106,4 @@ class TestTransactions(SingleDeviceTestCase):
chats.sign_transaction_button.click()
chats.got_it_button.click()
auction_house.find_full_text('You are the proud owner of the name: ' + auction_name, 120)
chats.verify_balance_is_updated(initial_balance, address)
verify_balance_is_updated(initial_balance, address)

View File

@ -1,8 +1,10 @@
from datetime import datetime
import pytest
from apis.ropsten_api import get_balance, verify_balance_is_updated
from apis.third_party_apis import get_ethereum_price_in_usd
from tests.basetestcase import SingleDeviceTestCase
from views.base_view import get_ethereum_price_in_usd, verify_transaction_in_ropsten
from views.base_view import verify_transaction_in_ropsten
from views.chats import get_unique_amount
from views.home import HomeView
from tests.preconditions import set_password_as_new_user, recover_access
from tests import transaction_users
@ -41,7 +43,7 @@ class TestWallet(SingleDeviceTestCase):
recipient_key = transaction_users[recipient]['public_key']
recipient_address = transaction_users[recipient]['address']
initial_balance_recipient = chats.get_balance(recipient_address)
initial_balance_recipient = get_balance(recipient_address)
chats.plus_button.click()
chats.add_new_contact.click()
@ -54,7 +56,7 @@ class TestWallet(SingleDeviceTestCase):
wallet = chats.wallet_button.click()
wallet.send_button.click()
wallet.amount_edit_box.click()
amount = '0,0%s' % datetime.now().strftime('%-m%-d%-H%-M%-S')
amount = get_unique_amount()
wallet.send_as_keyevent(amount)
wallet.confirm()
wallet.chose_recipient_button.click()
@ -75,13 +77,13 @@ class TestWallet(SingleDeviceTestCase):
chats.enter_password_input.send_keys(transaction_users[sender]['password'])
chats.sign_transaction_button.click()
chats.got_it_button.click()
chats.verify_balance_is_updated(initial_balance_recipient, recipient_address)
verify_balance_is_updated(initial_balance_recipient, recipient_address)
if test == 'sign_later':
tr_view.history_tab.click()
else:
chats.wallet_button.click()
tr_view = wallet.transactions_button.click()
transaction = tr_view.transactions_table.find_transaction(amount=amount.replace(',', '.'))
transaction = tr_view.transactions_table.find_transaction(amount=amount)
details_view = transaction.click()
transaction_hash = details_view.get_transaction_hash()
verify_transaction_in_ropsten(address=transaction_users[sender]['address'], transaction_hash=transaction_hash)
@ -96,7 +98,7 @@ class TestWallet(SingleDeviceTestCase):
username=transaction_users['A_USER']['username'])
chats = home.get_chats()
address = transaction_users['A_USER']['address']
balance = chats.get_balance(address) / 1000000000000000000
balance = get_balance(address) / 1000000000000000000
eth_rate = get_ethereum_price_in_usd()
wallet = chats.wallet_button.click()
wallet_balance = wallet.get_eth_value()

View File

@ -1,3 +1,6 @@
from selenium.common.exceptions import NoSuchElementException
from apis.ropsten_api import get_transactions, is_transaction_successful, get_balance
from views.base_element import BaseElement, BaseButton, BaseEditBox, BaseText
import logging
import time
@ -17,6 +20,20 @@ class BackButton(BaseButton):
return self.navigate()
class AllowButton(BaseButton):
def __init__(self, driver):
super(AllowButton, self).__init__(driver)
self.locator = self.Locator.xpath_selector("//*[@text='Allow']")
def click(self):
try:
for _ in range(3):
self.find_element().click()
except NoSuchElementException:
pass
logging.info('Tap on %s' % self.name)
class DenyButton(BaseButton):
def __init__(self, driver):
super(DenyButton, self).__init__(driver)
@ -77,21 +94,6 @@ class ContinueButtonAPK(BaseButton):
self.locator = self.Locator.xpath_selector("//*[@text='Continue']")
def get_ethereum_price_in_usd() -> float:
url = 'https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD'
return float(requests.request('GET', url).json()['USD'])
def get_transactions(address: str) -> dict:
url = 'http://ropsten.etherscan.io/api?module=account&action=txlist&address=0x%s&sort=desc' % address
return requests.request('GET', url=url).json()['result']
def is_transaction_successful(transaction_hash: str) -> int:
url = "https://ropsten.etherscan.io/api?module=transaction&action=getstatus&txhash=%s" % transaction_hash
return not int(requests.request('GET', url=url).json()['result']['isError'])
def verify_transaction_in_ropsten(address: str, transaction_hash: str):
transactions = get_transactions(address=address)
for transaction in transactions:
@ -138,6 +140,7 @@ class BaseViewObject(object):
self.yes_button = YesButton(self.driver)
self.no_button = NoButton(self.driver)
self.back_button = BackButton(self.driver)
self.allow_button = AllowButton(self.driver)
self.deny_button = DenyButton(self.driver)
self.continue_button_apk = ContinueButtonAPK(self.driver)
self.ok_button_apk = OkButtonAPK(self.driver)
@ -193,6 +196,19 @@ class BaseViewObject(object):
element.locator = element.Locator.xpath_selector('//*[@text="' + text + '"]')
return element
def element_by_text_part(self, text, element_type='base'):
element_types = {
'base': BaseElement,
'button': BaseButton,
'edit_box': BaseEditBox,
'text': BaseText
}
element = element_types[element_type](self.driver)
element.locator = element.Locator.xpath_selector('//*[contains(@text, "' + text + '")]')
return element
def get_chats(self):
from views.chats import ChatsViewObject
return ChatsViewObject(self.driver)
@ -201,39 +217,18 @@ class BaseViewObject(object):
from views.login import LoginView
return LoginView(self.driver)
def get_balance(self, address):
url = 'http://ropsten.etherscan.io/api?module=account&action=balance&address=0x%s&tag=latest' % address
for i in range(5):
try:
return int(requests.request('GET', url).json()["result"])
except ValueError:
pass
def get_donate(self, address, wait_time=300):
initial_balance = self.get_balance(address)
initial_balance = get_balance(address)
counter = 0
if initial_balance < 1000000000000000000:
response = requests.request('GET', 'http://46.101.129.137:3001/donate/0x%s' % address).json()
while True:
if counter == wait_time:
pytest.fail("Donation was not received during %s seconds!" % wait_time)
elif self.get_balance(address) == initial_balance:
elif get_balance(address) == initial_balance:
counter += 10
time.sleep(10)
logging.info('Waiting %s seconds for donation' % counter)
else:
logging.info('Got %s for %s' % (response["amount"], address))
break
def verify_balance_is_updated(self, initial_balance, recipient_address, wait_time=120):
counter = 0
while True:
if counter == wait_time:
pytest.fail('Balance is not changed during %s seconds, funds were not received!' % wait_time)
elif initial_balance == self.get_balance(recipient_address):
counter += 10
time.sleep(10)
logging.info('Waiting %s seconds for funds' % counter)
else:
logging.info('Transaction was received and verified on ropsten.etherscan.io')
break

View File

@ -1,16 +1,16 @@
from datetime import datetime
from views.base_view import BaseViewObject
import time
from views.base_element import *
class ProfileButton(BaseButton):
def __init__(self, driver):
super(ProfileButton, self).__init__(driver)
self.locator = self.Locator.accessibility_id('toolbar-hamburger-menu')
class ProfileIcon(BaseButton):
def __init__(self, driver):
super(ProfileButton.ProfileIcon, self).__init__(driver)
self.locator = self.Locator.accessibility_id('drawer-profile-icon')
@ -20,7 +20,6 @@ class ProfileButton(BaseButton):
return ProfileViewObject(self.driver)
class SwitchUsersButton(BaseButton):
def __init__(self, driver):
super(ProfileButton.SwitchUsersButton, self).__init__(driver)
self.locator = self.Locator.xpath_selector("//android.widget.TextView[@text='SWITCH USERS']")
@ -37,7 +36,6 @@ class ProfileButton(BaseButton):
class PlusButton(BaseButton):
def __init__(self, driver):
super(PlusButton, self).__init__(driver)
self.locator = self.Locator.xpath_selector(
@ -45,7 +43,6 @@ class PlusButton(BaseButton):
class ConsoleButton(BaseButton):
def __init__(self, driver):
super(ConsoleButton, self).__init__(driver)
self.locator = self.Locator.xpath_selector(
@ -53,7 +50,6 @@ class ConsoleButton(BaseButton):
class AddNewContactButton(BaseButton):
def __init__(self, driver):
super(AddNewContactButton, self).__init__(driver)
self.locator = self.Locator.xpath_selector(
@ -61,14 +57,12 @@ class AddNewContactButton(BaseButton):
class NewContactButton(BaseButton):
def __init__(self, driver):
super(NewContactButton, self).__init__(driver)
self.locator = self.Locator.xpath_selector("//android.widget.TextView[@text='']")
class NewGroupChatButton(BaseButton):
def __init__(self, driver):
super(NewGroupChatButton, self).__init__(driver)
self.locator = self.Locator.xpath_selector(
@ -110,7 +104,6 @@ class NewGroupChatButton(BaseButton):
class PublicKeyEditBox(BaseEditBox):
def __init__(self, driver):
super(PublicKeyEditBox, self).__init__(driver)
self.locator = \
@ -118,7 +111,6 @@ class PublicKeyEditBox(BaseEditBox):
class ConfirmPublicKeyButton(BaseButton):
def __init__(self, driver):
super(ConfirmPublicKeyButton, self).__init__(driver)
self.locator = \
@ -126,14 +118,12 @@ class ConfirmPublicKeyButton(BaseButton):
class ChatMessageInput(BaseEditBox):
def __init__(self, driver):
super(ChatMessageInput, self).__init__(driver)
self.locator = self.Locator.accessibility_id('chat-message-input')
class SendMessageButton(BaseButton):
def __init__(self, driver):
super(SendMessageButton, self).__init__(driver)
self.locator = self.Locator.accessibility_id("send-message-button")
@ -144,14 +134,12 @@ class SendMessageButton(BaseButton):
class AddToContacts(BaseButton):
def __init__(self, driver):
super(AddToContacts, self).__init__(driver)
self.locator = self.Locator.xpath_selector("//*[@text='Add to contacts']")
class UserNameText(BaseText):
def __init__(self, driver):
super(UserNameText, self).__init__(driver)
self.locator = \
@ -159,57 +147,54 @@ class UserNameText(BaseText):
class SendFundsButton(BaseButton):
def __init__(self, driver):
super(SendFundsButton, self).__init__(driver)
self.locator = self.Locator.xpath_selector("//*[@text='/send']")
class FirstRecipient(BaseButton):
def __init__(self, driver):
super(SendFundsButton.FirstRecipient, self).__init__(driver)
self.locator = self.Locator.xpath_selector("//*[@text='Choose recipient']/.."
"//android.widget.ImageView[@content-desc='chat-icon']")
class SignTransactionButton(BaseButton):
def __init__(self, driver):
super(SendFundsButton.SignTransactionButton, self).__init__(driver)
self.locator = self.Locator.xpath_selector("//*[@text='SIGN TRANSACTION']")
class SignLaterButton(BaseButton):
def __init__(self, driver):
super(SendFundsButton.SignLaterButton, self).__init__(driver)
self.locator = self.Locator.xpath_selector("//*[@text='SIGN LATER']")
class PasswordInput(BaseEditBox):
def __init__(self, driver):
super(SendFundsButton.PasswordInput, self).__init__(driver)
self.locator = self.Locator.xpath_selector("//*[@text='Password']")
class EnterPasswordInput(BaseEditBox):
def __init__(self, driver):
super(SendFundsButton.EnterPasswordInput, self).__init__(driver)
self.locator = self.Locator.xpath_selector("//android.widget.EditText[@NAF='true']")
class ConfirmButton(BaseButton):
def __init__(self, driver):
super(SendFundsButton.ConfirmButton, self).__init__(driver)
self.locator = self.Locator.xpath_selector("//*[@text='CONFIRM']")
class GotItButton(BaseButton):
def __init__(self, driver):
super(SendFundsButton.GotItButton, self).__init__(driver)
self.locator = self.Locator.xpath_selector("//*[@text='GOT IT']")
class ChatsViewObject(BaseViewObject):
class RequestFundsButton(BaseButton):
def __init__(self, driver):
super(RequestFundsButton, self).__init__(driver)
self.locator = self.Locator.xpath_selector("//*[@text='/request']")
class ChatsViewObject(BaseViewObject):
def __init__(self, driver):
super(ChatsViewObject, self).__init__(driver)
self.driver = driver
@ -250,6 +235,8 @@ class ChatsViewObject(BaseViewObject):
self.new_contact_button = NewContactButton(self.driver)
self.request_funds_button = RequestFundsButton(self.driver)
def wait_for_syncing_complete(self):
logging.info('Waiting for syncing complete:')
while True:
@ -258,3 +245,11 @@ class ChatsViewObject(BaseViewObject):
logging.info(sync.text)
except TimeoutException:
break
def verify_amount_is_sent(self, amount):
self.driver.find_element(
BaseElement.Locator.xpath_selector("//*[@text='/send']/../../*[@text='%s']/../*[@text='ETH']" % amount))
def get_unique_amount():
return '0.00%s' % datetime.now().strftime('%-m%-d%-H%-M%-S').strip('0')

View File

@ -44,7 +44,7 @@ class TransactionTable(BaseElement):
def find_transaction(self, amount: str) -> TransactionElement:
for i in range(18):
try:
element = self.get_transaction_element(amount=amount)
element = self.get_transaction_element(amount=amount.replace(',', '.'))
element.find_element()
return element
except NoSuchElementException: