@@ -1381,16 +1381,6 @@ func TestWatchonly(t *testing.T) {
13811381 // Disable watchonly, all accounts disappear.
13821382 require .NoError (t , b .SetWatchonly (rootFingerprint , false ))
13831383 checkShownAccountsLen (t , b , 0 , 3 )
1384-
1385- // Re-enable watchonly - accounts do not show up yet.
1386- require .NoError (t , b .SetWatchonly (rootFingerprint , true ))
1387- checkShownAccountsLen (t , b , 0 , 3 )
1388-
1389- // Reconnecting the keystore brings back the watched accounts.
1390- b .registerKeystore (ks )
1391- checkShownAccountsLen (t , b , 3 , 3 )
1392- b .DeregisterKeystore ()
1393- checkShownAccountsLen (t , b , 3 , 3 )
13941384 })
13951385
13961386 // Disable keystore's watchonly setting while keystore is connected does not make the accounts
@@ -1533,4 +1523,48 @@ func TestWatchonly(t *testing.T) {
15331523 checkShownAccountsLen (t , b , 3 , 6 )
15341524 })
15351525
1526+ // Adding new accounts after the keytore has been connected: new account is watched if the
1527+ // keystore is already watched.
1528+ t .Run ("" , func (t * testing.T ) {
1529+ b := newBackend (t , testnetDisabled , regtestDisabled )
1530+ defer b .Close ()
1531+
1532+ ks := makeBitBox02Multi ()
1533+
1534+ rootFingerprint , err := ks .RootFingerprint ()
1535+ require .NoError (t , err )
1536+
1537+ b .registerKeystore (ks )
1538+ checkShownAccountsLen (t , b , 3 , 3 )
1539+ require .NoError (t , b .SetWatchonly (rootFingerprint , true ))
1540+
1541+ // An account may already have been added as part of autodiscover, so we add two.
1542+ newAccountCode1 , err := b .CreateAndPersistAccountConfig (
1543+ coinpkg .CodeBTC ,
1544+ "Bitcoin account name" ,
1545+ ks ,
1546+ )
1547+ require .NoError (t , err )
1548+ require .Equal (t , accountsTypes .Code ("v0-55555555-btc-1" ), newAccountCode1 )
1549+
1550+ expectedNewAccountCode2 := accountsTypes .Code ("v0-55555555-btc-2" )
1551+ // Make sure the account to be added has not been added yet (autodiscover), so we know we
1552+ // are testing the correct setting of the Watch flag when a new account is persisted.
1553+ require .Nil (t , b .Config ().AccountsConfig ().Lookup (expectedNewAccountCode2 ))
1554+
1555+ newAccountCode2 , err := b .CreateAndPersistAccountConfig (
1556+ coinpkg .CodeBTC ,
1557+ "Bitcoin account name 2" ,
1558+ ks ,
1559+ )
1560+ require .NoError (t , err )
1561+ require .Equal (t , expectedNewAccountCode2 , newAccountCode2 )
1562+
1563+ require .NoError (t , err )
1564+
1565+ b .DeregisterKeystore ()
1566+
1567+ // Accounts, including the newly added ones, remain loaded.
1568+ checkShownAccountsLen (t , b , 5 , 5 )
1569+ })
15361570}
0 commit comments