1919from test_framework .key import ECPubKey
2020from test_framework .test_framework import BitcoinTestFramework
2121from test_framework .messages import COIN , CTransaction , CTxOut
22- from test_framework .script_util import key_to_p2pkh_script , script_to_p2sh_script , script_to_p2wsh_script
22+ from test_framework .script_util import key_to_p2pkh_script , key_to_p2pk_script , script_to_p2sh_script , script_to_p2wsh_script
2323from test_framework .util import (
2424 assert_equal ,
2525 assert_raises_rpc_error ,
2626 sha256sum_file ,
2727)
2828from test_framework .wallet_util import (
2929 get_generate_key ,
30+ generate_keypair ,
3031)
3132
3233
@@ -1006,6 +1007,17 @@ def check_comments():
10061007
10071008 wallet .unloadwallet ()
10081009
1010+ def test_migrate_simple_watch_only (self ):
1011+ self .log .info ("Test migrating a watch-only p2pk script" )
1012+ wallet = self .create_legacy_wallet ("bare_p2pk" , blank = True )
1013+ _ , pubkey = generate_keypair ()
1014+ p2pk_script = key_to_p2pk_script (pubkey )
1015+ wallet .importaddress (address = p2pk_script .hex ())
1016+ # Migrate wallet in the latest node
1017+ res , _ = self .migrate_and_get_rpc ("bare_p2pk" )
1018+ wo_wallet = self .master_node .get_wallet_rpc (res ['watchonly_name' ])
1019+ assert_equal (wo_wallet .listdescriptors ()['descriptors' ][0 ]['desc' ], descsum_create (f'pk({ pubkey .hex ()} )' ))
1020+ wo_wallet .unloadwallet ()
10091021
10101022 def run_test (self ):
10111023 self .master_node = self .nodes [0 ]
@@ -1032,6 +1044,8 @@ def run_test(self):
10321044 self .test_avoidreuse ()
10331045 self .test_preserve_tx_extra_info ()
10341046 self .test_blank ()
1047+ self .test_migrate_simple_watch_only ()
1048+
10351049
10361050if __name__ == '__main__' :
10371051 WalletMigrationTest (__file__ ).main ()
0 commit comments