MCPcopy Create free account
hub / github.com/CPChain/chain / TestUpdatedKeyfileContents

Function TestUpdatedKeyfileContents

accounts/keystore/account_cache_test.go:320–397  ·  view source on GitHub ↗

TestUpdatedKeyfileContents tests that updating the contents of a keystore file is noticed by the watcher, and the account cache is updated accordingly

(t *testing.T)

Source from the content-addressed store, hash-verified

318// TestUpdatedKeyfileContents tests that updating the contents of a keystore file
319// is noticed by the watcher, and the account cache is updated accordingly
320func TestUpdatedKeyfileContents(t *testing.T) {
321 //t.Parallel()
322
323 // Create a temporary kesytore to test with
324 rand.Seed(time.Now().UnixNano())
325 dir := filepath.Join(os.TempDir(), fmt.Sprintf("eth-keystore-watch-test-%d-%d", os.Getpid(), rand.Int()))
326 ks := NewKeyStore(dir, LightScryptN, LightScryptP)
327
328 list := ks.Accounts()
329 if len(list) > 0 {
330 t.Error("initial account list not empty:", list)
331 }
332 time.Sleep(100 * time.Millisecond)
333
334 // Create the directory and copy a key file into it.
335 os.MkdirAll(dir, 0700)
336 defer os.RemoveAll(dir)
337 file := filepath.Join(dir, "aaa")
338
339 // Place one of our testfiles in there
340 if err := cp.CopyFile(file, cachetestAccounts[0].URL.Path); err != nil {
341 t.Fatal(err)
342 }
343
344 // ks should see the account.
345 wantAccounts := []accounts.Account{cachetestAccounts[0]}
346 wantAccounts[0].URL = accounts.URL{Scheme: KeyStoreScheme, Path: file}
347 if err := waitForAccounts(wantAccounts, ks); err != nil {
348 t.Error(err)
349 return
350 }
351
352 // needed so that modTime of `file` is different to its current value after forceCopyFile
353 time.Sleep(1000 * time.Millisecond)
354
355 // Now replace file contents
356 if err := forceCopyFile(file, cachetestAccounts[1].URL.Path); err != nil {
357 t.Fatal(err)
358 return
359 }
360 wantAccounts = []accounts.Account{cachetestAccounts[1]}
361 wantAccounts[0].URL = accounts.URL{Scheme: KeyStoreScheme, Path: file}
362 if err := waitForAccounts(wantAccounts, ks); err != nil {
363 t.Errorf("First replacement failed")
364 t.Error(err)
365 return
366 }
367
368 // needed so that modTime of `file` is different to its current value after forceCopyFile
369 time.Sleep(1000 * time.Millisecond)
370
371 // Now replace file contents again
372 if err := forceCopyFile(file, cachetestAccounts[2].URL.Path); err != nil {
373 t.Fatal(err)
374 return
375 }
376 wantAccounts = []accounts.Account{cachetestAccounts[2]}
377 wantAccounts[0].URL = accounts.URL{Scheme: KeyStoreScheme, Path: file}

Callers

nothing calls this directly

Calls 8

AccountsMethod · 0.95
NewKeyStoreFunction · 0.85
waitForAccountsFunction · 0.85
forceCopyFileFunction · 0.85
SleepMethod · 0.80
NowMethod · 0.65
ErrorMethod · 0.65
FatalMethod · 0.65

Tested by

no test coverage detected