Skip to content

Commit

Permalink
WIP: Simplicity Functional Tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
roconnor-blockstream committed Aug 23, 2023
1 parent f0b9722 commit 16fd80c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/functional/feature_taproot.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ def default_witness_taproot(ctx):
suffix_annex = [annex]
if get(ctx, "leaf") is None:
return get(ctx, "inputs_keypath") + suffix_annex
elif get(ctx, "leafversion") == LEAF_VERSION_TAPSIMPLICITY:
return [bytes(get(ctx, "simplicity_program")), bytes(get(ctx, "script_taproot")), get(ctx, "controlblock")] + suffix_annex
else:
return get(ctx, "inputs") + [bytes(get(ctx, "script_taproot")), get(ctx, "controlblock")] + suffix_annex

Expand Down Expand Up @@ -357,6 +359,8 @@ def default_scriptsig(ctx):
"tapleaf": default_tapleaf,
# The script to push, and include in the sighash, for a taproot script path spend.
"script_taproot": default_script_taproot,
# The simplicity program for a taproot simplicity spend.
"simplicity_program": [],
# The internal pubkey for a taproot script path spend (32 bytes).
"pubkey_internal": default_pubkey_internal,
# The negation flag of the internal pubkey for a taproot script path spend.
Expand Down Expand Up @@ -591,6 +595,8 @@ def byte_popper(expr):
ERR_NO_SUCCESS = {"err_msg": "Script evaluated without error but finished with a false/empty top stack element"}
ERR_EMPTY_WITNESS = {"err_msg": "Witness program was passed an empty witness"}
ERR_CHECKSIGVERIFY = {"err_msg": "Script failed an OP_CHECKSIGVERIFY operation"}
ERR_SIMPLICITY_BITSTREAM_EOF = {"err_msg": "Unexpected end of bitstream"}
ERR_SIMPLICITY_BITSTREAM_UNUSED_BITS = {"err_msg": "Unused bits at the end of the program"}

VALID_SIGHASHES_ECDSA = [
SIGHASH_ALL,
Expand Down Expand Up @@ -1115,6 +1121,13 @@ def predict_sigops_ratio(n, dummy_size):
tap = taproot_construct(pubs[0], scripts)
add_spender(spenders, "alwaysvalid/notsuccessx", tap=tap, leaf="op_success", inputs=[], standard=False, failure={"leaf": "normal"}) # err_msg differs based on opcode

# == Simplicity tests ==

tap = taproot_construct(pubs[0], [("simplicity_iden", bytes.fromhex("dbfefcfc7796acfc86b435c1f81ed8a165dab2649dc48b0f35f832647868fb5e"), LEAF_VERSION_TAPSIMPLICITY)])
add_spender(spenders, "simplicity/empty_program", tap=tap, leaf="simplicity_iden", simplicity_program=bytes.fromhex("20"), failure={"simplicity_program": b''}, **ERR_SIMPLICITY_BITSTREAM_EOF)
# tempoarily removed because random bit errors will cause differt sorts of Simplicity errors.
# 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)

# == Legacy tests ==

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

0 comments on commit 16fd80c

Please sign in to comment.