Skip to content
Draft
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
7 changes: 7 additions & 0 deletions src/hedera_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ static char *hedera_format_amount(uint64_t amount, uint8_t decimals) {
if (decimals >= 20) return buf;

int i = 0;
bool contains_decimal_place = false;

while (i < (BUF_SIZE - 1) && (amount > 0 || i < decimals)) {
int digit = amount % 10;
Expand All @@ -34,6 +35,7 @@ static char *hedera_format_amount(uint64_t amount, uint8_t decimals) {

if (i == decimals) {
buf[i++] = '.';
contains_decimal_place = true;
}
}

Expand All @@ -55,6 +57,11 @@ static char *hedera_format_amount(uint64_t amount, uint8_t decimals) {
j += 1;
}

if (!contains_decimal_place) {
// We can skip decimal places trimming (as there are none)
return buf;
}

for (j = size - 1; j > 0; j--) {
if (buf[j] == '0') {
continue;
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.
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.
109 changes: 109 additions & 0 deletions tests/standalone/test_hedera.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,115 @@ def test_hedera_transfer_token_ok(backend, firmware, scenario_navigator):
):
navigation_helper_confirm(firmware, scenario_navigator)

def test_hedera_transfer_token_2_ok(backend, firmware, scenario_navigator):
hedera = HederaClient(backend)
conf = crypto_transfer_token_conf(
token_shardNum=15,
token_realmNum=16,
token_tokenNum=17,
sender_shardNum=57,
sender_realmNum=58,
sender_accountNum=59,
recipient_shardNum=100,
recipient_realmNum=101,
recipient_accountNum=102,
amount=20,
decimals=0,
)

with hedera.send_sign_transaction(
index=0,
operator_shard_num=1,
operator_realm_num=2,
operator_account_num=3,
transaction_fee=5,
memo="this_is_the_memo",
conf=conf,
):
navigation_helper_confirm(firmware, scenario_navigator)

def test_hedera_transfer_token_3_ok(backend, firmware, scenario_navigator):
hedera = HederaClient(backend)
conf = crypto_transfer_token_conf(
token_shardNum=15,
token_realmNum=16,
token_tokenNum=17,
sender_shardNum=57,
sender_realmNum=58,
sender_accountNum=59,
recipient_shardNum=100,
recipient_realmNum=101,
recipient_accountNum=102,
amount=20,
decimals=2,
)

with hedera.send_sign_transaction(
index=0,
operator_shard_num=1,
operator_realm_num=2,
operator_account_num=3,
transaction_fee=5,
memo="this_is_the_memo",
conf=conf,
):
navigation_helper_confirm(firmware, scenario_navigator)

def test_hedera_transfer_token_4_ok(backend, firmware, scenario_navigator):
hedera = HederaClient(backend)
conf = crypto_transfer_token_conf(
token_shardNum=15,
token_realmNum=16,
token_tokenNum=17,
sender_shardNum=57,
sender_realmNum=58,
sender_accountNum=59,
recipient_shardNum=100,
recipient_realmNum=101,
recipient_accountNum=102,
amount=1230000000,
decimals=9,
)

with hedera.send_sign_transaction(
index=0,
operator_shard_num=1,
operator_realm_num=2,
operator_account_num=3,
transaction_fee=5,
memo="",
conf=conf,
):
navigation_helper_confirm(firmware, scenario_navigator)

def test_hedera_transfer_token_5_ok(backend, firmware, scenario_navigator):
hedera = HederaClient(backend)
conf = crypto_transfer_token_conf(
token_shardNum=15,
token_realmNum=16,
token_tokenNum=17,
sender_shardNum=57,
sender_realmNum=58,
sender_accountNum=59,
recipient_shardNum=100,
recipient_realmNum=101,
recipient_accountNum=102,
amount=8,
decimals=12,
)

with hedera.send_sign_transaction(
index=0,
operator_shard_num=1,
operator_realm_num=2,
operator_account_num=3,
transaction_fee=5,
memo="",
conf=conf,
):
navigation_helper_confirm(firmware, scenario_navigator)



def test_hedera_transfer_known_token_1_ok(backend, firmware, scenario_navigator):
hedera = HederaClient(backend)
Expand Down
Loading