-
Notifications
You must be signed in to change notification settings - Fork 84
Add Wallet Integration Tests and Fix Descriptor Persistence Issues #821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
moisesPompilio
wants to merge
9
commits into
getfloresta:master
Choose a base branch
from
moisesPompilio:add-test-wallet
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fc17891
chore(integration): centralize constants in a dedicated module
moisesPompilio 04c5339
docs(cli): clarify documentation for wallet descriptor option
moisesPompilio 629ad69
fix(wallet): handle duplicate descriptors in push_descriptor method
moisesPompilio 39d1349
fix(wallet): improve xpub parsing and descriptor generation
moisesPompilio 0c6dc2a
test(integration): add wallet configuration and flag tests
moisesPompilio fcb3c4f
test(integration): add integration tests for `loaddescriptor` RPC method
moisesPompilio 5110de8
test(integration): add integration tests for `listdescriptors` RPC me…
moisesPompilio 4c883d5
chore(wallet): centralize descriptor parsing logic in `floresta-watch…
moisesPompilio 7f9b79b
chore(wallet): Centralize address derivation in `floresta-watch-only`…
moisesPompilio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| [default] | ||
| extend-ignore-re = [ | ||
| # This regex is used to prevent https://github.com/crate-ci/typos from analyzing words | ||
| # with lengths between 32 and 150 characters. These lengths correspond to hashes, | ||
| # public keys, private keys, XPUBs, descriptors, and Bitcoin addresses. | ||
| # These items are usually randomly generated for testing and may contain patterns | ||
| # that would be flagged as errors but should not be. | ||
| "[0-9A-Za-z]{32,150}+", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,12 +4,15 @@ use std::net::Ipv4Addr; | |
| use std::net::SocketAddr; | ||
| use std::path::Path; | ||
| use std::path::PathBuf; | ||
| use std::str::FromStr; | ||
| use std::sync::Arc; | ||
| use std::sync::Mutex; | ||
| #[cfg(feature = "json-rpc")] | ||
| use std::sync::OnceLock; | ||
|
|
||
| use bitcoin::Address; | ||
| pub use bitcoin::Network; | ||
| use bitcoin::ScriptBuf; | ||
| #[cfg(feature = "zmq-server")] | ||
| use floresta_chain::pruned_utreexo::BlockchainInterface; | ||
| pub use floresta_chain::AssumeUtreexoValue; | ||
|
|
@@ -27,6 +30,7 @@ use floresta_electrum::electrum_protocol::ElectrumServer; | |
| use floresta_mempool::Mempool; | ||
| use floresta_watch_only::kv_database::KvDatabase; | ||
| use floresta_watch_only::AddressCache; | ||
| use floresta_watch_only::WatchOnlyError; | ||
| use floresta_wire::address_man::AddressMan; | ||
| use floresta_wire::node::running_ctx::RunningNode; | ||
| use floresta_wire::node::UtreexoNode; | ||
|
|
@@ -57,7 +61,6 @@ use crate::error::FlorestadError; | |
| use crate::florestad::fs::OpenOptions; | ||
| #[cfg(feature = "json-rpc")] | ||
| use crate::json_rpc; | ||
| use crate::wallet_input::InitialWalletSetup; | ||
| #[cfg(feature = "zmq-server")] | ||
| use crate::zmq::ZMQServer; | ||
|
|
||
|
|
@@ -741,45 +744,71 @@ impl Florestad { | |
| Self::get_config_file(&default_path) | ||
| } | ||
| }; | ||
| let setup = self.prepare_wallet_setup(config_file)?; | ||
|
|
||
| // Add the configured descriptors and addresses to the wallet | ||
| for descriptor in setup.descriptors { | ||
| let descriptor = descriptor.to_string(); | ||
| let is_cached = wallet.is_cached(&descriptor)?; | ||
| for descriptor in self.get_descriptors(&config_file) { | ||
| if let Err(e) = wallet.push_descriptor(&descriptor) { | ||
| if let WatchOnlyError::DescriptorDuplicate = e { | ||
| warn!("Descriptor already exists in wallet, skipping: {descriptor}"); | ||
| } else { | ||
| return Err(FlorestadError::from(e)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if !is_cached { | ||
| wallet.push_descriptor(&descriptor)?; | ||
| for xpub in self.get_xpubs(&config_file) { | ||
| if let Err(e) = wallet.push_xpub(&xpub, self.config.network) { | ||
| if let WatchOnlyError::DescriptorDuplicate = e { | ||
| warn!("Descriptor for the provided XPUB already exists in the wallet. Skipping: {xpub}"); | ||
| } else { | ||
| return Err(FlorestadError::from(e)); | ||
| } | ||
| } | ||
|
Comment on lines
760
to
766
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer a match expression just as i suggested earlier |
||
| } | ||
| for addresses in setup.addresses { | ||
| wallet.cache_address(addresses.script_pubkey()); | ||
|
|
||
| for address in self.get_addresses(&config_file)? { | ||
| wallet.cache_address(address); | ||
| } | ||
|
|
||
| info!("Wallet setup completed!"); | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// Parses the configured list of xpubs, output descriptors and addresses to watch for, and | ||
| /// returns the constructed `InitialWalletSetup`. | ||
| fn prepare_wallet_setup( | ||
| &self, | ||
| config_file: ConfigFile, | ||
| ) -> Result<InitialWalletSetup, FlorestadError> { | ||
| let config = &self.config; | ||
| /// Get the wallet descriptors from the config file and the environment. | ||
| fn get_descriptors(&self, config_file: &ConfigFile) -> Vec<String> { | ||
| let mut descriptors = Vec::new(); | ||
| descriptors.extend(self.config.wallet_descriptor.clone().unwrap_or_default()); | ||
| descriptors.extend(config_file.wallet.descriptors.clone().unwrap_or_default()); | ||
|
|
||
| descriptors | ||
| } | ||
|
|
||
| /// Get the wallet xpubs from the config file and the environment | ||
| fn get_xpubs(&self, config_file: &ConfigFile) -> Vec<String> { | ||
| let mut xpubs = Vec::new(); | ||
| xpubs.extend(config.wallet_xpub.clone().unwrap_or_default()); | ||
| xpubs.extend(config_file.wallet.xpubs.unwrap_or_default()); | ||
| xpubs.extend(self.config.wallet_xpub.clone().unwrap_or_default()); | ||
| xpubs.extend(config_file.wallet.xpubs.clone().unwrap_or_default()); | ||
| xpubs.extend(Self::get_key_from_env()); | ||
|
|
||
| let mut descriptors = Vec::new(); | ||
| descriptors.extend(config.wallet_descriptor.clone().unwrap_or_default()); | ||
| descriptors.extend(config_file.wallet.descriptors.unwrap_or_default()); | ||
| xpubs | ||
| } | ||
|
|
||
| let addresses = config_file.wallet.addresses.unwrap_or_default(); | ||
| /// Get the wallet addresses from the config file | ||
| fn get_addresses(&self, config_file: &ConfigFile) -> Result<Vec<ScriptBuf>, FlorestadError> { | ||
| let addresses_string = config_file.wallet.addresses.clone().unwrap_or_default(); | ||
|
|
||
| let addresses = addresses_string | ||
| .iter() | ||
| .map(|address| match Address::from_str(address) { | ||
| Ok(address) => Ok(address.assume_checked().script_pubkey()), | ||
| Err(e) => { | ||
| error!("Invalid address provided: {address} \nReason: {e:?}"); | ||
| Err(e) | ||
| } | ||
| }) | ||
| .collect::<Result<Vec<_>, _>>()?; | ||
|
|
||
| InitialWalletSetup::build(&xpubs, &descriptors, &addresses, config.network, 100) | ||
| Ok(addresses) | ||
| } | ||
|
|
||
| /// Get the default Electrum port for the Network and TLS combination. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this diff messed ?