Wrong Slatepack address fix (#773)

This commit is contained in:
ardocrat
2026-08-09 19:49:29 +02:00
committed by wiesche
parent 9e3ec0ed5b
commit a3fb40caac
12 changed files with 338 additions and 110 deletions
+1 -1
View File
@@ -129,7 +129,7 @@ fn send_preflight() {
let args = InitTxArgs {
amount: 1,
send_args: Some(InitTxSendArgs {
dest: "unused".into(),
dest: "tgrin1xtxavwfgs48ckf3gk8wwgcndmn0nt4tvkl8a7ltyejjcy2mc6nfs9gm2lp".into(),
post_tx: false,
fluff: false,
skip_tor: Some(true),
+117 -2
View File
@@ -18,6 +18,7 @@ extern crate grin_wallet_controller as wallet;
extern crate grin_wallet_impls as impls;
use grin_core as core;
use grin_wallet_config::GlobalWalletConfig;
use grin_wallet_libwallet as libwallet;
use std::path::PathBuf;
@@ -28,8 +29,8 @@ use std::thread;
use std::time::Duration;
use grin_wallet_libwallet::{
InitTxArgs, IssueInvoiceTxArgs, Slate, Slatepack, SlatepackAddress, Slatepacker,
SlatepackerArgs,
InitTxArgs, InitTxSendArgs, IssueInvoiceTxArgs, Slate, Slatepack, SlatepackAddress,
Slatepacker, SlatepackerArgs,
};
use ed25519_dalek::SigningKey as edDalekSecretKey;
@@ -601,6 +602,110 @@ fn slatepack_api_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
Ok(())
}
/// Do not create transaction for invalid or wrong network Slatepack address.
fn slatepack_address_validation(test_dir: &'static str) -> Result<(), libwallet::Error> {
let mut wallet_proxy = create_wallet_proxy(test_dir);
let chain = wallet_proxy.chain.clone();
let stopper = wallet_proxy.running.clone();
let config_path = PathBuf::from(test_dir).join("grin-wallet.toml");
GlobalWalletConfig::for_chain(&core::global::ChainTypes::AutomatedTesting, &config_path)
.write_to_file(config_path.to_str().unwrap(), false, None, None)
.unwrap();
create_wallet_and_add!(
client1,
wallet1,
mask1_i,
test_dir,
"wallet1",
None,
&mut wallet_proxy,
false
);
let mask1 = (&mask1_i).as_ref();
create_wallet_and_add!(
client2,
wallet2,
mask2_i,
test_dir,
"wallet2",
None,
&mut wallet_proxy,
false
);
let mask2 = (&mask2_i).as_ref();
let proxy_thread = thread::spawn(move || {
if let Err(e) = wallet_proxy.run() {
error!("Wallet Proxy error: {}", e);
}
});
let reward = core::consensus::REWARD;
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 6, false);
let mut slate = Slate::blank(2, true);
wallet::controller::owner_single_use(wallet2.clone(), mask2, config_path.clone(), |api, m| {
slate = api.issue_invoice_tx(
m,
IssueInvoiceTxArgs {
amount: reward,
..Default::default()
},
)?;
Ok(())
})?;
wallet::controller::owner_single_use(wallet1.clone(), mask1, config_path, |api, m| {
let args = InitTxArgs {
src_acct_name: Some("mining".to_owned()),
amount: reward,
minimum_confirmations: 2,
max_outputs: 500,
num_change_outputs: 1,
selection_strategy_is_use_all: true,
..Default::default()
};
let mut wrong_net_args = args.clone();
wrong_net_args.send_args = Some(InitTxSendArgs {
dest: "grin1dvge9z4uqgqlpspmljrd7smh3grrw9xu2r9lkz3u67s3emj3ud2sd5gk9p".to_string(),
post_tx: false,
fluff: false,
skip_tor: Some(true),
});
assert!(api.init_send_tx(m, wrong_net_args.clone()).is_err());
assert!(api.process_invoice_tx(m, &slate, wrong_net_args).is_err());
let mut invalid_args = args.clone();
invalid_args.send_args = Some(InitTxSendArgs {
dest: "tgrinaddr10qlk22rxjap2ny8qltc2tl996kenxr3hhwuu6hrzs6tdq08yaqgqnlumr7"
.to_string(),
post_tx: false,
fluff: false,
skip_tor: Some(true),
});
assert!(api.init_send_tx(m, invalid_args.clone()).is_err());
assert!(api.process_invoice_tx(m, &slate, invalid_args).is_err());
let mut valid_args = args;
valid_args.send_args = Some(InitTxSendArgs {
dest: "tgrin1xtxavwfgs48ckf3gk8wwgcndmn0nt4tvkl8a7ltyejjcy2mc6nfs9gm2lp".to_string(),
post_tx: false,
fluff: false,
skip_tor: Some(true),
});
api.process_invoice_tx(m, &slate, valid_args.clone())?;
api.init_send_tx(m, valid_args)?;
Ok(())
})?;
stopper.store(false, Ordering::Relaxed);
proxy_thread.join().expect("wallet proxy thread panicked");
Ok(())
}
#[test]
fn slatepack_exchange_json() {
let test_dir = "test_output/slatepack_exchange_json";
@@ -677,3 +782,13 @@ fn slatepack_api() {
}
clean_output_dir(test_dir);
}
#[test]
fn slatepack_address() {
let test_dir = "test_output/slatepack_address";
setup(test_dir);
if let Err(e) = slatepack_address_validation(test_dir) {
panic!("Libwallet Error: {}", e);
}
clean_output_dir(test_dir);
}