11#!/usr/bin/env python3
2- # Copyright (c) 2015-2018 Daniel Kraft
2+ # Copyright (c) 2015-2019 Daniel Kraft
33# Distributed under the MIT/X11 software license, see the accompanying
44# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
88from test_framework .names import NameTestFramework
99from test_framework .util import *
1010
11- class NameScanningTest (NameTestFramework ):
11+ class NamePendingTest (NameTestFramework ):
1212
1313 def set_test_params (self ):
14- self .setup_name_test ()
14+ self .setup_name_test ([[]] * 2 )
1515
1616 def run_test (self ):
17+ node = self .nodes [0 ]
18+
1719 # Register a name that can then be update'd in the mempool.
18- newData = self . nodes [ 1 ] .name_new ("a" )
19- self .generate (0 , 10 )
20- self .firstupdateName (1 , "a" , newData , "old-value-a" )
21- self .generate (0 , 10 )
20+ newData = node .name_new ("a" )
21+ node .generate (10 )
22+ self .firstupdateName (0 , "a" , newData , "old-value-a" )
23+ node .generate (10 )
2224
2325 # Start a new name registration so we can first_update it.
24- newData = self . nodes [ 2 ] .name_new ("b" )
25- self .generate (0 , 15 )
26+ newData = node .name_new ("b" )
27+ node .generate (15 )
2628
2729 # Perform the unconfirmed updates. Include a currency transaction
2830 # and a name_new to check that those are not shown.
29- txa = self . nodes [ 1 ] .name_update ("a" , "value-a" )
30- txb = self .firstupdateName (2 , "b" , newData , "value-b" )
31- addrC = self .nodes [3 ].getnewaddress ()
32- self . nodes [ 2 ]. sendtoaddress (addrC , 1 )
33- newData = self . nodes [ 3 ] .name_new ("c" )
31+ txa = node .name_update ("a" , "value-a" )
32+ txb = self .firstupdateName (0 , "b" , newData , "value-b" )
33+ addrOther = self .nodes [1 ].getnewaddress ()
34+ node . sendtoaddress (addrOther , 1 )
35+ newData = node .name_new ("c" )
3436
3537 # Check that name_show still returns the old value.
3638 self .checkName (0 , "a" , "old-value-a" , None , False )
3739
3840 # Check sizes of mempool against name_pending.
39- self .sync_with_mode ('mempool' )
40- mempool = self .nodes [0 ].getrawmempool ()
41+ mempool = node .getrawmempool ()
4142 assert_equal (len (mempool ), 4 )
42- pending = self . nodes [ 0 ] .name_pending ()
43+ pending = node .name_pending ()
4344 assert_equal (len (pending ), 2 )
4445
4546 # Check result of full name_pending (called above).
4647 for op in pending :
4748 assert op ['txid' ] in mempool
48- assert not op ['ismine' ]
4949 if op ['name' ] == 'a' :
5050 assert_equal (op ['op' ], 'name_update' )
5151 assert_equal (op ['value' ], 'value-a' )
@@ -58,37 +58,37 @@ def run_test (self):
5858 assert False
5959
6060 # Check name_pending with name filter that does not match any name.
61- pending = self . nodes [ 0 ] .name_pending ('does not exist' )
61+ pending = node .name_pending ('does not exist' )
6262 assert_equal (pending , [])
6363
6464 # Check name_pending with name filter and ismine.
65- self .checkPendingName (1 , 'a' , 'name_update' , 'value-a' , txa , True )
66- self .checkPendingName (2 , 'a' , 'name_update' , 'value-a' , txa , False )
65+ self .checkPendingName (0 , 'a' , 'name_update' , 'value-a' , txa )
6766
6867 # We don't know the golden value for vout, as this is randomised. But we
6968 # can store the output now and then verify it with name_show after the
7069 # update has been mined.
71- pending = self . nodes [ 0 ] .name_pending ('a' )
70+ pending = node .name_pending ('a' )
7271 assert_equal (len (pending ), 1 )
7372 pending = pending [0 ]
7473 assert 'vout' in pending
7574
7675 # Mine a block and check that all mempool is cleared.
77- self .generate (0 , 1 )
78- assert_equal (self . nodes [ 3 ] .getrawmempool (), [])
79- assert_equal (self . nodes [ 3 ] .name_pending (), [])
76+ node .generate (1 )
77+ assert_equal (node .getrawmempool (), [])
78+ assert_equal (node .name_pending (), [])
8079
8180 # Verify vout from before against name_show.
82- confirmed = self . nodes [ 0 ] .name_show ('a' )
81+ confirmed = node .name_show ('a' )
8382 assert_equal (pending ['vout' ], confirmed ['vout' ])
83+ return
8484
8585 # Send a name and check that ismine is handled correctly.
86- tx = self . nodes [ 1 ]. name_update ('a' , 'sent-a' , {"destAddress" :addrC })
86+ tx = node . name_update ('a' , 'sent-a' , {"destAddress" : addrOther })
8787 self .sync_with_mode ('mempool' )
88- self .checkPendingName (1 , 'a' , 'name_update' , 'sent-a' , tx , False )
89- self .checkPendingName (3 , 'a' , 'name_update' , 'sent-a' , tx , True )
88+ self .checkPendingName (0 , 'a' , 'name_update' , 'sent-a' , tx , False )
89+ self .checkPendingName (1 , 'a' , 'name_update' , 'sent-a' , tx , True )
9090
91- def checkPendingName (self , ind , name , op , value , txid , mine ):
91+ def checkPendingName (self , ind , name , op , value , txid , mine = None ):
9292 """
9393 Call name_pending on a given name and check that the result
9494 matches the expected values.
@@ -103,12 +103,14 @@ def checkPendingName (self, ind, name, op, value, txid, mine):
103103 assert_equal (obj ['value' ], value )
104104 assert_equal (obj ['txid' ], txid )
105105 assert isinstance (obj ['ismine' ], bool )
106- assert_equal (obj ['ismine' ], mine )
106+ if mine is not None :
107+ assert_equal (obj ['ismine' ], mine )
107108
108109 # There is no golden value for vout, but we can decode the transaction
109110 # to make sure it is correct.
110111 rawtx = self .nodes [ind ].getrawtransaction (txid , 1 )
111112 assert 'nameOp' in rawtx ['vout' ][obj ['vout' ]]['scriptPubKey' ]
112113
114+
113115if __name__ == '__main__' :
114- NameScanningTest ().main ()
116+ NamePendingTest ().main ()
0 commit comments