Skip to content

Commit

Permalink
Adding test+fix for combined txs (cosmos#3)
Browse files Browse the repository at this point in the history
* Adding test+fix for combined txs
* bump version number
  • Loading branch information
jleni authored Jun 9, 2020
1 parent 8d2b46a commit 26a785e
Show file tree
Hide file tree
Showing 18 changed files with 166 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ include $(BOLOS_SDK)/Makefile.defines
# Main app configuration
APPNAME = "Cosmos"
APPVERSION_M=2
APPVERSION_N=13
APPVERSION_N=14
APPVERSION_P=0

APPPATH = "44'/118'"
Expand Down
13 changes: 9 additions & 4 deletions app/src/tx_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,9 @@ parser_error_t tx_indexRootFields() {
CHECK_PARSER_ERR(calculate_is_default_chainid());

// turn off grouping if we are not in expert mode
parser_tx_obj.flags.msg_type_grouping = parser_tx_obj.filter_msg_type_count > 0;
parser_tx_obj.flags.msg_from_grouping = !tx_is_expert_mode() && parser_tx_obj.filter_msg_from_count > 0;
if (tx_is_expert_mode()) {
parser_tx_obj.flags.msg_from_grouping = 0;
}

// check if from reference value matches the device address that will be signing
parser_tx_obj.flags.msg_from_grouping_hide_all = 0;
Expand Down Expand Up @@ -319,7 +320,9 @@ __Z_INLINE parser_error_t retrieve_tree_indexes(uint8_t display_index, root_item
// consume indexed subpages until we get the item index in the subpage
*root_item = 0;
*subitem_index = 0;
while (get_subitem_count(*root_item) == 0) (*root_item)++;
while (get_subitem_count(*root_item) == 0) {
(*root_item)++;
}

for (uint16_t i = 0; i < display_index; i++) {
(*subitem_index)++;
Expand All @@ -328,7 +331,9 @@ __Z_INLINE parser_error_t retrieve_tree_indexes(uint8_t display_index, root_item
// Advance root index and skip empty items
*subitem_index = 0;
(*root_item)++;
while (get_subitem_count(*root_item) == 0) (*root_item)++;
while (get_subitem_count(*root_item) == 0){
(*root_item)++;
}
}
}

Expand Down
Binary file modified docs/img/clion_debugging.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions tests/testcases/manual.json
Original file line number Diff line number Diff line change
Expand Up @@ -1472,5 +1472,59 @@
"37 | Gas : 200000"
],
"expert": true
},
{
"name": "combined",
"tx": {
"account_number": "108",
"chain_id": "cosmoshub-3",
"fee": {
"amount": [
{
"amount": "600",
"denom": "uatom"
}
],
"gas": "200000"
},
"memo": "",
"msgs": [
{
"type": "cosmos-sdk/MsgWithdrawDelegationReward",
"value": {
"delegator_address": "cosmos19umvgcvk8cxsvzemy239nj9ngc2ltukantgyp3",
"validator_address": "cosmosvaloper1648ynlpdw7fqa2axt0w2yp3fk542junl7rsvq6"
}
},
{
"type": "cosmos-sdk/MsgDelegate",
"value": {
"delegator_address": "cosmos19umvgcvk8cxsvzemy239nj9ngc2ltukantgyp3",
"validator_address": "cosmosvaloper1648ynlpdw7fqa2axt0w2yp3fk542junl7rsvq6",
"amount": {
"denom": "uatom",
"amount": "20139397"
}
}
}
],
"sequence": "106"
},
"parsingErr": "No error",
"validationErr": "No error",
"expected": [
"0 | Type : Withdraw Reward",
"1 | Delegator [1/2] : cosmos19umvgcvk8cxsvzemy239nj9ngc2ltuka",
"1 | Delegator [2/2] : ntgyp3",
"2 | Validator [1/2] : cosmosvaloper1648ynlpdw7fqa2axt0w2yp3fk",
"2 | Validator [2/2] : 542junl7rsvq6",
"3 | Type : Delegate",
"4 | Amount : 20.139397 ATOM",
"5 | Validator [1/2] : cosmosvaloper1648ynlpdw7fqa2axt0w2yp3fk",
"5 | Validator [2/2] : 542junl7rsvq6",
"6 | Fee : 0.000600 ATOM",
"7 | Gas : 200000"
],
"expert": false
}
]
1 change: 1 addition & 0 deletions tests_zemu/snapshots-tmp/sign-basic-combined/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*
Binary file added tests_zemu/snapshots/sign-basic-combined/0.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 added tests_zemu/snapshots/sign-basic-combined/1.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 added tests_zemu/snapshots/sign-basic-combined/10.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 added tests_zemu/snapshots/sign-basic-combined/2.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 added tests_zemu/snapshots/sign-basic-combined/3.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 added tests_zemu/snapshots/sign-basic-combined/4.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 added tests_zemu/snapshots/sign-basic-combined/5.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 added tests_zemu/snapshots/sign-basic-combined/6.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 added tests_zemu/snapshots/sign-basic-combined/7.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 added tests_zemu/snapshots/sign-basic-combined/8.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 added tests_zemu/snapshots/sign-basic-combined/9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 92 additions & 0 deletions tests_zemu/tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,42 @@ const example_tx_str_expert = {
"sequence": "106"
};

const example_tx_str_combined = {
"account_number": "108",
"chain_id": "cosmoshub-3",
"fee": {
"amount": [
{
"amount": "600",
"denom": "uatom"
}
],
"gas": "200000"
},
"memo": "",
"msgs": [
{
"type": "cosmos-sdk/MsgWithdrawDelegationReward",
"value": {
"delegator_address": "cosmos1w34k53py5v5xyluazqpq65agyajavep2rflq6h",
"validator_address": "cosmosvaloper1648ynlpdw7fqa2axt0w2yp3fk542junl7rsvq6"
}
},
{
"type": "cosmos-sdk/MsgDelegate",
"value": {
"amount": {
"amount": "20139397",
"denom": "uatom"
},
"delegator_address": "cosmos1w34k53py5v5xyluazqpq65agyajavep2rflq6h",
"validator_address": "cosmosvaloper1648ynlpdw7fqa2axt0w2yp3fk542junl7rsvq6",
}
}
],
"sequence": "106"
};

describe('Basic checks', function () {
it('can start and stop container', async function () {
const sim = new Zemu(APP_PATH);
Expand Down Expand Up @@ -321,6 +357,62 @@ describe('Basic checks', function () {
}
});

it('sign basic - combined tx', async function () {
const snapshotPrefixGolden = "snapshots/sign-basic-combined/";
const snapshotPrefixTmp = "snapshots-tmp/sign-basic-combined/";
let snapshotCount = 0;

const sim = new Zemu(APP_PATH);
try {
await sim.start(sim_options);
const app = new CosmosApp(sim.getTransport());

const path = [44, 118, 0, 0, 0];
let tx = JSON.stringify(example_tx_str_combined);

// get address / publickey
const respPk = await app.getAddressAndPubKey(path, "cosmos");
expect(respPk.return_code).toEqual(0x9000);
expect(respPk.error_message).toEqual("No errors");
console.log(respPk)

// do not wait here..
const signatureRequest = app.sign(path, tx);

await Zemu.sleep(2000);

// Reference window
await sim.snapshot(`${snapshotPrefixTmp}${snapshotCount++}.png`);
for (let i = 0; i < 10; i++) {
await sim.clickRight(Resolve(`${snapshotPrefixTmp}${snapshotCount++}.png`));
}
await sim.clickBoth();

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

compareSnapshots(snapshotPrefixTmp, snapshotPrefixGolden, snapshotCount);

expect(resp.return_code).toEqual(0x9000);
expect(resp.error_message).toEqual("No errors");

// Now verify the signature
const hash = crypto.createHash("sha256");
const msgHash = Uint8Array.from(hash.update(tx).digest());

const signatureDER = resp.signature;
const signature = secp256k1.signatureImport(Uint8Array.from(signatureDER));

const pk = Uint8Array.from(respPk.compressed_pk)

const signatureOk = secp256k1.ecdsaVerify(signature, msgHash, pk);
expect(signatureOk).toEqual(true);

} finally {
await sim.close();
}
});

it('show address and sign basic', async function () {
const snapshotPrefixGolden = "snapshots/show-address-and-sign-basic/";
const snapshotPrefixTmp = "snapshots-tmp/show-address-and-sign-basic/";
Expand Down
14 changes: 9 additions & 5 deletions tests_zemu/tools/debug.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@ const example_tx_str = {
{
"type": "cosmos-sdk/MsgWithdrawDelegationReward",
"value": {
"delegator_address": "cosmos1w34k53py5v5xyluazqpq65agyajavep2rflq6h",
"validator_address": "cosmosvaloper1kn3wugetjuy4zetlq6wadchfhvu3x740ae6z6x"
"delegator_address": "cosmos19umvgcvk8cxsvzemy239nj9ngc2ltukantgyp3",
"validator_address": "cosmosvaloper1648ynlpdw7fqa2axt0w2yp3fk542junl7rsvq6"
}
},
{
"type": "cosmos-sdk/MsgWithdrawDelegationReward",
"type": "cosmos-sdk/MsgDelegate",
"value": {
"delegator_address": "cosmos1w34k53py5v5xyluazqpq65agyajavep2rflq6h",
"validator_address": "cosmosvaloper1sjllsnramtg3ewxqwwrwjxfgc4n4ef9u2lcnj0"
"amount": {
"amount": "20139397",
"denom": "uatom"
},
"delegator_address": "cosmos19umvgcvk8cxsvzemy239nj9ngc2ltukantgyp3",
"validator_address": "cosmosvaloper1648ynlpdw7fqa2axt0w2yp3fk542junl7rsvq6",
}
}
],
Expand Down

0 comments on commit 26a785e

Please sign in to comment.