[WIP] V2 API Doctest generation (#24)

V2 API Doctest generation
This commit is contained in:
Yeastplume
2019-03-22 12:03:25 +00:00
committed by GitHub
parent 64772e6021
commit 94960b3edd
37 changed files with 1645 additions and 725 deletions
+3 -3
View File
@@ -111,14 +111,14 @@ fn accounts_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
w.set_parent_key_id_by_name("account1")?;
assert_eq!(w.parent_key_id(), ExtKeychain::derive_key_id(2, 1, 0, 0, 0));
}
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 7);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 7, false);
{
let mut w = wallet1.lock();
w.set_parent_key_id_by_name("account2")?;
assert_eq!(w.parent_key_id(), ExtKeychain::derive_key_id(2, 2, 0, 0, 0));
}
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 5);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 5, false);
// Should have 5 in account1 (5 spendable), 5 in account (2 spendable)
wallet::controller::owner_single_use(wallet1.clone(), |api| {
@@ -188,7 +188,7 @@ fn accounts_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
)?;
slate = client1.send_tx_slate_direct("wallet2", &slate)?;
api.tx_lock_outputs(&slate)?;
api.finalize_tx(&mut slate)?;
slate = api.finalize_tx(&slate)?;
api.post_tx(&slate.tx, false)?;
Ok(())
})?;
+9 -9
View File
@@ -38,7 +38,7 @@ macro_rules! send_to_dest {
WalletInst<LocalWalletClient, ExtKeychain>,
LocalWalletClient,
ExtKeychain,
>($a, $b, $c, $d)
>($a, $b, $c, $d, false)
};
}
@@ -111,7 +111,7 @@ fn check_repair_impl(test_dir: &str) -> Result<(), libwallet::Error> {
// Do some mining
let bh = 20u64;
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), bh as usize);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), bh as usize, false);
// Sanity check contents
wallet::controller::owner_single_use(wallet1.clone(), |api| {
@@ -135,7 +135,7 @@ fn check_repair_impl(test_dir: &str) -> Result<(), libwallet::Error> {
Ok(())
})?;
let w1_outputs: Vec<libwallet::types::OutputData> =
w1_outputs_commits.into_iter().map(|o| o.0).collect();
w1_outputs_commits.into_iter().map(|m| m.output).collect();
{
let mut w = wallet1.lock();
w.open_with_credentials()?;
@@ -337,7 +337,7 @@ fn two_wallets_one_seed_impl(test_dir: &str) -> Result<(), libwallet::Error> {
// Do some mining
let mut bh = 20u64;
let base_amount = consensus::GRIN_BASE;
let _ = test_framework::award_blocks_to_wallet(&chain, miner.clone(), bh as usize);
let _ = test_framework::award_blocks_to_wallet(&chain, miner.clone(), bh as usize, false);
// send some funds to wallets 1
send_to_dest!(miner.clone(), m_client.clone(), "wallet1", base_amount * 1)?;
@@ -360,7 +360,7 @@ fn two_wallets_one_seed_impl(test_dir: &str) -> Result<(), libwallet::Error> {
send_to_dest!(miner.clone(), m_client.clone(), "wallet2", base_amount * 6)?;
bh += 3;
let _ = test_framework::award_blocks_to_wallet(&chain, miner.clone(), cm);
let _ = test_framework::award_blocks_to_wallet(&chain, miner.clone(), cm, false);
bh += cm as u64;
// confirm balances
@@ -411,7 +411,7 @@ fn two_wallets_one_seed_impl(test_dir: &str) -> Result<(), libwallet::Error> {
send_to_dest!(miner.clone(), m_client.clone(), "wallet4", base_amount * 9)?;
bh += 3;
let _ = test_framework::award_blocks_to_wallet(&chain, miner.clone(), cm);
let _ = test_framework::award_blocks_to_wallet(&chain, miner.clone(), cm, false);
bh += cm as u64;
wallet::controller::owner_single_use(wallet4.clone(), |api| {
@@ -442,7 +442,7 @@ fn two_wallets_one_seed_impl(test_dir: &str) -> Result<(), libwallet::Error> {
send_to_dest!(miner.clone(), m_client.clone(), "wallet6", base_amount * 12)?;
bh += 3;
let _ = test_framework::award_blocks_to_wallet(&chain, miner.clone(), cm as usize);
let _ = test_framework::award_blocks_to_wallet(&chain, miner.clone(), cm as usize, false);
bh += cm as u64;
wallet::controller::owner_single_use(wallet6.clone(), |api| {
@@ -487,7 +487,7 @@ fn two_wallets_one_seed_impl(test_dir: &str) -> Result<(), libwallet::Error> {
bh += 3;
// check balances
let _ = test_framework::award_blocks_to_wallet(&chain, miner.clone(), cm);
let _ = test_framework::award_blocks_to_wallet(&chain, miner.clone(), cm, false);
bh += cm as u64;
wallet::controller::owner_single_use(wallet7.clone(), |api| {
@@ -552,7 +552,7 @@ fn two_wallets_one_seed_impl(test_dir: &str) -> Result<(), libwallet::Error> {
Ok(())
})?;
let _ = test_framework::award_blocks_to_wallet(&chain, miner.clone(), cm);
let _ = test_framework::award_blocks_to_wallet(&chain, miner.clone(), cm, false);
// 7) Ensure check_repair creates missing accounts
wallet::controller::owner_single_use(wallet10.clone(), |api| {
+3 -3
View File
@@ -89,7 +89,7 @@ fn file_exchange_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
w.set_parent_key_id_by_name("mining")?;
}
let mut bh = 10u64;
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), bh as usize);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), bh as usize, false);
let send_file = format!("{}/part_tx_1.tx", test_dir);
let receive_file = format!("{}/part_tx_2.tx", test_dir);
@@ -153,13 +153,13 @@ fn file_exchange_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
let adapter = FileWalletCommAdapter::new();
let mut slate = adapter.receive_tx_async(&receive_file)?;
api.verify_slate_messages(&slate)?;
api.finalize_tx(&mut slate)?;
slate = api.finalize_tx(&slate)?;
api.post_tx(&slate.tx, false)?;
bh += 1;
Ok(())
})?;
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3, false);
bh += 3;
// Check total in mining account
+7 -7
View File
@@ -88,7 +88,7 @@ fn file_repost_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
w.set_parent_key_id_by_name("mining")?;
}
let mut bh = 10u64;
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), bh as usize);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), bh as usize, false);
let send_file = format!("{}/part_tx_1.tx", test_dir);
let receive_file = format!("{}/part_tx_2.tx", test_dir);
@@ -119,7 +119,7 @@ fn file_repost_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
Ok(())
})?;
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3, false);
bh += 3;
// wallet 1 receives file to different account, completes
@@ -146,7 +146,7 @@ fn file_repost_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
wallet::controller::owner_single_use(wallet1.clone(), |api| {
let adapter = FileWalletCommAdapter::new();
slate = adapter.receive_tx_async(&receive_file)?;
api.finalize_tx(&mut slate)?;
slate = api.finalize_tx(&slate)?;
Ok(())
})?;
@@ -159,7 +159,7 @@ fn file_repost_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
Ok(())
})?;
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3, false);
bh += 3;
// update/test contents of both accounts
@@ -211,11 +211,11 @@ fn file_repost_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
)?;
slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
sender_api.tx_lock_outputs(&slate)?;
sender_api.finalize_tx(&mut slate)?;
slate = sender_api.finalize_tx(&mut slate)?;
Ok(())
})?;
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3, false);
bh += 3;
// Now repost from cached
@@ -227,7 +227,7 @@ fn file_repost_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
Ok(())
})?;
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3, false);
bh += 3;
//
// update/test contents of both accounts
+9 -9
View File
@@ -228,7 +228,7 @@ fn setup_restore(test_dir: &str) -> Result<(), libwallet::Error> {
});
// mine a few blocks
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 10);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 10, false);
// assert wallet contents
// and a single use api for a send command
@@ -246,13 +246,13 @@ fn setup_restore(test_dir: &str) -> Result<(), libwallet::Error> {
)?;
slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
sender_api.tx_lock_outputs(&slate)?;
sender_api.finalize_tx(&mut slate)?;
slate = sender_api.finalize_tx(&slate)?;
sender_api.post_tx(&slate.tx, false)?;
Ok(())
})?;
// mine a few more blocks
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3, false);
// Send some to wallet 3
wallet::controller::owner_single_use(wallet1.clone(), |sender_api| {
@@ -269,13 +269,13 @@ fn setup_restore(test_dir: &str) -> Result<(), libwallet::Error> {
)?;
slate = client1.send_tx_slate_direct("wallet3", &slate_i)?;
sender_api.tx_lock_outputs(&slate)?;
sender_api.finalize_tx(&mut slate)?;
slate = sender_api.finalize_tx(&slate)?;
sender_api.post_tx(&slate.tx, false)?;
Ok(())
})?;
// mine a few more blocks
let _ = test_framework::award_blocks_to_wallet(&chain, wallet3.clone(), 10);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet3.clone(), 10, false);
// Wallet3 to wallet 2
wallet::controller::owner_single_use(wallet3.clone(), |sender_api| {
@@ -292,7 +292,7 @@ fn setup_restore(test_dir: &str) -> Result<(), libwallet::Error> {
)?;
slate = client3.send_tx_slate_direct("wallet2", &slate_i)?;
sender_api.tx_lock_outputs(&slate)?;
sender_api.finalize_tx(&mut slate)?;
slate = sender_api.finalize_tx(&slate)?;
sender_api.post_tx(&slate.tx, false)?;
Ok(())
})?;
@@ -304,7 +304,7 @@ fn setup_restore(test_dir: &str) -> Result<(), libwallet::Error> {
}
// mine a few more blocks
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 2);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 2, false);
// Wallet3 to wallet 2 again (to another account)
wallet::controller::owner_single_use(wallet3.clone(), |sender_api| {
@@ -321,13 +321,13 @@ fn setup_restore(test_dir: &str) -> Result<(), libwallet::Error> {
)?;
slate = client3.send_tx_slate_direct("wallet2", &slate_i)?;
sender_api.tx_lock_outputs(&slate)?;
sender_api.finalize_tx(&mut slate)?;
slate = sender_api.finalize_tx(&slate)?;
sender_api.post_tx(&slate.tx, false)?;
Ok(())
})?;
// mine a few more blocks
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 5);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 5, false);
// update everyone
wallet::controller::owner_single_use(wallet1.clone(), |api| {
+3 -3
View File
@@ -76,7 +76,7 @@ fn self_send_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
w.set_parent_key_id_by_name("mining")?;
}
let mut bh = 10u64;
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), bh as usize);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), bh as usize, false);
// Should have 5 in account1 (5 spendable), 5 in account (2 spendable)
wallet::controller::owner_single_use(wallet1.clone(), |api| {
@@ -101,13 +101,13 @@ fn self_send_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
api.receive_tx(&mut slate, Some("listener"), None)?;
Ok(())
})?;
api.finalize_tx(&mut slate)?;
slate = api.finalize_tx(&slate)?;
api.post_tx(&slate.tx, false)?; // mines a block
bh += 1;
Ok(())
})?;
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3, false);
bh += 3;
// Check total in mining account
+21 -21
View File
@@ -75,7 +75,7 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
let reward = core::consensus::REWARD;
let cm = global::coinbase_maturity(); // assume all testing precedes soft fork height
// mine a few blocks
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 10);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 10, false);
// Check wallet 1 contents are as expected
wallet::controller::owner_single_use(wallet1.clone(), |api| {
@@ -114,7 +114,7 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
sender_api.tx_lock_outputs(&slate)?;
sender_api.finalize_tx(&mut slate)?;
slate = sender_api.finalize_tx(&slate)?;
// Check we have a single kernel and that it is a Plain kernel (no lock_height).
assert_eq!(slate.tx.kernels().len(), 1);
@@ -213,7 +213,7 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
})?;
// mine a few more blocks
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3, false);
// refresh wallets and retrieve info/tests for each wallet after maturity
wallet::controller::owner_single_use(wallet1.clone(), |api| {
@@ -249,7 +249,7 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
// Estimate fee and locked amount for a transaction
wallet::controller::owner_single_use(wallet1.clone(), |sender_api| {
let (total, fee) = sender_api.estimate_initiate_tx(
let est = sender_api.estimate_initiate_tx(
None,
amount * 2, // amount
2, // minimum confirmations
@@ -257,10 +257,10 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
1, // num change outputs
true, // select all outputs
)?;
assert_eq!(total, 600_000_000_000);
assert_eq!(fee, 4_000_000);
assert_eq!(est.total, 600_000_000_000);
assert_eq!(est.fee, 4_000_000);
let (total, fee) = sender_api.estimate_initiate_tx(
let est = sender_api.estimate_initiate_tx(
None,
amount * 2, // amount
2, // minimum confirmations
@@ -268,8 +268,8 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
1, // num change outputs
false, // select the smallest amount of outputs
)?;
assert_eq!(total, 180_000_000_000);
assert_eq!(fee, 6_000_000);
assert_eq!(est.total, 180_000_000_000);
assert_eq!(est.fee, 6_000_000);
Ok(())
})?;
@@ -290,7 +290,7 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
)?;
slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
sender_api.tx_lock_outputs(&slate)?;
sender_api.finalize_tx(&mut slate)?;
slate = sender_api.finalize_tx(&slate)?;
Ok(())
})?;
@@ -315,7 +315,7 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
})?;
// mine a few more blocks
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 3, false);
// check wallet2 has stored transaction
wallet::controller::owner_single_use(wallet2.clone(), |api| {
@@ -371,7 +371,7 @@ fn tx_rollback(test_dir: &str) -> Result<(), libwallet::Error> {
let reward = core::consensus::REWARD;
let cm = global::coinbase_maturity(); // assume all testing precedes soft fork height
// mine a few blocks
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 5);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 5, false);
let amount = 30_000_000_000;
let mut slate = Slate::blank(1);
@@ -387,7 +387,7 @@ fn tx_rollback(test_dir: &str) -> Result<(), libwallet::Error> {
)?;
slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
sender_api.tx_lock_outputs(&slate)?;
sender_api.finalize_tx(&mut slate)?;
slate = sender_api.finalize_tx(&slate)?;
Ok(())
})?;
@@ -406,16 +406,16 @@ fn tx_rollback(test_dir: &str) -> Result<(), libwallet::Error> {
let mut locked_count = 0;
let mut unconfirmed_count = 0;
// get the tx entry, check outputs are as expected
let (_, outputs) = api.retrieve_outputs(true, false, Some(tx.unwrap().id))?;
for (o, _) in outputs.clone() {
if o.status == OutputStatus::Locked {
let (_, output_mappings) = api.retrieve_outputs(true, false, Some(tx.unwrap().id))?;
for m in output_mappings.clone() {
if m.output.status == OutputStatus::Locked {
locked_count = locked_count + 1;
}
if o.status == OutputStatus::Unconfirmed {
if m.output.status == OutputStatus::Unconfirmed {
unconfirmed_count = unconfirmed_count + 1;
}
}
assert_eq!(outputs.len(), 3);
assert_eq!(output_mappings.len(), 3);
assert_eq!(locked_count, 2);
assert_eq!(unconfirmed_count, 1);
@@ -431,8 +431,8 @@ fn tx_rollback(test_dir: &str) -> Result<(), libwallet::Error> {
assert!(tx.is_some());
// get the tx entry, check outputs are as expected
let (_, outputs) = api.retrieve_outputs(true, false, Some(tx.unwrap().id))?;
for (o, _) in outputs.clone() {
if o.status == OutputStatus::Unconfirmed {
for m in outputs.clone() {
if m.output.status == OutputStatus::Unconfirmed {
unconfirmed_count = unconfirmed_count + 1;
}
}
@@ -447,7 +447,7 @@ fn tx_rollback(test_dir: &str) -> Result<(), libwallet::Error> {
// wallet 1 is bold and doesn't ever post the transaction
// mine a few more blocks
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 5);
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 5, false);
// Wallet 1 decides to roll back instead
wallet::controller::owner_single_use(wallet1.clone(), |api| {