Skip to content

Commit

Permalink
test(config): TestLoadNodeKeyID
Browse files Browse the repository at this point in the history
  • Loading branch information
lklimek committed Aug 21, 2024
1 parent dd10bcd commit f10f303
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"os"
"reflect"
"testing"
"time"
Expand Down Expand Up @@ -223,3 +224,39 @@ func TestP2PConfigValidateBasic(t *testing.T) {
reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(0)
}
}

// Given some invalid node key file, when I try to load it, I get an error
func TestLoadNodeKeyID(t *testing.T) {

testCases := []string{
`{
"type": "tendermint/PrivKeyEd25519",
"value": "wIVaBy3v4bKcrBxGsgFen9qJeqXiK4h18iWCM2LSYxMyH8PomXsANUb3KoucY9EBDj0NQi4LqrmG8DyT5D6xWQ=="
}`,
`{
"id":"0d846d89021b617026c3a3d4051ebcf4cdd09f7c",
"priv_key":{
"type":"tendermint/PrivKeyEd25519",
"value":"J5EWnwSixAZuuw2Gf5nbXXNbyliaURFgBawfwN+zU/N7ucjnxu0GLcVi107XEj2Myq95101jcPPcJE+dCncY1A=="
}
}`,
}

for _, tc := range testCases {
t.Run("", func(t *testing.T) {
cfg := DefaultBaseConfig()
tmpDir := t.TempDir()

// create invalid node key file
cfg.NodeKey = tmpDir + "/node_key.json"
err := os.WriteFile(cfg.NodeKey, []byte(tc), 0600)
require.NoError(t, err)

// when I try to load the node key
_, err = cfg.LoadNodeKeyID()

// then I get an error
assert.Error(t, err)
})
}
}

0 comments on commit f10f303

Please sign in to comment.