watchtower/blob/justice_kit_test: add sweep addr tests
Adds vectors to the justice kit tests to ensure variable length sweep addresses are properly encoded/decoded.
This commit is contained in:
parent
b7d811b3dd
commit
2255ce17db
@ -27,10 +27,20 @@ func makeSig(i int) lnwire.Sig {
|
|||||||
return sig
|
return sig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func makeAddr(size int) []byte {
|
||||||
|
addr := make([]byte, size)
|
||||||
|
if _, err := io.ReadFull(rand.Reader, addr); err != nil {
|
||||||
|
panic("unable to create addr")
|
||||||
|
}
|
||||||
|
|
||||||
|
return addr
|
||||||
|
}
|
||||||
|
|
||||||
type descriptorTest struct {
|
type descriptorTest struct {
|
||||||
name string
|
name string
|
||||||
encVersion uint16
|
encVersion uint16
|
||||||
decVersion uint16
|
decVersion uint16
|
||||||
|
sweepAddr []byte
|
||||||
revPubKey blob.PubKey
|
revPubKey blob.PubKey
|
||||||
delayPubKey blob.PubKey
|
delayPubKey blob.PubKey
|
||||||
csvDelay uint32
|
csvDelay uint32
|
||||||
@ -47,6 +57,7 @@ var descriptorTests = []descriptorTest{
|
|||||||
name: "to-local only",
|
name: "to-local only",
|
||||||
encVersion: 0,
|
encVersion: 0,
|
||||||
decVersion: 0,
|
decVersion: 0,
|
||||||
|
sweepAddr: makeAddr(22),
|
||||||
revPubKey: makePubKey(0),
|
revPubKey: makePubKey(0),
|
||||||
delayPubKey: makePubKey(1),
|
delayPubKey: makePubKey(1),
|
||||||
csvDelay: 144,
|
csvDelay: 144,
|
||||||
@ -56,6 +67,7 @@ var descriptorTests = []descriptorTest{
|
|||||||
name: "to-local and p2wkh",
|
name: "to-local and p2wkh",
|
||||||
encVersion: 0,
|
encVersion: 0,
|
||||||
decVersion: 0,
|
decVersion: 0,
|
||||||
|
sweepAddr: makeAddr(22),
|
||||||
revPubKey: makePubKey(0),
|
revPubKey: makePubKey(0),
|
||||||
delayPubKey: makePubKey(1),
|
delayPubKey: makePubKey(1),
|
||||||
csvDelay: 144,
|
csvDelay: 144,
|
||||||
@ -68,6 +80,7 @@ var descriptorTests = []descriptorTest{
|
|||||||
name: "unknown encrypt version",
|
name: "unknown encrypt version",
|
||||||
encVersion: 1,
|
encVersion: 1,
|
||||||
decVersion: 0,
|
decVersion: 0,
|
||||||
|
sweepAddr: makeAddr(34),
|
||||||
revPubKey: makePubKey(0),
|
revPubKey: makePubKey(0),
|
||||||
delayPubKey: makePubKey(1),
|
delayPubKey: makePubKey(1),
|
||||||
csvDelay: 144,
|
csvDelay: 144,
|
||||||
@ -78,12 +91,44 @@ var descriptorTests = []descriptorTest{
|
|||||||
name: "unknown decrypt version",
|
name: "unknown decrypt version",
|
||||||
encVersion: 0,
|
encVersion: 0,
|
||||||
decVersion: 1,
|
decVersion: 1,
|
||||||
|
sweepAddr: makeAddr(34),
|
||||||
revPubKey: makePubKey(0),
|
revPubKey: makePubKey(0),
|
||||||
delayPubKey: makePubKey(1),
|
delayPubKey: makePubKey(1),
|
||||||
csvDelay: 144,
|
csvDelay: 144,
|
||||||
commitToLocalSig: makeSig(1),
|
commitToLocalSig: makeSig(1),
|
||||||
decErr: blob.ErrUnknownBlobVersion,
|
decErr: blob.ErrUnknownBlobVersion,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "sweep addr length zero",
|
||||||
|
encVersion: 0,
|
||||||
|
decVersion: 0,
|
||||||
|
sweepAddr: makeAddr(0),
|
||||||
|
revPubKey: makePubKey(0),
|
||||||
|
delayPubKey: makePubKey(1),
|
||||||
|
csvDelay: 144,
|
||||||
|
commitToLocalSig: makeSig(1),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "sweep addr max size",
|
||||||
|
encVersion: 0,
|
||||||
|
decVersion: 0,
|
||||||
|
sweepAddr: makeAddr(blob.MaxSweepAddrSize),
|
||||||
|
revPubKey: makePubKey(0),
|
||||||
|
delayPubKey: makePubKey(1),
|
||||||
|
csvDelay: 144,
|
||||||
|
commitToLocalSig: makeSig(1),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "sweep addr too long",
|
||||||
|
encVersion: 0,
|
||||||
|
decVersion: 0,
|
||||||
|
sweepAddr: makeAddr(blob.MaxSweepAddrSize + 1),
|
||||||
|
revPubKey: makePubKey(0),
|
||||||
|
delayPubKey: makePubKey(1),
|
||||||
|
csvDelay: 144,
|
||||||
|
commitToLocalSig: makeSig(1),
|
||||||
|
encErr: blob.ErrSweepAddressToLong,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestBlobJusticeKitEncryptDecrypt asserts that encrypting and decrypting a
|
// TestBlobJusticeKitEncryptDecrypt asserts that encrypting and decrypting a
|
||||||
@ -100,6 +145,7 @@ func TestBlobJusticeKitEncryptDecrypt(t *testing.T) {
|
|||||||
|
|
||||||
func testBlobJusticeKitEncryptDecrypt(t *testing.T, test descriptorTest) {
|
func testBlobJusticeKitEncryptDecrypt(t *testing.T, test descriptorTest) {
|
||||||
boj := &blob.JusticeKit{
|
boj := &blob.JusticeKit{
|
||||||
|
SweepAddress: test.sweepAddr,
|
||||||
RevocationPubKey: test.revPubKey,
|
RevocationPubKey: test.revPubKey,
|
||||||
LocalDelayPubKey: test.delayPubKey,
|
LocalDelayPubKey: test.delayPubKey,
|
||||||
CSVDelay: test.csvDelay,
|
CSVDelay: test.csvDelay,
|
||||||
|
Loading…
Reference in New Issue
Block a user