|
|
@ -225,7 +225,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
# to a transaction, eg by violating standardness checks. |
|
|
|
# to a transaction, eg by violating standardness checks. |
|
|
|
tx2 = CTransaction() |
|
|
|
tx2 = CTransaction() |
|
|
|
tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), b"")) |
|
|
|
tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), b"")) |
|
|
|
tx2.vout.append(CTxOut(tx.vout[0].nValue-1000, scriptPubKey)) |
|
|
|
tx2.vout.append(CTxOut(tx.vout[0].nValue-100000, scriptPubKey)) |
|
|
|
tx2.rehash() |
|
|
|
tx2.rehash() |
|
|
|
self.test_node.test_transaction_acceptance(tx2, False, True) |
|
|
|
self.test_node.test_transaction_acceptance(tx2, False, True) |
|
|
|
self.nodes[0].generate(1) |
|
|
|
self.nodes[0].generate(1) |
|
|
@ -238,7 +238,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
# to the rejection cache. |
|
|
|
# to the rejection cache. |
|
|
|
tx3 = CTransaction() |
|
|
|
tx3 = CTransaction() |
|
|
|
tx3.vin.append(CTxIn(COutPoint(tx2.sha256, 0), CScript([p2sh_program]))) |
|
|
|
tx3.vin.append(CTxIn(COutPoint(tx2.sha256, 0), CScript([p2sh_program]))) |
|
|
|
tx3.vout.append(CTxOut(tx2.vout[0].nValue-1000, scriptPubKey)) |
|
|
|
tx3.vout.append(CTxOut(tx2.vout[0].nValue-100000, scriptPubKey)) |
|
|
|
tx3.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
tx3.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
tx3.wit.vtxinwit[0].scriptWitness.stack = [b'a'*400000] |
|
|
|
tx3.wit.vtxinwit[0].scriptWitness.stack = [b'a'*400000] |
|
|
|
tx3.rehash() |
|
|
|
tx3.rehash() |
|
|
@ -252,7 +252,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
# Now create a new anyone-can-spend utxo for the next test. |
|
|
|
# Now create a new anyone-can-spend utxo for the next test. |
|
|
|
tx4 = CTransaction() |
|
|
|
tx4 = CTransaction() |
|
|
|
tx4.vin.append(CTxIn(COutPoint(tx3.sha256, 0), CScript([p2sh_program]))) |
|
|
|
tx4.vin.append(CTxIn(COutPoint(tx3.sha256, 0), CScript([p2sh_program]))) |
|
|
|
tx4.vout.append(CTxOut(tx3.vout[0].nValue-1000, CScript([OP_TRUE]))) |
|
|
|
tx4.vout.append(CTxOut(tx3.vout[0].nValue-100000, CScript([OP_TRUE]))) |
|
|
|
tx4.rehash() |
|
|
|
tx4.rehash() |
|
|
|
self.test_node.test_transaction_acceptance(tx3, False, True) |
|
|
|
self.test_node.test_transaction_acceptance(tx3, False, True) |
|
|
|
self.test_node.test_transaction_acceptance(tx4, False, True) |
|
|
|
self.test_node.test_transaction_acceptance(tx4, False, True) |
|
|
@ -565,7 +565,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
# First try extra witness data on a tx that doesn't require a witness |
|
|
|
# First try extra witness data on a tx that doesn't require a witness |
|
|
|
tx = CTransaction() |
|
|
|
tx = CTransaction() |
|
|
|
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")) |
|
|
|
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(self.utxo[0].nValue-200000, scriptPubKey)) |
|
|
|
tx.vout.append(CTxOut(1000, CScript([OP_TRUE]))) # non-witness output |
|
|
|
tx.vout.append(CTxOut(1000, CScript([OP_TRUE]))) # non-witness output |
|
|
|
tx.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
tx.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
tx.wit.vtxinwit[0].scriptWitness.stack = [CScript([])] |
|
|
|
tx.wit.vtxinwit[0].scriptWitness.stack = [CScript([])] |
|
|
@ -640,12 +640,12 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
|
|
|
|
|
|
|
|
tx = CTransaction() |
|
|
|
tx = CTransaction() |
|
|
|
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")) |
|
|
|
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.vout.append(CTxOut(self.utxo[0].nValue-100000, scriptPubKey)) |
|
|
|
tx.rehash() |
|
|
|
tx.rehash() |
|
|
|
|
|
|
|
|
|
|
|
tx2 = CTransaction() |
|
|
|
tx2 = CTransaction() |
|
|
|
tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), b"")) |
|
|
|
tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), b"")) |
|
|
|
tx2.vout.append(CTxOut(tx.vout[0].nValue-1000, CScript([OP_TRUE]))) |
|
|
|
tx2.vout.append(CTxOut(tx.vout[0].nValue-100000, CScript([OP_TRUE]))) |
|
|
|
tx2.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
tx2.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
# First try a 521-byte stack element |
|
|
|
# First try a 521-byte stack element |
|
|
|
tx2.wit.vtxinwit[0].scriptWitness.stack = [ b'a'*(MAX_SCRIPT_ELEMENT_SIZE+1), witness_program ] |
|
|
|
tx2.wit.vtxinwit[0].scriptWitness.stack = [ b'a'*(MAX_SCRIPT_ELEMENT_SIZE+1), witness_program ] |
|
|
@ -682,12 +682,12 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
|
|
|
|
|
|
|
|
tx = CTransaction() |
|
|
|
tx = CTransaction() |
|
|
|
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")) |
|
|
|
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.vout.append(CTxOut(self.utxo[0].nValue-100000, long_scriptPubKey)) |
|
|
|
tx.rehash() |
|
|
|
tx.rehash() |
|
|
|
|
|
|
|
|
|
|
|
tx2 = CTransaction() |
|
|
|
tx2 = CTransaction() |
|
|
|
tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), b"")) |
|
|
|
tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), b"")) |
|
|
|
tx2.vout.append(CTxOut(tx.vout[0].nValue-1000, CScript([OP_TRUE]))) |
|
|
|
tx2.vout.append(CTxOut(tx.vout[0].nValue-100000, CScript([OP_TRUE]))) |
|
|
|
tx2.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
tx2.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
tx2.wit.vtxinwit[0].scriptWitness.stack = [b'a']*44 + [long_witness_program] |
|
|
|
tx2.wit.vtxinwit[0].scriptWitness.stack = [b'a']*44 + [long_witness_program] |
|
|
|
tx2.rehash() |
|
|
|
tx2.rehash() |
|
|
@ -807,7 +807,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
assert(len(self.utxo)) |
|
|
|
assert(len(self.utxo)) |
|
|
|
tx = CTransaction() |
|
|
|
tx = CTransaction() |
|
|
|
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")) |
|
|
|
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.vout.append(CTxOut(self.utxo[0].nValue-100000, CScript([OP_TRUE]))) |
|
|
|
tx.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
tx.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
tx.wit.vtxinwit[0].scriptWitness.stack = [ b'a' ] |
|
|
|
tx.wit.vtxinwit[0].scriptWitness.stack = [ b'a' ] |
|
|
|
tx.rehash() |
|
|
|
tx.rehash() |
|
|
@ -859,7 +859,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
assert(len(self.utxo)) |
|
|
|
assert(len(self.utxo)) |
|
|
|
tx = CTransaction() |
|
|
|
tx = CTransaction() |
|
|
|
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")) |
|
|
|
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.vout.append(CTxOut(self.utxo[0].nValue-100000, CScript([OP_TRUE]))) |
|
|
|
tx.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
tx.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
tx.wit.vtxinwit[0].scriptWitness.stack = [ b'a' ] |
|
|
|
tx.wit.vtxinwit[0].scriptWitness.stack = [ b'a' ] |
|
|
|
tx.rehash() |
|
|
|
tx.rehash() |
|
|
@ -881,7 +881,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
scriptPubKey = CScript([OP_0, witness_hash]) |
|
|
|
scriptPubKey = CScript([OP_0, witness_hash]) |
|
|
|
tx2 = CTransaction() |
|
|
|
tx2 = CTransaction() |
|
|
|
tx2.vin.append(CTxIn(COutPoint(tx_hash, 0), b"")) |
|
|
|
tx2.vin.append(CTxIn(COutPoint(tx_hash, 0), b"")) |
|
|
|
tx2.vout.append(CTxOut(tx.vout[0].nValue-1000, scriptPubKey)) |
|
|
|
tx2.vout.append(CTxOut(tx.vout[0].nValue-100000, scriptPubKey)) |
|
|
|
tx2.rehash() |
|
|
|
tx2.rehash() |
|
|
|
|
|
|
|
|
|
|
|
tx3 = CTransaction() |
|
|
|
tx3 = CTransaction() |
|
|
@ -892,7 +892,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
p2sh_program = CScript([OP_TRUE]) |
|
|
|
p2sh_program = CScript([OP_TRUE]) |
|
|
|
p2sh_pubkey = hash160(p2sh_program) |
|
|
|
p2sh_pubkey = hash160(p2sh_program) |
|
|
|
witness_program2 = CScript([b'a'*400000]) |
|
|
|
witness_program2 = CScript([b'a'*400000]) |
|
|
|
tx3.vout.append(CTxOut(tx2.vout[0].nValue-1000, CScript([OP_HASH160, p2sh_pubkey, OP_EQUAL]))) |
|
|
|
tx3.vout.append(CTxOut(tx2.vout[0].nValue-100000, CScript([OP_HASH160, p2sh_pubkey, OP_EQUAL]))) |
|
|
|
tx3.wit.vtxinwit[0].scriptWitness.stack = [witness_program2] |
|
|
|
tx3.wit.vtxinwit[0].scriptWitness.stack = [witness_program2] |
|
|
|
tx3.rehash() |
|
|
|
tx3.rehash() |
|
|
|
|
|
|
|
|
|
|
@ -903,7 +903,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
self.std_node.test_transaction_acceptance(tx3, True, False, b'tx-size') |
|
|
|
self.std_node.test_transaction_acceptance(tx3, True, False, b'tx-size') |
|
|
|
|
|
|
|
|
|
|
|
# Remove witness stuffing, instead add extra witness push on stack |
|
|
|
# Remove witness stuffing, instead add extra witness push on stack |
|
|
|
tx3.vout[0] = CTxOut(tx2.vout[0].nValue-1000, CScript([OP_TRUE])) |
|
|
|
tx3.vout[0] = CTxOut(tx2.vout[0].nValue-100000, CScript([OP_TRUE])) |
|
|
|
tx3.wit.vtxinwit[0].scriptWitness.stack = [CScript([CScriptNum(1)]), witness_program ] |
|
|
|
tx3.wit.vtxinwit[0].scriptWitness.stack = [CScript([CScriptNum(1)]), witness_program ] |
|
|
|
tx3.rehash() |
|
|
|
tx3.rehash() |
|
|
|
|
|
|
|
|
|
|
@ -1047,7 +1047,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
# First prepare a p2sh output (so that spending it will pass standardness) |
|
|
|
# First prepare a p2sh output (so that spending it will pass standardness) |
|
|
|
p2sh_tx = CTransaction() |
|
|
|
p2sh_tx = CTransaction() |
|
|
|
p2sh_tx.vin = [CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")] |
|
|
|
p2sh_tx.vin = [CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")] |
|
|
|
p2sh_tx.vout = [CTxOut(self.utxo[0].nValue-1000, p2sh_scriptPubKey)] |
|
|
|
p2sh_tx.vout = [CTxOut(self.utxo[0].nValue-100000, p2sh_scriptPubKey)] |
|
|
|
p2sh_tx.rehash() |
|
|
|
p2sh_tx.rehash() |
|
|
|
|
|
|
|
|
|
|
|
# Mine it on test_node to create the confirmed output. |
|
|
|
# Mine it on test_node to create the confirmed output. |
|
|
@ -1059,8 +1059,8 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
# Start by creating a transaction with two outputs. |
|
|
|
# Start by creating a transaction with two outputs. |
|
|
|
tx = CTransaction() |
|
|
|
tx = CTransaction() |
|
|
|
tx.vin = [CTxIn(COutPoint(p2sh_tx.sha256, 0), CScript([witness_program]))] |
|
|
|
tx.vin = [CTxIn(COutPoint(p2sh_tx.sha256, 0), CScript([witness_program]))] |
|
|
|
tx.vout = [CTxOut(p2sh_tx.vout[0].nValue-10000, scriptPubKey)] |
|
|
|
tx.vout = [CTxOut(p2sh_tx.vout[0].nValue-1000000, scriptPubKey)] |
|
|
|
tx.vout.append(CTxOut(8000, scriptPubKey)) # Might burn this later |
|
|
|
tx.vout.append(CTxOut(800000, scriptPubKey)) # Might burn this later |
|
|
|
tx.rehash() |
|
|
|
tx.rehash() |
|
|
|
|
|
|
|
|
|
|
|
self.std_node.test_transaction_acceptance(tx, with_witness=True, accepted=segwit_activated) |
|
|
|
self.std_node.test_transaction_acceptance(tx, with_witness=True, accepted=segwit_activated) |
|
|
@ -1071,13 +1071,13 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
if segwit_activated: |
|
|
|
if segwit_activated: |
|
|
|
# if tx was accepted, then we spend the second output. |
|
|
|
# if tx was accepted, then we spend the second output. |
|
|
|
tx2.vin = [CTxIn(COutPoint(tx.sha256, 1), b"")] |
|
|
|
tx2.vin = [CTxIn(COutPoint(tx.sha256, 1), b"")] |
|
|
|
tx2.vout = [CTxOut(7000, scriptPubKey)] |
|
|
|
tx2.vout = [CTxOut(700000, scriptPubKey)] |
|
|
|
tx2.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
tx2.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
tx2.wit.vtxinwit[0].scriptWitness.stack = [witness_program] |
|
|
|
tx2.wit.vtxinwit[0].scriptWitness.stack = [witness_program] |
|
|
|
else: |
|
|
|
else: |
|
|
|
# if tx wasn't accepted, we just re-spend the p2sh output we started with. |
|
|
|
# if tx wasn't accepted, we just re-spend the p2sh output we started with. |
|
|
|
tx2.vin = [CTxIn(COutPoint(p2sh_tx.sha256, 0), CScript([witness_program]))] |
|
|
|
tx2.vin = [CTxIn(COutPoint(p2sh_tx.sha256, 0), CScript([witness_program]))] |
|
|
|
tx2.vout = [CTxOut(p2sh_tx.vout[0].nValue-1000, scriptPubKey)] |
|
|
|
tx2.vout = [CTxOut(p2sh_tx.vout[0].nValue-100000, scriptPubKey)] |
|
|
|
tx2.rehash() |
|
|
|
tx2.rehash() |
|
|
|
|
|
|
|
|
|
|
|
self.std_node.test_transaction_acceptance(tx2, with_witness=True, accepted=segwit_activated) |
|
|
|
self.std_node.test_transaction_acceptance(tx2, with_witness=True, accepted=segwit_activated) |
|
|
@ -1089,7 +1089,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
# P2PKH output; just send tx's first output back to an anyone-can-spend. |
|
|
|
# P2PKH output; just send tx's first output back to an anyone-can-spend. |
|
|
|
sync_mempools([self.nodes[0], self.nodes[1]]) |
|
|
|
sync_mempools([self.nodes[0], self.nodes[1]]) |
|
|
|
tx3.vin = [CTxIn(COutPoint(tx.sha256, 0), b"")] |
|
|
|
tx3.vin = [CTxIn(COutPoint(tx.sha256, 0), b"")] |
|
|
|
tx3.vout = [CTxOut(tx.vout[0].nValue-1000, CScript([OP_TRUE]))] |
|
|
|
tx3.vout = [CTxOut(tx.vout[0].nValue-100000, CScript([OP_TRUE]))] |
|
|
|
tx3.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
tx3.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
tx3.wit.vtxinwit[0].scriptWitness.stack = [witness_program] |
|
|
|
tx3.wit.vtxinwit[0].scriptWitness.stack = [witness_program] |
|
|
|
tx3.rehash() |
|
|
|
tx3.rehash() |
|
|
@ -1097,7 +1097,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
else: |
|
|
|
else: |
|
|
|
# tx and tx2 didn't go anywhere; just clean up the p2sh_tx output. |
|
|
|
# tx and tx2 didn't go anywhere; just clean up the p2sh_tx output. |
|
|
|
tx3.vin = [CTxIn(COutPoint(p2sh_tx.sha256, 0), CScript([witness_program]))] |
|
|
|
tx3.vin = [CTxIn(COutPoint(p2sh_tx.sha256, 0), CScript([witness_program]))] |
|
|
|
tx3.vout = [CTxOut(p2sh_tx.vout[0].nValue-1000, witness_program)] |
|
|
|
tx3.vout = [CTxOut(p2sh_tx.vout[0].nValue-100000, witness_program)] |
|
|
|
tx3.rehash() |
|
|
|
tx3.rehash() |
|
|
|
self.test_node.test_transaction_acceptance(tx3, with_witness=True, accepted=True) |
|
|
|
self.test_node.test_transaction_acceptance(tx3, with_witness=True, accepted=True) |
|
|
|
|
|
|
|
|
|
|
@ -1117,7 +1117,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
if (len(self.utxo) < NUM_TESTS): |
|
|
|
if (len(self.utxo) < NUM_TESTS): |
|
|
|
tx = CTransaction() |
|
|
|
tx = CTransaction() |
|
|
|
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")) |
|
|
|
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")) |
|
|
|
split_value = (self.utxo[0].nValue - 4000) // NUM_TESTS |
|
|
|
split_value = (self.utxo[0].nValue - 400000) // NUM_TESTS |
|
|
|
for i in range(NUM_TESTS): |
|
|
|
for i in range(NUM_TESTS): |
|
|
|
tx.vout.append(CTxOut(split_value, CScript([OP_TRUE]))) |
|
|
|
tx.vout.append(CTxOut(split_value, CScript([OP_TRUE]))) |
|
|
|
tx.rehash() |
|
|
|
tx.rehash() |
|
|
@ -1140,7 +1140,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
# First try to spend to a future version segwit scriptPubKey. |
|
|
|
# First try to spend to a future version segwit scriptPubKey. |
|
|
|
scriptPubKey = CScript([CScriptOp(version), witness_hash]) |
|
|
|
scriptPubKey = CScript([CScriptOp(version), witness_hash]) |
|
|
|
tx.vin = [CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")] |
|
|
|
tx.vin = [CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")] |
|
|
|
tx.vout = [CTxOut(self.utxo[0].nValue-1000, scriptPubKey)] |
|
|
|
tx.vout = [CTxOut(self.utxo[0].nValue-100000, scriptPubKey)] |
|
|
|
tx.rehash() |
|
|
|
tx.rehash() |
|
|
|
self.std_node.test_transaction_acceptance(tx, with_witness=True, accepted=False) |
|
|
|
self.std_node.test_transaction_acceptance(tx, with_witness=True, accepted=False) |
|
|
|
self.test_node.test_transaction_acceptance(tx, with_witness=True, accepted=True) |
|
|
|
self.test_node.test_transaction_acceptance(tx, with_witness=True, accepted=True) |
|
|
@ -1156,7 +1156,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
scriptPubKey = CScript([CScriptOp(OP_1), witness_hash]) |
|
|
|
scriptPubKey = CScript([CScriptOp(OP_1), witness_hash]) |
|
|
|
tx2 = CTransaction() |
|
|
|
tx2 = CTransaction() |
|
|
|
tx2.vin = [CTxIn(COutPoint(tx.sha256, 0), b"")] |
|
|
|
tx2.vin = [CTxIn(COutPoint(tx.sha256, 0), b"")] |
|
|
|
tx2.vout = [CTxOut(tx.vout[0].nValue-1000, scriptPubKey)] |
|
|
|
tx2.vout = [CTxOut(tx.vout[0].nValue-100000, scriptPubKey)] |
|
|
|
tx2.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
tx2.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
tx2.wit.vtxinwit[0].scriptWitness.stack = [ witness_program ] |
|
|
|
tx2.wit.vtxinwit[0].scriptWitness.stack = [ witness_program ] |
|
|
|
tx2.rehash() |
|
|
|
tx2.rehash() |
|
|
@ -1175,7 +1175,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
tx3.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
tx3.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
total_value += i.nValue |
|
|
|
total_value += i.nValue |
|
|
|
tx3.wit.vtxinwit[-1].scriptWitness.stack = [witness_program] |
|
|
|
tx3.wit.vtxinwit[-1].scriptWitness.stack = [witness_program] |
|
|
|
tx3.vout.append(CTxOut(total_value - 1000, CScript([OP_TRUE]))) |
|
|
|
tx3.vout.append(CTxOut(total_value - 100000, CScript([OP_TRUE]))) |
|
|
|
tx3.rehash() |
|
|
|
tx3.rehash() |
|
|
|
# Spending a higher version witness output is not allowed by policy, |
|
|
|
# Spending a higher version witness output is not allowed by policy, |
|
|
|
# even with fRequireStandard=false. |
|
|
|
# even with fRequireStandard=false. |
|
|
@ -1243,7 +1243,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
assert(len(self.utxo)) |
|
|
|
assert(len(self.utxo)) |
|
|
|
tx = CTransaction() |
|
|
|
tx = CTransaction() |
|
|
|
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")) |
|
|
|
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.vout.append(CTxOut(self.utxo[0].nValue-100000, scriptPubKey)) |
|
|
|
tx.rehash() |
|
|
|
tx.rehash() |
|
|
|
|
|
|
|
|
|
|
|
self.test_node.test_transaction_acceptance(tx, with_witness=True, accepted=True) |
|
|
|
self.test_node.test_transaction_acceptance(tx, with_witness=True, accepted=True) |
|
|
@ -1262,7 +1262,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
block = self.build_next_block() |
|
|
|
block = self.build_next_block() |
|
|
|
tx = CTransaction() |
|
|
|
tx = CTransaction() |
|
|
|
tx.vin.append(CTxIn(COutPoint(prev_utxo.sha256, prev_utxo.n), b"")) |
|
|
|
tx.vin.append(CTxIn(COutPoint(prev_utxo.sha256, prev_utxo.n), b"")) |
|
|
|
tx.vout.append(CTxOut(prev_utxo.nValue - 1000, scriptPubKey)) |
|
|
|
tx.vout.append(CTxOut(prev_utxo.nValue - 100000, scriptPubKey)) |
|
|
|
tx.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
tx.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
# Too-large input value |
|
|
|
# Too-large input value |
|
|
|
sign_P2PK_witness_input(witness_program, tx, 0, hashtype, prev_utxo.nValue+1, key) |
|
|
|
sign_P2PK_witness_input(witness_program, tx, 0, hashtype, prev_utxo.nValue+1, key) |
|
|
@ -1427,7 +1427,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
# Fund the P2SH output |
|
|
|
# Fund the P2SH output |
|
|
|
tx = CTransaction() |
|
|
|
tx = CTransaction() |
|
|
|
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")) |
|
|
|
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.vout.append(CTxOut(self.utxo[0].nValue-100000, scriptPubKey)) |
|
|
|
tx.rehash() |
|
|
|
tx.rehash() |
|
|
|
|
|
|
|
|
|
|
|
# Verify mempool acceptance and block validity |
|
|
|
# Verify mempool acceptance and block validity |
|
|
@ -1440,7 +1440,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
# Now test attempts to spend the output. |
|
|
|
# Now test attempts to spend the output. |
|
|
|
spend_tx = CTransaction() |
|
|
|
spend_tx = CTransaction() |
|
|
|
spend_tx.vin.append(CTxIn(COutPoint(tx.sha256, 0), scriptSig)) |
|
|
|
spend_tx.vin.append(CTxIn(COutPoint(tx.sha256, 0), scriptSig)) |
|
|
|
spend_tx.vout.append(CTxOut(tx.vout[0].nValue-1000, CScript([OP_TRUE]))) |
|
|
|
spend_tx.vout.append(CTxOut(tx.vout[0].nValue-100000, CScript([OP_TRUE]))) |
|
|
|
spend_tx.rehash() |
|
|
|
spend_tx.rehash() |
|
|
|
|
|
|
|
|
|
|
|
# This transaction should not be accepted into the mempool pre- or |
|
|
|
# This transaction should not be accepted into the mempool pre- or |
|
|
@ -1682,7 +1682,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
scriptPKH = CScript([OP_0, pubkeyhash]) |
|
|
|
scriptPKH = CScript([OP_0, pubkeyhash]) |
|
|
|
tx = CTransaction() |
|
|
|
tx = CTransaction() |
|
|
|
tx.vin.append(CTxIn(COutPoint(utxo.sha256, utxo.n), b"")) |
|
|
|
tx.vin.append(CTxIn(COutPoint(utxo.sha256, utxo.n), b"")) |
|
|
|
tx.vout.append(CTxOut(utxo.nValue-1000, scriptPKH)) |
|
|
|
tx.vout.append(CTxOut(utxo.nValue-100000, scriptPKH)) |
|
|
|
tx.rehash() |
|
|
|
tx.rehash() |
|
|
|
|
|
|
|
|
|
|
|
# Confirm it in a block. |
|
|
|
# Confirm it in a block. |
|
|
@ -1698,7 +1698,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
|
|
|
|
|
|
|
|
tx2 = CTransaction() |
|
|
|
tx2 = CTransaction() |
|
|
|
tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), b"")) |
|
|
|
tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), b"")) |
|
|
|
tx2.vout.append(CTxOut(tx.vout[0].nValue-1000, scriptWSH)) |
|
|
|
tx2.vout.append(CTxOut(tx.vout[0].nValue-100000, scriptWSH)) |
|
|
|
script = GetP2PKHScript(pubkeyhash) |
|
|
|
script = GetP2PKHScript(pubkeyhash) |
|
|
|
sig_hash = SegwitVersion1SignatureHash(script, tx2, 0, SIGHASH_ALL, tx.vout[0].nValue) |
|
|
|
sig_hash = SegwitVersion1SignatureHash(script, tx2, 0, SIGHASH_ALL, tx.vout[0].nValue) |
|
|
|
signature = key.sign(sig_hash) + b'\x01' # 0x1 is SIGHASH_ALL |
|
|
|
signature = key.sign(sig_hash) + b'\x01' # 0x1 is SIGHASH_ALL |
|
|
@ -1722,7 +1722,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
|
|
|
|
|
|
|
|
tx3 = CTransaction() |
|
|
|
tx3 = CTransaction() |
|
|
|
tx3.vin.append(CTxIn(COutPoint(tx2.sha256, 0), b"")) |
|
|
|
tx3.vin.append(CTxIn(COutPoint(tx2.sha256, 0), b"")) |
|
|
|
tx3.vout.append(CTxOut(tx2.vout[0].nValue-1000, scriptP2SH)) |
|
|
|
tx3.vout.append(CTxOut(tx2.vout[0].nValue-100000, scriptP2SH)) |
|
|
|
tx3.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
tx3.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
sign_P2PK_witness_input(witness_program, tx3, 0, SIGHASH_ALL, tx2.vout[0].nValue, key) |
|
|
|
sign_P2PK_witness_input(witness_program, tx3, 0, SIGHASH_ALL, tx2.vout[0].nValue, key) |
|
|
|
|
|
|
|
|
|
|
@ -1739,7 +1739,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
scriptPubKey = GetP2PKHScript(pubkeyhash) |
|
|
|
scriptPubKey = GetP2PKHScript(pubkeyhash) |
|
|
|
tx4 = CTransaction() |
|
|
|
tx4 = CTransaction() |
|
|
|
tx4.vin.append(CTxIn(COutPoint(tx3.sha256, 0), scriptSig)) |
|
|
|
tx4.vin.append(CTxIn(COutPoint(tx3.sha256, 0), scriptSig)) |
|
|
|
tx4.vout.append(CTxOut(tx3.vout[0].nValue-1000, scriptPubKey)) |
|
|
|
tx4.vout.append(CTxOut(tx3.vout[0].nValue-100000, scriptPubKey)) |
|
|
|
tx4.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
tx4.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
sign_P2PK_witness_input(witness_program, tx4, 0, SIGHASH_ALL, tx3.vout[0].nValue, key) |
|
|
|
sign_P2PK_witness_input(witness_program, tx4, 0, SIGHASH_ALL, tx3.vout[0].nValue, key) |
|
|
|
|
|
|
|
|
|
|
@ -1753,7 +1753,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
# transactions. |
|
|
|
# transactions. |
|
|
|
tx5 = CTransaction() |
|
|
|
tx5 = CTransaction() |
|
|
|
tx5.vin.append(CTxIn(COutPoint(tx4.sha256, 0), b"")) |
|
|
|
tx5.vin.append(CTxIn(COutPoint(tx4.sha256, 0), b"")) |
|
|
|
tx5.vout.append(CTxOut(tx4.vout[0].nValue-1000, CScript([OP_TRUE]))) |
|
|
|
tx5.vout.append(CTxOut(tx4.vout[0].nValue-100000, CScript([OP_TRUE]))) |
|
|
|
(sig_hash, err) = SignatureHash(scriptPubKey, tx5, 0, SIGHASH_ALL) |
|
|
|
(sig_hash, err) = SignatureHash(scriptPubKey, tx5, 0, SIGHASH_ALL) |
|
|
|
signature = key.sign(sig_hash) + b'\x01' # 0x1 is SIGHASH_ALL |
|
|
|
signature = key.sign(sig_hash) + b'\x01' # 0x1 is SIGHASH_ALL |
|
|
|
tx5.vin[0].scriptSig = CScript([signature, pubkey]) |
|
|
|
tx5.vin[0].scriptSig = CScript([signature, pubkey]) |
|
|
@ -1783,7 +1783,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")) |
|
|
|
tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b"")) |
|
|
|
|
|
|
|
|
|
|
|
# For each script, generate a pair of P2WSH and P2SH-P2WSH output. |
|
|
|
# For each script, generate a pair of P2WSH and P2SH-P2WSH output. |
|
|
|
outputvalue = (self.utxo[0].nValue - 1000) // (len(scripts) * 2) |
|
|
|
outputvalue = (self.utxo[0].nValue - 100000) // (len(scripts) * 2) |
|
|
|
for i in scripts: |
|
|
|
for i in scripts: |
|
|
|
p2wsh = CScript([OP_0, sha256(i)]) |
|
|
|
p2wsh = CScript([OP_0, sha256(i)]) |
|
|
|
p2sh = hash160(p2wsh) |
|
|
|
p2sh = hash160(p2wsh) |
|
|
@ -1803,13 +1803,13 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
for i in range(len(scripts)): |
|
|
|
for i in range(len(scripts)): |
|
|
|
p2wsh_tx = CTransaction() |
|
|
|
p2wsh_tx = CTransaction() |
|
|
|
p2wsh_tx.vin.append(CTxIn(COutPoint(txid,i*2))) |
|
|
|
p2wsh_tx.vin.append(CTxIn(COutPoint(txid,i*2))) |
|
|
|
p2wsh_tx.vout.append(CTxOut(outputvalue - 5000, CScript([OP_0, hash160(hex_str_to_bytes(""))]))) |
|
|
|
p2wsh_tx.vout.append(CTxOut(outputvalue - 500000, CScript([OP_0, hash160(hex_str_to_bytes(""))]))) |
|
|
|
p2wsh_tx.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
p2wsh_tx.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
p2wsh_tx.rehash() |
|
|
|
p2wsh_tx.rehash() |
|
|
|
p2wsh_txs.append(p2wsh_tx) |
|
|
|
p2wsh_txs.append(p2wsh_tx) |
|
|
|
p2sh_tx = CTransaction() |
|
|
|
p2sh_tx = CTransaction() |
|
|
|
p2sh_tx.vin.append(CTxIn(COutPoint(txid,i*2+1), CScript([p2wsh_scripts[i]]))) |
|
|
|
p2sh_tx.vin.append(CTxIn(COutPoint(txid,i*2+1), CScript([p2wsh_scripts[i]]))) |
|
|
|
p2sh_tx.vout.append(CTxOut(outputvalue - 5000, CScript([OP_0, hash160(hex_str_to_bytes(""))]))) |
|
|
|
p2sh_tx.vout.append(CTxOut(outputvalue - 500000, CScript([OP_0, hash160(hex_str_to_bytes(""))]))) |
|
|
|
p2sh_tx.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
p2sh_tx.wit.vtxinwit.append(CTxInWitness()) |
|
|
|
p2sh_tx.rehash() |
|
|
|
p2sh_tx.rehash() |
|
|
|
p2sh_txs.append(p2sh_tx) |
|
|
|
p2sh_txs.append(p2sh_tx) |
|
|
|