Skip to content

Commit

Permalink
Realign the positions and update the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
brianp committed Nov 6, 2023
1 parent 641fa89 commit 92fca8f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion infrastructure/tari_script/src/op_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub enum Opcode {
/// if there is not a valid integer value on top of the stack. Fails with `StackUnderflow` if the stack is empty.
/// Fails with `VerifyFailed` if the block height < `height`.
CompareHeightVerify,
/// Pops the top of the stack as `height`, then pushes the value of (`height` - the current height) to the stack.
/// Pops the top of the stack as `height`, then pushes the value of (the current height - `height`) to the stack.
/// In other words, this opcode replaces the top of the stack with the difference between `height` and the
/// current height. Fails with `InvalidInput` if there is not a valid integer value on top of the stack. Fails
/// with `StackUnderflow` if the stack is empty.
Expand Down
8 changes: 4 additions & 4 deletions infrastructure/tari_script/src/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl TariScript {

// Here it is possible to underflow because the stack can take lower numbers where check
// height does not use a stack number and it's minimum can't be lower than 0.
let item = match target_height.checked_sub(block_height) {
let item = match block_height.checked_sub(target_height) {
Some(num) => StackItem::Number(num),
None => return Err(ScriptError::CompareFailed),
};
Expand Down Expand Up @@ -921,7 +921,7 @@ mod test {
let ctx = context_with_height(u64::try_from(block_height).unwrap());
assert_eq!(
script.execute_with_context(&inputs, &ctx).unwrap(),
Number(5 - block_height)
Number(block_height - 5)
);
}

Expand Down Expand Up @@ -1778,7 +1778,7 @@ mod test {
let ctx = context_with_height(24_u64);
let stack_item = script.execute_with_context(&inputs, &ctx);
assert!(stack_item.is_ok());
assert_eq!(stack_item.unwrap(), Number(76))
assert_eq!(stack_item.unwrap(), Number(-76))
}

#[test]
Expand All @@ -1789,7 +1789,7 @@ mod test {
let ctx = context_with_height(110_u64);
let stack_item = script.execute_with_context(&inputs, &ctx);
assert!(stack_item.is_ok());
assert_eq!(stack_item.unwrap(), Number(-10))
assert_eq!(stack_item.unwrap(), Number(10))
}

#[test]
Expand Down

0 comments on commit 92fca8f

Please sign in to comment.