Skip to content

Commit 24d5033

Browse files
committed
Merge bitcoin/bitcoin#32114: test: Add encodable PUSHDATA1 examples to feature_taproot
f974359 test: Add encodable PUSHDATA1 examples to feature_taproot (Greg Sanders) Pull request description: Inspired by discussion in bitcoin/bitcoin#31640 (comment) I made an example adding coverage I think is missing, with some extra commentary that might help future contributors (including myself when I forget how it works again). Open for suggestions how we can make it more welcoming beyond this. cc darosior EthanHeilman sipa ACKs for top commit: janb84: Re-ACK [f974359](bitcoin/bitcoin@f974359) rkrux: ACK f974359 Tree-SHA512: 7544d41c39c13d245a8a33522e53f22b4dd7593c069631978303e5a349cd12cf9d45bed648c391618c4732831232c4b82b8de2bf6cba5bf5e1232501db926122
2 parents cfe025f + f974359 commit 24d5033

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

test/functional/feature_taproot.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,41 @@ def spenders_taproot_nonstandard():
12311231

12321232
return spenders
12331233

1234+
def sample_spenders():
1235+
1236+
# Create key(s) for output creation, as well as key and script-spends
1237+
secs = [generate_privkey() for _ in range(2)]
1238+
pubs = [compute_xonly_pubkey(sec)[0] for sec in secs]
1239+
1240+
# Create a list of scripts which will be built into a taptree
1241+
scripts = [
1242+
# leaf label, followed by CScript
1243+
("encodeable_pushdata1", CScript([OP_DROP, OP_PUSHDATA1, b'aa' * 75])),
1244+
("nonstd_encodeable_pushdata1", CScript([OP_PUSHDATA1, b'aa'])),
1245+
("dummyleaf", CScript([])),
1246+
]
1247+
1248+
# Build TaprootInfo using scripts and appropriate pubkey for output creation
1249+
tap = taproot_construct(pubs[0], scripts)
1250+
1251+
# Finally, add spender(s).
1252+
# Each spender embodies a test with an optional failure condition.
1253+
# These failure conditions allow for fine-grained success/failure
1254+
# conditions that are tested randomly.
1255+
spenders = []
1256+
1257+
# Named comment, using first leaf from scripts, with empty string as witness data, no optional fail condition
1258+
add_spender(spenders, comment="tutorial/pushdata1", tap=tap, leaf="encodeable_pushdata1", inputs=[b'\x00'], no_fail=True)
1259+
1260+
# Spender with alternative failure tapscript via over-riding "failure" dictionary, along with the failure's expected err_msg / ERR_*
1261+
add_spender(spenders, comment="tutorial/pushdata1redux", tap=tap, leaf="encodeable_pushdata1", inputs=[b'\x00'], failure={"leaf": "dummyleaf"}, **ERR_NO_SUCCESS)
1262+
1263+
# Spender that is non-standard but otherwise valid, with extraneous signature data from inner key for optional failure condition
1264+
add_spender(spenders, comment="tutorial/nonminpushdata1", tap=tap, leaf="nonstd_encodeable_pushdata1", key=secs[0], standard=False, failure={"inputs": [getter("sign")]}, **ERR_CLEANSTACK)
1265+
1266+
# New scripts=[] can be defined, and rinse-repeated as necessary until the spenders list is returned for execution
1267+
return spenders
1268+
12341269
# Consensus validation flags to use in dumps for tests with "legacy/" or "inactive/" prefix.
12351270
LEGACY_FLAGS = "P2SH,DERSIG,CHECKLOCKTIMEVERIFY,CHECKSEQUENCEVERIFY,WITNESS,NULLDUMMY"
12361271
# Consensus validation flags to use in dumps for all other tests.
@@ -1757,12 +1792,20 @@ def run_test(self):
17571792
self.gen_test_vectors()
17581793

17591794
self.log.info("Post-activation tests...")
1760-
self.test_spenders(self.nodes[0], spenders_taproot_active(), input_counts=[1, 2, 2, 2, 2, 3])
1795+
1796+
# New sub-tests not checking standardness can be added to consensus_spenders
1797+
# to allow for increased coverage across input types.
1798+
# See sample_spenders for a minimal example
1799+
consensus_spenders = sample_spenders()
1800+
consensus_spenders += spenders_taproot_active()
1801+
self.test_spenders(self.nodes[0], consensus_spenders, input_counts=[1, 2, 2, 2, 2, 3])
1802+
17611803
# Run each test twice; once in isolation, and once combined with others. Testing in isolation
17621804
# means that the standardness is verified in every test (as combined transactions are only standard
17631805
# when all their inputs are standard).
1764-
self.test_spenders(self.nodes[0], spenders_taproot_nonstandard(), input_counts=[1])
1765-
self.test_spenders(self.nodes[0], spenders_taproot_nonstandard(), input_counts=[2, 3])
1806+
nonstd_spenders = spenders_taproot_nonstandard()
1807+
self.test_spenders(self.nodes[0], nonstd_spenders, input_counts=[1])
1808+
self.test_spenders(self.nodes[0], nonstd_spenders, input_counts=[2, 3])
17661809

17671810

17681811
if __name__ == '__main__':

0 commit comments

Comments
 (0)