diff options
author | Felix Lange <fjl@twurst.com> | 2016-08-18 19:28:17 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-09-16 21:24:31 +0800 |
commit | eeb322ae649c4a1a32430cdddfffed70f509181e (patch) | |
tree | 35622201208afb98665743d9bcf88883058e772a /node/config_test.go | |
parent | 52ede09b172094f8fd85f8b10e7d0578059353fb (diff) | |
download | go-tangerine-eeb322ae649c4a1a32430cdddfffed70f509181e.tar.gz go-tangerine-eeb322ae649c4a1a32430cdddfffed70f509181e.tar.zst go-tangerine-eeb322ae649c4a1a32430cdddfffed70f509181e.zip |
node: ensure datadir can be co-inhabited by different instances
This change ensures that nodes started with different Name but same
DataDir values don't use the same nodekey and IPC socket.
Diffstat (limited to 'node/config_test.go')
-rw-r--r-- | node/config_test.go | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/node/config_test.go b/node/config_test.go index 45a54d184..b258d2a8b 100644 --- a/node/config_test.go +++ b/node/config_test.go @@ -96,57 +96,55 @@ func TestIPCPathResolution(t *testing.T) { // ephemeral. func TestNodeKeyPersistency(t *testing.T) { // Create a temporary folder and make sure no key is present - dir, err := ioutil.TempDir("", "") + dir, err := ioutil.TempDir("", "node-test") if err != nil { t.Fatalf("failed to create temporary data directory: %v", err) } defer os.RemoveAll(dir) - if _, err := os.Stat(filepath.Join(dir, datadirPrivateKey)); err == nil { - t.Fatalf("non-created node key already exists") - } + keyfile := filepath.Join(dir, "unit-test", datadirPrivateKey) + // Configure a node with a preset key and ensure it's not persisted key, err := crypto.GenerateKey() if err != nil { t.Fatalf("failed to generate one-shot node key: %v", err) } - if _, err := New(&Config{DataDir: dir, PrivateKey: key}); err != nil { - t.Fatalf("failed to create empty stack: %v", err) - } - if _, err := os.Stat(filepath.Join(dir, datadirPrivateKey)); err == nil { + config := &Config{Name: "unit-test", DataDir: dir, PrivateKey: key} + config.NodeKey() + if _, err := os.Stat(filepath.Join(keyfile)); err == nil { t.Fatalf("one-shot node key persisted to data directory") } + // Configure a node with no preset key and ensure it is persisted this time - if _, err := New(&Config{DataDir: dir}); err != nil { - t.Fatalf("failed to create newly keyed stack: %v", err) - } - if _, err := os.Stat(filepath.Join(dir, datadirPrivateKey)); err != nil { + config = &Config{Name: "unit-test", DataDir: dir} + config.NodeKey() + if _, err := os.Stat(keyfile); err != nil { t.Fatalf("node key not persisted to data directory: %v", err) } - key, err = crypto.LoadECDSA(filepath.Join(dir, datadirPrivateKey)) + key, err = crypto.LoadECDSA(keyfile) if err != nil { t.Fatalf("failed to load freshly persisted node key: %v", err) } - blob1, err := ioutil.ReadFile(filepath.Join(dir, datadirPrivateKey)) + blob1, err := ioutil.ReadFile(keyfile) if err != nil { t.Fatalf("failed to read freshly persisted node key: %v", err) } + // Configure a new node and ensure the previously persisted key is loaded - if _, err := New(&Config{DataDir: dir}); err != nil { - t.Fatalf("failed to create previously keyed stack: %v", err) - } - blob2, err := ioutil.ReadFile(filepath.Join(dir, datadirPrivateKey)) + config = &Config{Name: "unit-test", DataDir: dir} + config.NodeKey() + blob2, err := ioutil.ReadFile(filepath.Join(keyfile)) if err != nil { t.Fatalf("failed to read previously persisted node key: %v", err) } if bytes.Compare(blob1, blob2) != 0 { t.Fatalf("persisted node key mismatch: have %x, want %x", blob2, blob1) } + // Configure ephemeral node and ensure no key is dumped locally - if _, err := New(&Config{DataDir: ""}); err != nil { - t.Fatalf("failed to create ephemeral stack: %v", err) - } - if _, err := os.Stat(filepath.Join(".", datadirPrivateKey)); err == nil { + config = &Config{Name: "unit-test", DataDir: ""} + config.NodeKey() + if _, err := os.Stat(filepath.Join(".", "unit-test", datadirPrivateKey)); err == nil { t.Fatalf("ephemeral node key persisted to disk") } } |