short_channel_id_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package lnwire
  2. import (
  3. "reflect"
  4. "testing"
  5. "github.com/davecgh/go-spew/spew"
  6. "github.com/stretchr/testify/require"
  7. )
  8. func TestShortChannelIDEncoding(t *testing.T) {
  9. t.Parallel()
  10. var testCases = []ShortChannelID{
  11. {
  12. BlockHeight: (1 << 24) - 1,
  13. TxIndex: (1 << 24) - 1,
  14. TxPosition: (1 << 16) - 1,
  15. },
  16. {
  17. BlockHeight: 2304934,
  18. TxIndex: 2345,
  19. TxPosition: 5,
  20. },
  21. {
  22. BlockHeight: 9304934,
  23. TxIndex: 2345,
  24. TxPosition: 5233,
  25. },
  26. }
  27. for _, testCase := range testCases {
  28. chanInt := testCase.ToUint64()
  29. newChanID := NewShortChanIDFromInt(chanInt)
  30. if !reflect.DeepEqual(testCase, newChanID) {
  31. t.Fatalf("chan ID's don't match: expected %v got %v",
  32. spew.Sdump(testCase), spew.Sdump(newChanID))
  33. }
  34. }
  35. }
  36. // TestScidTypeEncodeDecode tests that we're able to properly encode and decode
  37. // ShortChannelID within TLV streams.
  38. func TestScidTypeEncodeDecode(t *testing.T) {
  39. t.Parallel()
  40. aliasScid := ShortChannelID{
  41. BlockHeight: (1 << 24) - 1,
  42. TxIndex: (1 << 24) - 1,
  43. TxPosition: (1 << 16) - 1,
  44. }
  45. var extraData ExtraOpaqueData
  46. require.NoError(t, extraData.PackRecords(&aliasScid))
  47. var aliasScid2 ShortChannelID
  48. tlvs, err := extraData.ExtractRecords(&aliasScid2)
  49. require.NoError(t, err)
  50. require.Contains(t, tlvs, AliasScidRecordType)
  51. require.Equal(t, aliasScid, aliasScid2)
  52. }