mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-23 17:28:27 +00:00
Fix keystore loader bug (#2774)
This commit is contained in:
parent
fc5ea1c236
commit
0d4de335df
@ -36,10 +36,14 @@ proc loadKeystores*(am: var AccountsManager, path: string):
|
||||
createDir(path)
|
||||
for filename in walkDirRec(path):
|
||||
var data = Json.loadFile(filename, JsonNode)
|
||||
if data.kind != JObject:
|
||||
return err("expect json object of keystore data: " & filename)
|
||||
if not data.hasKey("address"):
|
||||
return err("no 'address' field in keystore data: " & filename)
|
||||
let address = Address.fromHex(data["address"].getStr())
|
||||
am.accounts[address] = NimbusAccount(keystore: data, unlocked: false)
|
||||
except CatchableError as exc:
|
||||
return err("loadKeystrores: " & exc.msg)
|
||||
return err("loadKeystores: " & exc.msg)
|
||||
|
||||
ok()
|
||||
|
||||
|
@ -0,0 +1 @@
|
||||
{"password":"monkeyelephant","crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"3ca1d5c5151fba8281f8880ece920740"},"ciphertext":"ec8b7626f3494605e4b66a889c3dbf9bae4d8fe249718d25f010441af3cf6c61","kdf":"pbkdf2","kdfparams":{"dklen":32,"c":1000000,"prf":"hmac-sha256","salt":"364a67e8bc0a782d715832946662850c"},"mac":"7001a9fb0f63db2b7538bab2a34d2103c67035f4754a3bcf4760359f530d5c21"},"id":"5098841b-9060-4ce7-baf7-c748b12d79c9","version":3}
|
1
tests/invalid_keystore/notobject/notobject.json
Normal file
1
tests/invalid_keystore/notobject/notobject.json
Normal file
@ -0,0 +1 @@
|
||||
"a string"
|
@ -9,12 +9,12 @@
|
||||
# according to those terms.
|
||||
|
||||
import
|
||||
std/[os],
|
||||
std/[os, strutils],
|
||||
pkg/[unittest2],
|
||||
eth/common/[base, keys],
|
||||
stew/byteutils,
|
||||
../nimbus/config,
|
||||
../nimbus/common/[chain_config, context],
|
||||
../nimbus/common/[chain_config, context, manager],
|
||||
./test_helpers
|
||||
|
||||
proc configurationMain*() =
|
||||
@ -295,5 +295,17 @@ proc configurationMain*() =
|
||||
check conf.dataDir.string == defaultDataDir()
|
||||
check conf.keyStore.string == "banana"
|
||||
|
||||
test "loadKeystores missing address":
|
||||
var am = AccountsManager.init()
|
||||
let res = am.loadKeystores("tests/invalid_keystore/missingaddress")
|
||||
check res.isErr
|
||||
check res.error.find("no 'address' field in keystore data:") == 0
|
||||
|
||||
test "loadKeystores not an object":
|
||||
var am = AccountsManager.init()
|
||||
let res = am.loadKeystores("tests/invalid_keystore/notobject")
|
||||
check res.isErr
|
||||
check res.error.find("expect json object of keystore data:") == 0
|
||||
|
||||
when isMainModule:
|
||||
configurationMain()
|
||||
|
Loading…
x
Reference in New Issue
Block a user