|
|
@ -8,9 +8,9 @@ from test_framework.test_framework import BitcoinTestFramework |
|
|
|
from test_framework.util import * |
|
|
|
from test_framework.util import * |
|
|
|
from test_framework.mininode import sha256, ripemd160, CTransaction, CTxIn, COutPoint, CTxOut, COIN |
|
|
|
from test_framework.mininode import sha256, ripemd160, CTransaction, CTxIn, COutPoint, CTxOut, COIN |
|
|
|
from test_framework.address import script_to_p2sh, key_to_p2pkh |
|
|
|
from test_framework.address import script_to_p2sh, key_to_p2pkh |
|
|
|
from test_framework.script import CScript, OP_HASH160, OP_CHECKSIG, OP_0, hash160, OP_EQUAL, OP_DUP, OP_EQUALVERIFY, OP_1, OP_2, OP_CHECKMULTISIG, hash160 |
|
|
|
from test_framework.script import CScript, OP_HASH160, OP_CHECKSIG, OP_0, hash160, OP_EQUAL, OP_DUP, OP_EQUALVERIFY, OP_1, OP_2, OP_CHECKMULTISIG, hash160, OP_TRUE |
|
|
|
from io import BytesIO |
|
|
|
from io import BytesIO |
|
|
|
from test_framework.mininode import FromHex, ToHex |
|
|
|
from test_framework.mininode import ToHex, FromHex, COIN |
|
|
|
|
|
|
|
|
|
|
|
NODE_0 = 0 |
|
|
|
NODE_0 = 0 |
|
|
|
NODE_1 = 1 |
|
|
|
NODE_1 = 1 |
|
|
@ -250,12 +250,54 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
assert(tmpl['transactions'][0]['txid'] == txid) |
|
|
|
assert(tmpl['transactions'][0]['txid'] == txid) |
|
|
|
assert(tmpl['transactions'][0]['sigops'] == 8) |
|
|
|
assert(tmpl['transactions'][0]['sigops'] == 8) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.nodes[0].generate(1) # Mine a block to clear the gbt cache |
|
|
|
|
|
|
|
|
|
|
|
self.log.info("Non-segwit miners are able to use GBT response after activation.") |
|
|
|
self.log.info("Non-segwit miners are able to use GBT response after activation.") |
|
|
|
txid = send_to_witness(1, self.nodes[0], find_unspent(self.nodes[0], 50), self.pubkey[0], False, Decimal("49.998")) |
|
|
|
# Create a 3-tx chain: tx1 (non-segwit input, paying to a segwit output) -> |
|
|
|
#assert_raises_jsonrpc(-8, "Support for 'segwit' rule requires explicit client support", self.nodes[0].getblocktemplate, {}) |
|
|
|
# tx2 (segwit input, paying to a non-segwit output) -> |
|
|
|
tmpl = self.nodes[0].getblocktemplate() |
|
|
|
# tx3 (non-segwit input, paying to a non-segwit output). |
|
|
|
# TODO: add a transaction with witness to mempool, and verify it's not |
|
|
|
# tx1 is allowed to appear in the block, but no others. |
|
|
|
# selected for mining. |
|
|
|
txid1 = send_to_witness(1, self.nodes[0], find_unspent(self.nodes[0], 50), self.pubkey[0], False, Decimal("49.996")) |
|
|
|
|
|
|
|
hex_tx = self.nodes[0].gettransaction(txid)['hex'] |
|
|
|
|
|
|
|
tx = FromHex(CTransaction(), hex_tx) |
|
|
|
|
|
|
|
assert(tx.wit.is_null()) # This should not be a segwit input |
|
|
|
|
|
|
|
assert(txid1 in self.nodes[0].getrawmempool()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Now create tx2, which will spend from txid1. |
|
|
|
|
|
|
|
tx = CTransaction() |
|
|
|
|
|
|
|
tx.vin.append(CTxIn(COutPoint(int(txid1, 16), 0), b'')) |
|
|
|
|
|
|
|
tx.vout.append(CTxOut(int(49.99*COIN), CScript([OP_TRUE]))) |
|
|
|
|
|
|
|
tx2_hex = self.nodes[0].signrawtransaction(ToHex(tx))['hex'] |
|
|
|
|
|
|
|
txid2 = self.nodes[0].sendrawtransaction(tx2_hex) |
|
|
|
|
|
|
|
tx = FromHex(CTransaction(), tx2_hex) |
|
|
|
|
|
|
|
assert(not tx.wit.is_null()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Now create tx3, which will spend from txid2 |
|
|
|
|
|
|
|
tx = CTransaction() |
|
|
|
|
|
|
|
tx.vin.append(CTxIn(COutPoint(int(txid2, 16), 0), b"")) |
|
|
|
|
|
|
|
tx.vout.append(CTxOut(int(49.95*COIN), CScript([OP_TRUE]))) # Huge fee |
|
|
|
|
|
|
|
tx.calc_sha256() |
|
|
|
|
|
|
|
txid3 = self.nodes[0].sendrawtransaction(ToHex(tx)) |
|
|
|
|
|
|
|
assert(tx.wit.is_null()) |
|
|
|
|
|
|
|
assert(txid3 in self.nodes[0].getrawmempool()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Now try calling getblocktemplate() without segwit support. |
|
|
|
|
|
|
|
template = self.nodes[0].getblocktemplate() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Check that tx1 is the only transaction of the 3 in the template. |
|
|
|
|
|
|
|
template_txids = [ t['txid'] for t in template['transactions'] ] |
|
|
|
|
|
|
|
assert(txid2 not in template_txids and txid3 not in template_txids) |
|
|
|
|
|
|
|
assert(txid1 in template_txids) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Check that running with segwit support results in all 3 being included. |
|
|
|
|
|
|
|
template = self.nodes[0].getblocktemplate({"rules": ["segwit"]}) |
|
|
|
|
|
|
|
template_txids = [ t['txid'] for t in template['transactions'] ] |
|
|
|
|
|
|
|
assert(txid1 in template_txids) |
|
|
|
|
|
|
|
assert(txid2 in template_txids) |
|
|
|
|
|
|
|
assert(txid3 in template_txids) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Mine a block to clear the gbt cache again. |
|
|
|
|
|
|
|
self.nodes[0].generate(1) |
|
|
|
|
|
|
|
|
|
|
|
self.log.info("Verify behaviour of importaddress, addwitnessaddress and listunspent") |
|
|
|
self.log.info("Verify behaviour of importaddress, addwitnessaddress and listunspent") |
|
|
|
|
|
|
|
|
|
|
|