aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/key_store_passphrase_test.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-03-03 08:15:42 +0800
committerFelix Lange <fjl@twurst.com>2016-04-12 21:58:07 +0800
commita9f26dcd0d14c0cb9f309ebccf81e8f741fc4636 (patch)
tree1a1e269194f3698737b0c1dbaf918c4e8dbae347 /accounts/key_store_passphrase_test.go
parentef63e9af55fcfe3255dddec3197bd8a807152c66 (diff)
downloadgo-tangerine-a9f26dcd0d14c0cb9f309ebccf81e8f741fc4636.tar
go-tangerine-a9f26dcd0d14c0cb9f309ebccf81e8f741fc4636.tar.gz
go-tangerine-a9f26dcd0d14c0cb9f309ebccf81e8f741fc4636.tar.bz2
go-tangerine-a9f26dcd0d14c0cb9f309ebccf81e8f741fc4636.tar.lz
go-tangerine-a9f26dcd0d14c0cb9f309ebccf81e8f741fc4636.tar.xz
go-tangerine-a9f26dcd0d14c0cb9f309ebccf81e8f741fc4636.tar.zst
go-tangerine-a9f26dcd0d14c0cb9f309ebccf81e8f741fc4636.zip
accounts: cache key addresses
In order to avoid disk thrashing for Accounts and HasAccount, address->key file mappings are now cached in memory. This makes it no longer necessary to keep the key address in the file name. The address of each key is derived from file content instead. There are minor user-visible changes: - "geth account list" now reports key file paths alongside the address. - If multiple keys are present for an address, unlocking by address is not possible. Users are directed to remove the duplicate files instead. Unlocking by index is still possible. - Key files are overwritten written in place when updating the password.
Diffstat (limited to 'accounts/key_store_passphrase_test.go')
-rw-r--r--accounts/key_store_passphrase_test.go15
1 files changed, 12 insertions, 3 deletions
diff --git a/accounts/key_store_passphrase_test.go b/accounts/key_store_passphrase_test.go
index 6ff3ae422..217393fa5 100644
--- a/accounts/key_store_passphrase_test.go
+++ b/accounts/key_store_passphrase_test.go
@@ -17,16 +17,25 @@
package accounts
import (
+ "io/ioutil"
"testing"
"github.com/ethereum/go-ethereum/common"
)
+const (
+ veryLightScryptN = 2
+ veryLightScryptP = 1
+)
+
// Tests that a json key file can be decrypted and encrypted in multiple rounds.
func TestKeyEncryptDecrypt(t *testing.T) {
- address := common.HexToAddress("f626acac23772cbe04dd578bee681b06bdefb9fa")
- keyjson := []byte("{\"address\":\"f626acac23772cbe04dd578bee681b06bdefb9fa\",\"crypto\":{\"cipher\":\"aes-128-ctr\",\"ciphertext\":\"1bcf0ab9b14459795ce59f63e63255ffd84dc38d31614a5a78e37144d7e4a17f\",\"cipherparams\":{\"iv\":\"df4c7e225ee2d81adef522013e3fbe24\"},\"kdf\":\"scrypt\",\"kdfparams\":{\"dklen\":32,\"n\":262144,\"p\":1,\"r\":8,\"salt\":\"2909a99dd2bfa7079a4b40991773b1083f8512c0c55b9b63402ab0e3dc8db8b3\"},\"mac\":\"4ecf6a4ad92ae2c016cb7c44abade74799480c3303eb024661270dfefdbc7510\"},\"id\":\"b4718210-9a30-4883-b8a6-dbdd08bd0ceb\",\"version\":3}")
+ keyjson, err := ioutil.ReadFile("testdata/very-light-scrypt.json")
+ if err != nil {
+ t.Fatal(err)
+ }
password := ""
+ address := common.HexToAddress("45dea0fb0bba44f4fcf290bba71fd57d7117cbb8")
// Do a few rounds of decryption and encryption
for i := 0; i < 3; i++ {
@@ -44,7 +53,7 @@ func TestKeyEncryptDecrypt(t *testing.T) {
}
// Recrypt with a new password and start over
password += "new data appended"
- if keyjson, err = EncryptKey(key, password, LightScryptN, LightScryptP); err != nil {
+ if keyjson, err = EncryptKey(key, password, veryLightScryptN, veryLightScryptP); err != nil {
t.Errorf("test %d: failed to recrypt key %v", i, err)
}
}