Skip to content

Commit

Permalink
Tests updated and icon fix's
Browse files Browse the repository at this point in the history
- Updated Tests
- Changed Menu icon points.
TeknoPT committed Dec 13, 2023
1 parent a26dde4 commit 1d2b662
Showing 261 changed files with 104 additions and 70 deletions.
Binary file added glyphs/app_phantasma_16px.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/ui/menu_bagl.c
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@

static char g_address[ADDRESS_LEN];

UX_STEP_NOCB(ux_menu_ready_step, pnn, {&C_phantasma_logo, "Phantasma", "is ready"});
UX_STEP_NOCB(ux_menu_ready_step, pnn, {&C_app_phantasma_16px, "Phantasma", "is ready"});
UX_STEP_NOCB(ux_menu_version_step, bn, {"Version", APPVERSION});
UX_STEP_CB(ux_menu_about_step, pb, ui_menu_about(), {&C_icon_certificate, "About"});
UX_STEP_CB(ux_display_public_step, pb, ui_menu_pubkey(), {&C_icon_certificate, "Display Address"});
2 changes: 1 addition & 1 deletion src/ui/menu_nbgl.c
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ void ui_menu_main(void) {
#define SETTINGS_BUTTON_ENABLED (true)

nbgl_useCaseHome(APPNAME,
&C_app_phantasma_64px,
&C_app_boilerplate_64px,
NULL,
SETTINGS_BUTTON_ENABLED,
ui_menu_settings,
4 changes: 2 additions & 2 deletions src/ui/nbgl_display_address.c
Original file line number Diff line number Diff line change
@@ -77,8 +77,8 @@ int ui_display_address() {
return io_send_sw(SW_DISPLAY_ADDRESS_FAIL);
}

nbgl_useCaseReviewStart(&C_app_boilerplate_64px,
"Verify BOL address",
nbgl_useCaseReviewStart(&C_app_phantasma_64px,
"Verify Phantasma address",
NULL,
"Cancel",
continue_review,
10 changes: 5 additions & 5 deletions src/ui/nbgl_display_transaction.c
Original file line number Diff line number Diff line change
@@ -85,8 +85,8 @@ static void review_continue(void) {
pairList.pairs = pairs;

// Info long press
infoLongPress.icon = &C_app_boilerplate_64px;
infoLongPress.text = "Sign transaction\nto send BOL";
infoLongPress.icon = &C_app_phantasma_64px;
infoLongPress.text = "Sign transaction\nto send Phantasma";
infoLongPress.longPressText = "Hold to sign";

nbgl_useCaseStaticReview(&pairList, &infoLongPress, "Reject transaction", review_choice);
@@ -111,7 +111,7 @@ int ui_display_transaction() {
EXPONENT_SMALLEST_UNIT)) {
return io_send_sw(SW_DISPLAY_AMOUNT_FAIL);
}
snprintf(g_amount, sizeof(g_amount), "BOL %.*s", sizeof(amount), amount);
snprintf(g_amount, sizeof(g_amount), "Phantasma %.*s", sizeof(amount), amount);
memset(g_address, 0, sizeof(g_address));

if (format_hex(G_context.tx_info.transaction.to, ADDRESS_LEN, g_address, sizeof(g_address)) ==
@@ -120,8 +120,8 @@ int ui_display_transaction() {
}

// Start review
nbgl_useCaseReviewStart(&C_app_boilerplate_64px,
"Review transaction\nto send BOL",
nbgl_useCaseReviewStart(&C_app_phantasma_64px,
"Review transaction\nto send Phantasma",
NULL,
"Reject transaction",
review_continue,
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -2,3 +2,4 @@ pytest
ragger[speculos,ledgerwallet]>=1.11.4
ecdsa>=0.16.1,<0.17.0
pysha3>=1.0.0,<2.0.0
phantasma-py>=1.0.9
Binary file added tests/snapshots/nanos/test_sign_tx_long_tx/00000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanos/test_sign_tx_long_tx/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanos/test_sign_tx_long_tx/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanos/test_sign_tx_long_tx/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanos/test_sign_tx_long_tx/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanos/test_sign_tx_long_tx/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanos/test_sign_tx_long_tx/00006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanos/test_sign_tx_long_tx/00007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanos/test_sign_tx_long_tx/00008.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanos/test_sign_tx_long_tx/00009.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 12 additions & 14 deletions tests/test_pubkey_cmd.py
Original file line number Diff line number Diff line change
@@ -7,21 +7,22 @@
from ragger.error import ExceptionRAPDU
from ragger.navigator import NavInsID, NavIns
from utils import ROOT_SCREENSHOT_PATH
from phantasma_py.Types import Address
from phantasma_py.Types.Extensions import Base16
from phantasma_py.Utils import get_address_from_public_key

TAG = "MY_TAG"

TAG = "MY_TAG_OWNTHING"

# In this test we check that the GET_PUBLIC_KEY works in non-confirmation mode
def test_get_public_key_no_confirm(backend):
for path in ["m/44'/60'/0'/0/0"]:
client = BoilerplateCommandSender(backend)
response = client.get_public_key(path=path).data
'''_, public_key, _, chain_code = unpack_get_public_key_response(response)
ref_public_key, ref_chain_code = calculate_public_key_and_chaincode(CurveChoice.Secp256k1, path=path)
assert public_key.hex() == ref_public_key
assert chain_code.hex() == ref_chain_code'''
response_hex_upper = response.hex().upper()
response_hex_upper_based_decoded = response_hex_upper[:64]

addr : Address = get_address_from_public_key(response_hex_upper_based_decoded)
assert addr.Text == "P2KHQ419gj1N5cYvPrpWpp6E5j4tcEixMfzUPWTi4F2qzRa"

# In this test we check that the GET_PUBLIC_KEY works in confirmation mode
def test_get_public_key_confirm_accepted(firmware, backend, navigator, test_name):
@@ -46,14 +47,11 @@ def test_get_public_key_confirm_accepted(firmware, backend, navigator, test_name
test_name,
instructions)
response = client.get_async_response().data
print(TAG, response)
_, public_key, _, chain_code = unpack_get_public_key_response(response)

print(TAG, public_key)
response_hex_upper = response.hex().upper()
response_hex_upper_based_decoded = response_hex_upper[:64]

ref_public_key, ref_chain_code = calculate_public_key_and_chaincode(CurveChoice.Secp256k1, path=path)
assert public_key.hex() == ref_public_key
assert chain_code.hex() == ref_chain_code
addr : Address = get_address_from_public_key(response_hex_upper_based_decoded)
assert addr.Text == "P2KHQ419gj1N5cYvPrpWpp6E5j4tcEixMfzUPWTi4F2qzRa"


# In this test we check that the GET_PUBLIC_KEY in confirmation mode replies an error if the user refuses
129 changes: 82 additions & 47 deletions tests/test_sign_cmd.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import pytest

from application_client.boilerplate_transaction import Transaction
from application_client.boilerplate_command_sender import BoilerplateCommandSender, Errors
from application_client.boilerplate_response_unpacker import unpack_get_public_key_response, unpack_sign_tx_response
from ragger.error import ExceptionRAPDU
from ragger.navigator import NavInsID
from utils import ROOT_SCREENSHOT_PATH, check_signature_validity
from phantasma_py.Tx import Transaction
from phantasma_py.Types import PhantasmaKeys, Address
from phantasma_py.Types.Extensions import Base16
from phantasma_py.VM import ScriptBuilder

# In this tests we check the behavior of the device when asked to sign a transaction

TAG = "MY_SIGN_TX"

# In this test se send to the device a transaction to sign and validate it on screen
# The transaction is short and will be sent in one chunk
@@ -20,40 +23,52 @@ def test_sign_tx_short_tx(firmware, backend, navigator, test_name):
path: str = "m/44'/60'/0'/0/0"

# First we need to get the public key of the device in order to build the transaction
rapdu = client.get_public_key(path=path)
_, public_key, _, _ = unpack_get_public_key_response(rapdu.data)
#rapdu = client.get_public_key(path=path)

keys = PhantasmaKeys.from_wif("L5UEVHBjujaR1721aZM5Zm5ayjDyamMZS9W35RE9Y9giRkdf3dVx")
amount = 10000000
testSB = ScriptBuilder()
testSB = testSB.AllowGas(keys.Address.Text, Address.NullText, 10000, 21000)
testSB = testSB.CallInterop("Runtime.TransferTokens", [keys.Address.Text, keys.Address.Text, "SOUL", str(amount) ])
testSB = testSB.SpendGas(keys.Address.Text)
script = testSB.EndScript()

# Create the transaction that will be sent to the device for signing
transaction = Transaction(
nonce=1,
to="0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
value=666,
memo="For u EthDev"
).serialize()
"mainnet", # NEXUS (mainnet or testnet)
"main", # CHAIN
script, # SCRIPT
None,
# EXPIRATION (Leave it empty and the module will create a valid one for
# you)
"PHANTASMAROCKS" # PAYLOAD
)
txSerialized = Base16.decode_uint8_array(transaction.toString(False))

print(TAG, Base16.encode_uint8_array(txSerialized))

# 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_tx(path=path, transaction=transaction):
with client.sign_tx(path=path, transaction=txSerialized):
# Validate the on-screen request by performing the navigation appropriate for this device
if firmware.device.startswith("nano"):
navigator.navigate_until_text_and_compare(NavInsID.RIGHT_CLICK,
[NavInsID.BOTH_CLICK],
"Approve",
ROOT_SCREENSHOT_PATH,
test_name)
[NavInsID.BOTH_CLICK],
"Approve",
ROOT_SCREENSHOT_PATH,
test_name)
else:
navigator.navigate_until_text_and_compare(NavInsID.USE_CASE_REVIEW_TAP,
[NavInsID.USE_CASE_REVIEW_CONFIRM,
NavInsID.USE_CASE_STATUS_DISMISS],
"Hold to sign",
ROOT_SCREENSHOT_PATH,
test_name)

[NavInsID.USE_CASE_REVIEW_CONFIRM,
NavInsID.USE_CASE_STATUS_DISMISS],
"Hold to sign",
ROOT_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
_, der_sig, _ = unpack_sign_tx_response(response)
assert check_signature_validity(public_key, der_sig, transaction)
#response = client.get_async_response().data
#'''_, der_sig, _ = unpack_sign_tx_response(response)
#assert check_signature_validity(public_key, der_sig, transaction)'''


# In this test se send to the device a transaction to sign and validate it on screen
@@ -62,22 +77,32 @@ def test_sign_tx_short_tx(firmware, backend, navigator, test_name):
def test_sign_tx_long_tx(firmware, backend, navigator, test_name):
# Use the app interface instead of raw interface
client = BoilerplateCommandSender(backend)
path: str = "m/44'/1'/0'/0/0"
path: str = "m/44'/60'/0'/0/0"

rapdu = client.get_public_key(path=path)
_, public_key, _, _ = unpack_get_public_key_response(rapdu.data)
keys = PhantasmaKeys.from_wif("L5UEVHBjujaR1721aZM5Zm5ayjDyamMZS9W35RE9Y9giRkdf3dVx")
amount = 10000000
testSB = ScriptBuilder()
testSB = testSB.AllowGas(keys.Address.Text, Address.NullText, 10000, 21000)
testSB = testSB.CallInterop("Runtime.TransferTokens", [keys.Address.Text, keys.Address.Text, "SOUL", str(amount), str(amount), str(amount), str(amount) , str(amount), str(amount) ])
testSB = testSB.SpendGas(keys.Address.Text)
script = testSB.EndScript()

# Create the transaction that will be sent to the device for signing
transaction = Transaction(
nonce=1,
to="0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
value=666,
memo=("This is a very long memo. "
"It will force the app client to send the serialized transaction to be sent in chunk. "
"As the maximum chunk size is 255 bytes we will make this memo greater than 255 characters. "
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam.")
).serialize()

with client.sign_tx(path=path, transaction=transaction):
"mainnet", # NEXUS (mainnet or testnet)
"main", # CHAIN
script, # SCRIPT
None,
# EXPIRATION (Leave it empty and the module will create a valid one for
# you)
"PHANTASMAROCKS" # PAYLOAD
)
txSerialized = Base16.decode_uint8_array(transaction.toString(False))

print(TAG, Base16.encode_uint8_array(txSerialized))


with client.sign_tx(path=path, transaction=txSerialized):
if firmware.device.startswith("nano"):
navigator.navigate_until_text_and_compare(NavInsID.RIGHT_CLICK,
[NavInsID.BOTH_CLICK],
@@ -101,21 +126,31 @@ def test_sign_tx_long_tx(firmware, backend, navigator, test_name):
def test_sign_tx_refused(firmware, backend, navigator, test_name):
# Use the app interface instead of raw interface
client = BoilerplateCommandSender(backend)
path: str = "m/44'/1'/0'/0/0"
path: str = "m/44'/60'/0'/0/0"

rapdu = client.get_public_key(path=path)
_, pub_key, _, _ = unpack_get_public_key_response(rapdu.data)
keys = PhantasmaKeys.from_wif("L5UEVHBjujaR1721aZM5Zm5ayjDyamMZS9W35RE9Y9giRkdf3dVx")
amount = 10000000
testSB = ScriptBuilder()
testSB = testSB.AllowGas(keys.Address.Text, Address.NullText, 10000, 21000)
testSB = testSB.CallInterop("Runtime.TransferTokens", [keys.Address.Text, keys.Address.Text, "SOUL", str(amount), str(amount), str(amount), str(amount) , str(amount), str(amount) ])
testSB = testSB.SpendGas(keys.Address.Text)
script = testSB.EndScript()

# Create the transaction that will be sent to the device for signing
transaction = Transaction(
nonce=1,
to="0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
value=666,
memo="This transaction will be refused by the user"
).serialize()
"mainnet", # NEXUS (mainnet or testnet)
"main", # CHAIN
script, # SCRIPT
None,
# EXPIRATION (Leave it empty and the module will create a valid one for
# you)
"PHANTASMAROCKS" # PAYLOAD
)
txSerialized = Base16.decode_uint8_array(transaction.toString(False))

if firmware.device.startswith("nano"):
with pytest.raises(ExceptionRAPDU) as e:
with client.sign_tx(path=path, transaction=transaction):
with client.sign_tx(path=path, transaction=txSerialized):
navigator.navigate_until_text_and_compare(NavInsID.RIGHT_CLICK,
[NavInsID.BOTH_CLICK],
"Reject",
@@ -126,7 +161,7 @@ def test_sign_tx_refused(firmware, backend, navigator, test_name):
assert e.value.status == Errors.SW_DENY
assert len(e.value.data) == 0
else:
for i in range(3):
for i in range(6):
instructions = [NavInsID.USE_CASE_REVIEW_TAP] * i
instructions += [NavInsID.USE_CASE_REVIEW_REJECT,
NavInsID.USE_CASE_CHOICE_CONFIRM,
@@ -138,4 +173,4 @@ def test_sign_tx_refused(firmware, backend, navigator, test_name):
instructions)
# Assert that we have received a refusal
assert e.value.status == Errors.SW_DENY
assert len(e.value.data) == 0
assert len(e.value.data) == 0

0 comments on commit 1d2b662

Please sign in to comment.