Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
Allow set-payee on both validator and stack keys (#21)
Browse files Browse the repository at this point in the history
* Allow set-payee on both validator and stack keys

* bump version number

* updating tests and polkadot.js
  • Loading branch information
jleni authored Jun 22, 2020
1 parent 9027636 commit 5767c8a
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
APPVERSION_M=1
APPVERSION_N=2011
APPVERSION_P=0
APPVERSION_P=1
25 changes: 17 additions & 8 deletions app/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![no_std]
#![no_builtins]

#![allow(dead_code, unused_imports)]

#[cfg(test)]
Expand All @@ -13,21 +12,25 @@ extern crate core;

fn debug(_msg: &str) {}

use core::convert::TryInto;
use core::mem;
#[cfg(not(test))]
use core::panic::PanicInfo;
use core::mem;
use core::convert::TryInto;
use sha2::{Sha256, Digest, Sha512Trunc256};
use sha2::{Digest, Sha256, Sha512Trunc256};

#[cfg(not(test))]
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}


#[no_mangle]
pub extern "C" fn rs_sha512_256(input_ptr: *const u8, input_size: usize, output_ptr: *const u8, output_size: usize) -> i8 {
pub extern "C" fn rs_sha512_256(
input_ptr: *const u8,
input_size: usize,
output_ptr: *const u8,
output_size: usize,
) -> i8 {
if output_size != 32 {
return -1;
}
Expand Down Expand Up @@ -55,7 +58,10 @@ mod tests {
hasher.input(b"Zondax");
let result = hasher.result();

assert_eq!(result[..], hex!("3d119a287af12a4a1f263803f18a674f200d86e07954286dfe33cad245fe1be9")[..]);
assert_eq!(
result[..],
hex!("3d119a287af12a4a1f263803f18a674f200d86e07954286dfe33cad245fe1be9")[..]
);
}

#[test]
Expand All @@ -65,6 +71,9 @@ mod tests {

rs_sha512_256(data.as_ptr(), data.len(), result.as_ptr(), result.len());

assert_eq!(result[..], hex!("3d119a287af12a4a1f263803f18a674f200d86e07954286dfe33cad245fe1be9")[..]);
assert_eq!(
result[..],
hex!("3d119a287af12a4a1f263803f18a674f200d86e07954286dfe33cad245fe1be9")[..]
);
}
}
5 changes: 4 additions & 1 deletion app/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ parser_error_t parser_validate(const parser_context_t *ctx) {
return parser_ok;
}
if (parser_tx_obj.callIndex.idx==PD_CALL_STAKING_NOMINATE) {
// FIXME: Check whitelist
// FIXME: Check allowlist
return parser_ok;
}
}
}
if (hdPath[2] == HDPATH_2_VALIDATOR) {
if (parser_tx_obj.callIndex.moduleIdx == PD_CALL_STAKING) {
if (parser_tx_obj.callIndex.idx==PD_CALL_STAKING_SET_PAYEE) {
return parser_ok;
}
if (parser_tx_obj.callIndex.idx==PD_CALL_STAKING_VALIDATE) {
return parser_ok;
}
Expand Down
22 changes: 11 additions & 11 deletions tests_zemu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@
"zondax"
],
"dependencies": {
"@zondax/ledger-polkadot": "^0.9.2",
"@zondax/ledger-polkadot": "^0.10.4",
"@zondax/zemu": "^0.2"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.0",
"@babel/node": "^7.8.7",
"@babel/plugin-transform-runtime": "^7.9.0",
"@babel/preset-env": "^7.9.5",
"@babel/cli": "^7.10.3",
"@babel/core": "^7.10.3",
"@babel/node": "^7.10.3",
"@babel/plugin-transform-runtime": "^7.10.3",
"@babel/preset-env": "^7.10.3",
"babel-eslint": "^10.1.0",
"babel-jest": "26.0.1",
"blakejs": "^1.1.0",
"crypto-js": "4.0.0",
"ed25519-supercop": "^1.2.0",
"eslint": "^7.2.0",
"eslint": "^7.3.0",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-config-prettier": "^6.10.1",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.21.2",
"eslint-plugin-jest": "^23.8.2",
"eslint-plugin-jest": "^23.16.0",
"eslint-plugin-prettier": "^3.1.4",
"jest": "26.0.1",
"jest-serial-runner": "^1.1.0 "
"jest": "^26.0.1",
"jest-serial-runner": "^1.1.0"
}
}
15 changes: 8 additions & 7 deletions tests_zemu/tests/test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { expect, test } from "jest";
import {expect, test} from "jest";
import Zemu from "@zondax/zemu";
import LedgerApp from "@zondax/ledger-polkadot";
import { blake2bInit, blake2bUpdate, blake2bFinal } from "blakejs";
import {blake2bInit, blake2bUpdate, blake2bFinal} from "blakejs";

const ed25519 = require("ed25519-supercop");
const {newKusamaApp} = require("@zondax/ledger-polkadot");

const Resolve = require("path").resolve;
const APP_PATH = Resolve("../app/bin/app.elf");
Expand Down Expand Up @@ -39,7 +40,7 @@ describe('Basic checks', function () {
const sim = new Zemu(APP_PATH);
try {
await sim.start(sim_options);
const app = new LedgerApp(sim.getTransport());
const app = newKusamaApp(sim.getTransport());
const resp = await app.getVersion();

console.log(resp);
Expand All @@ -59,7 +60,7 @@ describe('Basic checks', function () {
const sim = new Zemu(APP_PATH);
try {
await sim.start(sim_options);
const app = new LedgerApp(sim.getTransport());
const app = newKusamaApp(sim.getTransport());

// FIXME: Zemu/Speculos are enforcing fully hardened paths
const resp = await app.getAddress(0x80000000, 0x80000000, 0x80000000);
Expand Down Expand Up @@ -88,7 +89,7 @@ describe('Basic checks', function () {
const sim = new Zemu(APP_PATH);
try {
await sim.start(sim_options);
const app = new LedgerApp(sim.getTransport());
const app = newKusamaApp(sim.getTransport());

const respRequest = app.getAddress(0x80000000, 0x80000000, 0x80000000, true);

Expand Down Expand Up @@ -130,7 +131,7 @@ describe('Basic checks', function () {
const sim = new Zemu(APP_PATH);
try {
await sim.start(sim_options);
const app = new LedgerApp(sim.getTransport());
const app = newKusamaApp(sim.getTransport());
const pathAccount = 0x80000000;
const pathChange = 0x80000000;
const pathIndex = 0x80000000;
Expand Down
5 changes: 3 additions & 2 deletions tests_zemu/tools/debug.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Zemu from "@zondax/zemu";
import LedgerApp from "@zondax/ledger-polkadot";
import path from "path";

const {newKusamaApp} = require("@zondax/ledger-polkadot");

const APP_PATH = path.resolve(`./../../app/bin/app.elf`);

const seed = "equip will roof matter pink blind book anxiety banner elbow sun young"
Expand Down Expand Up @@ -76,7 +77,7 @@ async function main() {

try {
await sim.start(SIM_OPTIONS);
const app = new LedgerApp.default(sim.getTransport());
const app = newKusamaApp(sim.getTransport());

////////////
/// TIP you can use zemu commands here to take the app to the point where you trigger a breakpoint
Expand Down

0 comments on commit 5767c8a

Please sign in to comment.