Skip to content

Commit 8bcafc7

Browse files
committed
Fix functional/feature_segwit.py file
1 parent 1f93c0e commit 8bcafc7

File tree

2 files changed

+52
-26
lines changed

2 files changed

+52
-26
lines changed

test/functional/feature_dbcrash.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def set_test_params(self):
6565

6666
# Node3 is a normal node with default args, except will mine full blocks
6767
# and txs with "dust" outputs
68-
self.node3_args = ["-blockmaxweight=4000000", "-dustrelayfee=0"]
68+
self.node3_args = ["-blockmaxweight=400000", "-dustrelayfee=0"]
6969
self.extra_args = [self.node0_args, self.node1_args, self.node2_args, self.node3_args]
7070

7171
def setup_network(self):

test/functional/feature_segwit.py

+51-25
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
send_to_witness,
1818
witness_script,
1919
)
20+
from test_framework.descriptors import descsum_create
2021
from test_framework.messages import (
2122
COIN,
2223
COutPoint,
@@ -48,10 +49,10 @@
4849
assert_raises_rpc_error,
4950
try_rpc,
5051
)
51-
5252
from test_framework.wallet_util import (
5353
get_generate_key,
5454
)
55+
5556
NODE_0 = 0
5657
NODE_2 = 2
5758
P2WPKH = 0
@@ -112,7 +113,7 @@ def setup_network(self):
112113
self.sync_all()
113114

114115
def success_mine(self, node, txid, sign, redeem_script=""):
115-
send_to_witness(1, node, getutxo(txid), self.pubkey[0], False, Decimal("49.998"), sign, redeem_script)
116+
send_to_witness(1, node, getutxo(txid), self.pubkey[0], False, Decimal("199.998"), sign, redeem_script)
116117
block = self.generate(node, 1)
117118
assert_equal(len(node.getblock(block[0])["tx"]), 2)
118119
self.sync_blocks()
@@ -126,12 +127,12 @@ def run_test(self):
126127
self.log.info("Verify sigops are counted in GBT with pre-BIP141 rules before the fork")
127128
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
128129
tmpl = self.nodes[0].getblocktemplate({'rules': ['segwit']})
129-
assert_equal(tmpl['sizelimit'], 100000)
130-
assert 'weightlimit' not in tmpl
131-
assert_equal(tmpl['sigoplimit'], 20000)
132-
assert_equal(tmpl['transactions'][0]['hash'], txid)
133-
assert_equal(tmpl['transactions'][0]['sigops'], 2)
134-
assert '!segwit' not in tmpl['rules']
130+
assert_equal(tmpl['sizelimit'], 400000)
131+
#assert 'weightlimit' not in tmpl Commented out because Bitgesell defaults to segwit
132+
assert_equal(tmpl['sigoplimit'], 80000)
133+
#assert_equal(tmpl['transactions'][0]['hash'], txid) Commented out because Bitgesell defaults to segwit
134+
assert_equal(tmpl['transactions'][0]['sigops'], 9)
135+
#assert '!segwit' not in tmpl['rules'] Commented out because Bitgesell defaults to segwit
135136
self.generate(self.nodes[0], 1) # block 162
136137

137138
balance_presetup = self.nodes[0].getbalance()
@@ -147,6 +148,31 @@ def run_test(self):
147148
bip173_ms_addr = self.nodes[i].createmultisig(1, [self.pubkey[-1]], 'bech32')['address']
148149
assert_equal(p2sh_ms_addr, script_to_p2sh_p2wsh(multiscript))
149150
assert_equal(bip173_ms_addr, script_to_p2wsh(multiscript))
151+
152+
p2sh_ms_desc = descsum_create(f"sh(wsh(multi(1,{key.privkey})))")
153+
bip173_ms_desc = descsum_create(f"wsh(multi(1,{key.privkey}))")
154+
assert_equal(self.nodes[i].deriveaddresses(p2sh_ms_desc)[0], p2sh_ms_addr)
155+
assert_equal(self.nodes[i].deriveaddresses(bip173_ms_desc)[0], bip173_ms_addr)
156+
157+
sh_wpkh_desc = descsum_create(f"sh(wpkh({key.privkey}))")
158+
wpkh_desc = descsum_create(f"wpkh({key.privkey})")
159+
assert_equal(self.nodes[i].deriveaddresses(sh_wpkh_desc)[0], key.p2sh_p2wpkh_addr)
160+
assert_equal(self.nodes[i].deriveaddresses(wpkh_desc)[0], key.p2wpkh_addr)
161+
162+
if self.options.descriptors:
163+
res = self.nodes[i].importdescriptors([
164+
{"desc": p2sh_ms_desc, "timestamp": "now"},
165+
{"desc": bip173_ms_desc, "timestamp": "now"},
166+
{"desc": sh_wpkh_desc, "timestamp": "now"},
167+
{"desc": wpkh_desc, "timestamp": "now"},
168+
])
169+
else:
170+
# The nature of the legacy wallet is that this import results in also adding all of the necessary scripts
171+
res = self.nodes[i].importmulti([
172+
{"desc": p2sh_ms_desc, "timestamp": "now"},
173+
])
174+
assert all([r["success"] for r in res])
175+
150176
p2sh_ids.append([])
151177
wit_ids.append([])
152178
for _ in range(2):
@@ -156,15 +182,15 @@ def run_test(self):
156182
for _ in range(5):
157183
for n in range(3):
158184
for v in range(2):
159-
wit_ids[n][v].append(send_to_witness(v, self.nodes[0], find_spendable_utxo(self.nodes[0], 50), self.pubkey[n], False, Decimal("49.999")))
160-
p2sh_ids[n][v].append(send_to_witness(v, self.nodes[0], find_spendable_utxo(self.nodes[0], 50), self.pubkey[n], True, Decimal("49.999")))
185+
wit_ids[n][v].append(send_to_witness(v, self.nodes[0], find_spendable_utxo(self.nodes[0], 200), self.pubkey[n], False, Decimal("199.999")))
186+
p2sh_ids[n][v].append(send_to_witness(v, self.nodes[0], find_spendable_utxo(self.nodes[0], 200), self.pubkey[n], True, Decimal("199.999")))
161187

162188
self.generate(self.nodes[0], 1) # block 163
163189

164190
# Make sure all nodes recognize the transactions as theirs
165-
assert_equal(self.nodes[0].getbalance(), balance_presetup - 60 * 50 + 20 * Decimal("49.999") + 50)
166-
assert_equal(self.nodes[1].getbalance(), 20 * Decimal("49.999"))
167-
assert_equal(self.nodes[2].getbalance(), 20 * Decimal("49.999"))
191+
assert_equal(self.nodes[0].getbalance(), balance_presetup - 60 * 200 + 20 * Decimal("199.999") + 200)
192+
assert_equal(self.nodes[1].getbalance(), 20 * Decimal("199.999"))
193+
assert_equal(self.nodes[2].getbalance(), 20 * Decimal("199.999"))
168194

169195
self.log.info("Verify unsigned p2sh witness txs without a redeem script are invalid")
170196
self.fail_accept(self.nodes[2], "mandatory-script-verify-flag-failed (Operation not valid with the current stack size)", p2sh_ids[NODE_2][P2WPKH][1], sign=False)
@@ -174,10 +200,10 @@ def run_test(self):
174200

175201
self.log.info("Verify witness txs are mined as soon as segwit activates")
176202

177-
send_to_witness(1, self.nodes[2], getutxo(wit_ids[NODE_2][P2WPKH][0]), self.pubkey[0], encode_p2sh=False, amount=Decimal("49.998"), sign=True)
178-
send_to_witness(1, self.nodes[2], getutxo(wit_ids[NODE_2][P2WSH][0]), self.pubkey[0], encode_p2sh=False, amount=Decimal("49.998"), sign=True)
179-
send_to_witness(1, self.nodes[2], getutxo(p2sh_ids[NODE_2][P2WPKH][0]), self.pubkey[0], encode_p2sh=False, amount=Decimal("49.998"), sign=True)
180-
send_to_witness(1, self.nodes[2], getutxo(p2sh_ids[NODE_2][P2WSH][0]), self.pubkey[0], encode_p2sh=False, amount=Decimal("49.998"), sign=True)
203+
send_to_witness(1, self.nodes[2], getutxo(wit_ids[NODE_2][P2WPKH][0]), self.pubkey[0], encode_p2sh=False, amount=Decimal("199.998"), sign=True)
204+
send_to_witness(1, self.nodes[2], getutxo(wit_ids[NODE_2][P2WSH][0]), self.pubkey[0], encode_p2sh=False, amount=Decimal("199.998"), sign=True)
205+
send_to_witness(1, self.nodes[2], getutxo(p2sh_ids[NODE_2][P2WPKH][0]), self.pubkey[0], encode_p2sh=False, amount=Decimal("199.998"), sign=True)
206+
send_to_witness(1, self.nodes[2], getutxo(p2sh_ids[NODE_2][P2WSH][0]), self.pubkey[0], encode_p2sh=False, amount=Decimal("199.998"), sign=True)
181207

182208
assert_equal(len(self.nodes[2].getrawmempool()), 4)
183209
blockhash = self.generate(self.nodes[2], 1)[0] # block 165 (first block with new rules)
@@ -219,8 +245,8 @@ def run_test(self):
219245
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
220246
raw_tx = self.nodes[0].getrawtransaction(txid, True)
221247
tmpl = self.nodes[0].getblocktemplate({'rules': ['segwit']})
222-
assert_greater_than_or_equal(tmpl['sizelimit'], 3999577) # actual maximum size is lower due to minimum mandatory non-witness data
223-
assert_equal(tmpl['weightlimit'], 4000000)
248+
assert_greater_than_or_equal(tmpl['sizelimit'], 399957) # actual maximum size is lower due to minimum mandatory non-witness data
249+
assert_equal(tmpl['weightlimit'], 400000)
224250
assert_equal(tmpl['sigoplimit'], 80000)
225251
assert_equal(tmpl['transactions'][0]['txid'], txid)
226252
expected_sigops = 9 if 'txinwitness' in raw_tx["vin"][0] else 8
@@ -234,7 +260,7 @@ def run_test(self):
234260
# tx2 (segwit input, paying to a non-segwit output) ->
235261
# tx3 (non-segwit input, paying to a non-segwit output).
236262
# tx1 is allowed to appear in the block, but no others.
237-
txid1 = send_to_witness(1, self.nodes[0], find_spendable_utxo(self.nodes[0], 50), self.pubkey[0], False, Decimal("49.996"))
263+
txid1 = send_to_witness(1, self.nodes[0], find_spendable_utxo(self.nodes[0], 200), self.pubkey[0], False, Decimal("199.996"))
238264
assert txid1 in self.nodes[0].getrawmempool()
239265

240266
tx1_hex = self.nodes[0].gettransaction(txid1)['hex']
@@ -250,7 +276,7 @@ def run_test(self):
250276
# Now create tx2, which will spend from txid1.
251277
tx = CTransaction()
252278
tx.vin.append(CTxIn(COutPoint(int(txid1, 16), 0), b''))
253-
tx.vout.append(CTxOut(int(49.99 * COIN), CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
279+
tx.vout.append(CTxOut(int(199.99 * COIN), CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))
254280
tx2_hex = self.nodes[0].signrawtransactionwithwallet(tx.serialize().hex())['hex']
255281
txid2 = self.nodes[0].sendrawtransaction(tx2_hex)
256282
tx = tx_from_hex(tx2_hex)
@@ -305,9 +331,9 @@ def run_test(self):
305331

306332
# Import a compressed key and an uncompressed key, generate some multisig addresses
307333
self.nodes[0].importprivkey("92e6XLo5jVAVwrQKPNTs93oQco8f8sDNBcpv73Dsrs397fQtFQn")
308-
uncompressed_spendable_address = ["mvozP4UwyGD2mGZU4D2eMvMLPB9WkMmMQu"]
334+
uncompressed_spendable_address = ["EwnYZhXmJNXZntpoAuP72GPkvLJsyxUYJH"]
309335
self.nodes[0].importprivkey("cNC8eQ5dg3mFAVePDX4ddmPYpPbw41r9bm2jd1nLJT77e6RrzTRR")
310-
compressed_spendable_address = ["mmWQubrDomqpgSYekvsU7HWEVjLFHAakLe"]
336+
compressed_spendable_address = ["EnUy6Eu38tAMi4oysdDvmdYf2tVcYavA2C"]
311337
assert not self.nodes[0].getaddressinfo(uncompressed_spendable_address[0])['iscompressed']
312338
assert self.nodes[0].getaddressinfo(compressed_spendable_address[0])['iscompressed']
313339

@@ -472,9 +498,9 @@ def run_test(self):
472498
# Repeat some tests. This time we don't add witness scripts with importaddress
473499
# Import a compressed key and an uncompressed key, generate some multisig addresses
474500
self.nodes[0].importprivkey("927pw6RW8ZekycnXqBQ2JS5nPyo1yRfGNN8oq74HeddWSpafDJH")
475-
uncompressed_spendable_address = ["mguN2vNSCEUh6rJaXoAVwY3YZwZvEmf5xi"]
501+
uncompressed_spendable_address = ["EhsvDZRFXLoE8UZueVWxbt5y76jHPyiucv"]
476502
self.nodes[0].importprivkey("cMcrXaaUC48ZKpcyydfFo8PxHAjpsYLhdsp6nmtB3E2ER9UUHWnw")
477-
compressed_spendable_address = ["n1UNmpmbVUJ9ytXYXiurmGPQ3TRrXqPWKL"]
503+
compressed_spendable_address = ["F2SvxTpQpach1WnseRGKRcRpacbDmYjDZi"]
478504

479505
self.nodes[0].importpubkey(pubkeys[5])
480506
compressed_solvable_address = [key_to_p2pkh(pubkeys[5])]

0 commit comments

Comments
 (0)