Skip to content

Commit 25a8170

Browse files
committed
test: rpc_createmultisig, remove unnecessary checkbalances()
The function exists merely to check that the node2's wallet received the transactions created during all the 'do_multisig()' calls. It was created as a standalone function because 'getbalance()' only returns something when transactions are confirmed. So, the rationale on that time was to have a method mining blocks to confirm the recently created transactions to be able to check the incoming balance. This is why we have the "moved" class field. This change removes all the hardcoded amounts and verifies node2 balance reception directly inside 'do_multisig()'.
1 parent b5a3289 commit 25a8170

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

test/functional/rpc_createmultisig.py

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import os
1010

1111
from test_framework.address import address_to_scriptpubkey
12-
from test_framework.blocktools import COINBASE_MATURITY
1312
from test_framework.descriptors import descsum_create, drop_origins
1413
from test_framework.key import ECPubKey
1514
from test_framework.messages import COIN
@@ -41,10 +40,6 @@ def create_keys(self, num_keys):
4140
privkey, pubkey = generate_keypair(wif=True)
4241
self.pub.append(pubkey.hex())
4342
self.priv.append(privkey)
44-
if self.is_bdb_compiled():
45-
self.final = self.nodes[2].getnewaddress()
46-
else:
47-
self.final = getnewdestination('bech32')[2]
4843

4944
def create_wallet(self, node, wallet_name):
5045
node.createwallet(wallet_name=wallet_name, disable_private_keys=True)
@@ -54,23 +49,20 @@ def run_test(self):
5449
node0, node1, node2 = self.nodes
5550
self.wallet = MiniWallet(test_node=node0)
5651

57-
if self.is_bdb_compiled():
52+
if self.is_wallet_compiled():
5853
self.check_addmultisigaddress_errors()
5954

6055
self.log.info('Generating blocks ...')
6156
self.generate(self.wallet, 149)
6257

6358
wallet_multi = self.create_wallet(node1, 'wmulti') if self._requires_wallet else None
64-
self.moved = 0
6559
self.create_keys(5)
6660
for nkeys in [3, 5]:
6761
for nsigs in [2, 3]:
6862
for output_type in ["bech32", "p2sh-segwit", "legacy"]:
6963
self.do_multisig(nkeys, nsigs, output_type, wallet_multi)
7064
if wallet_multi is not None:
7165
wallet_multi.unloadwallet()
72-
if self.is_bdb_compiled():
73-
self.checkbalances()
7466

7567
# Test mixed compressed and uncompressed pubkeys
7668
self.log.info('Mixed compressed and uncompressed multisigs are not allowed')
@@ -139,22 +131,6 @@ def check_addmultisigaddress_errors(self):
139131
pubs = [self.nodes[1].getaddressinfo(addr)["pubkey"] for addr in addresses]
140132
assert_raises_rpc_error(-5, "Bech32m multisig addresses cannot be created with legacy wallets", self.nodes[0].addmultisigaddress, 2, pubs, "", "bech32m")
141133

142-
def checkbalances(self):
143-
node0, node1, node2 = self.nodes
144-
self.generate(node0, COINBASE_MATURITY)
145-
146-
bal0 = node0.getbalance()
147-
bal1 = node1.getbalance()
148-
bal2 = node2.getbalance()
149-
balw = self.wallet.get_balance()
150-
151-
height = node0.getblockchaininfo()["blocks"]
152-
assert 150 < height < 350
153-
total = 149 * 50 + (height - 149 - 100) * 25
154-
assert bal1 == 0
155-
assert bal2 == self.moved
156-
assert_equal(bal0 + bal1 + bal2 + balw, total)
157-
158134
def do_multisig(self, nkeys, nsigs, output_type, wallet_multi):
159135
node0, node1, node2 = self.nodes
160136
pub_keys = self.pub[0: nkeys]
@@ -196,7 +172,10 @@ def do_multisig(self, nkeys, nsigs, output_type, wallet_multi):
196172
self.generate(node0, 1)
197173

198174
outval = value - decimal.Decimal("0.00001000")
199-
rawtx = node2.createrawtransaction([{"txid": tx["txid"], "vout": tx["sent_vout"]}], [{self.final: outval}])
175+
# send coins to node2 when wallet is enabled
176+
node2_balance = node2.getbalances()['mine']['trusted'] if self.is_wallet_compiled() else 0
177+
out_addr = node2.getnewaddress() if self.is_wallet_compiled() else getnewdestination('bech32')[2]
178+
rawtx = node2.createrawtransaction([{"txid": tx["txid"], "vout": tx["sent_vout"]}], [{out_addr: outval}])
200179

201180
prevtx_err = dict(prevtxs[0])
202181
del prevtx_err["redeemScript"]
@@ -227,11 +206,14 @@ def do_multisig(self, nkeys, nsigs, output_type, wallet_multi):
227206
rawtx2 = node2.signrawtransactionwithkey(rawtx, priv_keys[0:nsigs - 1], prevtxs)
228207
rawtx3 = node2.signrawtransactionwithkey(rawtx2["hex"], [priv_keys[-1]], prevtxs)
229208

230-
self.moved += outval
231209
tx = node0.sendrawtransaction(rawtx3["hex"], 0)
232210
blk = self.generate(node0, 1)[0]
233211
assert tx in node0.getblock(blk)["tx"]
234212

213+
# When the wallet is enabled, assert node2 sees the incoming amount
214+
if self.is_wallet_compiled():
215+
assert_equal(node2.getbalances()['mine']['trusted'], node2_balance + outval)
216+
235217
txinfo = node0.getrawtransaction(tx, True, blk)
236218
self.log.info("n/m=%d/%d %s size=%d vsize=%d weight=%d" % (nsigs, nkeys, output_type, txinfo["size"], txinfo["vsize"], txinfo["weight"]))
237219

0 commit comments

Comments
 (0)