projects
/
rust-lightning
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Impl PartialOrd and Ord for Invoice
[rust-lightning]
/
lightning
/
src
/
util
/
test_utils.rs
diff --git
a/lightning/src/util/test_utils.rs
b/lightning/src/util/test_utils.rs
index 5be32a87f726d9fa486da514d237c96f3148b5e9..658876fe33a6a478865da7f2ccaf1d729cb15569 100644
(file)
--- a/
lightning/src/util/test_utils.rs
+++ b/
lightning/src/util/test_utils.rs
@@
-16,7
+16,7
@@
use crate::chain::chainmonitor::MonitorUpdateId;
use crate::chain::channelmonitor;
use crate::chain::channelmonitor::MonitorEvent;
use crate::chain::transaction::OutPoint;
use crate::chain::channelmonitor;
use crate::chain::channelmonitor::MonitorEvent;
use crate::chain::transaction::OutPoint;
-use crate::
chain::keysinterface
;
+use crate::
sign
;
use crate::events;
use crate::ln::channelmanager;
use crate::ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
use crate::events;
use crate::ln::channelmanager;
use crate::ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
@@
-25,7
+25,7
@@
use crate::ln::msgs::LightningError;
use crate::ln::script::ShutdownScript;
use crate::routing::gossip::{EffectiveCapacity, NetworkGraph, NodeId};
use crate::routing::utxo::{UtxoLookup, UtxoLookupError, UtxoResult};
use crate::ln::script::ShutdownScript;
use crate::routing::gossip::{EffectiveCapacity, NetworkGraph, NodeId};
use crate::routing::utxo::{UtxoLookup, UtxoLookupError, UtxoResult};
-use crate::routing::router::{find_route, InFlightHtlcs,
Route, RouteHop
, RouteParameters, Router, ScorerAccountingForInFlightHtlcs};
+use crate::routing::router::{find_route, InFlightHtlcs,
Path, Route
, RouteParameters, Router, ScorerAccountingForInFlightHtlcs};
use crate::routing::scoring::{ChannelUsage, Score};
use crate::util::config::UserConfig;
use crate::util::enforcing_trait_impls::{EnforcingSigner, EnforcementState};
use crate::routing::scoring::{ChannelUsage, Score};
use crate::util::config::UserConfig;
use crate::util::enforcing_trait_impls::{EnforcingSigner, EnforcementState};
@@
-54,12
+54,21
@@
use crate::sync::{Mutex, Arc};
use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use core::mem;
use bitcoin::bech32::u5;
use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use core::mem;
use bitcoin::bech32::u5;
-use crate::
chain::keysinterface
::{InMemorySigner, Recipient, EntropySource, NodeSigner, SignerProvider};
+use crate::
sign
::{InMemorySigner, Recipient, EntropySource, NodeSigner, SignerProvider};
#[cfg(feature = "std")]
use std::time::{SystemTime, UNIX_EPOCH};
use bitcoin::Sequence;
#[cfg(feature = "std")]
use std::time::{SystemTime, UNIX_EPOCH};
use bitcoin::Sequence;
+pub fn pubkey(byte: u8) -> PublicKey {
+ let secp_ctx = Secp256k1::new();
+ PublicKey::from_secret_key(&secp_ctx, &privkey(byte))
+}
+
+pub fn privkey(byte: u8) -> SecretKey {
+ SecretKey::from_slice(&[byte; 32]).unwrap()
+}
+
pub struct TestVecWriter(pub Vec<u8>);
impl Writer for TestVecWriter {
fn write_all(&mut self, buf: &[u8]) -> Result<(), io::Error> {
pub struct TestVecWriter(pub Vec<u8>);
impl Writer for TestVecWriter {
fn write_all(&mut self, buf: &[u8]) -> Result<(), io::Error> {
@@
-106,7
+115,7
@@
impl<'a> Router for TestRouter<'a> {
let scorer = ScorerAccountingForInFlightHtlcs::new(locked_scorer, inflight_htlcs);
for path in &route.paths {
let mut aggregate_msat = 0u64;
let scorer = ScorerAccountingForInFlightHtlcs::new(locked_scorer, inflight_htlcs);
for path in &route.paths {
let mut aggregate_msat = 0u64;
- for (idx, hop) in path.iter().rev().enumerate() {
+ for (idx, hop) in path.
hops.
iter().rev().enumerate() {
aggregate_msat += hop.fee_msat;
let usage = ChannelUsage {
amount_msat: aggregate_msat,
aggregate_msat += hop.fee_msat;
let usage = ChannelUsage {
amount_msat: aggregate_msat,
@@
-116,11
+125,11
@@
impl<'a> Router for TestRouter<'a> {
// Since the path is reversed, the last element in our iteration is the first
// hop.
// Since the path is reversed, the last element in our iteration is the first
// hop.
- if idx == path.len() - 1 {
+ if idx == path.
hops.
len() - 1 {
scorer.channel_penalty_msat(hop.short_channel_id, &NodeId::from_pubkey(payer), &NodeId::from_pubkey(&hop.pubkey), usage);
} else {
scorer.channel_penalty_msat(hop.short_channel_id, &NodeId::from_pubkey(payer), &NodeId::from_pubkey(&hop.pubkey), usage);
} else {
- let curr_hop_path_idx = path.len() - 1 - idx;
- scorer.channel_penalty_msat(hop.short_channel_id, &NodeId::from_pubkey(&path[curr_hop_path_idx - 1].pubkey), &NodeId::from_pubkey(&hop.pubkey), usage);
+ let curr_hop_path_idx = path.
hops.
len() - 1 - idx;
+ scorer.channel_penalty_msat(hop.short_channel_id, &NodeId::from_pubkey(&path
.hops
[curr_hop_path_idx - 1].pubkey), &NodeId::from_pubkey(&hop.pubkey), usage);
}
}
}
}
}
}
@@
-171,8
+180,8
@@
impl SignerProvider for OnlyReadsKeysInterface {
))
}
))
}
- fn get_destination_script(&self) ->
Script { unreachable!();
}
- fn get_shutdown_scriptpubkey(&self) ->
ShutdownScript { unreachable!();
}
+ fn get_destination_script(&self) ->
Result<Script, ()> { Err(())
}
+ fn get_shutdown_scriptpubkey(&self) ->
Result<ShutdownScript, ()> { Err(())
}
}
pub struct TestChainMonitor<'a> {
}
pub struct TestChainMonitor<'a> {
@@
-280,7
+289,7
@@
impl TestPersister {
self.update_rets.lock().unwrap().push_back(next_ret);
}
}
self.update_rets.lock().unwrap().push_back(next_ret);
}
}
-impl<Signer:
keysinterface
::WriteableEcdsaChannelSigner> chainmonitor::Persist<Signer> for TestPersister {
+impl<Signer:
sign
::WriteableEcdsaChannelSigner> chainmonitor::Persist<Signer> for TestPersister {
fn persist_new_channel(&self, _funding_txo: OutPoint, _data: &channelmonitor::ChannelMonitor<Signer>, _id: MonitorUpdateId) -> chain::ChannelMonitorUpdateStatus {
if let Some(update_ret) = self.update_rets.lock().unwrap().pop_front() {
return update_ret
fn persist_new_channel(&self, _funding_txo: OutPoint, _data: &channelmonitor::ChannelMonitor<Signer>, _id: MonitorUpdateId) -> chain::ChannelMonitorUpdateStatus {
if let Some(update_ret) = self.update_rets.lock().unwrap().pop_front() {
return update_ret
@@
-702,7
+711,7
@@
impl TestNodeSigner {
}
impl NodeSigner for TestNodeSigner {
}
impl NodeSigner for TestNodeSigner {
- fn get_inbound_payment_key_material(&self) -> crate::
chain::keysinterface
::KeyMaterial {
+ fn get_inbound_payment_key_material(&self) -> crate::
sign
::KeyMaterial {
unreachable!()
}
unreachable!()
}
@@
-735,7
+744,7
@@
impl NodeSigner for TestNodeSigner {
}
pub struct TestKeysInterface {
}
pub struct TestKeysInterface {
- pub backing:
keysinterface
::PhantomKeysManager,
+ pub backing:
sign
::PhantomKeysManager,
pub override_random_bytes: Mutex<Option<[u8; 32]>>,
pub disable_revocation_policy_check: bool,
enforcement_states: Mutex<HashMap<[u8;32], Arc<Mutex<EnforcementState>>>>,
pub override_random_bytes: Mutex<Option<[u8; 32]>>,
pub disable_revocation_policy_check: bool,
enforcement_states: Mutex<HashMap<[u8;32], Arc<Mutex<EnforcementState>>>>,
@@
-761,7
+770,7
@@
impl NodeSigner for TestKeysInterface {
self.backing.ecdh(recipient, other_key, tweak)
}
self.backing.ecdh(recipient, other_key, tweak)
}
- fn get_inbound_payment_key_material(&self) ->
keysinterface
::KeyMaterial {
+ fn get_inbound_payment_key_material(&self) ->
sign
::KeyMaterial {
self.backing.get_inbound_payment_key_material()
}
self.backing.get_inbound_payment_key_material()
}
@@
-800,14
+809,14
@@
impl SignerProvider for TestKeysInterface {
))
}
))
}
- fn get_destination_script(&self) ->
Script
{ self.backing.get_destination_script() }
+ fn get_destination_script(&self) ->
Result<Script, ()>
{ self.backing.get_destination_script() }
- fn get_shutdown_scriptpubkey(&self) ->
ShutdownScript
{
+ fn get_shutdown_scriptpubkey(&self) ->
Result<ShutdownScript, ()>
{
match &mut *self.expectations.lock().unwrap() {
None => self.backing.get_shutdown_scriptpubkey(),
Some(expectations) => match expectations.pop_front() {
None => panic!("Unexpected get_shutdown_scriptpubkey"),
match &mut *self.expectations.lock().unwrap() {
None => self.backing.get_shutdown_scriptpubkey(),
Some(expectations) => match expectations.pop_front() {
None => panic!("Unexpected get_shutdown_scriptpubkey"),
- Some(expectation) =>
expectation.returns
,
+ Some(expectation) =>
Ok(expectation.returns)
,
},
}
}
},
}
}
@@
-817,7
+826,7
@@
impl TestKeysInterface {
pub fn new(seed: &[u8; 32], network: Network) -> Self {
let now = Duration::from_secs(genesis_block(network).header.time as u64);
Self {
pub fn new(seed: &[u8; 32], network: Network) -> Self {
let now = Duration::from_secs(genesis_block(network).header.time as u64);
Self {
- backing:
keysinterface
::PhantomKeysManager::new(seed, now.as_secs(), now.subsec_nanos(), seed),
+ backing:
sign
::PhantomKeysManager::new(seed, now.as_secs(), now.subsec_nanos(), seed),
override_random_bytes: Mutex::new(None),
disable_revocation_policy_check: false,
enforcement_states: Mutex::new(HashMap::new()),
override_random_bytes: Mutex::new(None),
disable_revocation_policy_check: false,
enforcement_states: Mutex::new(HashMap::new()),
@@
-825,7
+834,7
@@
impl TestKeysInterface {
}
}
}
}
- /// Sets an expectation that [`
keysinterface
::SignerProvider::get_shutdown_scriptpubkey`] is
+ /// Sets an expectation that [`
sign
::SignerProvider::get_shutdown_scriptpubkey`] is
/// called.
pub fn expect(&self, expectation: OnGetShutdownScriptpubkey) -> &Self {
self.expectations.lock().unwrap()
/// called.
pub fn expect(&self, expectation: OnGetShutdownScriptpubkey) -> &Self {
self.expectations.lock().unwrap()
@@
-873,7
+882,7
@@
impl Drop for TestKeysInterface {
}
}
}
}
-/// An expectation that [`
keysinterface
::SignerProvider::get_shutdown_scriptpubkey`] was called and
+/// An expectation that [`
sign
::SignerProvider::get_shutdown_scriptpubkey`] was called and
/// returns a [`ShutdownScript`].
pub struct OnGetShutdownScriptpubkey {
/// A shutdown script used to close a channel.
/// returns a [`ShutdownScript`].
pub struct OnGetShutdownScriptpubkey {
/// A shutdown script used to close a channel.
@@
-974,13
+983,13
@@
impl Score for TestScorer {
0
}
0
}
- fn payment_path_failed(&mut self, _actual_path: &
[&RouteHop]
, _actual_short_channel_id: u64) {}
+ fn payment_path_failed(&mut self, _actual_path: &
Path
, _actual_short_channel_id: u64) {}
- fn payment_path_successful(&mut self, _actual_path: &
[&RouteHop]
) {}
+ fn payment_path_successful(&mut self, _actual_path: &
Path
) {}
- fn probe_failed(&mut self, _actual_path: &
[&RouteHop]
, _: u64) {}
+ fn probe_failed(&mut self, _actual_path: &
Path
, _: u64) {}
- fn probe_successful(&mut self, _actual_path: &
[&RouteHop]
) {}
+ fn probe_successful(&mut self, _actual_path: &
Path
) {}
}
impl Drop for TestScorer {
}
impl Drop for TestScorer {