mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-30 07:35:07 +02:00
lnwire: separate ChannelID into a distinct struct, add tests
This commit separates out the ChannelID into a new file, with additional helper methods for conversion and formatting. With this commit, the struct is now more general purpose and can be used in the new routing package, database, and other related sub-systems.
This commit is contained in:
39
lnwire/channel_id_test.go
Normal file
39
lnwire/channel_id_test.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package lnwire
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
)
|
||||
|
||||
func TestChannelIDEncoding(t *testing.T) {
|
||||
var testCases = []ChannelID{
|
||||
{
|
||||
BlockHeight: (1 << 24) - 1,
|
||||
TxIndex: (1 << 24) - 1,
|
||||
TxPosition: (1 << 16) - 1,
|
||||
},
|
||||
{
|
||||
BlockHeight: 2304934,
|
||||
TxIndex: 2345,
|
||||
TxPosition: 5,
|
||||
},
|
||||
{
|
||||
BlockHeight: 9304934,
|
||||
TxIndex: 2345,
|
||||
TxPosition: 5233,
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
chanInt := testCase.ToUint64()
|
||||
|
||||
newChanID := NewChanIDFromInt(chanInt)
|
||||
|
||||
if !reflect.DeepEqual(testCase, newChanID) {
|
||||
t.Fatalf("chan ID's don't match: expected %v got %v",
|
||||
spew.Sdump(testCase), spew.Sdump(newChanID))
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user