2022-03-20 19:55:58 +00:00
|
|
|
package persistent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPack(t *testing.T) {
|
|
|
|
key, err := keys.NewPrivateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-21 11:53:49 +00:00
|
|
|
ts := new(TokenStore)
|
|
|
|
|
2022-03-20 19:55:58 +00:00
|
|
|
const exp = 12345
|
|
|
|
|
2022-03-21 11:53:49 +00:00
|
|
|
raw, err := ts.packToken(exp, &key.PrivateKey)
|
2022-03-20 19:55:58 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, uint64(exp), epochFromToken(raw))
|
|
|
|
|
2022-03-21 11:53:49 +00:00
|
|
|
unpacked, err := ts.unpackToken(raw)
|
2022-03-20 19:55:58 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, uint64(exp), unpacked.ExpiredAt())
|
|
|
|
require.Equal(t, true, key.Equal(unpacked.SessionKey()))
|
|
|
|
}
|