diff options
author | Matthew Wampler-Doty <matthew.wampler.doty@gmail.com> | 2015-02-28 05:13:31 +0800 |
---|---|---|
committer | Matthew Wampler-Doty <matthew.wampler.doty@gmail.com> | 2015-02-28 05:13:31 +0800 |
commit | 3820a65299831331f215e158d287fe3df3b69ea6 (patch) | |
tree | cf7b435109c646aac576ed98eefefb57e1f27223 /accounts/accounts_test.go | |
parent | 8653db6df0018d08212493e3a3df4677162bdd8f (diff) | |
parent | 0efd6a881afac0b3082f3b1e8780e3438eea5b02 (diff) | |
download | dexon-3820a65299831331f215e158d287fe3df3b69ea6.tar dexon-3820a65299831331f215e158d287fe3df3b69ea6.tar.gz dexon-3820a65299831331f215e158d287fe3df3b69ea6.tar.bz2 dexon-3820a65299831331f215e158d287fe3df3b69ea6.tar.lz dexon-3820a65299831331f215e158d287fe3df3b69ea6.tar.xz dexon-3820a65299831331f215e158d287fe3df3b69ea6.tar.zst dexon-3820a65299831331f215e158d287fe3df3b69ea6.zip |
Merge branch 'publictests' of github.com:ebuchman/go-ethereum into ethash_pow
Diffstat (limited to 'accounts/accounts_test.go')
-rw-r--r-- | accounts/accounts_test.go | 68 |
1 files changed, 65 insertions, 3 deletions
diff --git a/accounts/accounts_test.go b/accounts/accounts_test.go index 30e8c6285..44d1d72f1 100644 --- a/accounts/accounts_test.go +++ b/accounts/accounts_test.go @@ -5,16 +5,78 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto/randentropy" + "github.com/ethereum/go-ethereum/ethutil" + "time" ) func TestAccountManager(t *testing.T) { - ks := crypto.NewKeyStorePlain(crypto.DefaultDataDir()) - am := NewAccountManager(ks) + ks := crypto.NewKeyStorePlain(ethutil.DefaultDataDir() + "/testaccounts") + am := NewAccountManager(ks, 100) pass := "" // not used but required by API a1, err := am.NewAccount(pass) toSign := randentropy.GetEntropyCSPRNG(32) - _, err = am.Sign(a1, pass, toSign) + _, err = am.SignLocked(a1, pass, toSign) if err != nil { t.Fatal(err) } + + // Cleanup + time.Sleep(time.Millisecond * 150) // wait for locking + + 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) + } + } +} + +func TestAccountManagerLocking(t *testing.T) { + ks := crypto.NewKeyStorePassphrase(ethutil.DefaultDataDir() + "/testaccounts") + am := NewAccountManager(ks, 200) + pass := "foo" + a1, err := am.NewAccount(pass) + toSign := randentropy.GetEntropyCSPRNG(32) + + // Signing without passphrase fails because account is locked + _, err = am.Sign(a1, toSign) + if err != ErrLocked { + t.Fatal(err) + } + + // Signing with passphrase works + _, err = am.SignLocked(a1, pass, toSign) + if err != nil { + t.Fatal(err) + } + + // Signing without passphrase works because account is temp unlocked + _, err = am.Sign(a1, toSign) + if err != nil { + t.Fatal(err) + } + + // Signing without passphrase fails after automatic locking + time.Sleep(time.Millisecond * time.Duration(250)) + + _, err = am.Sign(a1, toSign) + if err != ErrLocked { + 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) + } + } } |