@ -52,7 +52,8 @@ class ImportMultiTest (BitcoinTestFramework):
@@ -52,7 +52,8 @@ class ImportMultiTest (BitcoinTestFramework):
result = self . nodes [ 1 ] . importmulti ( [ {
" scriptPubKey " : {
" address " : address [ ' address ' ]
}
} ,
" timestamp " : " now " ,
} ] )
assert_equal ( result [ 0 ] [ ' success ' ] , True )
address_assert = self . nodes [ 1 ] . validateaddress ( address [ ' address ' ] )
@ -65,6 +66,7 @@ class ImportMultiTest (BitcoinTestFramework):
@@ -65,6 +66,7 @@ class ImportMultiTest (BitcoinTestFramework):
address = self . nodes [ 0 ] . validateaddress ( self . nodes [ 0 ] . getnewaddress ( ) )
result = self . nodes [ 1 ] . importmulti ( [ {
" scriptPubKey " : address [ ' scriptPubKey ' ] ,
" timestamp " : " now " ,
" internal " : True
} ] )
assert_equal ( result [ 0 ] [ ' success ' ] , True )
@ -76,7 +78,8 @@ class ImportMultiTest (BitcoinTestFramework):
@@ -76,7 +78,8 @@ class ImportMultiTest (BitcoinTestFramework):
print ( " Should not import a scriptPubKey without internal flag " )
address = self . nodes [ 0 ] . validateaddress ( self . nodes [ 0 ] . getnewaddress ( ) )
result = self . nodes [ 1 ] . importmulti ( [ {
" scriptPubKey " : address [ ' scriptPubKey ' ]
" scriptPubKey " : address [ ' scriptPubKey ' ] ,
" timestamp " : " now " ,
} ] )
assert_equal ( result [ 0 ] [ ' success ' ] , False )
assert_equal ( result [ 0 ] [ ' error ' ] [ ' code ' ] , - 8 )
@ -93,6 +96,7 @@ class ImportMultiTest (BitcoinTestFramework):
@@ -93,6 +96,7 @@ class ImportMultiTest (BitcoinTestFramework):
" scriptPubKey " : {
" address " : address [ ' address ' ]
} ,
" timestamp " : " now " ,
" pubkeys " : [ address [ ' pubkey ' ] ]
} ] )
assert_equal ( result [ 0 ] [ ' success ' ] , True )
@ -106,6 +110,7 @@ class ImportMultiTest (BitcoinTestFramework):
@@ -106,6 +110,7 @@ class ImportMultiTest (BitcoinTestFramework):
address = self . nodes [ 0 ] . validateaddress ( self . nodes [ 0 ] . getnewaddress ( ) )
request = [ {
" scriptPubKey " : address [ ' scriptPubKey ' ] ,
" timestamp " : " now " ,
" pubkeys " : [ address [ ' pubkey ' ] ] ,
" internal " : True
} ]
@ -120,6 +125,7 @@ class ImportMultiTest (BitcoinTestFramework):
@@ -120,6 +125,7 @@ class ImportMultiTest (BitcoinTestFramework):
address = self . nodes [ 0 ] . validateaddress ( self . nodes [ 0 ] . getnewaddress ( ) )
request = [ {
" scriptPubKey " : address [ ' scriptPubKey ' ] ,
" timestamp " : " now " ,
" pubkeys " : [ address [ ' pubkey ' ] ]
} ]
result = self . nodes [ 1 ] . importmulti ( request )
@ -133,16 +139,19 @@ class ImportMultiTest (BitcoinTestFramework):
@@ -133,16 +139,19 @@ class ImportMultiTest (BitcoinTestFramework):
# Address + Private key + !watchonly
print ( " Should import an address with private key " )
address = self . nodes [ 0 ] . validateaddress ( self . nodes [ 0 ] . getnewaddress ( ) )
timestamp = self . nodes [ 1 ] . getblock ( self . nodes [ 1 ] . getbestblockhash ( ) ) [ ' mediantime ' ]
result = self . nodes [ 1 ] . importmulti ( [ {
" scriptPubKey " : {
" address " : address [ ' address ' ]
} ,
" timestamp " : " now " ,
" keys " : [ self . nodes [ 0 ] . dumpprivkey ( address [ ' address ' ] ) ]
} ] )
assert_equal ( result [ 0 ] [ ' success ' ] , True )
address_assert = self . nodes [ 1 ] . validateaddress ( address [ ' address ' ] )
assert_equal ( address_assert [ ' iswatchonly ' ] , False )
assert_equal ( address_assert [ ' ismine ' ] , True )
assert_equal ( address_assert [ ' timestamp ' ] , timestamp )
# Address + Private key + watchonly
print ( " Should not import an address with private key and with watchonly " )
@ -151,6 +160,7 @@ class ImportMultiTest (BitcoinTestFramework):
@@ -151,6 +160,7 @@ class ImportMultiTest (BitcoinTestFramework):
" scriptPubKey " : {
" address " : address [ ' address ' ]
} ,
" timestamp " : " now " ,
" keys " : [ self . nodes [ 0 ] . dumpprivkey ( address [ ' address ' ] ) ] ,
" watchonly " : True
} ] )
@ -166,6 +176,7 @@ class ImportMultiTest (BitcoinTestFramework):
@@ -166,6 +176,7 @@ class ImportMultiTest (BitcoinTestFramework):
address = self . nodes [ 0 ] . validateaddress ( self . nodes [ 0 ] . getnewaddress ( ) )
result = self . nodes [ 1 ] . importmulti ( [ {
" scriptPubKey " : address [ ' scriptPubKey ' ] ,
" timestamp " : " now " ,
" keys " : [ self . nodes [ 0 ] . dumpprivkey ( address [ ' address ' ] ) ] ,
" internal " : True
} ] )
@ -179,6 +190,7 @@ class ImportMultiTest (BitcoinTestFramework):
@@ -179,6 +190,7 @@ class ImportMultiTest (BitcoinTestFramework):
address = self . nodes [ 0 ] . validateaddress ( self . nodes [ 0 ] . getnewaddress ( ) )
result = self . nodes [ 1 ] . importmulti ( [ {
" scriptPubKey " : address [ ' scriptPubKey ' ] ,
" timestamp " : " now " ,
" keys " : [ self . nodes [ 0 ] . dumpprivkey ( address [ ' address ' ] ) ]
} ] )
assert_equal ( result [ 0 ] [ ' success ' ] , False )
@ -203,7 +215,8 @@ class ImportMultiTest (BitcoinTestFramework):
@@ -203,7 +215,8 @@ class ImportMultiTest (BitcoinTestFramework):
result = self . nodes [ 1 ] . importmulti ( [ {
" scriptPubKey " : {
" address " : multi_sig_script [ ' address ' ]
}
} ,
" timestamp " : " now " ,
} ] )
assert_equal ( result [ 0 ] [ ' success ' ] , True )
address_assert = self . nodes [ 1 ] . validateaddress ( multi_sig_script [ ' address ' ] )
@ -229,6 +242,7 @@ class ImportMultiTest (BitcoinTestFramework):
@@ -229,6 +242,7 @@ class ImportMultiTest (BitcoinTestFramework):
" scriptPubKey " : {
" address " : multi_sig_script [ ' address ' ]
} ,
" timestamp " : " now " ,
" redeemscript " : multi_sig_script [ ' redeemScript ' ]
} ] )
assert_equal ( result [ 0 ] [ ' success ' ] , True )
@ -253,6 +267,7 @@ class ImportMultiTest (BitcoinTestFramework):
@@ -253,6 +267,7 @@ class ImportMultiTest (BitcoinTestFramework):
" scriptPubKey " : {
" address " : multi_sig_script [ ' address ' ]
} ,
" timestamp " : " now " ,
" redeemscript " : multi_sig_script [ ' redeemScript ' ] ,
" keys " : [ self . nodes [ 0 ] . dumpprivkey ( sig_address_1 [ ' address ' ] ) , self . nodes [ 0 ] . dumpprivkey ( sig_address_2 [ ' address ' ] ) ]
} ] )
@ -277,6 +292,7 @@ class ImportMultiTest (BitcoinTestFramework):
@@ -277,6 +292,7 @@ class ImportMultiTest (BitcoinTestFramework):
" scriptPubKey " : {
" address " : multi_sig_script [ ' address ' ]
} ,
" timestamp " : " now " ,
" redeemscript " : multi_sig_script [ ' redeemScript ' ] ,
" keys " : [ self . nodes [ 0 ] . dumpprivkey ( sig_address_1 [ ' address ' ] ) , self . nodes [ 0 ] . dumpprivkey ( sig_address_2 [ ' address ' ] ) ] ,
" watchonly " : True
@ -294,6 +310,7 @@ class ImportMultiTest (BitcoinTestFramework):
@@ -294,6 +310,7 @@ class ImportMultiTest (BitcoinTestFramework):
" scriptPubKey " : {
" address " : address [ ' address ' ]
} ,
" timestamp " : " now " ,
" pubkeys " : [ address2 [ ' pubkey ' ] ]
} ] )
assert_equal ( result [ 0 ] [ ' success ' ] , False )
@ -310,6 +327,7 @@ class ImportMultiTest (BitcoinTestFramework):
@@ -310,6 +327,7 @@ class ImportMultiTest (BitcoinTestFramework):
address2 = self . nodes [ 0 ] . validateaddress ( self . nodes [ 0 ] . getnewaddress ( ) )
request = [ {
" scriptPubKey " : address [ ' scriptPubKey ' ] ,
" timestamp " : " now " ,
" pubkeys " : [ address2 [ ' pubkey ' ] ] ,
" internal " : True
} ]
@ -330,6 +348,7 @@ class ImportMultiTest (BitcoinTestFramework):
@@ -330,6 +348,7 @@ class ImportMultiTest (BitcoinTestFramework):
" scriptPubKey " : {
" address " : address [ ' address ' ]
} ,
" timestamp " : " now " ,
" keys " : [ self . nodes [ 0 ] . dumpprivkey ( address2 [ ' address ' ] ) ]
} ] )
assert_equal ( result [ 0 ] [ ' success ' ] , False )
@ -346,6 +365,7 @@ class ImportMultiTest (BitcoinTestFramework):
@@ -346,6 +365,7 @@ class ImportMultiTest (BitcoinTestFramework):
address2 = self . nodes [ 0 ] . validateaddress ( self . nodes [ 0 ] . getnewaddress ( ) )
result = self . nodes [ 1 ] . importmulti ( [ {
" scriptPubKey " : address [ ' scriptPubKey ' ] ,
" timestamp " : " now " ,
" keys " : [ self . nodes [ 0 ] . dumpprivkey ( address2 [ ' address ' ] ) ] ,
" internal " : True
} ] )
@ -356,5 +376,18 @@ class ImportMultiTest (BitcoinTestFramework):
@@ -356,5 +376,18 @@ class ImportMultiTest (BitcoinTestFramework):
assert_equal ( address_assert [ ' iswatchonly ' ] , False )
assert_equal ( address_assert [ ' ismine ' ] , False )
# Bad or missing timestamps
print ( " Should throw on invalid or missing timestamp values " )
assert_raises_message ( JSONRPCException , ' Missing required timestamp field for key ' ,
self . nodes [ 1 ] . importmulti , [ {
" scriptPubKey " : address [ ' scriptPubKey ' ] ,
} ] )
assert_raises_message ( JSONRPCException , ' Expected number or " now " timestamp value for key. got type string ' ,
self . nodes [ 1 ] . importmulti , [ {
" scriptPubKey " : address [ ' scriptPubKey ' ] ,
" timestamp " : " " ,
} ] )
if __name__ == ' __main__ ' :
ImportMultiTest ( ) . main ( )