Skip to content

Commit

Permalink
txscript: Add isDustOutput test (#109)
Browse files Browse the repository at this point in the history
* txscript: Add isDustOutput test
  • Loading branch information
JoeGruffins authored Mar 16, 2020
1 parent ea056ec commit 3921de6
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions decred/tests/unit/dcr/test_txscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -3742,3 +3742,38 @@ def txWithTxOuts(outs):
assert (
res == test["want"]
), f'wanted {test["want"]} but got {res} for test {test["name"]}'


def test_is_dust_output():
def txOut(script, value):
return msgtx.TxOut(
version=wire.DefaultPkScriptVersion, pkScript=script, value=value
)

nullDataScript = parseShortForm("RETURN")
P2PKH = parseShortForm("DUP HASH160 DATA_20 NULL_BYTES_20 EQUALVERIFY CHECKSIG")
"""
name (str): Short description of the test.
output (wire.TxOut): The transaction output.
relayFeePerKb (int): Minimum transaction fee allowable.
want (bool): True if output is a dust output.
"""
tests = [
dict(name="not dust", output=txOut(P2PKH, 1e8), want=False,),
dict(name="zero amount", output=txOut(P2PKH, 0), want=True,),
dict(name="script length zero", output=txOut(ByteArray(b""), 0), want=True,),
dict(
name="starts with op return",
output=txOut(ByteArray(opcode.OP_RETURN) + P2PKH, 1e8),
want=True,
),
dict(name="script doesn't parse", output=txOut(P2PKH[:-3], 1e8), want=True,),
dict(name="null data script", output=txOut(nullDataScript, 0), want=False,),
]

for test in tests:
# No fee for all tests. Fee amounts are tested in test_is_dust_amount.
res = txscript.isDustOutput(test["output"], 0)
assert (
res == test["want"]
), f'wanted {test["want"]} but got {res} for test {test["name"]}'

0 comments on commit 3921de6

Please sign in to comment.