|
|
@ -37,7 +37,7 @@ var testSigData = make([]byte, 32) |
|
|
|
|
|
|
|
|
|
|
|
func TestKeyStore(t *testing.T) { |
|
|
|
func TestKeyStore(t *testing.T) { |
|
|
|
t.Parallel() |
|
|
|
t.Parallel() |
|
|
|
dir, ks := tmpKeyStore(t, true) |
|
|
|
dir, ks := tmpKeyStore(t) |
|
|
|
|
|
|
|
|
|
|
|
a, err := ks.NewAccount("foo") |
|
|
|
a, err := ks.NewAccount("foo") |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -72,7 +72,7 @@ func TestKeyStore(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
func TestSign(t *testing.T) { |
|
|
|
func TestSign(t *testing.T) { |
|
|
|
t.Parallel() |
|
|
|
t.Parallel() |
|
|
|
_, ks := tmpKeyStore(t, true) |
|
|
|
_, ks := tmpKeyStore(t) |
|
|
|
|
|
|
|
|
|
|
|
pass := "" // not used but required by API
|
|
|
|
pass := "" // not used but required by API
|
|
|
|
a1, err := ks.NewAccount(pass) |
|
|
|
a1, err := ks.NewAccount(pass) |
|
|
@ -89,7 +89,7 @@ func TestSign(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
func TestSignWithPassphrase(t *testing.T) { |
|
|
|
func TestSignWithPassphrase(t *testing.T) { |
|
|
|
t.Parallel() |
|
|
|
t.Parallel() |
|
|
|
_, ks := tmpKeyStore(t, true) |
|
|
|
_, ks := tmpKeyStore(t) |
|
|
|
|
|
|
|
|
|
|
|
pass := "passwd" |
|
|
|
pass := "passwd" |
|
|
|
acc, err := ks.NewAccount(pass) |
|
|
|
acc, err := ks.NewAccount(pass) |
|
|
@ -117,7 +117,7 @@ func TestSignWithPassphrase(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
func TestTimedUnlock(t *testing.T) { |
|
|
|
func TestTimedUnlock(t *testing.T) { |
|
|
|
t.Parallel() |
|
|
|
t.Parallel() |
|
|
|
_, ks := tmpKeyStore(t, true) |
|
|
|
_, ks := tmpKeyStore(t) |
|
|
|
|
|
|
|
|
|
|
|
pass := "foo" |
|
|
|
pass := "foo" |
|
|
|
a1, err := ks.NewAccount(pass) |
|
|
|
a1, err := ks.NewAccount(pass) |
|
|
@ -152,7 +152,7 @@ func TestTimedUnlock(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
func TestOverrideUnlock(t *testing.T) { |
|
|
|
func TestOverrideUnlock(t *testing.T) { |
|
|
|
t.Parallel() |
|
|
|
t.Parallel() |
|
|
|
_, ks := tmpKeyStore(t, false) |
|
|
|
_, ks := tmpKeyStore(t) |
|
|
|
|
|
|
|
|
|
|
|
pass := "foo" |
|
|
|
pass := "foo" |
|
|
|
a1, err := ks.NewAccount(pass) |
|
|
|
a1, err := ks.NewAccount(pass) |
|
|
@ -193,7 +193,7 @@ func TestOverrideUnlock(t *testing.T) { |
|
|
|
// This test should fail under -race if signing races the expiration goroutine.
|
|
|
|
// This test should fail under -race if signing races the expiration goroutine.
|
|
|
|
func TestSignRace(t *testing.T) { |
|
|
|
func TestSignRace(t *testing.T) { |
|
|
|
t.Parallel() |
|
|
|
t.Parallel() |
|
|
|
_, ks := tmpKeyStore(t, false) |
|
|
|
_, ks := tmpKeyStore(t) |
|
|
|
|
|
|
|
|
|
|
|
// Create a test account.
|
|
|
|
// Create a test account.
|
|
|
|
a1, err := ks.NewAccount("") |
|
|
|
a1, err := ks.NewAccount("") |
|
|
@ -238,7 +238,7 @@ func waitForKsUpdating(t *testing.T, ks *KeyStore, wantStatus bool, maxTime time |
|
|
|
func TestWalletNotifierLifecycle(t *testing.T) { |
|
|
|
func TestWalletNotifierLifecycle(t *testing.T) { |
|
|
|
t.Parallel() |
|
|
|
t.Parallel() |
|
|
|
// Create a temporary keystore to test with
|
|
|
|
// Create a temporary keystore to test with
|
|
|
|
_, ks := tmpKeyStore(t, false) |
|
|
|
_, ks := tmpKeyStore(t) |
|
|
|
|
|
|
|
|
|
|
|
// Ensure that the notification updater is not running yet
|
|
|
|
// Ensure that the notification updater is not running yet
|
|
|
|
time.Sleep(250 * time.Millisecond) |
|
|
|
time.Sleep(250 * time.Millisecond) |
|
|
@ -284,7 +284,7 @@ type walletEvent struct { |
|
|
|
// or deleted from the keystore.
|
|
|
|
// or deleted from the keystore.
|
|
|
|
func TestWalletNotifications(t *testing.T) { |
|
|
|
func TestWalletNotifications(t *testing.T) { |
|
|
|
t.Parallel() |
|
|
|
t.Parallel() |
|
|
|
_, ks := tmpKeyStore(t, false) |
|
|
|
_, ks := tmpKeyStore(t) |
|
|
|
|
|
|
|
|
|
|
|
// Subscribe to the wallet feed and collect events.
|
|
|
|
// Subscribe to the wallet feed and collect events.
|
|
|
|
var ( |
|
|
|
var ( |
|
|
@ -346,7 +346,7 @@ func TestWalletNotifications(t *testing.T) { |
|
|
|
// TestImportExport tests the import functionality of a keystore.
|
|
|
|
// TestImportExport tests the import functionality of a keystore.
|
|
|
|
func TestImportECDSA(t *testing.T) { |
|
|
|
func TestImportECDSA(t *testing.T) { |
|
|
|
t.Parallel() |
|
|
|
t.Parallel() |
|
|
|
_, ks := tmpKeyStore(t, true) |
|
|
|
_, ks := tmpKeyStore(t) |
|
|
|
key, err := crypto.GenerateKey() |
|
|
|
key, err := crypto.GenerateKey() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("failed to generate key: %v", key) |
|
|
|
t.Fatalf("failed to generate key: %v", key) |
|
|
@ -365,7 +365,7 @@ func TestImportECDSA(t *testing.T) { |
|
|
|
// TestImportECDSA tests the import and export functionality of a keystore.
|
|
|
|
// TestImportECDSA tests the import and export functionality of a keystore.
|
|
|
|
func TestImportExport(t *testing.T) { |
|
|
|
func TestImportExport(t *testing.T) { |
|
|
|
t.Parallel() |
|
|
|
t.Parallel() |
|
|
|
_, ks := tmpKeyStore(t, true) |
|
|
|
_, ks := tmpKeyStore(t) |
|
|
|
acc, err := ks.NewAccount("old") |
|
|
|
acc, err := ks.NewAccount("old") |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("failed to create account: %v", acc) |
|
|
|
t.Fatalf("failed to create account: %v", acc) |
|
|
@ -374,7 +374,7 @@ func TestImportExport(t *testing.T) { |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("failed to export account: %v", acc) |
|
|
|
t.Fatalf("failed to export account: %v", acc) |
|
|
|
} |
|
|
|
} |
|
|
|
_, ks2 := tmpKeyStore(t, true) |
|
|
|
_, ks2 := tmpKeyStore(t) |
|
|
|
if _, err = ks2.Import(json, "old", "old"); err == nil { |
|
|
|
if _, err = ks2.Import(json, "old", "old"); err == nil { |
|
|
|
t.Errorf("importing with invalid password succeeded") |
|
|
|
t.Errorf("importing with invalid password succeeded") |
|
|
|
} |
|
|
|
} |
|
|
@ -394,7 +394,7 @@ func TestImportExport(t *testing.T) { |
|
|
|
// This test should fail under -race if importing races.
|
|
|
|
// This test should fail under -race if importing races.
|
|
|
|
func TestImportRace(t *testing.T) { |
|
|
|
func TestImportRace(t *testing.T) { |
|
|
|
t.Parallel() |
|
|
|
t.Parallel() |
|
|
|
_, ks := tmpKeyStore(t, true) |
|
|
|
_, ks := tmpKeyStore(t) |
|
|
|
acc, err := ks.NewAccount("old") |
|
|
|
acc, err := ks.NewAccount("old") |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("failed to create account: %v", acc) |
|
|
|
t.Fatalf("failed to create account: %v", acc) |
|
|
@ -403,7 +403,7 @@ func TestImportRace(t *testing.T) { |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("failed to export account: %v", acc) |
|
|
|
t.Fatalf("failed to export account: %v", acc) |
|
|
|
} |
|
|
|
} |
|
|
|
_, ks2 := tmpKeyStore(t, true) |
|
|
|
_, ks2 := tmpKeyStore(t) |
|
|
|
var atom atomic.Uint32 |
|
|
|
var atom atomic.Uint32 |
|
|
|
var wg sync.WaitGroup |
|
|
|
var wg sync.WaitGroup |
|
|
|
wg.Add(2) |
|
|
|
wg.Add(2) |
|
|
@ -457,11 +457,7 @@ func checkEvents(t *testing.T, want []walletEvent, have []walletEvent) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func tmpKeyStore(t *testing.T, encrypted bool) (string, *KeyStore) { |
|
|
|
func tmpKeyStore(t *testing.T) (string, *KeyStore) { |
|
|
|
d := t.TempDir() |
|
|
|
d := t.TempDir() |
|
|
|
newKs := NewPlaintextKeyStore |
|
|
|
return d, NewKeyStore(d, veryLightScryptN, veryLightScryptP) |
|
|
|
if encrypted { |
|
|
|
|
|
|
|
newKs = func(kd string) *KeyStore { return NewKeyStore(kd, veryLightScryptN, veryLightScryptP) } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return d, newKs(d) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|