def test_segwit_create_tx(self): from pycoin_grs.tx.tx_utils import create_tx, sign_tx from pycoin_grs.tx.Spendable import Spendable from pycoin_grs.tx.pay_to.ScriptPayToAddress import ScriptPayToAddress from pycoin_grs.tx.pay_to.ScriptPayToAddressWit import ScriptPayToAddressWit from pycoin_grs.ui import address_for_pay_to_script_wit, script_obj_from_address key1 = Key(1) coin_value = 5000000 script = ScriptPayToAddressWit(b'\0', key1.hash160()).script() tx_hash = b'\ee' * 32 tx_out_index = 0 spendable = Spendable(coin_value, script, tx_hash, tx_out_index) key2 = Key(2) tx = create_tx([spendable], [(key2.address(), coin_value)]) self.check_unsigned(tx) sign_tx(tx, [key1.wif()]) self.check_signed(tx) self.assertEqual(len(tx.txs_in[0].witness), 2) s1 = ScriptPayToAddress(key1.hash160()).script() address = address_for_pay_to_script_wit(s1) spendable.script = script_obj_from_address(address).script() tx = create_tx([spendable], [(key2.address(), coin_value)]) self.check_unsigned(tx) sign_tx(tx, [key1.wif()], p2sh_lookup=build_p2sh_lookup([s1])) self.check_signed(tx)
def test_sign_verify(self): private_key = Key(secret_exponent=1) h = b"\x00" * 32 sig = private_key.sign(h) self.assertTrue(private_key.verify(h, sig)) public_key = private_key.public_copy() self.assertTrue(public_key.verify(h, sig)) h160_key = Key(hash160=private_key.hash160()) self.assertTrue(h160_key.verify(h, sig))