Skip to content

Commit afe0f79

Browse files
committed
refactor tx_template and init_graph fn to use Cow
- refactor tx_template struct and init_graph to use Cow type - update the chain test_tx_graph test to use the updated tx_template struct and init_graph fn - update the test_tx_graph_conflicts to use the updated tx_template and init_graph fn [Issue: 1754]
1 parent 0223527 commit afe0f79

File tree

3 files changed

+251
-240
lines changed

3 files changed

+251
-240
lines changed

crates/chain/tests/test_tx_graph.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use bitcoin::{
1818
};
1919
use core::iter;
2020
use rand::RngCore;
21+
use std::borrow::Cow;
2122
use std::sync::Arc;
2223
use std::vec;
2324

@@ -1135,28 +1136,28 @@ fn call_map_anchors_with_non_deterministic_anchor() {
11351136

11361137
let template = [
11371138
TxTemplate {
1138-
tx_name: "tx1",
1139-
inputs: &[TxInTemplate::Bogus],
1140-
outputs: &[TxOutTemplate::new(10000, Some(1))],
1141-
anchors: &[block_id!(1, "A")],
1139+
tx_name: Cow::Borrowed("tx1"),
1140+
inputs: vec![TxInTemplate::Bogus],
1141+
outputs: vec![TxOutTemplate::new(10000, Some(1))],
1142+
anchors: vec![block_id!(1, "A")],
11421143
last_seen: None,
11431144
},
11441145
TxTemplate {
1145-
tx_name: "tx2",
1146-
inputs: &[TxInTemplate::PrevTx("tx1", 0)],
1147-
outputs: &[TxOutTemplate::new(20000, Some(2))],
1148-
anchors: &[block_id!(2, "B")],
1146+
tx_name: Cow::Borrowed("tx2"),
1147+
inputs: vec![TxInTemplate::PrevTx(Cow::Borrowed("tx1"), 0)],
1148+
outputs: vec![TxOutTemplate::new(20000, Some(2))],
1149+
anchors: vec![block_id!(2, "B")],
11491150
..Default::default()
11501151
},
11511152
TxTemplate {
1152-
tx_name: "tx3",
1153-
inputs: &[TxInTemplate::PrevTx("tx2", 0)],
1154-
outputs: &[TxOutTemplate::new(30000, Some(3))],
1155-
anchors: &[block_id!(3, "C"), block_id!(4, "D")],
1153+
tx_name: Cow::Borrowed("tx3"),
1154+
inputs: vec![TxInTemplate::PrevTx(Cow::Borrowed("tx2"), 0)],
1155+
outputs: vec![TxOutTemplate::new(30000, Some(3))],
1156+
anchors: vec![block_id!(3, "C"), block_id!(4, "D")],
11561157
..Default::default()
11571158
},
11581159
];
1159-
let (graph, _, _) = init_graph(&template);
1160+
let (graph, _, _) = init_graph(template);
11601161
let new_graph = graph.clone().map_anchors(|a| NonDeterministicAnchor {
11611162
anchor_block: a,
11621163
// A non-deterministic value

0 commit comments

Comments
 (0)