Skip to content

Commit 86223f8

Browse files
WIP: Simplicity Functional Tests.
1 parent e2c6597 commit 86223f8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

test/functional/feature_taproot.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ def default_witness_taproot(ctx):
292292
suffix_annex = [annex]
293293
if get(ctx, "leaf") is None:
294294
return get(ctx, "inputs_keypath") + suffix_annex
295+
elif get(ctx, "leafversion") == LEAF_VERSION_TAPSIMPLICITY:
296+
return [bytes(get(ctx, "simplicity_program")), bytes(get(ctx, "script_taproot")), get(ctx, "controlblock")] + suffix_annex
295297
else:
296298
return get(ctx, "inputs") + [bytes(get(ctx, "script_taproot")), get(ctx, "controlblock")] + suffix_annex
297299

@@ -358,6 +360,8 @@ def default_scriptsig(ctx):
358360
"tapleaf": default_tapleaf,
359361
# The script to push, and include in the sighash, for a taproot script path spend.
360362
"script_taproot": default_script_taproot,
363+
# The simplicity program for a taproot simplicity spend.
364+
"simplicity_program": [],
361365
# The internal pubkey for a taproot script path spend (32 bytes).
362366
"pubkey_internal": default_pubkey_internal,
363367
# The negation flag of the internal pubkey for a taproot script path spend.
@@ -592,6 +596,8 @@ def byte_popper(expr):
592596
ERR_NO_SUCCESS = {"err_msg": "Script evaluated without error but finished with a false/empty top stack element"}
593597
ERR_EMPTY_WITNESS = {"err_msg": "Witness program was passed an empty witness"}
594598
ERR_CHECKSIGVERIFY = {"err_msg": "Script failed an OP_CHECKSIGVERIFY operation"}
599+
ERR_SIMPLICITY_BITSTREAM_EOF = {"err_msg": "Unexpected end of bitstream"}
600+
ERR_SIMPLICITY_BITSTREAM_UNUSED_BITS = {"err_msg": "Unused bits at the end of the program"}
595601

596602
VALID_SIGHASHES_ECDSA = [
597603
SIGHASH_ALL,
@@ -1116,6 +1122,13 @@ def predict_sigops_ratio(n, dummy_size):
11161122
tap = taproot_construct(pubs[0], scripts)
11171123
add_spender(spenders, "alwaysvalid/notsuccessx", tap=tap, leaf="op_success", inputs=[], standard=False, failure={"leaf": "normal"}) # err_msg differs based on opcode
11181124

1125+
# == Simplicity tests ==
1126+
1127+
tap = taproot_construct(pubs[0], [("simplicity_iden", bytes.fromhex("dbfefcfc7796acfc86b435c1f81ed8a165dab2649dc48b0f35f832647868fb5e"), LEAF_VERSION_TAPSIMPLICITY)])
1128+
add_spender(spenders, "simplicity/empty_program", tap=tap, leaf="simplicity_iden", simplicity_program=bytes.fromhex("20"), failure={"simplicity_program": b''}, **ERR_SIMPLICITY_BITSTREAM_EOF)
1129+
# tempoarily removed because random bit errors will cause differt sorts of Simplicity errors.
1130+
# add_spender(spenders, "simplicity/iden", tap=tap, leaf="simplicity_iden", simplicity_program=bytes.fromhex("20"), failure={"simplicity_program": bitflipper(bytes.fromhex("20"))}, **ERR_SIMPLICITY_BITSTREAM_UNUSED_BITS)
1131+
11191132
# == Legacy tests ==
11201133

11211134
# Also add a few legacy spends into the mix, so that transactions which combine taproot and pre-taproot spends get tested too.

0 commit comments

Comments
 (0)