Skip to content

Commit

Permalink
Merge pull request #536 from LedgerHQ/feat/apa/explicit_unknown_ticker
Browse files Browse the repository at this point in the history
Explicit unknown ticker
  • Loading branch information
apaillier-ledger authored Feb 13, 2024
2 parents 8a1ce2f + 9ea5d42 commit adbe34c
Show file tree
Hide file tree
Showing 53 changed files with 15 additions and 109 deletions.
4 changes: 4 additions & 0 deletions src/handle_get_printable_amount.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ void handle_get_printable_amount(get_printable_amount_parameters_t* params,
}
// If the amount is a fee, the ticker should be the chain's native currency
if (params->is_fee) {
// fallback mechanism in the absence of chain ID in swap config
if (chain_id == 0) {
chain_id = config->chainId;
}
strlcpy(ticker, get_displayable_ticker(&chain_id, config), sizeof(ticker));
decimals = WEI_TO_ETHER;
}
Expand Down
4 changes: 4 additions & 0 deletions src/handle_swap_sign_transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ bool copy_transaction_parameters(create_transaction_parameters_t* sign_transacti
return false;
}

// fallback mechanism in the absence of chain ID in swap config
if (chain_id == 0) {
chain_id = config->chainId;
}
// If the amount is a fee, its value is nominated in ETH even if we're doing an ERC20 swap
strlcpy(ticker, get_displayable_ticker(&chain_id, config), sizeof(ticker));
decimals = WEI_TO_ETHER;
Expand Down
8 changes: 7 additions & 1 deletion src/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ typedef struct network_info_s {
uint64_t chain_id;
} network_info_t;

static const char *unknown_ticker = "???";

// Mappping of chain ids to networks.
static const network_info_t NETWORK_MAPPING[] = {
{.chain_id = 1, .name = "Ethereum", .ticker = "ETH"},
Expand Down Expand Up @@ -140,7 +142,11 @@ const char *get_displayable_ticker(const uint64_t *chain_id, const chain_config_
const char *ticker = get_network_ticker_from_chain_id(chain_id);

if (ticker == NULL) {
ticker = chain_cfg->coinName;
if (*chain_id == chain_cfg->chainId) {
ticker = chain_cfg->coinName;
} else {
ticker = unknown_ticker;
}
}
return ticker;
}
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.
Binary file modified tests/ragger/snapshots/nanox/domain_name_unknown_chain/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/ragger/snapshots/nanox/domain_name_unknown_chain/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/ragger/snapshots/stax/domain_name_unknown_chain/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
84 changes: 0 additions & 84 deletions tests/speculos/test_sign_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,90 +83,6 @@ def test_sign_simple(cmd):
assert v == 0x26 # 38
assert r.hex() == "6f389d15320f0501383526ed03de917c14212716f09a262dbc98431086a5db49"
assert s.hex() == "0dc994b7b97230bb35fdf6fec2f4d8ff4cfb8bfeb2a652c364c738ff033c05dd"


def test_sign_dai_coin_type_on_network_5234(cmd):
result: list = []

# DAI coin type
bip32_path="44'/700'/1'/0/0"

transaction = Transaction(
txType=0xEB,
nonce=0,
gasPrice=0x0306dc4200,
gasLimit=0x5208,
to="0x5a321744667052affa8386ed49e00ef223cbffc3",
value=0x6f9c9e7bf61818,
chainID=5243,
)

with cmd.simple_sign_tx(bip32_path=bip32_path, transaction=transaction, result=result) as ex:
sleep(0.5)

if cmd.model == "nanos":
# Review transaction
compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/dai_coin_type_on_network_5234/00000.png")
cmd.client.press_and_release('right')

# Amount 1/3, 2/3, 3/3
compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/dai_coin_type_on_network_5234/00001.png")
cmd.client.press_and_release('right')
compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/dai_coin_type_on_network_5234/00002.png")
cmd.client.press_and_release('right')
compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/dai_coin_type_on_network_5234/00003.png")
cmd.client.press_and_release('right')

# Address 1/3, 2/3, 3/3
compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/dai_coin_type_on_network_5234/00004.png")
cmd.client.press_and_release('right')
compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/dai_coin_type_on_network_5234/00005.png")
cmd.client.press_and_release('right')
compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/dai_coin_type_on_network_5234/00006.png")
cmd.client.press_and_release('right')

# Network 5243
compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/dai_coin_type_on_network_5234/00007.png")
cmd.client.press_and_release('right')

# Max Fees
compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/dai_coin_type_on_network_5234/00008.png")
cmd.client.press_and_release('right')

# Accept and send
compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/dai_coin_type_on_network_5234/00009.png")
cmd.client.press_and_release('both')

if cmd.model == "nanox" or cmd.model == "nanosp":
# Review transaction
compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/dai_coin_type_on_network_5234/00000.png")
cmd.client.press_and_release('right')

# Amount
compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/dai_coin_type_on_network_5234/00001.png")
cmd.client.press_and_release('right')

# Address
compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/dai_coin_type_on_network_5234/00002.png")
cmd.client.press_and_release('right')

# Network 5243
compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/dai_coin_type_on_network_5234/00003.png")
cmd.client.press_and_release('right')

# Max Fees
compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/dai_coin_type_on_network_5234/00004.png")
cmd.client.press_and_release('right')

# Accept and send
compare_screenshot(cmd, f"screenshots/sign/{PATH_IMG[cmd.model]}/dai_coin_type_on_network_5234/00005.png")
cmd.client.press_and_release('both')

v, r, s = result

assert v == 0x1A # 26
assert r.hex() == "7ebfa5d5cac1e16bb1f1a8c67706b5c6019c0f198df6bb44e742a9de72330961"
assert s.hex() == "537419d8d1443d38ea87943c110789decb43b8f4fea8fae256fe842f669da634"


def test_sign_reject(cmd):
Expand Down
Binary file modified tests/zemu/snapshots/nanos_starkware_usdt_deposit/00012.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

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.

This file was deleted.

Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.

This file was deleted.

Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.

This file was deleted.

Diff not rendered.
22 changes: 0 additions & 22 deletions tests/zemu/src/send.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,3 @@ nano_models.forEach(function(model) {
await expect(tx).rejects.toEqual(new TransportStatusError(0x6807));
}));
});

nano_models.forEach(function(model) {
test('[Nano ' + model.letter + '] Transfer Ether on network 5234 on Ethereum app', zemu(model, async (sim, eth) => {

const tx = eth.signTransaction(
"44'/60'/1'/0/0",
'ED44850306DC4200825208945A321744667052AFFA8386ED49E00EF223CBFFC3876F9C9E7BF61818808214728080',
);

await waitForAppScreen(sim);
let clicks;
if (model.letter === 'S') clicks = 10;
else clicks = 6;
await sim.navigateAndCompareSnapshots('.', model.name + '_transfer_ethereum_5234_network', [clicks, -1, 0]);

await expect(tx).resolves.toEqual({
"r": "07a7982dfd16360c96a03467877d0cf9c36f799deff4dace250cdb18e28a3b90",
"s": "773318a93da2e32c1cf308ddd6add1e8c0d285973e541520a05fb4dc720e4fb1",
"v": "2908",
});
}));
});

0 comments on commit adbe34c

Please sign in to comment.