Browse Source

Update RPC tests to account for decreased block interval

pull/4/head
Jack Grigg 8 years ago
parent
commit
196cf25d5b
  1. 10
      qa/rpc-tests/mempool_coinbase_spends.py
  2. 4
      qa/rpc-tests/mempool_resurrect_test.py
  3. 2
      qa/rpc-tests/mempool_spendcoinbase.py
  4. 6
      qa/rpc-tests/merkle_blocks.py
  5. 2
      qa/rpc-tests/rawtransactions.py
  6. 8
      qa/rpc-tests/rest.py
  7. 2
      qa/rpc-tests/test_framework/test_framework.py
  8. 34
      qa/rpc-tests/txn_doublespend.py
  9. 33
      qa/rpc-tests/wallet.py
  10. 10
      qa/rpc-tests/walletbackup.py
  11. 2
      qa/rpc-tests/zapwallettxes.py

10
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, 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)
spend_101_raw = self.create_tx(coinbase_txids[0], node1_address, 10)
spend_102_raw = self.create_tx(coinbase_txids[1], node0_address, 10)
spend_103_raw = self.create_tx(coinbase_txids[2], node0_address, 10)
# 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, 40)
spend_103_1_raw = self.create_tx(spend_103_id, node1_address, 40)
spend_102_1_raw = self.create_tx(spend_102_id, node1_address, 10)
spend_103_1_raw = self.create_tx(spend_103_id, node1_address, 10)
# Broadcast and mine 103_1:
spend_103_1_id = self.nodes[0].sendrawtransaction(spend_103_1_raw)

4
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, 40) for txid in coinbase_txids ]
spends1_raw = [ self.create_tx(txid, node0_address, 10) 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, 39.99) for txid in spends1_id ]
spends2_raw = [ self.create_tx(txid, node0_address, 9.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))

2
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, 40) for txid in coinbase_txids ]
spends_raw = [ self.create_tx(txid, node0_address, 10) for txid in coinbase_txids ]
spend_101_id = self.nodes[0].sendrawtransaction(spends_raw[0])

6
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(): 40})
tx1 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 10})
txid1 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransaction(tx1)["hex"])
tx2 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 40})
tx2 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 10})
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(): 40})
tx3 = self.nodes[1].createrawtransaction([txin_spent], {self.nodes[0].getnewaddress(): 10})
self.nodes[0].sendrawtransaction(self.nodes[1].signrawtransaction(tx3)["hex"])
self.nodes[0].generate(1)
self.sync_all()

2
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('40.00000000')+Decimal('2.19000000')) #block reward + tx
assert_equal(self.nodes[0].getbalance(), bal+Decimal('10.00000000')+Decimal('2.19000000')) #block reward + tx
if __name__ == '__main__':
RawTransactionsTest().main()

8
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(), 40)
assert_equal(self.nodes[0].getbalance(), 10)
txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1)
self.sync_all()
@ -262,9 +262,9 @@ class RESTTest (BitcoinTestFramework):
# check block tx details
# let's make 3 tx and mine them on node 1
txs = []
txs.append(self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11))
txs.append(self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11))
txs.append(self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11))
txs.append(self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1))
txs.append(self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1))
txs.append(self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1))
self.sync_all()
# now mine the transactions

2
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*40)
assert_equal(node.getbalance(), 25*10)
def add_options(self, parser):
pass

34
qa/rpc-tests/txn_doublespend.py

@ -24,7 +24,7 @@ class TxnMallTest(BitcoinTestFramework):
return super(TxnMallTest, self).setup_network(True)
def run_test(self):
mining_reward = 40
mining_reward = 10
starting_balance = mining_reward * 25
for i in range(4):
@ -32,20 +32,20 @@ class TxnMallTest(BitcoinTestFramework):
self.nodes[i].getnewaddress("") # bug workaround, coins generated assigned to first getnewaddress!
# Assign coins to foo and bar accounts:
self.nodes[0].move("", "foo", (starting_balance - (mining_reward - 20)))
self.nodes[0].move("", "bar", (mining_reward - 20))
self.nodes[0].move("", "foo", (starting_balance - (mining_reward - 5)))
self.nodes[0].move("", "bar", (mining_reward - 5))
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 (starting_balance - (mining_reward - 10)) BTC to node1_address,
# First: use raw transaction API to send (starting_balance - (mining_reward - 2)) BTC to node1_address,
# but don't broadcast:
(total_in, inputs) = gather_inputs(self.nodes[0], (starting_balance - (mining_reward - 10)))
(total_in, inputs) = gather_inputs(self.nodes[0], (starting_balance - (mining_reward - 2)))
change_address = self.nodes[0].getnewaddress("foo")
outputs = {}
outputs[change_address] = (mining_reward - 10)
outputs[node1_address] = (starting_balance - (mining_reward - 10))
outputs[change_address] = (mining_reward - 2)
outputs[node1_address] = (starting_balance - (mining_reward - 2))
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
doublespend = self.nodes[0].signrawtransaction(rawtx)
assert_equal(doublespend["complete"], True)
@ -53,8 +53,8 @@ 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, (starting_balance - (mining_reward - 10)), 0)
txid2 = self.nodes[0].sendfrom("bar", node1_address, 20, 0)
txid1 = self.nodes[0].sendfrom("foo", node1_address, (starting_balance - (mining_reward - 2)), 0)
txid2 = self.nodes[0].sendfrom("bar", node1_address, 5, 0)
# Have node0 mine a block:
if (self.options.mine_block):
@ -65,7 +65,7 @@ class TxnMallTest(BitcoinTestFramework):
tx2 = self.nodes[0].gettransaction(txid2)
# Node0's balance should be starting balance, plus mining_reward for another
# matured block, minus (starting_balance - (mining_reward - 10)), minus 20, and minus transaction fees:
# matured block, minus (starting_balance - (mining_reward - 2)), minus 5, and minus transaction fees:
expected = starting_balance
if self.options.mine_block: expected += mining_reward
expected += tx1["amount"] + tx1["fee"]
@ -73,8 +73,8 @@ class TxnMallTest(BitcoinTestFramework):
assert_equal(self.nodes[0].getbalance(), expected)
# foo and bar accounts should be debited:
assert_equal(self.nodes[0].getbalance("foo"), (starting_balance - (mining_reward - 20))+tx1["amount"]+tx1["fee"])
assert_equal(self.nodes[0].getbalance("bar"), (mining_reward - 20)+tx2["amount"]+tx2["fee"])
assert_equal(self.nodes[0].getbalance("foo"), (starting_balance - (mining_reward - 5))+tx1["amount"]+tx1["fee"])
assert_equal(self.nodes[0].getbalance("bar"), (mining_reward - 5)+tx2["amount"]+tx2["fee"])
if self.options.mine_block:
assert_equal(tx1["confirmations"], 1)
@ -104,17 +104,17 @@ class TxnMallTest(BitcoinTestFramework):
assert_equal(tx2["confirmations"], -1)
# Node0's total balance should be starting balance, plus 100BTC for
# two more matured blocks, minus (starting_balance - (mining_reward - 10)) for the double-spend:
expected = starting_balance + (mining_reward * 2) - (starting_balance - (mining_reward - 10))
# two more matured blocks, minus (starting_balance - (mining_reward - 2)) for the double-spend:
expected = starting_balance + (mining_reward * 2) - (starting_balance - (mining_reward - 2))
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"), (starting_balance - (mining_reward - 20))-(starting_balance - (mining_reward - 10)))
assert_equal(self.nodes[0].getbalance("bar"), (mining_reward - 20))
assert_equal(self.nodes[0].getbalance("foo"), (starting_balance - (mining_reward - 5))-(starting_balance - (mining_reward - 2)))
assert_equal(self.nodes[0].getbalance("bar"), (mining_reward - 5))
# Node1's "from" account balance should be just the mutated send:
assert_equal(self.nodes[1].getbalance("from0"), (starting_balance - (mining_reward - 10)))
assert_equal(self.nodes[1].getbalance("from0"), (starting_balance - (mining_reward - 2)))
if __name__ == '__main__':
TxnMallTest().main()

33
qa/rpc-tests/wallet.py

@ -24,7 +24,7 @@ class WalletTest (BitcoinTestFramework):
def run_test (self):
print "Mining blocks..."
self.nodes[0].generate(1)
self.nodes[0].generate(4)
walletinfo = self.nodes[0].getwalletinfo()
assert_equal(walletinfo['immature_balance'], 40)
@ -35,7 +35,7 @@ class WalletTest (BitcoinTestFramework):
self.sync_all()
assert_equal(self.nodes[0].getbalance(), 40)
assert_equal(self.nodes[1].getbalance(), 40)
assert_equal(self.nodes[1].getbalance(), 10)
assert_equal(self.nodes[2].getbalance(), 0)
# Send 21 BTC from 0 to 2 using sendtoaddress call.
@ -54,16 +54,16 @@ class WalletTest (BitcoinTestFramework):
self.nodes[1].generate(100)
self.sync_all()
# node0 should end up with 100 btc in block rewards plus fees, but
# node0 should end up with 50 btc in block rewards plus fees, but
# minus the 21 plus fees sent to node2
assert_equal(self.nodes[0].getbalance(), 80-21)
assert_equal(self.nodes[0].getbalance(), 50-21)
assert_equal(self.nodes[2].getbalance(), 21)
# Node0 should have two unspent outputs.
# Node0 should have three unspent outputs.
# Create a couple of transactions to send them to node2, submit them through
# node1, and make sure both node0 and node2 pick them up properly:
node0utxos = self.nodes[0].listunspent(1)
assert_equal(len(node0utxos), 2)
assert_equal(len(node0utxos), 3)
# create both transactions
txns_to_send = []
@ -78,14 +78,15 @@ class WalletTest (BitcoinTestFramework):
# Have node 1 (miner) send the transactions
self.nodes[1].sendrawtransaction(txns_to_send[0]["hex"], True)
self.nodes[1].sendrawtransaction(txns_to_send[1]["hex"], True)
self.nodes[1].sendrawtransaction(txns_to_send[2]["hex"], True)
# Have node1 mine a block to confirm transactions:
self.nodes[1].generate(1)
self.sync_all()
assert_equal(self.nodes[0].getbalance(), 0)
assert_equal(self.nodes[2].getbalance(), 80)
assert_equal(self.nodes[2].getbalance("from1"), 80-21)
assert_equal(self.nodes[2].getbalance(), 50)
assert_equal(self.nodes[2].getbalance("from1"), 50-21)
# Send 10 BTC normal
address = self.nodes[0].getnewaddress("test")
@ -93,28 +94,28 @@ class WalletTest (BitcoinTestFramework):
txid = self.nodes[2].sendtoaddress(address, 10, "", "", False)
self.nodes[2].generate(1)
self.sync_all()
assert_equal(self.nodes[2].getbalance(), Decimal('69.99900000'))
assert_equal(self.nodes[2].getbalance(), Decimal('39.99900000'))
assert_equal(self.nodes[0].getbalance(), Decimal('10.00000000'))
# Send 10 BTC with subtract fee from amount
txid = self.nodes[2].sendtoaddress(address, 10, "", "", True)
self.nodes[2].generate(1)
self.sync_all()
assert_equal(self.nodes[2].getbalance(), Decimal('59.99900000'))
assert_equal(self.nodes[2].getbalance(), Decimal('29.99900000'))
assert_equal(self.nodes[0].getbalance(), Decimal('19.99900000'))
# Sendmany 10 BTC
txid = self.nodes[2].sendmany('from1', {address: 10}, 0, "", [])
self.nodes[2].generate(1)
self.sync_all()
assert_equal(self.nodes[2].getbalance(), Decimal('49.99800000'))
assert_equal(self.nodes[2].getbalance(), Decimal('19.99800000'))
assert_equal(self.nodes[0].getbalance(), Decimal('29.99900000'))
# Sendmany 10 BTC with subtract fee from amount
txid = self.nodes[2].sendmany('from1', {address: 10}, 0, "", [address])
self.nodes[2].generate(1)
self.sync_all()
assert_equal(self.nodes[2].getbalance(), Decimal('39.99800000'))
assert_equal(self.nodes[2].getbalance(), Decimal('9.99800000'))
assert_equal(self.nodes[0].getbalance(), Decimal('39.99800000'))
# Test ResendWalletTransactions:
@ -142,7 +143,7 @@ class WalletTest (BitcoinTestFramework):
#4. check if recipient (node0) can list the zero value tx
usp = self.nodes[1].listunspent()
inputs = [{"txid":usp[0]['txid'], "vout":usp[0]['vout']}]
outputs = {self.nodes[1].getnewaddress(): 39.998, self.nodes[0].getnewaddress(): 11.11}
outputs = {self.nodes[1].getnewaddress(): 9.998, self.nodes[0].getnewaddress(): 11.11}
rawTx = self.nodes[1].createrawtransaction(inputs, outputs).replace("c0833842", "00000000") #replace 11.11 with 0.0 (int32)
decRawTx = self.nodes[1].decoderawtransaction(rawTx)
@ -176,14 +177,14 @@ class WalletTest (BitcoinTestFramework):
txObjNotBroadcasted = self.nodes[0].gettransaction(txIdNotBroadcasted)
self.nodes[1].generate(1) #mine a block, tx should not be in there
self.sync_all()
assert_equal(self.nodes[2].getbalance(), Decimal('39.99800000')); #should not be changed because tx was not broadcasted
assert_equal(self.nodes[2].getbalance(), Decimal('9.99800000')); #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(txObjNotBroadcasted['hex'])
self.nodes[1].generate(1)
self.sync_all()
txObjNotBroadcasted = self.nodes[0].gettransaction(txIdNotBroadcasted)
assert_equal(self.nodes[2].getbalance(), Decimal('41.99800000')); #should not be
assert_equal(self.nodes[2].getbalance(), Decimal('11.99800000')); #should not be
#create another tx
txIdNotBroadcasted = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 2);
@ -201,7 +202,7 @@ class WalletTest (BitcoinTestFramework):
sync_blocks(self.nodes)
#tx should be added to balance because after restarting the nodes tx should be broadcastet
assert_equal(self.nodes[2].getbalance(), Decimal('43.99800000')); #should not be
assert_equal(self.nodes[2].getbalance(), Decimal('13.99800000')); #should not be
if __name__ == '__main__':
WalletTest ().main ()

10
qa/rpc-tests/walletbackup.py

@ -110,9 +110,9 @@ class WalletBackupTest(BitcoinTestFramework):
self.nodes[3].generate(100)
sync_blocks(self.nodes)
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[0].getbalance(), 10)
assert_equal(self.nodes[1].getbalance(), 10)
assert_equal(self.nodes[2].getbalance(), 10)
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 * 40 = 4560.
assert_equal(total, 4560)
# 114 are mature, so the sum of all wallets should be 114 * 10 = 1140.
assert_equal(total, 1140)
##
# Test restoring spender wallets from backups

2
qa/rpc-tests/zapwallettxes.py

@ -23,7 +23,7 @@ class ZapWalletTXesTest (BitcoinTestFramework):
def run_test (self):
print "Mining blocks..."
self.nodes[0].generate(1)
self.nodes[0].generate(4)
self.sync_all()
self.nodes[1].generate(101)
self.sync_all()

Loading…
Cancel
Save