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

CLTV: Add more tests to improve coverage #6368

Merged
merged 1 commit into from Jul 9, 2015
Merged

Conversation

@eordano
Copy link
Contributor

eordano commented Jul 3, 2015

This should be a pretty straightforward code review, adding a few tests to the script interpreter when CHECKLOCKTIMEVERIFY is enabled.

The test cases improve coverage for these cases:

  • The CLTV operand type mismatches the tx locktime. In the script it is 1 (interpreted as block height), but in the tx is 500000000 (interpreted as date)
  • The stack is empty when executing OP_CLTV
  • The tx is final by having only one input with MAX_INT sequence number
  • The operand for CLTV is negative (after OP_0 OP_1 OP_SUB)
@laanwj laanwj added the Tests label Jul 3, 2015
@petertodd
petertodd reviewed Jul 3, 2015
View changes
src/test/data/tx_invalid.json Outdated
@@ -185,5 +185,21 @@
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "HASH160 0x14 0xc5b93064159b3b2d6ab506a41b1f50463771b988 EQUAL"]],
"0100000001000100000000000000000000000000000000000000000000000000000000000000000000030251b1000000000100000000000000000000000000", "P2SH,CHECKLOCKTIMEVERIFY"],

["Failure due to non-matching CHECKLOCKTIMEVERIFY kind"],
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "1"]],
"01000000010001000000000000000000000000000000000000000000000000000000000000000000000251b100000000010000000000000000000065cd1d", "P2SH,CHECKLOCKTIMEVERIFY"],

This comment has been minimized.

Copy link
@petertodd

petertodd Jul 3, 2015

Contributor

Seems that this test is nearly identical to the one at https://github.com/eordano/bitcoin/blob/test/cltv/src/test/data/tx_invalid.json#L160, other than being in the scriptSig vs. scriptPubKey, and using 1 as the threshold rather than 0. Is that correct, or am I misunderstanding something?

@petertodd
petertodd reviewed Jul 3, 2015
View changes
src/test/data/tx_invalid.json Outdated

["Failure due to an empty stack for CHECKLOCKTIMEVERIFY"],
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "1"]],
"010000000100010000000000000000000000000000000000000000000000000000000000000000000001b1010000000100000000000000000000000000", "P2SH,CHECKLOCKTIMEVERIFY"],

This comment has been minimized.

Copy link
@petertodd

petertodd Jul 3, 2015

Contributor

Duplicate of https://github.com/eordano/bitcoin/blob/test/cltv/src/test/data/tx_invalid.json#L139, but triggered in the scriptSig instead of scriptPubKey. How about you move this test to be next to that one to keep the similar testcases together?

@petertodd
petertodd reviewed Jul 3, 2015
View changes
src/test/data/tx_invalid.json Outdated

["Failure due to a non-final input in CHECKLOCKTIMEVERIFY"],
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "1"]],
"01000000010001000000000000000000000000000000000000000000000000000000000000000000000251b1ffffffff0100000000000000000002000000", "P2SH,CHECKLOCKTIMEVERIFY"],

This comment has been minimized.

Copy link
@petertodd

petertodd Jul 3, 2015

Contributor

Again, lets move this to be next to https://github.com/eordano/bitcoin/blob/test/cltv/src/test/data/tx_invalid.json#L151 to keep the similar tests together. Very good idea to test this one though with both scriptPubKey and scriptSig versions! Come to think of it, adding a version that's in a redeemScript as well it wouldn't be a bad idea.

@petertodd
petertodd reviewed Jul 3, 2015
View changes
src/test/data/tx_invalid.json Outdated

["Failure due to a negative locktime in CHECKLOCKTIMEVERIFY"],
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "1"]],
"010000000100010000000000000000000000000000000000000000000000000000000000000000000004005194b1010000000100000000000000000002000000", "P2SH,CHECKLOCKTIMEVERIFY"],

This comment has been minimized.

@petertodd
Copy link
Contributor

petertodd commented Jul 3, 2015

Thanks for the review!

Four cases included:

* The CLTV operand type mismatches the tx locktime. In the script it is
  1 (interpreted as block height), but in the tx is 500000000
  (interpreted as date)
* The stack is empty when executing OP_CLTV
* The tx is final by having only one input with MAX_INT sequence number
* The operand for CLTV is negative (after OP_0 OP_1 OP_SUB)
@petertodd
Copy link
Contributor

petertodd commented Jul 9, 2015

Looks good now, ACK

@laanwj
Copy link
Member

laanwj commented Jul 9, 2015

ACK

@laanwj laanwj merged commit cb54d17 into bitcoin:master Jul 9, 2015
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
laanwj added a commit that referenced this pull request Jul 9, 2015
cb54d17 CLTV: Add more tests to improve coverage (Esteban Ordano)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.