2014-11-26 21:01:25 -08:00
|
|
|
#!/usr/bin/env python2
|
2014-11-19 12:55:40 -08:00
|
|
|
# Copyright (c) 2014 The Bitcoin Core developers
|
2014-12-12 20:09:33 -08:00
|
|
|
# Distributed under the MIT software license, see the accompanying
|
2014-11-19 12:55:40 -08:00
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
|
2015-05-02 03:53:35 -07:00
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
|
|
from test_framework.util import *
|
2016-09-20 16:22:30 -07:00
|
|
|
from time import *
|
2014-11-19 12:55:40 -08:00
|
|
|
|
|
|
|
class WalletTest (BitcoinTestFramework):
|
|
|
|
|
|
|
|
def setup_chain(self):
|
|
|
|
print("Initializing test directory "+self.options.tmpdir)
|
2015-03-23 10:47:18 -07:00
|
|
|
initialize_chain_clean(self.options.tmpdir, 4)
|
2014-11-19 12:55:40 -08:00
|
|
|
|
|
|
|
def setup_network(self, split=False):
|
|
|
|
self.nodes = start_nodes(3, self.options.tmpdir)
|
|
|
|
connect_nodes_bi(self.nodes,0,1)
|
|
|
|
connect_nodes_bi(self.nodes,1,2)
|
|
|
|
connect_nodes_bi(self.nodes,0,2)
|
|
|
|
self.is_network_split=False
|
|
|
|
self.sync_all()
|
|
|
|
|
|
|
|
def run_test (self):
|
|
|
|
print "Mining blocks..."
|
|
|
|
|
2016-06-07 02:01:33 -07:00
|
|
|
self.nodes[0].generate(4)
|
2014-11-19 12:55:40 -08:00
|
|
|
|
2014-12-24 23:57:16 -08:00
|
|
|
walletinfo = self.nodes[0].getwalletinfo()
|
2016-04-08 16:27:27 -07:00
|
|
|
assert_equal(walletinfo['immature_balance'], 40)
|
2014-12-24 23:57:16 -08:00
|
|
|
assert_equal(walletinfo['balance'], 0)
|
|
|
|
|
2014-11-19 12:55:40 -08:00
|
|
|
self.sync_all()
|
2015-03-31 20:28:28 -07:00
|
|
|
self.nodes[1].generate(101)
|
2014-11-19 12:55:40 -08:00
|
|
|
self.sync_all()
|
|
|
|
|
2016-04-08 16:27:27 -07:00
|
|
|
assert_equal(self.nodes[0].getbalance(), 40)
|
2016-06-07 02:01:33 -07:00
|
|
|
assert_equal(self.nodes[1].getbalance(), 10)
|
2014-11-19 12:55:40 -08:00
|
|
|
assert_equal(self.nodes[2].getbalance(), 0)
|
2016-09-20 16:22:30 -07:00
|
|
|
assert_equal(self.nodes[0].getbalance("*"), 40)
|
|
|
|
assert_equal(self.nodes[1].getbalance("*"), 10)
|
|
|
|
assert_equal(self.nodes[2].getbalance("*"), 0)
|
2014-11-19 12:55:40 -08:00
|
|
|
|
|
|
|
# Send 21 BTC from 0 to 2 using sendtoaddress call.
|
|
|
|
# Second transaction will be child of first, and will require a fee
|
|
|
|
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11)
|
|
|
|
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10)
|
|
|
|
|
2014-12-24 23:57:16 -08:00
|
|
|
walletinfo = self.nodes[0].getwalletinfo()
|
|
|
|
assert_equal(walletinfo['immature_balance'], 0)
|
|
|
|
|
2015-04-28 07:48:28 -07:00
|
|
|
# Have node0 mine a block, thus it will collect its own fee.
|
2016-10-21 16:37:14 -07:00
|
|
|
self.sync_all()
|
2015-03-31 20:28:28 -07:00
|
|
|
self.nodes[0].generate(1)
|
2014-11-19 12:55:40 -08:00
|
|
|
self.sync_all()
|
|
|
|
|
|
|
|
# Have node1 generate 100 blocks (so node0 can recover the fee)
|
2015-03-31 20:28:28 -07:00
|
|
|
self.nodes[1].generate(100)
|
2014-11-19 12:55:40 -08:00
|
|
|
self.sync_all()
|
|
|
|
|
2016-06-07 02:01:33 -07:00
|
|
|
# node0 should end up with 50 btc in block rewards plus fees, but
|
2014-11-19 12:55:40 -08:00
|
|
|
# minus the 21 plus fees sent to node2
|
2016-06-07 02:01:33 -07:00
|
|
|
assert_equal(self.nodes[0].getbalance(), 50-21)
|
2014-11-19 12:55:40 -08:00
|
|
|
assert_equal(self.nodes[2].getbalance(), 21)
|
2016-09-20 16:22:30 -07:00
|
|
|
assert_equal(self.nodes[0].getbalance("*"), 50-21)
|
|
|
|
assert_equal(self.nodes[2].getbalance("*"), 21)
|
2014-11-19 12:55:40 -08:00
|
|
|
|
2016-06-07 02:01:33 -07:00
|
|
|
# Node0 should have three unspent outputs.
|
2015-07-14 12:13:16 -07:00
|
|
|
# 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:
|
2014-11-19 12:55:40 -08:00
|
|
|
node0utxos = self.nodes[0].listunspent(1)
|
2016-06-07 02:01:33 -07:00
|
|
|
assert_equal(len(node0utxos), 3)
|
2014-11-19 12:55:40 -08:00
|
|
|
|
|
|
|
# create both transactions
|
|
|
|
txns_to_send = []
|
2015-07-14 12:13:16 -07:00
|
|
|
for utxo in node0utxos:
|
2014-11-19 12:55:40 -08:00
|
|
|
inputs = []
|
|
|
|
outputs = {}
|
|
|
|
inputs.append({ "txid" : utxo["txid"], "vout" : utxo["vout"]})
|
2016-10-10 12:26:52 -07:00
|
|
|
outputs[self.nodes[2].getnewaddress("")] = utxo["amount"]
|
2014-11-19 12:55:40 -08:00
|
|
|
raw_tx = self.nodes[0].createrawtransaction(inputs, outputs)
|
|
|
|
txns_to_send.append(self.nodes[0].signrawtransaction(raw_tx))
|
|
|
|
|
|
|
|
# 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)
|
2016-06-07 02:01:33 -07:00
|
|
|
self.nodes[1].sendrawtransaction(txns_to_send[2]["hex"], True)
|
2014-11-19 12:55:40 -08:00
|
|
|
|
|
|
|
# Have node1 mine a block to confirm transactions:
|
2016-10-21 16:37:14 -07:00
|
|
|
self.sync_all()
|
2015-03-31 20:28:28 -07:00
|
|
|
self.nodes[1].generate(1)
|
2014-11-19 12:55:40 -08:00
|
|
|
self.sync_all()
|
|
|
|
|
|
|
|
assert_equal(self.nodes[0].getbalance(), 0)
|
2016-06-07 02:01:33 -07:00
|
|
|
assert_equal(self.nodes[2].getbalance(), 50)
|
2016-09-20 16:22:30 -07:00
|
|
|
assert_equal(self.nodes[0].getbalance("*"), 0)
|
|
|
|
assert_equal(self.nodes[2].getbalance("*"), 50)
|
2014-11-19 12:55:40 -08:00
|
|
|
|
2015-03-05 05:59:19 -08:00
|
|
|
# Send 10 BTC normal
|
2016-10-10 12:26:52 -07:00
|
|
|
address = self.nodes[0].getnewaddress("")
|
2014-07-23 05:34:36 -07:00
|
|
|
self.nodes[2].settxfee(Decimal('0.001'))
|
|
|
|
txid = self.nodes[2].sendtoaddress(address, 10, "", "", False)
|
2016-10-21 16:37:14 -07:00
|
|
|
self.sync_all()
|
2015-03-31 20:28:28 -07:00
|
|
|
self.nodes[2].generate(1)
|
2014-07-23 05:34:36 -07:00
|
|
|
self.sync_all()
|
2016-06-07 02:01:33 -07:00
|
|
|
assert_equal(self.nodes[2].getbalance(), Decimal('39.99900000'))
|
2014-07-23 05:34:36 -07:00
|
|
|
assert_equal(self.nodes[0].getbalance(), Decimal('10.00000000'))
|
2016-09-20 16:22:30 -07:00
|
|
|
assert_equal(self.nodes[2].getbalance("*"), Decimal('39.99900000'))
|
|
|
|
assert_equal(self.nodes[0].getbalance("*"), Decimal('10.00000000'))
|
2014-07-23 05:34:36 -07:00
|
|
|
|
2015-03-05 05:59:19 -08:00
|
|
|
# Send 10 BTC with subtract fee from amount
|
2014-07-23 05:34:36 -07:00
|
|
|
txid = self.nodes[2].sendtoaddress(address, 10, "", "", True)
|
2016-10-21 16:37:14 -07:00
|
|
|
self.sync_all()
|
2015-03-31 20:28:28 -07:00
|
|
|
self.nodes[2].generate(1)
|
2014-07-23 05:34:36 -07:00
|
|
|
self.sync_all()
|
2016-06-07 02:01:33 -07:00
|
|
|
assert_equal(self.nodes[2].getbalance(), Decimal('29.99900000'))
|
2014-07-23 05:34:36 -07:00
|
|
|
assert_equal(self.nodes[0].getbalance(), Decimal('19.99900000'))
|
2016-09-20 16:22:30 -07:00
|
|
|
assert_equal(self.nodes[2].getbalance("*"), Decimal('29.99900000'))
|
|
|
|
assert_equal(self.nodes[0].getbalance("*"), Decimal('19.99900000'))
|
2014-11-19 12:55:40 -08:00
|
|
|
|
2015-03-05 05:59:19 -08:00
|
|
|
# Sendmany 10 BTC
|
2016-10-10 12:26:52 -07:00
|
|
|
txid = self.nodes[2].sendmany("", {address: 10}, 0, "", [])
|
2016-10-21 16:37:14 -07:00
|
|
|
self.sync_all()
|
2015-03-31 20:28:28 -07:00
|
|
|
self.nodes[2].generate(1)
|
2015-03-05 05:59:19 -08:00
|
|
|
self.sync_all()
|
2016-06-07 02:01:33 -07:00
|
|
|
assert_equal(self.nodes[2].getbalance(), Decimal('19.99800000'))
|
2015-03-05 05:59:19 -08:00
|
|
|
assert_equal(self.nodes[0].getbalance(), Decimal('29.99900000'))
|
2016-09-20 16:22:30 -07:00
|
|
|
assert_equal(self.nodes[2].getbalance("*"), Decimal('19.99800000'))
|
|
|
|
assert_equal(self.nodes[0].getbalance("*"), Decimal('29.99900000'))
|
2015-03-05 05:59:19 -08:00
|
|
|
|
|
|
|
# Sendmany 10 BTC with subtract fee from amount
|
2016-10-10 12:26:52 -07:00
|
|
|
txid = self.nodes[2].sendmany("", {address: 10}, 0, "", [address])
|
2016-10-21 16:37:14 -07:00
|
|
|
self.sync_all()
|
2015-03-31 20:28:28 -07:00
|
|
|
self.nodes[2].generate(1)
|
2015-03-05 05:59:19 -08:00
|
|
|
self.sync_all()
|
2016-06-07 02:01:33 -07:00
|
|
|
assert_equal(self.nodes[2].getbalance(), Decimal('9.99800000'))
|
2015-03-05 05:59:19 -08:00
|
|
|
assert_equal(self.nodes[0].getbalance(), Decimal('39.99800000'))
|
2016-09-20 16:22:30 -07:00
|
|
|
assert_equal(self.nodes[2].getbalance("*"), Decimal('9.99800000'))
|
|
|
|
assert_equal(self.nodes[0].getbalance("*"), Decimal('39.99800000'))
|
2015-03-05 05:59:19 -08:00
|
|
|
|
2015-03-23 10:47:18 -07:00
|
|
|
# Test ResendWalletTransactions:
|
|
|
|
# Create a couple of transactions, then start up a fourth
|
|
|
|
# node (nodes[3]) and ask nodes[0] to rebroadcast.
|
|
|
|
# EXPECT: nodes[3] should have those transactions in its mempool.
|
|
|
|
txid1 = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1)
|
|
|
|
txid2 = self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 1)
|
|
|
|
sync_mempools(self.nodes)
|
|
|
|
|
|
|
|
self.nodes.append(start_node(3, self.options.tmpdir))
|
|
|
|
connect_nodes_bi(self.nodes, 0, 3)
|
|
|
|
sync_blocks(self.nodes)
|
|
|
|
|
|
|
|
relayed = self.nodes[0].resendwallettransactions()
|
|
|
|
assert_equal(set(relayed), set([txid1, txid2]))
|
|
|
|
sync_mempools(self.nodes)
|
|
|
|
|
|
|
|
assert(txid1 in self.nodes[3].getrawmempool())
|
2016-10-10 12:27:16 -07:00
|
|
|
|
2015-04-21 01:27:35 -07:00
|
|
|
#check if we can list zero value tx as available coins
|
|
|
|
#1. create rawtx
|
2015-07-14 12:13:16 -07:00
|
|
|
#2. hex-changed one output to 0.0
|
2015-04-21 01:27:35 -07:00
|
|
|
#3. sign and send
|
|
|
|
#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']}]
|
2016-06-07 02:01:33 -07:00
|
|
|
outputs = {self.nodes[1].getnewaddress(): 9.998, self.nodes[0].getnewaddress(): 11.11}
|
2016-10-10 12:27:16 -07:00
|
|
|
|
2015-04-21 01:27:35 -07:00
|
|
|
rawTx = self.nodes[1].createrawtransaction(inputs, outputs).replace("c0833842", "00000000") #replace 11.11 with 0.0 (int32)
|
|
|
|
decRawTx = self.nodes[1].decoderawtransaction(rawTx)
|
|
|
|
signedRawTx = self.nodes[1].signrawtransaction(rawTx)
|
|
|
|
decRawTx = self.nodes[1].decoderawtransaction(signedRawTx['hex'])
|
|
|
|
zeroValueTxid= decRawTx['txid']
|
|
|
|
sendResp = self.nodes[1].sendrawtransaction(signedRawTx['hex'])
|
2016-10-10 12:27:16 -07:00
|
|
|
|
2015-04-21 01:27:35 -07:00
|
|
|
self.sync_all()
|
|
|
|
self.nodes[1].generate(1) #mine a block
|
|
|
|
self.sync_all()
|
2016-10-10 12:27:16 -07:00
|
|
|
|
2015-04-21 01:27:35 -07:00
|
|
|
unspentTxs = self.nodes[0].listunspent() #zero value tx must be in listunspents output
|
|
|
|
found = False
|
|
|
|
for uTx in unspentTxs:
|
|
|
|
if uTx['txid'] == zeroValueTxid:
|
|
|
|
found = True
|
|
|
|
assert_equal(uTx['amount'], Decimal('0.00000000'));
|
|
|
|
assert(found)
|
2016-10-10 12:27:16 -07:00
|
|
|
|
2015-04-01 02:56:52 -07:00
|
|
|
#do some -walletbroadcast tests
|
|
|
|
stop_nodes(self.nodes)
|
|
|
|
wait_bitcoinds()
|
|
|
|
self.nodes = start_nodes(3, self.options.tmpdir, [["-walletbroadcast=0"],["-walletbroadcast=0"],["-walletbroadcast=0"]])
|
|
|
|
connect_nodes_bi(self.nodes,0,1)
|
|
|
|
connect_nodes_bi(self.nodes,1,2)
|
|
|
|
connect_nodes_bi(self.nodes,0,2)
|
|
|
|
self.sync_all()
|
2015-03-23 10:47:18 -07:00
|
|
|
|
2015-04-01 02:56:52 -07:00
|
|
|
txIdNotBroadcasted = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 2);
|
|
|
|
txObjNotBroadcasted = self.nodes[0].gettransaction(txIdNotBroadcasted)
|
2016-10-21 16:37:14 -07:00
|
|
|
self.sync_all()
|
2015-04-09 08:36:10 -07:00
|
|
|
self.nodes[1].generate(1) #mine a block, tx should not be in there
|
2015-04-01 02:56:52 -07:00
|
|
|
self.sync_all()
|
2016-06-07 02:01:33 -07:00
|
|
|
assert_equal(self.nodes[2].getbalance(), Decimal('9.99800000')); #should not be changed because tx was not broadcasted
|
2016-09-20 16:22:30 -07:00
|
|
|
assert_equal(self.nodes[2].getbalance("*"), Decimal('9.99800000')); #should not be changed because tx was not broadcasted
|
|
|
|
|
2015-04-01 02:56:52 -07:00
|
|
|
#now broadcast from another node, mine a block, sync, and check the balance
|
|
|
|
self.nodes[1].sendrawtransaction(txObjNotBroadcasted['hex'])
|
2016-10-21 16:37:14 -07:00
|
|
|
self.sync_all()
|
2015-04-09 08:36:10 -07:00
|
|
|
self.nodes[1].generate(1)
|
2015-04-01 02:56:52 -07:00
|
|
|
self.sync_all()
|
|
|
|
txObjNotBroadcasted = self.nodes[0].gettransaction(txIdNotBroadcasted)
|
2016-06-07 02:01:33 -07:00
|
|
|
assert_equal(self.nodes[2].getbalance(), Decimal('11.99800000')); #should not be
|
2016-09-20 16:22:30 -07:00
|
|
|
assert_equal(self.nodes[2].getbalance("*"), Decimal('11.99800000')); #should not be
|
2016-10-10 12:27:16 -07:00
|
|
|
|
2015-04-01 02:56:52 -07:00
|
|
|
#create another tx
|
|
|
|
txIdNotBroadcasted = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 2);
|
2016-10-10 12:27:16 -07:00
|
|
|
|
2015-04-01 02:56:52 -07:00
|
|
|
#restart the nodes with -walletbroadcast=1
|
|
|
|
stop_nodes(self.nodes)
|
|
|
|
wait_bitcoinds()
|
|
|
|
self.nodes = start_nodes(3, self.options.tmpdir)
|
|
|
|
connect_nodes_bi(self.nodes,0,1)
|
|
|
|
connect_nodes_bi(self.nodes,1,2)
|
|
|
|
connect_nodes_bi(self.nodes,0,2)
|
|
|
|
sync_blocks(self.nodes)
|
2016-10-10 12:27:16 -07:00
|
|
|
|
2015-04-09 08:36:10 -07:00
|
|
|
self.nodes[0].generate(1)
|
2015-04-01 02:56:52 -07:00
|
|
|
sync_blocks(self.nodes)
|
2016-10-10 12:27:16 -07:00
|
|
|
|
2015-04-01 02:56:52 -07:00
|
|
|
#tx should be added to balance because after restarting the nodes tx should be broadcastet
|
2016-06-07 02:01:33 -07:00
|
|
|
assert_equal(self.nodes[2].getbalance(), Decimal('13.99800000')); #should not be
|
2016-09-20 16:22:30 -07:00
|
|
|
assert_equal(self.nodes[2].getbalance("*"), Decimal('13.99800000')); #should not be
|
|
|
|
|
|
|
|
# send from node 0 to node 2 taddr
|
|
|
|
mytaddr = self.nodes[2].getnewaddress();
|
2016-10-06 18:55:14 -07:00
|
|
|
mytxid = self.nodes[0].sendtoaddress(mytaddr, 10.0);
|
2016-10-21 16:37:14 -07:00
|
|
|
self.sync_all()
|
2016-09-20 16:22:30 -07:00
|
|
|
self.nodes[0].generate(1)
|
|
|
|
self.sync_all()
|
|
|
|
|
|
|
|
mybalance = self.nodes[2].z_getbalance(mytaddr)
|
|
|
|
assert_equal(self.nodes[2].z_getbalance(mytaddr), Decimal('10.0'));
|
|
|
|
|
2016-10-06 18:55:14 -07:00
|
|
|
mytxdetails = self.nodes[2].gettransaction(mytxid)
|
|
|
|
myvjoinsplits = mytxdetails["vjoinsplit"]
|
|
|
|
assert_equal(0, len(myvjoinsplits))
|
|
|
|
|
2016-11-06 13:08:07 -08:00
|
|
|
# z_sendmany is expected to fail if tx size breaks limit
|
|
|
|
myzaddr = self.nodes[0].z_getnewaddress()
|
|
|
|
|
|
|
|
recipients = []
|
|
|
|
num_t_recipients = 3000
|
|
|
|
amount_per_recipient = Decimal('0.00000001')
|
|
|
|
errorString = ''
|
|
|
|
for i in xrange(0,num_t_recipients):
|
|
|
|
newtaddr = self.nodes[2].getnewaddress()
|
|
|
|
recipients.append({"address":newtaddr, "amount":amount_per_recipient})
|
|
|
|
try:
|
|
|
|
self.nodes[0].z_sendmany(myzaddr, recipients)
|
|
|
|
except JSONRPCException,e:
|
|
|
|
errorString = e.error['message']
|
|
|
|
assert("Too many outputs, size of raw transaction" in errorString)
|
|
|
|
|
|
|
|
recipients = []
|
|
|
|
num_t_recipients = 2000
|
|
|
|
num_z_recipients = 50
|
|
|
|
amount_per_recipient = Decimal('0.00000001')
|
|
|
|
errorString = ''
|
|
|
|
for i in xrange(0,num_t_recipients):
|
|
|
|
newtaddr = self.nodes[2].getnewaddress()
|
|
|
|
recipients.append({"address":newtaddr, "amount":amount_per_recipient})
|
|
|
|
for i in xrange(0,num_z_recipients):
|
|
|
|
newzaddr = self.nodes[2].z_getnewaddress()
|
|
|
|
recipients.append({"address":newzaddr, "amount":amount_per_recipient})
|
|
|
|
try:
|
|
|
|
self.nodes[0].z_sendmany(myzaddr, recipients)
|
|
|
|
except JSONRPCException,e:
|
|
|
|
errorString = e.error['message']
|
|
|
|
assert("size of raw transaction would be larger than limit" in errorString)
|
|
|
|
|
|
|
|
recipients = []
|
|
|
|
num_z_recipients = 100
|
|
|
|
amount_per_recipient = Decimal('0.00000001')
|
|
|
|
errorString = ''
|
|
|
|
for i in xrange(0,num_z_recipients):
|
|
|
|
newzaddr = self.nodes[2].z_getnewaddress()
|
|
|
|
recipients.append({"address":newzaddr, "amount":amount_per_recipient})
|
|
|
|
try:
|
|
|
|
self.nodes[0].z_sendmany(myzaddr, recipients)
|
|
|
|
except JSONRPCException,e:
|
|
|
|
errorString = e.error['message']
|
|
|
|
assert("Invalid parameter, too many zaddr outputs" in errorString)
|
|
|
|
|
2016-09-20 16:22:30 -07:00
|
|
|
# add zaddr to node 2
|
2016-10-04 11:05:57 -07:00
|
|
|
myzaddr = self.nodes[2].z_getnewaddress()
|
2016-09-20 16:22:30 -07:00
|
|
|
|
|
|
|
# send node 2 taddr to zaddr
|
|
|
|
recipients = []
|
2016-10-20 17:10:25 -07:00
|
|
|
recipients.append({"address":myzaddr, "amount":7})
|
2016-09-20 16:22:30 -07:00
|
|
|
myopid = self.nodes[2].z_sendmany(mytaddr, recipients)
|
|
|
|
|
|
|
|
opids = []
|
|
|
|
opids.append(myopid)
|
|
|
|
|
2017-01-18 16:54:39 -08:00
|
|
|
timeout = 300
|
2016-09-20 16:22:30 -07:00
|
|
|
status = None
|
|
|
|
for x in xrange(1, timeout):
|
|
|
|
results = self.nodes[2].z_getoperationresult(opids)
|
|
|
|
if len(results)==0:
|
|
|
|
sleep(1)
|
|
|
|
else:
|
|
|
|
status = results[0]["status"]
|
2016-10-06 18:55:14 -07:00
|
|
|
mytxid = results[0]["result"]["txid"]
|
2016-09-20 16:22:30 -07:00
|
|
|
break
|
|
|
|
|
|
|
|
assert_equal("success", status)
|
2016-10-21 16:37:14 -07:00
|
|
|
self.sync_all()
|
2016-09-20 16:22:30 -07:00
|
|
|
self.nodes[2].generate(1)
|
|
|
|
self.sync_all()
|
|
|
|
|
|
|
|
# check balances
|
|
|
|
zsendmanynotevalue = Decimal('7.0')
|
|
|
|
zsendmanyfee = Decimal('0.0001')
|
|
|
|
node2utxobalance = Decimal('23.998') - zsendmanynotevalue - zsendmanyfee
|
|
|
|
|
|
|
|
assert_equal(self.nodes[2].getbalance(), node2utxobalance)
|
|
|
|
assert_equal(self.nodes[2].getbalance("*"), node2utxobalance)
|
|
|
|
|
|
|
|
# check zaddr balance
|
|
|
|
assert_equal(self.nodes[2].z_getbalance(myzaddr), zsendmanynotevalue);
|
|
|
|
|
|
|
|
# check via z_gettotalbalance
|
|
|
|
resp = self.nodes[2].z_gettotalbalance()
|
|
|
|
assert_equal(Decimal(resp["transparent"]), node2utxobalance)
|
|
|
|
assert_equal(Decimal(resp["private"]), zsendmanynotevalue)
|
|
|
|
assert_equal(Decimal(resp["total"]), node2utxobalance + zsendmanynotevalue)
|
|
|
|
|
2016-10-06 18:55:14 -07:00
|
|
|
# there should be at least one joinsplit
|
|
|
|
mytxdetails = self.nodes[2].gettransaction(mytxid)
|
|
|
|
myvjoinsplits = mytxdetails["vjoinsplit"]
|
|
|
|
assert_greater_than(len(myvjoinsplits), 0)
|
2016-09-20 16:22:30 -07:00
|
|
|
|
2017-02-09 08:38:01 -08:00
|
|
|
# the first (probably only) joinsplit should take in all the public value
|
|
|
|
myjoinsplit = self.nodes[2].getrawtransaction(mytxid, 1)["vjoinsplit"][0]
|
|
|
|
assert_equal(myjoinsplit["vpub_old"], zsendmanynotevalue)
|
|
|
|
assert_equal(myjoinsplit["vpub_new"], 0)
|
2017-02-09 14:48:58 -08:00
|
|
|
assert("onetimePubKey" in myjoinsplit.keys())
|
|
|
|
assert("randomSeed" in myjoinsplit.keys())
|
|
|
|
assert("ciphertexts" in myjoinsplit.keys())
|
|
|
|
|
2017-02-09 08:38:01 -08:00
|
|
|
|
2016-09-20 16:22:30 -07:00
|
|
|
# send from private note to node 0 and node 2
|
|
|
|
node0balance = self.nodes[0].getbalance() # 25.99794745
|
|
|
|
node2balance = self.nodes[2].getbalance() # 16.99790000
|
|
|
|
|
|
|
|
recipients = []
|
2016-10-20 17:10:25 -07:00
|
|
|
recipients.append({"address":self.nodes[0].getnewaddress(), "amount":1})
|
2016-09-20 16:22:30 -07:00
|
|
|
recipients.append({"address":self.nodes[2].getnewaddress(), "amount":1.0})
|
|
|
|
myopid = self.nodes[2].z_sendmany(myzaddr, recipients)
|
|
|
|
|
|
|
|
status = None
|
|
|
|
opids = []
|
|
|
|
opids.append(myopid)
|
|
|
|
for x in xrange(1, timeout):
|
|
|
|
results = self.nodes[2].z_getoperationresult(opids)
|
|
|
|
if len(results)==0:
|
|
|
|
sleep(1)
|
|
|
|
else:
|
|
|
|
status = results[0]["status"]
|
|
|
|
break
|
|
|
|
|
|
|
|
assert_equal("success", status)
|
2016-10-21 16:37:14 -07:00
|
|
|
self.sync_all()
|
2016-09-20 16:22:30 -07:00
|
|
|
self.nodes[2].generate(1)
|
|
|
|
self.sync_all()
|
|
|
|
|
|
|
|
node0balance += Decimal('1.0')
|
|
|
|
node2balance += Decimal('1.0')
|
|
|
|
assert_equal(Decimal(self.nodes[0].getbalance()), node0balance)
|
|
|
|
assert_equal(Decimal(self.nodes[0].getbalance("*")), node0balance)
|
|
|
|
assert_equal(Decimal(self.nodes[2].getbalance()), node2balance)
|
|
|
|
assert_equal(Decimal(self.nodes[2].getbalance("*")), node2balance)
|
|
|
|
|
2015-07-14 12:13:16 -07:00
|
|
|
#send a tx with value in a string (PR#6380 +)
|
|
|
|
txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "2")
|
|
|
|
txObj = self.nodes[0].gettransaction(txId)
|
|
|
|
assert_equal(txObj['amount'], Decimal('-2.00000000'))
|
|
|
|
|
|
|
|
txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "0.0001")
|
|
|
|
txObj = self.nodes[0].gettransaction(txId)
|
|
|
|
assert_equal(txObj['amount'], Decimal('-0.00010000'))
|
|
|
|
|
|
|
|
#check if JSON parser can handle scientific notation in strings
|
|
|
|
txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "1e-4")
|
|
|
|
txObj = self.nodes[0].gettransaction(txId)
|
|
|
|
assert_equal(txObj['amount'], Decimal('-0.00010000'))
|
|
|
|
|
|
|
|
#this should fail
|
|
|
|
errorString = ""
|
|
|
|
try:
|
|
|
|
txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), "1f-4")
|
|
|
|
except JSONRPCException,e:
|
|
|
|
errorString = e.error['message']
|
|
|
|
|
|
|
|
assert_equal("Invalid amount" in errorString, True);
|
|
|
|
|
|
|
|
errorString = ""
|
|
|
|
try:
|
|
|
|
self.nodes[0].generate("2") #use a string to as block amount parameter must fail because it's not interpreted as amount
|
|
|
|
except JSONRPCException,e:
|
|
|
|
errorString = e.error['message']
|
|
|
|
|
|
|
|
assert_equal("not an integer" in errorString, True);
|
|
|
|
|
|
|
|
|
2014-11-19 12:55:40 -08:00
|
|
|
if __name__ == '__main__':
|
|
|
|
WalletTest ().main ()
|