fix early proof export and slatepack account errors

This commit is contained in:
wiesche
2026-09-15 20:28:20 +02:00
parent 049e73ac07
commit a1d683294b
10 changed files with 290 additions and 32 deletions
@@ -240,6 +240,49 @@ fn contract_early_proofs_srs_test_impl(test_dir: &'static str) -> Result<(), lib
},
)?;
// export and verify through the CLI
let proof_file = format!("{}/early_proof.json", test_dir);
let tampered_file = format!("{}/early_proof_tampered.json", test_dir);
wallet::controller::owner_single_use(
send_wallet.clone(),
send_mask,
PathBuf::from(test_dir),
|api, m| {
wallet::command::proof_export(
api,
m,
wallet::command::ProofExportArgs {
output_file: proof_file.clone(),
id: None,
tx_slate_id: Some(slate.id),
},
)
.map_err(|e| libwallet::Error::GenericError(e.to_string()))?;
wallet::command::proof_verify(
api,
m,
wallet::command::ProofVerifyArgs {
input_file: proof_file.clone(),
},
)
.map_err(|e| libwallet::Error::GenericError(e.to_string()))?;
// tweak the amount and it shouldn't verify
let mut tampered: serde_json::Value =
serde_json::from_str(&std::fs::read_to_string(&proof_file).unwrap()).unwrap();
tampered["proof"]["amount"] = serde_json::Value::from("400000");
std::fs::write(&tampered_file, tampered.to_string()).unwrap();
let retval = wallet::command::proof_verify(
api,
m,
wallet::command::ProofVerifyArgs {
input_file: tampered_file.clone(),
},
);
assert!(retval.is_err());
Ok(())
},
)?;
// let logging finish
stopper.store(false, Ordering::Relaxed);
thread::sleep(Duration::from_millis(200));
+2
View File
@@ -224,6 +224,7 @@ fn contract_rsr_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
assert_eq!(txs.len(), 5); // 4 mined and 1 received
let tx_log = common::tx_log_for_slate(api, m, &slate)?;
assert_eq!(tx_log.tx_type, TxLogEntryType::TxReceived);
assert_eq!(tx_log.tx_slate_state, Some(SlateState::Invoice3));
assert_eq!(tx_log.amount_credited, 5_000_000_000);
assert_eq!(tx_log.amount_debited, 0);
assert_eq!(tx_log.num_inputs, 1);
@@ -251,6 +252,7 @@ fn contract_rsr_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
assert_eq!(txs.len() as u64, bh - 4 + 1); // send_wallet didn't mine 4 blocks and made 1 tx
let tx_log = common::tx_log_for_slate(api, m, &slate)?;
assert_eq!(tx_log.tx_type, TxLogEntryType::TxSent);
assert_eq!(tx_log.tx_slate_state, Some(SlateState::Invoice2));
assert_eq!(tx_log.amount_credited, 0);
assert_eq!(tx_log.amount_debited, 5_000_000_000);
assert_eq!(tx_log.num_inputs, 1);
+2
View File
@@ -631,6 +631,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
assert_eq!(txs.len(), 5); // 4 mined and 1 received
let tx_log = common::tx_log_for_slate(api, m, &slate)?;
assert_eq!(tx_log.tx_type, TxLogEntryType::TxReceived);
assert_eq!(tx_log.tx_slate_state, Some(SlateState::Standard2));
assert_eq!(tx_log.amount_credited, 5_000_000_000);
assert_eq!(tx_log.amount_debited, 0);
assert_eq!(tx_log.num_inputs, 1);
@@ -657,6 +658,7 @@ fn contract_srs_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error>
assert_eq!(txs.len() as u64, bh - 4 + 1); // send wallet didn't mine 4 blocks and made 1 tx
let tx_log = common::tx_log_for_slate(api, m, &slate)?;
assert_eq!(tx_log.tx_type, TxLogEntryType::TxSent);
assert_eq!(tx_log.tx_slate_state, Some(SlateState::Standard3));
assert_eq!(tx_log.amount_credited, 0);
assert_eq!(tx_log.amount_debited, 5_000_000_000);
assert_eq!(tx_log.num_inputs, 1);
+11
View File
@@ -609,6 +609,17 @@ fn slatepack_api_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
println!("{}", slatepack_raw);
let decoded_slate = api.slate_from_slatepack_message(m, slatepack, vec![0])?;
println!("{}", decoded_slate);
// wrong active account, the error names the right one
let own_address = api.get_slatepack_address(m, 0)?;
let own_slatepack =
api.create_slatepack_message(m, &slate, Some(0), vec![own_address])?;
api.create_account_path(m, "second")?;
api.set_active_account(m, "second")?;
let err = api
.slate_from_slatepack_message(m, own_slatepack, vec![0])
.unwrap_err();
assert!(err.to_string().contains("account 'default'"), "{}", err);
api.set_active_account(m, "default")?;
Ok(())
},
)?;