diff --git a/qa/pull-tester/rpc-tests.py b/qa/pull-tester/rpc-tests.py index 0a0d639b69720..9200811b14558 100755 --- a/qa/pull-tester/rpc-tests.py +++ b/qa/pull-tester/rpc-tests.py @@ -123,6 +123,7 @@ 'abandonconflict.py', 'p2p-versionbits-warning.py', 'p2p-segwit.py', + 'segwit.py', 'importprunedfunds.py', ] if ENABLE_ZMQ: diff --git a/qa/rpc-tests/p2p-segwit.py b/qa/rpc-tests/p2p-segwit.py index b241bac26e4ce..5dd0d226be970 100755 --- a/qa/rpc-tests/p2p-segwit.py +++ b/qa/rpc-tests/p2p-segwit.py @@ -1,8 +1,7 @@ #!/usr/bin/env python2 -# -# Distributed under the MIT/X11 software license, see the accompanying +# Copyright (c) 2016 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. -# from test_framework.mininode import * from test_framework.test_framework import BitcoinTestFramework @@ -212,7 +211,7 @@ def test_non_witness_transaction(self): # Create a transaction that spends the coinbase tx = CTransaction() - tx.vin.append(CTxIn(COutPoint(txid, 0), "")) + tx.vin.append(CTxIn(COutPoint(txid, 0), b"")) tx.vout.append(CTxOut(49*100000000, CScript([OP_TRUE]))) tx.calc_sha256() @@ -237,7 +236,7 @@ def test_unnecessary_witness_before_segwit_activation(self): assert(get_bip9_status(self.nodes[0], 'witness')['status'] != 'active') tx = CTransaction() - tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), "")) + tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")) tx.vout.append(CTxOut(self.utxo[0].nValue-1000, CScript([OP_TRUE]))) tx.wit.vtxinwit.append(CTxinWitness()) tx.wit.vtxinwit[0].scriptWitness.stack = [CScript([CScriptNum(1)])] @@ -331,7 +330,7 @@ def test_witness_commitments(self): # Now test commitments with actual transactions assert (len(self.utxo) > 0) tx = CTransaction() - tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), "")) + tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")) # Let's construct a witness program witness_program = CScript([OP_TRUE]) @@ -342,7 +341,7 @@ def test_witness_commitments(self): # tx2 will spend tx1, and send back to a regular anyone-can-spend address tx2 = CTransaction() - tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), "")) + tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), b"")) tx2.vout.append(CTxOut(tx.vout[0].nValue-1000, witness_program)) tx2.wit.vtxinwit.append(CTxinWitness()) tx2.wit.vtxinwit[0].scriptWitness.stack = [witness_program] @@ -379,7 +378,7 @@ def test_witness_commitments(self): # omit the commitment. block_4 = self.build_next_block() tx3 = CTransaction() - tx3.vin.append(CTxIn(COutPoint(tx2.sha256, 0), "")) + tx3.vin.append(CTxIn(COutPoint(tx2.sha256, 0), b"")) tx3.vout.append(CTxOut(tx.vout[0].nValue-1000, witness_program)) tx3.rehash() block_4.vtx.append(tx3) @@ -402,7 +401,7 @@ def test_block_malleability(self): add_witness_commitment(block) block.solve() - block.vtx[0].wit.vtxinwit[0].scriptWitness.stack.append('a'*5000000) + block.vtx[0].wit.vtxinwit[0].scriptWitness.stack.append(b'a'*5000000) assert(get_virtual_size(block) > MAX_BLOCK_SIZE) # We can't send over the p2p network, because this is too big to relay @@ -458,7 +457,7 @@ def test_witness_block_size(self): value = self.utxo[0].nValue parent_tx = CTransaction() - parent_tx.vin.append(CTxIn(prevout, "")) + parent_tx.vin.append(CTxIn(prevout, b"")) child_value = int(value/NUM_OUTPUTS) for i in xrange(NUM_OUTPUTS): parent_tx.vout.append(CTxOut(child_value, scriptPubKey)) @@ -468,11 +467,11 @@ def test_witness_block_size(self): child_tx = CTransaction() for i in xrange(NUM_OUTPUTS): - child_tx.vin.append(CTxIn(COutPoint(parent_tx.sha256, i), "")) + child_tx.vin.append(CTxIn(COutPoint(parent_tx.sha256, i), b"")) child_tx.vout = [CTxOut(value - 100000, CScript([OP_TRUE]))] for i in xrange(NUM_OUTPUTS): child_tx.wit.vtxinwit.append(CTxinWitness()) - child_tx.wit.vtxinwit[-1].scriptWitness.stack = ['a'*195]*(2*NUM_DROPS) + [witness_program] + child_tx.wit.vtxinwit[-1].scriptWitness.stack = [b'a'*195]*(2*NUM_DROPS) + [witness_program] child_tx.rehash() self.update_witness_block_with_transactions(block, [parent_tx, child_tx]) @@ -482,7 +481,7 @@ def test_witness_block_size(self): while additional_bytes > 0: # Add some more bytes to each input until we hit MAX_BLOCK_SIZE+1 extra_bytes = min(additional_bytes+1, 55) - block.vtx[-1].wit.vtxinwit[int(i/(2*NUM_DROPS))].scriptWitness.stack[i%(2*NUM_DROPS)] = 'a'*(195+extra_bytes) + block.vtx[-1].wit.vtxinwit[int(i/(2*NUM_DROPS))].scriptWitness.stack[i%(2*NUM_DROPS)] = b'a'*(195+extra_bytes) additional_bytes -= extra_bytes i += 1 @@ -499,7 +498,7 @@ def test_witness_block_size(self): # Now resize the second transaction to make the block fit. cur_length = len(block.vtx[-1].wit.vtxinwit[0].scriptWitness.stack[0]) - block.vtx[-1].wit.vtxinwit[0].scriptWitness.stack[0] = 'a'*(cur_length-1) + block.vtx[-1].wit.vtxinwit[0].scriptWitness.stack[0] = b'a'*(cur_length-1) block.vtx[0].vout.pop() add_witness_commitment(block) block.solve() @@ -563,7 +562,7 @@ def test_extra_witness_data(self): # First try extra witness data on a tx that doesn't require a witness tx = CTransaction() - tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), "")) + tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")) tx.vout.append(CTxOut(self.utxo[0].nValue-2000, scriptPubKey)) tx.vout.append(CTxOut(1000, CScript([OP_TRUE]))) # non-witness output tx.wit.vtxinwit.append(CTxinWitness()) @@ -586,8 +585,8 @@ def test_extra_witness_data(self): # Now try extra witness/signature data on an input that DOES require a # witness tx2 = CTransaction() - tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), "")) # witness output - tx2.vin.append(CTxIn(COutPoint(tx.sha256, 1), "")) # non-witness + tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), b"")) # witness output + tx2.vin.append(CTxIn(COutPoint(tx.sha256, 1), b"")) # non-witness tx2.vout.append(CTxOut(tx.vout[0].nValue, CScript([OP_TRUE]))) tx2.wit.vtxinwit.extend([CTxinWitness(), CTxinWitness()]) tx2.wit.vtxinwit[0].scriptWitness.stack = [ CScript([CScriptNum(1)]), CScript([CScriptNum(1)]), witness_program ] @@ -613,7 +612,7 @@ def test_extra_witness_data(self): # Now get rid of the extra scriptsig on the witness input, and verify # success (even with extra scriptsig data in the non-witness input) - tx2.vin[0].scriptSig = "" + tx2.vin[0].scriptSig = b"" tx2.rehash() add_witness_commitment(block) block.solve() @@ -638,23 +637,23 @@ def test_max_witness_push_length(self): scriptPubKey = CScript([OP_0, witness_hash]) tx = CTransaction() - tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), "")) + tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")) tx.vout.append(CTxOut(self.utxo[0].nValue-1000, scriptPubKey)) tx.rehash() tx2 = CTransaction() - tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), "")) + tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), b"")) tx2.vout.append(CTxOut(tx.vout[0].nValue-1000, CScript([OP_TRUE]))) tx2.wit.vtxinwit.append(CTxinWitness()) # First try a 521-byte stack element - tx2.wit.vtxinwit[0].scriptWitness.stack = [ 'a'*(MAX_SCRIPT_ELEMENT_SIZE+1), witness_program ] + tx2.wit.vtxinwit[0].scriptWitness.stack = [ b'a'*(MAX_SCRIPT_ELEMENT_SIZE+1), witness_program ] tx2.rehash() self.update_witness_block_with_transactions(block, [tx, tx2]) self.test_node.test_witness_block(block, accepted=False) # Now reduce the length of the stack element - tx2.wit.vtxinwit[0].scriptWitness.stack[0] = 'a'*(MAX_SCRIPT_ELEMENT_SIZE) + tx2.wit.vtxinwit[0].scriptWitness.stack[0] = b'a'*(MAX_SCRIPT_ELEMENT_SIZE) add_witness_commitment(block) block.solve() @@ -672,7 +671,7 @@ def test_max_witness_program_length(self): MAX_PROGRAM_LENGTH = 10000 # This program is 19 max pushes (9937 bytes), then 64 more opcode-bytes. - long_witness_program = CScript(['a'*520]*19 + [OP_DROP]*63 + [OP_TRUE]) + long_witness_program = CScript([b'a'*520]*19 + [OP_DROP]*63 + [OP_TRUE]) assert(len(long_witness_program) == MAX_PROGRAM_LENGTH+1) long_witness_hash = sha256(long_witness_program) long_scriptPubKey = CScript([OP_0, long_witness_hash]) @@ -680,15 +679,15 @@ def test_max_witness_program_length(self): block = self.build_next_block() tx = CTransaction() - tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), "")) + tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")) tx.vout.append(CTxOut(self.utxo[0].nValue-1000, long_scriptPubKey)) tx.rehash() tx2 = CTransaction() - tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), "")) + tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), b"")) tx2.vout.append(CTxOut(tx.vout[0].nValue-1000, CScript([OP_TRUE]))) tx2.wit.vtxinwit.append(CTxinWitness()) - tx2.wit.vtxinwit[0].scriptWitness.stack = ['a']*44 + [long_witness_program] + tx2.wit.vtxinwit[0].scriptWitness.stack = [b'a']*44 + [long_witness_program] tx2.rehash() self.update_witness_block_with_transactions(block, [tx, tx2]) @@ -696,7 +695,7 @@ def test_max_witness_program_length(self): self.test_node.test_witness_block(block, accepted=False) # Try again with one less byte in the witness program - witness_program = CScript(['a'*520]*19 + [OP_DROP]*62 + [OP_TRUE]) + witness_program = CScript([b'a'*520]*19 + [OP_DROP]*62 + [OP_TRUE]) assert(len(witness_program) == MAX_PROGRAM_LENGTH) witness_hash = sha256(witness_program) scriptPubKey = CScript([OP_0, witness_hash]) @@ -704,7 +703,7 @@ def test_max_witness_program_length(self): tx.vout[0] = CTxOut(tx.vout[0].nValue, scriptPubKey) tx.rehash() tx2.vin[0].prevout.hash = tx.sha256 - tx2.wit.vtxinwit[0].scriptWitness.stack = ['a']*43 + [witness_program] + tx2.wit.vtxinwit[0].scriptWitness.stack = [b'a']*43 + [witness_program] tx2.rehash() block.vtx = [block.vtx[0]] self.update_witness_block_with_transactions(block, [tx, tx2]) @@ -725,7 +724,7 @@ def test_witness_input_length(self): # Create a transaction that splits our utxo into many outputs tx = CTransaction() - tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), "")) + tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")) nValue = self.utxo[0].nValue for i in xrange(10): tx.vout.append(CTxOut(int(nValue/10), scriptPubKey)) @@ -744,7 +743,7 @@ def serialize_with_witness(self): flags = 0 if not self.wit.is_null(): flags |= 1 - r = "" + r = b"" r += struct.pack("