Skip to content

Commit

Permalink
fix cpp tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ftheirs committed Nov 7, 2023
1 parent a915cc9 commit a8cba09
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 31 deletions.
31 changes: 11 additions & 20 deletions app/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,10 @@ parser_error_t parser_validate(const parser_context_t *ctx) {
return parser_unsupported_tx;
}

zemu_log("parser_validate::validated\n");

// Iterate through all items to check that all can be shown and are valid
uint8_t numItems = 0;
CHECK_PARSER_ERR(parser_getNumItems(ctx, &numItems));

char log_tmp[100];
snprintf(log_tmp, sizeof(log_tmp), "parser_validate %d\n", numItems);
zemu_log(log_tmp);

char tmpKey[40] = {0};
char tmpVal[40] = {0};

Expand All @@ -154,14 +148,11 @@ parser_error_t parser_validate(const parser_context_t *ctx) {
sizeof(tmpVal), 0, &pageCount))
}

zemu_log("parser_validate::ok\n");
return parser_ok;
}

parser_error_t parser_getNumItems(const parser_context_t *ctx,
uint8_t *num_items) {
zemu_log("parser_getNumItems\n");

switch (ctx->tx_type) {
case fil_tx: {
*num_items = _getNumItems(ctx, &parser_tx_obj.base_tx);
Expand Down Expand Up @@ -217,9 +208,7 @@ parser_error_t _getItemFil(const parser_context_t *ctx, uint8_t displayIdx,
char *outKey, uint16_t outKeyLen, char *outVal,
uint16_t outValLen, uint8_t pageIdx,
uint8_t *pageCount) {
char log_tmp[100];
snprintf(log_tmp, sizeof(log_tmp), "getItem %d\n", displayIdx);
zemu_log(log_tmp);

const bool expert_mode = app_mode_expert();

MEMZERO(outKey, outKeyLen);
Expand All @@ -236,32 +225,34 @@ parser_error_t _getItemFil(const parser_context_t *ctx, uint8_t displayIdx,
return parser_no_data;
}

uint8_t adjustedIndex = displayIdx;
if (parser_tx_obj.base_tx.to.buffer[0] != ADDRESS_PROTOCOL_DELEGATED) {
displayIdx++;
adjustedIndex++;
}
if (displayIdx >= 2 && parser_tx_obj.base_tx.from.buffer[0] != ADDRESS_PROTOCOL_DELEGATED) {
displayIdx++;

if (adjustedIndex >= 2 && parser_tx_obj.base_tx.from.buffer[0] != ADDRESS_PROTOCOL_DELEGATED) {
adjustedIndex++;
}

// Normal mode: 6 fields [To | From | Value | Gas Limit | Gas Fee Cap |
// Method] + Params (variable length) Expert mode: 8 fields [To | From | Value
// | Gas Limit | Gas Fee Cap | Gas Premium | Nonce | Method] + Params
// (variable length)
switch (displayIdx) {
switch (adjustedIndex) {
case 0:
snprintf(outKey, outKeyLen, "To");
snprintf(outKey, outKeyLen, "To ");
return printEthAddress(&parser_tx_obj.base_tx.to, outVal, outValLen, pageIdx,
pageCount);
case 1:
snprintf(outKey, outKeyLen, "To");
snprintf(outKey, outKeyLen, "To ");
return printAddress(&parser_tx_obj.base_tx.to, outVal, outValLen, pageIdx,
pageCount);
case 2:
snprintf(outKey, outKeyLen, "From");
snprintf(outKey, outKeyLen, "From ");
return printEthAddress(&parser_tx_obj.base_tx.from, outVal, outValLen, pageIdx,
pageCount);
case 3:
snprintf(outKey, outKeyLen, "From");
snprintf(outKey, outKeyLen, "From ");
return printAddress(&parser_tx_obj.base_tx.from, outVal, outValLen, pageIdx,
pageCount);
case 4:
Expand Down
46 changes: 35 additions & 11 deletions tests/expected_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ std::vector<std::string> GenerateExpectedUIOutput(const Json::Value &json, bool)
///

auto message = json["message"];
auto from0x = message["from0x"].asString();
auto from = message["from"].asString();

auto to0x = message["to0x"].asString();
auto to = message["to"].asString();
auto nonce = message["nonce"].asUInt64();

Expand All @@ -94,33 +96,55 @@ std::vector<std::string> GenerateExpectedUIOutput(const Json::Value &json, bool)
auto params = message["params"];
///

auto toAddress = FormatAddress(0, "To ", to);
uint8_t idx = 0;
if (!to0x.empty()) {
auto to0xAddress = FormatAddress(idx, "To ", to0x);
answer.insert(answer.end(), to0xAddress.begin(), to0xAddress.end());
// addTo(answer, "{} | To : {}", idx, to0xAddress);
idx++;
}

auto toAddress = FormatAddress(idx, "To ", to);
answer.insert(answer.end(), toAddress.begin(), toAddress.end());
idx++;

auto fromAddress = FormatAddress(1, "From ", from);
answer.insert(answer.end(), fromAddress.begin(), fromAddress.end());
if (!from0x.empty()) {
auto fromAddress0x = FormatAddress(idx, "From ", from0x);
answer.insert(answer.end(), fromAddress0x.begin(), fromAddress0x.end());
idx++;
}

auto fromAddress = FormatAddress(idx, "From ", from);
answer.insert(answer.end(), fromAddress.begin(), fromAddress.end());
idx++;

addTo(answer, "2 | Value : {}", FormatAmount(value));
addTo(answer, "{} | Value : {}", idx, FormatAmount(value));
idx++;

addTo(answer, "3 | Gas Limit : {}", gaslimit);
addTo(answer, "{} | Gas Limit : {}", idx, gaslimit);
idx++;

addTo(answer, "4 | Gas Fee Cap : {}", FormatAmount(gasfeecap));
addTo(answer, "{} | Gas Fee Cap : {}", idx, FormatAmount(gasfeecap));
idx++;

addTo(answer, "5 | Gas Premium : {}", FormatAmount(gaspremium));
addTo(answer, "{} | Gas Premium : {}", idx, FormatAmount(gaspremium));
idx++;

addTo(answer, "6 | Nonce : {}", nonce);
addTo(answer, "{} | Nonce : {}", idx, nonce);
idx++;

if (method != 0) {
addTo(answer, "7 | Method : {}", method);
addTo(answer, "{} | Method : {}", idx, method);
idx++;
} else {
addTo(answer, "7 | Method : Transfer", method);
addTo(answer, "{} | Method : Transfer", idx, method);
idx++;
}

int paramIdx = 1;
for(auto value : params) {
std::string paramText = "Params |" + std::to_string(paramIdx) + "| ";
auto paramsAddress = FormatAddress(8 + paramIdx - 1, paramText, value.asString());
auto paramsAddress = FormatAddress(idx + paramIdx - 1, paramText, value.asString());
answer.insert(answer.end(), paramsAddress.begin(), paramsAddress.end());
paramIdx++;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/testvectors/manual.json
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,9 @@
"testnet": false,
"message": {
"version": 0,
"to0x": "0xd4224267c4ab4a184bd1aa066b3361e70efbbeaf",
"to": "f410f2qreez6evnfbqs6rvidgwm3b44hpxpvpeuoddga",
"from0x": "0xd4224267c4ab4a184bd1aa066b3361e70efbbeaf",
"from": "f410f2qreez6evnfbqs6rvidgwm3b44hpxpvpeuoddga",
"nonce": 1,
"value": "100000",
Expand Down Expand Up @@ -685,6 +687,7 @@
"testnet": true,
"message": {
"version": 0,
"to0x": "0xea71f8dc046717b8b14c18005186d03495a0e492",
"to": "t410f5jy7rxaem4l3rmkmdaafdbwqgsk2bzess6wu5qq",
"from": "t1d2xrzcslx7xlbbylc5c3d5lvandqw4iwl6epxba",
"nonce": 3,
Expand All @@ -704,6 +707,7 @@
"testnet": true,
"message": {
"version": 0,
"to0x": "0x6c297aed654816dc5d211c956de816ba923475d2",
"to": "t410fnquxv3lfjalnyxjbdskw32awxkjdi5osydrtwqi",
"from": "t1d2xrzcslx7xlbbylc5c3d5lvandqw4iwl6epxba",
"nonce": 8,
Expand Down

0 comments on commit a8cba09

Please sign in to comment.