Skip to content

Commit 2951c9a

Browse files
Ragger test
1 parent f9306f1 commit 2951c9a

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

tests/ragger/test_erc20.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
from constants import ABIS_FOLDER
1515
from test_sign import common as common_tx, BIP32_PATH
1616

17+
from client.token_info import TokenInfo, EthTUID
18+
19+
APPNAME = "Ethereum"
1720
TOKEN_ADDR = bytes.fromhex("A0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48")
1821
TOKEN_TICKER = "USDC"
1922
TOKEN_DECIMALS = 6
@@ -159,3 +162,64 @@ def test_approve_erc20_extra_data(scenario_navigator: NavigateWithScenario):
159162

160163
def test_approve_erc20_extra_data_nonascii(scenario_navigator: NavigateWithScenario):
161164
common_approve(scenario_navigator, 10, bytes.fromhex("deadcafe0042"))
165+
166+
def test_token_info_v2(scenario_navigator: NavigateWithScenario):
167+
app_client = EthAppClient(scenario_navigator.backend)
168+
amount = 5
169+
170+
with open(f"{ABIS_FOLDER}/erc20.json") as file:
171+
contract = Web3().eth.contract(
172+
abi=json.load(file),
173+
address=None
174+
)
175+
data = contract.encode_abi("approve", [
176+
bytes.fromhex("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045"),
177+
int(amount * pow(10, TOKEN_DECIMALS)),
178+
])
179+
180+
tx_params = {
181+
"chainId": TOKEN_CHAIN_ID,
182+
"nonce": 1337,
183+
"maxPriorityFeePerGas": Web3.to_wei(1.3, "gwei"),
184+
"maxFeePerGas": Web3.to_wei(2.62, "gwei"),
185+
"gas": 36007,
186+
"to": TOKEN_ADDR,
187+
"value": Web3.to_wei(0, "ether"),
188+
"data": data,
189+
}
190+
app_client.provide_token_info(TokenInfo(
191+
1,
192+
"Ethereum",
193+
TOKEN_TICKER,
194+
TOKEN_DECIMALS,
195+
tuid=EthTUID(TOKEN_CHAIN_ID, TOKEN_ADDR),
196+
))
197+
# use the same snapshots as the legacy test to make sure there are no visible differences
198+
common_tx(scenario_navigator, tx_params, "test_approve_erc20")
199+
200+
def test_token_info_v2_wrong_coin_type(scenario_navigator: NavigateWithScenario):
201+
app_client = EthAppClient(scenario_navigator.backend)
202+
203+
with pytest.raises(ExceptionRAPDU) as e:
204+
app_client.provide_token_info(TokenInfo(
205+
1,
206+
APPNAME,
207+
TOKEN_TICKER,
208+
TOKEN_DECIMALS,
209+
tuid=EthTUID(TOKEN_CHAIN_ID, TOKEN_ADDR),
210+
coin_type=501,
211+
))
212+
assert e.value.status == StatusWord.INVALID_DATA
213+
214+
def test_token_info_v2_unknown_chain_id(scenario_navigator: NavigateWithScenario):
215+
app_client = EthAppClient(scenario_navigator.backend)
216+
217+
with pytest.raises(ExceptionRAPDU) as e:
218+
app_client.provide_token_info(TokenInfo(
219+
1,
220+
APPNAME,
221+
TOKEN_TICKER,
222+
TOKEN_DECIMALS,
223+
tuid=EthTUID(2, TOKEN_ADDR),
224+
))
225+
assert e.value.status == StatusWord.INVALID_DATA

0 commit comments

Comments
 (0)