-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test_: services approach #6171
test_: services approach #6171
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) |
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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
from constants import user_1, DEFAULT_DISPLAY_NAME | ||
|
||
|
||
|
||
class StatusBackend(RpcClient, SignalClient): | ||
|
||
def __init__(self, await_signals=[], url=None): | ||
|
@@ -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) | ||
|
||
|
@@ -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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe let's add 31337 to constants, something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fbarbu15 100% agree with you, It should definitely be done |
||
method = "RestoreAccountAndLogin" | ||
data = { | ||
"rootDataDir": data_dir, | ||
|
@@ -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", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -28,15 +29,16 @@ class StatusBackendTestCase: | |
SignalType.NODE_LOGIN.value | ||
] | ||
|
||
network_id = 31337 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and then you don't need to define it here again |
||
|
||
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): | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I like this approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1