Skip to content

Commit e30a12b

Browse files
committed
Add BITCOIN_ASSET to all occurrences of getbalance()
1 parent ab00a4e commit e30a12b

26 files changed

+151
-138
lines changed

test/functional/feature_blocksign.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import random
66

77
from test_framework.test_framework import BitcoinTestFramework
8-
from test_framework.util import (assert_raises_rpc_error, assert_equal, connect_nodes_bi)
8+
from test_framework.util import (assert_raises_rpc_error, assert_equal, connect_nodes_bi, BITCOIN_ASSET)
99
from test_framework import (
1010
address,
1111
key,
@@ -97,12 +97,12 @@ def mine_block(self, make_transactions):
9797
if make_transactions:
9898
print(mineridx)
9999
for i in range(5):
100-
print(miner.getbalance())
101-
print(int(miner.getbalance()/10))
102-
txid = miner.sendtoaddress(miner_next.getnewaddress(), int(miner.getbalance()/10), "", "", True)
100+
print(miner.getbalance('*', 0, False, BITCOIN_ASSET))
101+
print(int(miner.getbalance('*', 0, False, BITCOIN_ASSET)/10))
102+
txid = miner.sendtoaddress(miner_next.getnewaddress(), int(miner.getbalance('*', 0, False, BITCOIN_ASSET)/10), "", "", True)
103103
print(txid)
104104
print(miner.getrawtransaction(txid))
105-
print(miner.getbalance())
105+
print(miner.getbalance('*', 0, False, BITCOIN_ASSET))
106106
# miner makes a block
107107
block = miner.getnewblockhex()
108108

test/functional/feature_pak.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Distributed under the MIT/X11 software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
from test_framework.test_framework import BitcoinTestFramework
6-
from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes_bi, sync_blocks, Decimal
6+
from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes_bi, sync_blocks, Decimal, BITCOIN_ASSET
77
import copy
88
import time
99

@@ -264,7 +264,7 @@ def compare(actual, expected):
264264
pak1_pegout_txid = self.nodes[i_pak1].sendtomainchain("", 1)["txid"]
265265
assert_equal(self.nodes[i_pak1].getwalletpakinfo()["bip32_counter"], "1")
266266
# Also spend the change to make chained payment that will be rejected as well
267-
pak1_child_txid = self.nodes[i_pak1].sendtoaddress(self.nodes[i_pak1].getnewaddress(), self.nodes[i_pak1].getbalance(), "", "", True)
267+
pak1_child_txid = self.nodes[i_pak1].sendtoaddress(self.nodes[i_pak1].getnewaddress(), self.nodes[i_pak1].getbalance('*', 0, False, BITCOIN_ASSET), "", "", True)
268268

269269

270270
# Wait for node("follow the leader" conf-undefined) to get transaction in

test/functional/feature_rbf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from test_framework.messages import COIN, COutPoint, CTransaction, CTxIn, CTxOut
1010
from test_framework.script import CScript, OP_DROP
1111
from test_framework.test_framework import BitcoinTestFramework
12-
from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str, satoshi_round
12+
from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str, satoshi_round, BITCOIN_ASSET
1313

1414
MAX_REPLACEMENT_LIMIT = 100
1515

@@ -25,7 +25,7 @@ def make_utxo(node, amount, confirmed=True, scriptPubKey=CScript([1])):
2525
unconfirmed otherwise.
2626
"""
2727
fee = 1*COIN
28-
while node.getbalance() < satoshi_round((amount + fee)/COIN):
28+
while node.getbalance('*', 0, False, BITCOIN_ASSET) < satoshi_round((amount + fee)/COIN):
2929
node.generate(100)
3030

3131
new_addr = node.getnewaddress()

test/functional/feature_segwit.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from test_framework.messages import COIN, COutPoint, CTransaction, CTxIn, CTxOut, FromHex, sha256, ToHex
2020
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, OP_TRUE, OP_DROP
2121
from test_framework.test_framework import BitcoinTestFramework
22-
from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str, connect_nodes, hex_str_to_bytes, sync_blocks, try_rpc
22+
from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str, connect_nodes, hex_str_to_bytes, sync_blocks, try_rpc, BITCOIN_ASSET
2323

2424
from io import BytesIO
2525

@@ -111,7 +111,7 @@ def run_test(self):
111111
assert(tmpl['transactions'][0]['sigops'] == 2)
112112
self.nodes[0].generate(1) #block 162
113113

114-
balance_presetup = self.nodes[0].getbalance()
114+
balance_presetup = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET)
115115
self.pubkey = []
116116
p2sh_ids = [] # p2sh_ids[NODE][VER] is an array of txids that spend to a witness version VER pkscript to an address for NODE embedded in p2sh
117117
wit_ids = [] # wit_ids[NODE][VER] is an array of txids that spend to a witness version VER pkscript to an address for NODE via bare witness
@@ -143,9 +143,9 @@ def run_test(self):
143143
sync_blocks(self.nodes)
144144

145145
# Make sure all nodes recognize the transactions as theirs
146-
assert_equal(self.nodes[0].getbalance(), balance_presetup - 60*50 + 20*Decimal("49.999") + 50)
147-
assert_equal(self.nodes[1].getbalance(), 20*Decimal("49.999"))
148-
assert_equal(self.nodes[2].getbalance(), 20*Decimal("49.999"))
146+
assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), balance_presetup - 60*50 + 20*Decimal("49.999") + 50)
147+
assert_equal(self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET), 20*Decimal("49.999"))
148+
assert_equal(self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET), 20*Decimal("49.999"))
149149

150150
self.nodes[0].generate(260) #block 423
151151
sync_blocks(self.nodes)

test/functional/interface_rest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
assert_greater_than,
2121
assert_greater_than_or_equal,
2222
hex_str_to_bytes,
23+
BITCOIN_ASSET,
2324
)
2425

2526
class ReqType(Enum):
@@ -84,15 +85,15 @@ def run_test(self):
8485
self.nodes[1].generatetoaddress(100, not_related_address)
8586
self.sync_all()
8687

87-
assert_equal(self.nodes[0].getbalance(), 50)
88+
assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), 50)
8889

8990
txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1)
9091
self.sync_all()
9192
self.nodes[1].generatetoaddress(1, not_related_address)
9293
self.sync_all()
9394
bb_hash = self.nodes[0].getbestblockhash()
9495

95-
assert_equal(self.nodes[1].getbalance(), Decimal("0.1"))
96+
assert_equal(self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET), Decimal("0.1"))
9697

9798
self.log.info("Load the transaction using the /tx URI")
9899

test/functional/mempool_persist.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import time
4141

4242
from test_framework.test_framework import BitcoinTestFramework
43-
from test_framework.util import assert_equal, assert_raises_rpc_error, wait_until
43+
from test_framework.util import assert_equal, assert_raises_rpc_error, wait_until, BITCOIN_ASSET
4444

4545
class MempoolPersistTest(BitcoinTestFramework):
4646
def set_test_params(self):
@@ -61,7 +61,7 @@ def run_test(self):
6161
self.log.debug("Send 5 transactions from node2 (to its own address)")
6262
for i in range(5):
6363
self.nodes[2].sendtoaddress(self.nodes[2].getnewaddress(), Decimal("10"))
64-
node2_balance = self.nodes[2].getbalance()
64+
node2_balance = self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET)
6565
self.sync_all()
6666

6767
self.log.debug("Verify that node0 and node1 have 5 transactions in their mempools")
@@ -83,7 +83,7 @@ def run_test(self):
8383

8484
# Verify accounting of mempool transactions after restart is correct
8585
self.nodes[2].syncwithvalidationinterfacequeue() # Flush mempool to wallet
86-
assert_equal(node2_balance, self.nodes[2].getbalance())
86+
assert_equal(node2_balance, self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET))
8787

8888
self.log.debug("Stop-start node0 with -persistmempool=0. Verify that it doesn't load its mempool.dat file.")
8989
self.stop_nodes()

test/functional/p2p_compactblocks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from test_framework.mininode import mininode_lock, P2PInterface
1717
from test_framework.script import CScript, OP_TRUE, OP_DROP
1818
from test_framework.test_framework import BitcoinTestFramework
19-
from test_framework.util import assert_equal, get_bip9_status, satoshi_round, sync_blocks, wait_until
19+
from test_framework.util import assert_equal, get_bip9_status, satoshi_round, sync_blocks, wait_until, BITCOIN_ASSET
2020
from test_framework import util
2121

2222
# TestP2PConn: A peer we use to send messages to bitcoind, and store responses.
@@ -267,7 +267,7 @@ def test_compactblock_construction(self, node, test_node, version, use_witness_a
267267
# Want at least one segwit spend, so move all funds to
268268
# a witness address.
269269
address = node.addwitnessaddress(address)
270-
value_to_send = node.getbalance()
270+
value_to_send = node.getbalance('*', 0, False, BITCOIN_ASSET)
271271
node.sendtoaddress(address, satoshi_round(value_to_send-Decimal(0.1)))
272272
node.generate(1)
273273

test/functional/rpc_createmultisig.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""Test transaction signing using the signrawtransaction* RPCs."""
66

77
from test_framework.test_framework import BitcoinTestFramework
8+
from test_framework.util import BITCOIN_ASSET
89
import decimal
910

1011
class RpcCreateMultiSigTest(BitcoinTestFramework):
@@ -43,9 +44,9 @@ def checkbalances(self):
4344
node0.generate(100)
4445
self.sync_all()
4546

46-
bal0 = node0.getbalance()
47-
bal1 = node1.getbalance()
48-
bal2 = node2.getbalance()
47+
bal0 = node0.getbalance('*', 0, False, BITCOIN_ASSET)
48+
bal1 = node1.getbalance('*', 0, False, BITCOIN_ASSET)
49+
bal2 = node2.getbalance('*', 0, False, BITCOIN_ASSET)
4950

5051
height = node0.getblockchaininfo()["blocks"]
5152
assert 150 < height < 350

test/functional/rpc_fundrawtransaction.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
connect_nodes_bi,
1616
count_bytes,
1717
find_vout_for_address,
18+
BITCOIN_ASSET,
1819
)
1920

2021

@@ -461,7 +462,7 @@ def run_test(self):
461462
self.nodes[1].generate(1)
462463
self.sync_all()
463464

464-
oldBalance = self.nodes[1].getbalance()
465+
oldBalance = self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET)
465466
inputs = []
466467
outputs = {self.nodes[1].getnewaddress():1.1}
467468
rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
@@ -474,7 +475,7 @@ def run_test(self):
474475
self.sync_all()
475476

476477
# make sure funds are received at node1
477-
assert_equal(oldBalance+Decimal('1.10000000'), self.nodes[1].getbalance())
478+
assert_equal(oldBalance+Decimal('1.10000000'), self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET))
478479

479480
############################################################
480481
# locked wallet test
@@ -513,7 +514,7 @@ def run_test(self):
513514

514515
assert_raises_rpc_error(-13, "walletpassphrase", self.nodes[1].sendtoaddress, self.nodes[0].getnewaddress(), 1.2)
515516

516-
oldBalance = self.nodes[0].getbalance()
517+
oldBalance = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET)
517518

518519
inputs = []
519520
outputs = {self.nodes[0].getnewaddress():1.1}
@@ -528,15 +529,15 @@ def run_test(self):
528529
self.sync_all()
529530

530531
# make sure funds are received at node1
531-
assert_equal(oldBalance+Decimal('51.10000000'), self.nodes[0].getbalance())
532+
assert_equal(oldBalance+Decimal('51.10000000'), self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET))
532533

533534

534535
###############################################
535536
# multiple (~19) inputs tx test | Compare fee #
536537
###############################################
537538

538539
#empty node1, send some small coins from node0 to node1
539-
self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), self.nodes[1].getbalance(), "", "", True)
540+
self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET), "", "", True)
540541
self.sync_all()
541542
self.nodes[0].generate(1)
542543
self.sync_all()
@@ -566,7 +567,7 @@ def run_test(self):
566567
#############################################
567568

568569
#again, empty node1, send some small coins from node0 to node1
569-
self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), self.nodes[1].getbalance(), "", "", True)
570+
self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET), "", "", True)
570571
self.sync_all()
571572
self.nodes[0].generate(1)
572573
self.sync_all()
@@ -577,7 +578,7 @@ def run_test(self):
577578
self.sync_all()
578579

579580
#fund a tx with ~20 small inputs
580-
oldBalance = self.nodes[0].getbalance()
581+
oldBalance = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET)
581582

582583
inputs = []
583584
outputs = {self.nodes[0].getnewaddress():0.15,self.nodes[0].getnewaddress():0.04}
@@ -588,7 +589,7 @@ def run_test(self):
588589
self.sync_all()
589590
self.nodes[0].generate(1)
590591
self.sync_all()
591-
assert_equal(oldBalance+Decimal('50.19000000'), self.nodes[0].getbalance()) #0.19+block reward
592+
assert_equal(oldBalance+Decimal('50.19000000'), self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET)) #0.19+block reward
592593

593594
#####################################################
594595
# test fundrawtransaction with OP_RETURN and no vin #

test/functional/rpc_rawtransaction.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from io import BytesIO
1818
from test_framework.messages import CTransaction, ToHex
1919
from test_framework.test_framework import BitcoinTestFramework
20-
from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str, connect_nodes_bi, hex_str_to_bytes
20+
from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str, connect_nodes_bi, hex_str_to_bytes, BITCOIN_ASSET
2121

2222
class multidict(dict):
2323
"""Dictionary that allows duplicate keys.
@@ -253,18 +253,18 @@ def run_test(self):
253253
mSigObj = self.nodes[2].addmultisigaddress(2, [addr1Obj['pubkey'], addr1])['address']
254254

255255
#use balance deltas instead of absolute values
256-
bal = self.nodes[2].getbalance()
256+
bal = self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET)
257257

258258
# send 1.2 BTC to msig adr
259259
txId = self.nodes[0].sendtoaddress(mSigObj, 1.2)
260260
self.sync_all()
261261
self.nodes[0].generate(1)
262262
self.sync_all()
263-
assert_equal(self.nodes[2].getbalance(), bal+Decimal('1.20000000')) #node2 has both keys of the 2of2 ms addr., tx should affect the balance
263+
assert_equal(self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET), bal+Decimal('1.20000000')) #node2 has both keys of the 2of2 ms addr., tx should affect the balance
264264

265265

266266
# 2of3 test from different nodes
267-
bal = self.nodes[2].getbalance()
267+
bal = self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET)
268268
addr1 = self.nodes[1].getnewaddress()
269269
addr2 = self.nodes[2].getnewaddress()
270270
addr3 = self.nodes[2].getnewaddress()
@@ -284,7 +284,7 @@ def run_test(self):
284284

285285
#THIS IS AN INCOMPLETE FEATURE
286286
#NODE2 HAS TWO OF THREE KEY AND THE FUNDS SHOULD BE SPENDABLE AND COUNT AT BALANCE CALCULATION
287-
assert_equal(self.nodes[2].getbalance(), bal) #for now, assume the funds of a 2of3 multisig tx are not marked as spendable
287+
assert_equal(self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET), bal) #for now, assume the funds of a 2of3 multisig tx are not marked as spendable
288288

289289
txDetails = self.nodes[0].gettransaction(txId, True)
290290
rawTx = self.nodes[0].decoderawtransaction(txDetails['hex'])
@@ -294,7 +294,7 @@ def run_test(self):
294294
vout = outpoint
295295
break
296296

297-
bal = self.nodes[0].getbalance()
297+
bal = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET)
298298
inputs = [{ "txid" : txId, "vout" : vout['n'], "scriptPubKey" : vout['scriptPubKey']['hex'], "amount" : vout['value']}]
299299
outputs = { self.nodes[0].getnewaddress() : 2.19 }
300300
rawTx = self.nodes[2].createrawtransaction(inputs, outputs)
@@ -308,10 +308,10 @@ def run_test(self):
308308
self.sync_all()
309309
self.nodes[0].generate(1)
310310
self.sync_all()
311-
assert_equal(self.nodes[0].getbalance(), bal+Decimal('50.00000000')+Decimal('2.19000000')) #block reward + tx
311+
assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), bal+Decimal('50.00000000')+Decimal('2.19000000')) #block reward + tx
312312

313313
# 2of2 test for combining transactions
314-
bal = self.nodes[2].getbalance()
314+
bal = self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET)
315315
addr1 = self.nodes[1].getnewaddress()
316316
addr2 = self.nodes[2].getnewaddress()
317317

@@ -329,7 +329,7 @@ def run_test(self):
329329
self.nodes[0].generate(1)
330330
self.sync_all()
331331

332-
assert_equal(self.nodes[2].getbalance(), bal) # the funds of a 2of2 multisig tx should not be marked as spendable
332+
assert_equal(self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET), bal) # the funds of a 2of2 multisig tx should not be marked as spendable
333333

334334
txDetails = self.nodes[0].gettransaction(txId, True)
335335
rawTx2 = self.nodes[0].decoderawtransaction(txDetails['hex'])
@@ -339,7 +339,7 @@ def run_test(self):
339339
vout = outpoint
340340
break
341341

342-
bal = self.nodes[0].getbalance()
342+
bal = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET)
343343
inputs = [{ "txid" : txId, "vout" : vout['n'], "scriptPubKey" : vout['scriptPubKey']['hex'], "redeemScript" : mSigObjValid['hex'], "amount" : vout['value']}]
344344
outputs = { self.nodes[0].getnewaddress() : 2.19 }
345345
rawTx2 = self.nodes[2].createrawtransaction(inputs, outputs)
@@ -357,7 +357,7 @@ def run_test(self):
357357
self.sync_all()
358358
self.nodes[0].generate(1)
359359
self.sync_all()
360-
assert_equal(self.nodes[0].getbalance(), bal+Decimal('50.00000000')+Decimal('2.19000000')) #block reward + tx
360+
assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), bal+Decimal('50.00000000')+Decimal('2.19000000')) #block reward + tx
361361

362362
# decoderawtransaction tests
363363
# witness transaction

0 commit comments

Comments
 (0)