forked from RGB-Tools/rgb-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b68c6d4
commit a338081
Showing
7 changed files
with
292 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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,58 @@ | ||
use super::*; | ||
use serial_test::parallel; | ||
|
||
#[test] | ||
#[parallel] | ||
fn success() { | ||
let test_data_dir_str = get_test_data_dir_string(); | ||
let test_data_dir = PathBuf::from(test_data_dir_str.clone()); | ||
fs::create_dir_all(test_data_dir).unwrap(); | ||
|
||
// test manual values | ||
let keys = generate_keys(BitcoinNetwork::Signet); | ||
let wallet_1 = Wallet::new(WalletData { | ||
data_dir: test_data_dir_str.clone(), | ||
bitcoin_network: BitcoinNetwork::Signet, | ||
database_type: DatabaseType::Sqlite, | ||
max_allocations_per_utxo: 1, | ||
pubkey: keys.account_xpub.clone(), | ||
mnemonic: Some(keys.mnemonic.clone()), | ||
vanilla_keychain: Some(2), | ||
}) | ||
.unwrap(); | ||
|
||
let wallet_1_data = test_get_wallet_data(&wallet_1); | ||
assert_eq!(wallet_1_data.data_dir, test_data_dir_str); | ||
assert_eq!( | ||
wallet_1.get_wallet_dir().parent().unwrap(), | ||
fs::canonicalize(wallet_1_data.data_dir).unwrap(), | ||
); | ||
assert_eq!(wallet_1_data.bitcoin_network, BitcoinNetwork::Signet); | ||
assert!(matches!(wallet_1_data.database_type, DatabaseType::Sqlite)); | ||
assert_eq!(wallet_1_data.pubkey, keys.account_xpub); | ||
assert_eq!(wallet_1_data.max_allocations_per_utxo, 1); | ||
assert_eq!(wallet_1_data.mnemonic.unwrap(), keys.mnemonic); | ||
assert_eq!(wallet_1_data.vanilla_keychain.unwrap(), 2); | ||
|
||
// test default values | ||
let wallet_2 = Wallet::new(WalletData { | ||
data_dir: test_data_dir_str.clone(), | ||
bitcoin_network: BitcoinNetwork::Regtest, | ||
database_type: DatabaseType::Sqlite, | ||
max_allocations_per_utxo: 5, | ||
pubkey: keys.account_xpub.clone(), | ||
mnemonic: None, | ||
vanilla_keychain: None, | ||
}) | ||
.unwrap(); | ||
let wallet_2_data = test_get_wallet_data(&wallet_2); | ||
assert_eq!(wallet_2_data.data_dir, test_data_dir_str); | ||
assert_eq!(wallet_2_data.bitcoin_network, BitcoinNetwork::Regtest); | ||
assert!(matches!(wallet_2_data.database_type, DatabaseType::Sqlite)); | ||
assert_eq!( | ||
wallet_2_data.max_allocations_per_utxo, | ||
MAX_ALLOCATIONS_PER_UTXO | ||
); | ||
assert!(wallet_2_data.mnemonic.is_none()); | ||
assert!(wallet_2_data.vanilla_keychain.is_none()); | ||
} |
This file contains 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,23 @@ | ||
use super::*; | ||
use serial_test::parallel; | ||
|
||
#[test] | ||
#[parallel] | ||
fn success() { | ||
let test_data_dir_str = get_test_data_dir_string(); | ||
let test_data_dir = PathBuf::from(test_data_dir_str.clone()); | ||
fs::create_dir_all(&test_data_dir).unwrap(); | ||
|
||
let keys = generate_keys(BitcoinNetwork::Regtest); | ||
let wallet = Wallet::new(get_test_wallet_data( | ||
&test_data_dir_str, | ||
&keys.account_xpub, | ||
&keys.mnemonic, | ||
)) | ||
.unwrap(); | ||
|
||
let expected_dir = fs::canonicalize(test_data_dir.join(keys.account_xpub_fingerprint)).unwrap(); | ||
|
||
let wallet_dir = test_get_wallet_dir(&wallet); | ||
assert_eq!(wallet_dir, expected_dir); | ||
} |
This file contains 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 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,113 @@ | ||
use super::*; | ||
use serial_test::parallel; | ||
|
||
#[test] | ||
#[parallel] | ||
fn success() { | ||
initialize(); | ||
let asset_amount: u64 = 66; | ||
|
||
// wallets | ||
let (wallet, online) = get_funded_wallet!(); | ||
let (rcv_wallet, _rcv_online) = get_empty_wallet!(); | ||
|
||
// NIA | ||
let nia_asset = test_issue_asset_nia(&wallet, &online, None); | ||
test_save_new_asset( | ||
&wallet, | ||
&online, | ||
&rcv_wallet, | ||
&nia_asset.asset_id, | ||
asset_amount, | ||
); | ||
assert!(&rcv_wallet | ||
.database | ||
.check_asset_exists(nia_asset.asset_id.clone()) | ||
.is_ok()); | ||
let asset_model = rcv_wallet | ||
.database | ||
.get_asset(nia_asset.asset_id.clone()) | ||
.unwrap() | ||
.unwrap(); | ||
assert_eq!(asset_model.id, nia_asset.asset_id); | ||
assert_eq!(asset_model.issued_supply, AMOUNT.to_string()); | ||
assert_eq!(asset_model.name, NAME); | ||
assert_eq!(asset_model.precision, PRECISION); | ||
assert_eq!(asset_model.ticker.unwrap(), TICKER); | ||
assert_eq!(asset_model.schema, AssetSchema::Nia); | ||
|
||
// CFA | ||
let cfa_asset = test_issue_asset_cfa(&wallet, &online, None, None); | ||
test_save_new_asset( | ||
&wallet, | ||
&online, | ||
&rcv_wallet, | ||
&cfa_asset.asset_id, | ||
asset_amount, | ||
); | ||
assert!(&rcv_wallet | ||
.database | ||
.check_asset_exists(cfa_asset.asset_id.clone()) | ||
.is_ok()); | ||
let asset_model = rcv_wallet | ||
.database | ||
.get_asset(cfa_asset.asset_id.clone()) | ||
.unwrap() | ||
.unwrap(); | ||
assert_eq!(asset_model.id, cfa_asset.asset_id); | ||
assert_eq!(asset_model.issued_supply, AMOUNT.to_string()); | ||
assert_eq!(asset_model.name, NAME); | ||
assert_eq!(asset_model.precision, PRECISION); | ||
assert!(asset_model.ticker.is_none()); | ||
assert_eq!(asset_model.schema, AssetSchema::Cfa); | ||
|
||
// UDA | ||
let uda_amount: u64 = 1; | ||
let file_str = "README.md"; | ||
let image_str = ["tests", "qrcode.png"].join(&MAIN_SEPARATOR.to_string()); | ||
let uda_asset = test_issue_asset_uda( | ||
&wallet, | ||
&online, | ||
Some(DETAILS), | ||
Some(file_str), | ||
vec![&image_str, file_str], | ||
); | ||
test_create_utxos(&wallet, &online, false, None, None, FEE_RATE); | ||
test_save_new_asset( | ||
&wallet, | ||
&online, | ||
&rcv_wallet, | ||
&uda_asset.asset_id, | ||
uda_amount, | ||
); | ||
assert!(&rcv_wallet | ||
.database | ||
.check_asset_exists(uda_asset.asset_id.clone()) | ||
.is_ok()); | ||
let asset_model = rcv_wallet | ||
.database | ||
.get_asset(uda_asset.asset_id.clone()) | ||
.unwrap() | ||
.unwrap(); | ||
assert_eq!(asset_model.id, uda_asset.asset_id); | ||
assert_eq!(asset_model.issued_supply, 1.to_string()); | ||
assert_eq!(asset_model.name, NAME); | ||
assert_eq!(asset_model.precision, PRECISION); | ||
assert_eq!(asset_model.ticker.unwrap(), TICKER); | ||
assert_eq!(asset_model.schema, AssetSchema::Uda); | ||
} | ||
|
||
#[test] | ||
#[parallel] | ||
fn fail() { | ||
initialize(); | ||
|
||
let (wallet, online) = get_funded_wallet!(); | ||
|
||
let asset_nia = test_issue_asset_nia(&wallet, &online, None); | ||
let asset_nia_cid = ContractId::from_str(&asset_nia.asset_id).unwrap(); | ||
let mut runtime = wallet._rgb_runtime().unwrap(); | ||
|
||
let result = wallet.save_new_asset(&mut runtime, &AssetSchema::Cfa, asset_nia_cid); | ||
assert!(matches!(result, Err(Error::Internal { details: _ }))); | ||
} |
This file contains 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 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,35 @@ | ||
use super::*; | ||
use serial_test::parallel; | ||
|
||
#[test] | ||
#[parallel] | ||
fn success() { | ||
initialize(); | ||
let (wallet, online) = get_funded_wallet!(); | ||
let address = test_get_address(&wallet); | ||
|
||
let unsigned_psbt_str = wallet | ||
.send_btc_begin(online, address, AMOUNT, FEE_RATE) | ||
.unwrap(); | ||
|
||
// no SignOptions | ||
let signed_psbt = wallet.sign_psbt(unsigned_psbt_str.clone(), None).unwrap(); | ||
assert!(BdkPsbt::from_str(&signed_psbt).is_ok()); | ||
|
||
// with SignOptions | ||
let opts = SignOptions::default(); | ||
let signed_psbt = wallet | ||
.sign_psbt(unsigned_psbt_str.clone(), Some(opts)) | ||
.unwrap(); | ||
assert!(BdkPsbt::from_str(&signed_psbt).is_ok()); | ||
} | ||
|
||
#[test] | ||
#[parallel] | ||
fn fail() { | ||
initialize(); | ||
let (wallet, _online) = get_funded_wallet!(); | ||
|
||
let result = wallet.sign_psbt("rgb1invalid".to_string(), None); | ||
assert!(matches!(result, Err(Error::Internal { details: _ }))); // PSBT parse error | ||
} |
This file contains 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