forked from cerc-io/plugeth
Fix key store address hex decoding and accounts test
Thanks to https://github.com/jaekwon for original fix!
This commit is contained in:
parent
91a8c08f03
commit
923950ccaa
@ -56,6 +56,10 @@ func NewAccountManager(keyStore crypto.KeyStore2) AccountManager {
|
||||
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) {
|
||||
key, err := am.keyStore.GetKey(fromAccount.Address, keyAuth)
|
||||
if err != nil {
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func TestAccountManager(t *testing.T) {
|
||||
ks := crypto.NewKeyStorePlain(ethutil.DefaultDataDir())
|
||||
ks := crypto.NewKeyStorePlain(ethutil.DefaultDataDir() + "/testaccounts")
|
||||
am := NewAccountManager(ks)
|
||||
pass := "" // not used but required by API
|
||||
a1, err := am.NewAccount(pass)
|
||||
@ -18,4 +18,16 @@ func TestAccountManager(t *testing.T) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -119,8 +119,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 New Issue
Block a user