Skip to content

Commit

Permalink
Add p2pk unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryp Toon committed Apr 15, 2024
1 parent 1ea9443 commit 5938b3f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
10 changes: 8 additions & 2 deletions tests/test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,14 @@ def test_script_verify_transaction_input_p2wsh(self):
self.assertTrue(s.evaluate(message=transaction_hash, env_data=data))

def test_script_verify_transaction_input_p2pk(self):
pass
# TODO
p2pk_lockscript = '210312ed54eee6c84b440dd90623a714360196bebd842bfa64c7c7767b71b92a238dac' # key + checksig
p2pk_unlockscript = \
('463043021f52f02788988b941e3b810357762ccea5148e405edf124ea6b3b7eb9eba15430220609a9261612aaaa7544b7dae34'
'7b5dc3e53b0fc304957d6c4a46e1ae90a5d30001') # signature
script = p2pk_unlockscript + p2pk_lockscript
s = Script.parse_hex(script)
transaction_hash = bytes.fromhex("67b94bf5a5c17a5f6b2bedbefc51a17db669ce7ff3bbbc4943cfd876d68df986")
self.assertTrue(s.evaluate(message=transaction_hash))

def test_script_verify_transaction_output_return(self):
script = bytes.fromhex('6a26062c74e4b802d60ffdd1daa37b848e39a2b0ecb2de72c6ca24d71b87813b5e056cb7f1e8c8b0')
Expand Down
15 changes: 14 additions & 1 deletion tests/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ def test_transaction_errors(self):
class TestTransactionsScripts(unittest.TestCase, CustomAssertions):

# def test_transaction_redeemscript_errors(self):
# exp_error = "Redeemscripts with more then 15 keys are non-standard and could result in locked up funds"
# exp_error = "Redeemscripts with more than 15 keys are non-standard and could result in locked up funds"
# keys = []
# for n in range(20):
# keys.append(HDKey().public_hex)
Expand Down Expand Up @@ -1062,6 +1062,19 @@ def test_transaction_p2pk_script(self):
self.assertEqual(t.inputs[0].script_type, 'signature')
self.assertEqual(t.outputs[0].script_type, 'p2pk')

wif = 'tprv8ZgxMBicQKsPdx411rqb5SjGvY43Bjc2PyhU2UCVtbEwCDSyKzHhaM88XaKHe5LcyNVdwWgG9NBut4oytRLbhr7iHbJ7KxioG' \
'nQETYvZu3j'
k = HDKey(wif)
rawtx = ('0100000001cb7b368efcf5f17b09e9e43ec3907cbed622a5b4b33addb4c9c6f0b8ce855c9f0000000047463043021f52f0278'
'8988b941e3b810357762ccea5148e405edf124ea6b3b7eb9eba15430220609a9261612aaaa7544b7dae347b5dc3e53b0fc304'
'957d6c4a46e1ae90a5d30001ffffffff01581b00000000000023210312ed54eee6c84b440dd90623a714360196bebd842bfa6'
'4c7c7767b71b92a238dac00000000')
t = Transaction.parse_hex(rawtx, network='testnet')
t.inputs[0].keys = [k.public()]
t.update_inputs(0)
t.sign_and_update()
self.assertTrue(t.verify())

def test_transaction_sign_uncompressed(self):
ki = Key('cTuDU2P6AhB72ZrhHRnFTcZRoHdnoWkp7sSMPCBnrMG23nRNnjUX',
compressed=False)
Expand Down

0 comments on commit 5938b3f

Please sign in to comment.