diff --git a/qa/rpc-tests/abc-p2p-fullblocktest.py b/qa/rpc-tests/abc-p2p-fullblocktest.py --- a/qa/rpc-tests/abc-p2p-fullblocktest.py +++ b/qa/rpc-tests/abc-p2p-fullblocktest.py @@ -323,9 +323,58 @@ # Rewind bad block tip(26) + # P2SH + # Build the redeem script, hash it, use hash to create the p2sh script + redeem_script = CScript([self.coinbase_pubkey] + [OP_2DUP, OP_CHECKSIGVERIFY]*5 + [OP_CHECKSIG]) + redeem_script_hash = hash160(redeem_script) + p2sh_script = CScript([OP_HASH160, redeem_script_hash, OP_EQUAL]) + + # Create a p2sh transaction with two outputs. The firt one is p2sh, the second one is anyone can spend + spend = out[22] + p2sh_tx = self.create_tx(spend.tx, spend.n,1000000000, p2sh_script) + p2sh_tx.vout.append(CTxOut(spend.tx.vout[spend.n].nValue-1000000000, CScript([OP_TRUE]))) + self.sign_tx(p2sh_tx, spend.tx, spend.n) + p2sh_tx.rehash() + + # Add the transaction to the block + block(29) + b29 = update_block(29,[p2sh_tx]) + yield accepted() + + # Validate the transaction hash + assert_equal(b29.vtx[1].sha256 == p2sh_tx.sha256, True) + + # Creates a new transaction using the p2sh transaction included in the last block + def spend_p2sh_tx (output_script=CScript([OP_TRUE])): + # Create the transaction + spent_p2sh_tx = CTransaction() + spent_p2sh_tx.vin.append(CTxIn(COutPoint(b29.vtx[1].sha256, 0), b'')) + spent_p2sh_tx.vout.append(CTxOut(1000000000, output_script)) + # Sign the transaction using the redeem script + (sighash, err) = SignatureHash(redeem_script, spent_p2sh_tx, 0, SIGHASH_ALL) + sig = self.coinbase_key.sign(sighash) + bytes(bytearray([SIGHASH_ALL])) + spent_p2sh_tx.vin[0].scriptSig = CScript([sig, redeem_script]) + spent_p2sh_tx.rehash() + return spent_p2sh_tx + + # Max valid sigops in the transaction output script + max_sigops = CScript([OP_CHECKSIG] * (MAX_BLOCK_SIGOPS_PER_MB - 1)) + block(30, block_size=ONE_MEGABYTE) + update_block(30,[spend_p2sh_tx(max_sigops)]) + yield rejected(RejectResult(16, b'bad-txn-sigops')) + + # Rewind bad block + tip(29) + + # Max valid sigops in the transaction output script minus redeem_script's sigops + valid_sigops = CScript([OP_CHECKSIG] * (MAX_BLOCK_SIGOPS_PER_MB - 1 - redeem_script.GetSigOpCount(True))) + block(31, block_size=ONE_MEGABYTE) + update_block(31,[spend_p2sh_tx(valid_sigops)]) + yield accepted() + # Too many sigops in one txn too_many_tx_checksigs = CScript([OP_CHECKSIG] * (MAX_BLOCK_SIGOPS_PER_MB + 1)) - block(29, spend=out[22], script=too_many_tx_checksigs, block_size=ONE_MEGABYTE + 1) + block(32, spend=out[23], script=too_many_tx_checksigs, block_size=ONE_MEGABYTE + 1) yield rejected(RejectResult(16, b'bad-txn-sigops'))