Skip to content

Commit fc5367b

Browse files
Adapt ragger tests
1 parent 6820096 commit fc5367b

File tree

3 files changed

+84
-7
lines changed

3 files changed

+84
-7
lines changed

tests/ragger/test_blind_sign.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import client.response_parser as ResponseParser
1919
from client.utils import recover_transaction
2020
from client.tx_simu import TxSimu
21+
from client.gating import Gating
22+
from client.proxy_info import ProxyInfo
2123

2224

2325
BIP32_PATH = "m/44'/60'/0'/0/0"
@@ -70,7 +72,8 @@ def common_blind_sign(scenario_navigator: NavigateWithScenario,
7072
test_name: str,
7173
app_client: EthAppClient,
7274
tx_params: dict,
73-
reject: bool = False):
75+
reject: bool = False,
76+
nb_warnings: int = 1) -> None:
7477
try:
7578
with app_client.sign(BIP32_PATH, tx_params):
7679
if reject:
@@ -80,9 +83,9 @@ def common_blind_sign(scenario_navigator: NavigateWithScenario,
8083
test_name += "_nonzero"
8184

8285
if reject:
83-
scenario_navigator.review_reject_with_warning(test_name=test_name)
86+
scenario_navigator.review_reject_with_warning(test_name=test_name, nb_warnings=nb_warnings)
8487
else:
85-
scenario_navigator.review_approve_with_warning(test_name=test_name)
88+
scenario_navigator.review_approve_with_warning(test_name=test_name, nb_warnings=nb_warnings)
8689

8790
except ExceptionRAPDU as e:
8891
assert reject
@@ -101,7 +104,9 @@ def test_blind_sign(navigator: Navigator,
101104
test_name: str,
102105
reject: bool,
103106
amount: float,
104-
simu_params: Optional[TxSimu] = None):
107+
simu_params: Optional[TxSimu] = None,
108+
gating_params: Optional[Gating] = None,
109+
with_proxy: bool = False):
105110
if reject and amount > 0.0:
106111
pytest.skip()
107112

@@ -115,6 +120,30 @@ def test_blind_sign(navigator: Navigator,
115120

116121
tx_params = common_tx_params(amount)
117122

123+
if with_proxy:
124+
# Change address to a proxy contract
125+
tx_params["to"] = bytes.fromhex("CcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC")
126+
# Set proxy implementation address
127+
address = bytes.fromhex("6b175474e89094c44da98b954eedeac495271d0f")
128+
if gating_params is not None:
129+
# Override gating address to match proxy implementation
130+
gating_params.address = address
131+
proxy_info = ProxyInfo(
132+
ResponseParser.challenge(app_client.get_challenge().data),
133+
address,
134+
tx_params["chainId"],
135+
tx_params["to"],
136+
selector=None,
137+
)
138+
response = app_client.provide_proxy_info(proxy_info.serialize())
139+
assert response.status == StatusWord.OK
140+
141+
nb_warnings = 1
142+
if gating_params is not None:
143+
response = app_client.provide_gating(gating_params)
144+
assert response.status == StatusWord.OK
145+
nb_warnings += 1
146+
118147
if not reject and simu_params is not None:
119148
_, tx_hash = app_client.serialize_tx(tx_params)
120149
simu_params.tx_hash = tx_hash
@@ -127,7 +156,8 @@ def test_blind_sign(navigator: Navigator,
127156
test_name,
128157
app_client,
129158
tx_params,
130-
reject)
159+
reject,
160+
nb_warnings)
131161

132162

133163
# Token approval, would require providing the token metadata from the CAL

tests/ragger/test_gating.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from ragger.navigator.navigation_scenario import NavigateWithScenario
2+
3+
from test_blind_sign import test_blind_sign as blind_sign
4+
5+
from client.gating import Gating
6+
7+
8+
def test_gating_blind_signing(scenario_navigator: NavigateWithScenario) -> None:
9+
"""Test the Gating descriptor APDU with a blind signing transaction"""
10+
11+
descriptor = Gating(
12+
bytes.fromhex("6b175474e89094c44da98b954eedeac495271d0f"),
13+
1,
14+
"To scan for threats and verify this transaction before signing, use Ledger Multisig.",
15+
"ledger.com/ledger-multisig",
16+
)
17+
blind_sign(scenario_navigator.navigator,
18+
scenario_navigator,
19+
scenario_navigator.test_name,
20+
False,
21+
0.0,
22+
gating_params=descriptor)
23+
24+
def test_gating_blind_signing_with_proxy(scenario_navigator: NavigateWithScenario) -> None:
25+
"""Test the Gating descriptor APDU with a blind signing transaction"""
26+
27+
descriptor = Gating(
28+
bytes.fromhex("Dad77910DbDFdE764fC21FCD4E74D71bBACA6D8D"),
29+
1,
30+
"To scan for threats and verify this transaction before signing, use Ledger Multisig.",
31+
"ledger.com/ledger-multisig",
32+
)
33+
34+
blind_sign(scenario_navigator.navigator,
35+
scenario_navigator,
36+
scenario_navigator.test_name,
37+
False,
38+
0.0,
39+
gating_params=descriptor,
40+
with_proxy=True)

tests/ragger/test_nft.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from client.utils import get_selector_from_data, recover_transaction
1717
from client.tx_simu import TxSimu
1818
from client.dynamic_networks import DynamicNetwork
19+
from client.gating import Gating
1920

2021

2122
BIP32_PATH = "m/44'/60'/0'/0/0"
@@ -56,7 +57,8 @@ def common_test_nft(scenario_navigator: NavigateWithScenario,
5657
action: Action,
5758
reject: bool,
5859
plugin_name: str,
59-
simu_params: Optional[TxSimu] = None):
60+
simu_params: Optional[TxSimu] = None,
61+
gating_params: Optional[Gating] = None):
6062
global DEVICE_ADDR
6163
backend = scenario_navigator.backend
6264
app_client = EthAppClient(backend)
@@ -79,6 +81,11 @@ def common_test_nft(scenario_navigator: NavigateWithScenario,
7981
response = app_client.provide_tx_simulation(simu_params)
8082
assert response.status == StatusWord.OK
8183

84+
if gating_params is not None:
85+
gating_params.selector = get_selector_from_data(tx_params["data"])
86+
response = app_client.provide_gating(gating_params)
87+
assert response.status == StatusWord.OK
88+
8289
# Send Network information (name, ticker, icon)
8390
name, ticker, icon = get_network_config(backend.device.type, collec.chain_id)
8491
if name and ticker:
@@ -100,7 +107,7 @@ def common_test_nft(scenario_navigator: NavigateWithScenario,
100107
test_name += f"_{action.fn_name}_{str(collec.chain_id)}"
101108
if reject:
102109
scenario_navigator.review_reject(test_name=test_name)
103-
elif simu_params is not None:
110+
elif simu_params is not None or gating_params is not None:
104111
scenario_navigator.review_approve_with_warning(test_name=test_name)
105112
else:
106113
scenario_navigator.review_approve(test_name=test_name)

0 commit comments

Comments
 (0)