channeldb: read raw htlc attempt session key

This commit is contained in:
carla committed 2021-05-19 09:03:52 +02:00
1 parent eb068bf666
commit 8071ebb16a
5 files changed
+52 -23

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
package channeldb
import (
"bytes"
"testing"
"github.com/stretchr/testify/require"
)
// TestLazySessionKeyDeserialize tests that we can read htlc attempt session
// keys that were previously serialized as a private key as raw bytes.
func TestLazySessionKeyDeserialize(t *testing.T) {
var b bytes.Buffer
// Serialize as a private key.
err := WriteElements(&b, priv)
require.NoError(t, err)
// Deserialize into [btcec.PrivKeyBytesLen]byte.
attempt := HTLCAttemptInfo{}
err = ReadElements(&b, &attempt.sessionKey)
require.NoError(t, err)
require.Zero(t, b.Len())
sessionKey := attempt.SessionKey()
require.Equal(t, priv, sessionKey)
}