Skip to content

Commit 55badf3

Browse files
committed
fix tests
1 parent deaa943 commit 55badf3

539 files changed

Lines changed: 266 additions & 370 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/app_ui/sign.rs

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ use crate::{
2929
use messages::{
3030
encode,
3131
mlcp::{
32-
AccountCommand, Amount, CoinType, Destination, IsTokenFreezable, IsTokenUnfreezable,
33-
NftIssuance, OrderAccountCommand, OutputTimeLock, OutputValue, PublicKey, TokenIssuance,
34-
TokenTotalSupply, TxOutput, VrfPublicKey, H256,
32+
AccountCommand, AccountSpending, Amount, CoinType, Destination, IsTokenFreezable,
33+
IsTokenUnfreezable, NftIssuance, OrderAccountCommand, OutputTimeLock, OutputValue,
34+
PublicKey, TokenIssuance, TokenTotalSupply, TxOutput, VrfPublicKey, H256,
3535
},
3636
AddrType,
3737
};
@@ -104,14 +104,9 @@ pub fn ui_streaming_review_show_output(
104104

105105
pub fn ui_approve_streaming_review(
106106
review: &NbglStreamingReview,
107-
output: &TxOutput,
108107
ctx: &TxParsingOutputsContext,
109108
) -> Result<bool, StatusWord> {
110109
let coin = ctx.coin();
111-
if !ui_streaming_review_show_output(review, output, coin)? {
112-
return Ok(false);
113-
}
114-
115110
let fees = ctx.summary().fees_iter().try_fold(
116111
String::new(),
117112
|mut acc, res| -> Result<_, StatusWord> {
@@ -473,6 +468,20 @@ fn format_output(output: &TxOutput, coin: CoinType) -> Result<FormatedOutput, St
473468

474469
fn format_input(input: &InputCommand, coin: CoinType) -> Result<FormatedOutput, StatusWord> {
475470
let (name, value) = match input {
471+
InputCommand::AccountSpending(cmd) => match cmd {
472+
AccountSpending::DelegationBalance(delegation_id, amount) => {
473+
let address_short = format!(
474+
"Delegation ID: {}\nAmount: {}",
475+
id_to_address(delegation_id.hash(), coin.delegation_id_address_prefix())?,
476+
format_amount(*amount, coin)
477+
);
478+
if cfg!(any(target_os = "nanosplus", target_os = "nanox")) {
479+
("Del Wdrwl", address_short)
480+
} else {
481+
("Delegation withdrawl", address_short)
482+
}
483+
}
484+
},
476485
InputCommand::AccountCommand(cmd) => match cmd {
477486
AccountCommand::MintTokens(token_id, amount) => {
478487
let address_short = format!(
@@ -494,7 +503,11 @@ fn format_input(input: &InputCommand, coin: CoinType) -> Result<FormatedOutput,
494503
"Token ID: {}",
495504
id_to_address(token_id.hash(), coin.token_id_address_prefix())?
496505
);
497-
("Lock token supply", address_short)
506+
if cfg!(any(target_os = "nanosplus", target_os = "nanox")) {
507+
("Lock token", address_short)
508+
} else {
509+
("Lock token supply", address_short)
510+
}
498511
}
499512
AccountCommand::FreezeToken(token_id, is_unfreezable) => {
500513
let address_short = format!(
@@ -513,23 +526,35 @@ fn format_input(input: &InputCommand, coin: CoinType) -> Result<FormatedOutput,
513526
"Token ID: {}",
514527
id_to_address(token_id.hash(), coin.token_id_address_prefix())?,
515528
);
516-
("Unfreeze token", address_short)
529+
if cfg!(any(target_os = "nanosplus", target_os = "nanox")) {
530+
("Unfrz token", address_short)
531+
} else {
532+
("Unfreeze token", address_short)
533+
}
517534
}
518535
AccountCommand::ChangeTokenAuthority(token_id, new_authority) => {
519536
let address_short = format!(
520537
"Token ID: {}\nNew authority: {}",
521538
id_to_address(token_id.hash(), coin.token_id_address_prefix())?,
522539
to_address(new_authority, coin)?
523540
);
524-
("Change token authority", address_short)
541+
if cfg!(any(target_os = "nanosplus", target_os = "nanox")) {
542+
("Chg token auth", address_short)
543+
} else {
544+
("Change token authority", address_short)
545+
}
525546
}
526547
AccountCommand::ChangeTokenMetadataUri(token_id, new_metadata_uri) => {
527548
let address_short = format!(
528549
"Token ID: {}\nNew metadata URI: {}",
529550
id_to_address(token_id.hash(), coin.token_id_address_prefix())?,
530551
String::from_utf8_lossy(new_metadata_uri)
531552
);
532-
("Change token metadata URI", address_short)
553+
if cfg!(any(target_os = "nanosplus", target_os = "nanox")) {
554+
("Chg token meta", address_short)
555+
} else {
556+
("Change token metadata URI", address_short)
557+
}
533558
}
534559
AccountCommand::ConcludeOrder(_) | AccountCommand::FillOrder(_, _, _) => {
535560
return Err(StatusWord::OrdersV0NotSupported)
@@ -556,7 +581,11 @@ fn format_input(input: &InputCommand, coin: CoinType) -> Result<FormatedOutput,
556581
"Order ID: {}",
557582
id_to_address(order_id.hash(), coin.order_id_address_prefix())?
558583
);
559-
("Conclude order", address_short)
584+
if cfg!(any(target_os = "nanosplus", target_os = "nanox")) {
585+
("Conclude ord", address_short)
586+
} else {
587+
("Conclude order", address_short)
588+
}
560589
}
561590
},
562591
};

src/handlers/sign_tx/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::{
3030
};
3131
use messages::{
3232
encode_as_compact, encode_to,
33-
mlcp::{CoinType as PCoinType, SighashInputCommitment, TxOutput, H256},
33+
mlcp::{CoinType as PCoinType, SighashInputCommitment, H256},
3434
CoinType, Encode, InputAddressPath, Response, SignTxReq, SignatureResponse, TxInputReq,
3535
TxInputSignatureResponse, TxMetadataReq, TxMetadataV1Req, TxMetadataVersionReq, TxOutputReq,
3636
};
@@ -202,7 +202,7 @@ impl TxParsingInputsContext {
202202
summary: self.summary,
203203
inputs: self.inputs,
204204
spinner: self.spinner,
205-
num_inputs_parsed: self.num_inputs_parsed,
205+
num_inputs_parsed: 0,
206206
},
207207
))
208208
} else {
@@ -236,7 +236,6 @@ impl TxParsingOutputsContext {
236236
fn advance_next_output_state(
237237
mut self,
238238
review: &NbglStreamingReview,
239-
output: &TxOutput,
240239
) -> Result<TxParsingContext, StatusWord> {
241240
if self.num_outputs_parsed < (self.metadata.num_outputs - 1) {
242241
self.num_outputs_parsed += 1;
@@ -250,7 +249,7 @@ impl TxParsingOutputsContext {
250249

251250
let tx_hash = mintlayer_hash(&message_hash[0..32])?;
252251

253-
if ui_approve_streaming_review(review, output, &self)? {
252+
if ui_approve_streaming_review(review, &self)? {
254253
Ok(TxParsingContext::Signing(TxSigningContext {
255254
metadata: self.metadata,
256255
inputs: self.inputs,
@@ -441,7 +440,7 @@ fn handle_output_req(
441440
if ui_streaming_review_show_output(review, &req.out, ctx.metadata.coin)? {
442441
ctx.summary.process_output(&req.out)?;
443442
update_hash(&req.out, &mut ctx.tx_hasher)?;
444-
ctx.advance_next_output_state(review, &req.out)
443+
ctx.advance_next_output_state(review)
445444
} else {
446445
Err(StatusWord::Deny)
447446
}

src/handlers/sign_tx/summary_collector.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub enum TxType {
5959
}
6060

6161
pub enum InputCommand {
62+
AccountSpending(AccountSpending),
6263
AccountCommand(AccountCommand),
6364
OrderCommand(OrderAccountCommand),
6465
}
@@ -207,10 +208,13 @@ impl TxSummaryCollector {
207208
};
208209
}
209210
},
210-
TxInputWithAdditionalInfo::Account(acc) => match acc.spending {
211-
AccountSpending::DelegationBalance(_, amount) => {
212-
self.tx_type = merge_tx_type(self.tx_type, TxType::DelegationWithdrawl);
213-
self.increase_input_totals(CoinOrTokenId::Coin, amount)?;
211+
TxInputWithAdditionalInfo::Account(acc) => {
212+
self.input_command = Some(InputCommand::AccountSpending(acc.spending.clone()));
213+
match acc.spending {
214+
AccountSpending::DelegationBalance(_, amount) => {
215+
self.tx_type = merge_tx_type(self.tx_type, TxType::DelegationWithdrawl);
216+
self.increase_input_totals(CoinOrTokenId::Coin, amount)?;
217+
}
214218
}
215219
},
216220
TxInputWithAdditionalInfo::AccountCommand(_, cmd) => {

src/main.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,13 @@ fn handle_command(cmd: &Command, ctx: &mut AppContext) -> Result<Response, Statu
303303
Ok(Response::TxSetup)
304304
}
305305
SignP1::Next => {
306-
let req = decode_all(data).ok_or(StatusWord::DeserializeFail)?;
307-
308306
let (mut tx_ctx, mut review) = match ctx.data_context.take() {
309307
Some(DataContext::TxContext(c, r)) => (c, r),
310308
_ => return Err(StatusWord::WrongContext),
311309
};
312310

311+
let req = decode_all(data).ok_or(StatusWord::DeserializeFail)?;
312+
313313
tx_ctx.show_spinner();
314314

315315
match handle_sign_tx(req, *tx_ctx, &mut review) {
@@ -335,7 +335,8 @@ fn handle_command(cmd: &Command, ctx: &mut AppContext) -> Result<Response, Statu
335335
Some(DataContext::SignMessageContext(ctx)) => ctx,
336336
_ => return Err(StatusWord::WrongContext),
337337
};
338-
handle_sign_message(data, msg_ctx).map(Response::MessageSignature)
338+
let response = handle_sign_message(data, msg_ctx).map(Response::MessageSignature);
339+
response
339340
}
340341
},
341342
Command::Ping => Ok(Response::Pong),

0 commit comments

Comments
 (0)