Fix AccountManager test not cleaning up test accounts

This commit is contained in:
= 2015-02-23 20:27:29 +00:00
parent 7c510109cd
commit 5b8321225a
3 changed files with 28 additions and 3 deletions

View file

@ -76,6 +76,10 @@ func (am AccountManager) NewAccount(auth string) (*Account, error) {
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
// TODO: do we need persistence of accounts as well?
func (am *AccountManager) Accounts() ([]Account, error) {

View file

@ -8,13 +8,31 @@ import (
)
func TestAccountManager(t *testing.T) {
ks := crypto.NewKeyStorePlain(crypto.DefaultDataDir())
// Get AccountManager
ks := crypto.NewKeyStorePlain(crypto.DefaultDataDir() + "/testaccounts")
am := NewAccountManager(ks)
// Create a new account
pass := "" // not used but required by API
a1, err := am.NewAccount(pass)
// Sign junk
toSign := randentropy.GetEntropyCSPRNG(32)
_, err = am.Sign(a1, pass, toSign)
if err != nil {
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)
}
}
}

View file

@ -126,8 +126,11 @@ func GetKeyAddresses(keysDirPath string) (addresses [][]byte, err error) {
}
addresses = make([][]byte, len(fileInfos))
for i, fileInfo := range fileInfos {
addresses[i] = make([]byte, 40)
addresses[i] = []byte(fileInfo.Name())
address, err := hex.DecodeString(fileInfo.Name())
if err != nil {
continue
}
addresses[i] = address
}
return addresses, err
}