mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-15 12:51:00 +02:00
[BROKEN] Account for assets in all balance inspection in tests
This commit is contained in:
parent
43f8b459dc
commit
b48aea8284
26 changed files with 165 additions and 148 deletions
|
|
@ -5,7 +5,7 @@ import hashlib
|
|||
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,
|
||||
|
|
@ -96,7 +96,7 @@ class BlockSignTest(BitcoinTestFramework):
|
|||
# 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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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 @@ class PAKTest (BitcoinTestFramework):
|
|||
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
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from decimal import Decimal
|
|||
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()['bitcoin'] < satoshi_round((amount + fee)/COIN):
|
||||
node.generate(100)
|
||||
|
||||
new_addr = node.getnewaddress()
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ from test_framework.blocktools import witness_script, send_to_witness
|
|||
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 @@ class SegWitTest(BitcoinTestFramework):
|
|||
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
|
||||
|
|
@ -143,9 +143,9 @@ class SegWitTest(BitcoinTestFramework):
|
|||
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)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ from test_framework.util import (
|
|||
assert_greater_than,
|
||||
assert_greater_than_or_equal,
|
||||
hex_str_to_bytes,
|
||||
BITCOIN_ASSET,
|
||||
)
|
||||
|
||||
class ReqType(Enum):
|
||||
|
|
@ -84,7 +85,7 @@ class RESTTest (BitcoinTestFramework):
|
|||
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()
|
||||
|
|
@ -92,7 +93,7 @@ class RESTTest (BitcoinTestFramework):
|
|||
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")
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ import os
|
|||
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 @@ class MempoolPersistTest(BitcoinTestFramework):
|
|||
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")
|
||||
|
|
@ -83,7 +83,7 @@ class MempoolPersistTest(BitcoinTestFramework):
|
|||
|
||||
# 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()
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ from test_framework.messages import BlockTransactions, BlockTransactionsRequest,
|
|||
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 @@ class CompactBlocksTest(BitcoinTestFramework):
|
|||
# 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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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 @@ class RpcCreateMultiSigTest(BitcoinTestFramework):
|
|||
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
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ from test_framework.util import (
|
|||
connect_nodes_bi,
|
||||
count_bytes,
|
||||
find_vout_for_address,
|
||||
BITCOIN_ASSET,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -461,7 +462,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
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)
|
||||
|
|
@ -474,7 +475,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
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
|
||||
|
|
@ -513,7 +514,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
|
||||
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}
|
||||
|
|
@ -528,7 +529,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
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'])
|
||||
|
||||
|
||||
###############################################
|
||||
|
|
@ -536,7 +537,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
###############################################
|
||||
|
||||
#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()
|
||||
|
|
@ -566,7 +567,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
#############################################
|
||||
|
||||
#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()
|
||||
|
|
@ -577,7 +578,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
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}
|
||||
|
|
@ -588,7 +589,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
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 #
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ from decimal import Decimal
|
|||
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 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
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()
|
||||
|
|
@ -284,7 +284,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
|
||||
#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'])
|
||||
|
|
@ -294,7 +294,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
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)
|
||||
|
|
@ -308,10 +308,10 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
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()
|
||||
|
||||
|
|
@ -329,7 +329,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
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'])
|
||||
|
|
@ -339,7 +339,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
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)
|
||||
|
|
@ -357,7 +357,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
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
|
||||
|
|
|
|||
|
|
@ -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 @@ class MerkleBlockTest(BitcoinTestFramework):
|
|||
|
||||
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})
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import struct
|
|||
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
|
||||
|
|
|
|||
|
|
@ -23,6 +23,11 @@ from io import BytesIO
|
|||
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -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 @@ class AbandonConflictTest(BitcoinTestFramework):
|
|||
def run_test(self):
|
||||
self.nodes[1].generate(100)
|
||||
sync_blocks(self.nodes)
|
||||
balance = self.nodes[0].getbalance()
|
||||
balance = self.nodes[0].getbalance()['bitcoin']
|
||||
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 @@ class AbandonConflictTest(BitcoinTestFramework):
|
|||
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()['bitcoin']
|
||||
assert(balance - newbalance < Decimal("0.001")) #no more than fees lost
|
||||
balance = newbalance
|
||||
|
||||
|
|
@ -83,7 +83,7 @@ class AbandonConflictTest(BitcoinTestFramework):
|
|||
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()['bitcoin']
|
||||
assert_equal(newbalance, balance - Decimal("30") + signed3_change)
|
||||
balance = newbalance
|
||||
|
||||
|
|
@ -98,11 +98,11 @@ class AbandonConflictTest(BitcoinTestFramework):
|
|||
|
||||
# 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()['bitcoin']
|
||||
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()['bitcoin']+ self.nodes[0].getbalance()['bitcoin']
|
||||
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 @@ class AbandonConflictTest(BitcoinTestFramework):
|
|||
# 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()['bitcoin']
|
||||
assert_equal(newbalance, balance + Decimal("30"))
|
||||
balance = newbalance
|
||||
|
||||
|
|
@ -119,19 +119,19 @@ class AbandonConflictTest(BitcoinTestFramework):
|
|||
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()['bitcoin'], 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()['bitcoin']
|
||||
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()['bitcoin']
|
||||
assert_equal(newbalance, balance - Decimal("10") - Decimal("14.99998") + Decimal("24.9996"))
|
||||
balance = newbalance
|
||||
|
||||
|
|
@ -139,7 +139,7 @@ class AbandonConflictTest(BitcoinTestFramework):
|
|||
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()['bitcoin']
|
||||
assert_equal(newbalance, balance - Decimal("24.9996"))
|
||||
balance = newbalance
|
||||
|
||||
|
|
@ -158,7 +158,7 @@ class AbandonConflictTest(BitcoinTestFramework):
|
|||
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()['bitcoin']
|
||||
assert_equal(newbalance, balance + Decimal("20"))
|
||||
balance = newbalance
|
||||
|
||||
|
|
@ -166,7 +166,7 @@ class AbandonConflictTest(BitcoinTestFramework):
|
|||
# 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()['bitcoin']
|
||||
#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")
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ from test_framework.util import (
|
|||
connect_nodes_bi,
|
||||
sync_blocks,
|
||||
sync_mempools,
|
||||
BITCOIN_ASSET,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -91,9 +92,9 @@ class AddressTypeTest(BitcoinTestFramework):
|
|||
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()['bitcoin'] for i in range(4)]
|
||||
else:
|
||||
return [self.nodes[i].getunconfirmedbalance() for i in range(4)]
|
||||
return [self.nodes[i].getunconfirmedbalance()['bitcoin'] for i in range(4)]
|
||||
|
||||
def test_address(self, node, address, multisig, typ):
|
||||
"""Run sanity checks on an address."""
|
||||
|
|
@ -262,7 +263,7 @@ class AddressTypeTest(BitcoinTestFramework):
|
|||
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()['bitcoin'], 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')
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ from random import randint
|
|||
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 @@ class WalletBackupTest(BitcoinTestFramework):
|
|||
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()['bitcoin'], 50)
|
||||
assert_equal(self.nodes[1].getbalance()['bitcoin'], 50)
|
||||
assert_equal(self.nodes[2].getbalance()['bitcoin'], 50)
|
||||
assert_equal(self.nodes[3].getbalance()['bitcoin'], 0)
|
||||
|
||||
self.log.info("Creating transactions")
|
||||
# Five rounds of sending each other transactions.
|
||||
|
|
@ -137,10 +137,10 @@ class WalletBackupTest(BitcoinTestFramework):
|
|||
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()['bitcoin']
|
||||
balance1 = self.nodes[1].getbalance()['bitcoin']
|
||||
balance2 = self.nodes[2].getbalance()['bitcoin']
|
||||
balance3 = self.nodes[3].getbalance()['bitcoin']
|
||||
total = balance0 + balance1 + balance2 + balance3
|
||||
|
||||
# At this point, there are 214 blocks (103 for setup, then 10 rounds, then 101.)
|
||||
|
|
@ -167,9 +167,9 @@ class WalletBackupTest(BitcoinTestFramework):
|
|||
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()['bitcoin'], balance0)
|
||||
assert_equal(self.nodes[1].getbalance()['bitcoin'], balance1)
|
||||
assert_equal(self.nodes[2].getbalance()['bitcoin'], balance2)
|
||||
|
||||
self.log.info("Restoring using dumped wallet")
|
||||
self.stop_three()
|
||||
|
|
@ -181,9 +181,9 @@ class WalletBackupTest(BitcoinTestFramework):
|
|||
|
||||
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()['bitcoin'], 0)
|
||||
assert_equal(self.nodes[1].getbalance()['bitcoin'], 0)
|
||||
assert_equal(self.nodes[2].getbalance()['bitcoin'], 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 @@ class WalletBackupTest(BitcoinTestFramework):
|
|||
|
||||
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()['bitcoin'], balance0)
|
||||
assert_equal(self.nodes[1].getbalance()['bitcoin'], balance1)
|
||||
assert_equal(self.nodes[2].getbalance()['bitcoin'], balance2)
|
||||
|
||||
# Backup to source wallet file must fail
|
||||
sourcePaths = [
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ from test_framework.util import (
|
|||
sync_blocks,
|
||||
sync_mempools,
|
||||
wait_until,
|
||||
BITCOIN_ASSET,
|
||||
)
|
||||
|
||||
class WalletTest(BitcoinTestFramework):
|
||||
|
|
@ -56,22 +57,22 @@ class WalletTest(BitcoinTestFramework):
|
|||
self.nodes[0].generate(1)
|
||||
|
||||
walletinfo = self.nodes[0].getwalletinfo()
|
||||
assert_equal(walletinfo['immature_balance'], 50)
|
||||
assert_equal(walletinfo['balance'], 0)
|
||||
assert_equal(walletinfo['immature_balance']['bitcoin'], 50)
|
||||
assert_equal(walletinfo['balance']['bitcoin'], 0)
|
||||
|
||||
self.sync_all([self.nodes[0:3]])
|
||||
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()['bitcoin'], 50)
|
||||
assert_equal(self.nodes[1].getbalance()['bitcoin'], 50)
|
||||
assert_equal(self.nodes[2].getbalance()['bitcoin'], 0)
|
||||
|
||||
# Check getbalance with different arguments
|
||||
assert_equal(self.nodes[0].getbalance("*"), 50)
|
||||
assert_equal(self.nodes[0].getbalance("*", 1), 50)
|
||||
assert_equal(self.nodes[0].getbalance("*", 1, True), 50)
|
||||
assert_equal(self.nodes[0].getbalance(minconf=1), 50)
|
||||
assert_equal(self.nodes[0].getbalance("*")['bitcoin'], 50)
|
||||
assert_equal(self.nodes[0].getbalance("*", 1)['bitcoin'], 50)
|
||||
assert_equal(self.nodes[0].getbalance("*", 1, True)['bitcoin'], 50)
|
||||
assert_equal(self.nodes[0].getbalance(minconf=1)['bitcoin'], 50)
|
||||
|
||||
# first argument of getbalance must be excluded or set to "*"
|
||||
assert_raises_rpc_error(-32, "dummy first argument must be excluded or set to \"*\"", self.nodes[0].getbalance, "")
|
||||
|
|
@ -115,10 +116,10 @@ class WalletTest(BitcoinTestFramework):
|
|||
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()['bitcoin']
|
||||
assert_equal(set([txout1['value'], txout2['value']]), set([10, balance]))
|
||||
walletinfo = self.nodes[0].getwalletinfo()
|
||||
assert_equal(walletinfo['immature_balance'], 0)
|
||||
assert_equal(walletinfo['immature_balance']['bitcoin'], 0)
|
||||
|
||||
# Have node0 mine a block, thus it will collect its own fee.
|
||||
self.nodes[0].generate(1)
|
||||
|
|
@ -156,8 +157,8 @@ class WalletTest(BitcoinTestFramework):
|
|||
|
||||
# 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()['bitcoin'], 100 - 21)
|
||||
assert_equal(self.nodes[2].getbalance()['bitcoin'], 21)
|
||||
|
||||
# Node0 should have two unspent outputs.
|
||||
# Create a couple of transactions to send them to node2, submit them through
|
||||
|
|
@ -183,8 +184,8 @@ class WalletTest(BitcoinTestFramework):
|
|||
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()['bitcoin'], 0)
|
||||
assert_equal(self.nodes[2].getbalance()['bitcoin'], 94)
|
||||
|
||||
# Verify that a spent output cannot be locked anymore
|
||||
spent_0 = {"txid": node0utxos[0]["txid"], "vout": node0utxos[0]["vout"]}
|
||||
|
|
@ -197,32 +198,32 @@ class WalletTest(BitcoinTestFramework):
|
|||
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()['bitcoin'], Decimal('84'), fee_per_byte, self.get_vsize(self.nodes[2].getrawtransaction(txid)))
|
||||
assert_equal(self.nodes[0].getbalance()['bitcoin'], 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()['bitcoin'], node_2_bal)
|
||||
node_0_bal = self.check_fee_amount(self.nodes[0].getbalance()['bitcoin'], 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()['bitcoin'], node_2_bal - Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].getrawtransaction(txid)))
|
||||
assert_equal(self.nodes[0].getbalance()['bitcoin'], 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()['bitcoin'], node_2_bal)
|
||||
node_0_bal = self.check_fee_amount(self.nodes[0].getbalance()['bitcoin'], 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
|
||||
|
|
@ -243,8 +244,8 @@ class WalletTest(BitcoinTestFramework):
|
|||
assert(txid1 in self.nodes[3].getrawmempool())
|
||||
|
||||
# Exercise balance rpcs
|
||||
assert_equal(self.nodes[0].getwalletinfo()["unconfirmed_balance"], 1)
|
||||
assert_equal(self.nodes[0].getunconfirmedbalance(), 1)
|
||||
assert_equal(self.nodes[0].getwalletinfo()["unconfirmed_balance"]['bitcoin'], 1)
|
||||
assert_equal(self.nodes[0].getunconfirmedbalance()['bitcoin'], 1)
|
||||
|
||||
# check if we can list zero value tx as available coins
|
||||
# 1. create raw_tx
|
||||
|
|
@ -287,7 +288,7 @@ class WalletTest(BitcoinTestFramework):
|
|||
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()['bitcoin'], 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 @@ class WalletTest(BitcoinTestFramework):
|
|||
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()['bitcoin'], node_2_bal)
|
||||
|
||||
# create another tx
|
||||
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 2)
|
||||
|
|
@ -315,21 +316,21 @@ class WalletTest(BitcoinTestFramework):
|
|||
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()['bitcoin'], node_2_bal)
|
||||
|
||||
# send a tx with value in a string (PR#6380 +)
|
||||
txid = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "2")
|
||||
tx_obj = self.nodes[0].gettransaction(txid)
|
||||
assert_equal(tx_obj['amount'], Decimal('-2'))
|
||||
assert_equal(tx_obj['amount']['bitcoin'], Decimal('-2'))
|
||||
|
||||
txid = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "0.0001")
|
||||
tx_obj = self.nodes[0].gettransaction(txid)
|
||||
assert_equal(tx_obj['amount'], Decimal('-0.0001'))
|
||||
assert_equal(tx_obj['amount']['bitcoin'], Decimal('-0.0001'))
|
||||
|
||||
# check if JSON parser can handle scientific notation in strings
|
||||
txid = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "1e-4")
|
||||
tx_obj = self.nodes[0].gettransaction(txid)
|
||||
assert_equal(tx_obj['amount'], Decimal('-0.0001'))
|
||||
assert_equal(tx_obj['amount']['bitcoin'], Decimal('-0.0001'))
|
||||
|
||||
# This will raise an exception because the amount type is wrong
|
||||
assert_raises_rpc_error(-3, "Invalid amount", self.nodes[0].sendtoaddress, self.nodes[2].getnewaddress(), "1f-4")
|
||||
|
|
@ -377,7 +378,7 @@ class WalletTest(BitcoinTestFramework):
|
|||
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()['bitcoin'] for i in range(3)]
|
||||
block_count = self.nodes[0].getblockcount()
|
||||
|
||||
# Check modes:
|
||||
|
|
@ -413,7 +414,7 @@ class WalletTest(BitcoinTestFramework):
|
|||
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()['bitcoin'] 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 @@ class WalletTest(BitcoinTestFramework):
|
|||
|
||||
# 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()['bitcoin'], "", "", True)
|
||||
self.nodes[0].generate(1)
|
||||
node0_balance = self.nodes[0].getbalance()
|
||||
node0_balance = self.nodes[0].getbalance()['bitcoin']
|
||||
# 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 @@ class WalletTest(BitcoinTestFramework):
|
|||
timeout -= 0.5
|
||||
assert_equal(len(self.nodes[0].getrawmempool()), chainlimit * 2)
|
||||
|
||||
node0_balance = self.nodes[0].getbalance()
|
||||
node0_balance = self.nodes[0].getbalance()['bitcoin']
|
||||
# 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'))
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ from decimal import Decimal
|
|||
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 @@ class BumpFeeTest(BitcoinTestFramework):
|
|||
self.sync_all()
|
||||
peer_node.generate(1)
|
||||
self.sync_all()
|
||||
assert_equal(rbf_node.getbalance(), Decimal("0.025"))
|
||||
assert_equal(rbf_node.getbalance()['bitcoin'], Decimal("0.025"))
|
||||
|
||||
self.log.info("Running tests")
|
||||
dest_address = peer_node.getnewaddress()
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||
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 @@ class WalletGroupTest(BitcoinTestFramework):
|
|||
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()['bitcoin'], subtractfeefromamount=True)
|
||||
self.sync_all()
|
||||
self.nodes[0].generate(1)
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||
from test_framework.util import (
|
||||
assert_equal,
|
||||
connect_nodes_bi,
|
||||
assert_raises_rpc_error
|
||||
assert_raises_rpc_error,
|
||||
BITCOIN_ASSET,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -71,7 +72,7 @@ class WalletHDTest(BitcoinTestFramework):
|
|||
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()['bitcoin'], NUM_HD_ADDS + 1)
|
||||
|
||||
self.log.info("Restore backup ...")
|
||||
self.stop_node(1)
|
||||
|
|
@ -97,7 +98,7 @@ class WalletHDTest(BitcoinTestFramework):
|
|||
# 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()['bitcoin'], NUM_HD_ADDS + 1)
|
||||
|
||||
# Try a RPC based rescan
|
||||
self.stop_node(1)
|
||||
|
|
@ -108,14 +109,14 @@ class WalletHDTest(BitcoinTestFramework):
|
|||
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()['bitcoin'], 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()['bitcoin'], 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)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||
from test_framework.util import (
|
||||
assert_equal,
|
||||
assert_raises_rpc_error,
|
||||
BITCOIN_ASSET,
|
||||
)
|
||||
|
||||
class ImportPrunedFundsTest(BitcoinTestFramework):
|
||||
|
|
@ -76,7 +77,7 @@ class ImportPrunedFundsTest(BitcoinTestFramework):
|
|||
# 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()['bitcoin']
|
||||
assert_equal(balance1, Decimal(0))
|
||||
|
||||
# Import with affiliated address with no rescan
|
||||
|
|
@ -88,7 +89,7 @@ class ImportPrunedFundsTest(BitcoinTestFramework):
|
|||
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()['bitcoin']
|
||||
assert_equal(balance3, Decimal('0.025'))
|
||||
|
||||
# Addresses Test - after import
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ from test_framework.util import (
|
|||
assert_equal,
|
||||
connect_nodes_bi,
|
||||
sync_blocks,
|
||||
BITCOIN_ASSET,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -62,7 +63,7 @@ class KeypoolRestoreTest(BitcoinTestFramework):
|
|||
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()['bitcoin'], 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'")
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ RPCs tested are:
|
|||
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 @@ class WalletLabelsTest(BitcoinTestFramework):
|
|||
# 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()['bitcoin'], 100)
|
||||
|
||||
# there should be 2 address groups
|
||||
# each with 1 address with a balance of 50 Bitcoins
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ from test_framework.test_node import ErrorMatch
|
|||
from test_framework.util import (
|
||||
assert_equal,
|
||||
assert_raises_rpc_error,
|
||||
BITCOIN_ASSET,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -157,18 +158,18 @@ class MultiWalletTest(BitcoinTestFramework):
|
|||
|
||||
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()['bitcoin'], 100)
|
||||
assert_equal(w2.getbalance()['bitcoin'], 0)
|
||||
assert_equal(w3.getbalance()['bitcoin'], 0)
|
||||
assert_equal(w4.getbalance()['bitcoin'], 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()['bitcoin'], 1)
|
||||
assert_equal(w3.getbalance()['bitcoin'], 2)
|
||||
assert_equal(w4.getbalance()['bitcoin'], 3)
|
||||
|
||||
batch = w1.batch([w1.getblockchaininfo.get_request(), w1.getwalletinfo.get_request()])
|
||||
assert_equal(batch[0]["result"]["chain"], self.chain)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ from test_framework.util import (
|
|||
connect_nodes,
|
||||
disconnect_nodes,
|
||||
sync_blocks,
|
||||
BITCOIN_ASSET,
|
||||
)
|
||||
|
||||
class TxnMallTest(BitcoinTestFramework):
|
||||
|
|
@ -42,7 +43,7 @@ class TxnMallTest(BitcoinTestFramework):
|
|||
# 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()['bitcoin'], starting_balance)
|
||||
self.nodes[i].getnewaddress() # bug workaround, coins generated assigned to first getnewaddress!
|
||||
|
||||
self.nodes[0].settxfee(.001)
|
||||
|
|
@ -55,8 +56,8 @@ class TxnMallTest(BitcoinTestFramework):
|
|||
node0_txid2 = self.nodes[0].sendtoaddress(node0_address2, 29)
|
||||
node0_tx2 = self.nodes[0].gettransaction(node0_txid2)
|
||||
|
||||
assert_equal(self.nodes[0].getbalance(),
|
||||
starting_balance + node0_tx1["fee"] + node0_tx2["fee"])
|
||||
assert_equal(self.nodes[0].getbalance()['bitcoin'],
|
||||
starting_balance + node0_tx1["fee"]['bitcoin'] + node0_tx2["fee"]['bitcoin'])
|
||||
|
||||
# Coins are sent to node1_address
|
||||
node1_address = self.nodes[1].getnewaddress()
|
||||
|
|
@ -94,12 +95,12 @@ class TxnMallTest(BitcoinTestFramework):
|
|||
|
||||
# Node0's balance should be starting balance, plus 50BTC for another
|
||||
# matured block, minus tx1 and tx2 amounts, and minus transaction fees:
|
||||
expected = starting_balance + node0_tx1["fee"] + node0_tx2["fee"]
|
||||
expected = starting_balance + node0_tx1["fee"]['bitcoin'] + node0_tx2["fee"]['bitcoin']
|
||||
if self.options.mine_block:
|
||||
expected += 50
|
||||
expected += tx1["amount"] + tx1["fee"]
|
||||
expected += tx2["amount"] + tx2["fee"]
|
||||
assert_equal(self.nodes[0].getbalance(), expected)
|
||||
expected += tx1["amount"]['bitcoin'] + tx1["fee"]['bitcoin']
|
||||
expected += tx2["amount"]['bitcoin'] + tx2["fee"]['bitcoin']
|
||||
assert_equal(self.nodes[0].getbalance()['bitcoin'], expected)
|
||||
|
||||
if self.options.mine_block:
|
||||
assert_equal(tx1["confirmations"], 1)
|
||||
|
|
@ -140,7 +141,7 @@ class TxnMallTest(BitcoinTestFramework):
|
|||
expected += 100
|
||||
if (self.options.mine_block):
|
||||
expected -= 50
|
||||
assert_equal(self.nodes[0].getbalance(), expected)
|
||||
assert_equal(self.nodes[0].getbalance()['bitcoin'], expected)
|
||||
|
||||
if __name__ == '__main__':
|
||||
TxnMallTest().main()
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ from test_framework.util import (
|
|||
disconnect_nodes,
|
||||
find_output,
|
||||
sync_blocks,
|
||||
BITCOIN_ASSET,
|
||||
)
|
||||
|
||||
class TxnMallTest(BitcoinTestFramework):
|
||||
|
|
@ -35,7 +36,7 @@ class TxnMallTest(BitcoinTestFramework):
|
|||
# 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()['bitcoin'], 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 @@ class TxnMallTest(BitcoinTestFramework):
|
|||
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()['bitcoin'],
|
||||
starting_balance + fund_foo_tx["fee"] + fund_bar_tx["fee"])
|
||||
|
||||
# Coins are sent to node1_address
|
||||
|
|
@ -90,13 +91,13 @@ class TxnMallTest(BitcoinTestFramework):
|
|||
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()['bitcoin'], 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()['bitcoin'], starting_balance - tx1["amount"] - tx2["amount"])
|
||||
else:
|
||||
assert_equal(tx1["confirmations"], 0)
|
||||
assert_equal(tx2["confirmations"], 0)
|
||||
|
|
@ -126,10 +127,10 @@ class TxnMallTest(BitcoinTestFramework):
|
|||
# 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()['bitcoin'], 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()['bitcoin'], 1250 + 1240)
|
||||
|
||||
if __name__ == '__main__':
|
||||
TxnMallTest().main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue