-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
exporttestutils.go
38 lines (27 loc) · 1.05 KB
/
exporttestutils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package keys
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/smartcontractkit/chainlink/v2/core/utils"
)
// KeyType represents a key type for keys testing
type KeyType interface {
ToEncryptedJSON(password string, scryptParams utils.ScryptParams) (export []byte, err error)
String() string
}
// CreateKeyFunc represents a function to create a key
type CreateKeyFunc func() (KeyType, error)
// DecryptFunc represents a function to decrypt a key
type DecryptFunc func(keyJSON []byte, password string) (KeyType, error)
// RunKeyExportImportTestcase executes a testcase to validate keys import/export functionality
func RunKeyExportImportTestcase(t *testing.T, createKey CreateKeyFunc, decrypt DecryptFunc) {
key, err := createKey()
require.NoError(t, err)
json, err := key.ToEncryptedJSON("password", utils.FastScryptParams)
require.NoError(t, err)
assert.NotEmpty(t, json)
imported, err := decrypt(json, "password")
require.NoError(t, err)
assert.Equal(t, key.String(), imported.String())
}