|
|
@ -50,22 +50,22 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
self.sync_all() |
|
|
|
self.sync_all() |
|
|
|
|
|
|
|
|
|
|
|
def success_mine(self, node, txid, sign, redeem_script=""): |
|
|
|
def success_mine(self, node, txid, sign, redeem_script=""): |
|
|
|
send_to_witness(1, node, getutxo(txid), self.pubkey[0], False, Decimal("49.998"), sign, redeem_script) |
|
|
|
send_to_witness(1, node, getutxo(txid), self.pubkey[0], False, Decimal("499.998"), sign, redeem_script) |
|
|
|
block = node.generate(1) |
|
|
|
block = node.generate(1) |
|
|
|
assert_equal(len(node.getblock(block[0])["tx"]), 2) |
|
|
|
assert_equal(len(node.getblock(block[0])["tx"]), 2) |
|
|
|
sync_blocks(self.nodes) |
|
|
|
sync_blocks(self.nodes) |
|
|
|
|
|
|
|
|
|
|
|
def skip_mine(self, node, txid, sign, redeem_script=""): |
|
|
|
def skip_mine(self, node, txid, sign, redeem_script=""): |
|
|
|
send_to_witness(1, node, getutxo(txid), self.pubkey[0], False, Decimal("49.998"), sign, redeem_script) |
|
|
|
send_to_witness(1, node, getutxo(txid), self.pubkey[0], False, Decimal("499.998"), sign, redeem_script) |
|
|
|
block = node.generate(1) |
|
|
|
block = node.generate(1) |
|
|
|
assert_equal(len(node.getblock(block[0])["tx"]), 1) |
|
|
|
assert_equal(len(node.getblock(block[0])["tx"]), 1) |
|
|
|
sync_blocks(self.nodes) |
|
|
|
sync_blocks(self.nodes) |
|
|
|
|
|
|
|
|
|
|
|
def fail_accept(self, node, error_msg, txid, sign, redeem_script=""): |
|
|
|
def fail_accept(self, node, error_msg, txid, sign, redeem_script=""): |
|
|
|
assert_raises_rpc_error(-26, error_msg, send_to_witness, 1, node, getutxo(txid), self.pubkey[0], False, Decimal("49.998"), sign, redeem_script) |
|
|
|
assert_raises_rpc_error(-26, error_msg, send_to_witness, 1, node, getutxo(txid), self.pubkey[0], False, Decimal("499.998"), sign, redeem_script) |
|
|
|
|
|
|
|
|
|
|
|
def fail_mine(self, node, txid, sign, redeem_script=""): |
|
|
|
def fail_mine(self, node, txid, sign, redeem_script=""): |
|
|
|
send_to_witness(1, node, getutxo(txid), self.pubkey[0], False, Decimal("49.998"), sign, redeem_script) |
|
|
|
send_to_witness(1, node, getutxo(txid), self.pubkey[0], False, Decimal("499.998"), sign, redeem_script) |
|
|
|
assert_raises_rpc_error(-1, "CreateNewBlock: TestBlockValidity failed", node.generate, 1) |
|
|
|
assert_raises_rpc_error(-1, "CreateNewBlock: TestBlockValidity failed", node.generate, 1) |
|
|
|
sync_blocks(self.nodes) |
|
|
|
sync_blocks(self.nodes) |
|
|
|
|
|
|
|
|
|
|
@ -75,13 +75,13 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
self.log.info("Verify sigops are counted in GBT with pre-BIP141 rules before the fork") |
|
|
|
self.log.info("Verify sigops are counted in GBT with pre-BIP141 rules before the fork") |
|
|
|
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1) |
|
|
|
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1) |
|
|
|
tmpl = self.nodes[0].getblocktemplate({}) |
|
|
|
tmpl = self.nodes[0].getblocktemplate({}) |
|
|
|
assert(tmpl['sizelimit'] == 1000000) |
|
|
|
assert(tmpl['sizelimit'] == 1500000) |
|
|
|
assert('weightlimit' not in tmpl) |
|
|
|
assert('weightlimit' not in tmpl) |
|
|
|
assert(tmpl['sigoplimit'] == 20000) |
|
|
|
assert(tmpl['sigoplimit'] == 20000) |
|
|
|
assert(tmpl['transactions'][0]['hash'] == txid) |
|
|
|
assert(tmpl['transactions'][0]['hash'] == txid) |
|
|
|
assert(tmpl['transactions'][0]['sigops'] == 2) |
|
|
|
assert(tmpl['transactions'][0]['sigops'] == 2) |
|
|
|
tmpl = self.nodes[0].getblocktemplate({'rules':['segwit']}) |
|
|
|
tmpl = self.nodes[0].getblocktemplate({'rules':['segwit']}) |
|
|
|
assert(tmpl['sizelimit'] == 1000000) |
|
|
|
assert(tmpl['sizelimit'] == 1500000) |
|
|
|
assert('weightlimit' not in tmpl) |
|
|
|
assert('weightlimit' not in tmpl) |
|
|
|
assert(tmpl['sigoplimit'] == 20000) |
|
|
|
assert(tmpl['sigoplimit'] == 20000) |
|
|
|
assert(tmpl['transactions'][0]['hash'] == txid) |
|
|
|
assert(tmpl['transactions'][0]['hash'] == txid) |
|
|
@ -113,16 +113,16 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
for i in range(5): |
|
|
|
for i in range(5): |
|
|
|
for n in range(3): |
|
|
|
for n in range(3): |
|
|
|
for v in range(2): |
|
|
|
for v in range(2): |
|
|
|
wit_ids[n][v].append(send_to_witness(v, self.nodes[0], find_unspent(self.nodes[0], 50), self.pubkey[n], False, Decimal("49.999"))) |
|
|
|
wit_ids[n][v].append(send_to_witness(v, self.nodes[0], find_unspent(self.nodes[0], 500), self.pubkey[n], False, Decimal("499.999"))) |
|
|
|
p2sh_ids[n][v].append(send_to_witness(v, self.nodes[0], find_unspent(self.nodes[0], 50), self.pubkey[n], True, Decimal("49.999"))) |
|
|
|
p2sh_ids[n][v].append(send_to_witness(v, self.nodes[0], find_unspent(self.nodes[0], 500), self.pubkey[n], True, Decimal("499.999"))) |
|
|
|
|
|
|
|
|
|
|
|
self.nodes[0].generate(1) #block 163 |
|
|
|
self.nodes[0].generate(1) #block 163 |
|
|
|
sync_blocks(self.nodes) |
|
|
|
sync_blocks(self.nodes) |
|
|
|
|
|
|
|
|
|
|
|
# Make sure all nodes recognize the transactions as theirs |
|
|
|
# Make sure all nodes recognize the transactions as theirs |
|
|
|
assert_equal(self.nodes[0].getbalance(), balance_presetup - 60*50 + 20*Decimal("49.999") + 50) |
|
|
|
assert_equal(self.nodes[0].getbalance(), balance_presetup - 60*500 + 20*Decimal("499.999") + 500) |
|
|
|
assert_equal(self.nodes[1].getbalance(), 20*Decimal("49.999")) |
|
|
|
assert_equal(self.nodes[1].getbalance(), 20*Decimal("499.999")) |
|
|
|
assert_equal(self.nodes[2].getbalance(), 20*Decimal("49.999")) |
|
|
|
assert_equal(self.nodes[2].getbalance(), 20*Decimal("499.999")) |
|
|
|
|
|
|
|
|
|
|
|
self.nodes[0].generate(260) #block 423 |
|
|
|
self.nodes[0].generate(260) #block 423 |
|
|
|
sync_blocks(self.nodes) |
|
|
|
sync_blocks(self.nodes) |
|
|
@ -197,7 +197,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1) |
|
|
|
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1) |
|
|
|
tmpl = self.nodes[0].getblocktemplate({'rules':['segwit']}) |
|
|
|
tmpl = self.nodes[0].getblocktemplate({'rules':['segwit']}) |
|
|
|
assert(tmpl['sizelimit'] >= 3999577) # actual maximum size is lower due to minimum mandatory non-witness data |
|
|
|
assert(tmpl['sizelimit'] >= 3999577) # actual maximum size is lower due to minimum mandatory non-witness data |
|
|
|
assert(tmpl['weightlimit'] == 4000000) |
|
|
|
assert(tmpl['weightlimit'] == 6000000) |
|
|
|
assert(tmpl['sigoplimit'] == 80000) |
|
|
|
assert(tmpl['sigoplimit'] == 80000) |
|
|
|
assert(tmpl['transactions'][0]['txid'] == txid) |
|
|
|
assert(tmpl['transactions'][0]['txid'] == txid) |
|
|
|
assert(tmpl['transactions'][0]['sigops'] == 8) |
|
|
|
assert(tmpl['transactions'][0]['sigops'] == 8) |
|
|
@ -209,7 +209,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
# tx2 (segwit input, paying to a non-segwit output) -> |
|
|
|
# tx2 (segwit input, paying to a non-segwit output) -> |
|
|
|
# tx3 (non-segwit input, paying to a non-segwit output). |
|
|
|
# tx3 (non-segwit input, paying to a non-segwit output). |
|
|
|
# tx1 is allowed to appear in the block, but no others. |
|
|
|
# tx1 is allowed to appear in the block, but no others. |
|
|
|
txid1 = send_to_witness(1, self.nodes[0], find_unspent(self.nodes[0], 50), self.pubkey[0], False, Decimal("49.996")) |
|
|
|
txid1 = send_to_witness(1, self.nodes[0], find_unspent(self.nodes[0], 500), self.pubkey[0], False, Decimal("499.996")) |
|
|
|
hex_tx = self.nodes[0].gettransaction(txid)['hex'] |
|
|
|
hex_tx = self.nodes[0].gettransaction(txid)['hex'] |
|
|
|
tx = FromHex(CTransaction(), hex_tx) |
|
|
|
tx = FromHex(CTransaction(), hex_tx) |
|
|
|
assert(tx.wit.is_null()) # This should not be a segwit input |
|
|
|
assert(tx.wit.is_null()) # This should not be a segwit input |
|
|
@ -218,7 +218,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
# Now create tx2, which will spend from txid1. |
|
|
|
# Now create tx2, which will spend from txid1. |
|
|
|
tx = CTransaction() |
|
|
|
tx = CTransaction() |
|
|
|
tx.vin.append(CTxIn(COutPoint(int(txid1, 16), 0), b'')) |
|
|
|
tx.vin.append(CTxIn(COutPoint(int(txid1, 16), 0), b'')) |
|
|
|
tx.vout.append(CTxOut(int(49.99 * COIN), CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE]))) |
|
|
|
tx.vout.append(CTxOut(int(499.99 * COIN), CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE]))) |
|
|
|
tx2_hex = self.nodes[0].signrawtransaction(ToHex(tx))['hex'] |
|
|
|
tx2_hex = self.nodes[0].signrawtransaction(ToHex(tx))['hex'] |
|
|
|
txid2 = self.nodes[0].sendrawtransaction(tx2_hex) |
|
|
|
txid2 = self.nodes[0].sendrawtransaction(tx2_hex) |
|
|
|
tx = FromHex(CTransaction(), tx2_hex) |
|
|
|
tx = FromHex(CTransaction(), tx2_hex) |
|
|
@ -227,7 +227,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
# Now create tx3, which will spend from txid2 |
|
|
|
# Now create tx3, which will spend from txid2 |
|
|
|
tx = CTransaction() |
|
|
|
tx = CTransaction() |
|
|
|
tx.vin.append(CTxIn(COutPoint(int(txid2, 16), 0), b"")) |
|
|
|
tx.vin.append(CTxIn(COutPoint(int(txid2, 16), 0), b"")) |
|
|
|
tx.vout.append(CTxOut(int(49.95 * COIN), CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE]))) # Huge fee |
|
|
|
tx.vout.append(CTxOut(int(499.95 * COIN), CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE]))) # Huge fee |
|
|
|
tx.calc_sha256() |
|
|
|
tx.calc_sha256() |
|
|
|
txid3 = self.nodes[0].sendrawtransaction(ToHex(tx)) |
|
|
|
txid3 = self.nodes[0].sendrawtransaction(ToHex(tx)) |
|
|
|
assert(tx.wit.is_null()) |
|
|
|
assert(tx.wit.is_null()) |
|
|
@ -570,7 +570,7 @@ class SegWitTest(BitcoinTestFramework): |
|
|
|
assert_equal(self.nodes[1].listtransactions("*", 1, 0, True)[0]["txid"], txid) |
|
|
|
assert_equal(self.nodes[1].listtransactions("*", 1, 0, True)[0]["txid"], txid) |
|
|
|
|
|
|
|
|
|
|
|
def mine_and_test_listunspent(self, script_list, ismine): |
|
|
|
def mine_and_test_listunspent(self, script_list, ismine): |
|
|
|
utxo = find_unspent(self.nodes[0], 50) |
|
|
|
utxo = find_unspent(self.nodes[0], 500) |
|
|
|
tx = CTransaction() |
|
|
|
tx = CTransaction() |
|
|
|
tx.vin.append(CTxIn(COutPoint(int('0x'+utxo['txid'],0), utxo['vout']))) |
|
|
|
tx.vin.append(CTxIn(COutPoint(int('0x'+utxo['txid'],0), utxo['vout']))) |
|
|
|
for i in script_list: |
|
|
|
for i in script_list: |
|
|
|