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 25f3d14
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 2 deletions.
90 changes: 89 additions & 1 deletion src/index/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl RuneEntry {
}

if let Some(cap) = mint.cap {
if self.mints > cap {
if self.mints >= cap {
return Err(MintError::Cap(cap));
}
}
Expand Down Expand Up @@ -565,4 +565,92 @@ 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),
..default()
}),
..default()
}
.mintable(Height(0), 0),
Ok(1000),
);

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

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

assert_eq!(
RuneEntry {
mint: Some(MintEntry {
deadline: Some(1),
limit: Some(1000),
..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)),
);
}
}
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 25f3d14

Please sign in to comment.