-
Notifications
You must be signed in to change notification settings - Fork 10
test: extract wallet setup into TestWalletContext
#539
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
xdustinface
wants to merge
1
commit into
v0.42-dev
Choose a base branch
from
test/wallet-context
base: v0.42-dev
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.
+138
−262
Open
Changes from all commits
Commits
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| mod account; | ||
| mod utxo; | ||
| mod wallet; | ||
|
|
||
| pub use wallet::TestWalletContext; |
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 |
|---|---|---|
| @@ -1,9 +1,53 @@ | ||
| use dashcore::Network; | ||
| use dashcore::{Address, Network}; | ||
|
|
||
| use crate::wallet::ManagedWalletInfo; | ||
| use crate::wallet::initialization::WalletAccountCreationOptions; | ||
| use crate::wallet::{ManagedWalletInfo, Wallet}; | ||
| use crate::ExtendedPubKey; | ||
|
|
||
| impl ManagedWalletInfo { | ||
| pub fn dummy(id: u8) -> Self { | ||
| ManagedWalletInfo::new(Network::Regtest, [id; 32]) | ||
| } | ||
| } | ||
|
|
||
| /// Pre-built wallet context for transaction checking tests. | ||
| /// | ||
| /// Provides a testnet wallet with a default BIP44 account, a pre-derived | ||
| /// receive address, and the corresponding extended public key. | ||
| pub struct TestWalletContext { | ||
| pub managed_wallet: ManagedWalletInfo, | ||
| pub wallet: Wallet, | ||
| pub receive_address: Address, | ||
| pub xpub: ExtendedPubKey, | ||
| } | ||
|
|
||
| impl TestWalletContext { | ||
| /// Creates a new random testnet wallet with a BIP44 account and one | ||
| /// pre-derived receive address. | ||
| pub fn new_random() -> Self { | ||
| let wallet = Wallet::new_random(Network::Testnet, WalletAccountCreationOptions::Default) | ||
| .expect("Should create wallet"); | ||
| let mut managed_wallet = | ||
| ManagedWalletInfo::from_wallet_with_name(&wallet, "Test".to_string()); | ||
|
|
||
| let xpub = wallet | ||
| .accounts | ||
| .standard_bip44_accounts | ||
| .get(&0) | ||
| .expect("Should have BIP44 account") | ||
| .account_xpub; | ||
|
|
||
| let receive_address = managed_wallet | ||
| .first_bip44_managed_account_mut() | ||
| .expect("Should have managed account") | ||
| .next_receive_address(Some(&xpub), true) | ||
| .expect("Should get address"); | ||
|
|
||
| Self { | ||
| managed_wallet, | ||
| wallet, | ||
| receive_address, | ||
| xpub, | ||
| } | ||
| } | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.