Merge pull request #378 from Gustav-Simonsson/fix_account_manager_tests

Fix key store address hex decoding and accounts test
This commit is contained in:
Jeffrey Wilcke 2015-02-24 21:58:42 +01:00
commit ed90efb05b
3 changed files with 22 additions and 3 deletions

View File

@ -56,6 +56,10 @@ func NewAccountManager(keyStore crypto.KeyStore2) AccountManager {
return *am return *am
} }
func (am AccountManager) DeleteAccount(address []byte, auth string) error {
return am.keyStore.DeleteKey(address, auth)
}
func (am *AccountManager) Sign(fromAccount *Account, keyAuth string, toSign []byte) (signature []byte, err error) { func (am *AccountManager) Sign(fromAccount *Account, keyAuth string, toSign []byte) (signature []byte, err error) {
key, err := am.keyStore.GetKey(fromAccount.Address, keyAuth) key, err := am.keyStore.GetKey(fromAccount.Address, keyAuth)
if err != nil { if err != nil {

View File

@ -9,7 +9,7 @@ import (
) )
func TestAccountManager(t *testing.T) { func TestAccountManager(t *testing.T) {
ks := crypto.NewKeyStorePlain(ethutil.DefaultDataDir()) ks := crypto.NewKeyStorePlain(ethutil.DefaultDataDir() + "/testaccounts")
am := NewAccountManager(ks) am := NewAccountManager(ks)
pass := "" // not used but required by API pass := "" // not used but required by API
a1, err := am.NewAccount(pass) a1, err := am.NewAccount(pass)
@ -18,4 +18,16 @@ func TestAccountManager(t *testing.T) {
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)
}
}
} }

View File

@ -119,8 +119,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
} }