@@ -232,6 +232,8 @@ def run_test(self):
232
232
address3 = "mw4ynwhS7MmrQ27hr82kgqu7zryNDK26JB"
233
233
addressHash3 = "aa9872b5bbcdb511d89e0e11aa27da73fd2c3f50" .decode ("hex" )
234
234
scriptPubKey3 = CScript ([OP_DUP , OP_HASH160 , addressHash3 , OP_EQUALVERIFY , OP_CHECKSIG ])
235
+ address4 = "2N8oFVB2vThAKury4vnLquW2zVjsYjjAkYQ"
236
+ scriptPubKey4 = CScript ([OP_HASH160 , addressHash3 , OP_EQUAL ])
235
237
unspent = self .nodes [2 ].listunspent ()
236
238
237
239
tx = CTransaction ()
@@ -246,36 +248,78 @@ def run_test(self):
246
248
tx2 = CTransaction ()
247
249
tx2 .vin = [CTxIn (COutPoint (int (unspent [1 ]["txid" ], 16 ), unspent [1 ]["vout" ]))]
248
250
amount = unspent [1 ]["amount" ] * 100000000
249
- tx2 .vout = [CTxOut (amount , scriptPubKey3 )]
251
+ tx2 .vout = [
252
+ CTxOut (amount / 4 , scriptPubKey3 ),
253
+ CTxOut (amount / 4 , scriptPubKey3 ),
254
+ CTxOut (amount / 4 , scriptPubKey4 ),
255
+ CTxOut (amount / 4 , scriptPubKey4 )
256
+ ]
250
257
tx2 .rehash ()
251
258
signed_tx2 = self .nodes [2 ].signrawtransaction (binascii .hexlify (tx2 .serialize ()).decode ("utf-8" ))
252
259
memtxid2 = self .nodes [2 ].sendrawtransaction (signed_tx2 ["hex" ], True )
253
260
time .sleep (2 )
254
261
255
262
mempool = self .nodes [2 ].getaddressmempool ({"addresses" : [address3 ]})
256
- assert_equal (len (mempool ), 2 )
263
+ assert_equal (len (mempool ), 3 )
257
264
assert_equal (mempool [0 ]["txid" ], memtxid1 )
258
- assert_equal (mempool [1 ]["txid" ], memtxid2 )
259
265
assert_equal (mempool [0 ]["address" ], address3 )
266
+ assert_equal (mempool [0 ]["index" ], 0 )
267
+ assert_equal (mempool [1 ]["txid" ], memtxid2 )
268
+ assert_equal (mempool [1 ]["index" ], 0 )
269
+ assert_equal (mempool [2 ]["txid" ], memtxid2 )
270
+ assert_equal (mempool [2 ]["index" ], 1 )
260
271
261
272
self .nodes [2 ].generate (1 );
262
273
self .sync_all ();
263
274
mempool2 = self .nodes [2 ].getaddressmempool ({"addresses" : [address3 ]})
264
275
assert_equal (len (mempool2 ), 0 )
265
276
266
277
tx = CTransaction ()
267
- tx .vin = [CTxIn (COutPoint (int (memtxid2 , 16 ), 0 ))]
268
- tx .vout = [CTxOut (amount - 10000 , scriptPubKey2 )]
278
+ tx .vin = [
279
+ CTxIn (COutPoint (int (memtxid2 , 16 ), 0 )),
280
+ CTxIn (COutPoint (int (memtxid2 , 16 ), 1 ))
281
+ ]
282
+ tx .vout = [CTxOut (amount / 2 - 10000 , scriptPubKey2 )]
269
283
tx .rehash ()
270
284
self .nodes [2 ].importprivkey (privKey3 )
271
285
signed_tx3 = self .nodes [2 ].signrawtransaction (binascii .hexlify (tx .serialize ()).decode ("utf-8" ))
272
286
memtxid3 = self .nodes [2 ].sendrawtransaction (signed_tx3 ["hex" ], True )
273
287
time .sleep (2 )
274
288
275
289
mempool3 = self .nodes [2 ].getaddressmempool ({"addresses" : [address3 ]})
276
- assert_equal (len (mempool3 ), 1 )
290
+ assert_equal (len (mempool3 ), 2 )
277
291
assert_equal (mempool3 [0 ]["prevtxid" ], memtxid2 )
278
292
assert_equal (mempool3 [0 ]["prevout" ], 0 )
293
+ assert_equal (mempool3 [1 ]["prevtxid" ], memtxid2 )
294
+ assert_equal (mempool3 [1 ]["prevout" ], 1 )
295
+
296
+ # sending and receiving to the same address
297
+ privkey1 = "cQY2s58LhzUCmEXN8jtAp1Etnijx78YRZ466w4ikX1V4UpTpbsf8"
298
+ address1 = "myAUWSHnwsQrhuMWv4Br6QsCnpB41vFwHn"
299
+ address1hash = "c192bff751af8efec15135d42bfeedf91a6f3e34" .decode ("hex" )
300
+ address1script = CScript ([OP_DUP , OP_HASH160 , address1hash , OP_EQUALVERIFY , OP_CHECKSIG ])
301
+
302
+ self .nodes [0 ].sendtoaddress (address1 , 10 )
303
+ self .nodes [0 ].generate (1 )
304
+ self .sync_all ()
305
+
306
+ utxos = self .nodes [1 ].getaddressutxos ({"addresses" : [address1 ]})
307
+ assert_equal (len (utxos ), 1 )
308
+
309
+ tx = CTransaction ()
310
+ tx .vin = [
311
+ CTxIn (COutPoint (int (utxos [0 ]["txid" ], 16 ), utxos [0 ]["outputIndex" ]))
312
+ ]
313
+ amount = utxos [0 ]["satoshis" ] - 1000
314
+ tx .vout = [CTxOut (amount , address1script )]
315
+ tx .rehash ()
316
+ self .nodes [0 ].importprivkey (privkey1 )
317
+ signed_tx = self .nodes [0 ].signrawtransaction (binascii .hexlify (tx .serialize ()).decode ("utf-8" ))
318
+ mem_txid = self .nodes [0 ].sendrawtransaction (signed_tx ["hex" ], True )
319
+
320
+ self .sync_all ()
321
+ mempool_deltas = self .nodes [2 ].getaddressmempool ({"addresses" : [address1 ]})
322
+ assert_equal (len (mempool_deltas ), 2 )
279
323
280
324
print "Passed\n "
281
325
0 commit comments