channeldb: add KeyLocator Record
This commit is contained in:
2 files changed
+70
No files matched your search
@@ -8,6 +8,8 @@ import (
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
@@ -50,6 +52,9 @@ var (
|
||||
IP: net.ParseIP("127.0.0.1"),
|
||||
Port: 18555,
|
||||
}
|
||||
|
||||
// keyLocIndex is the KeyLocator Index we use for TestKeyLocatorEncoding.
|
||||
keyLocIndex = uint32(2049)
|
||||
)
|
||||
|
||||
// testChannelParams is a struct which details the specifics of how a channel
|
||||
@@ -1587,3 +1592,33 @@ func TestHasChanStatus(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestKeyLocatorEncoding tests that we are able to serialize a given
|
||||
// keychain.KeyLocator. After successfully encoding, we check that the decode
|
||||
// output arrives at the same initial KeyLocator.
|
||||
func TestKeyLocatorEncoding(t *testing.T) {
|
||||
keyLoc := keychain.KeyLocator{
|
||||
Family: keychain.KeyFamilyRevocationRoot,
|
||||
Index: keyLocIndex,
|
||||
}
|
||||
|
||||
// First, we'll encode the KeyLocator into a buffer.
|
||||
var (
|
||||
b bytes.Buffer
|
||||
buf [8]byte
|
||||
)
|
||||
|
||||
err := EKeyLocator(&b, &keyLoc, &buf)
|
||||
require.NoError(t, err, "unable to encode key locator")
|
||||
|
||||
// Next, we'll attempt to decode the bytes into a new KeyLocator.
|
||||
r := bytes.NewReader(b.Bytes())
|
||||
var decodedKeyLoc keychain.KeyLocator
|
||||
|
||||
err = DKeyLocator(r, &decodedKeyLoc, &buf, 8)
|
||||
require.NoError(t, err, "unable to decode key locator")
|
||||
|
||||
// Finally, we'll compare that the original KeyLocator and the decoded
|
||||
// version are equal.
|
||||
require.Equal(t, keyLoc, decodedKeyLoc)
|
||||
}
|
||||
Reference in new issue
Block a user