Skip to content

Commit

Permalink
Merge pull request #11 from blooo-io/fix/differentiate-raw-amount-fro…
Browse files Browse the repository at this point in the history
…m-amount

fix: Add THOR.RUNE default denom + raw amount fix
  • Loading branch information
Z4karia authored Oct 1, 2024
2 parents a07a1b5 + 02ee3d9 commit dbb091f
Show file tree
Hide file tree
Showing 45 changed files with 60 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ APPVERSION_M=2
# This is the `spec_version` field of `Runtime`
APPVERSION_N=4
# This is the patch version of this release
APPVERSION_P=0
APPVERSION_P=1
1 change: 1 addition & 0 deletions app/src/coin.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ typedef enum {

#define COIN_DEFAULT_DENOM_BASE "rune"
#define COIN_DEFAULT_DENOM_REPR "RUNE"
#define COIN_DEFAULT_DENOM_REPR_2 "THOR.RUNE"
#define COIN_DEFAULT_DENOM_FACTOR 8u
#define COIN_DEFAULT_DENOM_TRIMMING 0u

Expand Down
34 changes: 20 additions & 14 deletions app/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ __Z_INLINE parser_error_t is_default_denom_base(const char *denom, uint8_t denom
return parser_ok;
}

if (strlen(COIN_DEFAULT_DENOM_BASE) != denom_len) {
if (strlen(COIN_DEFAULT_DENOM_BASE) != denom_len && strlen(COIN_DEFAULT_DENOM_REPR_2) != denom_len) {
*is_default = false;
return parser_ok;
}

if (memcmp(denom, COIN_DEFAULT_DENOM_BASE, denom_len) == 0) {
if (memcmp(denom, COIN_DEFAULT_DENOM_BASE, denom_len) == 0 || memcmp(denom, COIN_DEFAULT_DENOM_REPR_2, denom_len) == 0) {
*is_default = true;
return parser_ok;
}
Expand All @@ -125,7 +125,7 @@ __Z_INLINE parser_error_t is_default_denom_base(const char *denom, uint8_t denom

__Z_INLINE parser_error_t parser_formatAmountItem(uint16_t amountToken,
char *outVal, uint16_t outValLen,
uint8_t pageIdx, uint8_t *pageCount) {
uint8_t pageIdx, uint8_t *pageCount, bool *is_default) {
*pageCount = 0;

uint16_t numElements;
Expand Down Expand Up @@ -187,9 +187,9 @@ __Z_INLINE parser_error_t parser_formatAmountItem(uint16_t amountToken,

snprintf(bufferUI, sizeof(bufferUI), "%s ", tmpAmount);
// If denomination has been recognized format and replace
bool is_default =false;
CHECK_PARSER_ERR(is_default_denom_base(denomPtr, denomLen, &is_default))
if (is_default) {
*is_default = false;
CHECK_PARSER_ERR(is_default_denom_base(denomPtr, denomLen, is_default))
if (*is_default) {
if (fpstr_to_str(bufferUI, sizeof(bufferUI), tmpAmount, COIN_DEFAULT_DENOM_FACTOR) != 0) {
return parser_unexpected_error;
}
Expand All @@ -205,12 +205,12 @@ __Z_INLINE parser_error_t parser_formatAmountItem(uint16_t amountToken,

__Z_INLINE parser_error_t parser_formatAmount(uint16_t amountToken,
char *outVal, uint16_t outValLen,
uint8_t pageIdx, uint8_t *pageCount) {
ZEMU_LOGF(200, "[formatAmount] ------- pageidx %d", pageIdx)
uint8_t pageIdx, uint8_t *pageCount, bool *is_default) {
ZEMU_LOGF(200, "[formatAmount] ------- pageidx %d\n", pageIdx)

*pageCount = 0;
if (parser_tx_obj.tx_json.json.tokens[amountToken].type != JSMN_ARRAY) {
return parser_formatAmountItem(amountToken, outVal, outValLen, pageIdx, pageCount);
return parser_formatAmountItem(amountToken, outVal, outValLen, pageIdx, pageCount, is_default);
}

uint8_t totalPages = 0;
Expand All @@ -227,7 +227,7 @@ __Z_INLINE parser_error_t parser_formatAmount(uint16_t amountToken,
uint8_t subpagesCount;

CHECK_PARSER_ERR(array_get_nth_element(&parser_tx_obj.tx_json.json, amountToken, i, &itemTokenIdx));
CHECK_PARSER_ERR(parser_formatAmountItem(itemTokenIdx, outVal, outValLen, 0, &subpagesCount));
CHECK_PARSER_ERR(parser_formatAmountItem(itemTokenIdx, outVal, outValLen, 0, &subpagesCount, is_default));
totalPages += subpagesCount;

ZEMU_LOGF(200, "[formatAmount] [%d] TokenIdx: %d - PageIdx: %d - Pages: %d - Total %d", i, itemTokenIdx,
Expand Down Expand Up @@ -256,7 +256,7 @@ __Z_INLINE parser_error_t parser_formatAmount(uint16_t amountToken,
}

uint8_t dummy;
return parser_formatAmountItem(showItemTokenIdx, outVal, outValLen, showPageIdx, &dummy);
return parser_formatAmountItem(showItemTokenIdx, outVal, outValLen, showPageIdx, &dummy, is_default);
}

__Z_INLINE parser_error_t parser_getJsonItem(uint8_t displayIdx,
Expand Down Expand Up @@ -287,10 +287,12 @@ __Z_INLINE parser_error_t parser_getJsonItem(uint8_t displayIdx,
CHECK_APP_CANARY()
snprintf(outKey, outKeyLen, "%s", tmpKey);

bool is_default = false;

if (parser_isAmount(tmpKey)) {
CHECK_PARSER_ERR(parser_formatAmount(ret_value_token_index,
outVal, outValLen,
pageIdx, pageCount))
pageIdx, pageCount, &is_default))
} else {
CHECK_PARSER_ERR(tx_getToken(ret_value_token_index,
outVal, outValLen,
Expand All @@ -300,8 +302,12 @@ __Z_INLINE parser_error_t parser_getJsonItem(uint8_t displayIdx,

CHECK_PARSER_ERR(tx_display_make_friendly())
CHECK_APP_CANARY()

snprintf(outKey, outKeyLen, "%s", tmpKey);
// Display "Raw Amount" for non-default tokens
if(memcmp(tmpKey, "Amount", 6) == 0 && is_default == false){
snprintf(outKey, outKeyLen, "Raw %s", tmpKey);
} else {
snprintf(outKey, outKeyLen, "%s", tmpKey);
}
CHECK_APP_CANARY()

return parser_ok;
Expand Down
14 changes: 7 additions & 7 deletions tests/testcases/thor.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@
"1 | Account : 588",
"2 | Sequence : 5",
"3 | Type : Send",
"4 | Amount : 150000000 rune",
"4 | Raw Amount : 150000000 rune",
"5 | From [1/2] : tthor1c648xgpter9xffhmcqvs7lzd7hxh0prgv",
"5 | From [2/2] : 5t5gp",
"6 | To [1/2] : tthor10xgrknu44d83qr4s4uw56cqxg0hsev5e6",
"6 | To [2/2] : 8lc9z",
"7 | Amount : 50000000 rune",
"7 | Raw Amount : 50000000 rune",
"8 | From [1/2] : tthor1c648xgpter9xffhmcqvs7lzd7hxh0prgv",
"8 | From [2/2] : 5t5gp",
"9 | To [1/2] : tthor10xgrknu44d83qr4s4uw56cqxg0hsev5e6",
Expand Down Expand Up @@ -103,7 +103,7 @@
"1 | Account : 588",
"2 | Sequence : 5",
"3 | Type : Send",
"4 | Amount : 150000000 rune",
"4 | Raw Amount : 150000000 rune",
"5 | From [1/2] : tthor1c648xgpter9xffhmcqvs7lzd7hxh0prgv",
"5 | From [2/2] : 5t5gp",
"6 | To [1/2] : tthor10xgrknu44d83qr4s4uw56cqxg0hsev5e6",
Expand Down Expand Up @@ -185,7 +185,7 @@
"1 | Account : 588",
"2 | Sequence : 5",
"3 | Type : Send",
"4 | Amount : 150000000 rune",
"4 | Raw Amount : 150000000 rune",
"5 | From [1/2] : tthor1c648xgpter9xffhmcqvs7lzd7hxh0prgv",
"5 | From [2/2] : 5t5gp",
"6 | To [1/2] : tthor10xgrknu44d83qr4s4uw56cqxg0hsev5e6",
Expand Down Expand Up @@ -309,8 +309,8 @@
"1 | Account : 588",
"2 | Sequence : 6",
"3 | Type : Deposit",
"4 | Amount [1/2] : 330000000 THOR.RUNE",
"4 | Amount [2/2] : 220000000 BSC.USDT",
"4 | Raw Amount [1/2] : 330000000 THOR.RUNE",
"4 | Raw Amount [2/2] : 220000000 BSC.USDT",
"5 | Memo [1/2] : SWAP:BNB.BNB:tbnb1qk2m905ypazwfau9cn0qn",
"5 | Memo [2/2] : r4c4yxz63v9u9md20:",
"6 | Sender [1/2] : tthor1c648xgpter9xffhmcqvs7lzd7hxh0prgv",
Expand Down Expand Up @@ -352,7 +352,7 @@
"1 | Account : 588",
"2 | Sequence : 6",
"3 | Type : Deposit",
"4 | Amount : 330000000 THOR.RUNE",
"4 | Raw Amount : 330000000 THOR.RUNE",
"5 | Sender [1/2] : tthor1c648xgpter9xffhmcqvs7lzd7hxh0prgv",
"5 | Sender [2/2] : 5t5gp",
"6 | Fee : Empty",
Expand Down
Binary file modified tests_zemu/snapshots/fl-sign_msgDeposit/00001.png
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.
Binary file modified tests_zemu/snapshots/s-sign_msgDeposit/00001.png
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.
Binary file modified tests_zemu/snapshots/sp-sign_msgDeposit/00002.png
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.
Binary file modified tests_zemu/snapshots/st-sign_msgDeposit/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_zemu/snapshots/x-sign_msgDeposit/00002.png
26 changes: 26 additions & 0 deletions tests_zemu/tests/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,30 @@ export const example_tx_str_MsgDeposit = {
}
],
"sequence": "6"
};

export const example_tx_str_MsgDeposit_token_2 = {
"account_number": "588",
"chain_id": "thorchain",
"fee": {
"amount": [],
"gas": "10000000"
},
"memo": "",
"msgs": [
{
"type": "thorchain/MsgDeposit",
"value": {
"coins": [
{
"amount": "330000000",
"asset": "ETH.ETH"
}
],
"memo": "SWAP:BNB.BNB:tbnb1qk2m905ypazwfau9cn0qnr4c4yxz63v9u9md20:",
"signer": "tthor1c648xgpter9xffhmcqvs7lzd7hxh0prgv5t5gp"
}
}
],
"sequence": "6"
};
5 changes: 5 additions & 0 deletions tests_zemu/tests/thor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
AMINO_JSON_TX,
example_tx_str_MsgSend,
example_tx_str_MsgDeposit,
example_tx_str_MsgDeposit_token_2
} from './common'

// @ts-ignore
Expand Down Expand Up @@ -98,4 +99,8 @@ describe('Thor', function () {
await signAndVerifyTransaction(m, 'sign_msgDeposit', example_tx_str_MsgDeposit);
});

test.concurrent.each(DEVICE_MODELS)('sign msgDeposit token 2', async function (m) {
await signAndVerifyTransaction(m, 'sign_msgDeposit_token_2', example_tx_str_MsgDeposit_token_2);
});

})

0 comments on commit dbb091f

Please sign in to comment.