From 0b9db94d9956de3911787125da9ea4e048b4b71a Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Fri, 6 Sep 2024 15:57:36 +0200 Subject: [PATCH] Add Ragger test for missing token in EIP-712 amount-join --- .../00000.png | Bin 0 -> 472 bytes .../00001.png | Bin 0 -> 489 bytes .../00002.png | Bin 0 -> 343 bytes .../00003.png | Bin 0 -> 370 bytes .../00004.png | Bin 0 -> 364 bytes .../00005.png | Bin 0 -> 381 bytes .../00000.png | Bin 0 -> 472 bytes .../00001.png | Bin 0 -> 489 bytes .../00002.png | Bin 0 -> 367 bytes .../00003.png | Bin 0 -> 342 bytes .../00004.png | Bin 0 -> 364 bytes .../00005.png | Bin 0 -> 381 bytes tests/ragger/test_eip712.py | 111 ++++++++++++++++++ 13 files changed, 111 insertions(+) create mode 100644 tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-False-True/00000.png create mode 100644 tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-False-True/00001.png create mode 100644 tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-False-True/00002.png create mode 100644 tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-False-True/00003.png create mode 100644 tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-False-True/00004.png create mode 100644 tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-False-True/00005.png create mode 100644 tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-True-False/00000.png create mode 100644 tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-True-False/00001.png create mode 100644 tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-True-False/00002.png create mode 100644 tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-True-False/00003.png create mode 100644 tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-True-False/00004.png create mode 100644 tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-True-False/00005.png diff --git a/tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-False-True/00000.png b/tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-False-True/00000.png new file mode 100644 index 0000000000000000000000000000000000000000..b546f65af2e624cf54d7462335867daf18c90153 GIT binary patch literal 472 zcmV;}0Vn>6P)Nkl!1@zUYUn@802huw) z?fRqHv&kH0`to?FOand~0R4Elz%gFRzu3Y-*zSnjG9Fd{00000z+JzPLVxDA#@Ge` O00006_6ljWr=FfB?nBMN=%t+CxGP`@J=3H6GH})a)bUyv!7~Tr z#MjW~L-zFg5QK)3_H~a00000NkvXXu0mjf9sJ$$ literal 0 HcmV?d00001 diff --git a/tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-False-True/00002.png b/tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-False-True/00002.png new file mode 100644 index 0000000000000000000000000000000000000000..f27e25bb7787d9c881c2ab0c5f185c27b30b25f1 GIT binary patch literal 343 zcmeAS@N?(olHy`uVBq!ia0vp^4M6O`!2~2@x4h6`U|^KlARZl6mM{tzLgn>NTgvvGV^i{U;J_cyHM|{PPNs`*^~2NAWfP17G&2 zIao`+tMEPWEw+1(n>+(ULZsTRg)gIK-!J;UUw`YznzroE`m1h)oS5(b?aHgonaa$S zyE=S#M*EsP{&&fJbxh}HrcnJzZLPAOTir@(<#Lat>23;Y;fcfA!gObdDQJ-a36$OMZT^m~IWD$sy~fVw>G~jV``lCXlu0zNDo@rFSd4J{-YHcY(QO5;J{<~e9q=7F?O4)!WO}6UUdH! zS+Hz=(4})vCM2-VD4nt3W%LdvkyzeG%km#`1t_mu*zR}#jNB{EKZnW}g5-=Bym-_% z`=7%C>zxJL|9msNSMXnbQRayy^)nr>EU7olTHqoc^vG(B%bo(Id*|kR{84!`z2x6n zZ`;PkbrPvd6U}A>Y0chs_tyHmLi6kw6c{>JvYiQ=+MTFTx8d*9^V|R0+_75oZt9or zLetinU!`YMvFyLCb8XxElhO0{v2rTkNR$jMW7~4}*8a52+MC^J%KMbxPN-JRb2RNP zEsp0ebAPS3=e2G53#Z$XZAI6Yd=YU4`s1;0 z?{f>9Zfbf|_00eLCwPudd#p2Mzfg8-=Z~Y&(Z3(6-dSPln_e}2 z&8bJe=5=w3_V0Wxpw!uqXV@ zTyg#0l&4R7|Ayyoo}1J3WZRs6lez;p_x-s3`O4ERHjEo5Zk@S4@1z`Oka)v{pj(C~ z>TB;CrkB0D2@>;k^>bP0l+XkKqsFS~ literal 0 HcmV?d00001 diff --git a/tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-True-False/00000.png b/tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-True-False/00000.png new file mode 100644 index 0000000000000000000000000000000000000000..b546f65af2e624cf54d7462335867daf18c90153 GIT binary patch literal 472 zcmV;}0Vn>6P)Nkl!1@zUYUn@802huw) z?fRqHv&kH0`to?FOand~0R4Elz%gFRzu3Y-*zSnjG9Fd{00000z+JzPLVxDA#@Ge` O00006_6ljWr=FfB?nBMN=%t+CxGP`@J=3H6GH})a)bUyv!7~Tr z#MjW~L-zFg5QK)3_H~a00000NkvXXu0mjf9sJ$$ literal 0 HcmV?d00001 diff --git a/tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-True-False/00002.png b/tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-True-False/00002.png new file mode 100644 index 0000000000000000000000000000000000000000..864ee3753bc784505414c06e0e00bf5f6cf2297b GIT binary patch literal 367 zcmV-#0g(QQP)JBu;81vI}cuhd~9*dkt9{>R0w(RbPR;2~-Vm(|v#fcVM5$mUxIbMiCW|+UfOM^w9 zAqdFXFJae1&_?%+_kIk`AQSz|R60b&PCL)UKr z)+U1Pr=b7<0FX2O4e;PPw;PRPB`ih)#7KY`2@oRz_yf~W0002s7jN(-aDUC;)4%`# N002ovPDHLkV1g6lnXdo< literal 0 HcmV?d00001 diff --git a/tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-True-False/00003.png b/tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-True-False/00003.png new file mode 100644 index 0000000000000000000000000000000000000000..087939498cbfa25d44f33d8682df34f6b6451a2a GIT binary patch literal 342 zcmeAS@N?(olHy`uVBq!ia0vp^4M6O`!2~2@x4h6`U|^K>ba4!+nDh2#WL~p@07Jm` zSH3&`Pkg5Lx1%d&vx+8T^{nsz7}PhV?J=AJ)HVJ0i@S}_U0jOOXD!pSt;`nOc*Z3t zey{ZhsbafJz8&Z9$yPK*f5~6yZ*F`^JwftgjHSo?hBrXw&KJ*bv0YMM@F(tXv8z18 zgWRtx+syP=f4#YJ<*PSa*4#e-{q;9%_e&iW-_-wm319nJw7P3U{r;I&p3zI`v mEVp)?)*Q^K4-6V8nDb29*=XtVogZ{~K_Z^6elF{r5}E)-W}1Zn literal 0 HcmV?d00001 diff --git a/tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-True-False/00004.png b/tests/ragger/snapshots/nanosp/test_eip712_advanced_missing_token-True-False/00004.png new file mode 100644 index 0000000000000000000000000000000000000000..53ae65195fbea5b281a1bc1a80351dbf1cd79ff8 GIT binary patch literal 364 zcmeAS@N?(olHy`uVBq!ia0vp^4M6O`!2~2@x4h6`U|=-%ba4!+nDh2#AYZeBfa}G~ z%X2sUSKTFSd4J{-YHcY(QO5;J{<~e9q=7F?O4)!WO}6UUdH! zS+Hz=(4})vCM2-VD4nt3W%LdvkyzeG%km#`1t_mu*zR}#jNB{EKZnW}g5-=Bym-_% z`=7%C>zxJL|9msNSMXnbQRayy^)nr>EU7olTHqoc^vG(B%bo(Id*|kR{84!`z2x6n zZ`;PkbrPvd6U}A>Y0chs_tyHmLi6kw6c{>JvYiQ=+MTFTx8d*9^V|R0+_75oZt9or zLetinU!`YMvFyLCb8XxElhO0{v2rTkNR$jMW7~4}*8a52+MC^J%KMbxPN-JRb2RNP zEsp0ebAPS3=e2G53#Z$XZAI6Yd=YU4`s1;0 z?{f>9Zfbf|_00eLCwPudd#p2Mzfg8-=Z~Y&(Z3(6-dSPln_e}2 z&8bJe=5=w3_V0Wxpw!uqXV@ zTyg#0l&4R7|Ayyoo}1J3WZRs6lez;p_x-s3`O4ERHjEo5Zk@S4@1z`Oka)v{pj(C~ z>TB;CrkB0D2@>;k^>bP0l+XkKqsFS~ literal 0 HcmV?d00001 diff --git a/tests/ragger/test_eip712.py b/tests/ragger/test_eip712.py index 1f64fb159..f7e5256ba 100644 --- a/tests/ragger/test_eip712.py +++ b/tests/ragger/test_eip712.py @@ -437,3 +437,114 @@ def test_eip712_advanced_filtering(firmware: Firmware, # verify signature addr = recover_message(data_set.data, vrs) assert addr == get_wallet_addr(app_client) + + +TOKENS = [ + [ + { + "addr": "0x1111111111111111111111111111111111111111", + "ticker": "SRC", + "decimals": 18, + "chain_id": 1, + }, + {}, + ], + [ + {}, + { + "addr": "0x2222222222222222222222222222222222222222", + "ticker": "DST", + "decimals": 18, + "chain_id": 1, + }, + ] +] + + +@pytest.fixture(name="tokens", params=TOKENS) +def tokens_fixture(request) -> list[dict]: + return request.param + + +def test_eip712_advanced_missing_token(firmware: Firmware, + backend: BackendInterface, + navigator: Navigator, + default_screenshot_path: Path, + test_name: str, + tokens: list[dict], + golden_run: bool): + global SNAPS_CONFIG + + test_name += "-%s-%s" % (len(tokens[0]) == 0, len(tokens[1]) == 0) + SNAPS_CONFIG = SnapshotsConfig(test_name) + + app_client = EthAppClient(backend) + if firmware == Firmware.NANOS: + pytest.skip("Not supported on LNS") + + data = { + "types": { + "EIP712Domain": [ + {"name": "name", "type": "string"}, + {"name": "version", "type": "string"}, + {"name": "chainId", "type": "uint256"}, + {"name": "verifyingContract", "type": "address"}, + ], + "Root": [ + {"name": "token_from", "type": "address"}, + {"name": "value_from", "type": "uint256"}, + {"name": "token_to", "type": "address"}, + {"name": "value_to", "type": "uint256"}, + ] + }, + "primaryType": "Root", + "domain": { + "name": "test", + "version": "1", + "verifyingContract": "0x0000000000000000000000000000000000000000", + "chainId": 1, + }, + "message": { + "token_from": "0x1111111111111111111111111111111111111111", + "value_from": web3.Web3.to_wei(3.65, "ether"), + "token_to": "0x2222222222222222222222222222222222222222", + "value_to": web3.Web3.to_wei(15.47, "ether"), + } + } + + filters = { + "name": "Token not in CAL test", + "tokens": tokens, + "fields": { + "token_from": { + "type": "amount_join_token", + "token": 0, + }, + "value_from": { + "type": "amount_join_value", + "name": "From", + "token": 0, + }, + "token_to": { + "type": "amount_join_token", + "token": 1, + }, + "value_to": { + "type": "amount_join_value", + "name": "To", + "token": 1, + }, + } + } + vrs = eip712_new_common(firmware, + navigator, + default_screenshot_path, + app_client, + data, + filters, + False, + golden_run) + + # verify signature + addr = recover_message(data, vrs) + assert addr == get_wallet_addr(app_client)