Skip to content

Commit

Permalink
test_: WalletService class (#6171)
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-sirotin authored Dec 9, 2024
1 parent 943ae13 commit 4ccb08f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
7 changes: 5 additions & 2 deletions tests-functional/clients/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from conftest import option
from json import JSONDecodeError


class RpcClient:

def __init__(self, rpc_url, client=requests.Session()):
Expand Down Expand Up @@ -43,7 +44,9 @@ def verify_is_json_rpc_error(self, response):
self._check_decode_and_key_errors_in_response(response, "error")

@retry(stop=stop_after_delay(10), wait=wait_fixed(0.5), reraise=True)
def rpc_request(self, method, params=[], request_id=13, url=None):
def rpc_request(self, method, params=None, request_id=13, url=None):
if params is None:
params = []
url = url if url else self.rpc_url
data = {"jsonrpc": "2.0", "method": method, "id": request_id}
if params:
Expand All @@ -59,7 +62,7 @@ def rpc_request(self, method, params=[], request_id=13, url=None):
logging.info(f"Got response: {response.content}")
return response

def rpc_valid_request(self, method, params=[], _id=None, url=None):
def rpc_valid_request(self, method, params=None, _id=None, url=None):
response = self.rpc_request(method, params, _id, url)
self.verify_is_valid_json_rpc_response(response, _id)
return response
Expand Down
12 changes: 12 additions & 0 deletions tests-functional/clients/services/service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from clients.rpc import RpcClient


class Service:
def __init__(self, client: RpcClient, name: str):
assert name is not ""
self.rpc_client = client
self.name = name

def rpc_request(self, method: str, params=None):
full_method_name = f"{self.name}_{method}"
return self.rpc_client.rpc_request(full_method_name, params)
11 changes: 11 additions & 0 deletions tests-functional/clients/services/wallet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from clients.rpc import RpcClient
from clients.services.service import Service


class WalletService(Service):
def __init__(self, client: RpcClient):
super().__init__(client, "wallet")

def get_balances_at_by_chain(self, chains: list, addresses: list, tokens: list):
params = [chains, addresses, tokens]
return self.rpc_request("getBalancesByChain", params)
9 changes: 4 additions & 5 deletions tests-functional/clients/status_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from constants import user_1, DEFAULT_DISPLAY_NAME



class StatusBackend(RpcClient, SignalClient):

def __init__(self, await_signals=[], url=None):
Expand All @@ -27,7 +26,6 @@ def __init__(self, await_signals=[], url=None):
self.ws_url = f"{url}".replace("http", "ws")
self.rpc_url = f"{url}/statusgo/CallRPC"


RpcClient.__init__(self, self.rpc_url)
SignalClient.__init__(self, self.ws_url, await_signals)

Expand Down Expand Up @@ -83,7 +81,8 @@ def create_account_and_login(self, data_dir="/", display_name=DEFAULT_DISPLAY_NA
}
return self.api_valid_request(method, data)

def restore_account_and_login(self, data_dir="/",display_name=DEFAULT_DISPLAY_NAME, user=user_1):
def restore_account_and_login(self, data_dir="/",display_name=DEFAULT_DISPLAY_NAME, user=user_1,
network_id=31337):
method = "RestoreAccountAndLogin"
data = {
"rootDataDir": data_dir,
Expand All @@ -95,10 +94,10 @@ def restore_account_and_login(self, data_dir="/",display_name=DEFAULT_DISPLAY_NA
"logEnabled": True,
"logLevel": "DEBUG",
"testNetworksEnabled": False,
"networkId": 31337,
"networkId": network_id,
"networksOverride": [
{
"ChainID": 31337,
"ChainID": network_id,
"ChainName": "Anvil",
"DefaultRPCURL": "http://anvil:8545",
"RPCURL": "http://anvil:8545",
Expand Down
6 changes: 4 additions & 2 deletions tests-functional/tests/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import pytest

from clients.services.wallet import WalletService
from clients.signals import SignalClient, SignalType
from clients.status_backend import RpcClient, StatusBackend
from conftest import option
Expand All @@ -28,15 +29,16 @@ class StatusBackendTestCase:
SignalType.NODE_LOGIN.value
]

network_id = 31337

def setup_class(self):
self.rpc_client = StatusBackend(await_signals=self.await_signals)
self.wallet_service = WalletService(self.rpc_client)

self.rpc_client.init_status_backend()
self.rpc_client.restore_account_and_login()
self.rpc_client.wait_for_login()

self.network_id = 31337


class WalletTestCase(StatusBackendTestCase):

Expand Down

0 comments on commit 4ccb08f

Please sign in to comment.