Skip to content

Commit

Permalink
Test mintable
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Mar 25, 2024
1 parent 198b24f commit 0f15644
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 5 deletions.
114 changes: 110 additions & 4 deletions src/index/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ impl RuneEntry {
}
}

if let Some(cap) = mint.cap {
if self.mints > cap {
return Err(MintError::Cap(cap));
}
let cap = mint.cap.unwrap_or_default();

if self.mints >= cap {
return Err(MintError::Cap(cap));
}

Ok(mint.limit.unwrap_or_default())
Expand Down Expand Up @@ -565,4 +565,110 @@ mod tests {

assert_eq!(actual, expected);
}

#[test]
fn mintable() {
assert_eq!(
RuneEntry::default().mintable(Height(0), 0),
Err(MintError::Unmintable)
);

assert_eq!(
RuneEntry {
mint: Some(MintEntry {
end: Some(1),
limit: Some(1000),
cap: Some(1),
..default()
}),
..default()
}
.mintable(Height(0), 0),
Ok(1000),
);

assert_eq!(
RuneEntry {
mint: Some(MintEntry {
end: Some(1),
limit: Some(1000),
cap: Some(1),
..default()
}),
..default()
}
.mintable(Height(1), 0),
Err(MintError::End(1)),
);

assert_eq!(
RuneEntry {
mint: Some(MintEntry {
deadline: Some(1),
limit: Some(1000),
cap: Some(1),
..default()
}),
..default()
}
.mintable(Height(0), 0),
Ok(1000),
);

assert_eq!(
RuneEntry {
mint: Some(MintEntry {
deadline: Some(1),
limit: Some(1000),
cap: Some(1),
..default()
}),
..default()
}
.mintable(Height(0), 1),
Err(MintError::Deadline(1)),
);

assert_eq!(
RuneEntry {
mint: Some(MintEntry {
cap: Some(1),
limit: Some(1000),
..default()
}),
mints: 0,
..default()
}
.mintable(Height(0), 0),
Ok(1000),
);

assert_eq!(
RuneEntry {
mint: Some(MintEntry {
cap: Some(1),
limit: Some(1000),
..default()
}),
mints: 1,
..default()
}
.mintable(Height(0), 1),
Err(MintError::Cap(1)),
);

assert_eq!(
RuneEntry {
mint: Some(MintEntry {
cap: None,
limit: Some(1000),
..default()
}),
mints: 0,
..default()
}
.mintable(Height(0), 1),
Err(MintError::Cap(0)),
);
}
}
2 changes: 1 addition & 1 deletion src/runes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub mod varint;

type Result<T, E = Error> = std::result::Result<T, E>;

#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub enum MintError {
Cap(u128),
Deadline(u32),
Expand Down

0 comments on commit 0f15644

Please sign in to comment.