Skip to content
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

Merged
merged 1 commit into from
Dec 9, 2024
Merged

Conversation

igor-sirotin
Copy link
Collaborator

@igor-sirotin igor-sirotin commented Dec 5, 2024

  1. Added Service and WalletService(Service) classes.

    This is a way to group requests by service. They use given RpcClient and wrap requests to given service name.
    Instance of WalletService is created in StatusBackendTestCase.

    @antdanchenko @fbarbu15 @yevh-berdnyk let me know if you like the initiative.

  2. Fixed linter complaining about params=[] default argument value

  3. Added network_id argument to restore_account_and_login

4. Implemented test_get_balance_error test for #6169
(this PR is targeting that PR branch)

closes #6308

@status-im-auto
Copy link
Member

status-im-auto commented Dec 5, 2024

Jenkins Builds

Click to see older builds (9)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 47c6a28 #1 2024-12-05 14:50:44 ~4 min ios 📦zip
✔️ 47c6a28 #1 2024-12-05 14:50:52 ~4 min macos 📦zip
✔️ 47c6a28 #1 2024-12-05 14:51:01 ~5 min linux 📦zip
✔️ 47c6a28 #1 2024-12-05 14:51:19 ~5 min android 📦aar
✔️ 47c6a28 #1 2024-12-05 14:52:41 ~6 min windows 📦zip
✔️ 47c6a28 #1 2024-12-05 14:52:50 ~6 min tests-rpc 📄log
✔️ 47c6a28 #1 2024-12-05 14:54:51 ~8 min macos 📦zip
✖️ 47c6a28 #1 2024-12-05 15:17:21 ~31 min tests 📄log
✔️ 47c6a28 #2 2024-12-05 17:14:07 ~29 min tests 📄log
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ e811c66 #2 2024-12-06 21:55:55 ~5 min macos 📦zip
✔️ e811c66 #2 2024-12-06 21:55:55 ~5 min windows 📦zip
✔️ e811c66 #2 2024-12-06 21:56:17 ~5 min linux 📦zip
✔️ e811c66 #2 2024-12-06 21:56:22 ~5 min android 📦aar
✔️ e811c66 #2 2024-12-06 21:56:57 ~6 min ios 📦zip
✔️ e811c66 #2 2024-12-06 21:57:11 ~6 min tests-rpc 📄log
✔️ e811c66 #2 2024-12-06 21:59:53 ~9 min macos 📦zip
✔️ e811c66 #3 2024-12-06 22:21:23 ~30 min tests 📄log
✔️ 338df8d #3 2024-12-09 11:50:46 ~4 min windows 📦zip
✔️ 338df8d #3 2024-12-09 11:51:40 ~5 min linux 📦zip
✔️ 338df8d #3 2024-12-09 11:51:56 ~5 min android 📦aar
✔️ 338df8d #3 2024-12-09 11:52:01 ~5 min macos 📦zip
✔️ 338df8d #3 2024-12-09 11:52:39 ~5 min tests-rpc 📄log
✔️ 338df8d #3 2024-12-09 11:54:36 ~8 min ios 📦zip
✔️ 338df8d #3 2024-12-09 11:56:40 ~10 min macos 📦zip
✔️ 338df8d #4 2024-12-09 12:16:27 ~29 min tests 📄log

@igor-sirotin
Copy link
Collaborator Author

@osmaczko correctly pointed out that it might be an overkill to test such simple thing with a function test.
Such things should be tested with simpler tests. I'll check if it's possible.

Copy link
Contributor

@fbarbu15 fbarbu15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with minor comments


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

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@@ -80,7 +78,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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe let's add 31337 to constants, something like
DEFAULT_NETWORK_ID

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fbarbu15 100% agree with you, It should definitely be done
But it's better do it outside of this PR not to mess up things. 31337 is duplicated in quite many places already.

@@ -28,15 +29,16 @@ class StatusBackendTestCase:
SignalType.NODE_READY.value
]

network_id = 31337
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and then you don't need to define it here again

assert 'error' in json_response
assert json_response['error']['message'] == expected_error

# Test invalid contract
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be a different test? This way having Test invalid network fail would lead to Test invalid contract not beeing executed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fbarbu15 good point. It should probably even be possible to parametrize this test.

But what I've done instead, is I've rewritten this in status-go, so I will completely remove it from here. Just keep the services approach proposal.

// Test errors
chainClients = map[uint64]chain.ClientInterface{
w_common.ArbitrumMainnet: chainClientArb,
}
balances, err := bf.GetBalancesAtByChain(ctx, chainClients, nil, nil, atBlocks)
require.Error(t, err)
require.ErrorContains(t, err, errScanningContract.Error())
require.Nil(t, balances)

Turned out that this test is much simpler on status-go level with mocks. Thanks @osmaczko for heads up. Details in #6171 (comment).

@igor-sirotin igor-sirotin force-pushed the fix/GetBalancesAtByChain-error branch from 082b392 to c7903a8 Compare December 6, 2024 20:50
@igor-sirotin igor-sirotin force-pushed the test/failing-get_balance_at_by_chain branch from 47c6a28 to e811c66 Compare December 6, 2024 21:50
@igor-sirotin igor-sirotin changed the base branch from fix/GetBalancesAtByChain-error to develop December 6, 2024 21:50
@igor-sirotin igor-sirotin changed the title test_: Services approach test_: services approach Dec 6, 2024
Copy link

codecov bot commented Dec 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.93%. Comparing base (943ae13) to head (338df8d).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff              @@
##           develop    #6171       +/-   ##
============================================
+ Coverage    13.91%   60.93%   +47.02%     
============================================
  Files          817      832       +15     
  Lines       108323   109894     +1571     
============================================
+ Hits         15068    66962    +51894     
+ Misses       91332    35084    -56248     
- Partials      1923     7848     +5925     
Flag Coverage Δ
functional 13.91% <ø> (+<0.01%) ⬆️
unit 60.05% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

see 653 files with indirect coverage changes

@igor-sirotin igor-sirotin force-pushed the test/failing-get_balance_at_by_chain branch from e811c66 to 338df8d Compare December 9, 2024 11:46
@igor-sirotin igor-sirotin merged commit 4ccb08f into develop Dec 9, 2024
18 checks passed
@igor-sirotin igor-sirotin deleted the test/failing-get_balance_at_by_chain branch December 9, 2024 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test_: services approach
7 participants