mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
Fix AccountManager test not cleaning up test accounts
This commit is contained in:
parent
7c510109cd
commit
5b8321225a
3 changed files with 28 additions and 3 deletions
|
|
@ -76,6 +76,10 @@ func (am AccountManager) NewAccount(auth string) (*Account, error) {
|
||||||
return ua, err
|
return ua, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (am AccountManager) DeleteAccount(address []byte, auth string) error {
|
||||||
|
return am.keyStore.DeleteKey(address, auth)
|
||||||
|
}
|
||||||
|
|
||||||
// set of accounts == set of keys in given key store
|
// set of accounts == set of keys in given key store
|
||||||
// TODO: do we need persistence of accounts as well?
|
// TODO: do we need persistence of accounts as well?
|
||||||
func (am *AccountManager) Accounts() ([]Account, error) {
|
func (am *AccountManager) Accounts() ([]Account, error) {
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,31 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccountManager(t *testing.T) {
|
func TestAccountManager(t *testing.T) {
|
||||||
ks := crypto.NewKeyStorePlain(crypto.DefaultDataDir())
|
|
||||||
|
// Get AccountManager
|
||||||
|
ks := crypto.NewKeyStorePlain(crypto.DefaultDataDir() + "/testaccounts")
|
||||||
am := NewAccountManager(ks)
|
am := NewAccountManager(ks)
|
||||||
|
|
||||||
|
// Create a new account
|
||||||
pass := "" // not used but required by API
|
pass := "" // not used but required by API
|
||||||
a1, err := am.NewAccount(pass)
|
a1, err := am.NewAccount(pass)
|
||||||
|
|
||||||
|
// Sign junk
|
||||||
toSign := randentropy.GetEntropyCSPRNG(32)
|
toSign := randentropy.GetEntropyCSPRNG(32)
|
||||||
_, err = am.Sign(a1, pass, toSign)
|
_, err = am.Sign(a1, pass, toSign)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
accounts, err := am.Accounts()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for _, account := range accounts {
|
||||||
|
err := am.DeleteAccount(account.Address, pass)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -126,8 +126,11 @@ func GetKeyAddresses(keysDirPath string) (addresses [][]byte, err error) {
|
||||||
}
|
}
|
||||||
addresses = make([][]byte, len(fileInfos))
|
addresses = make([][]byte, len(fileInfos))
|
||||||
for i, fileInfo := range fileInfos {
|
for i, fileInfo := range fileInfos {
|
||||||
addresses[i] = make([]byte, 40)
|
address, err := hex.DecodeString(fileInfo.Name())
|
||||||
addresses[i] = []byte(fileInfo.Name())
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
addresses[i] = address
|
||||||
}
|
}
|
||||||
return addresses, err
|
return addresses, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue