Skip to content

Commit 39666c7

Browse files
committed
fix tests
1 parent 4d91763 commit 39666c7

12 files changed

Lines changed: 148 additions & 120 deletions

File tree

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn main() {
3535
.unwrap();
3636

3737
let output = Command::new("git")
38-
.args(&["rev-parse", "HEAD"])
38+
.args(["rev-parse", "HEAD"])
3939
.output()
4040
.expect("Failed to execute git command");
4141

messages/src/lib.rs

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -269,19 +269,19 @@ pub struct GetPublicKeyResponse {
269269
}
270270

271271
#[derive(Encode, Decode)]
272-
pub struct Signature(pub [u8; 64]);
272+
pub struct SignatureResponse(pub [u8; 64]);
273273

274274
#[derive(Encode, Decode)]
275275
pub struct TxInputSignatureResponse {
276-
pub signature: Signature,
276+
pub signature: SignatureResponse,
277277
pub input_idx: u32,
278278
pub multisig_idx: Option<u32>,
279279
pub has_next: bool,
280280
}
281281

282282
#[derive(Encode, Decode)]
283283
pub struct MsgSignatureResponse {
284-
pub signature: Signature,
284+
pub signature: SignatureResponse,
285285
}
286286

287287
#[derive(Encode, Decode)]
@@ -416,54 +416,44 @@ pub enum StatusWord {
416416
// App Specific Errors (0xB...)
417417
#[display("Transaction display failed")]
418418
TxDisplayFail = 0xB000,
419-
#[display("Address display failed")]
420-
AddrDisplayFail = 0xB001,
419+
#[display("Transaction lock time value is invalid")]
420+
TxLockTimeInvalid = 0xB001,
421421
#[display("Transaction wrong length")]
422422
TxWrongLength = 0xB002,
423-
#[display("Transaction parsing failed")]
424-
TxParsingFail = 0xB003,
425423
#[display("Transaction hashing failed")]
426-
TxHashFail = 0xB004,
424+
TxHashFail = 0xB003,
427425
#[display("Transaction address failed")]
428-
TxAddressFail = 0xB005,
429-
#[display("Transaction signing failed")]
430-
TxSignFail = 0xB006,
426+
TxAddressFail = 0xB004,
427+
#[display("Different instruction than expected")]
428+
WrongInstruction = 0xB005,
431429
#[display("Key derivation failed")]
432-
KeyDeriveFail = 0xB007,
433-
#[display("Version parsing failed")]
434-
VersionParsingFail = 0xB008,
430+
KeyDeriveFail = 0xB006,
431+
#[display("Orders V0 not supported")]
432+
OrdersV0NotSupported = 0xB007,
435433
#[display("Wrong context")]
436-
WrongContext = 0xB009,
434+
WrongContext = 0xB008,
437435
#[display("Deserialization failed")]
438-
DeserializeFail = 0xB00A,
436+
DeserializeFail = 0xB009,
439437
#[display("Invalid input UTXO")]
440-
TxInvalidInputUtxo = 0xB00B,
438+
TxInvalidInputUtxo = 0xB00A,
441439
#[display("Numeric operation failed")]
442-
TxNumericOperationFail = 0xB00C,
440+
TxNumericOperationFail = 0xB00B,
443441
#[display("Tx fee underflow")]
444-
TxFeeUnderflow = 0xB00D,
445-
#[display("Unsupported input")]
446-
TxUnsupportedInput = 0xB00E,
447-
#[display("Invalid Token V0")]
448-
TxInvalidTokenV0 = 0xB00F,
442+
TxFeeUnderflow = 0xB00C,
449443
#[display("Invalid input path")]
450-
TxInvalidInputPath = 0xB010,
444+
TxInvalidInputPath = 0xB00D,
451445
#[display("Nothing to sign")]
452-
NothingToSign = 0xB011,
446+
NothingToSign = 0xB00E,
453447
#[display("Transaction already finished")]
454-
TxAlreadyFinished = 0xB012,
448+
TxAlreadyFinished = 0xB00F,
455449
#[display("Invalid path")]
456-
InvalidPath = 0xB013,
450+
InvalidPath = 0xB010,
457451
#[display("Invalid uncompressed public key")]
458-
InvalidUncompressedPublicKey = 0xB014,
452+
InvalidUncompressedPublicKey = 0xB011,
459453
#[display("Max buffer length exceeded")]
460-
MaxBufferLenExceeded = 0xB015,
454+
MaxBufferLenExceeded = 0xB012,
461455
#[display("Different input commitment hash")]
462-
DifferentInputCommitmentHash = 0xB016,
463-
#[display("Orders V0 not supported")]
464-
OrdersV0NotSupported = 0xB017,
465-
#[display("Different instruction than expected")]
466-
WrongInstruction = 0xB018,
456+
DifferentInputCommitmentHash = 0xB013,
467457

468458
// Ecc Errors
469459
#[display("ECC Carry")]

src/handlers/sign_message.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::{
2020
DataContext, StatusWord,
2121
};
2222
use messages::{
23-
mlcp::CoinType, AddrType, Bip32Path, MsgSignatureResponse, SignMessageReq, Signature,
23+
mlcp::CoinType, AddrType, Bip32Path, MsgSignatureResponse, SignMessageReq, SignatureResponse,
2424
};
2525

2626
use alloc::vec::Vec;
@@ -49,20 +49,14 @@ impl SignMessageContext {
4949
}
5050
}
5151

52-
pub fn setup_sign_message(req: SignMessageReq, ctx: &mut DataContext) -> Result<(), StatusWord> {
53-
*ctx = DataContext::SignMessageContext(SignMessageContext::new(req));
54-
Ok(())
52+
pub fn setup_sign_message(req: SignMessageReq) -> DataContext {
53+
DataContext::SignMessageContext(SignMessageContext::new(req))
5554
}
5655

5756
pub fn handle_sign_message(
5857
message: &[u8],
59-
ctx: &mut DataContext,
58+
ctx: &mut SignMessageContext,
6059
) -> Result<MsgSignatureResponse, StatusWord> {
61-
let ctx = match ctx {
62-
DataContext::SignMessageContext(ctx) => ctx,
63-
_ => return Err(StatusWord::WrongContext),
64-
};
65-
6660
let private_key = Secp256k1::derive_from_path(ctx.path.as_ref());
6761
let public_key = private_key
6862
.public_key()
@@ -100,7 +94,7 @@ fn compute_signature<const N: usize>(
10094
let sig = schnorr_sign(private_key, message_hash2.as_bytes())?;
10195

10296
let response = MsgSignatureResponse {
103-
signature: Signature(sig),
97+
signature: SignatureResponse(sig),
10498
};
10599

106100
Ok(response)

src/handlers/sign_tx/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::{
2929
use messages::{
3030
encode_as_compact, encode_to,
3131
mlcp::{Amount, CoinType as PCoinType, SighashInputCommitment, TxOutput, H256},
32-
CoinType, Encode, InputAddressPath, Response, SignTxReq, Signature, TxInputReq,
32+
CoinType, Encode, InputAddressPath, Response, SignTxReq, SignatureResponse, TxInputReq,
3333
TxInputSignatureResponse, TxMetadataReq, TxMetadataV1Req, TxMetadataVersionReq, TxOutputReq,
3434
};
3535

@@ -467,7 +467,7 @@ pub fn handle_sign_tx(req: SignTxReq, ctx: &mut TxContext) -> Result<Response, S
467467
(SignTxReq::NextSignature, TxParsingState::Finished) => {
468468
return Err(StatusWord::TxAlreadyFinished)
469469
}
470-
(_, _) => return Err(StatusWord::WrongP1P2),
470+
(_, _) => return Err(StatusWord::WrongContext),
471471
};
472472

473473
match signing_state {
@@ -545,7 +545,7 @@ fn compute_signature_and_append(
545545
let private_key = Secp256k1::derive_from_path(&addr);
546546
let sig = schnorr_sign(&private_key, sighash.as_bytes())?;
547547

548-
let signature = Signature(sig);
548+
let signature = SignatureResponse(sig);
549549
let input_idx = address.input_idx;
550550
let multisig_idx = address.multisig_idx;
551551

src/handlers/sign_tx/summary_collector.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl TxSummaryCollector {
185185
| TxOutput::LockThenTransfer(value, _, _)
186186
| TxOutput::Htlc(value, _) => {
187187
let (coin_or_token_id, amount) =
188-
into_coin_or_token_id_and_amount(&value)?;
188+
into_coin_or_token_id_and_amount(value)?;
189189
self.increase_input_totals(coin_or_token_id, amount)?;
190190
}
191191
TxOutput::Burn(_)
@@ -259,9 +259,9 @@ impl TxSummaryCollector {
259259
match cmd {
260260
OrderAccountCommand::FillOrder(_, fill_amount) => {
261261
let (fill_coin_or_token_id, asked_amount) =
262-
into_coin_or_token_id_and_amount(&initially_asked)?;
262+
into_coin_or_token_id_and_amount(initially_asked)?;
263263
let (given_coin_or_token_id, given_amount) =
264-
into_coin_or_token_id_and_amount(&initially_given)?;
264+
into_coin_or_token_id_and_amount(initially_given)?;
265265

266266
self.increase_output_totals(fill_coin_or_token_id, *fill_amount)?;
267267

@@ -278,11 +278,11 @@ impl TxSummaryCollector {
278278
}
279279
OrderAccountCommand::ConcludeOrder(_) => {
280280
let (coin_or_token_id, _) =
281-
into_coin_or_token_id_and_amount(&initially_asked)?;
281+
into_coin_or_token_id_and_amount(initially_asked)?;
282282
self.increase_input_totals(coin_or_token_id, *ask_balance)?;
283283

284284
let (coin_or_token_id, _) =
285-
into_coin_or_token_id_and_amount(&initially_given)?;
285+
into_coin_or_token_id_and_amount(initially_given)?;
286286
self.increase_input_totals(coin_or_token_id, *give_balance)?;
287287

288288
self.tx_type = merge_tx_type(self.tx_type, TxType::ConcludeOrder);

tests/application_client/__init__.py

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,15 +392,26 @@ def init_mintlayer_types():
392392
["signature", "Signature"],
393393
],
394394
},
395-
"TxMetadataReq": {
395+
"TxMetadataVersionReq": {
396+
"type": "enum",
397+
"type_mapping": [
398+
["V1", "TxMetadataV1Req"],
399+
],
400+
},
401+
"TxMetadataV1Req": {
396402
"type": "struct",
397403
"type_mapping": [
398-
["coin", "u8"],
399-
["version", "u8"],
400404
["num_inputs", "u32"],
401405
["num_outputs", "u32"],
402406
],
403407
},
408+
"TxMetadataReq": {
409+
"type": "struct",
410+
"type_mapping": [
411+
["coin", "u8"],
412+
["version", "TxMetadataVersionReq"],
413+
],
414+
},
404415
"TxInputReq": {
405416
"type": "struct",
406417
"type_mapping": [
@@ -442,17 +453,48 @@ def init_mintlayer_types():
442453
["NextSignature", "()"],
443454
],
444455
},
456+
"SignatureResponse": "[u8; 64]",
445457
"MsgSignature": {
446458
"type": "struct",
447459
"type_mapping": [
448-
["signature", "[u8; 64]"],
460+
["signature", "SignatureResponse"],
449461
],
450462
},
463+
"TxInputSignatureResponse": {
464+
"type": "struct",
465+
"type_mapping": [
466+
["signature", "SignatureResponse"],
467+
["input_idx", "u32"],
468+
["multisig_idx", "Option<u32>"],
469+
["has_next", "bool"],
470+
],
471+
},
472+
"PublicKeyResponse": "[u8; 65]",
473+
"ChainCodeResponse": "[u8; 32]",
451474
"GetPublicKeyResponse": {
452475
"type": "struct",
453476
"type_mapping": [
454-
["public_key", "[u8; 65]"],
455-
["chain_code", "[u8; 32]"],
477+
["public_key", "PublicKeyResponse"],
478+
["chain_code", "ChainCodeResponse"],
479+
],
480+
},
481+
"MsgSignatureResponse": {
482+
"type": "struct",
483+
"type_mapping": [
484+
["signature", "SignatureResponse"],
485+
],
486+
},
487+
"Response": {
488+
"type": "enum",
489+
"type_mapping": [
490+
["ExpectingNextChunk", "()"],
491+
["PublicKey", "GetPublicKeyResponse"],
492+
["TxSetup", "()"],
493+
["TxNext", "()"],
494+
["TxSignature", "TxInputSignatureResponse"],
495+
["MessageSetup", "()"],
496+
["MessageSignature", "MsgSignatureResponse"],
497+
["Pong", "()"],
456498
],
457499
},
458500
"SemVer": {

0 commit comments

Comments
 (0)