simplify CC tests
This commit is contained in:
@@ -8,87 +8,49 @@ from testsupport import *
|
|||||||
|
|
||||||
@fanout_input(0)
|
@fanout_input(0)
|
||||||
def test_basic_spend(inp):
|
def test_basic_spend(inp):
|
||||||
spend0 = {
|
spend = {'inputs': [inp], "outputs": [nospend]}
|
||||||
'inputs': [inp],
|
spend_txid = submit(sign(spend))
|
||||||
"outputs": [
|
assert rpc.getrawtransaction(spend_txid)
|
||||||
{"amount": 500, "script": {"condition": cond_alice}},
|
|
||||||
{"amount": 500, "script": {"address": notary_addr}}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
spend0_txid = submit(sign(spend0))
|
|
||||||
spend1 = {
|
|
||||||
'inputs': [
|
|
||||||
{'txid': spend0_txid, 'idx': 0, 'script': {"fulfillment": cond_alice}},
|
|
||||||
{'txid': spend0_txid, 'idx': 1, 'script': {'address': notary_addr}}
|
|
||||||
],
|
|
||||||
'outputs': [{"amount": 1000, "script": {"address": notary_addr}}]
|
|
||||||
}
|
|
||||||
spend1_txid = submit(sign(spend1))
|
|
||||||
assert rpc.getrawtransaction(spend1_txid)
|
|
||||||
|
|
||||||
|
|
||||||
@fanout_input(1)
|
@fanout_input(1)
|
||||||
def test_fulfillment_wrong_signature(inp):
|
def test_fulfillment_wrong_signature(inp):
|
||||||
spend0 = {
|
# Set other pubkey and sign
|
||||||
'inputs': [inp],
|
inp['script']['fulfillment']['publicKey'] = bob_pk
|
||||||
"outputs": [{"amount": 1000, "script": {"condition": cond_bob}}]
|
spend = {'inputs': [inp], 'outputs': [nospend]}
|
||||||
}
|
signed = sign(spend)
|
||||||
spend0_txid = submit(sign(spend0))
|
|
||||||
spend1 = {
|
|
||||||
'inputs': [{'txid': spend0_txid, 'idx': 0, 'script': {"fulfillment": cond_alice}}],
|
|
||||||
'outputs': [{"amount": 1000, "script": {"address": notary_addr}}]
|
|
||||||
}
|
|
||||||
|
|
||||||
signed = sign(spend1)
|
|
||||||
# Set the correct pubkey, signature is wrong
|
# Set the correct pubkey, signature is wrong
|
||||||
signed['tx']['inputs'][0]['script']['fulfillment']['publicKey'] = bob_pk
|
signed['tx']['inputs'][0]['script']['fulfillment']['publicKey'] = alice_pk
|
||||||
|
|
||||||
try:
|
try:
|
||||||
assert not submit(sign(spend1)), 'should raise an error'
|
assert not submit(signed), 'should raise an error'
|
||||||
except RPCError as e:
|
except RPCError as e:
|
||||||
assert '16: mandatory-script-verify-flag-failed' in str(e), str(e)
|
assert 'Script evaluated without error but finished with a false/empty top stack element' in str(e), str(e)
|
||||||
|
|
||||||
|
|
||||||
@fanout_input(2)
|
@fanout_input(2)
|
||||||
def test_fulfillment_wrong_pubkey(inp):
|
def test_fulfillment_wrong_pubkey(inp):
|
||||||
spend0 = {
|
spend = {'inputs': [inp], 'outputs': [nospend]}
|
||||||
'inputs': [inp],
|
|
||||||
"outputs": [{"amount": 1000, "script": {"condition": cond_alice}}]
|
|
||||||
}
|
|
||||||
spend0_txid = submit(sign(spend0))
|
|
||||||
spend1 = {
|
|
||||||
'inputs': [{'txid': spend0_txid, 'idx': 0, 'script': {"fulfillment": cond_alice}}],
|
|
||||||
'outputs': [{"amount": 1000, "script": {"address": notary_addr}}]
|
|
||||||
}
|
|
||||||
|
|
||||||
signed = sign(spend1)
|
signed = sign(spend)
|
||||||
# Set the wrong pubkey, signature is correct
|
# Set the wrong pubkey, signature is correct
|
||||||
signed['tx']['inputs'][0]['script']['fulfillment']['publicKey'] = bob_pk
|
signed['tx']['inputs'][0]['script']['fulfillment']['publicKey'] = bob_pk
|
||||||
|
|
||||||
try:
|
try:
|
||||||
assert not submit(signed), 'should raise an error'
|
assert not submit(signed), 'should raise an error'
|
||||||
except RPCError as e:
|
except RPCError as e:
|
||||||
assert '16: mandatory-script-verify-flag-failed' in str(e), str(e)
|
assert 'Script evaluated without error but finished with a false/empty top stack element' in str(e), str(e)
|
||||||
|
|
||||||
|
|
||||||
@fanout_input(3)
|
@fanout_input(3)
|
||||||
def test_fulfillment_invalid_fulfillment(inp):
|
def test_fulfillment_invalid_fulfillment(inp):
|
||||||
spend0 = {
|
|
||||||
'inputs': [inp],
|
|
||||||
"outputs": [{"amount": 1000, "script": {"condition": cond_alice}}]
|
|
||||||
}
|
|
||||||
spend0_txid = submit(sign(spend0))
|
|
||||||
|
|
||||||
# Create a valid script with an invalid fulfillment payload
|
# Create a valid script with an invalid fulfillment payload
|
||||||
script = binascii.hexlify(b"\007invalid").decode('utf-8')
|
inp['script'] = binascii.hexlify(b"\007invalid").decode('utf-8')
|
||||||
|
spend = {'inputs': [inp], 'outputs': [nospend]}
|
||||||
spend1 = {
|
|
||||||
'inputs': [{'txid': spend0_txid, 'idx': 0, 'script': script}],
|
|
||||||
'outputs': [{"amount": 1000, "script": {"address": notary_addr}}]
|
|
||||||
}
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
assert not submit({'tx': spend1}), 'should raise an error'
|
assert not submit({'tx': spend}), 'should raise an error'
|
||||||
except RPCError as e:
|
except RPCError as e:
|
||||||
assert 'Crypto-Condition payload is invalid' in str(e), str(e)
|
assert 'Crypto-Condition payload is invalid' in str(e), str(e)
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ def wait_for_block(height):
|
|||||||
|
|
||||||
def sign(tx):
|
def sign(tx):
|
||||||
signed = hoek.signTxBitcoin({'tx': tx, 'privateKeys': [notary_sk]})
|
signed = hoek.signTxBitcoin({'tx': tx, 'privateKeys': [notary_sk]})
|
||||||
return hoek.signTxEd25519({'tx': signed['tx'], 'privateKeys': [alice_sk]})
|
return hoek.signTxEd25519({'tx': signed['tx'], 'privateKeys': [alice_sk, bob_sk]})
|
||||||
|
|
||||||
|
|
||||||
def submit(tx):
|
def submit(tx):
|
||||||
@@ -98,7 +98,7 @@ def get_fanout_txid():
|
|||||||
{'txid': reward_txid, 'idx': 0, 'script': {'pubkey': notary_pk}}
|
{'txid': reward_txid, 'idx': 0, 'script': {'pubkey': notary_pk}}
|
||||||
],
|
],
|
||||||
"outputs": (100 * [
|
"outputs": (100 * [
|
||||||
{"amount": 1000, "script": {"address": notary_addr}}
|
{"amount": 1000, "script": {"condition": cond_alice}}
|
||||||
] + [{"amount": remainder, 'script': {'address': notary_addr}}])
|
] + [{"amount": remainder, 'script': {'address': notary_addr}}])
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ def fanout_input(n):
|
|||||||
def wrapper():
|
def wrapper():
|
||||||
if not hasattr(fanout_input, 'txid'):
|
if not hasattr(fanout_input, 'txid'):
|
||||||
fanout_input.txid = get_fanout_txid()
|
fanout_input.txid = get_fanout_txid()
|
||||||
inp = {'txid': fanout_input.txid, 'idx': n, 'script': {'address': notary_addr}}
|
inp = {'txid': fanout_input.txid, 'idx': n, 'script': {'fulfillment': cond_alice}}
|
||||||
f(inp)
|
f(inp)
|
||||||
return functools.wraps(f)(wrapper)
|
return functools.wraps(f)(wrapper)
|
||||||
return decorate
|
return decorate
|
||||||
@@ -126,3 +126,4 @@ cond_alice = {"type": "ed25519-sha-256", "publicKey": alice_pk}
|
|||||||
bob_pk = 'C8MfEjKiFxDguacHvcM7MV83cRQ55RAHacC73xqg8qeu'
|
bob_pk = 'C8MfEjKiFxDguacHvcM7MV83cRQ55RAHacC73xqg8qeu'
|
||||||
bob_sk = 'GrP1fZdUxUc1NYmu7kiNkJV4p7PKpshp1yBY7hogPUWT'
|
bob_sk = 'GrP1fZdUxUc1NYmu7kiNkJV4p7PKpshp1yBY7hogPUWT'
|
||||||
cond_bob = {"type": "ed25519-sha-256", "publicKey": bob_pk}
|
cond_bob = {"type": "ed25519-sha-256", "publicKey": bob_pk}
|
||||||
|
nospend = {"amount": 1000, "script": {"address": notary_addr}}
|
||||||
|
|||||||
Reference in New Issue
Block a user