Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions verify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ pub fn grep_for_re_export(path: &Path, s: &str) -> Result<bool> {
.with_context(|| format!("Failed to grep for string in {}", path.display()))?;
let reader = io::BufReader::new(file);

let s = format!("{}[,}};]", &s);
let re = Regex::new(&s)?;
let pattern = format!(r"\b{}[,}};]", regex::escape(s));
let re = Regex::new(&pattern)?;

for line in reader.lines() {
let line = line?;
Expand Down
68 changes: 50 additions & 18 deletions verify/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,37 +53,48 @@ fn main() -> Result<()> {
}

fn verify_all_versions(test_output: Option<&String>, quiet: bool) -> Result<()> {
let mut any_failed = false;
for version in VERSIONS {
println!("\nVerifying for Bitcoin Core version {} ...", version);
verify_version(version, test_output, quiet)?;
if verify_version(version, test_output, quiet).is_err() {
any_failed = true;
}
}
if any_failed {
return Err(anyhow::anyhow!("verification failed for one or more versions"))
}
Ok(())
}

fn verify_version(version: Version, test_output: Option<&String>, quiet: bool) -> Result<()> {
let mut failures = 0;

let s = format!("{}::METHOD data", version);
let msg = format!("Checking that the {} list is correct", s);
check(&msg, quiet);
let correct = verify_correct_methods(version, method::all_methods(version), &s)?;
close(correct, quiet);
if !correct {
process::exit(1);
match verify_correct_methods(version, method::all_methods(version), &s) {
Ok(()) => close(true, quiet),
Err(e) => { if !quiet { eprintln!("{}", e); } close(false, quiet); failures += 1; }
}

let s = "rustdoc version specific rustdocs";
let msg = format!("Checking that the {} list is correct", s);
check(&msg, quiet);
let correct = verify_correct_methods(version, versioned::all_methods(version)?, s)?;
close(correct, quiet);
if !correct {
process::exit(1);
match verify_correct_methods(version, versioned::all_methods(version)?, s) {
Ok(()) => close(true, quiet),
Err(e) => { if !quiet { eprintln!("{}", e); } close(false, quiet); failures += 1; }
}

let msg = "Checking that the status claimed in the version specific rustdocs is correct";
check(msg, quiet);
verify_status(version, test_output)?;
close(correct, quiet);
match verify_status(version, test_output) {
Ok(()) => close(true, quiet),
Err(e) => { if !quiet { eprintln!("{}", e); } close(false, quiet); failures += 1; }
}

if failures > 0 {
return Err(anyhow::anyhow!("verification failed ({} check(s) failed)", failures));
}
Ok(())
}

Expand All @@ -94,40 +105,53 @@ fn check(msg: &str, quiet: bool) {
}

fn close(correct: bool, quiet: bool) {
if correct && !quiet {
if quiet { return; }
if correct {
println!("Correct \u{2713} \n");
} else {
println!("\u{001b}[31mIncorrect \u{2717}\u{001b}[0m \n");
}
}

/// Verifies that the correct set of methods are documented.
fn verify_correct_methods(version: Version, methods: Vec<String>, msg: &str) -> Result<bool> {
fn verify_correct_methods(version: Version, methods: Vec<String>, msg: &str) -> Result<()> {
let ssot = ssot::all_methods(version)?;
let want = ssot.iter().map(|s| s.as_str()).collect::<Vec<&str>>();
let got = methods.iter().map(|s| s.as_str()).collect::<Vec<&str>>();
Ok(verify::correct_methods(&got, &want, msg))
if !verify::correct_methods(&got, &want, msg) {
return Err(anyhow::anyhow!("incorrect {}", msg));
}
Ok(())
}

/// Verifies that the status we claim is correct.
fn verify_status(version: Version, test_output: Option<&String>) -> Result<()> {
let methods = versioned::methods_and_status(version)?;
let mut failures = 0;
for method in methods {
match method.status {
Status::Done => {
check_types_exist_if_required(version, &method.name)?;
if check_types_exist_if_required(version, &method.name).is_err() {
failures += 1;
}

if let Some(test_output) = test_output {
if !check_integration_test_crate::test_exists(version, &method.name, test_output)? {
if check_integration_test_crate::test_exists(version, &method.name, test_output).is_err() {
eprintln!("missing integration test: {}", method.name);
failures += 1;
}
}
}
Status::Untested => {
check_types_exist_if_required(version, &method.name)?;
if check_types_exist_if_required(version, &method.name).is_err() {
failures += 1;
}

// Make sure we didn't forget to mark as tested after implementing integration test.
if let Some(test_output) = test_output {
if check_integration_test_crate::test_exists(version, &method.name, test_output)? {
if check_integration_test_crate::test_exists(version, &method.name, test_output).is_ok() {
eprintln!("found integration test for untested method: {}", method.name);
failures += 1;
}
}
}
Expand All @@ -137,15 +161,20 @@ fn verify_status(version: Version, test_output: Option<&String>) -> Result<()> {

if versioned::type_exists(version, &method.name)? && !versioned::requires_type(version, &method.name)? {
eprintln!("return type found but method is omitted or TODO: {}", output_method(out));
failures += 1;
}

if model::type_exists(version, &method.name)? && !model::requires_type(version, &method.name)? {
eprintln!("model type found but method is omitted or TODO: {}", output_method(out));
failures += 1;
}
}
}
}

if failures > 0 {
return Err(anyhow::anyhow!("status verification failed ({} issue(s))", failures));
}
Ok(())
}

Expand All @@ -154,12 +183,15 @@ fn check_types_exist_if_required(version: Version, method_name: &str) -> Result<

if versioned::requires_type(version, method_name)? && !versioned::type_exists(version, method_name)? {
eprintln!("missing return type: {}", output_method(out));
return Err(anyhow::anyhow!("missing return type"));
}
if model::requires_type(version, method_name)? && !model::type_exists(version, method_name)? {
eprintln!("missing model type: {}", output_method(out));
return Err(anyhow::anyhow!("missing model type"));
}
if model::type_exists(version, method_name)? && !model::requires_type(version, method_name)? {
eprintln!("found model type when none expected: {}", output_method(out));
return Err(anyhow::anyhow!("unexpected model type"));
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion verify/src/method/v21.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub const METHODS: &[Method] = &[
"sign_raw_transaction_with_wallet",
),
Method::new_nothing("unloadwallet", "unload_wallet"),
Method::new_no_model("upgradewallet", "UpgradeWalled", "upgrade_wallet"),
Method::new_no_model("upgradewallet", "UpgradeWallet", "upgrade_wallet"),
Method::new_modelled(
"walletcreatefundedpsbt",
"WalletCreateFundedPsbt",
Expand Down
2 changes: 1 addition & 1 deletion verify/src/method/v22.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub const METHODS: &[Method] = &[
"sign_raw_transaction_with_wallet",
),
Method::new_nothing("unloadwallet", "unload_wallet"),
Method::new_no_model("upgradewallet", "UpgradeWalled", "upgrade_wallet"),
Method::new_no_model("upgradewallet", "UpgradeWallet", "upgrade_wallet"),
Method::new_modelled(
"walletcreatefundedpsbt",
"WalletCreateFundedPsbt",
Expand Down
9 changes: 4 additions & 5 deletions verify/src/method/v23.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub const METHODS: &[Method] = &[
Method::new_modelled("getblockchaininfo", "GetBlockchainInfo", "get_blockchain_info"),
Method::new_modelled("getblockcount", "GetBlockCount", "get_block_count"),
Method::new_modelled("getblockfilter", "GetBlockFilter", "get_block_filter"),
Method::new_modelled("getblockfrompeer", "GetBlockFromPeer", "get_block_from_peer"),
Method::new_nothing("getblockfrompeer", "get_block_from_peer"),
Method::new_modelled("getblockhash", "GetBlockHash", "get_block_hash"),
Method::new_modelled("getblockheader", "GetBlockHeader", "get_block_header"),
Method::new_modelled("getblockstats", "GetBlockStats", "get_block_stats"),
Expand Down Expand Up @@ -84,7 +84,6 @@ pub const METHODS: &[Method] = &[
Method::new_nothing("signrawtransactionwithkey", "sign_raw_transaction_with_key"),
Method::new_nothing("testmempoolaccept", "test_mempool_accept"),
Method::new_modelled("utxoupdatepsbt", "UtxoUpdatePsbt", "utxo_update_psbt"),
Method::new_modelled("enumeratesigners", "EnumerateSigners", "enumerate_signers"),
Method::new_modelled("createmultisig", "CreateMultisig", "create_multisig"),
Method::new_modelled("deriveaddresses", "DeriveAddresses", "derive_addresses"),
Method::new_nothing("estimatesmartfee", "estimate_smart_fee"),
Expand Down Expand Up @@ -132,7 +131,7 @@ pub const METHODS: &[Method] = &[
Method::new_no_model("listdescriptors", "ListDescriptors", "list_descriptors"),
Method::new_no_model("listlabels", "ListLabels", "list_labels"),
Method::new_modelled("listlockunspent", "ListLockUnspent", "list_lock_unspent"),
Method::new_modelled("newkeypool", "NewKeyPool", "new_key_pool"),
Method::new_nothing("newkeypool", "new_key_pool"),
Method::new_modelled("psbtbumpfee", "PsbtBumpFee", "psbt_bump_fee"),
Method::new_modelled(
"listreceivedbyaddress",
Expand All @@ -149,7 +148,7 @@ pub const METHODS: &[Method] = &[
Method::new_no_model("lockunspent", "LockUnspent", "lock_unspent"),
Method::new_nothing("removeprunedfunds", "remove_pruned_funds"),
Method::new_modelled("rescanblockchain", "RescanBlockchain", "rescan_blockchain"),
Method::new_modelled("restorewallet", "RestoreWallet", "restore_wallet"),
Method::new_no_model("restorewallet", "RestoreWallet", "restore_wallet"),
Method::new_modelled("send", "Send", "send"),
Method::new_modelled("sendmany", "SendMany", "send_many"),
Method::new_modelled("sendtoaddress", "SendToAddress", "send_to_address"),
Expand All @@ -164,7 +163,7 @@ pub const METHODS: &[Method] = &[
"sign_raw_transaction_with_wallet",
),
Method::new_nothing("unloadwallet", "unload_wallet"),
Method::new_no_model("upgradewallet", "UpgradeWalled", "upgrade_wallet"),
Method::new_no_model("upgradewallet", "UpgradeWallet", "upgrade_wallet"),
Method::new_modelled(
"walletcreatefundedpsbt",
"WalletCreateFundedPsbt",
Expand Down
9 changes: 4 additions & 5 deletions verify/src/method/v24.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub const METHODS: &[Method] = &[
Method::new_modelled("getblockchaininfo", "GetBlockchainInfo", "get_blockchain_info"),
Method::new_modelled("getblockcount", "GetBlockCount", "get_block_count"),
Method::new_modelled("getblockfilter", "GetBlockFilter", "get_block_filter"),
Method::new_modelled("getblockfrompeer", "GetBlockFromPeer", "get_block_from_peer"),
Method::new_nothing("getblockfrompeer", "get_block_from_peer"),
Method::new_modelled("getblockhash", "GetBlockHash", "get_block_hash"),
Method::new_modelled("getblockheader", "GetBlockHeader", "get_block_header"),
Method::new_modelled("getblockstats", "GetBlockStats", "get_block_stats"),
Expand Down Expand Up @@ -85,7 +85,6 @@ pub const METHODS: &[Method] = &[
Method::new_nothing("signrawtransactionwithkey", "sign_raw_transaction_with_key"),
Method::new_nothing("testmempoolaccept", "test_mempool_accept"),
Method::new_modelled("utxoupdatepsbt", "UtxoUpdatePsbt", "utxo_update_psbt"),
Method::new_modelled("enumeratesigners", "EnumerateSigners", "enumerate_signers"),
Method::new_modelled("createmultisig", "CreateMultisig", "create_multisig"),
Method::new_modelled("deriveaddresses", "DeriveAddresses", "derive_addresses"),
Method::new_nothing("estimatesmartfee", "estimate_smart_fee"),
Expand Down Expand Up @@ -134,7 +133,7 @@ pub const METHODS: &[Method] = &[
Method::new_no_model("listlabels", "ListLabels", "list_labels"),
Method::new_modelled("listlockunspent", "ListLockUnspent", "list_lock_unspent"),
Method::new_no_model("migratewallet", "MigrateWallet", "migrate_wallet"),
Method::new_modelled("newkeypool", "NewKeyPool", "new_key_pool"),
Method::new_nothing("newkeypool", "new_key_pool"),
Method::new_modelled("psbtbumpfee", "PsbtBumpFee", "psbt_bump_fee"),
Method::new_modelled(
"listreceivedbyaddress",
Expand All @@ -151,7 +150,7 @@ pub const METHODS: &[Method] = &[
Method::new_no_model("lockunspent", "LockUnspent", "lock_unspent"),
Method::new_nothing("removeprunedfunds", "remove_pruned_funds"),
Method::new_modelled("rescanblockchain", "RescanBlockchain", "rescan_blockchain"),
Method::new_modelled("restorewallet", "RestoreWallet", "restore_wallet"),
Method::new_no_model("restorewallet", "RestoreWallet", "restore_wallet"),
Method::new_modelled("send", "Send", "send"),
Method::new_modelled("sendall", "SendAll", "send_all"),
Method::new_modelled("sendmany", "SendMany", "send_many"),
Expand All @@ -168,7 +167,7 @@ pub const METHODS: &[Method] = &[
),
Method::new_modelled("simulaterawtransaction", "SimulateRawTransaction", "simulate_raw_transaction"),
Method::new_nothing("unloadwallet", "unload_wallet"),
Method::new_no_model("upgradewallet", "UpgradeWalled", "upgrade_wallet"),
Method::new_no_model("upgradewallet", "UpgradeWallet", "upgrade_wallet"),
Method::new_modelled(
"walletcreatefundedpsbt",
"WalletCreateFundedPsbt",
Expand Down
11 changes: 5 additions & 6 deletions verify/src/method/v25.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub const METHODS: &[Method] = &[
Method::new_modelled("getblockchaininfo", "GetBlockchainInfo", "get_blockchain_info"),
Method::new_modelled("getblockcount", "GetBlockCount", "get_block_count"),
Method::new_modelled("getblockfilter", "GetBlockFilter", "get_block_filter"),
Method::new_modelled("getblockfrompeer", "GetBlockFromPeer", "get_block_from_peer"),
Method::new_nothing("getblockfrompeer", "get_block_from_peer"),
Method::new_modelled("getblockhash", "GetBlockHash", "get_block_hash"),
Method::new_modelled("getblockheader", "GetBlockHeader", "get_block_header"),
Method::new_modelled("getblockstats", "GetBlockStats", "get_block_stats"),
Expand All @@ -36,7 +36,7 @@ pub const METHODS: &[Method] = &[
Method::new_nothing("preciousblock", "precious_block"),
Method::new_no_model("pruneblockchain", "PruneBlockchain", "prune_blockchain"),
Method::new_no_model("savemempool", "SaveMempool", "save_mempool"),
Method::new_modelled("scanblocks", "ScanBlocks", "scan_blocks"),
Method::new_modelled("scanblocks", "ScanBlocksStart", "scan_blocks"),
Method::new_modelled("scantxoutset", "ScanTxOutSet", "scan_tx_out_set"),
Method::new_no_model("verifychain", "VerifyChain", "verify_chain"),
Method::new_modelled("verifytxoutproof", "VerifyTxOutProof", "verify_tx_out_proof"),
Expand Down Expand Up @@ -86,7 +86,6 @@ pub const METHODS: &[Method] = &[
Method::new_nothing("signrawtransactionwithkey", "sign_raw_transaction_with_key"),
Method::new_nothing("testmempoolaccept", "test_mempool_accept"),
Method::new_modelled("utxoupdatepsbt", "UtxoUpdatePsbt", "utxo_update_psbt"),
Method::new_modelled("enumeratesigners", "EnumerateSigners", "enumerate_signers"),
Method::new_modelled("createmultisig", "CreateMultisig", "create_multisig"),
Method::new_modelled("deriveaddresses", "DeriveAddresses", "derive_addresses"),
Method::new_nothing("estimatesmartfee", "estimate_smart_fee"),
Expand Down Expand Up @@ -135,7 +134,7 @@ pub const METHODS: &[Method] = &[
Method::new_no_model("listlabels", "ListLabels", "list_labels"),
Method::new_modelled("listlockunspent", "ListLockUnspent", "list_lock_unspent"),
Method::new_no_model("migratewallet", "MigrateWallet", "migrate_wallet"),
Method::new_modelled("newkeypool", "NewKeyPool", "new_key_pool"),
Method::new_nothing("newkeypool", "new_key_pool"),
Method::new_modelled("psbtbumpfee", "PsbtBumpFee", "psbt_bump_fee"),
Method::new_modelled(
"listreceivedbyaddress",
Expand All @@ -152,7 +151,7 @@ pub const METHODS: &[Method] = &[
Method::new_no_model("lockunspent", "LockUnspent", "lock_unspent"),
Method::new_nothing("removeprunedfunds", "remove_pruned_funds"),
Method::new_modelled("rescanblockchain", "RescanBlockchain", "rescan_blockchain"),
Method::new_modelled("restorewallet", "RestoreWallet", "restore_wallet"),
Method::new_no_model("restorewallet", "RestoreWallet", "restore_wallet"),
Method::new_modelled("send", "Send", "send"),
Method::new_modelled("sendall", "SendAll", "send_all"),
Method::new_modelled("sendmany", "SendMany", "send_many"),
Expand All @@ -169,7 +168,7 @@ pub const METHODS: &[Method] = &[
),
Method::new_modelled("simulaterawtransaction", "SimulateRawTransaction", "simulate_raw_transaction"),
Method::new_nothing("unloadwallet", "unload_wallet"),
Method::new_no_model("upgradewallet", "UpgradeWalled", "upgrade_wallet"),
Method::new_no_model("upgradewallet", "UpgradeWallet", "upgrade_wallet"),
Method::new_modelled(
"walletcreatefundedpsbt",
"WalletCreateFundedPsbt",
Expand Down
Loading