record: add AMP record and encode/decode methods

This commit is contained in:
Conner Fromknecht
2020-01-28 06:43:07 -08:00
parent e79897e651
commit de88a4b174
2 changed files with 135 additions and 2 deletions

View File

@@ -17,8 +17,11 @@ type recordEncDecTest struct {
}
var (
testTotal = lnwire.MilliSatoshi(45)
testAddr = [32]byte{0x01, 0x02}
testTotal = lnwire.MilliSatoshi(45)
testAddr = [32]byte{0x01, 0x02}
testShare = [32]byte{0x03, 0x04}
testSetID = [32]byte{0x05, 0x06}
testChildIndex = uint16(17)
)
var recordEncDecTests = []recordEncDecTest{
@@ -40,6 +43,29 @@ var recordEncDecTests = []recordEncDecTest{
}
},
},
{
name: "amp",
encRecord: func() tlv.RecordProducer {
return record.NewAMP(
testShare, testSetID, testChildIndex,
)
},
decRecord: func() tlv.RecordProducer {
return new(record.AMP)
},
assert: func(t *testing.T, r interface{}) {
amp := r.(*record.AMP)
if amp.RootShare() != testShare {
t.Fatal("incorrect root share")
}
if amp.SetID() != testSetID {
t.Fatal("incorrect set id")
}
if amp.ChildIndex() != testChildIndex {
t.Fatal("incorrect child index")
}
},
},
}
// TestRecordEncodeDecode is a generic test framework for custom TLV records. It