|
| 1 | +// SPDX-License-Identifier: CC0-1.0 |
| 2 | + |
| 3 | +//! Tests for methods found under the `== Signer ==` section of the API docs. |
| 4 | +
|
| 5 | +#![allow(non_snake_case)] // Test names intentionally use double underscore. |
| 6 | +#![allow(unused_imports)] // Because of feature gated tests. |
| 7 | + |
| 8 | +use integration_test::{Node, NodeExt as _, Wallet}; |
| 9 | +use node::{mtype, Input, Output}; |
| 10 | +use node::vtype::*; // All the version specific types. |
| 11 | + |
| 12 | +#[test] |
| 13 | +#[cfg(unix)] |
| 14 | +#[cfg(not(feature = "v21_and_below"))] |
| 15 | +fn signer__enumerate_signers() { |
| 16 | + use std::os::unix::fs::PermissionsExt; |
| 17 | + |
| 18 | + let script_path = integration_test::random_tmp_file(); |
| 19 | + // `script_body` is minimal JSON array expected by `enumeratesigners` RPC: an array |
| 20 | + // of signer objects with at least a fingerprint and name. Using a hard-coded |
| 21 | + // dummy signer (fingerprint "deadbeef"). |
| 22 | + let script_body = "#!/bin/sh\necho '[{\"fingerprint\":\"deadbeef\",\"name\":\"TestSigner\"}]'\n"; |
| 23 | + std::fs::write(&script_path, script_body).expect("write signer script"); |
| 24 | + |
| 25 | + // Script needs to be executable so bitcoind can invoke it via the -signer arg. |
| 26 | + std::fs::set_permissions(&script_path, std::fs::Permissions::from_mode(0o755)) |
| 27 | + .expect("chmod"); |
| 28 | + |
| 29 | + let signer_arg = format!("-signer={}", script_path.to_str().unwrap()); |
| 30 | + let node = Node::with_wallet(Wallet::None, &[&signer_arg]); |
| 31 | + let json: EnumerateSigners = node.client.enumerate_signers().expect("enumeratesigners"); |
| 32 | + let first_tx = json.signers.first().expect("no signers found"); |
| 33 | + |
| 34 | + assert_eq!(first_tx.fingerprint, "deadbeef"); |
| 35 | +} |
0 commit comments