[#1255] node/session: Add encryption tests

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-03-21 14:54:28 +03:00 committed by Alex Vanin
parent 01ed366e99
commit 016eaa25f3

View file

@ -0,0 +1,29 @@
package persistent
import (
"bytes"
"path/filepath"
"testing"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/stretchr/testify/require"
)
func TestTokenStore_Encryption(t *testing.T) {
pk, err := keys.NewPrivateKey()
require.NoError(t, err)
ts, err := NewTokenStore(filepath.Join(t.TempDir(), ".storage"), WithEncryptionKey(&pk.PrivateKey))
require.NoError(t, err)
data := []byte("nice encryption, awesome tests")
encryptedData, err := ts.encrypt(data)
require.NoError(t, err)
require.False(t, bytes.Equal(data, encryptedData))
decryptedData, err := ts.decrypt(encryptedData)
require.NoError(t, err)
require.Equal(t, data, decryptedData)
}