Skip to content

Commit

Permalink
Merge pull request #96 from Zondax/ui_gas
Browse files Browse the repository at this point in the history
UI Adjustments
  • Loading branch information
jleni authored Mar 7, 2022
2 parents 25578dd + 2ec3c46 commit 263fbd8
Show file tree
Hide file tree
Showing 205 changed files with 72 additions and 28 deletions.
4 changes: 2 additions & 2 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ COIN=FIL
endif

APPVERSION_M=0
APPVERSION_N=20
APPVERSION_P=2
APPVERSION_N=21
APPVERSION_P=0

$(info COIN = [$(COIN)])
ifeq ($(COIN),FIL)
Expand Down
41 changes: 22 additions & 19 deletions app/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ parser_error_t parser_parse(parser_context_t *ctx, const uint8_t *data, size_t d
}

parser_error_t parser_validate(const parser_context_t *ctx) {
zemu_log("parser_validate");
zemu_log("parser_validate\n");
CHECK_PARSER_ERR(_validateTx(ctx, &parser_tx_obj))
zemu_log("parser_validate::validated\n");

Expand Down Expand Up @@ -121,6 +121,7 @@ parser_error_t parser_getItem(const parser_context_t *ctx,
char log_tmp[100];
snprintf(log_tmp, sizeof(log_tmp), "getItem %d\n", displayIdx);
zemu_log(log_tmp);
uint8_t expert_mode = app_mode_expert();

MEMZERO(outKey, outKeyLen);
MEMZERO(outVal, outValLen);
Expand Down Expand Up @@ -149,20 +150,11 @@ parser_error_t parser_getItem(const parser_context_t *ctx,
}

if (displayIdx == 2) {
snprintf(outKey, outKeyLen, "Nonce ");
if (uint64_to_str(outVal, outValLen, parser_tx_obj.nonce) != NULL) {
return parser_unexepected_error;
}
*pageCount = 1;
return parser_ok;
}

if (displayIdx == 3) {
snprintf(outKey, outKeyLen, "Value ");
return parser_printBigIntFixedPoint(&parser_tx_obj.value, outVal, outValLen, pageIdx, pageCount);
}

if (displayIdx == 4) {
if (displayIdx == 3) {
snprintf(outKey, outKeyLen, "Gas Limit ");
if (int64_to_str(outVal, outValLen, parser_tx_obj.gaslimit) != NULL) {
return parser_unexepected_error;
Expand All @@ -171,17 +163,28 @@ parser_error_t parser_getItem(const parser_context_t *ctx,
return parser_ok;
}

if (displayIdx == 5) {
snprintf(outKey, outKeyLen, "Gas Premium ");
return parser_printBigIntFixedPoint(&parser_tx_obj.gaspremium, outVal, outValLen, pageIdx, pageCount);
}

if (displayIdx == 6) {
if (displayIdx == 4) {
snprintf(outKey, outKeyLen, "Gas Fee Cap ");
return parser_printBigIntFixedPoint(&parser_tx_obj.gasfeecap, outVal, outValLen, pageIdx, pageCount);
}

if (displayIdx == 7) {
if (expert_mode){
if (displayIdx == 5) {
snprintf(outKey, outKeyLen, "Gas Premium ");
return parser_printBigIntFixedPoint(&parser_tx_obj.gaspremium, outVal, outValLen, pageIdx, pageCount);
}

if (displayIdx == 6) {
snprintf(outKey, outKeyLen, "Nonce ");
if (uint64_to_str(outVal, outValLen, parser_tx_obj.nonce) != NULL) {
return parser_unexepected_error;
}
*pageCount = 1;
return parser_ok;
}
}

if ((displayIdx == 5 && !expert_mode) || (displayIdx == 7 && expert_mode)) {
snprintf(outKey, outKeyLen, "Method ");
*pageCount = 1;

Expand All @@ -205,7 +208,7 @@ parser_error_t parser_getItem(const parser_context_t *ctx,
}

// remaining display pages show the params
int32_t paramIdxSigned = displayIdx - 8;
int32_t paramIdxSigned = displayIdx - (numItems - parser_tx_obj.numparams);

// end of params
if (paramIdxSigned < 0 || paramIdxSigned >= parser_tx_obj.numparams) {
Expand Down
6 changes: 5 additions & 1 deletion app/src/parser_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,11 @@ parser_error_t _validateTx(__Z_UNUSED const parser_context_t *c, __Z_UNUSED cons

uint8_t _getNumItems(__Z_UNUSED const parser_context_t *c, const parser_tx_t *v) {

uint8_t itemCount = 8;
uint8_t itemCount = 6;

if (app_mode_expert()){
itemCount = 8;
}

return itemCount + v->numparams;
}
8 changes: 4 additions & 4 deletions tests/expected_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ std::vector<std::string> GenerateExpectedUIOutput(const Json::Value &json, bool)
answer.insert(answer.end(), fromAddress.begin(), fromAddress.end());


addTo(answer, "2 | Nonce : {}", nonce);
addTo(answer, "2 | Value : {}", FormatAmount(value));

addTo(answer, "3 | Value : {}", FormatAmount(value));
addTo(answer, "3 | Gas Limit : {}", gaslimit);

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

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

addTo(answer, "6 | Gas Fee Cap : {}", FormatAmount(gasfeecap));
addTo(answer, "6 | Nonce : {}", nonce);

switch (method) {
case 0:
Expand Down
Binary file modified tests_zemu/snapshots/s-mainmenu/00002.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/s-sign_basic/00006.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/s-sign_basic/00007.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/s-sign_basic/00008.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/s-sign_basic/00009.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/s-sign_basic/00010.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/s-sign_basic/00011.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/s-sign_proposal/00003.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/s-sign_proposal/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_zemu/snapshots/s-sign_proposal/00005.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/s-sign_proposal/00006.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/s-sign_proposal/00007.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/s-sign_proposal/00008.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/s-sign_proposal/00009.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/s-sign_proposal/00010.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/s-sign_proposal/00011.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/s-sign_proposal/00012.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/s-sign_proposal/00013.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.
Binary file modified tests_zemu/snapshots/x-mainmenu/00002.png
Binary file modified tests_zemu/snapshots/x-sign_basic/00005.png
Binary file modified tests_zemu/snapshots/x-sign_basic/00006.png
Binary file modified tests_zemu/snapshots/x-sign_basic/00007.png
Binary file modified tests_zemu/snapshots/x-sign_basic/00008.png
Binary file modified tests_zemu/snapshots/x-sign_basic/00009.png
Binary file modified tests_zemu/snapshots/x-sign_basic/00010.png
Binary file modified tests_zemu/snapshots/x-sign_proposal/00003.png
Binary file modified tests_zemu/snapshots/x-sign_proposal/00004.png
Binary file modified tests_zemu/snapshots/x-sign_proposal/00005.png
Binary file modified tests_zemu/snapshots/x-sign_proposal/00006.png
Binary file modified tests_zemu/snapshots/x-sign_proposal/00007.png
Binary file modified tests_zemu/snapshots/x-sign_proposal/00008.png
Binary file modified tests_zemu/snapshots/x-sign_proposal/00009.png
Binary file modified tests_zemu/snapshots/x-sign_proposal/00010.png
Binary file modified tests_zemu/snapshots/x-sign_proposal/00011.png
Binary file modified tests_zemu/snapshots/x-sign_proposal/00012.png
41 changes: 39 additions & 2 deletions tests_zemu/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe('Standard', function () {
// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot());

await sim.compareSnapshotsAndAccept(".", `${m.prefix.toLowerCase()}-sign_basic`, m.name === "nanos" ? 12 : 11);
await sim.compareSnapshotsAndAccept(".", `${m.prefix.toLowerCase()}-sign_basic`, m.name === "nanos" ? 10 : 9);

let resp = await signatureRequest;
console.log(resp);
Expand Down Expand Up @@ -207,6 +207,42 @@ describe('Standard', function () {
});

test.each(models)('sign proposal', async function (m) {
const sim = new Zemu(m.path);
try {
await sim.start({...defaultOptions, model: m.name,});
const app = new FilecoinApp(sim.getTransport());

const path = "m/44'/461'/0'/0/1";
const txBlob = Buffer.from(
"8a004300ec075501dfe49184d46adc8f89d44638beb45f78fcad259001401a000f4240430009c4430009c402581d845501dfe49184d46adc8f89d44638beb45f78fcad2590430003e80040",
"hex",
);

const pkResponse = await app.getAddressAndPubKey(path);
console.log(pkResponse);
expect(pkResponse.return_code).toEqual(0x9000);
expect(pkResponse.error_message).toEqual("No errors");
console.log("No errors retriving address")

// do not wait here so we can get snapshots and interact with the app
const signatureRequest = app.sign(path, txBlob);

// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot());

await sim.compareSnapshotsAndAccept(".", `${m.prefix.toLowerCase()}-sign_proposal`, m.name === "nanos" ? 12 : 11);

let resp = await signatureRequest;
console.log(resp);

expect(resp.return_code).toEqual(0x9000);
expect(resp.error_message).toEqual("No errors");
} finally {
await sim.close();
}
});

test.each(models)('sign proposal expert ', async function (m) {
const sim = new Zemu(m.path);
try {
await sim.start({...defaultOptions, model: m.name,});
Expand Down Expand Up @@ -234,7 +270,7 @@ describe('Standard', function () {
// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot());

await sim.compareSnapshotsAndAccept(".", `${m.prefix.toLowerCase()}-sign_proposal`, m.name === "nanos" ? 14 : 13);
await sim.compareSnapshotsAndAccept(".", `${m.prefix.toLowerCase()}-sign_proposal_expert`, m.name === "nanos" ? 14 : 13);

let resp = await signatureRequest;
console.log(resp);
Expand All @@ -246,6 +282,7 @@ describe('Standard', function () {
}
});


test.each(models)('sign proposal -- unsupported method', async function (m) {
const sim = new Zemu(m.path);
try {
Expand Down

0 comments on commit 263fbd8

Please sign in to comment.