Skip to content

Commit

Permalink
Merge pull request #33 from blooo-io/test/LDG-517--nano-app-implement…
Browse files Browse the repository at this point in the history
…-transfertopublic-test

Test/LDG-517--nano-app-implement-transfertopublic-test
  • Loading branch information
n4l5u0r authored Dec 10, 2024
2 parents 837c7a8 + fdf660d commit e8bdebc
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/application_client/boilerplate_command_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from contextlib import contextmanager

from ragger.backend.interface import BackendInterface, RAPDU
from ragger.error import ExceptionRAPDU
from ragger.bip import pack_derivation_path
from utils import split_message

Expand All @@ -27,6 +28,10 @@ class P1(IntEnum):
P1_EXPORT_PRIVATE_KEY = 0x00
P1_EXPORT_WITH_ALTERNATIVE_DISPLAY = 0x01
P1_EXPORT_PRFKEY_AND_IDCREDSEC = 0x02
# Parameter 1 for transfer to public
P1_INITIAL_TRANSFER_TO_PUBLIC = 0x00
P1_REMAINING_AMOUNT_TRANSFER_TO_PUBLIC = 0x01
P1_PROOF_TRANSFER_TO_PUBLIC = 0x02
# Basic P1 for all instructions
P1_NONE = 0x00

Expand Down Expand Up @@ -294,6 +299,59 @@ def sign_configure_delegation(
) as response:
yield response

@contextmanager
def sign_transfer_to_public(
self, path: str, header_and_type: bytes, data: bytes, proof: bytes
) -> Generator[None, None, None]:
temp_data = pack_derivation_path(path)
temp_data += header_and_type
# send the header and type (no display)
temp_response = self.backend.exchange(
cla=CLA,
ins=InsType.TRANSFER_TO_PUBLIC,
p1=P1.P1_INITIAL_TRANSFER_TO_PUBLIC,
p2=P2.P2_NONE,
data=temp_data,
)

if temp_response.status != 0x9000:
raise ExceptionRAPDU(temp_response.status)
# send remaining amount [192] + transaction amount [8]
# + amount index [1] + proof size [1] (no display)
temp_response = self.backend.exchange(
cla=CLA,
ins=InsType.TRANSFER_TO_PUBLIC,
p1=P1.P1_REMAINING_AMOUNT_TRANSFER_TO_PUBLIC,
p2=P2.P2_NONE,
data=data,
)
print("km------------temp_response 2", temp_response)
if temp_response.status != 0x9000:
raise ExceptionRAPDU(temp_response.status)

# send proof in chunks
proof_chunks = split_message(proof, MAX_APDU_LEN)
last_chunk = proof_chunks.pop()
for chunk in proof_chunks:
temp_response = self.backend.exchange(
cla=CLA,
ins=InsType.TRANSFER_TO_PUBLIC,
p1=P1.P1_PROOF_TRANSFER_TO_PUBLIC,
p2=P2.P2_NONE,
data=chunk,
)
print("km------------temp_response 3", temp_response)
if temp_response.status != 0x9000:
raise ExceptionRAPDU(temp_response.status)
with self.backend.exchange_async(
cla=CLA,
ins=InsType.TRANSFER_TO_PUBLIC,
p1=P1.P1_PROOF_TRANSFER_TO_PUBLIC,
p2=P2.P2_NONE,
data=last_chunk,
) as response:
yield response

# @contextmanager
# def sign_tx(
# self, path: str, tx_type_ins: InsType, transaction: bytes
Expand Down
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.
46 changes: 46 additions & 0 deletions tests/test_transfer_to_public.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import pytest

from application_client.boilerplate_command_sender import (
BoilerplateCommandSender,
Errors,
)
from application_client.boilerplate_response_unpacker import (
unpack_get_public_key_response,
)
from ragger.bip import calculate_public_key_and_chaincode, CurveChoice
from ragger.error import ExceptionRAPDU
from ragger.navigator import NavInsID, NavIns
from ragger.firmware import Firmware
from utils import navigate_until_text_and_compare


@pytest.mark.active_test_scope
def test_transfer_to_public(
backend, firmware, navigator, test_name, default_screenshot_path
):
client = BoilerplateCommandSender(backend)
header_and_type = bytes.fromhex(
"20a845815bd43a1999e90fbf971537a70392eb38f89e6bd32b3dd70e1a9551d7000000000000000a0000000000000064000000290000000063de5da712"
)
remaining_amount = bytes.fromhex(
"97a9558421515a34f7c27c3b55c8dc561ed8c45a983387edf4f95ef834c5fd12d4fc5bb772490cb5653d249926bd9fc9938768d3921a4aa2361ae620e294637beb2d052cb0351745d81e2b34fee677c1e37cd8fedd1e4afbd66557d08f827db6803e57a7473ee78c7ba2db84c6910d355f497d257f89588a5e7176265b890841add54085462b35c3d0a01d562a29023db80fbac86061bf8970ceb5cf0889cc762e0cc6720ffac0b932c6168038aaec96e824c68cdb95e8cea823fa32792f43600000c0a0000f4240000c0a00000000010a9f"
)
proof = bytes.fromhex(
"a47cdf9133572e9ad5c02c3a7ffd1d05db7bb98860d918092454146153d62788f224c0157c65853ed4a0245ab3e0a593a3f85fa81cc4cb99eeaa643bfc793eab01fc695a8c51d4599cbe032a39832ad49bab900d88105b01d025b760b0d0d555b8c828f2d8fe29cc78c6307d979e6358b8bba9cf4d8200f272cc85b2a3813eff957aec4b2b7ed979ba2079d62246d135aefd61e7f46690c452fec8bcbb593481e229f6f1968194a09cf612490887e71d96730e2d852201e53fec9c89d36f8a90a124bfe9d3a0da01249bbbfa5d51cde2da81e4f905849b9e0706bdbb7eb0c0875e12a18902359e613b64633146166872000100842763340db76ac5c80a205bda5b5316ff71683d78b482f7854b83ad55b294ca76219fe1a3cc33079bee95d88fcacff90000000000000005a43287b922ec1f58e48e9f66c5d73b14193b35c19d06b1726f284514c25db2954566e4943cd3589e98c1a6685f20c99d96bc2ca5f2d1b1dd98e9ee8b73bc3a84dc31a94f44bb043406c59229a11b741da702a7621524e7bee85f7fcd9fa2a2b08174536be08461dd43bec45838de2e7e5bc06bc1794403844ccd22a283897d8fc9f19b82032b0b3009ca22a4f935871483bae012befeb6374ac4549e615c20b8378049385f129c7bcaa73f7dff53475ab3e5c45f75ada7ec14ef0fb73b43a04ba2b17ef2bdad6fa5ecfec277d85426afd328b112132d6777b7ab49ee74c990c349f57126196f9d92b8216a03494b5d10ca0e16ea6cd6206e538eef8bb2aad9e575e75243e586064de5c1584eba1fd72e0000000500000001307a73f17a6ee00535dce62f022ab2246eddacb9ab3904eb0b1cf2f8fe598ea750a26560b1f8f1355f632ef5ee97098c04d6d8e9de6d0e77078e5e09d6f6355426978499bb410a7c015d86b26f72a32be1b9a0c3f6c7f205be9fbf49b4c4fd7e0000000204eff935bdd56a489ef400e642873f8c9472a739ed4b92222076165b8ef4f1886af3dd283d7866baa42fc7bd1e326674944d7b524b6ef12ebd6099c42627b5bf70adecb3b92b9ee996a06419d45e06ae059fcef4545acf59e612e3782ca6c458000000033b60dbcdca743789710d4ba9ce59f295a836cc64ce97c8c378d6e1367d49467c53f8bc63f6dfffae872181ea483f226e2b45292df65be921425de20cf0cb9b96131695525b2af5c0bc4780fd5f958f95bd948e155e8a3a61a44e5367e4645d37000000046ab002aa8779122cd9b0b043e83288a30a9f29707bd2c781b7b33b73abc025ab041e9578cc2337264913f9bf3aca5849dc285a54de3b098efe7cd44bbb60956f5b8c5ddec6a6056db2f6e4ec5cb705686cbfeefc15468229a0d40a92ca67bf900000000573d0721be638df4be39e1dd7fe1c171b6c3a710313be643da7c1f41bc164678c40b818a3d9060519c54d83d8fb55f6b652101476d93e22b124fc3ad78ad3fee609eb93ee519337f0e60fdd01b95456fc2c9165564c9ef6e70e07ab43dc8f31676da6743b0b5b4edb34687e4b22598af0296cfdd178319a69fd13f6ee81e468820000000851cf206b3d5fd7eaa043893517e7759c8a1380879f11327bbc2c84bb543daf83629c2332df19a349985d4512475b99773e75e2bd9b0c88e07014ce5b3b30411d624cb52699853264f031bce7e940250bbde60419e457400047a14e3c37576be35fcf0b0cca05a4cff3a2b3c88051fa2cafc89fb707aa1ca86769961f67dcf3560df1b51d5fb909414a3265d39d135a8007a3d92604f106f7380dcf94db8ea94124701f9657e6527e0dbab7d8c0993b027f60280e797eef2c848dd7e99698dfa512e152352e81ff2140c978f532d41c3ba6cb298c0aaee78424c81a42c89c1dd84e4f4ec62e1344c63237d34e1dfd9a0473e74de11e3681c6f525076b9a4089336d6622b55ffa2636f7d0a8488e7f4f9b5fbacc7c67e0ffe7024d9fa05eaf924a658f1f1d23ef0c63fd882371345517277f3027d7c7925129dbcc0d86f63193082a55f26ef315a9727268eaf8d7f290c1b8126305ced248048ee015024f78f2712c30aed9988375247df8fe614b925dbed6b8265e420c12cceefbad6c4fcc46c437c43ca4a02f0009cab6f92d45844ccd615a7f8f5d9c3e8395ec8720c7aec226058d6625a16202d6687b98c4287b5893691cd96de6e32bdb9db7f33a0b6b61e86a7773bddc4f5a27e89a6d2710afb62f56df8e794442d3c150382410b76236441fc6a3be61a33808d509c5623d8ca959a7e6aabef772713a2bd22bad3639b0182baee029aeee7863320af187579fd7ee73042b690e515fdc801b0fc905a11ecf119738ca62ad42f12e71a7d4d0aa3ef9f1428efe3346f45ee5fcede357ff03cb64e8a03ee5b467ec62db77733492cd2aee90f724975b3c3397de5f6e00eaa91148442c814f923bf2a0d3560447be8c350723777cf4a29d95733e4dbc755c2d0b616bb13392f38c49a5e21b0570db22492dfac261d214cf72bea26154f75c5b4803000b39f0b179499e5bafb5a53f9a25099a791a7ff8fcdfe02f9c9b271eea7e4407722b9bb0a70f04e538c3407d05734b629517e6146fa0b38f0d46717ba7048d0501d62d16a443e23ba180e67c37e5a85f102a35e2ee8bf2921a3e321036cd064a7f9ce3080db6b9b9cdaa658cffab5d2114f4f17f6397f82e35b4b4da39c50463070201af9df19e915b222f80b02fc2db1adf3e3fd1d90b7254d0360252d9baf1ba134dc6a20eecc2679e57f4d41b6358dba244091337769ea6172177b1549710a30aa087b877d8c3d6fc2c6a01d0d8ac6632ccfef6bb01720d61283604854a4ad0efe7c8501223ee671ce6dea2262dc9fe93954f42b69b186f78754e1a3eb45bf04c42e24f323a2a222a5e66c9fce617d62b445cfcffce789c315332ac6708bb4e4b8d24bcaa7130fca5332ffd0353e34a9c06ee0d3bba5811e506842a8c6a1049f20163ec4caaaf1b74d5ee000263653064a2f6cb5a92106ebe746a626fbc2cd04b13f96e897a0d9fe923bd8702e077625191728b17d0fe1c32ee49beb370cd0bbc57796c5c7e59d221903d814950de86ae5bd4bbcb6bbb8afc472f974a25b6f55e71ba298b718855d605a69503d855e659d610cb161f52cbb84b14d7a2c73824d63c8b1f449ef98e9857fa1435e9fb1e733060dd7a36edd0c5ce605ba95e4598a100000004aa9ef709ad51fbc44978124e1f07e2bdd7d2ae4030c6bc35b7a137cebebf9e2c94261f7ffd3d29798eed266776a46559a1bed13fd8ccda57df3aa2cca53e2241914f2f1ae93c6e11f45e149a30dbf48ecb193c58b96c4d0e4ef54ab48578aaf180f3be8b6691c31c03756b4145e9172617eadedef24dd41c6fefa4284fe0bb093574578bcb6153e16e339dcd339c68d682526770ac78df0c355ae3d5cbf3d279fc48aba80ba85b5502832039e78f1da8a30e9facae8712da6a56c526454104c2987499629970c704c761a2e4ca1074e517f71eaffe0056d4fc597f54c133923ce57284f87af842903a8187be8c1c6d07a6b68d84f0c45ed4661a84767608946a63d2a208529a0964248670a9bead664f5c6389d7a33cfe5f6237c71cd158b7dd8f57b9a108644f0faf1f8d362591d683edc8b951d03e52749d8c62ab92175310f33ad98221cde75265e201f70a14bbf2b20bf8d36524eb6b6eccead65382ce63c500b367407f1a43dbd2092d59426ce927bc0a1c0db982cb5fa58af5a7e5c32725af354be28346778cfae8194bcd76e174d1f7763dd5887d772f2e80343bfab80de4eddcd0417fe86d47f8abc2ff57ab8a42e6fb6856173dd0d8750abbad9678"
)

with client.sign_transfer_to_public(
path="m/1105/0/0/0/0/2/0/0",
header_and_type=header_and_type,
data=remaining_amount,
proof=proof,
):
navigate_until_text_and_compare(
firmware, navigator, "Sign", default_screenshot_path, test_name
)
response = client.get_async_response()
print("km------------response", response)
assert response.status == 0x9000
assert response.data == bytes.fromhex(
"764a57e2bf0b875e3ed6ffa7073264c451651edfc31b7208ed3be15f48a5aafdd627fafb024c55d1e8b31db6e1199b341975f5f6f93506a189c270cb5e304b02"
)

0 comments on commit e8bdebc

Please sign in to comment.