From 2255ce17db9d9e062affe524c148370078319d04 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Mon, 29 Oct 2018 14:23:31 -0700 Subject: [PATCH] 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. --- watchtower/blob/justice_kit_test.go | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/watchtower/blob/justice_kit_test.go b/watchtower/blob/justice_kit_test.go index ae81f3cb..606e43e5 100644 --- a/watchtower/blob/justice_kit_test.go +++ b/watchtower/blob/justice_kit_test.go @@ -27,10 +27,20 @@ func makeSig(i int) lnwire.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 { name string encVersion uint16 decVersion uint16 + sweepAddr []byte revPubKey blob.PubKey delayPubKey blob.PubKey csvDelay uint32 @@ -47,6 +57,7 @@ var descriptorTests = []descriptorTest{ name: "to-local only", encVersion: 0, decVersion: 0, + sweepAddr: makeAddr(22), revPubKey: makePubKey(0), delayPubKey: makePubKey(1), csvDelay: 144, @@ -56,6 +67,7 @@ var descriptorTests = []descriptorTest{ name: "to-local and p2wkh", encVersion: 0, decVersion: 0, + sweepAddr: makeAddr(22), revPubKey: makePubKey(0), delayPubKey: makePubKey(1), csvDelay: 144, @@ -68,6 +80,7 @@ var descriptorTests = []descriptorTest{ name: "unknown encrypt version", encVersion: 1, decVersion: 0, + sweepAddr: makeAddr(34), revPubKey: makePubKey(0), delayPubKey: makePubKey(1), csvDelay: 144, @@ -78,12 +91,44 @@ var descriptorTests = []descriptorTest{ name: "unknown decrypt version", encVersion: 0, decVersion: 1, + sweepAddr: makeAddr(34), revPubKey: makePubKey(0), delayPubKey: makePubKey(1), csvDelay: 144, commitToLocalSig: makeSig(1), 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 @@ -100,6 +145,7 @@ func TestBlobJusticeKitEncryptDecrypt(t *testing.T) { func testBlobJusticeKitEncryptDecrypt(t *testing.T, test descriptorTest) { boj := &blob.JusticeKit{ + SweepAddress: test.sweepAddr, RevocationPubKey: test.revPubKey, LocalDelayPubKey: test.delayPubKey, CSVDelay: test.csvDelay,