Fix (most) rpc tests by updating balances. zcpour, zcpourdoublespend, and txn_doublespend currently fail.

This commit is contained in:
Nathan Wilcox 2016-04-08 18:05:51 -07:00
parent 349a7b3714
commit ad56edf7d4
14 changed files with 59 additions and 72 deletions

View File

@ -77,8 +77,8 @@ class InvalidBlockRequestTest(ComparisonTestFramework):
self.block_time += 1
# chr(81) is OP_TRUE
tx1 = create_transaction(self.block1.vtx[0], 0, chr(81), 50*100000000)
tx2 = create_transaction(tx1, 0, chr(81), 50*100000000)
tx1 = create_transaction(self.block1.vtx[0], 0, chr(81), 40*100000000)
tx2 = create_transaction(tx1, 0, chr(81), 40*100000000)
block2.vtx.extend([tx1, tx2])
block2.hashMerkleRoot = block2.calc_merkle_root()

View File

@ -54,9 +54,9 @@ class MempoolCoinbaseTest(BitcoinTestFramework):
# and make sure the mempool code behaves correctly.
b = [ self.nodes[0].getblockhash(n) for n in range(102, 105) ]
coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
spend_101_raw = self.create_tx(coinbase_txids[0], node1_address, 50)
spend_102_raw = self.create_tx(coinbase_txids[1], node0_address, 50)
spend_103_raw = self.create_tx(coinbase_txids[2], node0_address, 50)
spend_101_raw = self.create_tx(coinbase_txids[0], node1_address, 40)
spend_102_raw = self.create_tx(coinbase_txids[1], node0_address, 40)
spend_103_raw = self.create_tx(coinbase_txids[2], node0_address, 40)
# Broadcast and mine spend_102 and 103:
spend_102_id = self.nodes[0].sendrawtransaction(spend_102_raw)
@ -64,8 +64,8 @@ class MempoolCoinbaseTest(BitcoinTestFramework):
self.nodes[0].generate(1)
# Create 102_1 and 103_1:
spend_102_1_raw = self.create_tx(spend_102_id, node1_address, 50)
spend_103_1_raw = self.create_tx(spend_103_id, node1_address, 50)
spend_102_1_raw = self.create_tx(spend_102_id, node1_address, 40)
spend_103_1_raw = self.create_tx(spend_103_id, node1_address, 40)
# Broadcast and mine 103_1:
spend_103_1_id = self.nodes[0].sendrawtransaction(spend_103_1_raw)

View File

@ -45,13 +45,13 @@ class MempoolCoinbaseTest(BitcoinTestFramework):
b = [ self.nodes[0].getblockhash(n) for n in range(1, 4) ]
coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
spends1_raw = [ self.create_tx(txid, node0_address, 50) for txid in coinbase_txids ]
spends1_raw = [ self.create_tx(txid, node0_address, 40) for txid in coinbase_txids ]
spends1_id = [ self.nodes[0].sendrawtransaction(tx) for tx in spends1_raw ]
blocks = []
blocks.extend(self.nodes[0].generate(1))
spends2_raw = [ self.create_tx(txid, node0_address, 49.99) for txid in spends1_id ]
spends2_raw = [ self.create_tx(txid, node0_address, 39.99) for txid in spends1_id ]
spends2_id = [ self.nodes[0].sendrawtransaction(tx) for tx in spends2_raw ]
blocks.extend(self.nodes[0].generate(1))

View File

@ -46,7 +46,7 @@ class MempoolSpendCoinbaseTest(BitcoinTestFramework):
# is too immature to spend.
b = [ self.nodes[0].getblockhash(n) for n in range(101, 103) ]
coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
spends_raw = [ self.create_tx(txid, node0_address, 50) for txid in coinbase_txids ]
spends_raw = [ self.create_tx(txid, node0_address, 40) for txid in coinbase_txids ]
spend_101_id = self.nodes[0].sendrawtransaction(spends_raw[0])

View File

@ -44,9 +44,9 @@ class MerkleBlockTest(BitcoinTestFramework):
assert_equal(self.nodes[2].getbalance(), 0)
node0utxos = self.nodes[0].listunspent(1)
tx1 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 50})
tx1 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 40})
txid1 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransaction(tx1)["hex"])
tx2 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 50})
tx2 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 40})
txid2 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransaction(tx2)["hex"])
assert_raises(JSONRPCException, self.nodes[0].gettxoutproof, [txid1])
@ -64,7 +64,7 @@ class MerkleBlockTest(BitcoinTestFramework):
assert_equal(self.nodes[2].verifytxoutproof(self.nodes[2].gettxoutproof([txid1, txid2], blockhash)), txlist)
txin_spent = self.nodes[1].listunspent(1).pop()
tx3 = self.nodes[1].createrawtransaction([txin_spent], {self.nodes[0].getnewaddress(): 50})
tx3 = self.nodes[1].createrawtransaction([txin_spent], {self.nodes[0].getnewaddress(): 40})
self.nodes[0].sendrawtransaction(self.nodes[1].signrawtransaction(tx3)["hex"])
self.nodes[0].generate(1)
self.sync_all()

View File

@ -139,7 +139,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(), bal+Decimal('40.00000000')+Decimal('2.19000000')) #block reward + tx
if __name__ == '__main__':
RawTransactionsTest().main()

View File

@ -65,7 +65,7 @@ class RESTTest (BitcoinTestFramework):
self.nodes[2].generate(100)
self.sync_all()
assert_equal(self.nodes[0].getbalance(), 50)
assert_equal(self.nodes[0].getbalance(), 40)
txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1)
self.sync_all()

View File

@ -23,7 +23,7 @@ class BitcoinTestFramework(object):
def run_test(self):
for node in self.nodes:
assert_equal(node.getblockcount(), 200)
assert_equal(node.getbalance(), 25*50)
assert_equal(node.getbalance(), 25*40)
def add_options(self, parser):
pass

View File

@ -24,27 +24,29 @@ class TxnMallTest(BitcoinTestFramework):
return super(TxnMallTest, self).setup_network(True)
def run_test(self):
# All nodes should start with 1,250 BTC:
starting_balance = 1250
starting_balance = 1000
for i in range(4):
assert_equal(self.nodes[i].getbalance(), starting_balance)
self.nodes[i].getnewaddress("") # bug workaround, coins generated assigned to first getnewaddress!
# Assign coins to foo and bar accounts:
self.nodes[0].move("", "foo", 1220)
self.nodes[0].move("", "bar", 30)
amtfoo = 970
amtbar = starting_balance - amtfoo
self.nodes[0].move("", "foo", amtfoo)
self.nodes[0].move("", "bar", amtbar)
assert_equal(self.nodes[0].getbalance(""), 0)
# Coins are sent to node1_address
node1_address = self.nodes[1].getnewaddress("from0")
# First: use raw transaction API to send 1210 BTC to node1_address,
# First: use raw transaction API to send amtqux BTC to node1_address,
# but don't broadcast:
(total_in, inputs) = gather_inputs(self.nodes[0], 1210)
amtqux = 713
(total_in, inputs) = gather_inputs(self.nodes[0], amtqux)
change_address = self.nodes[0].getnewaddress("foo")
outputs = {}
outputs[change_address] = 40
outputs[node1_address] = 1210
outputs[change_address] = starting_balance - amtqux
outputs[node1_address] = amtqux
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
doublespend = self.nodes[0].signrawtransaction(rawtx)
assert_equal(doublespend["complete"], True)
@ -52,8 +54,9 @@ class TxnMallTest(BitcoinTestFramework):
# Create two transaction from node[0] to node[1]; the
# second must spend change from the first because the first
# spends all mature inputs:
txid1 = self.nodes[0].sendfrom("foo", node1_address, 1210, 0)
txid2 = self.nodes[0].sendfrom("bar", node1_address, 20, 0)
txid1 = self.nodes[0].sendfrom("foo", node1_address, amtqux, 0)
amtbar2 = 20
txid2 = self.nodes[0].sendfrom("bar", node1_address, amtbar2, 0)
# Have node0 mine a block:
if (self.options.mine_block):
@ -63,17 +66,17 @@ class TxnMallTest(BitcoinTestFramework):
tx1 = self.nodes[0].gettransaction(txid1)
tx2 = self.nodes[0].gettransaction(txid2)
# Node0's balance should be starting balance, plus 50BTC for another
# matured block, minus 1210, minus 20, and minus transaction fees:
# Node0's balance should be starting balance, plus 40BTC for another
# matured block, minus amtqux, minus amtbar2, and minus transaction fees:
expected = starting_balance
if self.options.mine_block: expected += 50
if self.options.mine_block: expected += 40
expected += tx1["amount"] + tx1["fee"]
expected += tx2["amount"] + tx2["fee"]
assert_equal(self.nodes[0].getbalance(), expected)
# foo and bar accounts should be debited:
assert_equal(self.nodes[0].getbalance("foo"), 1220+tx1["amount"]+tx1["fee"])
assert_equal(self.nodes[0].getbalance("bar"), 30+tx2["amount"]+tx2["fee"])
assert_equal(self.nodes[0].getbalance("foo"), amtfoo+tx1["amount"]+tx1["fee"])
assert_equal(self.nodes[0].getbalance("bar"), amtbar+tx2["amount"]+tx2["fee"])
if self.options.mine_block:
assert_equal(tx1["confirmations"], 1)
@ -102,18 +105,18 @@ class TxnMallTest(BitcoinTestFramework):
assert_equal(tx1["confirmations"], -1)
assert_equal(tx2["confirmations"], -1)
# Node0's total balance should be starting balance, plus 100BTC for
# two more matured blocks, minus 1210 for the double-spend:
expected = starting_balance + 100 - 1210
# Node0's total balance should be starting balance, plus 80BTC for
# two more matured blocks, minus amtqux for the double-spend:
expected = starting_balance + 80 - amtqux
assert_equal(self.nodes[0].getbalance(), expected)
assert_equal(self.nodes[0].getbalance("*"), expected)
# foo account should be debited, but bar account should not:
assert_equal(self.nodes[0].getbalance("foo"), 1220-1210)
assert_equal(self.nodes[0].getbalance("bar"), 30)
assert_equal(self.nodes[0].getbalance("foo"), amtfoo-amtqux)
assert_equal(self.nodes[0].getbalance("bar"), amtbar)
# Node1's "from" account balance should be just the mutated send:
assert_equal(self.nodes[1].getbalance("from0"), 1210)
assert_equal(self.nodes[1].getbalance("from0"), amtqux)
if __name__ == '__main__':
TxnMallTest().main()

View File

@ -3,21 +3,6 @@
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
# Exercise the wallet. Ported from wallet.sh.
# Does the following:
# a) creates 3 nodes, with an empty chain (no blocks).
# b) node0 mines a block
# c) node1 mines 101 blocks, so now nodes 0 and 1 have 50btc, node2 has none.
# d) node0 sends 21 btc to node2, in two transactions (11 btc, then 10 btc).
# e) node0 mines a block, collects the fee on the second transaction
# f) node1 mines 100 blocks, to mature node0's just-mined block
# g) check that node0 has 100-21, node2 has 21
# h) node0 should now have 2 unspent outputs; send these to node2 via raw tx broadcast by node1
# i) have node1 mine a block
# j) check balances - node0 should have 0, node2 should have 100
# k) test ResendWalletTransactions - create transactions, startup fourth node, make sure it syncs
#
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *

View File

@ -10,7 +10,7 @@ Test case is:
4 nodes. 1 2 and 3 send transactions between each other,
fourth node is a miner.
1 2 3 each mine a block to start, then
Miner creates 100 blocks so 1 2 3 each have 50 mature
Miner creates 100 blocks so 1 2 3 each have 40 mature
coins to spend.
Then 5 iterations of 1/2/3 sending coins amongst
themselves to get transactions in the wallets,
@ -23,7 +23,7 @@ Miner then generates 101 more blocks, so any
transaction fees paid mature.
Sanity check:
Sum(1,2,3,4 balances) == 114*50
Sum(1,2,3,4 balances) == 114*40
1/2/3 are shutdown, and their wallets erased.
Then restore using wallet.dat backup. And
@ -110,9 +110,9 @@ 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[0].getbalance(), 40)
assert_equal(self.nodes[1].getbalance(), 40)
assert_equal(self.nodes[2].getbalance(), 40)
assert_equal(self.nodes[3].getbalance(), 0)
logging.info("Creating transactions")
@ -144,8 +144,8 @@ class WalletBackupTest(BitcoinTestFramework):
total = balance0 + balance1 + balance2 + balance3
# At this point, there are 214 blocks (103 for setup, then 10 rounds, then 101.)
# 114 are mature, so the sum of all wallets should be 114 * 50 = 5700.
assert_equal(total, 5700)
# 114 are mature, so the sum of all wallets should be 114 * 40 = 4560.
assert_equal(total, 4560)
##
# Test restoring spender wallets from backups

View File

@ -28,7 +28,7 @@ class ZapWalletTXesTest (BitcoinTestFramework):
self.nodes[1].generate(101)
self.sync_all()
assert_equal(self.nodes[0].getbalance(), 50)
assert_equal(self.nodes[0].getbalance(), 40)
txid0 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11)
txid1 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10)
@ -37,7 +37,7 @@ class ZapWalletTXesTest (BitcoinTestFramework):
self.sync_all()
txid2 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11)
txid3 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10)
txid3 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 5)
tx0 = self.nodes[0].gettransaction(txid0)
assert_equal(tx0['txid'], txid0) #tx0 must be available (confirmed)

View File

@ -21,9 +21,9 @@ class PourTxTest(BitcoinTestFramework):
zcsecretkey = zckeypair["zcsecretkey"]
zcaddress = zckeypair["zcaddress"]
(total_in, inputs) = gather_inputs(self.nodes[1], 50)
(total_in, inputs) = gather_inputs(self.nodes[1], 40)
protect_tx = self.nodes[1].createrawtransaction(inputs, {})
pour_result = self.nodes[1].zcrawpour(protect_tx, {}, {zcaddress:49.9}, 50, 0.1)
pour_result = self.nodes[1].zcrawpour(protect_tx, {}, {zcaddress:49.9}, 40, 0.1)
receive_result = self.nodes[1].zcrawreceive(zcsecretkey, pour_result["encryptedbucket1"])
assert_equal(receive_result["exists"], False)
@ -50,12 +50,11 @@ class PourTxTest(BitcoinTestFramework):
assert_equal(receive_result["exists"], True)
def run_test(self):
# All nodes should start with 1,250 BTC:
starting_balance = 1250
starting_balance = 1000
for i in range(4):
assert_equal(self.nodes[i].getbalance(), starting_balance)
self.nodes[i].getnewaddress("") # bug workaround, coins generated assigned to first getnewaddress!
# Generate zcaddress keypairs
zckeypair1 = self.nodes[0].zcrawkeygen()
zcsecretkey1 = zckeypair1["zcsecretkey"]
@ -65,14 +64,14 @@ class PourTxTest(BitcoinTestFramework):
zcsecretkey2 = zckeypair2["zcsecretkey"]
zcaddress2 = zckeypair2["zcaddress"]
self.nodes[0].move("", "foo", 1220)
self.nodes[0].move("", "foo", 970)
self.nodes[0].move("", "bar", 30)
assert_equal(self.nodes[0].getbalance(""), 0)
change_address = self.nodes[0].getnewaddress("foo")
# Pour some of our money into this address
(total_in, inputs) = gather_inputs(self.nodes[0], 1210)
(total_in, inputs) = gather_inputs(self.nodes[0], 960)
outputs = {}
outputs[change_address] = 78
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)

View File

@ -41,8 +41,7 @@ class PourTxTest(BitcoinTestFramework):
assert_equal(self.cannot_pour(node, txn), True)
def run_test(self):
# All nodes should start with 1,250 BTC:
starting_balance = 1250
starting_balance = 1000
for i in range(4):
assert_equal(self.nodes[i].getbalance(), starting_balance)
self.nodes[i].getnewaddress("") # bug workaround, coins generated assigned to first getnewaddress!
@ -54,9 +53,9 @@ class PourTxTest(BitcoinTestFramework):
pool = [0, 1, 2, 3]
for i in range(4):
(total_in, inputs) = gather_inputs(self.nodes[i], 50)
(total_in, inputs) = gather_inputs(self.nodes[i], 40)
pool[i] = self.nodes[i].createrawtransaction(inputs, {})
pool[i] = self.nodes[i].zcrawpour(pool[i], {}, {zcaddress:49.9}, 50, 0.1)
pool[i] = self.nodes[i].zcrawpour(pool[i], {}, {zcaddress:49.9}, 40, 0.1)
signed = self.nodes[i].signrawtransaction(pool[i]["rawtxn"])
# send the tx to both halves of the network
@ -181,3 +180,4 @@ class PourTxTest(BitcoinTestFramework):
if __name__ == '__main__':
PourTxTest().main()