Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tikka
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
Tikka
Commits
d8b175d5
Commit
d8b175d5
authored
2 years ago
by
Vincent Texier
Browse files
Options
Downloads
Patches
Plain Diff
[fix] fix transfer window opened even if unlock window canceled
parent
d000bc14
No related branches found
No related tags found
No related merge requests found
Pipeline
#18391
waiting for manual action
Stage: checks
Stage: release
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/slots/pyqt/widgets/test_account.py
+135
-4
135 additions, 4 deletions
tests/slots/pyqt/widgets/test_account.py
tikka/slots/pyqt/widgets/account.py
+5
-3
5 additions, 3 deletions
tikka/slots/pyqt/widgets/account.py
with
140 additions
and
7 deletions
tests/slots/pyqt/widgets/test_account.py
+
135
−
4
View file @
d8b175d5
...
...
@@ -14,21 +14,152 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
PyQt5.QtCore
import
QMutex
from
pytestqt.qtbot
import
QtBot
from
substrateinterface
import
Keypair
,
KeypairType
from
tikka.domains.application
import
Application
from
tikka.domains.entities.account
import
Account
from
tikka.slots.pyqt.entities.worker
import
AsyncQWorker
from
tikka.slots.pyqt.widgets.account
import
AccountWidget
from
tikka.slots.pyqt.windows.account_unlock
import
AccountUnlockWindow
from
tikka.slots.pyqt.windows.transfer
import
TransferWindow
def
test_account
(
qtbot
:
QtBot
,
application
:
Application
,
account
:
Account
,
monkeypatch
def
call_count
(
count
):
"""
Decorator to add the call_count attribute to a function
:param count: Set call_count value to count
:return:
"""
def
wrapper
(
function
):
function
.
call_count
=
count
return
function
return
wrapper
def
test_account_transfer_button_on_locked_account
(
qtbot
:
QtBot
,
application
:
Application
,
account
:
Account
,
wallet_mnemonic
:
str
,
wallet_password
:
str
,
monkeypatch
,
):
# pylint: disable=missing-function-docstring
application
.
accounts
.
add
(
account
)
monkeypatch
.
setattr
(
AsyncQWorker
,
"
start
"
,
lambda
*
args
:
None
)
# create wallet
keypair
=
Keypair
.
create_from_mnemonic
(
mnemonic
=
wallet_mnemonic
,
language_code
=
"
en
"
,
crypto_type
=
KeypairType
.
SR25519
,
ss58_format
=
application
.
currencies
.
get_current
().
ss58_format
,
)
wallet
=
application
.
wallets
.
create
(
keypair
,
wallet_password
)
application
.
wallets
.
add
(
wallet
)
widget
=
AccountWidget
(
application
,
account
,
QMutex
())
qtbot
.
addWidget
(
widget
)
assert
widget
.
addressLabel
.
text
()
==
account
.
address
# TEST ACCOUNT UNLOCK IS SUCCESSFUL
# if unlock window is opened, count call, unlock account and accept window
@call_count
(
0
)
def
unlock_window_success_exec_mock
(
dialog
):
assert
isinstance
(
dialog
,
AccountUnlockWindow
)
unlock_window_success_exec_mock
.
call_count
=
1
dialog
.
application
.
accounts
.
unlock
(
dialog
.
account
,
wallet_password
)
dialog
.
accept
()
monkeypatch
.
setattr
(
AccountUnlockWindow
,
"
exec_
"
,
unlock_window_success_exec_mock
)
# if transfer window is opened, count call, accept window
@call_count
(
0
)
def
transfer_window_exec_mock
(
dialog
):
assert
isinstance
(
dialog
,
TransferWindow
)
transfer_window_exec_mock
.
call_count
=
1
dialog
.
accept
()
monkeypatch
.
setattr
(
TransferWindow
,
"
exec_
"
,
transfer_window_exec_mock
)
widget
.
transferButton
.
click
()
# check if unlock window is called, then the transfer window if the account is unlocked
assert
unlock_window_success_exec_mock
.
call_count
==
1
assert
transfer_window_exec_mock
.
call_count
==
1
# reset account to locked status
application
.
accounts
.
lock
(
account
)
# TEST ACCOUNT UNLOCK IS CANCELED
transfer_window_exec_mock
.
call_count
=
0
# if unlock window is opened, count call, unlock account and accept window
@call_count
(
0
)
def
unlock_window_cancel_exec_mock
(
dialog
):
assert
isinstance
(
dialog
,
AccountUnlockWindow
)
unlock_window_cancel_exec_mock
.
call_count
=
1
dialog
.
reject
()
monkeypatch
.
setattr
(
AccountUnlockWindow
,
"
exec_
"
,
unlock_window_cancel_exec_mock
)
widget
.
transferButton
.
click
()
# check if unlock window is called, then the transfer window if the account is unlocked
assert
unlock_window_cancel_exec_mock
.
call_count
==
1
assert
transfer_window_exec_mock
.
call_count
==
0
def
test_account_transfer_button_on_unlocked_account
(
qtbot
:
QtBot
,
application
:
Application
,
account
:
Account
,
wallet_mnemonic
:
str
,
wallet_password
:
str
,
monkeypatch
,
):
# pylint: disable=missing-function-docstring
application
.
accounts
.
add
(
account
)
# create wallet
keypair
=
Keypair
.
create_from_mnemonic
(
mnemonic
=
wallet_mnemonic
,
language_code
=
"
en
"
,
crypto_type
=
KeypairType
.
SR25519
,
ss58_format
=
application
.
currencies
.
get_current
().
ss58_format
,
)
wallet
=
application
.
wallets
.
create
(
keypair
,
wallet_password
)
application
.
wallets
.
add
(
wallet
)
# unlock account
application
.
accounts
.
unlock
(
account
,
wallet_password
)
widget
=
AccountWidget
(
application
,
account
,
QMutex
())
qtbot
.
addWidget
(
widget
)
assert
widget
.
addressLabel
.
text
()
==
account
.
address
# if unlock window is opened, count call, unlock account and accept window
@call_count
(
0
)
def
unlock_window_exec_mock
(
dialog
):
assert
isinstance
(
dialog
,
AccountUnlockWindow
)
unlock_window_exec_mock
.
call_count
=
1
dialog
.
accept
()
monkeypatch
.
setattr
(
AccountUnlockWindow
,
"
exec_
"
,
unlock_window_exec_mock
)
# if transfer window is opened, count call, accept window
@call_count
(
0
)
def
transfer_window_exec_mock
(
dialog
):
assert
isinstance
(
dialog
,
TransferWindow
)
transfer_window_exec_mock
.
call_count
=
1
dialog
.
accept
()
monkeypatch
.
setattr
(
TransferWindow
,
"
exec_
"
,
transfer_window_exec_mock
)
widget
.
transferButton
.
click
()
# check if unlock window is called (no on unlocked account), then check the transfer window
assert
unlock_window_exec_mock
.
call_count
==
0
assert
transfer_window_exec_mock
.
call_count
==
1
This diff is collapsed.
Click to expand it.
tikka/slots/pyqt/widgets/account.py
+
5
−
3
View file @
d8b175d5
...
...
@@ -105,13 +105,15 @@ class AccountWidget(QWidget, Ui_AccountWidget):
:return:
"""
# account wallet is unlocked ?
# account wallet is
not
unlocked ?
if
not
self
.
application
.
wallets
.
is_unlocked
(
self
.
account
.
address
):
# open unlock account window
AccountUnlockWindow
(
self
.
application
,
self
.
account
,
self
.
parent
()).
exec_
()
parent
=
self
.
parent
()
TransferWindow
(
self
.
application
,
self
.
account
,
self
.
mutex
,
parent
).
exec_
()
if
self
.
application
.
wallets
.
is_unlocked
(
self
.
account
.
address
):
TransferWindow
(
self
.
application
,
self
.
account
,
self
.
mutex
,
self
.
parent
()
).
exec_
()
def
_on_transfer_sent
(
self
):
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment