Skip to content

Commit 50f2597

Browse files
committed
rust/bitcoin: negative address_simple tests
With the negative tests added, the Rust unit tests fully replace the C unit tests.
1 parent 76a4713 commit 50f2597

File tree

3 files changed

+25
-195
lines changed

3 files changed

+25
-195
lines changed

src/rust/bitbox02-rust/src/hww/api/bitcoin.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,5 +385,30 @@ mod tests {
385385
}))),
386386
);
387387
}
388+
389+
// --- Negative tests
390+
mock_unlocked();
391+
// First check a valid request:
392+
let req = pb::BtcPubRequest {
393+
coin: BtcCoin::Btc as _,
394+
keypath: [49 + HARDENED, 0 + HARDENED, 1 + HARDENED, 1, 100].to_vec(),
395+
display: false,
396+
output: Some(Output::ScriptConfig(BtcScriptConfig {
397+
config: Some(Config::SimpleType(SimpleType::P2wpkhP2sh as _)),
398+
})),
399+
};
400+
assert!(block_on(process_pub(&req)).unwrap().is_ok());
401+
// -- Wrong coin: MIN-1
402+
let mut req_invalid = req.clone();
403+
req_invalid.coin = BtcCoin::Btc as i32 - 1;
404+
assert!(block_on(process_pub(&req_invalid)).unwrap().is_err());
405+
// -- Wrong coin: MAX + 1
406+
let mut req_invalid = req.clone();
407+
req_invalid.coin = BtcCoin::Tltc as i32 + 1;
408+
assert!(block_on(process_pub(&req_invalid)).unwrap().is_err());
409+
// -- Wrong keypath
410+
let mut req_invalid = req.clone();
411+
req_invalid.keypath = [49 + HARDENED, 0 + HARDENED, 1 + HARDENED, 1, 10000].to_vec();
412+
assert!(block_on(process_pub(&req_invalid)).unwrap().is_err());
388413
}
389414
}

test/unit-test/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,6 @@ set(TEST_LIST
227227
"-Wl,--wrap=rand,--wrap=wally_sha256"
228228
apps_common_bip32
229229
""
230-
app_btc
231-
"-Wl,--wrap=keystore_secp256k1_pubkey_hash160,--wrap=btc_common_is_valid_keypath_address_simple,--wrap=btc_common_outputhash_from_pubkeyhash"
232230
app_btc_multisig
233231
"-Wl,--wrap=memory_multisig_get_by_hash,--wrap=apps_btc_confirm_multisig_basic"
234232
app_btc_common

test/unit-test/test_app_btc.c

Lines changed: 0 additions & 193 deletions
This file was deleted.

0 commit comments

Comments
 (0)