Skip to content

Commit b12c960

Browse files
committed
fixed gettransactions test
1 parent c7514ac commit b12c960

File tree

9 files changed

+41
-39
lines changed

9 files changed

+41
-39
lines changed

stackslib/src/chainstate/coordinator/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,12 @@ impl ChainsCoordinatorConfig {
223223
}
224224
}
225225

226-
pub fn test_new() -> ChainsCoordinatorConfig {
226+
pub fn test_new(txindex: bool) -> ChainsCoordinatorConfig {
227227
ChainsCoordinatorConfig {
228228
always_use_affirmation_maps: false,
229229
require_affirmed_anchor_blocks: false,
230230
assume_present_anchor_blocks: false,
231-
txindex: false,
231+
txindex,
232232
}
233233
}
234234
}
@@ -651,6 +651,7 @@ impl<T: BlockEventDispatcher, U: RewardSetProvider, B: BurnchainHeaderReader>
651651
path: &str,
652652
reward_set_provider: U,
653653
indexer: B,
654+
txindex: bool,
654655
) -> ChainsCoordinator<'a, T, (), U, (), (), B> {
655656
ChainsCoordinator::test_new_full(
656657
burnchain,
@@ -660,6 +661,7 @@ impl<T: BlockEventDispatcher, U: RewardSetProvider, B: BurnchainHeaderReader>
660661
None,
661662
indexer,
662663
None,
664+
txindex,
663665
)
664666
}
665667

@@ -673,6 +675,7 @@ impl<T: BlockEventDispatcher, U: RewardSetProvider, B: BurnchainHeaderReader>
673675
dispatcher: Option<&'a T>,
674676
burnchain_indexer: B,
675677
atlas_config: Option<AtlasConfig>,
678+
txindex: bool,
676679
) -> ChainsCoordinator<'a, T, (), U, (), (), B> {
677680
let burnchain = burnchain.clone();
678681

@@ -718,7 +721,7 @@ impl<T: BlockEventDispatcher, U: RewardSetProvider, B: BurnchainHeaderReader>
718721
notifier: (),
719722
atlas_config,
720723
atlas_db: Some(atlas_db),
721-
config: ChainsCoordinatorConfig::test_new(),
724+
config: ChainsCoordinatorConfig::test_new(txindex),
722725
burnchain_indexer,
723726
refresh_stacker_db: Arc::new(AtomicBool::new(false)),
724727
in_nakamoto_epoch: false,

stackslib/src/chainstate/coordinator/tests.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,13 +469,15 @@ pub fn make_coordinator<'a>(
469469
path,
470470
OnChainRewardSetProvider(None),
471471
indexer,
472+
false,
472473
)
473474
}
474475

475476
pub fn make_coordinator_atlas<'a>(
476477
path: &str,
477478
burnchain: Option<Burnchain>,
478479
atlas_config: Option<AtlasConfig>,
480+
txindex: bool,
479481
) -> ChainsCoordinator<
480482
'a,
481483
NullEventDispatcher,
@@ -495,6 +497,7 @@ pub fn make_coordinator_atlas<'a>(
495497
None,
496498
indexer,
497499
atlas_config,
500+
txindex,
498501
)
499502
}
500503

@@ -544,6 +547,7 @@ fn make_reward_set_coordinator<'a>(
544547
path,
545548
StubbedRewardSetProvider(addrs),
546549
indexer,
550+
false,
547551
)
548552
}
549553

@@ -4656,6 +4660,7 @@ fn atlas_stop_start() {
46564660
path,
46574661
Some(burnchain_conf.clone()),
46584662
Some(atlas_config.clone()),
4663+
false,
46594664
);
46604665

46614666
coord.handle_new_burnchain_block().unwrap();
@@ -4850,7 +4855,7 @@ fn atlas_stop_start() {
48504855
// now, we'll shut down all the coordinator connections and reopen them
48514856
// to ensure that the queue remains in place
48524857
let coord = (); // dispose of the coordinator, closing all its connections
4853-
let coord = make_coordinator_atlas(path, Some(burnchain_conf), Some(atlas_config));
4858+
let coord = make_coordinator_atlas(path, Some(burnchain_conf), Some(atlas_config), false);
48544859

48554860
let atlas_queue = coord
48564861
.atlas_db

stackslib/src/chainstate/nakamoto/coordinator/tests.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,21 +1631,18 @@ fn transactions_indexing() {
16311631
// compare transactions to what has been tracked
16321632
for tx in tracked_block.txs {
16331633
let current_tx_hex = to_hex(&tx.serialize_to_vec());
1634-
let (index_block_hash, tx_hex) =
1635-
NakamotoChainState::get_index_block_hash_and_tx_hex_from_txid(
1636-
&chainstate.index_conn(),
1637-
tx.txid(),
1638-
)
1639-
.unwrap()
1640-
.unwrap();
1634+
let (index_block_hash, tx_hex, _) =
1635+
NakamotoChainState::get_tx_info_from_txid(&chainstate.index_conn(), tx.txid())
1636+
.unwrap()
1637+
.unwrap();
16411638
assert_eq!(index_block_hash, tracked_block_id);
16421639
assert_eq!(tx_hex, current_tx_hex);
16431640
}
16441641

16451642
// ensure untracked transactions are not recorded
16461643
for tx in untracked_block.txs {
16471644
assert_eq!(
1648-
NakamotoChainState::get_index_block_hash_and_tx_hex_from_txid(
1645+
NakamotoChainState::get_tx_info_from_txid(
16491646
&chainstate.index_conn(),
16501647
tx.txid(),
16511648
)

stackslib/src/chainstate/nakamoto/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3564,20 +3564,20 @@ impl NakamotoChainState {
35643564
}
35653565

35663566
// Get index_block_hash and transaction payload hex by txid from the transactions table
3567-
pub fn get_index_block_hash_and_tx_hex_from_txid(
3567+
pub fn get_tx_info_from_txid(
35683568
conn: &Connection,
35693569
txid: Txid,
3570-
) -> Result<Option<(StacksBlockId, String)>, ChainstateError> {
3571-
let sql = "SELECT index_block_hash, tx_hex FROM transactions WHERE txid = ?";
3570+
) -> Result<Option<(StacksBlockId, String, String)>, ChainstateError> {
3571+
let sql = "SELECT index_block_hash, tx_hex, result FROM transactions WHERE txid = ?";
35723572
let args = params![txid];
35733573

35743574
let mut stmt = conn.prepare(sql)?;
35753575
Ok(stmt
35763576
.query_row(args, |row| {
35773577
let index_block_hash: StacksBlockId = row.get(0)?;
35783578
let tx_hex: String = row.get(1)?;
3579-
3580-
Ok((index_block_hash, tx_hex))
3579+
let result: String = row.get(2)?;
3580+
Ok((index_block_hash, tx_hex, result))
35813581
})
35823582
.optional()?)
35833583
}

stackslib/src/net/api/gettransactions.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use crate::burnchains::Txid;
3131
use crate::chainstate::burn::db::sortdb::SortitionDB;
3232
use crate::chainstate::nakamoto::NakamotoChainState;
3333
use crate::chainstate::stacks::db::StacksChainState;
34+
use crate::chainstate::stacks::StacksTransaction;
3435
use crate::core::mempool::MemPoolDB;
3536
use crate::net::http::{
3637
parse_json, Error, HttpNotFound, HttpNotImplemented, HttpRequest, HttpRequestContents,
@@ -48,6 +49,7 @@ use crate::net::{Error as NetError, StacksNodeState, TipRequest};
4849
pub struct TransactionResponse {
4950
pub index_block_hash: StacksBlockId,
5051
pub tx: String,
52+
pub result: String,
5153
}
5254

5355
#[derive(Clone)]
@@ -124,31 +126,28 @@ impl RPCRequestHandler for RPCGetTransactionRequestHandler {
124126
.ok_or(NetError::SendError("`txid` no set".into()))?;
125127

126128
node.with_node_state(|_network, _sortdb, chainstate, _mempool, _rpc_args| {
127-
let index_block_hash_and_tx_hex_opt =
128-
match NakamotoChainState::get_index_block_hash_and_tx_hex_from_txid(
129-
chainstate.index_conn().conn(),
130-
txid,
131-
) {
132-
Ok(index_block_hash_and_tx_hex_opt) => index_block_hash_and_tx_hex_opt,
133-
Err(e) => {
134-
// nope -- error trying to check
135-
let msg = format!("Failed to load transaction: {:?}\n", &e);
136-
warn!("{}", &msg);
137-
return StacksHttpResponse::new_error(
138-
&preamble,
139-
&HttpServerError::new(msg),
140-
)
129+
let index_block_hash_and_tx_hex_opt = match NakamotoChainState::get_tx_info_from_txid(
130+
chainstate.index_conn().conn(),
131+
txid,
132+
) {
133+
Ok(index_block_hash_and_tx_hex_opt) => index_block_hash_and_tx_hex_opt,
134+
Err(e) => {
135+
// nope -- error trying to check
136+
let msg = format!("Failed to load transaction: {:?}\n", &e);
137+
warn!("{}", &msg);
138+
return StacksHttpResponse::new_error(&preamble, &HttpServerError::new(msg))
141139
.try_into_contents()
142140
.map_err(NetError::from);
143-
}
144-
};
141+
}
142+
};
145143

146144
match index_block_hash_and_tx_hex_opt {
147-
Some((index_block_hash, tx_hex)) => {
145+
Some((index_block_hash, tx_hex, result)) => {
148146
let preamble = HttpResponsePreamble::ok_json(&preamble);
149147
let body = HttpResponseContents::try_from_json(&TransactionResponse {
150148
index_block_hash,
151149
tx: tx_hex,
150+
result,
152151
})?;
153152
return Ok((preamble, body));
154153
}

stackslib/src/net/api/tests/gettransactions.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,12 @@ fn test_try_make_response() {
164164

165165
// check genesis txid
166166
let response = responses.remove(0);
167-
let contents = response.get_http_payload_ok().unwrap();
168-
let response_json: serde_json::Value = contents.try_into().unwrap();
169-
println!("RESPONSE: {}", response_json);
170-
/*
171167
let resp = response.decode_gettransaction().unwrap();
172168

173169
let tx_bytes = hex_bytes(&resp.tx).unwrap();
174170
let stacks_transaction = StacksTransaction::consensus_deserialize(&mut &tx_bytes[..]).unwrap();
175171
assert_eq!(stacks_transaction.txid(), tx_genesis.txid());
176172
assert_eq!(stacks_transaction.serialize_to_vec(), tx_bytes);
177-
*/
178173

179174
// check tip txid
180175
let response = responses.remove(0);

stackslib/src/net/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3141,6 +3141,7 @@ pub mod test {
31413141
observer,
31423142
indexer,
31433143
None,
3144+
config.txindex,
31443145
);
31453146
coord.handle_new_burnchain_block().unwrap();
31463147

stackslib/src/net/tests/inv/nakamoto.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ where
517517
.with_test_signers(test_signers)
518518
.with_test_stackers(test_stackers),
519519
);
520+
520521
plan.initial_balances.append(&mut initial_balances);
521522

522523
let (peer, other_peers) = plan.boot_into_nakamoto_peers(boot_tenures, Some(observer));

stackslib/src/net/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ impl NakamotoBootPlan {
367367
peer_config.network_id = self.network_id;
368368
peer_config.private_key = self.private_key.clone();
369369
peer_config.txindex = self.txindex;
370+
370371
let addr = StacksAddress::from_public_keys(
371372
C32_ADDRESS_VERSION_TESTNET_SINGLESIG,
372373
&AddressHashMode::SerializeP2PKH,

0 commit comments

Comments
 (0)