Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
twosatsmaxi committed Sep 5, 2024
1 parent 6915fee commit c0788d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1416,13 +1416,15 @@ impl Index {

let sequence_number_to_children = rtx.open_multimap_table(SEQUENCE_NUMBER_TO_CHILDREN)?;
let sequence_number_to_inscription_entry =
rtx.open_table(SEQUENCE_NUMBER_TO_INSCRIPTION_ENTRY)?;
rtx.open_table(SEQUENCE_NUMBER_TO_INSCRIPTION_ENTRY)?;
if index < 0 {
sequence_number_to_children
.get(sequence_number)?
.nth_back((index + 1).abs_diff(0))
} else {
sequence_number_to_children.get(sequence_number)?.nth(index.abs_diff(0))
sequence_number_to_children
.get(sequence_number)?
.nth(index.abs_diff(0))
}
.map(|result| {
result
Expand All @@ -1433,7 +1435,8 @@ impl Index {
.map(|entry| InscriptionEntry::load(entry.unwrap().value()).id)
})
.map_err(|err| anyhow!(err.to_string()))
}).transpose()
})
.transpose()
}
#[cfg(test)]
pub(crate) fn get_inscription_id_by_inscription_number(
Expand Down
18 changes: 11 additions & 7 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ impl Server {
"/r/children/:inscription_id/inscriptions",
get(Self::child_inscriptions_recursive),
)
.route(
"/r/children/:inscription_id/inscriptions/at/:index",
get(Self::child_inscription_at_index),
)
.route(
"/r/children/:inscription_id/inscriptions/at/:index",
get(Self::child_inscription_at_index),
)
.route(
"/r/children/:inscription_id/inscriptions/:page",
get(Self::child_inscriptions_recursive_paginated),
Expand Down Expand Up @@ -1894,7 +1894,8 @@ impl Server {
.get_inscription_entry(parent)?
.ok_or_not_found(|| format!("inscription {parent}"))?;

let id = index.get_children_at_index_by_sequence_number(entry.sequence_number, inscription_index)?
let id = index
.get_children_at_index_by_sequence_number(entry.sequence_number, inscription_index)?
.ok_or_not_found(|| format!("child {inscription_index}"))?;

let satpoint = index
Expand Down Expand Up @@ -6267,7 +6268,8 @@ next

server.mine_blocks(1);

let children_json = server.get_json::<api::Children>(format!("/r/children/{parent_inscription_id}"));
let children_json =
server.get_json::<api::Children>(format!("/r/children/{parent_inscription_id}"));
assert_eq!(children_json.ids.len(), 0);

let mut builder = script::Builder::new();
Expand All @@ -6291,7 +6293,9 @@ next

server.mine_blocks(1);
let latest_child_inscription_id = InscriptionId { txid, index: 110 };
let children_json = server.get_json::<api::ChildInscriptionRecursive>(format!("/r/children/{parent_inscription_id}/inscriptions/at/-1"));
let children_json = server.get_json::<api::ChildInscriptionRecursive>(format!(
"/r/children/{parent_inscription_id}/inscriptions/at/-1"
));
assert_eq!(children_json.id, latest_child_inscription_id);
}

Expand Down

0 comments on commit c0788d8

Please sign in to comment.