Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/features/generic_tx_parser/gtp_param_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ bool format_param_token(const s_param_token *param, const char *name) {
buf_shrink_expand(collec.value[i].ptr, collec.value[i].length, addr, sizeof(addr));
if (match_native(addr, param)) {
ticker = get_displayable_ticker(&chain_id, g_chain_config, true);
} else if ((token_info = get_matching_token_info(&chain_id, addr))) {
} else {
if ((token_info = get_matching_token_info_or_dummy(&chain_id, addr)) == NULL) {
ret = false;
break;
}
ticker = token_info->ticker;
}
if (ticker == NULL) {
Expand Down
7 changes: 4 additions & 3 deletions src/features/generic_tx_parser/gtp_param_token_amount.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ static bool process_token_amount(const s_param_token_amount *param,
ticker = get_displayable_ticker(&chain_id, g_chain_config, true);
decimals = WEI_TO_ETHER;
} else {
if ((token_info = get_matching_token_info(&chain_id, addr_buf)) != NULL) {
ticker = token_info->ticker;
decimals = token_info->decimals;
if ((token_info = get_matching_token_info_or_dummy(&chain_id, addr_buf)) == NULL) {
return false;
}
ticker = token_info->ticker;
decimals = token_info->decimals;
}
}

Expand Down
22 changes: 22 additions & 0 deletions src/features/provide_erc20_token_information/token_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "lists.h"
#include "app_mem_utils.h"
#include "token_info.h"
#include "network.h"

typedef struct {
flist_node_t _list;
Expand Down Expand Up @@ -59,3 +60,24 @@ const s_token_info *get_matching_token_info(const uint64_t *chain_id, const uint
}
return NULL;
}

const s_token_info *get_matching_token_info_or_dummy(const uint64_t *chain_id,
const uint8_t *address) {
const s_token_info *info_ptr;
s_token_info info;

if ((chain_id == NULL) || (address == NULL)) {
return NULL;
}
if ((info_ptr = get_matching_token_info(chain_id, address)) != NULL) {
return info_ptr;
}
info.chain_id = *chain_id;
memcpy(info.address, address, ADDRESS_LENGTH);
strlcpy(info.ticker, g_unknown_ticker, sizeof(info.ticker));
info.decimals = 0;
if (set_token_info(&info) == -1) {
return NULL;
}
return get_matching_token_info(chain_id, address);
}
2 changes: 2 additions & 0 deletions src/features/provide_erc20_token_information/token_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ typedef struct {
int set_token_info(const s_token_info *info);
void clear_token_infos(void);
const s_token_info *get_matching_token_info(const uint64_t *chain_id, const uint8_t *address);
const s_token_info *get_matching_token_info_or_dummy(const uint64_t *chain_id,
const uint8_t *address);
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.
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.
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.
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.
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.
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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 12 additions & 3 deletions tests/ragger/test_gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import hashlib
from pathlib import Path

import pytest
from web3 import Web3

from ragger.navigator.navigation_scenario import NavigateWithScenario
Expand Down Expand Up @@ -594,7 +595,12 @@ def test_gcs_proxy(scenario_navigator: NavigateWithScenario):
scenario_navigator.review_approve()


def test_gcs_4226(scenario_navigator: NavigateWithScenario):
@pytest.fixture(name="known_tokens", params=[True, False])
def known_tokens_fixture(request) -> bool:
return request.param


def test_gcs_4226(scenario_navigator: NavigateWithScenario, known_tokens: bool):
backend = scenario_navigator.backend
app_client = EthAppClient(backend)

Expand Down Expand Up @@ -691,8 +697,11 @@ def test_gcs_4226(scenario_navigator: NavigateWithScenario):

app_client.provide_transaction_info(tx_info.serialize())

app_client.provide_token_metadata("rSWELL", tx_params["to"], 18, 1)
app_client.provide_token_metadata("SWELL", swell_token_addr, 18, 1)
if known_tokens:
app_client.provide_token_metadata("rSWELL", tx_params["to"], 18, 1)
app_client.provide_token_metadata("SWELL", swell_token_addr, 18, 1)
else:
scenario_navigator.test_name += "_unknown_tokens"

for field in fields:
app_client.provide_transaction_field_desc(field.serialize())
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ target_link_libraries(test_param_token_amount PUBLIC
-Wl,--wrap=value_cleanup
-Wl,--wrap=handle_value_struct
-Wl,--wrap=get_current_tx_info
-Wl,--wrap=get_matching_token_info
-Wl,--wrap=get_matching_token_info_or_dummy
-Wl,--wrap=add_to_field_table
-Wl,--wrap=get_displayable_ticker
)
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/src/test_param_token_amount.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ const s_tx_info *__wrap_get_current_tx_info(void) {
return &g_fake_tx_info;
}

const s_token_info *__wrap_get_matching_token_info(const uint64_t *chain_id, const uint8_t *addr) {
const s_token_info *__wrap_get_matching_token_info_or_dummy(const uint64_t *chain_id,
const uint8_t *addr) {
(void) chain_id;
(void) addr;
return (const s_token_info *) mock();
Expand Down Expand Up @@ -115,7 +116,7 @@ static uint8_t g_usdc_addr[ADDRESS_LENGTH] = {
0x9D, 0x4a, 0x2e, 0x9E, 0xb0, 0xcE, 0x36, 0x06, 0xeB, 0x48,
};

// Fake USDC extra_info returned by get_matching_token_info
// Fake USDC extra_info returned by get_matching_token_info_or_dummy
static s_token_info g_usdc_info = {
.address =
{
Expand Down Expand Up @@ -163,8 +164,8 @@ static void test_token_amount_broadcast_ok(void **state) {
g_fake_tx_info.chain_id = 1;

// token resolution: USDC found (called for each of the 2 iterations)
will_return(__wrap_get_matching_token_info, &g_usdc_info);
will_return(__wrap_get_matching_token_info, &g_usdc_info);
will_return(__wrap_get_matching_token_info_or_dummy, &g_usdc_info);
will_return(__wrap_get_matching_token_info_or_dummy, &g_usdc_info);

// Expected field table entries: "1 USDC" then "2 USDC"
expect_value(__wrap_add_to_field_table, type, PARAM_TYPE_TOKEN_AMOUNT);
Expand Down
Loading