def test_sign_pay_to_script_multisig(self):
    (M, N) = (3, 3)
    keys = [Key(secret_exponent=i, generator=secp256k1_generator) for i in range(1, (N + 2))]
    tx_in = TxIn.coinbase_tx_in(script=b'')
    underlying_script = script_for_multisig(m=M, sec_keys=[key.sec() for key in keys[:N]])
    address = address_for_p2s(underlying_script)
    self.assertEqual(address, '39qEwuwyb2cAX38MFtrNzvq3KV9hSNov3q')
    script = script_for_address(address)
    tx_out = TxOut(1000000, script)
    tx1 = Tx(version=1, txs_in=[tx_in], txs_out=[tx_out])
    tx2 = tx_utils.create_tx(tx1.tx_outs_as_spendable(), [address])
    hash160_lookup = build_hash160_lookup((key.secret_exponent() for key in keys[:N]), [secp256k1_generator])
    p2sh_lookup = build_p2sh_lookup([underlying_script])
    tx2.sign(hash160_lookup=hash160_lookup, p2sh_lookup=p2sh_lookup)
    self.assertEqual(tx2.bad_solution_count(), 0)
def test_sign_pay_to_script_multisig(self):
    (M, N) = (3, 3)
    keys = [Key(secret_exponent=i, generator=secp256k1_generator) for i in range(1, (N + 2))]
    tx_in = TxIn.coinbase_tx_in(script=b)
    underlying_script = script_for_multisig(m=M, sec_keys=[key.sec() for key in keys[:N]])
    address = address_for_p2s(underlying_script)
    self.assertEqual(address, '39qEwuwyb2cAX38MFtrNzvq3KV9hSNov3q')
    script = script_for_address(address)
    tx_out = TxOut(1000000, script)
    tx1 = Tx(version=1, txs_in=[tx_in], txs_out=[tx_out])
    tx2 = tx_utils.create_tx(tx1.tx_outs_as_spendable(), [address])
    hash160_lookup = build_hash160_lookup((key.secret_exponent() for key in keys[:N]), [secp256k1_generator])
    p2sh_lookup = build_p2sh_lookup([underlying_script])
    tx2.sign(hash160_lookup=hash160_lookup, p2sh_lookup=p2sh_lookup)
    self.assertEqual(tx2.bad_solution_count(), 0)