diff --git a/base_layer/core/src/transactions/transaction_protocol/transaction_initializer.rs b/base_layer/core/src/transactions/transaction_protocol/transaction_initializer.rs index 3735e680fa..d8d0facab3 100644 --- a/base_layer/core/src/transactions/transaction_protocol/transaction_initializer.rs +++ b/base_layer/core/src/transactions/transaction_protocol/transaction_initializer.rs @@ -488,9 +488,16 @@ impl SenderTransactionInitializer { Self::check_value("Missing Lock Height", &self.lock_height, &mut message); Self::check_value("Missing Fee per gram", &self.fee_per_gram, &mut message); Self::check_value("Missing Offset", &self.offset, &mut message); - Self::check_value("Change script", &self.private_nonce, &mut message); - Self::check_value("Change input data", &self.private_nonce, &mut message); - Self::check_value("Change script private key", &self.private_nonce, &mut message); + Self::check_value("Missing private nonce", &self.private_nonce, &mut message); + if self.change_secret.is_some() { + Self::check_value("Missing change script", &self.change_script, &mut message); + Self::check_value("Missing change input data", &self.change_input_data, &mut message); + Self::check_value( + "Change script private key", + &self.change_script_private_key, + &mut message, + ); + } if !message.is_empty() { return self.build_err(&message.join(",")); @@ -1149,4 +1156,14 @@ mod test { ), } } + + #[test] + fn fail_change_not_provided() { + let mut builder = SenderTransactionInitializer::new(1, &create_consensus_constants(0)); + builder.with_change_secret(PrivateKey::random(&mut OsRng)); + let err = builder.build(&CryptoFactories::default(), None, u64::MAX).unwrap_err(); + assert!(err.message.contains("change script")); + assert!(err.message.contains("change input data")); + assert!(err.message.contains("Change script private key")); + } }