4
4
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
6
6
#
7
- # Exercise the wallet. Ported from wallet.sh.
7
+ # Exercise the wallet. Ported from wallet.sh.
8
8
# Does the following:
9
9
# a) creates 3 nodes, with an empty chain (no blocks).
10
10
# b) node0 mines a block
11
- # c) node1 mines 101 blocks, so now nodes 0 and 1 have 50btc, node2 has none.
11
+ # c) node1 mines 101 blocks, so now nodes 0 and 1 have 50btc, node2 has none.
12
12
# d) node0 sends 21 btc to node2, in two transactions (11 btc, then 10 btc).
13
13
# e) node0 mines a block, collects the fee on the second transaction
14
14
# f) node1 mines 100 blocks, to mature node0's just-mined block
@@ -75,14 +75,14 @@ def run_test (self):
75
75
assert_equal (self .nodes [2 ].getbalance (), 21 )
76
76
77
77
# Node0 should have two unspent outputs.
78
- # Create a couple of transactions to send them to node2, submit them through
79
- # node1, and make sure both node0 and node2 pick them up properly:
78
+ # Create a couple of transactions to send them to node2, submit them through
79
+ # node1, and make sure both node0 and node2 pick them up properly:
80
80
node0utxos = self .nodes [0 ].listunspent (1 )
81
81
assert_equal (len (node0utxos ), 2 )
82
82
83
83
# create both transactions
84
84
txns_to_send = []
85
- for utxo in node0utxos :
85
+ for utxo in node0utxos :
86
86
inputs = []
87
87
outputs = {}
88
88
inputs .append ({ "txid" : utxo ["txid" ], "vout" : utxo ["vout" ]})
@@ -149,35 +149,35 @@ def run_test (self):
149
149
sync_mempools (self .nodes )
150
150
151
151
assert (txid1 in self .nodes [3 ].getrawmempool ())
152
-
152
+
153
153
#check if we can list zero value tx as available coins
154
154
#1. create rawtx
155
- #2. hex-changed one output to 0.0
155
+ #2. hex-changed one output to 0.0
156
156
#3. sign and send
157
157
#4. check if recipient (node0) can list the zero value tx
158
158
usp = self .nodes [1 ].listunspent ()
159
159
inputs = [{"txid" :usp [0 ]['txid' ], "vout" :usp [0 ]['vout' ]}]
160
160
outputs = {self .nodes [1 ].getnewaddress (): 49.998 , self .nodes [0 ].getnewaddress (): 11.11 }
161
-
161
+
162
162
rawTx = self .nodes [1 ].createrawtransaction (inputs , outputs ).replace ("c0833842" , "00000000" ) #replace 11.11 with 0.0 (int32)
163
163
decRawTx = self .nodes [1 ].decoderawtransaction (rawTx )
164
164
signedRawTx = self .nodes [1 ].signrawtransaction (rawTx )
165
165
decRawTx = self .nodes [1 ].decoderawtransaction (signedRawTx ['hex' ])
166
166
zeroValueTxid = decRawTx ['txid' ]
167
167
sendResp = self .nodes [1 ].sendrawtransaction (signedRawTx ['hex' ])
168
-
168
+
169
169
self .sync_all ()
170
170
self .nodes [1 ].generate (1 ) #mine a block
171
171
self .sync_all ()
172
-
172
+
173
173
unspentTxs = self .nodes [0 ].listunspent () #zero value tx must be in listunspents output
174
174
found = False
175
175
for uTx in unspentTxs :
176
176
if uTx ['txid' ] == zeroValueTxid :
177
177
found = True
178
178
assert_equal (uTx ['amount' ], Decimal ('0.00000000' ));
179
179
assert (found )
180
-
180
+
181
181
#do some -walletbroadcast tests
182
182
stop_nodes (self .nodes )
183
183
wait_bitcoinds ()
@@ -192,17 +192,17 @@ def run_test (self):
192
192
self .nodes [1 ].generate (1 ) #mine a block, tx should not be in there
193
193
self .sync_all ()
194
194
assert_equal (self .nodes [2 ].getbalance (), Decimal ('59.99800000' )); #should not be changed because tx was not broadcasted
195
-
195
+
196
196
#now broadcast from another node, mine a block, sync, and check the balance
197
197
self .nodes [1 ].sendrawtransaction (txObjNotBroadcasted ['hex' ])
198
198
self .nodes [1 ].generate (1 )
199
199
self .sync_all ()
200
200
txObjNotBroadcasted = self .nodes [0 ].gettransaction (txIdNotBroadcasted )
201
201
assert_equal (self .nodes [2 ].getbalance (), Decimal ('61.99800000' )); #should not be
202
-
202
+
203
203
#create another tx
204
204
txIdNotBroadcasted = self .nodes [0 ].sendtoaddress (self .nodes [2 ].getnewaddress (), 2 );
205
-
205
+
206
206
#restart the nodes with -walletbroadcast=1
207
207
stop_nodes (self .nodes )
208
208
wait_bitcoinds ()
@@ -211,12 +211,44 @@ def run_test (self):
211
211
connect_nodes_bi (self .nodes ,1 ,2 )
212
212
connect_nodes_bi (self .nodes ,0 ,2 )
213
213
sync_blocks (self .nodes )
214
-
214
+
215
215
self .nodes [0 ].generate (1 )
216
216
sync_blocks (self .nodes )
217
-
217
+
218
218
#tx should be added to balance because after restarting the nodes tx should be broadcastet
219
219
assert_equal (self .nodes [2 ].getbalance (), Decimal ('63.99800000' )); #should not be
220
-
220
+
221
+ #send a tx with value in a string (PR#6380 +)
222
+ txId = self .nodes [0 ].sendtoaddress (self .nodes [2 ].getnewaddress (), "2" )
223
+ txObj = self .nodes [0 ].gettransaction (txId )
224
+ assert_equal (txObj ['amount' ], Decimal ('-2.00000000' ))
225
+
226
+ txId = self .nodes [0 ].sendtoaddress (self .nodes [2 ].getnewaddress (), "0.0001" )
227
+ txObj = self .nodes [0 ].gettransaction (txId )
228
+ assert_equal (txObj ['amount' ], Decimal ('-0.00010000' ))
229
+
230
+ #check if JSON parser can handle scientific notation in strings
231
+ txId = self .nodes [0 ].sendtoaddress (self .nodes [2 ].getnewaddress (), "1e-4" )
232
+ txObj = self .nodes [0 ].gettransaction (txId )
233
+ assert_equal (txObj ['amount' ], Decimal ('-0.00010000' ))
234
+
235
+ #this should fail
236
+ errorString = ""
237
+ try :
238
+ txId = self .nodes [0 ].sendtoaddress (self .nodes [2 ].getnewaddress (), "1f-4" )
239
+ except JSONRPCException ,e :
240
+ errorString = e .error ['message' ]
241
+
242
+ assert_equal ("Invalid amount" in errorString , True );
243
+
244
+ errorString = ""
245
+ try :
246
+ self .nodes [0 ].generate ("2" ) #use a string to as block amount parameter must fail because it's not interpreted as amount
247
+ except JSONRPCException ,e :
248
+ errorString = e .error ['message' ]
249
+
250
+ assert_equal ("not an integer" in errorString , True );
251
+
252
+
221
253
if __name__ == '__main__' :
222
254
WalletTest ().main ()
0 commit comments