mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-04-28 04:13:14 +00:00
add constructors from ranges
This commit is contained in:
parent
953a1dacd3
commit
70ccb1befa
@ -323,6 +323,23 @@ impl ProgramOutput {
|
|||||||
self.validity_window.set_to(id)?;
|
self.validity_window.set_to(id)?;
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the validity window from an infallible range conversion (`1..`, `..5`, `..`).
|
||||||
|
#[must_use]
|
||||||
|
pub fn with_validity_window<W: Into<ValidityWindow>>(mut self, window: W) -> Self {
|
||||||
|
self.validity_window = window.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the validity window from a fallible range conversion (`1..5`).
|
||||||
|
/// Returns `Err` if the range is empty.
|
||||||
|
pub fn try_with_validity_window<W: TryInto<ValidityWindow, Error = InvalidWindow>>(
|
||||||
|
mut self,
|
||||||
|
window: W,
|
||||||
|
) -> Result<Self, InvalidWindow> {
|
||||||
|
self.validity_window = window.try_into()?;
|
||||||
|
Ok(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Representation of a number as `lo + hi * 2^128`.
|
/// Representation of a number as `lo + hi * 2^128`.
|
||||||
@ -571,6 +588,35 @@ mod tests {
|
|||||||
assert_eq!(w.to(), None);
|
assert_eq!(w.to(), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn program_output_try_with_validity_window_range() {
|
||||||
|
let output = ProgramOutput::new(vec![], vec![], vec![])
|
||||||
|
.try_with_validity_window(10_u64..100)
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(output.validity_window.from(), Some(10));
|
||||||
|
assert_eq!(output.validity_window.to(), Some(100));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn program_output_with_validity_window_range_from() {
|
||||||
|
let output = ProgramOutput::new(vec![], vec![], vec![]).with_validity_window(10_u64..);
|
||||||
|
assert_eq!(output.validity_window.from(), Some(10));
|
||||||
|
assert_eq!(output.validity_window.to(), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn program_output_with_validity_window_range_to() {
|
||||||
|
let output = ProgramOutput::new(vec![], vec![], vec![]).with_validity_window(..100_u64);
|
||||||
|
assert_eq!(output.validity_window.from(), None);
|
||||||
|
assert_eq!(output.validity_window.to(), Some(100));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn program_output_try_with_validity_window_empty_range_fails() {
|
||||||
|
let result = ProgramOutput::new(vec![], vec![], vec![]).try_with_validity_window(5_u64..5);
|
||||||
|
assert!(result.is_err());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn post_state_new_with_claim_constructor() {
|
fn post_state_new_with_claim_constructor() {
|
||||||
let account = Account {
|
let account = Account {
|
||||||
|
|||||||
@ -19,15 +19,12 @@ fn main() {
|
|||||||
|
|
||||||
let post = pre.account.clone();
|
let post = pre.account.clone();
|
||||||
|
|
||||||
let output = ProgramOutput::new(
|
ProgramOutput::new(
|
||||||
instruction_words,
|
instruction_words,
|
||||||
vec![pre],
|
vec![pre],
|
||||||
vec![AccountPostState::new(post)],
|
vec![AccountPostState::new(post)],
|
||||||
)
|
)
|
||||||
.valid_from_id(from_id)
|
.try_with_validity_window((from_id, until_id))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.valid_until_id(until_id)
|
.write();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
output.write();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,9 +44,7 @@ fn main() {
|
|||||||
vec![pre],
|
vec![pre],
|
||||||
vec![AccountPostState::new(post)],
|
vec![AccountPostState::new(post)],
|
||||||
)
|
)
|
||||||
.valid_from_id(from_id)
|
.try_with_validity_window((from_id, until_id))
|
||||||
.unwrap()
|
|
||||||
.valid_until_id(until_id)
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.with_chained_calls(vec![chained_call])
|
.with_chained_calls(vec![chained_call])
|
||||||
.write();
|
.write();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user