From ad56edf7d4e6f7613fd18610084bbbe136068c9a Mon Sep 17 00:00:00 2001 From: Nathan Wilcox Date: Fri, 8 Apr 2016 18:05:51 -0700 Subject: [PATCH] Fix (most) rpc tests by updating balances. zcpour, zcpourdoublespend, and txn_doublespend currently fail. --- qa/rpc-tests/invalidblockrequest.py | 4 +- qa/rpc-tests/mempool_coinbase_spends.py | 10 ++--- qa/rpc-tests/mempool_resurrect_test.py | 4 +- qa/rpc-tests/mempool_spendcoinbase.py | 2 +- qa/rpc-tests/merkle_blocks.py | 6 +-- qa/rpc-tests/rawtransactions.py | 2 +- qa/rpc-tests/rest.py | 2 +- qa/rpc-tests/test_framework/test_framework.py | 2 +- qa/rpc-tests/txn_doublespend.py | 45 ++++++++++--------- qa/rpc-tests/wallet.py | 15 ------- qa/rpc-tests/walletbackup.py | 14 +++--- qa/rpc-tests/zapwallettxes.py | 4 +- qa/rpc-tests/zcpour.py | 13 +++--- qa/rpc-tests/zcpourdoublespend.py | 8 ++-- 14 files changed, 59 insertions(+), 72 deletions(-) diff --git a/qa/rpc-tests/invalidblockrequest.py b/qa/rpc-tests/invalidblockrequest.py index 64b8e2639..272cc08f9 100755 --- a/qa/rpc-tests/invalidblockrequest.py +++ b/qa/rpc-tests/invalidblockrequest.py @@ -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() diff --git a/qa/rpc-tests/mempool_coinbase_spends.py b/qa/rpc-tests/mempool_coinbase_spends.py index c64a15b9f..34a5c52ed 100755 --- a/qa/rpc-tests/mempool_coinbase_spends.py +++ b/qa/rpc-tests/mempool_coinbase_spends.py @@ -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) diff --git a/qa/rpc-tests/mempool_resurrect_test.py b/qa/rpc-tests/mempool_resurrect_test.py index 19c74bb75..451b4a4da 100755 --- a/qa/rpc-tests/mempool_resurrect_test.py +++ b/qa/rpc-tests/mempool_resurrect_test.py @@ -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)) diff --git a/qa/rpc-tests/mempool_spendcoinbase.py b/qa/rpc-tests/mempool_spendcoinbase.py index fc17c5069..5954a28f5 100755 --- a/qa/rpc-tests/mempool_spendcoinbase.py +++ b/qa/rpc-tests/mempool_spendcoinbase.py @@ -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]) diff --git a/qa/rpc-tests/merkle_blocks.py b/qa/rpc-tests/merkle_blocks.py index 72a80ce6c..26944041f 100755 --- a/qa/rpc-tests/merkle_blocks.py +++ b/qa/rpc-tests/merkle_blocks.py @@ -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() diff --git a/qa/rpc-tests/rawtransactions.py b/qa/rpc-tests/rawtransactions.py index 173faf736..924bfedfb 100755 --- a/qa/rpc-tests/rawtransactions.py +++ b/qa/rpc-tests/rawtransactions.py @@ -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() diff --git a/qa/rpc-tests/rest.py b/qa/rpc-tests/rest.py index a2efca286..03676fd5b 100755 --- a/qa/rpc-tests/rest.py +++ b/qa/rpc-tests/rest.py @@ -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() diff --git a/qa/rpc-tests/test_framework/test_framework.py b/qa/rpc-tests/test_framework/test_framework.py index 5671431f6..baed39a51 100755 --- a/qa/rpc-tests/test_framework/test_framework.py +++ b/qa/rpc-tests/test_framework/test_framework.py @@ -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 diff --git a/qa/rpc-tests/txn_doublespend.py b/qa/rpc-tests/txn_doublespend.py index 99dcdae55..254af2cdf 100755 --- a/qa/rpc-tests/txn_doublespend.py +++ b/qa/rpc-tests/txn_doublespend.py @@ -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() diff --git a/qa/rpc-tests/wallet.py b/qa/rpc-tests/wallet.py index 1624b65a2..bd4fcb4c9 100755 --- a/qa/rpc-tests/wallet.py +++ b/qa/rpc-tests/wallet.py @@ -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 * diff --git a/qa/rpc-tests/walletbackup.py b/qa/rpc-tests/walletbackup.py index da100d7fc..a0533c3d8 100755 --- a/qa/rpc-tests/walletbackup.py +++ b/qa/rpc-tests/walletbackup.py @@ -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 diff --git a/qa/rpc-tests/zapwallettxes.py b/qa/rpc-tests/zapwallettxes.py index 0ec8ec536..54006b654 100755 --- a/qa/rpc-tests/zapwallettxes.py +++ b/qa/rpc-tests/zapwallettxes.py @@ -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) diff --git a/qa/rpc-tests/zcpour.py b/qa/rpc-tests/zcpour.py index b116fc544..64a33a0dd 100755 --- a/qa/rpc-tests/zcpour.py +++ b/qa/rpc-tests/zcpour.py @@ -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) diff --git a/qa/rpc-tests/zcpourdoublespend.py b/qa/rpc-tests/zcpourdoublespend.py index b6582d04f..69e189194 100755 --- a/qa/rpc-tests/zcpourdoublespend.py +++ b/qa/rpc-tests/zcpourdoublespend.py @@ -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() +