Skip to content

Commit

Permalink
fix(test): UTXO timelock >= -> >
Browse files Browse the repository at this point in the history
Time needs to be greater than release data, not greater than
or equal to.

Also adds a test that this is how the consensus program type script is
implemented.
  • Loading branch information
Sword-Smith committed Nov 27, 2024
1 parent 16e4340 commit 8f72470
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/models/blockchain/transaction/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,10 @@ mod utxo_tests {
prop_assert!(!utxo.can_spend_at(release_date - delta));
prop_assert!(utxo.is_timelocked_but_otherwise_spendable_at(release_date - delta));

prop_assert!(utxo.can_spend_at(release_date));
let epsilon = Timestamp::millis(1);
prop_assert!(!utxo.can_spend_at(release_date - epsilon));
prop_assert!(!utxo.can_spend_at(release_date));
prop_assert!(utxo.can_spend_at(release_date + epsilon));
prop_assert!(utxo.can_spend_at(release_date + delta));
prop_assert!(!utxo.is_timelocked_but_otherwise_spendable_at(release_date + delta));
}
Expand Down
33 changes: 33 additions & 0 deletions src/models/blockchain/type_scripts/time_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,9 +1051,12 @@ fn arbitrary_primitive_witness_with_timelocks(
mod test {
use num_traits::Zero;
use proptest::collection::vec;
use proptest::prelude::Arbitrary;
use proptest::prelude::Strategy;
use proptest::prop_assert;
use proptest::prop_assert_eq;
use proptest::strategy::Just;
use proptest::test_runner::TestRunner;
use proptest_arbitrary_interop::arb;
use test_strategy::proptest;
use tokio::runtime::Runtime;
Expand Down Expand Up @@ -1097,6 +1100,36 @@ mod test {
prop_assert_eq!(rust_result.unwrap(), tasm_result.unwrap());
}

#[test]
fn tx_timestamp_same_as_release_time_must_fail() {
// Verify use of `>`, not `>=`.
let release_date = Timestamp::now();
let mut test_runner = TestRunner::deterministic();
let time_lock_witness =
TimeLockWitness::arbitrary_with((vec![release_date], 1, 0, release_date))
.new_tree(&mut test_runner)
.unwrap()
.current();
assert!(
TimeLock {}
.run_rust(
&time_lock_witness.standard_input(),
time_lock_witness.nondeterminism(),
)
.is_err(),
"time lock program failed to panic"
);
assert!(
TimeLock {}
.run_tasm(
&time_lock_witness.standard_input(),
time_lock_witness.nondeterminism(),
)
.is_err(),
"time lock program failed to panic"
);
}

#[proptest(cases = 20)]
fn test_locked(
#[strategy(1usize..=3)] _num_inputs: usize,
Expand Down

0 comments on commit 8f72470

Please sign in to comment.