mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
Merge 5b8321225a into 0adff214c3
This commit is contained in:
commit
c95e7d2554
3 changed files with 28 additions and 3 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue