From db2df2c37ba98cf7490122a9176f0cad17d94f85 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Thu, 22 Feb 2018 00:59:15 -0300 Subject: [PATCH] integration test for basic aux condition --- qa/cryptoconditions/test_integration.py | 42 ++++++++++++++++++++++++- src/cryptoconditions | 2 +- src/komodo_cryptoconditions.cpp | 7 ++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/qa/cryptoconditions/test_integration.py b/qa/cryptoconditions/test_integration.py index 24792cc60..d5b456953 100644 --- a/qa/cryptoconditions/test_integration.py +++ b/qa/cryptoconditions/test_integration.py @@ -74,7 +74,7 @@ def test_invalid_condition(inp): assert 'Script evaluated without error but finished with a false/empty top stack element' in str(e), str(e) -@fanout_input(19) +@fanout_input(5) def test_oversize_fulfillment(inp): # Create oversize fulfillment script where the total length is <2000 binscript = b'\x4d%s%s' % (struct.pack('h', 2000), b'a' * 2000) @@ -87,6 +87,46 @@ def test_oversize_fulfillment(inp): assert 'scriptsig-size' in str(e), str(e) +@fanout_input(6) +def test_aux_basic(inp): + aux_cond = { + 'type': 'aux-sha-256', + 'method': 'equals', + 'conditionAux': 'LTE', + 'fulfillmentAux': 'LTE' + } + + # Setup some aux outputs + spend0 = { + 'inputs': [inp], + 'outputs': [ + {'amount': 500, 'script': {'condition': aux_cond}}, + {'amount': 500, 'script': {'condition': aux_cond}} + ] + } + spend0_txid = submit(sign(spend0)) + assert rpc.getrawtransaction(spend0_txid) + + # Test a good fulfillment + spend1 = { + 'inputs': [{'txid': spend0_txid, 'idx': 0, 'script': {'fulfillment': aux_cond}}], + 'outputs': [{'amount': 500, 'script': {'condition': aux_cond}}] + } + spend1_txid = submit(sign(spend1)) + assert rpc.getrawtransaction(spend1_txid) + + # Test a bad fulfillment + aux_cond['fulfillmentAux'] = 'WYW' + spend2 = { + 'inputs': [{'txid': spend0_txid, 'idx': 1, 'script': {'fulfillment': aux_cond}}], + 'outputs': [{'amount': 500, 'script': {'condition': aux_cond}}] + } + try: + assert not submit(sign(spend2)), 'should raise an error' + except RPCError as e: + assert 'Script evaluated without error but finished with a false/empty top stack element' in str(e), str(e) + + if __name__ == '__main__': logging.basicConfig(level=logging.INFO) for name, f in globals().items(): diff --git a/src/cryptoconditions b/src/cryptoconditions index e33203ae3..0dcac79cf 160000 --- a/src/cryptoconditions +++ b/src/cryptoconditions @@ -1 +1 @@ -Subproject commit e33203ae3430d2682a4eb734ceaf63791eb0eb6d +Subproject commit 0dcac79cf9ffeda8aff9d3e9e41fa23ac8208486 diff --git a/src/komodo_cryptoconditions.cpp b/src/komodo_cryptoconditions.cpp index a7fcf9f99..9617add50 100644 --- a/src/komodo_cryptoconditions.cpp +++ b/src/komodo_cryptoconditions.cpp @@ -4,5 +4,10 @@ int CryptoConditionChecker::CheckAuxCondition(const CC *cond) const { - return true; + if (0 == strcmp((const char*)cond->method, "equals")) { + return (cond->conditionAuxLength == cond->fulfillmentAuxLength) && + (0 == memcmp(cond->conditionAux, cond->fulfillmentAux, cond->conditionAuxLength)); + } + printf("no defined behaviour for method:%s\n", cond->method); + return 0; }