@@ -1523,4 +1523,48 @@ func TestWatchonly(t *testing.T) {
1523
1523
checkShownAccountsLen (t , b , 3 , 6 )
1524
1524
})
1525
1525
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
+ })
1526
1570
}
0 commit comments