forked from Concordium/concordium-ledger-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_configure_baker.py
365 lines (312 loc) · 14.9 KB
/
test_configure_baker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
import pytest
from application_client.boilerplate_command_sender import BoilerplateCommandSender
from utils import navigate_until_text_and_compare
from ragger.navigator import NavInsID
url = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
signVerifyKey = "7873cd57848d7aea7be03fbb3f1e8b9e69987fc73f13e473356776a16f26c96b"
signVerifyKeyProof = "a47cdf9133572e9ad5c02c3a7ffd1d05db7bb98860d918092454146153d62788f224c0157c65853ed4a0245ab3e0a593a3f85fa81cc4cb99eeaa643bfc793eab"
electionVerifyKey = "32f892fb3d0dc6138976b6848259cf730e37fa4a61a659c782ec6def978c0828"
electionVerifyKeyProof = "01fc695a8c51d4599cbe032a39832ad49bab900d88105b01d025b760b0d0d555b8c828f2d8fe29cc78c6307d979e6358b8bba9cf4d8200f272cc85b2a3813eff"
aggregationVerifyKey = "7873cd57848d7aea7be03fbb3f1e8b9e69987fc73f13e473356776a16f26c96b32f892fb3d0dc6138976b6848259cf730e37fa4a61a659c782ec6def978c082832f892fb3d0dc6138976b6848259cf730e37fa4a61a659c782ec6def978c0828"
aggregationVerifyKeyProof = "957aec4b2b7ed979ba2079d62246d135aefd61e7f46690c452fec8bcbb593481e229f6f1968194a09cf612490887e71d96730e2d852201e53fec9c89d36f8a90"
# In these tests we send to the device a transaction to sign and validate it on screen
# The transactions are short and will be sent in one chunk
# We will ensure that the displayed information is correct by using screenshots comparison
@pytest.mark.active_test_scope
def test_sign_configure_baker_capital_restake_open_status_and_keys(
backend, firmware, navigator, default_screenshot_path, test_name
):
# Use the app interface instead of raw interface
client = BoilerplateCommandSender(backend)
# Create the transaction that will be sent to the device for signing
transaction = "0000FFFFFFFFFFFF01027873cd57848d7aea7be03fbb3f1e8b9e69987fc73f13e473356776a16f26c96ba47cdf9133572e9ad5c02c3a7ffd1d05db7bb98860d918092454146153d62788f224c0157c65853ed4a0245ab3e0a593a3f85fa81cc4cb99eeaa643bfc793eab32f892fb3d0dc6138976b6848259cf730e37fa4a61a659c782ec6def978c082801fc695a8c51d4599cbe032a39832ad49bab900d88105b01d025b760b0d0d555b8c828f2d8fe29cc78c6307d979e6358b8bba9cf4d8200f272cc85b2a3813eff"
transaction = bytes.fromhex(transaction)
bitmap = "000f"
bitmap = bytes.fromhex(bitmap)
# Send the sign device instruction.
# As it requires on-screen validation, the function is asynchronous.
# It will yield the result when the navigation is done
with client.sign_configure_baker(
aggregation_key=bytes.fromhex(aggregationVerifyKey + aggregationVerifyKeyProof),
transaction=transaction,
bitmap=bitmap,
):
# Validate the on-screen request by performing the navigation appropriate for this device
navigate_until_text_and_compare(
firmware, navigator, "Sign", default_screenshot_path, test_name
)
# The device as yielded the result, parse it and ensure that the signature is correct
response = client.get_async_response().data
response_hex = response.hex()
print("response", response_hex)
assert (
response_hex
== "d9dbbab9e659c43409fe9cfcd9d18f3f0582656a1bffb420a875c6ef015a7c93d0d0fb34f2131db973647b60cafb745d0f4666d5e26e17b445c636e59a6a5208"
)
@pytest.mark.active_test_scope
def test_sign_configure_baker_stop_baking(
backend, firmware, navigator, default_screenshot_path, test_name
):
# Use the app interface instead of raw interface
client = BoilerplateCommandSender(backend)
# Create the transaction that will be sent to the device for signing
transaction = "0000000000000000"
transaction = bytes.fromhex(transaction)
bitmap = "0001"
bitmap = bytes.fromhex(bitmap)
# Send the sign device instruction.
# As it requires on-screen validation, the function is asynchronous.
# It will yield the result when the navigation is done
with client.sign_configure_baker(
transaction=transaction,
bitmap=bitmap,
):
# Validate the on-screen request by performing the navigation appropriate for this device
navigate_until_text_and_compare(
firmware, navigator, "Sign", default_screenshot_path, test_name
)
# The device as yielded the result, parse it and ensure that the signature is correct
response = client.get_async_response().data
response_hex = response.hex()
print("response", response_hex)
assert (
response_hex
== "3ca6549799f2f6ba3edcb66c1fc50330bdfe3b1f3df999178a040cf2ae4a68f88630808a4458b72e7aa4ace625e12c087530e976d1941acdaa8a719c4b034401"
)
@pytest.mark.active_test_scope
def test_sign_configure_baker_capital_restake_open_status_without_keys(
backend, firmware, navigator, default_screenshot_path, test_name
):
# Use the app interface instead of raw interface
client = BoilerplateCommandSender(backend)
# Create the transaction that will be sent to the device for signing
transaction = "0000FFFFFFFFFFFF0102"
transaction = bytes.fromhex(transaction)
bitmap = "0007"
bitmap = bytes.fromhex(bitmap)
# Send the sign device instruction.
# As it requires on-screen validation, the function is asynchronous.
# It will yield the result when the navigation is done
with client.sign_configure_baker(
transaction=transaction,
bitmap=bitmap,
):
# Validate the on-screen request by performing the navigation appropriate for this device
navigate_until_text_and_compare(
firmware, navigator, "Sign", default_screenshot_path, test_name
)
# The device as yielded the result, parse it and ensure that the signature is correct
response = client.get_async_response().data
response_hex = response.hex()
print("response", response_hex)
assert (
response_hex
== "dbcb60773c48e18ffa34c0702db87fbb5998a519cbb7302ff57025298a56a3e869cac88bcf571befa702123e1c0dd58ff75e0d67578e9ea8fec3737da9914009"
)
@pytest.mark.active_test_scope
def test_sign_configure_baker_only_keys(
backend, firmware, navigator, default_screenshot_path, test_name
):
# Use the app interface instead of raw interface
client = BoilerplateCommandSender(backend)
# Create the transaction that will be sent to the device for signing
transaction = (
signVerifyKey + signVerifyKeyProof + electionVerifyKey + electionVerifyKeyProof
)
transaction = bytes.fromhex(transaction)
bitmap = "0008"
bitmap = bytes.fromhex(bitmap)
# Send the sign device instruction.
# As it requires on-screen validation, the function is asynchronous.
# It will yield the result when the navigation is done
with client.sign_configure_baker(
aggregation_key=bytes.fromhex(aggregationVerifyKey + aggregationVerifyKeyProof),
transaction=transaction,
bitmap=bitmap,
):
# Validate the on-screen request by performing the navigation appropriate for this device
navigate_until_text_and_compare(
firmware, navigator, "Sign", default_screenshot_path, test_name
)
# The device as yielded the result, parse it and ensure that the signature is correct
response = client.get_async_response().data
response_hex = response.hex()
print("response", response_hex)
assert (
response_hex
== "9f38c0162cd68b61ba74f6b421b2d11970fa9c3de712d604387a340f289d17783d9832e9863ac916ad5a0c6cead51f0902e9d2fb7486d0f7988b148f56afb100"
)
@pytest.mark.active_test_scope
def test_sign_configure_baker_url_only(
backend, firmware, navigator, default_screenshot_path, test_name
):
# Use the app interface instead of raw interface
client = BoilerplateCommandSender(backend)
# Create the transaction that will be sent to the device for signing
url_bytes = url.encode("utf-8")
bitmap = "0010"
bitmap = bytes.fromhex(bitmap)
# Send the sign device instruction.
# As it requires on-screen validation, the function is asynchronous.
# It will yield the result when the navigation is done
with client.sign_configure_baker_url(
url=url_bytes,
bitmap=bitmap,
):
# Validate the on-screen request by performing the navigation appropriate for this device
navigate_until_text_and_compare(
firmware, navigator, "Sign", default_screenshot_path, test_name
)
# The device as yielded the result, parse it and ensure that the signature is correct
response = client.get_async_response().data
response_hex = response.hex()
print("response", response_hex)
assert (
response_hex
== "d9582b9f03d31562024145b37f536942dcd6111c553630a74ea5c38a379fd16289de8cbf7523731a1207c74362f09ea5804d601b1a472de109c576c431f75707"
)
@pytest.mark.active_test_scope
def test_sign_configure_baker_commission_rate_only(
backend, firmware, navigator, default_screenshot_path, test_name
):
# Use the app interface instead of raw interface
client = BoilerplateCommandSender(backend)
# Create the transaction that will be sent to the device for signing
url_bytes = url.encode("utf-8")
bitmap = "00E0"
bitmap = bytes.fromhex(bitmap)
# Send the sign device instruction.
# As it requires on-screen validation, the function is asynchronous.
# It will yield the result when the navigation is done
with client.sign_configure_baker_commission_rate(
bitmap=bitmap,
transaction_fee=True,
baking_reward=True,
finalization_reward=True,
):
# Validate the on-screen request by performing the navigation appropriate for this device
navigate_until_text_and_compare(
firmware, navigator, "Sign", default_screenshot_path, test_name
)
# The device as yielded the result, parse it and ensure that the signature is correct
response = client.get_async_response().data
response_hex = response.hex()
print("response", response_hex)
assert (
response_hex
== "2a6f49a786b62514d89bfc0e354689e1af2f3d3194b18b93433abd032e518fb72c55501fb5605402bf5a84b88f74d30a46ccb6a05907cb78144e93363b133205"
)
@pytest.mark.active_test_scope
def test_sign_configure_baker_suspended_only(
backend, firmware, navigator, default_screenshot_path, test_name
):
# Use the app interface instead of raw interface
client = BoilerplateCommandSender(backend)
bitmap = "0100"
bitmap = bytes.fromhex(bitmap)
# Send the sign device instruction.
# As it requires on-screen validation, the function is asynchronous.
# It will yield the result when the navigation is done
with client.sign_configure_baker_suspended(
bitmap=bitmap,
suspended=False,
is_called_first=True
):
# Validate the on-screen request by performing the navigation appropriate for this device
navigate_until_text_and_compare(
firmware, navigator, "Sign", default_screenshot_path, test_name
)
# The device as yielded the result, parse it and ensure that the signature is correct
response = client.get_async_response().data
response_hex = response.hex()
print("response", response_hex)
assert (
response_hex
== "ebc5ded8d20f43387615a40818e5890558008dd8c9a596cc4ecd007b3ec7923b918dc428b5a37a411c4f9c12a9df7c4d2d6edf3c0793159925720e7bb7078a08"
)
@pytest.mark.active_test_scope
def test_sign_configure_baker_all_parameters(
backend, firmware, navigator, default_screenshot_path, test_name
):
nano_continue_1_instructions = [
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK,
]
nano_continue_2_instructions = [
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.RIGHT_CLICK,
NavInsID.BOTH_CLICK,
]
client = BoilerplateCommandSender(backend)
# Create the transaction with all keys
transaction = "0000FFFFFFFFFFFF01027873cd57848d7aea7be03fbb3f1e8b9e69987fc73f13e473356776a16f26c96ba47cdf9133572e9ad5c02c3a7ffd1d05db7bb98860d918092454146153d62788f224c0157c65853ed4a0245ab3e0a593a3f85fa81cc4cb99eeaa643bfc793eab32f892fb3d0dc6138976b6848259cf730e37fa4a61a659c782ec6def978c082801fc695a8c51d4599cbe032a39832ad49bab900d88105b01d025b760b0d0d555b8c828f2d8fe29cc78c6307d979e6358b8bba9cf4d8200f272cc85b2a3813eff"
# URL from the existing test
url_bytes = url.encode("utf-8")
# Bitmap indicating all features are enabled (keys, url, and commission rates)
bitmap = "01FF"
with client.sign_configure_baker(
transaction=bytes.fromhex(transaction),
bitmap=bytes.fromhex(bitmap),
aggregation_key=bytes.fromhex(aggregationVerifyKey + aggregationVerifyKeyProof),
):
if firmware.is_nano:
navigator.navigate_and_compare(
default_screenshot_path,
test_name + "_1",
nano_continue_1_instructions,
screen_change_before_first_instruction=False,
screen_change_after_last_instruction=False,
)
else:
navigate_until_text_and_compare(
firmware, navigator, "Continue", default_screenshot_path, test_name + "_1", True, False, NavInsID.USE_CASE_CHOICE_CONFIRM
)
with client.sign_configure_baker_url(
url=url_bytes, bitmap=bitmap, is_called_first=False
):
if firmware.is_nano:
navigator.navigate_and_compare(
default_screenshot_path,
test_name + "_2",
nano_continue_2_instructions,
screen_change_before_first_instruction=False,
screen_change_after_last_instruction=False,
)
else:
navigate_until_text_and_compare(
firmware, navigator, "Continue", default_screenshot_path, test_name + "_2", True, False, NavInsID.USE_CASE_CHOICE_CONFIRM
)
with client.sign_configure_baker_commission_rate(
bitmap=bitmap,
transaction_fee=True,
baking_reward=True,
finalization_reward=True,
is_called_first=False,
):
navigate_until_text_and_compare(
firmware, navigator, "Continue", default_screenshot_path, test_name + "_3", True, False, NavInsID.USE_CASE_CHOICE_CONFIRM
)
with client.sign_configure_baker_suspended(
bitmap=bitmap,
suspended=True,
is_called_first=False,
):
navigate_until_text_and_compare(
firmware, navigator, "Sign", default_screenshot_path, test_name + "_4"
)
response = client.get_async_response().data
response_hex = response.hex()
print("response", response_hex)
assert (
response_hex
== "bba026c23bae21bf5deb23cab3f6ec57ccbe2fb504324dbfe28298ea9eb0a1874626db70d911c0922348616862a7eadac7b479dd181a706e31246ceab1a5f604"
)