Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(wallet): create tx locktime cltv for a specific time #1682

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

f3r10
Copy link
Contributor

@f3r10 f3r10 commented Nov 13, 2024

Description

This PR adds a unit test that checks the satisfaction of timestamp-based timelocks. The goal is to test the absolute time therefore the variable passed to the miniscript fragment after has to be equal to or greater that 500_000_000 otherwise it would be checking the block height.

Notes to the reviewers

This unit test tries to check if #642 is still an issue.

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

@f3r10 f3r10 changed the title test: create tx locktime cltv for a specific time test(wallet): create tx locktime cltv for a specific time Nov 13, 2024
@f3r10 f3r10 marked this pull request as ready for review November 13, 2024 16:44
/// the parameter passed to miniscript fragment `after` has to equal or grather than 500_000_000
/// in order to use a lock based on unix time
pub fn get_test_single_sig_cltv_for_specific_time() -> &'static str {
"wsh(and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),after(500000000)))"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ just a nit but we should use a timestamp that's sometime after the genesis block. Sometimes people use these tests as examples so will make more sense to use a more recent time. Also the number is easier to read in the code with the underscores.

Suggested change
"wsh(and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),after(500000000)))"
"wsh(and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),after(1_734_230_218)))"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to update the descriptor as you mentioned, but there is an error with the format:
descriptors must be valid: Miniscript(Unexpected("unexpected «1_734_230_218»"))
It looks like miniscript does not have support for numbers with underscores.

@@ -160,6 +160,13 @@ pub fn get_test_single_sig_cltv() -> &'static str {
"wsh(and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),after(100000)))"
}

/// `wsh` descriptor with policy `and(pk(A),after(500_000_000))`
/// the parameter passed to miniscript fragment `after` has to equal or grather than 500_000_000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// the parameter passed to miniscript fragment `after` has to equal or grather than 500_000_000
/// the parameter passed to miniscript fragment `after` has to equal or greater than 500_000_000

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@f3r10 I don't think the extra commentary is needed, but we can make it a code comment as a note to developers and leave the doc string as a single line:

/// `wsh` descriptor with policy `and(pk(A),after(1734230218))`

Can you give this helper a better name, like get_test_single_sig_cltv_timestamp. I agree with the suggestion to use a realistic timestamp (without underscores).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ValuedMammal fixed with your comments.

However, based on what we talked about at the previous meeting, I was about to close this PR.
Do you think that this test is testing what is supposed to?

Maybe when the implementation of the planning module that you are working on is finished, this test will be more relevant. 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I think we should have the test, I'm not sure of another way to test that time based timelocks are satisfied.

@notmandatory notmandatory added this to the 1.0.0-beta milestone Nov 15, 2024
@notmandatory notmandatory removed this from the 1.0.0-beta milestone Nov 21, 2024
@f3r10 f3r10 force-pushed the test_timelock_descriptors branch from a636a6b to af30026 Compare December 21, 2024 21:00
Copy link
Contributor

@ValuedMammal ValuedMammal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK af30026

@ValuedMammal ValuedMammal added this to the 1.1.0 milestone Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs Review
Development

Successfully merging this pull request may close these issues.

3 participants