Skip to content

Commit

Permalink
[BROKEN] Account for assets in all balance inspection in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenroose committed Mar 20, 2019
1 parent 43f8b45 commit b48aea8
Show file tree
Hide file tree
Showing 26 changed files with 165 additions and 148 deletions.
4 changes: 2 additions & 2 deletions test/functional/feature_blocksign.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -96,7 +96,7 @@ def mine_block(self, make_transactions):
# Make a few transactions to make non-empty blocks for compact transmission
if make_transactions:
for i in range(5):
miner.sendtoaddress(miner_next.getnewaddress(), int(miner.getbalance()/10), "", "", True)
miner.sendtoaddress(miner_next.getnewaddress(), int(miner.getbalance()['bitcoin']/10), "", "", True)
# miner makes a block
block = miner.getnewblockhex()

Expand Down
4 changes: 2 additions & 2 deletions test/functional/feature_pak.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()['bitcoin'], "", "", True)


# Wait for node("follow the leader" conf-undefined) to get transaction in
Expand Down
4 changes: 2 additions & 2 deletions test/functional/feature_rbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()['bitcoin'] < satoshi_round((amount + fee)/COIN):
node.generate(100)

new_addr = node.getnewaddress()
Expand Down
10 changes: 5 additions & 5 deletions test/functional/feature_segwit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()['bitcoin']
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
Expand Down Expand Up @@ -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()['bitcoin'], balance_presetup - 60*50 + 20*Decimal("49.999") + 50)
assert_equal(self.nodes[1].getbalance()['bitcoin'], 20*Decimal("49.999"))
assert_equal(self.nodes[2].getbalance()['bitcoin'], 20*Decimal("49.999"))

self.nodes[0].generate(260) #block 423
sync_blocks(self.nodes)
Expand Down
5 changes: 3 additions & 2 deletions test/functional/interface_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
assert_greater_than,
assert_greater_than_or_equal,
hex_str_to_bytes,
BITCOIN_ASSET,
)

class ReqType(Enum):
Expand Down Expand Up @@ -84,15 +85,15 @@ 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()['bitcoin'], 50)

txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1)
self.sync_all()
self.nodes[1].generatetoaddress(1, not_related_address)
self.sync_all()
bb_hash = self.nodes[0].getbestblockhash()

assert_equal(self.nodes[1].getbalance(), Decimal("0.1"))
assert_equal(self.nodes[1].getbalance()['bitcoin'], Decimal("0.1"))

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

Expand Down
6 changes: 3 additions & 3 deletions test/functional/mempool_persist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()['bitcoin']
self.sync_all()

self.log.debug("Verify that node0 and node1 have 5 transactions in their mempools")
Expand All @@ -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()['bitcoin'])

self.log.debug("Stop-start node0 with -persistmempool=0. Verify that it doesn't load its mempool.dat file.")
self.stop_nodes()
Expand Down
4 changes: 2 additions & 2 deletions test/functional/p2p_compactblocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()['bitcoin']
node.sendtoaddress(address, satoshi_round(value_to_send-Decimal(0.1)))
node.generate(1)

Expand Down
7 changes: 4 additions & 3 deletions test/functional/rpc_createmultisig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()['bitcoin']
bal1 = node1.getbalance()['bitcoin']
bal2 = node2.getbalance()['bitcoin']

height = node0.getblockchaininfo()["blocks"]
assert 150 < height < 350
Expand Down
17 changes: 9 additions & 8 deletions test/functional/rpc_fundrawtransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
connect_nodes_bi,
count_bytes,
find_vout_for_address,
BITCOIN_ASSET,
)


Expand Down Expand Up @@ -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()['bitcoin']
inputs = []
outputs = {self.nodes[1].getnewaddress():1.1}
rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
Expand All @@ -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()['bitcoin'])

############################################################
# locked wallet test
Expand Down Expand Up @@ -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()['bitcoin']

inputs = []
outputs = {self.nodes[0].getnewaddress():1.1}
Expand All @@ -528,15 +529,15 @@ 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()['bitcoin'])


###############################################
# multiple (~19) inputs tx test | Compare fee #
###############################################

#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()['bitcoin'], "", "", True)
self.sync_all()
self.nodes[0].generate(1)
self.sync_all()
Expand Down Expand Up @@ -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()['bitcoin'], "", "", True)
self.sync_all()
self.nodes[0].generate(1)
self.sync_all()
Expand 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()['bitcoin']

inputs = []
outputs = {self.nodes[0].getnewaddress():0.15,self.nodes[0].getnewaddress():0.04}
Expand All @@ -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()['bitcoin']) #0.19+block reward

#####################################################
# test fundrawtransaction with OP_RETURN and no vin #
Expand Down
22 changes: 11 additions & 11 deletions test/functional/rpc_rawtransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()['bitcoin']

# 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()['bitcoin'], 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()['bitcoin']
addr1 = self.nodes[1].getnewaddress()
addr2 = self.nodes[2].getnewaddress()
addr3 = self.nodes[2].getnewaddress()
Expand All @@ -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()['bitcoin'], 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'])
Expand All @@ -294,7 +294,7 @@ def run_test(self):
vout = outpoint
break

bal = self.nodes[0].getbalance()
bal = self.nodes[0].getbalance()['bitcoin']
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)
Expand All @@ -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()['bitcoin'], 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()['bitcoin']
addr1 = self.nodes[1].getnewaddress()
addr2 = self.nodes[2].getnewaddress()

Expand All @@ -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()['bitcoin'], 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'])
Expand All @@ -339,7 +339,7 @@ def run_test(self):
vout = outpoint
break

bal = self.nodes[0].getbalance()
bal = self.nodes[0].getbalance()['bitcoin']
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)
Expand All @@ -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()['bitcoin'], bal+Decimal('50.00000000')+Decimal('2.19000000')) #block reward + tx

# decoderawtransaction tests
# witness transaction
Expand Down
6 changes: 3 additions & 3 deletions test/functional/rpc_txoutproof.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()['bitcoin'], 0)
assert_equal(self.nodes[2].getbalance()['bitcoin'], 0)

node0utxos = self.nodes[0].listunspent(1)
tx1 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 49.99})
Expand Down
2 changes: 1 addition & 1 deletion test/functional/test_framework/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/functional/test_framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading

0 comments on commit b48aea8

Please sign in to comment.