@@ -22,6 +22,7 @@ import (
22
22
accountsTypes "github.com/digitalbitbox/bitbox-wallet-app/backend/accounts/types"
23
23
"github.com/digitalbitbox/bitbox-wallet-app/backend/coins/btc"
24
24
coinpkg "github.com/digitalbitbox/bitbox-wallet-app/backend/coins/coin"
25
+ "github.com/digitalbitbox/bitbox-wallet-app/backend/config"
25
26
keystoremock "github.com/digitalbitbox/bitbox-wallet-app/backend/keystore/mocks"
26
27
"github.com/digitalbitbox/bitbox-wallet-app/backend/keystore/software"
27
28
"github.com/digitalbitbox/bitbox-wallet-app/backend/signing"
@@ -98,6 +99,9 @@ func TestRegisterKeystore(t *testing.T) {
98
99
require .NotNil (t , b .Config ().AccountsConfig ().Lookup ("v0-55555555-btc-0" ))
99
100
require .NotNil (t , b .Config ().AccountsConfig ().Lookup ("v0-55555555-ltc-0" ))
100
101
require .NotNil (t , b .Config ().AccountsConfig ().Lookup ("v0-55555555-eth-0" ))
102
+ require .NotNil (t , b .accounts .lookup ("v0-55555555-btc-0" ))
103
+ require .NotNil (t , b .accounts .lookup ("v0-55555555-ltc-0" ))
104
+ require .NotNil (t , b .accounts .lookup ("v0-55555555-eth-0" ))
101
105
require .Equal (t , "Bitcoin" , b .Config ().AccountsConfig ().Accounts [0 ].Name )
102
106
require .Equal (t , "Litecoin" , b .Config ().AccountsConfig ().Accounts [1 ].Name )
103
107
require .Equal (t , "Ethereum" , b .Config ().AccountsConfig ().Accounts [2 ].Name )
@@ -113,32 +117,79 @@ func TestRegisterKeystore(t *testing.T) {
113
117
// tests, but we check that it was set and recent.
114
118
require .True (t , time .Since (b .Config ().AccountsConfig ().Keystores [0 ].LastConnected ) < 10 * time .Second )
115
119
116
- // Deregistering the keystore removes the loaded accounts, but not the persisted accounts and
117
- // keystores.
120
+ // Deregistering the keystore leaves the loaded accounts (watchonly), and leaves the persisted
121
+ // accounts and keystores.
122
+ // Mark accounts as watch-only.
123
+ require .NoError (t , b .config .ModifyAccountsConfig (func (cfg * config.AccountsConfig ) error {
124
+ for _ , acct := range cfg .Accounts {
125
+ f := true
126
+ acct .Watch = & f
127
+ }
128
+ return nil
129
+ }))
118
130
b .DeregisterKeystore ()
119
- require .Len (t , b .Accounts (), 0 )
131
+ require .Len (t , b .Accounts (), 3 )
120
132
require .Len (t , b .Config ().AccountsConfig ().Accounts , 3 )
121
133
require .Len (t , b .Config ().AccountsConfig ().Keystores , 1 )
122
134
123
135
// Registering the same keystore again loads the previously persisted accounts and does not
124
136
// automatically persist more accounts.
125
- b .DeregisterKeystore ()
126
137
b .registerKeystore (ks1 )
127
138
require .Len (t , b .Accounts (), 3 )
128
139
require .Len (t , b .Config ().AccountsConfig ().Accounts , 3 )
129
140
require .Len (t , b .Config ().AccountsConfig ().Keystores , 1 )
130
141
131
142
// Registering another keystore persists a set of initial default accounts and loads them.
143
+ // They are added to the previous set of watchonly accounts
132
144
b .DeregisterKeystore ()
133
145
b .registerKeystore (ks2 )
134
- require .Len (t , b .Accounts (), 3 )
146
+ require .Len (t , b .Accounts (), 6 )
135
147
require .Len (t , b .Config ().AccountsConfig ().Accounts , 6 )
136
148
require .NotNil (t , b .Config ().AccountsConfig ().Lookup ("v0-66666666-btc-0" ))
137
149
require .NotNil (t , b .Config ().AccountsConfig ().Lookup ("v0-66666666-ltc-0" ))
138
150
require .NotNil (t , b .Config ().AccountsConfig ().Lookup ("v0-66666666-eth-0" ))
151
+ require .NotNil (t , b .accounts .lookup ("v0-66666666-btc-0" ))
152
+ require .NotNil (t , b .accounts .lookup ("v0-66666666-ltc-0" ))
153
+ require .NotNil (t , b .accounts .lookup ("v0-66666666-eth-0" ))
139
154
require .Len (t , b .Config ().AccountsConfig ().Keystores , 2 )
140
155
require .Equal (t , "Mock keystore 2" , b .Config ().AccountsConfig ().Keystores [1 ].Name )
141
156
require .Equal (t , rootFingerprint2 , []byte (b .Config ().AccountsConfig ().Keystores [1 ].RootFingerprint ))
157
+
158
+ b .DeregisterKeystore ()
159
+ // Enable watch-only for all but two accounts, one of each keystore. Now, all watch-only
160
+ // accounts plus the non-watch only accounts of the connected keystore will be loaded.
161
+ require .NoError (t , b .config .ModifyAccountsConfig (func (cfg * config.AccountsConfig ) error {
162
+ for _ , acct := range cfg .Accounts {
163
+ t := true
164
+ acct .Watch = & t
165
+ }
166
+
167
+ f := false
168
+ cfg .Lookup ("v0-55555555-btc-0" ).Watch = & f
169
+ cfg .Lookup ("v0-66666666-ltc-0" ).Watch = & f
170
+ return nil
171
+ }))
172
+ b .registerKeystore (ks1 )
173
+ require .Len (t , b .Accounts (), 5 )
174
+ // v0-55555555-btc-0 loaded even though watch=false, as the keystore is connected.
175
+ require .NotNil (t , b .accounts .lookup ("v0-55555555-btc-0" ))
176
+ require .NotNil (t , b .accounts .lookup ("v0-55555555-ltc-0" ))
177
+ require .NotNil (t , b .accounts .lookup ("v0-55555555-eth-0" ))
178
+ require .NotNil (t , b .accounts .lookup ("v0-66666666-btc-0" ))
179
+ // v0-66666666-ltc-0 not loaded (watch=false).
180
+ require .Nil (t , b .accounts .lookup ("v0-66666666-ltc-0" ))
181
+ require .NotNil (t , b .accounts .lookup ("v0-66666666-eth-0" ))
182
+
183
+ b .DeregisterKeystore ()
184
+ require .Len (t , b .Accounts (), 4 )
185
+ // v0-55555555-btc-0 not loaded (watch = false)
186
+ require .Nil (t , b .accounts .lookup ("v0-55555555-btc-0" ))
187
+ require .NotNil (t , b .accounts .lookup ("v0-55555555-ltc-0" ))
188
+ require .NotNil (t , b .accounts .lookup ("v0-55555555-eth-0" ))
189
+ require .NotNil (t , b .accounts .lookup ("v0-66666666-btc-0" ))
190
+ // v0-66666666-ltc-0 not loaded (watch=false).
191
+ require .Nil (t , b .accounts .lookup ("v0-66666666-ltc-0" ))
192
+ require .NotNil (t , b .accounts .lookup ("v0-66666666-eth-0" ))
142
193
}
143
194
144
195
func lookup (accts []accounts.Interface , code accountsTypes.Code ) accounts.Interface {
0 commit comments