From 7fbbfaa66580c9cb0d6fdee80ff4801f5ad66730 Mon Sep 17 00:00:00 2001 From: Martin Novak Date: Mon, 19 Sep 2022 14:29:56 +0200 Subject: [PATCH] tests(core): built-in Ethereum definitions --- ...d6d6c5fe4a677d343cc433536bb717bae167dd.dat | Bin 0 -> 568 bytes .../by_chain_id/11297108109/network.dat | Bin 0 -> 550 bytes .../by_chain_id/28945486/network.dat | Bin 0 -> 561 bytes .../by_chain_id/3125659152/network.dat | Bin 0 -> 551 bytes .../by_chain_id/4/network.dat | Bin 0 -> 549 bytes .../by_chain_id/61/network.dat | Bin 0 -> 557 bytes .../by_chain_id/888/network.dat | Bin 0 -> 553 bytes .../by_slip44/5718350/network.dat | Bin 0 -> 553 bytes .../by_slip44/6060/network.dat | Bin 0 -> 548 bytes .../by_slip44/61/network.dat | Bin 0 -> 557 bytes .../tests/fixtures/ethereum/getaddress.json | 6 ++++ common/tests/fixtures/ethereum/sign_tx.json | 6 ++-- .../fixtures/ethereum/sign_tx_eip155.json | 15 ++++++--- .../fixtures/ethereum/sign_tx_eip1559.json | 6 ++-- core/src/apps/ethereum/networks.py | 1 + python/src/trezorlib/cli/ethereum.py | 5 +-- python/src/trezorlib/ethereum.py | 21 +++++++----- .../device_tests/ethereum/test_getaddress.py | 13 ++++++-- tests/device_tests/ethereum/test_signtx.py | 31 +++++++++++++++++- 19 files changed, 81 insertions(+), 23 deletions(-) create mode 100644 common/tests/fixtures/ethereum/definitions-latest/by_chain_id/1/token_d0d6d6c5fe4a677d343cc433536bb717bae167dd.dat create mode 100644 common/tests/fixtures/ethereum/definitions-latest/by_chain_id/11297108109/network.dat create mode 100644 common/tests/fixtures/ethereum/definitions-latest/by_chain_id/28945486/network.dat create mode 100644 common/tests/fixtures/ethereum/definitions-latest/by_chain_id/3125659152/network.dat create mode 100644 common/tests/fixtures/ethereum/definitions-latest/by_chain_id/4/network.dat create mode 100644 common/tests/fixtures/ethereum/definitions-latest/by_chain_id/61/network.dat create mode 100644 common/tests/fixtures/ethereum/definitions-latest/by_chain_id/888/network.dat create mode 100644 common/tests/fixtures/ethereum/definitions-latest/by_slip44/5718350/network.dat create mode 100644 common/tests/fixtures/ethereum/definitions-latest/by_slip44/6060/network.dat create mode 100644 common/tests/fixtures/ethereum/definitions-latest/by_slip44/61/network.dat diff --git a/common/tests/fixtures/ethereum/definitions-latest/by_chain_id/1/token_d0d6d6c5fe4a677d343cc433536bb717bae167dd.dat b/common/tests/fixtures/ethereum/definitions-latest/by_chain_id/1/token_d0d6d6c5fe4a677d343cc433536bb717bae167dd.dat new file mode 100644 index 0000000000000000000000000000000000000000..ac81886fabc0a0b0e1a564bc344e1e2b62dbacc1 GIT binary patch literal 568 zcmV-80>}Mya(ZMj00001V<Jah`B@3PAnw}(wU!>NmgZ}14GS~@q%@2wn+>Rn7rO;mNSL@Yzngp}q)#?VlC*VipRqnwGA#ysC@hg-7qO z97uJ~t4m+r0LHK}I;at=B?CIc;IM zg1O6a@cb(-+2=(5__G);CozTHGa1=Iq43&JjIY;w%{X%XXu@+Ee9gmb3B3J31g`<# zhQcHSb&j^p%QFc(Hq4a*^s{TY(e$bG7=))SN0@?j^a(ZMj00000V<Z1&wNa zfNne>P8`wH?}I)XZ=P8zyE6f+R0Zu1H(G6!(lB>92rqosAKF27Y+5=i6Lk zvB8nm4bSYS`n)p^ zULk3milRHM*!W0w{$g5w!wo|Xx2%5-oGb|3qA0WOD~!150vJ_??ChXh&|DhJU4&&u zWtd7((LuyGzkVIxRo3!a8PyTjl48Ob-I|1+D>^eHcg$X2#rBXBQ(;?7nWl?Cw-F0C zjlNFXEE9Uf^e5O@uRb;3d{Ym_c79_&YE4>WV3-_NK7Q z-Kv;f+_xBjB&q3KN4X{XYb+0pEtgBm{Miw#~~k2|G5-l>+p$ oYq-($sq`3xr!7i8Z%Xl-V+?`}L+aHFwH?9_Pf-gv6yEQp2^%j1UjP6A literal 0 HcmV?d00001 diff --git a/common/tests/fixtures/ethereum/definitions-latest/by_chain_id/28945486/network.dat b/common/tests/fixtures/ethereum/definitions-latest/by_chain_id/28945486/network.dat new file mode 100644 index 0000000000000000000000000000000000000000..a14a9b04466372baf255bcce9d2677202453d73a GIT binary patch literal 561 zcmV-10?z$(a(ZMj00000V<4hAZ6Ho%ba!uZ zYbXE?_3pwjL!e0V{K@ih-@kBMj5B3o`G$4kwk>X}1`7x{C{9DSy}j~v5WlAIP$?1k zFT1n#v=_KBSxk@T-B<+qre)El==zE4IsGEzLNpr^B{8FJzq+jH9>4CS4#!)sV*88Z z3G$54Re|`ZE!>J22^=ZI%y098`rg~nh}Nt4Pd)&8vK<^LSvi$Ae6k2vx_?ynOIYj_ zS7cO6kr~$5+gxL@$iOz$S@{+};zuaOuBHT~#r@rVW4227t_RTLb~c*%Mv>W9m6V+l zPFW!h&+MoAyfY47A!(e7qC2hF_(*mBVp@K~4MPpLtbY!iEC}49D6{S>jJW9n7*&Vt z?4VoFTpG(=gk?r$m`YI5LBu$}ejVRc*78~z)e+Z{V!{~RnuMM!Ix{18%wAu`_K*`( zVOva@ri(zg5eqntzE0aL6MDq-C)il8J~iKbQxC;>>nPODuiz# z-@=vZiYch}rm)N1s+e8ew-|sVssOH!Mx_<)p+eg~5@A8J#C+39q`;>*ykZi+0-_)c zn$aEy{`j*PE+;XC-7^{4L80*4P>iqFd(Aj<{b<5-8hp*eYze&mKLoD<--f~@1a*$K z&C4?hJ2uRf0`#+MxY6{f^caMvElNIbO7WXx41x?p>eUOi9l{S!Q42T}-tVOeeL@fC literal 0 HcmV?d00001 diff --git a/common/tests/fixtures/ethereum/definitions-latest/by_chain_id/3125659152/network.dat b/common/tests/fixtures/ethereum/definitions-latest/by_chain_id/3125659152/network.dat new file mode 100644 index 0000000000000000000000000000000000000000..29185fc2fa26a9fe27586555842c93e212d210b1 GIT binary patch literal 551 zcmV+?0@(d@a(ZMj00000V<x2R01nJ@@L_@R zi|}0*8G8Z23&g+7?)~g`V>@Seqc8JY{J3-o{m?~oYipQ87QWp4IcX{>BNrn$|I%xj z6q5oi-IE;A)a5f$SO7-SYjwc7c}m-NJn+2v2u{^Q9L+`@;4T_QbK#6rAr~pguel|p z0JwjyAqqmv+0&XTbHI}7Db&nx2OB1434$aqO|D2=y%hJ19qF%tZ=H=1eFlDbvgg}e zW3kAiy4hwSX2ThLq@%Uy(J zMrD{vP|-oeIKO@!-&NM~S{c<5*OFqw7~PtLo+~;tBX`VRU&Z#26H{SZOqr&OK(`SK zIE}te+bk1$#PlcFSg$@c-+WUK#ddyUKjml^*ec@mF+%Jg9+)bGZz12pmFkKqsP?9? z%iXG&UEH@AfF!B_u8&5g744xy+dmRvL9@hs(@CVjr#QS~62AhXAPkz(9tZyTvluQX zF@@bT8QDRh@Y+y}uh)CcICA}H!gCsY&BJU7y!}4}uL0kN!XyNBj<(IqGYLC3%#{N4 pvun7~^r`e1gr_Y^K5t6#n_~=u3`6SG3$-1>4^L4GI27LRr3tup1SkLi literal 0 HcmV?d00001 diff --git a/common/tests/fixtures/ethereum/definitions-latest/by_chain_id/4/network.dat b/common/tests/fixtures/ethereum/definitions-latest/by_chain_id/4/network.dat new file mode 100644 index 0000000000000000000000000000000000000000..5f29959893f44b51790639defd687306515489b4 GIT binary patch literal 549 zcmV+=0^0p_a(ZMj00000V<La3%e%LFA4F4g<7+eO3B6w#yU# z)ky7x)}aC3miarlm~C*GdWkYAWh!hr+?*L#iaYiGzNTP&LWNbA%+y~Ck-XMcc;1yh zM+$Ec)$v7N>>nPODuiz#-@=vZiYch}rm)N1 zs+e8ew-|sVssOH!Mx_<)p+eg~5@A8J#C+39q`;>*ykZi+0-_)cn$aEy{`j*PE+;XC z-7^{4L80*4P>iqFd(Aj<{b<5-8hp*eYze&mKLoD<--f~@1a*$K&C4?hJ2uRf0`#+M nxY6{f^caMvElNIbO7WXx41x?p>eUOi9l{S!Q42T}-tVOey`2U> literal 0 HcmV?d00001 diff --git a/common/tests/fixtures/ethereum/definitions-latest/by_chain_id/61/network.dat b/common/tests/fixtures/ethereum/definitions-latest/by_chain_id/61/network.dat new file mode 100644 index 0000000000000000000000000000000000000000..18493d3049e719a97b3356d991324033710ad3cc GIT binary patch literal 557 zcmV+|0@D3-a(ZMj00000V<*H&gSrQrc0$TlfQCBrkF9ihljv8y&TBVU+g%yG*;3gV7h8O{2>%du3hl~we*6Q4Pu)hTgTqi4ydeqeW-PJA$o{z7|L7b-;{l>>nPODuiz#-@=vZ ziYch}rm)N1s+e8ew-|sVssOH!Mx_<)p+eg~5@A8J#C+39q`;>*ykZi+0-_)cn$aEy z{`j*PE+;XC-7^{4L80*4P>iqFd(Aj<{b<5-8hp*eYze&mKLoD<--f~@1a*$K&C4?h vJ2uRf0`#+MxY6{f^caMvElNIbO7WXx41x?p>eUOi9l{S!Q42T}-tVOemfj5& literal 0 HcmV?d00001 diff --git a/common/tests/fixtures/ethereum/definitions-latest/by_chain_id/888/network.dat b/common/tests/fixtures/ethereum/definitions-latest/by_chain_id/888/network.dat new file mode 100644 index 0000000000000000000000000000000000000000..86955f048eba20cd965f9780a1f128972da821ee GIT binary patch literal 553 zcmV+^0@nR>a(ZMj00000V<mI zGL!K1P8mk8TD-_rKg6ob6Vml9|HDY3{4#3Gtv^Sc;KCm-Xv7+Sw2ijN3;$D6mom!F zgQngb_oxE(JPl!E47&W05vyc2>>nPODuiz#-@=vZiYch} zrm)N1s+e8ew-|sVssOH!Mx_<)p+eg~5@A8J#C+39q`;>*ykZi+0-_)cn$aEy{`j*P zE+;XC-7^{4L80*4P>iqFd(Aj<{b<5-8hp*eYze&mKLoD<--f~@1a*$K&C4?hJ2uRf r0`#+MxY6{f^caMvElNIbO7WXx41x?p>eUOi9l{S!Q42T}-tVOe>4O4k literal 0 HcmV?d00001 diff --git a/common/tests/fixtures/ethereum/definitions-latest/by_slip44/5718350/network.dat b/common/tests/fixtures/ethereum/definitions-latest/by_slip44/5718350/network.dat new file mode 100644 index 0000000000000000000000000000000000000000..86955f048eba20cd965f9780a1f128972da821ee GIT binary patch literal 553 zcmV+^0@nR>a(ZMj00000V<mI zGL!K1P8mk8TD-_rKg6ob6Vml9|HDY3{4#3Gtv^Sc;KCm-Xv7+Sw2ijN3;$D6mom!F zgQngb_oxE(JPl!E47&W05vyc2>>nPODuiz#-@=vZiYch} zrm)N1s+e8ew-|sVssOH!Mx_<)p+eg~5@A8J#C+39q`;>*ykZi+0-_)cn$aEy{`j*P zE+;XC-7^{4L80*4P>iqFd(Aj<{b<5-8hp*eYze&mKLoD<--f~@1a*$K&C4?hJ2uRf r0`#+MxY6{f^caMvElNIbO7WXx41x?p>eUOi9l{S!Q42T}-tVOe>4O4k literal 0 HcmV?d00001 diff --git a/common/tests/fixtures/ethereum/definitions-latest/by_slip44/6060/network.dat b/common/tests/fixtures/ethereum/definitions-latest/by_slip44/6060/network.dat new file mode 100644 index 0000000000000000000000000000000000000000..6ee543543b572ca9b95371c777ff78a643dca8aa GIT binary patch literal 548 zcmV+<0^9v`a(ZMj00000V<-} z2XO*O*ne|Wu@|0fz(3f>vC4i)rR)pfCK@}27y)AIz+V2lO^@i{nx2PqlM=`7O6NC+ zj164Y>fCy;zXb|hCo7G5)YSXk)h-F1kFUu=oTnK5#(j!~7@>Ax?b%`B{j;kF{LAdb z%CuwzC8nHt=n?RTkcD$<9uF$|`qT4uKE0<()B?r5&%5&X#%EsqO8%+9y=-j!Mcf93 zxy>;K(H;l>__G);CozTH zGa1=Iq43&JjIY;w%{X%XXu@+Ee9gmb3B3J31g`<#hQcHSb&j^p%QFc(Hq4a*^s{TY m(e$bG7=))SN*H&gSrQrc0$TlfQCBrkF9ihljv8y&TBVU+g%yG*;3gV7h8O{2>%du3hl~we*6Q4Pu)hTgTqi4ydeqeW-PJA$o{z7|L7b-;{l>>nPODuiz#-@=vZ ziYch}rm)N1s+e8ew-|sVssOH!Mx_<)p+eg~5@A8J#C+39q`;>*ykZi+0-_)cn$aEy z{`j*PE+;XC-7^{4L80*4P>iqFd(Aj<{b<5-8hp*eYze&mKLoD<--f~@1a*$K&C4?h vJ2uRf0`#+MxY6{f^caMvElNIbO7WXx41x?p>eUOi9l{S!Q42T}-tVOemfj5& literal 0 HcmV?d00001 diff --git a/common/tests/fixtures/ethereum/getaddress.json b/common/tests/fixtures/ethereum/getaddress.json index 43b725ffca..8e76ef8c3a 100644 --- a/common/tests/fixtures/ethereum/getaddress.json +++ b/common/tests/fixtures/ethereum/getaddress.json @@ -39,6 +39,8 @@ { "name": "ETC", "parameters": { + "builtin_network": false, + "slip44": 61, "path": "m/44'/61'/0'/0/0" }, "result": { @@ -48,6 +50,8 @@ { "name": "GoChain", "parameters": { + "builtin_network": false, + "slip44": 6060, "path": "m/44'/6060'/0'/0/0" }, "result": { @@ -57,6 +61,8 @@ { "name": "Wanchain", "parameters": { + "builtin_network": false, + "slip44": 5718350, "path": "m/44'/5718350'/0'/0/0" }, "result": { diff --git a/common/tests/fixtures/ethereum/sign_tx.json b/common/tests/fixtures/ethereum/sign_tx.json index 1d3358a029..fc6334c2b3 100644 --- a/common/tests/fixtures/ethereum/sign_tx.json +++ b/common/tests/fixtures/ethereum/sign_tx.json @@ -16,7 +16,8 @@ "gas_price": "0x14", "gas_limit": "0x14", "tx_type": null, - "value": "0x0" + "value": "0x0", + "builtin_token": false }, "result": { "sig_v": 37, @@ -55,7 +56,8 @@ "gas_price": "0x14", "gas_limit": "0x14", "tx_type": 1, - "value": "0x64" + "value": "0x64", + "builtin_network": false }, "result": { "sig_v": 1811, diff --git a/common/tests/fixtures/ethereum/sign_tx_eip155.json b/common/tests/fixtures/ethereum/sign_tx_eip155.json index b31965bae1..747803f84e 100644 --- a/common/tests/fixtures/ethereum/sign_tx_eip155.json +++ b/common/tests/fixtures/ethereum/sign_tx_eip155.json @@ -53,7 +53,8 @@ "value": "0x2540be400", "to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98", "tx_type": null, - "data": "" + "data": "", + "builtin_network": false }, "result": { "sig_v": 43, @@ -72,7 +73,8 @@ "value": "0x2540be400", "to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98", "tx_type": null, - "data": "" + "data": "", + "builtin_network": false }, "result": { "sig_v": 158, @@ -91,7 +93,8 @@ "value": "0x2540be400", "to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98", "tx_type": null, - "data": "" + "data": "", + "builtin_network": false }, "result": { "sig_v": 57891008, @@ -110,7 +113,8 @@ "value": "0x2540be400", "to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98", "tx_type": null, - "data": "" + "data": "", + "builtin_network": false }, "result": { "sig_v": 6251318340, @@ -167,7 +171,8 @@ "value": "0x2540be400", "to_address": "0x8eA7a3fccC211ED48b763b4164884DDbcF3b0A98", "tx_type": null, - "data": "" + "data": "", + "builtin_network": false }, "result": { "sig_v": 22594216254, diff --git a/common/tests/fixtures/ethereum/sign_tx_eip1559.json b/common/tests/fixtures/ethereum/sign_tx_eip1559.json index 239c6b07cd..6cf4188dbe 100644 --- a/common/tests/fixtures/ethereum/sign_tx_eip1559.json +++ b/common/tests/fixtures/ethereum/sign_tx_eip1559.json @@ -73,7 +73,8 @@ "gas_limit": "0x14", "max_gas_fee": "0x14", "max_priority_fee": "0x1", - "value": "0x0" + "value": "0x0", + "builtin_token": false }, "result": { "sig_v": 1, @@ -113,7 +114,8 @@ "gas_limit": "0x14", "max_gas_fee": "0x14", "max_priority_fee": "0x1", - "value": "0xa" + "value": "0xa", + "builtin_network": false }, "result": { "sig_v": 0, diff --git a/core/src/apps/ethereum/networks.py b/core/src/apps/ethereum/networks.py index 128f755958..6dce0b2cee 100644 --- a/core/src/apps/ethereum/networks.py +++ b/core/src/apps/ethereum/networks.py @@ -23,6 +23,7 @@ if TYPE_CHECKING: bool # rskip60 ] # fmt: on + UNKNOWN_NETWORK_SHORTCUT = "UNKN" diff --git a/python/src/trezorlib/cli/ethereum.py b/python/src/trezorlib/cli/ethereum.py index 40d6aabc41..1cfc9f3dec 100644 --- a/python/src/trezorlib/cli/ethereum.py +++ b/python/src/trezorlib/cli/ethereum.py @@ -37,6 +37,7 @@ from typing import ( import click from .. import ethereum, tools +from ..tools import UH_ from . import with_client if TYPE_CHECKING: @@ -194,7 +195,7 @@ def _get_ethereum_definitions( if definitions_dir is not None: if chain_id is not None or slip44_hardened is not None: defs.encoded_network = ethereum.network_definition_from_dir( - definitions_dir, chain_id, slip44_hardened + definitions_dir, chain_id, UH_(slip44_hardened) # type: ignore [Argument of type "int | None" cannot be assigned to parameter "x" of type "int" in function "UH_"] ) if chain_id is not None and token_address is not None: defs.encoded_token = ethereum.token_definition_from_dir( @@ -210,7 +211,7 @@ def _get_ethereum_definitions( elif download_definitions: if chain_id is not None or slip44_hardened is not None: defs.encoded_network = ethereum.download_network_definition( - chain_id, slip44_hardened + chain_id, UH_(slip44_hardened) # type: ignore [Argument of type "int | None" cannot be assigned to parameter "x" of type "int" in function "UH_"] ) if chain_id is not None and token_address is not None: defs.encoded_token = ethereum.download_token_definition( diff --git a/python/src/trezorlib/ethereum.py b/python/src/trezorlib/ethereum.py index fe804d7214..bf13aacbfb 100644 --- a/python/src/trezorlib/ethereum.py +++ b/python/src/trezorlib/ethereum.py @@ -21,7 +21,7 @@ from typing import TYPE_CHECKING, Any, AnyStr, Dict, List, Optional, Tuple import requests from . import exceptions, messages -from .tools import UH_, expect, prepare_message_bytes, session +from .tools import expect, prepare_message_bytes, session if TYPE_CHECKING: from .client import TrezorClient @@ -162,11 +162,11 @@ def download_from_url(url: str, error_msg: str = "") -> bytes: def download_network_definition( - chain_id: Optional[int] = None, slip44_hardened: Optional[int] = None + chain_id: Optional[int] = None, slip44: Optional[int] = None ) -> Optional[bytes]: - if not ((chain_id is None) != (slip44_hardened is None)): # not XOR + if not ((chain_id is None) != (slip44 is None)): # not XOR raise RuntimeError( - "Exactly one of chain_id or slip44_hardened parameters are needed to load network definition from directory." + "Exactly one of chain_id or slip44 parameters are needed to load network definition from directory." ) if chain_id is not None: @@ -178,7 +178,7 @@ def download_network_definition( else: url = DEFS_BASE_URL.format( lookup_type=DEFS_NETWORK_BY_SLIP44_LOOKUP_TYPE, - id=UH_(slip44_hardened), # type: ignore [Argument of type "int | None" cannot be assigned to parameter "x" of type "int" in function "UH_"] + id=slip44, name=DEFS_NETWORK_URI_NAME, ) @@ -207,11 +207,11 @@ def download_token_definition( def network_definition_from_dir( path: pathlib.Path, chain_id: Optional[int] = None, - slip44_hardened: Optional[int] = None, + slip44: Optional[int] = None, ) -> Optional[bytes]: - if not ((chain_id is None) != (slip44_hardened is None)): # not XOR + if not ((chain_id is None) != (slip44 is None)): # not XOR raise RuntimeError( - "Exactly one of chain_id or slip44_hardened parameters are needed to load network definition from directory." + "Exactly one of chain_id or slip44 parameters are needed to load network definition from directory." ) def read_definition(path: pathlib.Path) -> Optional[bytes]: @@ -232,7 +232,7 @@ def network_definition_from_dir( return read_definition( path / DEFS_NETWORK_BY_SLIP44_LOOKUP_TYPE - / str(UH_(slip44_hardened)) # type: ignore [Argument of type "int | None" cannot be assigned to parameter "x" of type "int" in function "UH_"] + / str(slip44) / (DEFS_NETWORK_URI_NAME + ".dat") ) @@ -247,6 +247,9 @@ def token_definition_from_dir( "Both chain_id and token_address parameters are needed to load token definition from directory." ) + if token_address is not None and token_address.startswith("0x"): + token_address = token_address[2:] + path = ( path / DEFS_NETWORK_BY_CHAINID_LOOKUP_TYPE diff --git a/tests/device_tests/ethereum/test_getaddress.py b/tests/device_tests/ethereum/test_getaddress.py index b9cd6d8c65..d31813cc6b 100644 --- a/tests/device_tests/ethereum/test_getaddress.py +++ b/tests/device_tests/ethereum/test_getaddress.py @@ -20,12 +20,21 @@ from trezorlib import ethereum from trezorlib.debuglink import TrezorClientDebugLink as Client from trezorlib.tools import parse_path -from ...common import parametrize_using_common_fixtures +from ...common import COMMON_FIXTURES_DIR, parametrize_using_common_fixtures pytestmark = [pytest.mark.altcoin, pytest.mark.ethereum] @parametrize_using_common_fixtures("ethereum/getaddress.json") def test_getaddress(client: Client, parameters, result): + encoded_network = None + if not parameters.get("builtin_network", True): + encoded_network = ethereum.network_definition_from_dir( + path=COMMON_FIXTURES_DIR / "ethereum" / "definitions-latest", + slip44=parameters["slip44"], + ) address_n = parse_path(parameters["path"]) - assert ethereum.get_address(client, address_n) == result["address"] + assert ( + ethereum.get_address(client, address_n, encoded_network=encoded_network) + == result["address"] + ) diff --git a/tests/device_tests/ethereum/test_signtx.py b/tests/device_tests/ethereum/test_signtx.py index 6ab96677c6..f49fb50ac3 100644 --- a/tests/device_tests/ethereum/test_signtx.py +++ b/tests/device_tests/ethereum/test_signtx.py @@ -14,6 +14,8 @@ # You should have received a copy of the License along with this library. # If not, see . +from typing import Optional + import pytest from trezorlib import ethereum, exceptions, messages @@ -21,7 +23,7 @@ from trezorlib.debuglink import TrezorClientDebugLink as Client, message_filters from trezorlib.exceptions import TrezorFailure from trezorlib.tools import parse_path -from ...common import parametrize_using_common_fixtures +from ...common import COMMON_FIXTURES_DIR, parametrize_using_common_fixtures TO_ADDR = "0x1d1c328764a41bda0492b66baa30c4a339ff85ef" SHOW_ALL = (143, 167) @@ -30,6 +32,31 @@ GO_BACK = (16, 220) pytestmark = [pytest.mark.altcoin, pytest.mark.ethereum] +def get_EthereumEncodedDefinitions( + parameters: dict, +) -> Optional[messages.EthereumEncodedDefinitions]: + encoded_network = None + encoded_token = None + if not parameters.get("builtin_network", True): + encoded_network = ethereum.network_definition_from_dir( + path=COMMON_FIXTURES_DIR / "ethereum" / "definitions-latest", + chain_id=parameters["chain_id"], + ) + if not parameters.get("builtin_token", True): + encoded_token = ethereum.token_definition_from_dir( + path=COMMON_FIXTURES_DIR / "ethereum" / "definitions-latest", + chain_id=parameters["chain_id"], + token_address=parameters["to_address"], + ) + + if encoded_network is not None or encoded_token is not None: + return messages.EthereumEncodedDefinitions( + encoded_network=encoded_network, encoded_token=encoded_token + ) + + return None + + @parametrize_using_common_fixtures( "ethereum/sign_tx.json", "ethereum/sign_tx_eip155.json", @@ -47,6 +74,7 @@ def test_signtx(client: Client, parameters, result): value=int(parameters["value"], 16), tx_type=parameters["tx_type"], data=bytes.fromhex(parameters["data"]), + definitions=get_EthereumEncodedDefinitions(parameters), ) expected_v = 2 * parameters["chain_id"] + 35 @@ -70,6 +98,7 @@ def test_signtx_eip1559(client: Client, parameters, result): chain_id=parameters["chain_id"], value=int(parameters["value"], 16), data=bytes.fromhex(parameters["data"]), + definitions=get_EthereumEncodedDefinitions(parameters), ) assert sig_r.hex() == result["sig_r"]