From e30a12bcfa238393d42c56aa74acf748fb14e089 Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Fri, 22 Feb 2019 19:24:30 +0000 Subject: [PATCH] Add BITCOIN_ASSET to all occurrences of getbalance() --- test/functional/feature_blocksign.py | 10 ++--- test/functional/feature_pak.py | 4 +- test/functional/feature_rbf.py | 4 +- test/functional/feature_segwit.py | 10 ++--- test/functional/interface_rest.py | 5 ++- test/functional/mempool_persist.py | 6 +-- test/functional/p2p_compactblocks.py | 4 +- test/functional/rpc_createmultisig.py | 7 +-- test/functional/rpc_fundrawtransaction.py | 17 +++---- test/functional/rpc_rawtransaction.py | 22 ++++----- test/functional/rpc_txoutproof.py | 6 +-- test/functional/test_framework/messages.py | 6 +-- test/functional/test_framework/util.py | 5 +++ test/functional/wallet_abandonconflict.py | 26 +++++------ test/functional/wallet_address_types.py | 5 ++- test/functional/wallet_backup.py | 36 +++++++-------- test/functional/wallet_basic.py | 49 +++++++++++---------- test/functional/wallet_bumpfee.py | 4 +- test/functional/wallet_groups.py | 3 +- test/functional/wallet_hd.py | 11 ++--- test/functional/wallet_importprunedfunds.py | 5 ++- test/functional/wallet_keypool_topup.py | 3 +- test/functional/wallet_labels.py | 4 +- test/functional/wallet_multiwallet.py | 15 ++++--- test/functional/wallet_txn_clone.py | 9 ++-- test/functional/wallet_txn_doublespend.py | 13 +++--- 26 files changed, 151 insertions(+), 138 deletions(-) diff --git a/test/functional/feature_blocksign.py b/test/functional/feature_blocksign.py index 8d9b188a61..e52d483fe2 100755 --- a/test/functional/feature_blocksign.py +++ b/test/functional/feature_blocksign.py @@ -5,7 +5,7 @@ import random from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import (assert_raises_rpc_error, assert_equal, connect_nodes_bi) +from test_framework.util import (assert_raises_rpc_error, assert_equal, connect_nodes_bi, BITCOIN_ASSET) from test_framework import ( address, key, @@ -97,12 +97,12 @@ def mine_block(self, make_transactions): if make_transactions: print(mineridx) for i in range(5): - print(miner.getbalance()) - print(int(miner.getbalance()/10)) - txid = miner.sendtoaddress(miner_next.getnewaddress(), int(miner.getbalance()/10), "", "", True) + print(miner.getbalance('*', 0, False, BITCOIN_ASSET)) + print(int(miner.getbalance('*', 0, False, BITCOIN_ASSET)/10)) + txid = miner.sendtoaddress(miner_next.getnewaddress(), int(miner.getbalance('*', 0, False, BITCOIN_ASSET)/10), "", "", True) print(txid) print(miner.getrawtransaction(txid)) - print(miner.getbalance()) + print(miner.getbalance('*', 0, False, BITCOIN_ASSET)) # miner makes a block block = miner.getnewblockhex() diff --git a/test/functional/feature_pak.py b/test/functional/feature_pak.py index 4a22efbe72..6a90ae9b85 100755 --- a/test/functional/feature_pak.py +++ b/test/functional/feature_pak.py @@ -3,7 +3,7 @@ # Distributed under the MIT/X11 software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes_bi, sync_blocks, Decimal +from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes_bi, sync_blocks, Decimal, BITCOIN_ASSET import copy import time @@ -264,7 +264,7 @@ def compare(actual, expected): pak1_pegout_txid = self.nodes[i_pak1].sendtomainchain("", 1)["txid"] assert_equal(self.nodes[i_pak1].getwalletpakinfo()["bip32_counter"], "1") # Also spend the change to make chained payment that will be rejected as well - pak1_child_txid = self.nodes[i_pak1].sendtoaddress(self.nodes[i_pak1].getnewaddress(), self.nodes[i_pak1].getbalance(), "", "", True) + pak1_child_txid = self.nodes[i_pak1].sendtoaddress(self.nodes[i_pak1].getnewaddress(), self.nodes[i_pak1].getbalance('*', 0, False, BITCOIN_ASSET), "", "", True) # Wait for node("follow the leader" conf-undefined) to get transaction in diff --git a/test/functional/feature_rbf.py b/test/functional/feature_rbf.py index ff7c2b23bf..be14a47530 100755 --- a/test/functional/feature_rbf.py +++ b/test/functional/feature_rbf.py @@ -9,7 +9,7 @@ from test_framework.messages import COIN, COutPoint, CTransaction, CTxIn, CTxOut from test_framework.script import CScript, OP_DROP from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str, satoshi_round +from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str, satoshi_round, BITCOIN_ASSET MAX_REPLACEMENT_LIMIT = 100 @@ -25,7 +25,7 @@ def make_utxo(node, amount, confirmed=True, scriptPubKey=CScript([1])): unconfirmed otherwise. """ fee = 1*COIN - while node.getbalance() < satoshi_round((amount + fee)/COIN): + while node.getbalance('*', 0, False, BITCOIN_ASSET) < satoshi_round((amount + fee)/COIN): node.generate(100) new_addr = node.getnewaddress() diff --git a/test/functional/feature_segwit.py b/test/functional/feature_segwit.py index 34a5f14937..53aabbfe2e 100755 --- a/test/functional/feature_segwit.py +++ b/test/functional/feature_segwit.py @@ -19,7 +19,7 @@ from test_framework.messages import COIN, COutPoint, CTransaction, CTxIn, CTxOut, FromHex, sha256, ToHex 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 from test_framework.test_framework import BitcoinTestFramework -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 +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 from io import BytesIO @@ -111,7 +111,7 @@ def run_test(self): assert(tmpl['transactions'][0]['sigops'] == 2) self.nodes[0].generate(1) #block 162 - balance_presetup = self.nodes[0].getbalance() + balance_presetup = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET) self.pubkey = [] 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 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): sync_blocks(self.nodes) # 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[1].getbalance(), 20*Decimal("49.999")) - assert_equal(self.nodes[2].getbalance(), 20*Decimal("49.999")) + assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), balance_presetup - 60*50 + 20*Decimal("49.999") + 50) + assert_equal(self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET), 20*Decimal("49.999")) + assert_equal(self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET), 20*Decimal("49.999")) self.nodes[0].generate(260) #block 423 sync_blocks(self.nodes) diff --git a/test/functional/interface_rest.py b/test/functional/interface_rest.py index 7ebeea558a..01714c57c4 100755 --- a/test/functional/interface_rest.py +++ b/test/functional/interface_rest.py @@ -20,6 +20,7 @@ assert_greater_than, assert_greater_than_or_equal, hex_str_to_bytes, + BITCOIN_ASSET, ) class ReqType(Enum): @@ -84,7 +85,7 @@ def run_test(self): self.nodes[1].generatetoaddress(100, not_related_address) self.sync_all() - assert_equal(self.nodes[0].getbalance(), 50) + assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), 50) txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1) self.sync_all() @@ -92,7 +93,7 @@ def run_test(self): self.sync_all() bb_hash = self.nodes[0].getbestblockhash() - assert_equal(self.nodes[1].getbalance(), Decimal("0.1")) + assert_equal(self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET), Decimal("0.1")) self.log.info("Load the transaction using the /tx URI") diff --git a/test/functional/mempool_persist.py b/test/functional/mempool_persist.py index 281b127c5a..bcdcc4f347 100755 --- a/test/functional/mempool_persist.py +++ b/test/functional/mempool_persist.py @@ -40,7 +40,7 @@ import time from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, assert_raises_rpc_error, wait_until +from test_framework.util import assert_equal, assert_raises_rpc_error, wait_until, BITCOIN_ASSET class MempoolPersistTest(BitcoinTestFramework): def set_test_params(self): @@ -61,7 +61,7 @@ def run_test(self): self.log.debug("Send 5 transactions from node2 (to its own address)") for i in range(5): self.nodes[2].sendtoaddress(self.nodes[2].getnewaddress(), Decimal("10")) - node2_balance = self.nodes[2].getbalance() + node2_balance = self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET) self.sync_all() self.log.debug("Verify that node0 and node1 have 5 transactions in their mempools") @@ -83,7 +83,7 @@ def run_test(self): # Verify accounting of mempool transactions after restart is correct self.nodes[2].syncwithvalidationinterfacequeue() # Flush mempool to wallet - assert_equal(node2_balance, self.nodes[2].getbalance()) + assert_equal(node2_balance, self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET)) self.log.debug("Stop-start node0 with -persistmempool=0. Verify that it doesn't load its mempool.dat file.") self.stop_nodes() diff --git a/test/functional/p2p_compactblocks.py b/test/functional/p2p_compactblocks.py index 48af469171..1a29878b99 100755 --- a/test/functional/p2p_compactblocks.py +++ b/test/functional/p2p_compactblocks.py @@ -16,7 +16,7 @@ from test_framework.mininode import mininode_lock, P2PInterface from test_framework.script import CScript, OP_TRUE, OP_DROP from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, get_bip9_status, satoshi_round, sync_blocks, wait_until +from test_framework.util import assert_equal, get_bip9_status, satoshi_round, sync_blocks, wait_until, BITCOIN_ASSET from test_framework import util # 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 # Want at least one segwit spend, so move all funds to # a witness address. address = node.addwitnessaddress(address) - value_to_send = node.getbalance() + value_to_send = node.getbalance('*', 0, False, BITCOIN_ASSET) node.sendtoaddress(address, satoshi_round(value_to_send-Decimal(0.1))) node.generate(1) diff --git a/test/functional/rpc_createmultisig.py b/test/functional/rpc_createmultisig.py index 3cc35a7b9a..71053b199f 100755 --- a/test/functional/rpc_createmultisig.py +++ b/test/functional/rpc_createmultisig.py @@ -5,6 +5,7 @@ """Test transaction signing using the signrawtransaction* RPCs.""" from test_framework.test_framework import BitcoinTestFramework +from test_framework.util import BITCOIN_ASSET import decimal class RpcCreateMultiSigTest(BitcoinTestFramework): @@ -43,9 +44,9 @@ def checkbalances(self): node0.generate(100) self.sync_all() - bal0 = node0.getbalance() - bal1 = node1.getbalance() - bal2 = node2.getbalance() + bal0 = node0.getbalance('*', 0, False, BITCOIN_ASSET) + bal1 = node1.getbalance('*', 0, False, BITCOIN_ASSET) + bal2 = node2.getbalance('*', 0, False, BITCOIN_ASSET) height = node0.getblockchaininfo()["blocks"] assert 150 < height < 350 diff --git a/test/functional/rpc_fundrawtransaction.py b/test/functional/rpc_fundrawtransaction.py index 07ffcab587..86df98f22f 100755 --- a/test/functional/rpc_fundrawtransaction.py +++ b/test/functional/rpc_fundrawtransaction.py @@ -15,6 +15,7 @@ connect_nodes_bi, count_bytes, find_vout_for_address, + BITCOIN_ASSET, ) @@ -461,7 +462,7 @@ def run_test(self): self.nodes[1].generate(1) self.sync_all() - oldBalance = self.nodes[1].getbalance() + oldBalance = self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET) inputs = [] outputs = {self.nodes[1].getnewaddress():1.1} rawtx = self.nodes[2].createrawtransaction(inputs, outputs) @@ -474,7 +475,7 @@ def run_test(self): self.sync_all() # make sure funds are received at node1 - assert_equal(oldBalance+Decimal('1.10000000'), self.nodes[1].getbalance()) + assert_equal(oldBalance+Decimal('1.10000000'), self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET)) ############################################################ # locked wallet test @@ -513,7 +514,7 @@ def run_test(self): assert_raises_rpc_error(-13, "walletpassphrase", self.nodes[1].sendtoaddress, self.nodes[0].getnewaddress(), 1.2) - oldBalance = self.nodes[0].getbalance() + oldBalance = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET) inputs = [] outputs = {self.nodes[0].getnewaddress():1.1} @@ -528,7 +529,7 @@ def run_test(self): self.sync_all() # make sure funds are received at node1 - assert_equal(oldBalance+Decimal('51.10000000'), self.nodes[0].getbalance()) + assert_equal(oldBalance+Decimal('51.10000000'), self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET)) ############################################### @@ -536,7 +537,7 @@ def run_test(self): ############################################### #empty node1, send some small coins from node0 to node1 - self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), self.nodes[1].getbalance(), "", "", True) + self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET), "", "", True) self.sync_all() self.nodes[0].generate(1) self.sync_all() @@ -566,7 +567,7 @@ def run_test(self): ############################################# #again, empty node1, send some small coins from node0 to node1 - self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), self.nodes[1].getbalance(), "", "", True) + self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET), "", "", True) self.sync_all() self.nodes[0].generate(1) self.sync_all() @@ -577,7 +578,7 @@ def run_test(self): self.sync_all() #fund a tx with ~20 small inputs - oldBalance = self.nodes[0].getbalance() + oldBalance = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET) inputs = [] outputs = {self.nodes[0].getnewaddress():0.15,self.nodes[0].getnewaddress():0.04} @@ -588,7 +589,7 @@ def run_test(self): self.sync_all() self.nodes[0].generate(1) self.sync_all() - assert_equal(oldBalance+Decimal('50.19000000'), self.nodes[0].getbalance()) #0.19+block reward + assert_equal(oldBalance+Decimal('50.19000000'), self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET)) #0.19+block reward ##################################################### # test fundrawtransaction with OP_RETURN and no vin # diff --git a/test/functional/rpc_rawtransaction.py b/test/functional/rpc_rawtransaction.py index 6eeb5b9529..a252898bd2 100755 --- a/test/functional/rpc_rawtransaction.py +++ b/test/functional/rpc_rawtransaction.py @@ -17,7 +17,7 @@ from io import BytesIO from test_framework.messages import CTransaction, ToHex from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str, connect_nodes_bi, hex_str_to_bytes +from test_framework.util import assert_equal, assert_raises_rpc_error, bytes_to_hex_str, connect_nodes_bi, hex_str_to_bytes, BITCOIN_ASSET class multidict(dict): """Dictionary that allows duplicate keys. @@ -253,18 +253,18 @@ def run_test(self): mSigObj = self.nodes[2].addmultisigaddress(2, [addr1Obj['pubkey'], addr1])['address'] #use balance deltas instead of absolute values - bal = self.nodes[2].getbalance() + bal = self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET) # send 1.2 BTC to msig adr txId = self.nodes[0].sendtoaddress(mSigObj, 1.2) self.sync_all() self.nodes[0].generate(1) self.sync_all() - assert_equal(self.nodes[2].getbalance(), bal+Decimal('1.20000000')) #node2 has both keys of the 2of2 ms addr., tx should affect the balance + 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 # 2of3 test from different nodes - bal = self.nodes[2].getbalance() + bal = self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET) addr1 = self.nodes[1].getnewaddress() addr2 = self.nodes[2].getnewaddress() addr3 = self.nodes[2].getnewaddress() @@ -284,7 +284,7 @@ def run_test(self): #THIS IS AN INCOMPLETE FEATURE #NODE2 HAS TWO OF THREE KEY AND THE FUNDS SHOULD BE SPENDABLE AND COUNT AT BALANCE CALCULATION - assert_equal(self.nodes[2].getbalance(), bal) #for now, assume the funds of a 2of3 multisig tx are not marked as spendable + 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 txDetails = self.nodes[0].gettransaction(txId, True) rawTx = self.nodes[0].decoderawtransaction(txDetails['hex']) @@ -294,7 +294,7 @@ def run_test(self): vout = outpoint break - bal = self.nodes[0].getbalance() + bal = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET) inputs = [{ "txid" : txId, "vout" : vout['n'], "scriptPubKey" : vout['scriptPubKey']['hex'], "amount" : vout['value']}] outputs = { self.nodes[0].getnewaddress() : 2.19 } rawTx = self.nodes[2].createrawtransaction(inputs, outputs) @@ -308,10 +308,10 @@ def run_test(self): self.sync_all() self.nodes[0].generate(1) self.sync_all() - assert_equal(self.nodes[0].getbalance(), bal+Decimal('50.00000000')+Decimal('2.19000000')) #block reward + tx + assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), bal+Decimal('50.00000000')+Decimal('2.19000000')) #block reward + tx # 2of2 test for combining transactions - bal = self.nodes[2].getbalance() + bal = self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET) addr1 = self.nodes[1].getnewaddress() addr2 = self.nodes[2].getnewaddress() @@ -329,7 +329,7 @@ def run_test(self): self.nodes[0].generate(1) self.sync_all() - assert_equal(self.nodes[2].getbalance(), bal) # the funds of a 2of2 multisig tx should not be marked as spendable + assert_equal(self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET), bal) # the funds of a 2of2 multisig tx should not be marked as spendable txDetails = self.nodes[0].gettransaction(txId, True) rawTx2 = self.nodes[0].decoderawtransaction(txDetails['hex']) @@ -339,7 +339,7 @@ def run_test(self): vout = outpoint break - bal = self.nodes[0].getbalance() + bal = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET) inputs = [{ "txid" : txId, "vout" : vout['n'], "scriptPubKey" : vout['scriptPubKey']['hex'], "redeemScript" : mSigObjValid['hex'], "amount" : vout['value']}] outputs = { self.nodes[0].getnewaddress() : 2.19 } rawTx2 = self.nodes[2].createrawtransaction(inputs, outputs) @@ -357,7 +357,7 @@ def run_test(self): self.sync_all() self.nodes[0].generate(1) self.sync_all() - assert_equal(self.nodes[0].getbalance(), bal+Decimal('50.00000000')+Decimal('2.19000000')) #block reward + tx + assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), bal+Decimal('50.00000000')+Decimal('2.19000000')) #block reward + tx # decoderawtransaction tests # witness transaction diff --git a/test/functional/rpc_txoutproof.py b/test/functional/rpc_txoutproof.py index 867ba25022..d883e4251e 100755 --- a/test/functional/rpc_txoutproof.py +++ b/test/functional/rpc_txoutproof.py @@ -6,7 +6,7 @@ from test_framework.messages import CMerkleBlock, FromHex, ToHex from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes +from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes, BITCOIN_ASSET class MerkleBlockTest(BitcoinTestFramework): def set_test_params(self): @@ -33,8 +33,8 @@ def run_test(self): chain_height = self.nodes[1].getblockcount() assert_equal(chain_height, 105) - assert_equal(self.nodes[1].getbalance(), 0) - assert_equal(self.nodes[2].getbalance(), 0) + assert_equal(self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET), 0) + assert_equal(self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET), 0) node0utxos = self.nodes[0].listunspent(1) tx1 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 49.99}) diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py index 51be9a943a..2633410cf1 100755 --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -24,7 +24,7 @@ import time from test_framework.siphash import siphash256 -from test_framework.util import hex_str_to_bytes, bytes_to_hex_str, calcfastmerkleroot +from test_framework.util import hex_str_to_bytes, bytes_to_hex_str, calcfastmerkleroot, BITCOIN_ASSET_OUT MIN_VERSION_SUPPORTED = 60001 MY_VERSION = 70014 # past bip-31 for ping/pong @@ -50,10 +50,6 @@ MSG_WITNESS_FLAG = 1 << 30 MSG_TYPE_MASK = 0xffffffff >> 2 -BITCOIN_ASSET = bytearray.fromhex("e08fa5a62d79b9e3f5f476743a5535512f0f44444533275a2adc5fe8476a2eac") -BITCOIN_ASSET.reverse() -BITCOIN_ASSET_OUT = b"\x01"+BITCOIN_ASSET - # Serialization/deserialization tools def sha256(s): return hashlib.new('sha256', s).digest() diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index 743395edda..4a523838e4 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -23,6 +23,11 @@ logger = logging.getLogger("TestFramework.utils") +BITCOIN_ASSET = "e08fa5a62d79b9e3f5f476743a5535512f0f44444533275a2adc5fe8476a2eac" +BITCOIN_ASSET_BYTES = bytearray.fromhex(BITCOIN_ASSET) +BITCOIN_ASSET_BYTES.reverse() +BITCOIN_ASSET_OUT = b"\x01"+BITCOIN_ASSET_BYTES + # This variable should be set to the node being used for CalcFastMerkleRoot calls node_fastmerkle = None diff --git a/test/functional/wallet_abandonconflict.py b/test/functional/wallet_abandonconflict.py index e5ac2c8bd4..fd2e73f6d1 100755 --- a/test/functional/wallet_abandonconflict.py +++ b/test/functional/wallet_abandonconflict.py @@ -13,7 +13,7 @@ from decimal import Decimal from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes, disconnect_nodes, sync_blocks, sync_mempools +from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes, disconnect_nodes, sync_blocks, sync_mempools, BITCOIN_ASSET class AbandonConflictTest(BitcoinTestFramework): def set_test_params(self): @@ -26,7 +26,7 @@ def skip_test_if_missing_module(self): def run_test(self): self.nodes[1].generate(100) sync_blocks(self.nodes) - balance = self.nodes[0].getbalance() + balance = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET) txA = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal("10")) txB = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal("10")) txC = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), Decimal("10")) @@ -39,7 +39,7 @@ def run_test(self): assert_raises_rpc_error(-5, 'Transaction not eligible for abandonment', lambda: self.nodes[0].abandontransaction(txid=txA)) sync_blocks(self.nodes) - newbalance = self.nodes[0].getbalance() + newbalance = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET) assert(balance - newbalance < Decimal("0.001")) #no more than fees lost balance = newbalance @@ -83,7 +83,7 @@ def run_test(self): self.nodes[0].sendrawtransaction(signed3["hex"]) # In mempool txs from self should increase balance from change - newbalance = self.nodes[0].getbalance() + newbalance = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET) assert_equal(newbalance, balance - Decimal("30") + signed3_change) balance = newbalance @@ -98,11 +98,11 @@ def run_test(self): # Not in mempool txs from self should only reduce balance # inputs are still spent, but change not received - newbalance = self.nodes[0].getbalance() + newbalance = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET) assert_equal(newbalance, balance - signed3_change) # Unconfirmed received funds that are not in mempool, also shouldn't show # up in unconfirmed balance - unconfbalance = self.nodes[0].getunconfirmedbalance() + self.nodes[0].getbalance() + unconfbalance = self.nodes[0].getunconfirmedbalance() + self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET) assert_equal(unconfbalance, newbalance) # Also shouldn't show up in listunspent assert(not txABC2 in [utxo["txid"] for utxo in self.nodes[0].listunspent(0)]) @@ -111,7 +111,7 @@ def run_test(self): # Abandon original transaction and verify inputs are available again # including that the child tx was also abandoned self.nodes[0].abandontransaction(txAB1) - newbalance = self.nodes[0].getbalance() + newbalance = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET) assert_equal(newbalance, balance + Decimal("30")) balance = newbalance @@ -119,19 +119,19 @@ def run_test(self): self.stop_node(0) self.start_node(0, extra_args=["-minrelaytxfee=0.00001"]) assert_equal(len(self.nodes[0].getrawmempool()), 0) - assert_equal(self.nodes[0].getbalance(), balance) + assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), balance) # But if it is received again then it is unabandoned # And since now in mempool, the change is available # But its child tx remains abandoned self.nodes[0].sendrawtransaction(signed["hex"]) - newbalance = self.nodes[0].getbalance() + newbalance = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET) assert_equal(newbalance, balance - Decimal("20") + Decimal("14.99998")) balance = newbalance # Send child tx again so it is unabandoned self.nodes[0].sendrawtransaction(signed2["hex"]) - newbalance = self.nodes[0].getbalance() + newbalance = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET) assert_equal(newbalance, balance - Decimal("10") - Decimal("14.99998") + Decimal("24.9996")) balance = newbalance @@ -139,7 +139,7 @@ def run_test(self): self.stop_node(0) self.start_node(0, extra_args=["-minrelaytxfee=0.0001"]) assert_equal(len(self.nodes[0].getrawmempool()), 0) - newbalance = self.nodes[0].getbalance() + newbalance = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET) assert_equal(newbalance, balance - Decimal("24.9996")) balance = newbalance @@ -158,7 +158,7 @@ def run_test(self): sync_blocks(self.nodes) # Verify that B and C's 10 BTC outputs are available for spending again because AB1 is now conflicted - newbalance = self.nodes[0].getbalance() + newbalance = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET) assert_equal(newbalance, balance + Decimal("20")) balance = newbalance @@ -166,7 +166,7 @@ def run_test(self): # Invalidate the block with the double spend and B's 10 BTC output should no longer be available # Don't think C's should either self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash()) - newbalance = self.nodes[0].getbalance() + newbalance = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET) #assert_equal(newbalance, balance - Decimal("10")) self.log.info("If balance has not declined after invalidateblock then out of mempool wallet tx which is no longer") self.log.info("conflicted has not resumed causing its inputs to be seen as spent. See Issue #7315") diff --git a/test/functional/wallet_address_types.py b/test/functional/wallet_address_types.py index 0f75045c9d..602be4c759 100755 --- a/test/functional/wallet_address_types.py +++ b/test/functional/wallet_address_types.py @@ -61,6 +61,7 @@ connect_nodes_bi, sync_blocks, sync_mempools, + BITCOIN_ASSET, ) @@ -91,7 +92,7 @@ def setup_network(self): def get_balances(self, confirmed=True): """Return a list of confirmed or unconfirmed balances.""" if confirmed: - return [self.nodes[i].getbalance() for i in range(4)] + return [self.nodes[i].getbalance('*', 0, False, BITCOIN_ASSET) for i in range(4)] else: return [self.nodes[i].getunconfirmedbalance() for i in range(4)] @@ -262,7 +263,7 @@ def run_test(self): self.nodes[5].sendtoaddress(self.nodes[4].getnewaddress(), Decimal("1")) self.nodes[5].generate(1) sync_blocks(self.nodes) - assert_equal(self.nodes[4].getbalance(), 1) + assert_equal(self.nodes[4].getbalance('*', 0, False, BITCOIN_ASSET), 1) self.log.info("Nodes with addresstype=legacy never use a P2WPKH change output") self.test_change_output_type(0, [to_address_bech32_1], 'legacy') diff --git a/test/functional/wallet_backup.py b/test/functional/wallet_backup.py index c4798e1c87..724c5a87d1 100755 --- a/test/functional/wallet_backup.py +++ b/test/functional/wallet_backup.py @@ -36,7 +36,7 @@ import shutil from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes, sync_blocks, sync_mempools +from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes, sync_blocks, sync_mempools, BITCOIN_ASSET class WalletBackupTest(BitcoinTestFramework): def set_test_params(self): @@ -110,10 +110,10 @@ def run_test(self): self.nodes[3].generate(100) sync_blocks(self.nodes) - assert_equal(self.nodes[0].getbalance(), 50) - assert_equal(self.nodes[1].getbalance(), 50) - assert_equal(self.nodes[2].getbalance(), 50) - assert_equal(self.nodes[3].getbalance(), 0) + assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), 50) + assert_equal(self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET), 50) + assert_equal(self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET), 50) + assert_equal(self.nodes[3].getbalance('*', 0, False, BITCOIN_ASSET), 0) self.log.info("Creating transactions") # Five rounds of sending each other transactions. @@ -137,10 +137,10 @@ def run_test(self): self.nodes[3].generate(101) self.sync_all() - balance0 = self.nodes[0].getbalance() - balance1 = self.nodes[1].getbalance() - balance2 = self.nodes[2].getbalance() - balance3 = self.nodes[3].getbalance() + balance0 = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET) + balance1 = self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET) + balance2 = self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET) + balance3 = self.nodes[3].getbalance('*', 0, False, BITCOIN_ASSET) total = balance0 + balance1 + balance2 + balance3 # At this point, there are 214 blocks (103 for setup, then 10 rounds, then 101.) @@ -167,9 +167,9 @@ def run_test(self): self.start_three() sync_blocks(self.nodes) - assert_equal(self.nodes[0].getbalance(), balance0) - assert_equal(self.nodes[1].getbalance(), balance1) - assert_equal(self.nodes[2].getbalance(), balance2) + assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), balance0) + assert_equal(self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET), balance1) + assert_equal(self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET), balance2) self.log.info("Restoring using dumped wallet") self.stop_three() @@ -181,9 +181,9 @@ def run_test(self): self.start_three() - assert_equal(self.nodes[0].getbalance(), 0) - assert_equal(self.nodes[1].getbalance(), 0) - assert_equal(self.nodes[2].getbalance(), 0) + assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), 0) + assert_equal(self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET), 0) + assert_equal(self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET), 0) self.nodes[0].importwallet(os.path.join(self.nodes[0].datadir, 'wallet.dump')) self.nodes[1].importwallet(os.path.join(self.nodes[1].datadir, 'wallet.dump')) @@ -191,9 +191,9 @@ def run_test(self): sync_blocks(self.nodes) - assert_equal(self.nodes[0].getbalance(), balance0) - assert_equal(self.nodes[1].getbalance(), balance1) - assert_equal(self.nodes[2].getbalance(), balance2) + assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), balance0) + assert_equal(self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET), balance1) + assert_equal(self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET), balance2) # Backup to source wallet file must fail sourcePaths = [ diff --git a/test/functional/wallet_basic.py b/test/functional/wallet_basic.py index 4079d05491..ed16819f0d 100755 --- a/test/functional/wallet_basic.py +++ b/test/functional/wallet_basic.py @@ -16,6 +16,7 @@ sync_blocks, sync_mempools, wait_until, + BITCOIN_ASSET, ) class WalletTest(BitcoinTestFramework): @@ -63,9 +64,9 @@ def run_test(self): self.nodes[1].generate(101) self.sync_all([self.nodes[0:3]]) - assert_equal(self.nodes[0].getbalance(), 50) - assert_equal(self.nodes[1].getbalance(), 50) - assert_equal(self.nodes[2].getbalance(), 0) + assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), 50) + assert_equal(self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET), 50) + assert_equal(self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET), 0) # Check getbalance with different arguments assert_equal(self.nodes[0].getbalance("*"), 50) @@ -115,7 +116,7 @@ def run_test(self): txout2 = self.nodes[0].gettxout(mempool_txid, 1, True) # note the mempool tx will have randomly assigned indices # but 10 will go to node2 and the rest will go to node0 - balance = self.nodes[0].getbalance() + balance = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET) assert_equal(set([txout1['value'], txout2['value']]), set([10, balance])) walletinfo = self.nodes[0].getwalletinfo() assert_equal(walletinfo['immature_balance'], 0) @@ -156,8 +157,8 @@ def run_test(self): # node0 should end up with 100 btc in block rewards plus fees, but # minus the 21 plus fees sent to node2 - assert_equal(self.nodes[0].getbalance(), 100 - 21) - assert_equal(self.nodes[2].getbalance(), 21) + assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), 100 - 21) + assert_equal(self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET), 21) # Node0 should have two unspent outputs. # Create a couple of transactions to send them to node2, submit them through @@ -183,8 +184,8 @@ def run_test(self): self.nodes[1].generate(1) self.sync_all([self.nodes[0:3]]) - assert_equal(self.nodes[0].getbalance(), 0) - assert_equal(self.nodes[2].getbalance(), 94) + assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), 0) + assert_equal(self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET), 94) # Verify that a spent output cannot be locked anymore spent_0 = {"txid": node0utxos[0]["txid"], "vout": node0utxos[0]["vout"]} @@ -197,32 +198,32 @@ def run_test(self): txid = self.nodes[2].sendtoaddress(address, 10, "", "", False) self.nodes[2].generate(1) self.sync_all([self.nodes[0:3]]) - node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), Decimal('84'), fee_per_byte, self.get_vsize(self.nodes[2].getrawtransaction(txid))) - assert_equal(self.nodes[0].getbalance(), Decimal('10')) + node_2_bal = self.check_fee_amount(self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET), Decimal('84'), fee_per_byte, self.get_vsize(self.nodes[2].getrawtransaction(txid))) + assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), Decimal('10')) # Send 10 BTC with subtract fee from amount txid = self.nodes[2].sendtoaddress(address, 10, "", "", True) self.nodes[2].generate(1) self.sync_all([self.nodes[0:3]]) node_2_bal -= Decimal('10') - assert_equal(self.nodes[2].getbalance(), node_2_bal) - node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), Decimal('20'), fee_per_byte, self.get_vsize(self.nodes[2].getrawtransaction(txid))) + assert_equal(self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET), node_2_bal) + node_0_bal = self.check_fee_amount(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), Decimal('20'), fee_per_byte, self.get_vsize(self.nodes[2].getrawtransaction(txid))) # Sendmany 10 BTC txid = self.nodes[2].sendmany('', {address: 10}, 0, "", []) self.nodes[2].generate(1) self.sync_all([self.nodes[0:3]]) node_0_bal += Decimal('10') - node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), node_2_bal - Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].getrawtransaction(txid))) - assert_equal(self.nodes[0].getbalance(), node_0_bal) + node_2_bal = self.check_fee_amount(self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET), node_2_bal - Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].getrawtransaction(txid))) + assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), node_0_bal) # Sendmany 10 BTC with subtract fee from amount txid = self.nodes[2].sendmany('', {address: 10}, 0, "", [address]) self.nodes[2].generate(1) self.sync_all([self.nodes[0:3]]) node_2_bal -= Decimal('10') - assert_equal(self.nodes[2].getbalance(), node_2_bal) - node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), node_0_bal + Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].getrawtransaction(txid))) + assert_equal(self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET), node_2_bal) + node_0_bal = self.check_fee_amount(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), node_0_bal + Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].getrawtransaction(txid))) # Test ResendWalletTransactions: # Create a couple of transactions, then start up a fourth @@ -287,7 +288,7 @@ def run_test(self): tx_obj_not_broadcast = self.nodes[0].gettransaction(txid_not_broadcast) self.nodes[1].generate(1) # mine a block, tx should not be in there self.sync_all([self.nodes[0:3]]) - assert_equal(self.nodes[2].getbalance(), node_2_bal) # should not be changed because tx was not broadcasted + assert_equal(self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET), node_2_bal) # should not be changed because tx was not broadcasted # now broadcast from another node, mine a block, sync, and check the balance self.nodes[1].sendrawtransaction(tx_obj_not_broadcast['hex']) @@ -295,7 +296,7 @@ def run_test(self): self.sync_all([self.nodes[0:3]]) node_2_bal += 2 tx_obj_not_broadcast = self.nodes[0].gettransaction(txid_not_broadcast) - assert_equal(self.nodes[2].getbalance(), node_2_bal) + assert_equal(self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET), node_2_bal) # create another tx self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 2) @@ -315,7 +316,7 @@ def run_test(self): node_2_bal += 2 # tx should be added to balance because after restarting the nodes tx should be broadcast - assert_equal(self.nodes[2].getbalance(), node_2_bal) + assert_equal(self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET), node_2_bal) # send a tx with value in a string (PR#6380 +) txid = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "2") @@ -377,7 +378,7 @@ def run_test(self): self.sync_all([self.nodes[0:3]]) blocks = self.nodes[0].generate(2) self.sync_all([self.nodes[0:3]]) - balance_nodes = [self.nodes[i].getbalance() for i in range(3)] + balance_nodes = [self.nodes[i].getbalance('*', 0, False, BITCOIN_ASSET) for i in range(3)] block_count = self.nodes[0].getblockcount() # Check modes: @@ -413,7 +414,7 @@ def run_test(self): if m == '-reindex': # reindex will leave rpc warm up "early"; Wait for it to finish wait_until(lambda: [block_count] * 3 == [self.nodes[i].getblockcount() for i in range(3)]) - assert_equal(balance_nodes, [self.nodes[i].getbalance() for i in range(3)]) + assert_equal(balance_nodes, [self.nodes[i].getbalance('*', 0, False, BITCOIN_ASSET) for i in range(3)]) # Exercise listsinceblock with the last two blocks coinbase_tx_1 = self.nodes[0].listsinceblock(blocks[0]) @@ -426,9 +427,9 @@ def run_test(self): # Get all non-zero utxos together chain_addrs = [self.nodes[0].getnewaddress(), self.nodes[0].getnewaddress()] - singletxid = self.nodes[0].sendtoaddress(chain_addrs[0], self.nodes[0].getbalance(), "", "", True) + singletxid = self.nodes[0].sendtoaddress(chain_addrs[0], self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), "", "", True) self.nodes[0].generate(1) - node0_balance = self.nodes[0].getbalance() + node0_balance = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET) # Split into two chains rawtx = self.nodes[0].createrawtransaction([{"txid": singletxid, "vout": 0}], {chain_addrs[0]: node0_balance / 2 - Decimal('0.01'), chain_addrs[1]: node0_balance / 2 - Decimal('0.01')}) signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx) @@ -466,7 +467,7 @@ def run_test(self): timeout -= 0.5 assert_equal(len(self.nodes[0].getrawmempool()), chainlimit * 2) - node0_balance = self.nodes[0].getbalance() + node0_balance = self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET) # With walletrejectlongchains we will not create the tx and store it in our wallet. assert_raises_rpc_error(-4, "Transaction has too long of a mempool chain", self.nodes[0].sendtoaddress, sending_addr, node0_balance - Decimal('0.01')) diff --git a/test/functional/wallet_bumpfee.py b/test/functional/wallet_bumpfee.py index 00bfd84768..75d1b2edbb 100755 --- a/test/functional/wallet_bumpfee.py +++ b/test/functional/wallet_bumpfee.py @@ -19,7 +19,7 @@ from test_framework.blocktools import add_witness_commitment, create_block, create_coinbase, send_to_witness from test_framework.messages import BIP125_SEQUENCE_NUMBER, CTransaction from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, assert_greater_than, assert_raises_rpc_error, bytes_to_hex_str, connect_nodes_bi, hex_str_to_bytes, sync_mempools +from test_framework.util import assert_equal, assert_greater_than, assert_raises_rpc_error, bytes_to_hex_str, connect_nodes_bi, hex_str_to_bytes, sync_mempools, BITCOIN_ASSET from test_framework import util import io @@ -62,7 +62,7 @@ def run_test(self): self.sync_all() peer_node.generate(1) self.sync_all() - assert_equal(rbf_node.getbalance(), Decimal("0.025")) + assert_equal(rbf_node.getbalance('*', 0, False, BITCOIN_ASSET), Decimal("0.025")) self.log.info("Running tests") dest_address = peer_node.getnewaddress() diff --git a/test/functional/wallet_groups.py b/test/functional/wallet_groups.py index 9d61483868..2e07097252 100755 --- a/test/functional/wallet_groups.py +++ b/test/functional/wallet_groups.py @@ -8,6 +8,7 @@ from test_framework.messages import CTransaction, FromHex, ToHex from test_framework.util import ( assert_equal, + BITCOIN_ASSET, ) def assert_approx(v, vexp, vspan=0.00001): @@ -69,7 +70,7 @@ def run_test(self): assert_approx(v[1], 1.3, 0.0001) # Empty out node2's wallet - self.nodes[2].sendtoaddress(address=self.nodes[0].getnewaddress(), amount=self.nodes[2].getbalance(), subtractfeefromamount=True) + self.nodes[2].sendtoaddress(address=self.nodes[0].getnewaddress(), amount=self.nodes[2].getbalance('*', 0, False, BITCOIN_ASSET), subtractfeefromamount=True) self.sync_all() self.nodes[0].generate(1) diff --git a/test/functional/wallet_hd.py b/test/functional/wallet_hd.py index ecc09dbfd1..a32498fc3a 100755 --- a/test/functional/wallet_hd.py +++ b/test/functional/wallet_hd.py @@ -11,7 +11,8 @@ from test_framework.util import ( assert_equal, connect_nodes_bi, - assert_raises_rpc_error + assert_raises_rpc_error, + BITCOIN_ASSET, ) @@ -71,7 +72,7 @@ def run_test(self): assert_equal(change_addrV["hdkeypath"], "m/0'/1'/1'") #second internal child key self.sync_all() - assert_equal(self.nodes[1].getbalance(), NUM_HD_ADDS + 1) + assert_equal(self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET), NUM_HD_ADDS + 1) self.log.info("Restore backup ...") self.stop_node(1) @@ -97,7 +98,7 @@ def run_test(self): # Needs rescan self.stop_node(1) self.start_node(1, extra_args=self.extra_args[1] + ['-rescan']) - assert_equal(self.nodes[1].getbalance(), NUM_HD_ADDS + 1) + assert_equal(self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET), NUM_HD_ADDS + 1) # Try a RPC based rescan self.stop_node(1) @@ -108,14 +109,14 @@ def run_test(self): connect_nodes_bi(self.nodes, 0, 1) self.sync_all() # Wallet automatically scans blocks older than key on startup - assert_equal(self.nodes[1].getbalance(), NUM_HD_ADDS + 1) + assert_equal(self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET), NUM_HD_ADDS + 1) out = self.nodes[1].rescanblockchain(0, 1) assert_equal(out['start_height'], 0) assert_equal(out['stop_height'], 1) out = self.nodes[1].rescanblockchain() assert_equal(out['start_height'], 0) assert_equal(out['stop_height'], self.nodes[1].getblockcount()) - assert_equal(self.nodes[1].getbalance(), NUM_HD_ADDS + 1) + assert_equal(self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET), NUM_HD_ADDS + 1) # send a tx and make sure its using the internal chain for the changeoutput txid = self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 1) diff --git a/test/functional/wallet_importprunedfunds.py b/test/functional/wallet_importprunedfunds.py index 26b181db33..54a72e5b01 100755 --- a/test/functional/wallet_importprunedfunds.py +++ b/test/functional/wallet_importprunedfunds.py @@ -9,6 +9,7 @@ from test_framework.util import ( assert_equal, assert_raises_rpc_error, + BITCOIN_ASSET, ) class ImportPrunedFundsTest(BitcoinTestFramework): @@ -76,7 +77,7 @@ def run_test(self): # Import with no affiliated address assert_raises_rpc_error(-5, "No addresses", self.nodes[1].importprunedfunds, rawtxn1, proof1) - balance1 = self.nodes[1].getbalance() + balance1 = self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET) assert_equal(balance1, Decimal(0)) # Import with affiliated address with no rescan @@ -88,7 +89,7 @@ def run_test(self): self.nodes[1].importprivkey(privkey=address3_privkey, rescan=False) self.nodes[1].importprunedfunds(rawtxn3, proof3) assert [tx for tx in self.nodes[1].listtransactions() if tx['txid'] == txnid3] - balance3 = self.nodes[1].getbalance() + balance3 = self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET) assert_equal(balance3, Decimal('0.025')) # Addresses Test - after import diff --git a/test/functional/wallet_keypool_topup.py b/test/functional/wallet_keypool_topup.py index 561b69b5fb..8555c45eff 100755 --- a/test/functional/wallet_keypool_topup.py +++ b/test/functional/wallet_keypool_topup.py @@ -18,6 +18,7 @@ assert_equal, connect_nodes_bi, sync_blocks, + BITCOIN_ASSET, ) @@ -62,7 +63,7 @@ def run_test(self): self.sync_all() self.log.info("Verify keypool is restored and balance is correct") - assert_equal(self.nodes[1].getbalance(), 15) + assert_equal(self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET), 15) assert_equal(self.nodes[1].listtransactions()[0]['category'], "receive") # Check that we have marked all keys up to the used keypool key as used assert_equal(self.nodes[1].getaddressinfo(self.nodes[1].getnewaddress())['hdkeypath'], "m/0'/0'/110'") diff --git a/test/functional/wallet_labels.py b/test/functional/wallet_labels.py index 8d7c77bb96..a3877baabb 100755 --- a/test/functional/wallet_labels.py +++ b/test/functional/wallet_labels.py @@ -12,7 +12,7 @@ from collections import defaultdict from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, assert_raises_rpc_error +from test_framework.util import assert_equal, assert_raises_rpc_error, BITCOIN_ASSET class WalletLabelsTest(BitcoinTestFramework): def set_test_params(self): @@ -31,7 +31,7 @@ def run_test(self): # the same address, so we call twice to get two addresses w/50 each node.generate(1) node.generate(101) - assert_equal(node.getbalance(), 100) + assert_equal(node.getbalance('*', 0, False, BITCOIN_ASSET), 100) # there should be 2 address groups # each with 1 address with a balance of 50 Bitcoins diff --git a/test/functional/wallet_multiwallet.py b/test/functional/wallet_multiwallet.py index dc0a935f85..f633829494 100755 --- a/test/functional/wallet_multiwallet.py +++ b/test/functional/wallet_multiwallet.py @@ -14,6 +14,7 @@ from test_framework.util import ( assert_equal, assert_raises_rpc_error, + BITCOIN_ASSET, ) @@ -157,18 +158,18 @@ def wallet_file(name): w1, w2, w3, w4, *_ = wallets w1.generate(101) - assert_equal(w1.getbalance(), 100) - assert_equal(w2.getbalance(), 0) - assert_equal(w3.getbalance(), 0) - assert_equal(w4.getbalance(), 0) + assert_equal(w1.getbalance('*', 0, False, BITCOIN_ASSET), 100) + assert_equal(w2.getbalance('*', 0, False, BITCOIN_ASSET), 0) + assert_equal(w3.getbalance('*', 0, False, BITCOIN_ASSET), 0) + assert_equal(w4.getbalance('*', 0, False, BITCOIN_ASSET), 0) w1.sendtoaddress(w2.getnewaddress(), 1) w1.sendtoaddress(w3.getnewaddress(), 2) w1.sendtoaddress(w4.getnewaddress(), 3) w1.generate(1) - assert_equal(w2.getbalance(), 1) - assert_equal(w3.getbalance(), 2) - assert_equal(w4.getbalance(), 3) + assert_equal(w2.getbalance('*', 0, False, BITCOIN_ASSET), 1) + assert_equal(w3.getbalance('*', 0, False, BITCOIN_ASSET), 2) + assert_equal(w4.getbalance('*', 0, False, BITCOIN_ASSET), 3) batch = w1.batch([w1.getblockchaininfo.get_request(), w1.getwalletinfo.get_request()]) assert_equal(batch[0]["result"]["chain"], self.chain) diff --git a/test/functional/wallet_txn_clone.py b/test/functional/wallet_txn_clone.py index 583dc48f66..f600a02469 100755 --- a/test/functional/wallet_txn_clone.py +++ b/test/functional/wallet_txn_clone.py @@ -12,6 +12,7 @@ connect_nodes, disconnect_nodes, sync_blocks, + BITCOIN_ASSET, ) class TxnMallTest(BitcoinTestFramework): @@ -42,7 +43,7 @@ def run_test(self): # All nodes should start with 1,250 BTC: starting_balance = 1250 for i in range(4): - assert_equal(self.nodes[i].getbalance(), starting_balance) + assert_equal(self.nodes[i].getbalance('*', 0, False, BITCOIN_ASSET), starting_balance) self.nodes[i].getnewaddress() # bug workaround, coins generated assigned to first getnewaddress! self.nodes[0].settxfee(.001) @@ -55,7 +56,7 @@ def run_test(self): node0_txid2 = self.nodes[0].sendtoaddress(node0_address2, 29) node0_tx2 = self.nodes[0].gettransaction(node0_txid2) - assert_equal(self.nodes[0].getbalance(), + assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), starting_balance + node0_tx1["fee"] + node0_tx2["fee"]) # Coins are sent to node1_address @@ -99,7 +100,7 @@ def run_test(self): expected += 50 expected += tx1["amount"] + tx1["fee"] expected += tx2["amount"] + tx2["fee"] - assert_equal(self.nodes[0].getbalance(), expected) + assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), expected) if self.options.mine_block: assert_equal(tx1["confirmations"], 1) @@ -140,7 +141,7 @@ def run_test(self): expected += 100 if (self.options.mine_block): expected -= 50 - assert_equal(self.nodes[0].getbalance(), expected) + assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), expected) if __name__ == '__main__': TxnMallTest().main() diff --git a/test/functional/wallet_txn_doublespend.py b/test/functional/wallet_txn_doublespend.py index f114d5ab68..8ccecb8185 100755 --- a/test/functional/wallet_txn_doublespend.py +++ b/test/functional/wallet_txn_doublespend.py @@ -12,6 +12,7 @@ disconnect_nodes, find_output, sync_blocks, + BITCOIN_ASSET, ) class TxnMallTest(BitcoinTestFramework): @@ -35,7 +36,7 @@ def run_test(self): # All nodes should start with 1,250 BTC: starting_balance = 1250 for i in range(4): - assert_equal(self.nodes[i].getbalance(), starting_balance) + assert_equal(self.nodes[i].getbalance('*', 0, False, BITCOIN_ASSET), starting_balance) self.nodes[i].getnewaddress("") # bug workaround, coins generated assigned to first getnewaddress! # Assign coins to foo and bar addresses: @@ -47,7 +48,7 @@ def run_test(self): fund_bar_txid = self.nodes[0].sendtoaddress(node0_address_bar, 29) fund_bar_tx = self.nodes[0].gettransaction(fund_bar_txid) - assert_equal(self.nodes[0].getbalance(), + assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), starting_balance + fund_foo_tx["fee"] + fund_bar_tx["fee"]) # Coins are sent to node1_address @@ -90,13 +91,13 @@ def run_test(self): expected += 50 expected += tx1["amount"] + tx1["fee"] expected += tx2["amount"] + tx2["fee"] - assert_equal(self.nodes[0].getbalance(), expected) + assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), expected) if self.options.mine_block: assert_equal(tx1["confirmations"], 1) assert_equal(tx2["confirmations"], 1) # Node1's balance should be both transaction amounts: - assert_equal(self.nodes[1].getbalance(), starting_balance - tx1["amount"] - tx2["amount"]) + assert_equal(self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET), starting_balance - tx1["amount"] - tx2["amount"]) else: assert_equal(tx1["confirmations"], 0) assert_equal(tx2["confirmations"], 0) @@ -126,10 +127,10 @@ def run_test(self): # two more matured blocks, minus 1240 for the double-spend, plus fees (which are # negative): expected = starting_balance + 100 - 1240 + fund_foo_tx["fee"] + fund_bar_tx["fee"] + doublespend_fee - assert_equal(self.nodes[0].getbalance(), expected) + assert_equal(self.nodes[0].getbalance('*', 0, False, BITCOIN_ASSET), expected) # Node1's balance should be its initial balance (1250 for 25 block rewards) plus the doublespend: - assert_equal(self.nodes[1].getbalance(), 1250 + 1240) + assert_equal(self.nodes[1].getbalance('*', 0, False, BITCOIN_ASSET), 1250 + 1240) if __name__ == '__main__': TxnMallTest().main()